@mastra/mysql 0.4.0 → 0.5.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/index.cjs +21 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/mysql
|
|
2
2
|
|
|
3
|
+
## 0.5.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added exact metadata filtering to message history queries across Memory APIs and supported storage providers. ([#19991](https://github.com/mastra-ai/mastra/pull/19991))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const messages = await memory.recall({
|
|
11
|
+
threadId: 'thread-1',
|
|
12
|
+
filter: {
|
|
13
|
+
metadata: {
|
|
14
|
+
status: 'done',
|
|
15
|
+
priority: 'high',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Multiple fields use AND semantics. Supported values are strings, finite numbers, booleans, and `null`.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`0dca9d0`](https://github.com/mastra-ai/mastra/commit/0dca9d0b1356024a53b72ea6f040db528b126caa)]:
|
|
26
|
+
- @mastra/core@1.54.0-alpha.0
|
|
27
|
+
|
|
3
28
|
## 0.4.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -5216,6 +5216,22 @@ function parseJSON3(value) {
|
|
|
5216
5216
|
return null;
|
|
5217
5217
|
}
|
|
5218
5218
|
}
|
|
5219
|
+
function addMySQLMessageMetadataFilter(conditions, params, metadataFilter) {
|
|
5220
|
+
if (!metadataFilter) return;
|
|
5221
|
+
for (const [key, value] of Object.entries(metadataFilter)) {
|
|
5222
|
+
const path = `$.metadata.${key}`;
|
|
5223
|
+
conditions.push(`JSON_VALID(${quoteIdentifier("content", "column name")})`);
|
|
5224
|
+
conditions.push(`JSON_CONTAINS_PATH(${quoteIdentifier("content", "column name")}, 'one', ?)`);
|
|
5225
|
+
params.push(path);
|
|
5226
|
+
if (value === null) {
|
|
5227
|
+
conditions.push(`JSON_TYPE(JSON_EXTRACT(${quoteIdentifier("content", "column name")}, ?)) = 'NULL'`);
|
|
5228
|
+
params.push(path);
|
|
5229
|
+
} else {
|
|
5230
|
+
conditions.push(`JSON_EXTRACT(${quoteIdentifier("content", "column name")}, ?) = CAST(? AS JSON)`);
|
|
5231
|
+
params.push(path, JSON.stringify(value));
|
|
5232
|
+
}
|
|
5233
|
+
}
|
|
5234
|
+
}
|
|
5219
5235
|
var MemoryMySQL = class _MemoryMySQL extends storage.MemoryStorage {
|
|
5220
5236
|
supportsObservationalMemory = true;
|
|
5221
5237
|
pool;
|
|
@@ -6071,6 +6087,7 @@ var MemoryMySQL = class _MemoryMySQL extends storage.MemoryStorage {
|
|
|
6071
6087
|
const { threadId, resourceId, filter, orderBy, page = 0, perPage: perPageInput } = args;
|
|
6072
6088
|
const selectBy = args.selectBy;
|
|
6073
6089
|
const include = args.include ?? selectBy?.include;
|
|
6090
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
6074
6091
|
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
6075
6092
|
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
6076
6093
|
throw emitValidationError("threadId must be a non-empty string or array of non-empty strings");
|
|
@@ -6117,6 +6134,7 @@ var MemoryMySQL = class _MemoryMySQL extends storage.MemoryStorage {
|
|
|
6117
6134
|
conditions.push(`${quoteIdentifier("createdAt", "column name")} ${endOp} ?`);
|
|
6118
6135
|
params.push(transformToSqlValue(filter.dateRange.end));
|
|
6119
6136
|
}
|
|
6137
|
+
addMySQLMessageMetadataFilter(conditions, params, metadataFilter);
|
|
6120
6138
|
if (selectBy?.vectorSearchString) {
|
|
6121
6139
|
conditions.push(`${quoteIdentifier("content", "column name")} LIKE ?`);
|
|
6122
6140
|
params.push(`%${selectBy.vectorSearchString}%`);
|
|
@@ -6198,7 +6216,7 @@ var MemoryMySQL = class _MemoryMySQL extends storage.MemoryStorage {
|
|
|
6198
6216
|
const mainThreadMessageCount = messages.filter(
|
|
6199
6217
|
(msg) => msg.threadId !== void 0 && threadIdSet.has(msg.threadId)
|
|
6200
6218
|
).length;
|
|
6201
|
-
const hasMore =
|
|
6219
|
+
const hasMore = metadataFilter || !include?.length || mainThreadMessageCount < total ? baseHasMore : false;
|
|
6202
6220
|
return {
|
|
6203
6221
|
messages,
|
|
6204
6222
|
total,
|
|
@@ -6227,6 +6245,7 @@ var MemoryMySQL = class _MemoryMySQL extends storage.MemoryStorage {
|
|
|
6227
6245
|
}
|
|
6228
6246
|
async listMessagesByResourceId(args) {
|
|
6229
6247
|
const { resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
6248
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
6230
6249
|
if (!resourceId || typeof resourceId !== "string" || resourceId.trim().length === 0) {
|
|
6231
6250
|
throw new error.MastraError(
|
|
6232
6251
|
{
|
|
@@ -6267,6 +6286,7 @@ var MemoryMySQL = class _MemoryMySQL extends storage.MemoryStorage {
|
|
|
6267
6286
|
conditions.push(`${quoteIdentifier("createdAt", "column name")} ${endOp} ?`);
|
|
6268
6287
|
params.push(transformToSqlValue(filter.dateRange.end));
|
|
6269
6288
|
}
|
|
6289
|
+
addMySQLMessageMetadataFilter(conditions, params, metadataFilter);
|
|
6270
6290
|
const whereSql = `WHERE ${conditions.join(" AND ")}`;
|
|
6271
6291
|
const tableName = formatTableName(storage.TABLE_MESSAGES);
|
|
6272
6292
|
const [countRows] = await this.pool.execute(
|