@mastra/libsql 1.21.1 → 1.22.0-alpha.2

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 (48) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/dist/docs/SKILL.md +1 -1
  3. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  4. package/dist/docs/references/docs-deployment-workers.md +2 -2
  5. package/dist/docs/references/docs-storage.md +2 -0
  6. package/dist/docs/references/integrations-databases-libsql.md +16 -0
  7. package/dist/docs/references/reference-core-mastra-class.md +1 -1
  8. package/dist/index.cjs +31 -10
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +31 -10
  11. package/dist/index.js.map +1 -1
  12. package/dist/storage/db/client.d.ts +31 -0
  13. package/dist/storage/db/client.d.ts.map +1 -0
  14. package/dist/storage/db/index.d.ts +1 -1
  15. package/dist/storage/db/index.d.ts.map +1 -1
  16. package/dist/storage/db/utils.d.ts +1 -1
  17. package/dist/storage/db/utils.d.ts.map +1 -1
  18. package/dist/storage/db/write-lock.d.ts +2 -2
  19. package/dist/storage/db/write-lock.d.ts.map +1 -1
  20. package/dist/storage/domains/agents/index.d.ts.map +1 -1
  21. package/dist/storage/domains/background-tasks/index.d.ts +3 -1
  22. package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
  23. package/dist/storage/domains/blobs/index.d.ts.map +1 -1
  24. package/dist/storage/domains/channels/index.d.ts.map +1 -1
  25. package/dist/storage/domains/datasets/index.d.ts.map +1 -1
  26. package/dist/storage/domains/experiments/index.d.ts.map +1 -1
  27. package/dist/storage/domains/favorites/index.d.ts.map +1 -1
  28. package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
  29. package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -1
  30. package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -1
  31. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  32. package/dist/storage/domains/notifications/index.d.ts.map +1 -1
  33. package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -1
  34. package/dist/storage/domains/schedules/index.d.ts.map +1 -1
  35. package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -1
  36. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  37. package/dist/storage/domains/skills/index.d.ts.map +1 -1
  38. package/dist/storage/domains/thread-state/index.d.ts.map +1 -1
  39. package/dist/storage/domains/tool-provider-connections/index.d.ts.map +1 -1
  40. package/dist/storage/domains/utils.d.ts +1 -1
  41. package/dist/storage/domains/utils.d.ts.map +1 -1
  42. package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -1
  43. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  44. package/dist/storage/domains/workspaces/index.d.ts.map +1 -1
  45. package/dist/storage/factory-storage.d.ts.map +1 -1
  46. package/dist/storage/index.d.ts +12 -1
  47. package/dist/storage/index.d.ts.map +1 -1
  48. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,87 @@
1
1
  # @mastra/libsql
2
2
 
3
+ ## 1.22.0-alpha.2
4
+
5
+ ### Minor Changes
6
+
7
+ - Added embedded-replica sync support to LibSQLStore. You can now pass `syncUrl` and `syncInterval` to keep a local database file synced with a remote libSQL primary (for example Turso), matching the options LibSQLVector already supports. ([#22261](https://github.com/mastra-ai/mastra/pull/22261))
8
+
9
+ ```typescript
10
+ import { LibSQLStore } from '@mastra/libsql';
11
+
12
+ const storage = new LibSQLStore({
13
+ id: 'libsql-storage',
14
+ url: 'file:./replica.db',
15
+ syncUrl: 'libsql://your-db-name.turso.io',
16
+ authToken: process.env.TURSO_AUTH_TOKEN,
17
+ syncInterval: 60,
18
+ });
19
+ ```
20
+
21
+ See https://github.com/mastra-ai/mastra/issues/21994
22
+
23
+ ### Patch Changes
24
+
25
+ - Experiment results now include isolated metadata snapshots from the dataset items that ran. ([#22005](https://github.com/mastra-ai/mastra/pull/22005))
26
+
27
+ - Enforce atomic conditional background task state updates so cancellation cannot be overwritten during dispatch. Background task storage is no longer exposed by Cloudflare KV or ClickHouse, which cannot provide the required compare-and-set semantics. ([#22228](https://github.com/mastra-ai/mastra/pull/22228))
28
+
29
+ - Updated dependencies [[`aa3a85d`](https://github.com/mastra-ai/mastra/commit/aa3a85daf094c683bb97efdf4b6a696d2e474af5), [`d29d06f`](https://github.com/mastra-ai/mastra/commit/d29d06fe00bbd35b4571150ea04c59d2ed783c71), [`e6516df`](https://github.com/mastra-ai/mastra/commit/e6516dfcdae4f4ac0e7971d84359a81385ee602f), [`0b2a3d1`](https://github.com/mastra-ai/mastra/commit/0b2a3d1783875c5b97b7b36ab3d03d7360e0dde7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`57de7d6`](https://github.com/mastra-ai/mastra/commit/57de7d644ba7146edb4e9e6111ec4fa98c3a59e9), [`e8e299c`](https://github.com/mastra-ai/mastra/commit/e8e299cc6abdfc39947e2fec25803493015d3882), [`edfc548`](https://github.com/mastra-ai/mastra/commit/edfc548886bc7bae17b681f8b6b41a47eb32bcd2), [`a8a4871`](https://github.com/mastra-ai/mastra/commit/a8a4871215f51da95c47129602157ce5372f634a), [`5165cdc`](https://github.com/mastra-ai/mastra/commit/5165cdcdcf50e144bb8113278535196cc9b07065), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`9ee8120`](https://github.com/mastra-ai/mastra/commit/9ee8120ce17f76b9f617489e05a283353742690a), [`d975e92`](https://github.com/mastra-ai/mastra/commit/d975e924d4936f46c386bd3dee39c671720289f6), [`1cfa878`](https://github.com/mastra-ai/mastra/commit/1cfa8784d8da0dfaa0317e5048bc48b6084a5ea5), [`c118318`](https://github.com/mastra-ai/mastra/commit/c1183181c9804303db4b511c2e2648f8b714712b), [`fc07c64`](https://github.com/mastra-ai/mastra/commit/fc07c6465043e08e99193a6751a01c56ffc2e7a1), [`542dee2`](https://github.com/mastra-ai/mastra/commit/542dee254167f974ff8cbbbfc0ce10f9a2616a7b), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`895e9df`](https://github.com/mastra-ai/mastra/commit/895e9dfc17d6f34299eca64e317ded9e5f5e5ef8)]:
30
+ - @mastra/core@1.62.0-alpha.8
31
+
32
+ ## 1.22.0-alpha.1
33
+
34
+ ### Minor Changes
35
+
36
+ - Added a reusable SQLite client contract so storage adapters can use compatible SQLite drivers. ([#22181](https://github.com/mastra-ai/mastra/pull/22181))
37
+
38
+ ```typescript
39
+ import type { SqliteClient } from '@mastra/libsql';
40
+
41
+ const client: SqliteClient = createCompatibleSqliteClient();
42
+ ```
43
+
44
+ ### Patch Changes
45
+
46
+ - Added native Turso Database file storage for Mastra agents, workflows, memory, and other storage domains. ([#22181](https://github.com/mastra-ai/mastra/pull/22181))
47
+
48
+ ```typescript
49
+ import { TursoStore } from '@mastra/turso';
50
+
51
+ const storage = new TursoStore({
52
+ id: 'local-storage',
53
+ path: './mastra.db',
54
+ });
55
+ ```
56
+
57
+ - Updated dependencies [[`ae8790c`](https://github.com/mastra-ai/mastra/commit/ae8790c4bfaa088d2ab279d1dcc06f326b9fd109), [`04a815f`](https://github.com/mastra-ai/mastra/commit/04a815fc8971d29e97fcdcc5008a1eb472fc00ff), [`cced745`](https://github.com/mastra-ai/mastra/commit/cced745a056ec2225c5bc702e32d848847aa8b65)]:
58
+ - @mastra/core@1.62.0-alpha.7
59
+
60
+ ## 1.22.0-alpha.0
61
+
62
+ ### Minor Changes
63
+
64
+ - Added native application collection counts so totals no longer load matching rows. ([#22021](https://github.com/mastra-ai/mastra/pull/22021))
65
+
66
+ **Before**
67
+
68
+ ```ts
69
+ const total = (await storage.ops.findMany('jobs', { status: 'failed' })).length;
70
+ ```
71
+
72
+ **After**
73
+
74
+ ```ts
75
+ const total = await storage.ops.count?.('jobs', { status: 'failed' });
76
+ ```
77
+
78
+ ### Patch Changes
79
+
80
+ - Workflow snapshot upserts no longer overwrite a previously stored `resourceId` with NULL when a run is re-persisted without one (for example during resume). ([#22105](https://github.com/mastra-ai/mastra/pull/22105))
81
+
82
+ - Updated dependencies [[`2c85f42`](https://github.com/mastra-ai/mastra/commit/2c85f428e04ccd63ea31a7ec80b5b327afdad555), [`11bbeb9`](https://github.com/mastra-ai/mastra/commit/11bbeb9b108ef2264e05acefc6dafb9cbb342921), [`1a485f3`](https://github.com/mastra-ai/mastra/commit/1a485f3538f5ec64d58bd8b5e1e99de0c695c87b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`8661d7d`](https://github.com/mastra-ai/mastra/commit/8661d7d7179f0a024456aabdd8679bcecd09ac28), [`575e343`](https://github.com/mastra-ai/mastra/commit/575e343900451021d96110916497d334af7bc252), [`cacb839`](https://github.com/mastra-ai/mastra/commit/cacb8392d9e74189b56d857290b0615f98a2683d), [`b47b26e`](https://github.com/mastra-ai/mastra/commit/b47b26e6fe95cb8a3482be2c5e52de157fe59d0b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`c46eb09`](https://github.com/mastra-ai/mastra/commit/c46eb09ce4987509af57a0ac582c61241a6dd2f1), [`30ed33e`](https://github.com/mastra-ai/mastra/commit/30ed33ee14084a26019aba15fceadda6d6ddefaf), [`91ad69d`](https://github.com/mastra-ai/mastra/commit/91ad69d64994c89199b0c55399e64ed91c61df2f), [`8dc408d`](https://github.com/mastra-ai/mastra/commit/8dc408d34438f9e13297f792c11a5cfd6cf952e1), [`c92def1`](https://github.com/mastra-ai/mastra/commit/c92def10a13c822972c96f0a4ca6ffc1f4258aed), [`c5eaec5`](https://github.com/mastra-ai/mastra/commit/c5eaec5a860d80d0e3805e67db0414b87ac8cbed), [`e66b2ba`](https://github.com/mastra-ai/mastra/commit/e66b2ba100db63eaeab6e21e1ea34b113f2ec781)]:
83
+ - @mastra/core@1.62.0-alpha.3
84
+
3
85
  ## 1.21.1
4
86
 
5
87
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-libsql
3
3
  description: Documentation for @mastra/libsql. Use when working with @mastra/libsql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/libsql"
6
- version: "1.21.1"
6
+ version: "1.22.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.21.1",
2
+ "version": "1.22.0-alpha.2",
3
3
  "package": "@mastra/libsql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -29,7 +29,7 @@ Subscribes to workflow events on the [PubSub](https://mastra.ai/docs/server/pubs
29
29
 
30
30
  In a split deployment, the orchestration worker pulls events from a distributed PubSub backend and delegates step execution back to the API over HTTP. In-process, it runs steps directly.
31
31
 
32
- The orchestration worker requires a PubSub backend that supports pull mode (e.g., [`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams) or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)).
32
+ The orchestration worker requires a PubSub backend that supports pull mode (e.g., [`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams), [`ValkeyStreamsPubSub`](https://mastra.ai/reference/pubsub/valkey-streams), or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)).
33
33
 
34
34
  ### Scheduler worker
35
35
 
@@ -104,7 +104,7 @@ Any [supported storage backend](https://mastra.ai/reference/workers/overview) wo
104
104
 
105
105
  Run the same build artifact in multiple containers, each with a different [`MASTRA_WORKERS`](https://mastra.ai/reference/workers/overview) value to control which worker starts in each process.
106
106
 
107
- Split deployments require a distributed PubSub backend ([`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams) or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)), a shared [storage backend](https://mastra.ai/reference/workers/overview), and network connectivity between the orchestration worker and the API.
107
+ Split deployments require a distributed PubSub backend ([`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams), [`ValkeyStreamsPubSub`](https://mastra.ai/reference/pubsub/valkey-streams), or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)), a shared [storage backend](https://mastra.ai/reference/workers/overview), and network connectivity between the orchestration worker and the API.
108
108
 
109
109
  ### Select workers
110
110
 
@@ -197,6 +197,7 @@ Each provider page includes installation instructions, configuration parameters,
197
197
  - [Convex](https://mastra.ai/integrations/databases/convex)
198
198
  - [DuckDB](https://mastra.ai/integrations/databases/duckdb)
199
199
  - [DynamoDB](https://mastra.ai/integrations/databases/dynamodb)
200
+ - [Elasticsearch](https://mastra.ai/integrations/databases/elasticsearch)
200
201
  - [Google Cloud Spanner](https://mastra.ai/integrations/databases/spanner)
201
202
  - [LanceDB](https://mastra.ai/integrations/databases/lancedb)
202
203
  - [libSQL](https://mastra.ai/integrations/databases/libsql)
@@ -207,6 +208,7 @@ Each provider page includes installation instructions, configuration parameters,
207
208
  - [OracleDB](https://mastra.ai/integrations/databases/oracledb)
208
209
  - [PostgreSQL](https://mastra.ai/integrations/databases/postgresql)
209
210
  - [Redis](https://mastra.ai/integrations/databases/redis)
211
+ - [Valkey](https://mastra.ai/integrations/databases/valkey)
210
212
  - [Upstash](https://mastra.ai/integrations/databases/upstash)
211
213
 
212
214
  ## Next steps
@@ -89,12 +89,28 @@ storage: new LibSQLStore({
89
89
 
90
90
  > **Warning:** In-memory storage resets when the process changes. Only suitable for development.
91
91
 
92
+ Embedded replica synced with a remote primary (for example Turso):
93
+
94
+ ```typescript
95
+ storage: new LibSQLStore({
96
+ id: 'libsql-storage',
97
+ url: 'file:./replica.db',
98
+ syncUrl: 'libsql://your-db-name.aws-ap-northeast-1.turso.io',
99
+ authToken: process.env.TURSO_AUTH_TOKEN,
100
+ syncInterval: 60,
101
+ })
102
+ ```
103
+
92
104
  ## Options
93
105
 
94
106
  **url** (`string`): Database URL. Use :memory: for in-memory database, file:filename.db for a file database, or a libSQL connection string (e.g., libsql://your-database.turso.io) for remote storage.
95
107
 
96
108
  **authToken** (`string`): Authentication token for remote libSQL databases.
97
109
 
110
+ **syncUrl** (`string`): URL of the remote primary database to sync from, enabling an embedded replica. Requires a local file: url.
111
+
112
+ **syncInterval** (`number`): Interval in seconds for automatic sync with the remote primary. Only applies when syncUrl is set.
113
+
98
114
  ## Managed tables
99
115
 
100
116
  The storage implementation creates the core storage tables automatically, including `mastra_notifications` for notification inbox records and delivery metadata.
@@ -79,7 +79,7 @@ Visit the [Configuration reference](https://mastra.ai/reference/configuration) f
79
79
 
80
80
  **bundler** (`BundlerConfig`): Configuration for the asset bundler with options for externals, sourcemap, transpilePackages, and dynamicPackages. (Default: `{ externals: [], sourcemap: false, transpilePackages: [], dynamicPackages: [] }`)
81
81
 
82
- **scorers** (`Record<string, Scorer>`): Scorers for evaluating agent responses and workflow outputs (Default: `{}`)
82
+ **scorers** (`Record<string, Scorer>`): Scorers for evaluating agent responses and workflow outputs. Registration also makes a scorer resolvable by ID, which is required to persist its scores. See Score persistence (Default: `{}`)
83
83
 
84
84
  **processors** (`Record<string, Processor>`): Input/output processors for transforming agent inputs and outputs (Default: `{}`)
85
85
 
package/dist/index.cjs CHANGED
@@ -2967,7 +2967,7 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends _mastra_core_sto
2967
2967
  }
2968
2968
  });
2969
2969
  }
2970
- async updateTask(taskId, update) {
2970
+ async updateTask(taskId, update, options) {
2971
2971
  const setClauses = [];
2972
2972
  const params = [];
2973
2973
  if ("status" in update) {
@@ -3002,12 +3002,17 @@ var BackgroundTasksLibSQL = class BackgroundTasksLibSQL extends _mastra_core_sto
3002
3002
  setClauses.push("completedAt = ?");
3003
3003
  params.push(update.completedAt?.toISOString() ?? null);
3004
3004
  }
3005
- if (setClauses.length === 0) return;
3005
+ if (setClauses.length === 0) return false;
3006
3006
  params.push(taskId);
3007
- await this.#client.execute({
3008
- sql: `UPDATE ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} SET ${setClauses.join(", ")} WHERE id = ?`,
3007
+ let where = "id = ?";
3008
+ if (options?.expectedStatus) {
3009
+ where += " AND status = ?";
3010
+ params.push(options.expectedStatus);
3011
+ }
3012
+ return (await this.#client.execute({
3013
+ sql: `UPDATE ${_mastra_core_storage.TABLE_BACKGROUND_TASKS} SET ${setClauses.join(", ")} WHERE ${where}`,
3009
3014
  args: params
3010
- });
3015
+ })).rowsAffected > 0;
3011
3016
  }
3012
3017
  async getTask(taskId) {
3013
3018
  const row = (await this.#client.execute({
@@ -4617,6 +4622,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
4617
4622
  "tags",
4618
4623
  "comment",
4619
4624
  "toolMockReport",
4625
+ "metadata",
4620
4626
  "organizationId",
4621
4627
  "projectId",
4622
4628
  "attempt"
@@ -4763,6 +4769,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
4763
4769
  input: (0, _mastra_core_storage.safelyParseJSON)(row.input),
4764
4770
  output: row.output ? (0, _mastra_core_storage.safelyParseJSON)(row.output) : null,
4765
4771
  groundTruth: row.groundTruth ? (0, _mastra_core_storage.safelyParseJSON)(row.groundTruth) : null,
4772
+ metadata: row.metadata ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : null,
4766
4773
  error: row.error ? (0, _mastra_core_storage.safelyParseJSON)(row.error) : null,
4767
4774
  startedAt: (0, _mastra_core_storage.ensureDate)(row.startedAt),
4768
4775
  completedAt: (0, _mastra_core_storage.ensureDate)(row.completedAt),
@@ -5065,6 +5072,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
5065
5072
  input: input.input,
5066
5073
  output: input.output,
5067
5074
  groundTruth: input.groundTruth,
5075
+ metadata: input.metadata ?? null,
5068
5076
  error: input.error ?? null,
5069
5077
  startedAt: input.startedAt.toISOString(),
5070
5078
  completedAt: input.completedAt.toISOString(),
@@ -5087,6 +5095,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
5087
5095
  input: input.input,
5088
5096
  output: input.output,
5089
5097
  groundTruth: input.groundTruth,
5098
+ metadata: input.metadata ?? null,
5090
5099
  error: input.error,
5091
5100
  startedAt: input.startedAt,
5092
5101
  completedAt: input.completedAt,
@@ -5141,7 +5150,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
5141
5150
  await this.#client.execute({
5142
5151
  sql: `UPDATE ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} SET
5143
5152
  "itemDatasetVersion" = ?, "organizationId" = ?, "projectId" = ?,
5144
- "input" = ?, "output" = ?, "groundTruth" = ?, "error" = ?,
5153
+ "input" = ?, "output" = ?, "groundTruth" = ?, "metadata" = ?, "error" = ?,
5145
5154
  "startedAt" = ?, "completedAt" = ?, "retryCount" = ?, "attempt" = ?,
5146
5155
  "traceId" = ?, "status" = ?, "tags" = ?, "toolMockReport" = ?
5147
5156
  WHERE "id" = ?`,
@@ -5152,6 +5161,7 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
5152
5161
  JSON.stringify(input.input),
5153
5162
  input.output != null ? JSON.stringify(input.output) : null,
5154
5163
  input.groundTruth != null ? JSON.stringify(input.groundTruth) : null,
5164
+ input.metadata != null ? JSON.stringify(input.metadata) : null,
5155
5165
  input.error != null ? JSON.stringify(input.error) : null,
5156
5166
  input.startedAt.toISOString(),
5157
5167
  input.completedAt.toISOString(),
@@ -13055,7 +13065,7 @@ var WorkflowsLibSQL = class WorkflowsLibSQL extends _mastra_core_storage.Workflo
13055
13065
  sql: `INSERT INTO ${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT} (workflow_name, run_id, resourceId, snapshot, createdAt, updatedAt)
13056
13066
  VALUES (?, ?, ?, jsonb(?), ?, ?)
13057
13067
  ON CONFLICT(workflow_name, run_id)
13058
- DO UPDATE SET resourceId = excluded.resourceId, snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
13068
+ DO UPDATE SET resourceId = COALESCE(excluded.resourceId, ${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}.resourceId), snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
13059
13069
  args: [
13060
13070
  workflowName,
13061
13071
  runId,
@@ -13855,6 +13865,15 @@ var LibSQLFactoryStorageOps = class {
13855
13865
  async findMany(collection, where, opts) {
13856
13866
  return this.#select(collection, where, opts);
13857
13867
  }
13868
+ async count(collection, where) {
13869
+ const schema = this.#schema(collection);
13870
+ const filter = this.#buildWhere(schema, where);
13871
+ const result = await this.#client.execute({
13872
+ sql: `SELECT COUNT(*) AS count FROM "${schema.name}" WHERE ${filter.sql}`,
13873
+ args: filter.args
13874
+ });
13875
+ return Number(result.rows[0]?.count ?? 0);
13876
+ }
13858
13877
  async #insertOne(collection, row) {
13859
13878
  const schema = this.#schema(collection);
13860
13879
  const pk = primaryKeyOf(schema);
@@ -14004,7 +14023,7 @@ var LibSQLFactoryStorage = class extends _mastra_core_storage.FactoryStorage {
14004
14023
  });
14005
14024
  }
14006
14025
  async close() {
14007
- this.#client.close();
14026
+ await this.#client.close();
14008
14027
  }
14009
14028
  authDatabase() {
14010
14029
  return {
@@ -14124,10 +14143,12 @@ var LibSQLStore = class extends _mastra_core_storage.MastraCompositeStore {
14124
14143
  };
14125
14144
  if ("url" in config) {
14126
14145
  if (config.url.includes(":memory:")) this.shouldCacheInit = false;
14127
- this.isLocalDb = config.url.startsWith("file:") || config.url.includes(":memory:");
14146
+ this.isLocalDb = (config.url.startsWith("file:") || config.url.includes(":memory:")) && !config.syncUrl;
14128
14147
  this.client = (0, _libsql_client.createClient)({
14129
14148
  url: config.url,
14130
14149
  ...config.authToken ? { authToken: config.authToken } : {},
14150
+ ...config.syncUrl ? { syncUrl: config.syncUrl } : {},
14151
+ ...config.syncInterval !== void 0 ? { syncInterval: config.syncInterval } : {},
14131
14152
  ...this.isLocalDb ? { timeout: this.connectionTimeoutMs } : {}
14132
14153
  });
14133
14154
  this.pragmasReady = this.isLocalDb ? this.applyLocalPragmas() : Promise.resolve();
@@ -14251,7 +14272,7 @@ var LibSQLStore = class extends _mastra_core_storage.MastraCompositeStore {
14251
14272
  * Safe to call more than once; subsequent calls are no-ops.
14252
14273
  */
14253
14274
  async close() {
14254
- if (!this.client.closed) this.client.close();
14275
+ if (!this.client.closed) await this.client.close();
14255
14276
  }
14256
14277
  };
14257
14278
  //#endregion