@mastra/mssql 1.4.1-alpha.0 → 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 +62 -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,67 @@
|
|
|
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
|
+
|
|
28
|
+
## 1.4.1
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Add optional `batchId`, `datasetId`, and `datasetItemId` fields to persisted scores so saved baseline scores can be grouped as one scoring pass and joined back to the dataset items they came from. ([#18331](https://github.com/mastra-ai/mastra/pull/18331))
|
|
33
|
+
- `scoreTrace()` accepts top-level `batchId`, `datasetId`, and `datasetItemId` when persisting a score for a stored trace.
|
|
34
|
+
- `ScoreRowData` and score save payloads now include nullable `batchId`, `datasetId`, and `datasetItemId`.
|
|
35
|
+
- Built-in stores with explicit score schema or attribute mappings now persist these provenance fields on saved scores.
|
|
36
|
+
- D1, DSQL, MSSQL, and Upstash score stores now apply additive provenance migrations or deterministic score ordering for persisted score reads.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
await scoreTrace({
|
|
40
|
+
storage,
|
|
41
|
+
scorer,
|
|
42
|
+
target: { traceId },
|
|
43
|
+
batchId: 'baseline-batch-1',
|
|
44
|
+
datasetId,
|
|
45
|
+
datasetItemId,
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Added optional `organizationId` and `projectId` fields to scores for multi-tenant isolation. Scores can now be saved with tenancy metadata and the `listScoresBy*` methods accept a `filters` option to scope results by organization and project. ([#18331](https://github.com/mastra-ai/mastra/pull/18331))
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
await storage.saveScore({ ...score, organizationId: 'org-a', projectId: 'proj-1' });
|
|
53
|
+
|
|
54
|
+
const result = await storage.listScoresByScorerId({
|
|
55
|
+
scorerId,
|
|
56
|
+
filters: { organizationId: 'org-a', projectId: 'proj-1' },
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`projectId` identifies the project scope, separate from `resourceId` which continues to mean the agent memory resource.
|
|
61
|
+
|
|
62
|
+
- Updated dependencies [[`700619b`](https://github.com/mastra-ai/mastra/commit/700619b61d572e592cbaaf758121d168844ca4d2), [`0f69865`](https://github.com/mastra-ai/mastra/commit/0f69865aced225d98eac812e22699dc445ee18cb), [`9250acd`](https://github.com/mastra-ai/mastra/commit/9250acd1357f0f1f33d0dcca16f9655084c58eca), [`0c3d4bc`](https://github.com/mastra-ai/mastra/commit/0c3d4bcae13ea3699d379403e6f350d5cf4efe9f), [`cc440a3`](https://github.com/mastra-ai/mastra/commit/cc440a39400d8ce06655462b26c1666a1b3d4320), [`6a61846`](https://github.com/mastra-ai/mastra/commit/6a61846eeda29fb714549b70f1bee2bf6b141c44), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`17369b2`](https://github.com/mastra-ai/mastra/commit/17369b25250561e9ed994ae509be1d15bfb33bcb), [`c64c2a8`](https://github.com/mastra-ai/mastra/commit/c64c2a8503a50252f9ca6b8e8c54cadee31b92a2), [`bcae929`](https://github.com/mastra-ai/mastra/commit/bcae929945cbf265bd9f327cc715ecafa072b5b9), [`ea6327b`](https://github.com/mastra-ai/mastra/commit/ea6327ba2d63ca647804bc97b347e03a58617162), [`3439fa8`](https://github.com/mastra-ai/mastra/commit/3439fa836ecfcaa257b40c20b30ac2a8be22e9ea), [`85107f2`](https://github.com/mastra-ai/mastra/commit/85107f2758b527147fccbedff962961927c2d3b8), [`b33822e`](https://github.com/mastra-ai/mastra/commit/b33822e8d470884954b02f7b0745407ee4ef74b1), [`06e2680`](https://github.com/mastra-ai/mastra/commit/06e26806b51d2cbd858afdc66daa2b86ff3ba64a), [`06ff9e0`](https://github.com/mastra-ai/mastra/commit/06ff9e0befd1d642ab87ff749285ee4091205c7e), [`d5c11e3`](https://github.com/mastra-ai/mastra/commit/d5c11e3ba5045969caa7272a7bd1fd141c93ab6c), [`7f5e1ff`](https://github.com/mastra-ai/mastra/commit/7f5e1ff695a92f672bb3976363925d1e9136b54a), [`ff80671`](https://github.com/mastra-ai/mastra/commit/ff8067185e208b27198b4e5b71803013175c3643), [`b8375c1`](https://github.com/mastra-ai/mastra/commit/b8375c1f8fe905df8ae2ae9a893bb365f17aec4e), [`dab1257`](https://github.com/mastra-ai/mastra/commit/dab1257b64e4ed576dc5038bb7a3f7072338bc9f), [`1240f05`](https://github.com/mastra-ai/mastra/commit/1240f051c8e5371f1c014448bf37b1a1b9a05e47), [`705ff39`](https://github.com/mastra-ai/mastra/commit/705ff3969e57214ff2fdaf3815d751dd558886ed), [`e6fbd5b`](https://github.com/mastra-ai/mastra/commit/e6fbd5bfdc28e92c0c0433f29aa1bc152d3430f6), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`6f2026c`](https://github.com/mastra-ai/mastra/commit/6f2026cdf114ff1e21e49133ca774ec7d5085059), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`003f35d`](https://github.com/mastra-ai/mastra/commit/003f35d19e07b23b4bacc591c8bc0c59b42124ae), [`f890eda`](https://github.com/mastra-ai/mastra/commit/f890eda2c8a2ae83d9b30bc6d85842f93b6c266b), [`1340fb7`](https://github.com/mastra-ai/mastra/commit/1340fb76262a3ca062130aa71859f07257a0a5a4)]:
|
|
63
|
+
- @mastra/core@1.49.0
|
|
64
|
+
|
|
3
65
|
## 1.4.1-alpha.0
|
|
4
66
|
|
|
5
67
|
### 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,
|