@mastra/mssql 1.4.1 → 1.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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +33 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +13 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/mssql
|
|
2
2
|
|
|
3
|
+
## 1.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
|
## 1.4.1
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2292,6 +2292,32 @@ var BackgroundTasksMSSQL = class _BackgroundTasksMSSQL extends storage.Backgroun
|
|
|
2292
2292
|
return Number(result.recordset[0]?.count ?? 0);
|
|
2293
2293
|
}
|
|
2294
2294
|
};
|
|
2295
|
+
function bindMssqlMetadataParams(request, params) {
|
|
2296
|
+
for (const [paramName, paramValue] of Object.entries(params)) {
|
|
2297
|
+
request.input(paramName, paramValue);
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
function buildMssqlMessageMetadataFilter(metadataFilter) {
|
|
2301
|
+
if (!metadataFilter) return { clauses: [], params: {} };
|
|
2302
|
+
const clauses = [];
|
|
2303
|
+
const params = {};
|
|
2304
|
+
Object.entries(metadataFilter).forEach(([key, value], index) => {
|
|
2305
|
+
const keyParam = `metadataKey${index}`;
|
|
2306
|
+
params[keyParam] = key;
|
|
2307
|
+
clauses.push("ISJSON(content) = 1");
|
|
2308
|
+
if (value === null) {
|
|
2309
|
+
clauses.push(`EXISTS (SELECT 1 FROM OPENJSON(content, '$.metadata') WHERE [key] = @${keyParam} AND [type] = 0)`);
|
|
2310
|
+
return;
|
|
2311
|
+
}
|
|
2312
|
+
const valueParam = `metadataValue${index}`;
|
|
2313
|
+
params[valueParam] = String(value);
|
|
2314
|
+
const jsonType = typeof value === "string" ? 1 : typeof value === "number" ? 2 : 3;
|
|
2315
|
+
clauses.push(
|
|
2316
|
+
`EXISTS (SELECT 1 FROM OPENJSON(content, '$.metadata') WHERE [key] = @${keyParam} AND [type] = ${jsonType} AND [value] = @${valueParam})`
|
|
2317
|
+
);
|
|
2318
|
+
});
|
|
2319
|
+
return { clauses, params };
|
|
2320
|
+
}
|
|
2295
2321
|
var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
|
|
2296
2322
|
pool;
|
|
2297
2323
|
schema;
|
|
@@ -2851,6 +2877,7 @@ var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
|
|
|
2851
2877
|
}
|
|
2852
2878
|
async listMessages(args) {
|
|
2853
2879
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
2880
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
2854
2881
|
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
2855
2882
|
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
2856
2883
|
throw new error.MastraError(
|
|
@@ -2887,10 +2914,13 @@ var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
|
|
|
2887
2914
|
...resourceId ? { resourceId } : {},
|
|
2888
2915
|
...buildDateRangeFilter(filter?.dateRange, "createdAt")
|
|
2889
2916
|
};
|
|
2890
|
-
const { sql:
|
|
2917
|
+
const { sql: preparedWhereClause = "", params: whereParams } = prepareWhereClause(
|
|
2891
2918
|
filters);
|
|
2919
|
+
const metadataWhere = buildMssqlMessageMetadataFilter(metadataFilter);
|
|
2920
|
+
const actualWhereClause = metadataWhere.clauses.length ? `${preparedWhereClause || " WHERE 1 = 1"} AND ${metadataWhere.clauses.join(" AND ")}` : preparedWhereClause;
|
|
2892
2921
|
const bindWhereParams = (req) => {
|
|
2893
2922
|
Object.entries(whereParams).forEach(([paramName, paramValue]) => req.input(paramName, paramValue));
|
|
2923
|
+
bindMssqlMetadataParams(req, metadataWhere.params);
|
|
2894
2924
|
};
|
|
2895
2925
|
if (perPage === 0 && (!include || include.length === 0)) {
|
|
2896
2926
|
return { messages: [], total: 0, page, perPage: perPageForResponse, hasMore: false };
|
|
@@ -2926,6 +2956,7 @@ var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
|
|
|
2926
2956
|
};
|
|
2927
2957
|
const baseRows = perPage === 0 ? [] : await fetchBaseMessages();
|
|
2928
2958
|
const messages = [...baseRows];
|
|
2959
|
+
const primaryPageCount = messages.length;
|
|
2929
2960
|
const seqById = /* @__PURE__ */ new Map();
|
|
2930
2961
|
messages.forEach((msg) => {
|
|
2931
2962
|
if (typeof msg.seq_id === "number") seqById.set(msg.id, msg.seq_id);
|
|
@@ -2966,7 +2997,7 @@ var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
|
|
|
2966
2997
|
});
|
|
2967
2998
|
const threadIdSet = new Set(threadIds);
|
|
2968
2999
|
const returnedThreadMessageCount = finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).length;
|
|
2969
|
-
const hasMore = perPageInput !== false && returnedThreadMessageCount < total && offset + perPage < total;
|
|
3000
|
+
const hasMore = metadataFilter ? perPageInput !== false && offset + primaryPageCount < total : perPageInput !== false && returnedThreadMessageCount < total && offset + perPage < total;
|
|
2970
3001
|
return {
|
|
2971
3002
|
messages: finalMessages,
|
|
2972
3003
|
total,
|