@mastra/libsql 1.10.1-alpha.2 → 1.10.1
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 +40 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-composite.md +1 -1
- package/dist/docs/references/reference-storage-dynamodb.md +1 -1
- package/dist/docs/references/reference-storage-libsql.md +1 -1
- package/dist/index.cjs +146 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +146 -44
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/channels/index.d.ts.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +27 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 1.10.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- **Fixed** Workflow run snapshots no longer lose fields when serialized for storage. The libsql `safeStringify` cycle-detection treated any object that appeared more than once in a snapshot as a circular reference and dropped it. Because `snapshot.result` and the final step's `context[step].output` share the same reference on success, `snapshot.result` was being silently stripped on every persist. This caused `listWorkflowRuns` to return runs with `snapshot.result === undefined` and broke workflow resume when suspended-state fields were shared elsewhere in the snapshot. ([#16368](https://github.com/mastra-ai/mastra/pull/16368))
|
|
8
|
+
|
|
9
|
+
- **Fixed** Workflow runs no longer fail to persist when request context contains non-serializable values (for example functions, circular references, or platform proxy objects). This prevents errors when saving workflow snapshots and scorer results. See #12301. ([#12573](https://github.com/mastra-ai/mastra/pull/12573))
|
|
10
|
+
|
|
11
|
+
- Respect optional `resourceId` in `getThreadById` so scoped thread lookups return `null` when the thread belongs to a different resource. ([#14237](https://github.com/mastra-ai/mastra/pull/14237))
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
const thread = await memory.getThreadById({
|
|
17
|
+
threadId: 'my-thread-id',
|
|
18
|
+
resourceId: 'my-user-id',
|
|
19
|
+
});
|
|
20
|
+
// Returns null if the thread does not belong to 'my-user-id'.
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- Improved local LibSQL startup performance by applying conservative local SQLite performance settings before initialization, exposing local PRAGMA overrides, and reducing schema initialization contention. ([#16513](https://github.com/mastra-ai/mastra/pull/16513))
|
|
24
|
+
|
|
25
|
+
- Track `suspendedAt` and `suspendPayload` on background tasks. SQL adapters auto-migrate the new columns via `alterTable`. ([#16260](https://github.com/mastra-ai/mastra/pull/16260))
|
|
26
|
+
|
|
27
|
+
- Added LibSQL indexes for thread message history queries to speed up recent-message and observational-memory loading. ([#16513](https://github.com/mastra-ai/mastra/pull/16513))
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`ac47842`](https://github.com/mastra-ai/mastra/commit/ac478427aa7a5f5fdaed633a911218689b438c60), [`cc189cc`](https://github.com/mastra-ai/mastra/commit/cc189cc0128eb7af233476b5e421ec6888bffde7), [`d1fdbd0`](https://github.com/mastra-ai/mastra/commit/d1fdbd012add5623cb7e6b7f882b605ab358bbb4), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`bae019e`](https://github.com/mastra-ai/mastra/commit/bae019ecb6694da96909f7ec7b9eb3a0a33aa887), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`37c0dc5`](https://github.com/mastra-ai/mastra/commit/37c0dc5697d343db98628bf867bf71ce6deec6d7), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`ef6b584`](https://github.com/mastra-ai/mastra/commit/ef6b5847ac33c0a7e80af3a86e8801e2933dd3ee), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`d91ebe2`](https://github.com/mastra-ai/mastra/commit/d91ebe28ee065d8f2ed6df741c3c07f58d359529), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`33f5061`](https://github.com/mastra-ai/mastra/commit/33f5061cd1c0335020c3faae61ce96de822854fa), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`ce01024`](https://github.com/mastra-ai/mastra/commit/ce010242eee9bdfc09e4c26725b9d37998679a8d), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`dccd8f1`](https://github.com/mastra-ai/mastra/commit/dccd8f1f8b8f1ad203b77556207e5529567c616d), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`4dd900d`](https://github.com/mastra-ai/mastra/commit/4dd900d75dfe9be89f8c15188b368a8622aa1e18), [`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`99869ec`](https://github.com/mastra-ai/mastra/commit/99869ecb1f2aa6dfcc44fa4e843e5ee0344efa64), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`4ff5bdf`](https://github.com/mastra-ai/mastra/commit/4ff5bdfe170cba6dfb5260c6af0f4ba668430772), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`bbcd93c`](https://github.com/mastra-ai/mastra/commit/bbcd93cf7d8aa1007d6d84bfd033b8015c912087), [`8373ff4`](https://github.com/mastra-ai/mastra/commit/8373ff46745d77af79f183c4470f80fa2727a6b2), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a), [`308bd07`](https://github.com/mastra-ai/mastra/commit/308bd074f35cef0c75d82fc1eb19382fe04ecf6f), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`d86f031`](https://github.com/mastra-ai/mastra/commit/d86f031eb6b0b2570145afafea664e59bf688962), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`11c1528`](https://github.com/mastra-ai/mastra/commit/11c152848c5d0ef227184853b5040f5b41ee7b1e), [`4999667`](https://github.com/mastra-ai/mastra/commit/49996678b68356cad7f088430009690406c50fbd), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`105e454`](https://github.com/mastra-ai/mastra/commit/105e454c95af06a7c741c15969d8f9b0f02463a7), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066), [`5688881`](https://github.com/mastra-ai/mastra/commit/5688881669c7ed157f31ac77f6fc5f8d95ceea32)]:
|
|
30
|
+
- @mastra/core@1.33.0
|
|
31
|
+
|
|
32
|
+
## 1.10.1-alpha.3
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- Improved local LibSQL startup performance by applying conservative local SQLite performance settings before initialization, exposing local PRAGMA overrides, and reducing schema initialization contention. ([#16513](https://github.com/mastra-ai/mastra/pull/16513))
|
|
37
|
+
|
|
38
|
+
- Added LibSQL indexes for thread message history queries to speed up recent-message and observational-memory loading. ([#16513](https://github.com/mastra-ai/mastra/pull/16513))
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [[`4999667`](https://github.com/mastra-ai/mastra/commit/49996678b68356cad7f088430009690406c50fbd)]:
|
|
41
|
+
- @mastra/core@1.33.0-alpha.17
|
|
42
|
+
|
|
3
43
|
## 1.10.1-alpha.2
|
|
4
44
|
|
|
5
45
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -242,4 +242,4 @@ const storage = new MastraCompositeStore({
|
|
|
242
242
|
|
|
243
243
|
> **Note:** `ObservabilityStorageClickhouseVNext` is the current observability domain implementation. The legacy `ObservabilityStorageClickhouse` class is also exported and remains supported for projects that have not migrated. See the [ClickHouse storage reference](https://mastra.ai/reference/storage/clickhouse) for details.
|
|
244
244
|
|
|
245
|
-
> **Info:** This approach is also required when using storage providers that don't support observability (like Convex, DynamoDB, or Cloudflare). See the [
|
|
245
|
+
> **Info:** This approach is also required when using storage providers that don't support observability (like Convex, DynamoDB, or Cloudflare). See the [MastraStorageExporter documentation](https://mastra.ai/docs/observability/tracing/exporters/mastra-storage) for the full list of supported providers.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The DynamoDB storage implementation provides a scalable and performant NoSQL database solution for Mastra, leveraging a single-table design pattern with [ElectroDB](https://electrodb.dev/).
|
|
4
4
|
|
|
5
|
-
> **Observability Not Supported:** DynamoDB storage **doesn't support the observability domain**. Traces from the `
|
|
5
|
+
> **Observability Not Supported:** DynamoDB storage **doesn't support the observability domain**. Traces from the `MastraStorageExporter` can't be persisted to DynamoDB, and [Studio's](https://mastra.ai/docs/studio/overview) observability features won't work with DynamoDB as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse.
|
|
6
6
|
|
|
7
7
|
> **Item Size Limit:** DynamoDB enforces a **400 KB maximum item size**. This limit can be exceeded when storing messages with base64-encoded attachments such as images. See [Handling large attachments](https://mastra.ai/docs/memory/storage) for workarounds including uploading attachments to external storage.
|
|
8
8
|
|
|
@@ -130,6 +130,6 @@ const thread = await memoryStore?.getThreadById({ threadId: '...' })
|
|
|
130
130
|
|
|
131
131
|
## Observability
|
|
132
132
|
|
|
133
|
-
libSQL supports observability and is ideal for local development. Use the `realtime` [tracing strategy](https://mastra.ai/docs/observability/tracing/exporters/
|
|
133
|
+
libSQL supports observability and is ideal for local development. Use the `realtime` [tracing strategy](https://mastra.ai/docs/observability/tracing/exporters/mastra-storage) for immediate visibility while debugging.
|
|
134
134
|
|
|
135
135
|
For production environments with higher trace volumes, consider using [PostgreSQL](https://mastra.ai/reference/storage/postgresql) or [ClickHouse via composite storage](https://mastra.ai/reference/storage/composite).
|
package/dist/index.cjs
CHANGED
|
@@ -1934,15 +1934,21 @@ var LibSQLDB = class extends base.MastraBase {
|
|
|
1934
1934
|
async migrateSpansTable() {
|
|
1935
1935
|
const schema = storage.TABLE_SCHEMAS[storage.TABLE_SPANS];
|
|
1936
1936
|
try {
|
|
1937
|
+
const existingColumnsRaw = await this.getTableColumns(storage.TABLE_SPANS);
|
|
1938
|
+
const existingColumns = new Set([...existingColumnsRaw].map((column) => column.toLowerCase()));
|
|
1939
|
+
let addedColumns = false;
|
|
1937
1940
|
for (const [columnName, columnDef] of Object.entries(schema)) {
|
|
1938
|
-
|
|
1939
|
-
if (!columnExists) {
|
|
1941
|
+
if (!existingColumns.has(columnName.toLowerCase())) {
|
|
1940
1942
|
const sqlType = this.getSqlType(columnDef.type);
|
|
1941
1943
|
const alterSql = `ALTER TABLE "${storage.TABLE_SPANS}" ADD COLUMN "${columnName}" ${sqlType}`;
|
|
1942
1944
|
await this.client.execute(alterSql);
|
|
1945
|
+
addedColumns = true;
|
|
1943
1946
|
this.logger.debug(`LibSQLDB: Added column '${columnName}' to ${storage.TABLE_SPANS}`);
|
|
1944
1947
|
}
|
|
1945
1948
|
}
|
|
1949
|
+
if (addedColumns) {
|
|
1950
|
+
this.tableColumnsCache.delete(storage.TABLE_SPANS);
|
|
1951
|
+
}
|
|
1946
1952
|
const indexExists = await this.spansUniqueIndexExists();
|
|
1947
1953
|
if (!indexExists) {
|
|
1948
1954
|
const duplicateInfo = await this.checkForDuplicateSpans();
|
|
@@ -3351,11 +3357,18 @@ var ChannelsLibSQL = class extends storage.ChannelsStorage {
|
|
|
3351
3357
|
tableName: storage.TABLE_CHANNEL_CONFIG,
|
|
3352
3358
|
schema: storage.TABLE_SCHEMAS[storage.TABLE_CHANNEL_CONFIG]
|
|
3353
3359
|
});
|
|
3354
|
-
await this.#client.
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3360
|
+
await this.#client.batch(
|
|
3361
|
+
[
|
|
3362
|
+
{
|
|
3363
|
+
sql: `CREATE UNIQUE INDEX IF NOT EXISTS idx_channel_installations_webhook ON "${storage.TABLE_CHANNEL_INSTALLATIONS}" ("webhookId")`,
|
|
3364
|
+
args: []
|
|
3365
|
+
},
|
|
3366
|
+
{
|
|
3367
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_channel_installations_platform_agent ON "${storage.TABLE_CHANNEL_INSTALLATIONS}" ("platform", "agentId")`,
|
|
3368
|
+
args: []
|
|
3369
|
+
}
|
|
3370
|
+
],
|
|
3371
|
+
"write"
|
|
3359
3372
|
);
|
|
3360
3373
|
}
|
|
3361
3374
|
async dangerouslyClearAll() {
|
|
@@ -3499,26 +3512,31 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
3499
3512
|
await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "requestContext", "TEXT");
|
|
3500
3513
|
await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "source", "TEXT");
|
|
3501
3514
|
await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "expectedTrajectory", "TEXT");
|
|
3502
|
-
await this.#client.
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3515
|
+
await this.#client.batch(
|
|
3516
|
+
[
|
|
3517
|
+
{
|
|
3518
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_dataset_items_dataset_validto ON "${storage.TABLE_DATASET_ITEMS}" ("datasetId", "validTo")`,
|
|
3519
|
+
args: []
|
|
3520
|
+
},
|
|
3521
|
+
{
|
|
3522
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_dataset_items_dataset_version ON "${storage.TABLE_DATASET_ITEMS}" ("datasetId", "datasetVersion")`,
|
|
3523
|
+
args: []
|
|
3524
|
+
},
|
|
3525
|
+
{
|
|
3526
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_dataset_items_dataset_validto_deleted ON "${storage.TABLE_DATASET_ITEMS}" ("datasetId", "validTo", "isDeleted")`,
|
|
3527
|
+
args: []
|
|
3528
|
+
},
|
|
3529
|
+
{
|
|
3530
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_dataset_versions_dataset_version ON "${storage.TABLE_DATASET_VERSIONS}" ("datasetId", "version")`,
|
|
3531
|
+
args: []
|
|
3532
|
+
},
|
|
3533
|
+
{
|
|
3534
|
+
sql: `CREATE UNIQUE INDEX IF NOT EXISTS idx_dataset_versions_dataset_version_unique ON "${storage.TABLE_DATASET_VERSIONS}" ("datasetId", "version")`,
|
|
3535
|
+
args: []
|
|
3536
|
+
}
|
|
3537
|
+
],
|
|
3538
|
+
"write"
|
|
3539
|
+
);
|
|
3522
3540
|
}
|
|
3523
3541
|
async #addColumnIfNotExists(table, column, sqlType) {
|
|
3524
3542
|
const exists = await this.#db.hasColumn(table, column);
|
|
@@ -4419,18 +4437,23 @@ var ExperimentsLibSQL = class extends storage.ExperimentsStorage {
|
|
|
4419
4437
|
schema: storage.EXPERIMENT_RESULTS_SCHEMA,
|
|
4420
4438
|
ifNotExists: ["status", "tags"]
|
|
4421
4439
|
});
|
|
4422
|
-
await this.#client.
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4440
|
+
await this.#client.batch(
|
|
4441
|
+
[
|
|
4442
|
+
{
|
|
4443
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_experiments_datasetid ON "${storage.TABLE_EXPERIMENTS}" ("datasetId")`,
|
|
4444
|
+
args: []
|
|
4445
|
+
},
|
|
4446
|
+
{
|
|
4447
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_experiment_results_experimentid ON "${storage.TABLE_EXPERIMENT_RESULTS}" ("experimentId")`,
|
|
4448
|
+
args: []
|
|
4449
|
+
},
|
|
4450
|
+
{
|
|
4451
|
+
sql: `CREATE UNIQUE INDEX IF NOT EXISTS idx_experiment_results_exp_item ON "${storage.TABLE_EXPERIMENT_RESULTS}" ("experimentId", "itemId")`,
|
|
4452
|
+
args: []
|
|
4453
|
+
}
|
|
4454
|
+
],
|
|
4455
|
+
"write"
|
|
4456
|
+
);
|
|
4434
4457
|
}
|
|
4435
4458
|
async dangerouslyClearAll() {
|
|
4436
4459
|
await this.#db.deleteData({ tableName: storage.TABLE_EXPERIMENT_RESULTS });
|
|
@@ -5970,6 +5993,19 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
|
|
|
5970
5993
|
schema: storage.TABLE_SCHEMAS[storage.TABLE_MESSAGES],
|
|
5971
5994
|
ifNotExists: ["resourceId"]
|
|
5972
5995
|
});
|
|
5996
|
+
await this.#client.batch(
|
|
5997
|
+
[
|
|
5998
|
+
{
|
|
5999
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_messages_thread_created_at ON ${storage.TABLE_MESSAGES} (thread_id, "createdAt")`,
|
|
6000
|
+
args: []
|
|
6001
|
+
},
|
|
6002
|
+
{
|
|
6003
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_messages_thread_resource_created_at ON ${storage.TABLE_MESSAGES} (thread_id, "resourceId", "createdAt")`,
|
|
6004
|
+
args: []
|
|
6005
|
+
}
|
|
6006
|
+
],
|
|
6007
|
+
"write"
|
|
6008
|
+
);
|
|
5973
6009
|
if (omSchema) {
|
|
5974
6010
|
await this.#client.execute({
|
|
5975
6011
|
sql: `CREATE INDEX IF NOT EXISTS idx_om_lookup_key ON "${OM_TABLE}" ("lookupKey")`,
|
|
@@ -11403,10 +11439,15 @@ var WorkspacesLibSQL = class extends storage.WorkspacesStorage {
|
|
|
11403
11439
|
};
|
|
11404
11440
|
|
|
11405
11441
|
// src/storage/index.ts
|
|
11442
|
+
var DEFAULT_LOCAL_CACHE_SIZE = -16e3;
|
|
11443
|
+
var DEFAULT_LOCAL_MMAP_SIZE = 134217728;
|
|
11406
11444
|
var LibSQLStore = class extends storage.MastraCompositeStore {
|
|
11407
11445
|
client;
|
|
11408
11446
|
maxRetries;
|
|
11409
11447
|
initialBackoffMs;
|
|
11448
|
+
pragmasReady;
|
|
11449
|
+
isLocalDb;
|
|
11450
|
+
localPragmas;
|
|
11410
11451
|
stores;
|
|
11411
11452
|
constructor(config) {
|
|
11412
11453
|
if (!config.id || typeof config.id !== "string" || config.id.trim() === "") {
|
|
@@ -11415,20 +11456,24 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
|
|
|
11415
11456
|
super({ id: config.id, name: `LibSQLStore`, disableInit: config.disableInit });
|
|
11416
11457
|
this.maxRetries = config.maxRetries ?? 5;
|
|
11417
11458
|
this.initialBackoffMs = config.initialBackoffMs ?? 100;
|
|
11459
|
+
this.localPragmas = {
|
|
11460
|
+
cacheSize: config.localPragmas?.cacheSize ?? DEFAULT_LOCAL_CACHE_SIZE,
|
|
11461
|
+
mmapSize: config.localPragmas?.mmapSize ?? DEFAULT_LOCAL_MMAP_SIZE
|
|
11462
|
+
};
|
|
11418
11463
|
if ("url" in config) {
|
|
11419
|
-
if (config.url.
|
|
11464
|
+
if (config.url.includes(":memory:")) {
|
|
11420
11465
|
this.shouldCacheInit = false;
|
|
11421
11466
|
}
|
|
11422
11467
|
this.client = client.createClient({
|
|
11423
11468
|
url: config.url,
|
|
11424
11469
|
...config.authToken ? { authToken: config.authToken } : {}
|
|
11425
11470
|
});
|
|
11426
|
-
|
|
11427
|
-
|
|
11428
|
-
this.client.execute("PRAGMA busy_timeout = 5000;").then(() => this.logger.debug("LibSQLStore: PRAGMA busy_timeout=5000 set.")).catch((err) => this.logger.warn("LibSQLStore: Failed to set PRAGMA busy_timeout.", err));
|
|
11429
|
-
}
|
|
11471
|
+
this.isLocalDb = config.url.startsWith("file:") || config.url.includes(":memory:");
|
|
11472
|
+
this.pragmasReady = this.isLocalDb ? this.applyLocalPragmas() : Promise.resolve();
|
|
11430
11473
|
} else {
|
|
11431
11474
|
this.client = config.client;
|
|
11475
|
+
this.isLocalDb = false;
|
|
11476
|
+
this.pragmasReady = Promise.resolve();
|
|
11432
11477
|
}
|
|
11433
11478
|
const domainConfig = {
|
|
11434
11479
|
client: this.client,
|
|
@@ -11472,6 +11517,63 @@ var LibSQLStore = class extends storage.MastraCompositeStore {
|
|
|
11472
11517
|
schedules
|
|
11473
11518
|
};
|
|
11474
11519
|
}
|
|
11520
|
+
async applyLocalPragmas() {
|
|
11521
|
+
const pragmas = [
|
|
11522
|
+
["journal_mode=WAL", "PRAGMA journal_mode=WAL;"],
|
|
11523
|
+
["busy_timeout=5000", "PRAGMA busy_timeout=5000;"],
|
|
11524
|
+
["synchronous=NORMAL", "PRAGMA synchronous=NORMAL;"],
|
|
11525
|
+
["temp_store=MEMORY", "PRAGMA temp_store=MEMORY;"],
|
|
11526
|
+
[`cache_size=${this.localPragmas.cacheSize}`, `PRAGMA cache_size=${this.localPragmas.cacheSize};`],
|
|
11527
|
+
[`mmap_size=${this.localPragmas.mmapSize}`, `PRAGMA mmap_size=${this.localPragmas.mmapSize};`]
|
|
11528
|
+
];
|
|
11529
|
+
for (const [label, sql] of pragmas) {
|
|
11530
|
+
try {
|
|
11531
|
+
await this.client.execute(sql);
|
|
11532
|
+
this.logger.debug(`LibSQLStore: PRAGMA ${label} set.`);
|
|
11533
|
+
} catch (err) {
|
|
11534
|
+
this.logger.warn(`LibSQLStore: Failed to set PRAGMA ${label}.`, err);
|
|
11535
|
+
}
|
|
11536
|
+
}
|
|
11537
|
+
}
|
|
11538
|
+
getStoresToInit() {
|
|
11539
|
+
return Object.values(this.stores).filter(Boolean);
|
|
11540
|
+
}
|
|
11541
|
+
async initDomainsSequentially() {
|
|
11542
|
+
for (const store of this.getStoresToInit()) {
|
|
11543
|
+
await store.init();
|
|
11544
|
+
}
|
|
11545
|
+
return true;
|
|
11546
|
+
}
|
|
11547
|
+
async initDomainsInParallel() {
|
|
11548
|
+
await Promise.all(this.getStoresToInit().map((store) => store.init()));
|
|
11549
|
+
return true;
|
|
11550
|
+
}
|
|
11551
|
+
async init() {
|
|
11552
|
+
await this.pragmasReady;
|
|
11553
|
+
if (!this.isLocalDb) {
|
|
11554
|
+
if (this.shouldCacheInit) {
|
|
11555
|
+
if (this.hasInitialized) {
|
|
11556
|
+
await this.hasInitialized;
|
|
11557
|
+
return;
|
|
11558
|
+
}
|
|
11559
|
+
this.hasInitialized = this.initDomainsInParallel();
|
|
11560
|
+
await this.hasInitialized;
|
|
11561
|
+
return;
|
|
11562
|
+
}
|
|
11563
|
+
await this.initDomainsInParallel();
|
|
11564
|
+
return;
|
|
11565
|
+
}
|
|
11566
|
+
if (this.shouldCacheInit) {
|
|
11567
|
+
if (this.hasInitialized) {
|
|
11568
|
+
await this.hasInitialized;
|
|
11569
|
+
return;
|
|
11570
|
+
}
|
|
11571
|
+
this.hasInitialized = this.initDomainsSequentially();
|
|
11572
|
+
await this.hasInitialized;
|
|
11573
|
+
return;
|
|
11574
|
+
}
|
|
11575
|
+
await this.initDomainsSequentially();
|
|
11576
|
+
}
|
|
11475
11577
|
};
|
|
11476
11578
|
|
|
11477
11579
|
// src/vector/prompt.ts
|