@mastra/mssql 1.4.0 → 1.4.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,79 @@
1
1
  # @mastra/mssql
2
2
 
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 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))
8
+ - `scoreTrace()` accepts top-level `batchId`, `datasetId`, and `datasetItemId` when persisting a score for a stored trace.
9
+ - `ScoreRowData` and score save payloads now include nullable `batchId`, `datasetId`, and `datasetItemId`.
10
+ - Built-in stores with explicit score schema or attribute mappings now persist these provenance fields on saved scores.
11
+ - D1, DSQL, MSSQL, and Upstash score stores now apply additive provenance migrations or deterministic score ordering for persisted score reads.
12
+
13
+ ```ts
14
+ await scoreTrace({
15
+ storage,
16
+ scorer,
17
+ target: { traceId },
18
+ batchId: 'baseline-batch-1',
19
+ datasetId,
20
+ datasetItemId,
21
+ });
22
+ ```
23
+
24
+ - 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))
25
+
26
+ ```ts
27
+ await storage.saveScore({ ...score, organizationId: 'org-a', projectId: 'proj-1' });
28
+
29
+ const result = await storage.listScoresByScorerId({
30
+ scorerId,
31
+ filters: { organizationId: 'org-a', projectId: 'proj-1' },
32
+ });
33
+ ```
34
+
35
+ `projectId` identifies the project scope, separate from `resourceId` which continues to mean the agent memory resource.
36
+
37
+ - 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)]:
38
+ - @mastra/core@1.49.0
39
+
40
+ ## 1.4.1-alpha.0
41
+
42
+ ### Patch Changes
43
+
44
+ - 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))
45
+ - `scoreTrace()` accepts top-level `batchId`, `datasetId`, and `datasetItemId` when persisting a score for a stored trace.
46
+ - `ScoreRowData` and score save payloads now include nullable `batchId`, `datasetId`, and `datasetItemId`.
47
+ - Built-in stores with explicit score schema or attribute mappings now persist these provenance fields on saved scores.
48
+ - D1, DSQL, MSSQL, and Upstash score stores now apply additive provenance migrations or deterministic score ordering for persisted score reads.
49
+
50
+ ```ts
51
+ await scoreTrace({
52
+ storage,
53
+ scorer,
54
+ target: { traceId },
55
+ batchId: 'baseline-batch-1',
56
+ datasetId,
57
+ datasetItemId,
58
+ });
59
+ ```
60
+
61
+ - 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))
62
+
63
+ ```ts
64
+ await storage.saveScore({ ...score, organizationId: 'org-a', projectId: 'proj-1' });
65
+
66
+ const result = await storage.listScoresByScorerId({
67
+ scorerId,
68
+ filters: { organizationId: 'org-a', projectId: 'proj-1' },
69
+ });
70
+ ```
71
+
72
+ `projectId` identifies the project scope, separate from `resourceId` which continues to mean the agent memory resource.
73
+
74
+ - Updated dependencies [[`9250acd`](https://github.com/mastra-ai/mastra/commit/9250acd1357f0f1f33d0dcca16f9655084c58eca), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`c64c2a8`](https://github.com/mastra-ai/mastra/commit/c64c2a8503a50252f9ca6b8e8c54cadee31b92a2), [`06e2680`](https://github.com/mastra-ai/mastra/commit/06e26806b51d2cbd858afdc66daa2b86ff3ba64a), [`1240f05`](https://github.com/mastra-ai/mastra/commit/1240f051c8e5371f1c014448bf37b1a1b9a05e47), [`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), [`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)]:
75
+ - @mastra/core@1.49.0-alpha.5
76
+
3
77
  ## 1.4.0
4
78
 
5
79
  ### Minor Changes
@@ -3,7 +3,7 @@ name: mastra-mssql
3
3
  description: Documentation for @mastra/mssql. Use when working with @mastra/mssql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mssql"
6
- version: "1.4.0"
6
+ version: "1.4.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.0",
2
+ "version": "1.4.1",
3
3
  "package": "@mastra/mssql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # MSSQL storage
2
4
 
3
5
  The MSSQL storage implementation provides a production-ready storage solution using Microsoft SQL Server databases.
package/dist/index.cjs CHANGED
@@ -4066,6 +4066,19 @@ function transformScoreRow(row) {
4066
4066
  convertTimestamps: true
4067
4067
  });
4068
4068
  }
4069
+ function buildTenancyConditions(filters) {
4070
+ const conditions = [];
4071
+ const params = {};
4072
+ if (filters?.organizationId !== void 0) {
4073
+ conditions.push("[organizationId] = @org");
4074
+ params.org = filters.organizationId;
4075
+ }
4076
+ if (filters?.projectId !== void 0) {
4077
+ conditions.push("[projectId] = @proj");
4078
+ params.proj = filters.projectId;
4079
+ }
4080
+ return { conditions, params };
4081
+ }
4069
4082
  var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4070
4083
  pool;
4071
4084
  db;
@@ -4235,7 +4248,8 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4235
4248
  pagination,
4236
4249
  entityId,
4237
4250
  entityType,
4238
- source
4251
+ source,
4252
+ filters
4239
4253
  }) {
4240
4254
  try {
4241
4255
  const conditions = ["[scorerId] = @p1"];
@@ -4256,6 +4270,9 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4256
4270
  params[`p${paramIndex}`] = source;
4257
4271
  paramIndex++;
4258
4272
  }
4273
+ const tenancy = buildTenancyConditions(filters);
4274
+ conditions.push(...tenancy.conditions);
4275
+ Object.assign(params, tenancy.params);
4259
4276
  const whereClause = conditions.join(" AND ");
4260
4277
  const tableName = getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) });
4261
4278
  const countRequest = this.pool.request();
@@ -4286,7 +4303,7 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4286
4303
  });
4287
4304
  dataRequest.input("perPage", limitValue);
4288
4305
  dataRequest.input("offset", start);
4289
- const dataQuery = `SELECT * FROM ${tableName} WHERE ${whereClause} ORDER BY [createdAt] DESC OFFSET @offset ROWS FETCH NEXT @perPage ROWS ONLY`;
4306
+ const dataQuery = `SELECT * FROM ${tableName} WHERE ${whereClause} ORDER BY [seq_id] DESC OFFSET @offset ROWS FETCH NEXT @perPage ROWS ONLY`;
4290
4307
  const result = await dataRequest.query(dataQuery);
4291
4308
  return {
4292
4309
  pagination: {
@@ -4311,13 +4328,17 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4311
4328
  }
4312
4329
  async listScoresByRunId({
4313
4330
  runId,
4314
- pagination
4331
+ pagination,
4332
+ filters
4315
4333
  }) {
4316
4334
  try {
4335
+ const tenancy = buildTenancyConditions(filters);
4336
+ const tenancySql = tenancy.conditions.length > 0 ? ` AND ${tenancy.conditions.join(" AND ")}` : "";
4317
4337
  const request = this.pool.request();
4318
4338
  request.input("p1", runId);
4339
+ Object.entries(tenancy.params).forEach(([key, value]) => request.input(key, value));
4319
4340
  const totalResult = await request.query(
4320
- `SELECT COUNT(*) as count FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [runId] = @p1`
4341
+ `SELECT COUNT(*) as count FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [runId] = @p1${tenancySql}`
4321
4342
  );
4322
4343
  const total = totalResult.recordset[0]?.count || 0;
4323
4344
  const { page, perPage: perPageInput } = pagination;
@@ -4340,8 +4361,9 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4340
4361
  dataRequest.input("p1", runId);
4341
4362
  dataRequest.input("p2", limitValue);
4342
4363
  dataRequest.input("p3", start);
4364
+ Object.entries(tenancy.params).forEach(([key, value]) => dataRequest.input(key, value));
4343
4365
  const result = await dataRequest.query(
4344
- `SELECT * FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [runId] = @p1 ORDER BY [createdAt] DESC OFFSET @p3 ROWS FETCH NEXT @p2 ROWS ONLY`
4366
+ `SELECT * FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [runId] = @p1${tenancySql} ORDER BY [seq_id] DESC OFFSET @p3 ROWS FETCH NEXT @p2 ROWS ONLY`
4345
4367
  );
4346
4368
  return {
4347
4369
  pagination: {
@@ -4367,14 +4389,18 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4367
4389
  async listScoresByEntityId({
4368
4390
  entityId,
4369
4391
  entityType,
4370
- pagination
4392
+ pagination,
4393
+ filters
4371
4394
  }) {
4372
4395
  try {
4396
+ const tenancy = buildTenancyConditions(filters);
4397
+ const tenancySql = tenancy.conditions.length > 0 ? ` AND ${tenancy.conditions.join(" AND ")}` : "";
4373
4398
  const request = this.pool.request();
4374
4399
  request.input("p1", entityId);
4375
4400
  request.input("p2", entityType);
4401
+ Object.entries(tenancy.params).forEach(([key, value]) => request.input(key, value));
4376
4402
  const totalResult = await request.query(
4377
- `SELECT COUNT(*) as count FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [entityId] = @p1 AND [entityType] = @p2`
4403
+ `SELECT COUNT(*) as count FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [entityId] = @p1 AND [entityType] = @p2${tenancySql}`
4378
4404
  );
4379
4405
  const total = totalResult.recordset[0]?.count || 0;
4380
4406
  const { page, perPage: perPageInput } = pagination;
@@ -4398,8 +4424,9 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4398
4424
  dataRequest.input("p2", entityType);
4399
4425
  dataRequest.input("p3", limitValue);
4400
4426
  dataRequest.input("p4", start);
4427
+ Object.entries(tenancy.params).forEach(([key, value]) => dataRequest.input(key, value));
4401
4428
  const result = await dataRequest.query(
4402
- `SELECT * FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [entityId] = @p1 AND [entityType] = @p2 ORDER BY [createdAt] DESC OFFSET @p4 ROWS FETCH NEXT @p3 ROWS ONLY`
4429
+ `SELECT * FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [entityId] = @p1 AND [entityType] = @p2${tenancySql} ORDER BY [seq_id] DESC OFFSET @p4 ROWS FETCH NEXT @p3 ROWS ONLY`
4403
4430
  );
4404
4431
  return {
4405
4432
  pagination: {
@@ -4425,14 +4452,18 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4425
4452
  async listScoresBySpan({
4426
4453
  traceId,
4427
4454
  spanId,
4428
- pagination
4455
+ pagination,
4456
+ filters
4429
4457
  }) {
4430
4458
  try {
4459
+ const tenancy = buildTenancyConditions(filters);
4460
+ const tenancySql = tenancy.conditions.length > 0 ? ` AND ${tenancy.conditions.join(" AND ")}` : "";
4431
4461
  const request = this.pool.request();
4432
4462
  request.input("p1", traceId);
4433
4463
  request.input("p2", spanId);
4464
+ Object.entries(tenancy.params).forEach(([key, value]) => request.input(key, value));
4434
4465
  const totalResult = await request.query(
4435
- `SELECT COUNT(*) as count FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [traceId] = @p1 AND [spanId] = @p2`
4466
+ `SELECT COUNT(*) as count FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [traceId] = @p1 AND [spanId] = @p2${tenancySql}`
4436
4467
  );
4437
4468
  const total = totalResult.recordset[0]?.count || 0;
4438
4469
  const { page, perPage: perPageInput } = pagination;
@@ -4456,8 +4487,9 @@ var ScoresMSSQL = class _ScoresMSSQL extends storage.ScoresStorage {
4456
4487
  dataRequest.input("p2", spanId);
4457
4488
  dataRequest.input("p3", limitValue);
4458
4489
  dataRequest.input("p4", start);
4490
+ Object.entries(tenancy.params).forEach(([key, value]) => dataRequest.input(key, value));
4459
4491
  const result = await dataRequest.query(
4460
- `SELECT * FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [traceId] = @p1 AND [spanId] = @p2 ORDER BY [createdAt] DESC OFFSET @p4 ROWS FETCH NEXT @p3 ROWS ONLY`
4492
+ `SELECT * FROM ${getTableName2({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName2(this.schema) })} WHERE [traceId] = @p1 AND [spanId] = @p2${tenancySql} ORDER BY [seq_id] DESC OFFSET @p4 ROWS FETCH NEXT @p3 ROWS ONLY`
4461
4493
  );
4462
4494
  return {
4463
4495
  pagination: {