@mastra/mssql 0.4.2 → 0.4.3
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 +22 -0
- package/dist/index.cjs +78 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +78 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +8 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +9 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { MastraStorage, LegacyEvalsStorage, StoreOperations, TABLE_WORKFLOW_SNAP
|
|
|
3
3
|
import sql2 from 'mssql';
|
|
4
4
|
import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
|
|
5
5
|
import { MessageList } from '@mastra/core/agent';
|
|
6
|
+
import { saveScorePayloadSchema } from '@mastra/core/scores';
|
|
6
7
|
|
|
7
8
|
// src/storage/index.ts
|
|
8
9
|
function getSchemaName(schema) {
|
|
@@ -1473,6 +1474,19 @@ var ScoresMSSQL = class extends ScoresStorage {
|
|
|
1473
1474
|
}
|
|
1474
1475
|
}
|
|
1475
1476
|
async saveScore(score) {
|
|
1477
|
+
let validatedScore;
|
|
1478
|
+
try {
|
|
1479
|
+
validatedScore = saveScorePayloadSchema.parse(score);
|
|
1480
|
+
} catch (error) {
|
|
1481
|
+
throw new MastraError(
|
|
1482
|
+
{
|
|
1483
|
+
id: "MASTRA_STORAGE_MSSQL_STORE_SAVE_SCORE_VALIDATION_FAILED",
|
|
1484
|
+
domain: ErrorDomain.STORAGE,
|
|
1485
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1486
|
+
},
|
|
1487
|
+
error
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1476
1490
|
try {
|
|
1477
1491
|
const scoreId = crypto.randomUUID();
|
|
1478
1492
|
const {
|
|
@@ -1486,7 +1500,7 @@ var ScoresMSSQL = class extends ScoresStorage {
|
|
|
1486
1500
|
runtimeContext,
|
|
1487
1501
|
entity,
|
|
1488
1502
|
...rest
|
|
1489
|
-
} =
|
|
1503
|
+
} = validatedScore;
|
|
1490
1504
|
await this.operations.insert({
|
|
1491
1505
|
tableName: TABLE_SCORERS,
|
|
1492
1506
|
record: {
|
|
@@ -1671,6 +1685,60 @@ var ScoresMSSQL = class extends ScoresStorage {
|
|
|
1671
1685
|
);
|
|
1672
1686
|
}
|
|
1673
1687
|
}
|
|
1688
|
+
async getScoresBySpan({
|
|
1689
|
+
traceId,
|
|
1690
|
+
spanId,
|
|
1691
|
+
pagination
|
|
1692
|
+
}) {
|
|
1693
|
+
try {
|
|
1694
|
+
const request = this.pool.request();
|
|
1695
|
+
request.input("p1", traceId);
|
|
1696
|
+
request.input("p2", spanId);
|
|
1697
|
+
const totalResult = await request.query(
|
|
1698
|
+
`SELECT COUNT(*) as count FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: getSchemaName(this.schema) })} WHERE [traceId] = @p1 AND [spanId] = @p2`
|
|
1699
|
+
);
|
|
1700
|
+
const total = totalResult.recordset[0]?.count || 0;
|
|
1701
|
+
if (total === 0) {
|
|
1702
|
+
return {
|
|
1703
|
+
pagination: {
|
|
1704
|
+
total: 0,
|
|
1705
|
+
page: pagination.page,
|
|
1706
|
+
perPage: pagination.perPage,
|
|
1707
|
+
hasMore: false
|
|
1708
|
+
},
|
|
1709
|
+
scores: []
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
const limit = pagination.perPage + 1;
|
|
1713
|
+
const dataRequest = this.pool.request();
|
|
1714
|
+
dataRequest.input("p1", traceId);
|
|
1715
|
+
dataRequest.input("p2", spanId);
|
|
1716
|
+
dataRequest.input("p3", limit);
|
|
1717
|
+
dataRequest.input("p4", pagination.page * pagination.perPage);
|
|
1718
|
+
const result = await dataRequest.query(
|
|
1719
|
+
`SELECT * FROM ${getTableName({ indexName: TABLE_SCORERS, schemaName: getSchemaName(this.schema) })} WHERE [traceId] = @p1 AND [spanId] = @p2 ORDER BY [createdAt] DESC OFFSET @p4 ROWS FETCH NEXT @p3 ROWS ONLY`
|
|
1720
|
+
);
|
|
1721
|
+
return {
|
|
1722
|
+
pagination: {
|
|
1723
|
+
total: Number(total),
|
|
1724
|
+
page: pagination.page,
|
|
1725
|
+
perPage: pagination.perPage,
|
|
1726
|
+
hasMore: result.recordset.length > pagination.perPage
|
|
1727
|
+
},
|
|
1728
|
+
scores: result.recordset.slice(0, pagination.perPage).map((row) => transformScoreRow(row))
|
|
1729
|
+
};
|
|
1730
|
+
} catch (error) {
|
|
1731
|
+
throw new MastraError(
|
|
1732
|
+
{
|
|
1733
|
+
id: "MASTRA_STORAGE_MSSQL_STORE_GET_SCORES_BY_SPAN_FAILED",
|
|
1734
|
+
domain: ErrorDomain.STORAGE,
|
|
1735
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1736
|
+
details: { traceId, spanId }
|
|
1737
|
+
},
|
|
1738
|
+
error
|
|
1739
|
+
);
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1674
1742
|
};
|
|
1675
1743
|
var TracesMSSQL = class extends TracesStorage {
|
|
1676
1744
|
pool;
|
|
@@ -2160,7 +2228,8 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
2160
2228
|
resourceWorkingMemory: true,
|
|
2161
2229
|
hasColumn: true,
|
|
2162
2230
|
createTable: true,
|
|
2163
|
-
deleteMessages: true
|
|
2231
|
+
deleteMessages: true,
|
|
2232
|
+
getScoresBySpan: true
|
|
2164
2233
|
};
|
|
2165
2234
|
}
|
|
2166
2235
|
/** @deprecated use getEvals instead */
|
|
@@ -2358,6 +2427,13 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
2358
2427
|
pagination: _pagination
|
|
2359
2428
|
});
|
|
2360
2429
|
}
|
|
2430
|
+
async getScoresBySpan({
|
|
2431
|
+
traceId,
|
|
2432
|
+
spanId,
|
|
2433
|
+
pagination: _pagination
|
|
2434
|
+
}) {
|
|
2435
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination: _pagination });
|
|
2436
|
+
}
|
|
2361
2437
|
};
|
|
2362
2438
|
|
|
2363
2439
|
export { MSSQLStore };
|