@mastra/libsql 1.10.1-alpha.0 → 1.10.1-alpha.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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/libsql
2
2
 
3
+ ## 1.10.1-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - **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))
8
+
9
+ - Updated dependencies [[`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066)]:
10
+ - @mastra/core@1.33.0-alpha.7
11
+
3
12
  ## 1.10.1-alpha.0
4
13
 
5
14
  ### 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.10.1-alpha.0"
6
+ version: "1.10.1-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.10.1-alpha.0",
2
+ "version": "1.10.1-alpha.1",
3
3
  "package": "@mastra/libsql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -121,26 +121,88 @@ Each vector store page below includes installation instructions, configuration p
121
121
 
122
122
  ## Recall configuration
123
123
 
124
- The three main parameters that control semantic recall behavior are:
124
+ The following options control semantic recall behavior:
125
125
 
126
- 1. **topK**: How many semantically similar messages to retrieve
127
- 2. **messageRange**: How much surrounding context to include with each match
128
- 3. **scope**: Whether to search within the current thread or across all threads owned by a resource (the default is resource scope).
126
+ 1. **topK**: The number of similar messages to retrieve
127
+ 2. **messageRange**: The surrounding messages to include with each match
128
+ 3. **scope**: Whether to search the current thread or all threads for a resource
129
+ 4. **filter**: Metadata criteria that restrict search results
129
130
 
130
131
  ```typescript
131
132
  const agent = new Agent({
132
133
  memory: new Memory({
133
134
  options: {
134
135
  semanticRecall: {
135
- topK: 3, // Retrieve 3 most similar messages
136
+ topK: 3, // Retrieve 3 similar messages
136
137
  messageRange: 2, // Include 2 messages before and after each match
137
- scope: 'resource', // Search across all threads for this user (default setting if omitted)
138
+ scope: 'resource', // Search all threads for this resource
139
+ filter: { projectId: { $eq: 'project-a' } },
138
140
  },
139
141
  },
140
142
  }),
141
143
  })
142
144
  ```
143
145
 
146
+ > **Note:** `scope: 'resource'` is supported by the LibSQL, PostgreSQL, and Upstash storage adapters.
147
+
148
+ ### Metadata filtering
149
+
150
+ The `filter` option restricts semantic recall results to messages with matching thread metadata.
151
+
152
+ ```typescript
153
+ const agent = new Agent({
154
+ memory: new Memory({
155
+ options: {
156
+ semanticRecall: {
157
+ scope: 'resource',
158
+ filter: {
159
+ projectId: { $eq: 'project-a' },
160
+ category: { $in: ['work', 'personal'] },
161
+ },
162
+ },
163
+ },
164
+ }),
165
+ })
166
+ ```
167
+
168
+ Filters match metadata stored on message embeddings when messages are saved. If thread metadata changes later, existing embeddings keep their previous metadata until those messages are saved or indexed again.
169
+
170
+ Supported filter operators:
171
+
172
+ - `$and`: Logical AND
173
+ - `$eq`: Equal to
174
+ - `$gt`: Greater than
175
+ - `$gte`: Greater than or equal
176
+ - `$in`: In array
177
+ - `$lt`: Less than
178
+ - `$lte`: Less than or equal
179
+ - `$ne`: Not equal to
180
+ - `$nin`: Not in array
181
+ - `$or`: Logical OR
182
+
183
+ The following example demonstrates metadata filters for common use cases:
184
+
185
+ ```typescript
186
+ // Filter by project
187
+ const options = {
188
+ semanticRecall: { filter: { projectId: { $eq: 'my-project' } } },
189
+ }
190
+
191
+ // Filter by multiple categories
192
+ const options = {
193
+ semanticRecall: { filter: { category: { $in: ['work', 'research'] } } },
194
+ }
195
+
196
+ // Filter by project and priority
197
+ const options = {
198
+ semanticRecall: {
199
+ filter: {
200
+ $and: [{ projectId: { $eq: 'project-a' } }, { priority: { $gte: 3 } }],
201
+ },
202
+ },
203
+ }
204
+ ```
205
+
144
206
  ## Embedder configuration
145
207
 
146
208
  Semantic recall relies on an [embedding model](https://mastra.ai/reference/memory/memory-class) to convert messages into embeddings. Mastra supports embedding models through the model router using `provider/model` strings, or you can use any [embedding model](https://sdk.vercel.ai/docs/ai-sdk-core/embeddings) compatible with the AI SDK.
package/dist/index.cjs CHANGED
@@ -1172,6 +1172,33 @@ var LibSQLVector = class extends vector.MastraVector {
1172
1172
  });
1173
1173
  }
1174
1174
  };
1175
+ var safeStringify = (value) => {
1176
+ const seen = /* @__PURE__ */ new WeakSet();
1177
+ const sanitize = (val) => {
1178
+ if (val === null || val === void 0) return val;
1179
+ if (typeof val === "function") return void 0;
1180
+ if (typeof val === "symbol") return void 0;
1181
+ if (typeof val === "bigint") return val.toString();
1182
+ if (typeof val !== "object") return val;
1183
+ if (seen.has(val)) return void 0;
1184
+ seen.add(val);
1185
+ if (typeof val.toJSON === "function") {
1186
+ return sanitize(val.toJSON());
1187
+ }
1188
+ if (Array.isArray(val)) {
1189
+ return val.map((item) => sanitize(item));
1190
+ }
1191
+ const result = {};
1192
+ for (const key of Object.keys(val)) {
1193
+ const sanitized = sanitize(val[key]);
1194
+ if (sanitized !== void 0) {
1195
+ result[key] = sanitized;
1196
+ }
1197
+ }
1198
+ return result;
1199
+ };
1200
+ return JSON.stringify(sanitize(value)) ?? "null";
1201
+ };
1175
1202
  function buildSelectColumns(tableName) {
1176
1203
  const schema = storage.TABLE_SCHEMAS[tableName];
1177
1204
  return Object.keys(schema).map((col) => {
@@ -1238,12 +1265,12 @@ function prepareStatement({ tableName, record }) {
1238
1265
  }
1239
1266
  const colDef = schema[col];
1240
1267
  if (colDef?.type === "jsonb") {
1241
- return JSON.stringify(v);
1268
+ return safeStringify(v);
1242
1269
  }
1243
1270
  if (v instanceof Date) {
1244
1271
  return v.toISOString();
1245
1272
  }
1246
- return typeof v === "object" ? JSON.stringify(v) : v;
1273
+ return typeof v === "object" ? safeStringify(v) : v;
1247
1274
  });
1248
1275
  const placeholders = columnNames.map((col) => {
1249
1276
  const colDef = schema[col];
@@ -1286,12 +1313,12 @@ function transformToSqlValue(value, forceJsonStringify = false) {
1286
1313
  return null;
1287
1314
  }
1288
1315
  if (forceJsonStringify) {
1289
- return JSON.stringify(value);
1316
+ return safeStringify(value);
1290
1317
  }
1291
1318
  if (value instanceof Date) {
1292
1319
  return value.toISOString();
1293
1320
  }
1294
- return typeof value === "object" ? JSON.stringify(value) : value;
1321
+ return typeof value === "object" ? safeStringify(value) : value;
1295
1322
  }
1296
1323
  function prepareDeleteStatement({ tableName, keys }) {
1297
1324
  const parsedTableName = utils.parseSqlIdentifier(tableName, "table name");
@@ -10607,7 +10634,7 @@ var WorkflowsLibSQL = class extends storage.WorkflowsStorage {
10607
10634
  VALUES (?, ?, jsonb(?), ?, ?)
10608
10635
  ON CONFLICT(workflow_name, run_id)
10609
10636
  DO UPDATE SET snapshot = excluded.snapshot, updatedAt = excluded.updatedAt`,
10610
- args: [workflowName, runId, JSON.stringify(snapshot), now, now]
10637
+ args: [workflowName, runId, safeStringify(snapshot), now, now]
10611
10638
  });
10612
10639
  await tx.commit();
10613
10640
  return snapshot.context;
@@ -10644,7 +10671,7 @@ var WorkflowsLibSQL = class extends storage.WorkflowsStorage {
10644
10671
  const updatedSnapshot = { ...snapshot, ...opts };
10645
10672
  await tx.execute({
10646
10673
  sql: `UPDATE ${storage.TABLE_WORKFLOW_SNAPSHOT} SET snapshot = jsonb(?) WHERE workflow_name = ? AND run_id = ?`,
10647
- args: [JSON.stringify(updatedSnapshot), workflowName, runId]
10674
+ args: [safeStringify(updatedSnapshot), workflowName, runId]
10648
10675
  });
10649
10676
  await tx.commit();
10650
10677
  return updatedSnapshot;