@mastra/upstash 0.15.2-alpha.1 → 0.15.3-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/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { MastraStorage, StoreOperations, TracesStorage, TABLE_TRACES, ScoresStor
2
2
  import { Redis } from '@upstash/redis';
3
3
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
4
4
  import { MessageList } from '@mastra/core/agent';
5
+ import { saveScorePayloadSchema } from '@mastra/core/scores';
5
6
  import { randomUUID } from 'crypto';
6
7
  import { MastraVector } from '@mastra/core/vector';
7
8
  import { Index } from '@upstash/vector';
@@ -1291,7 +1292,20 @@ var ScoresUpstash = class extends ScoresStorage {
1291
1292
  };
1292
1293
  }
1293
1294
  async saveScore(score) {
1294
- const { key, processedRecord } = processRecord(TABLE_SCORERS, score);
1295
+ let validatedScore;
1296
+ try {
1297
+ validatedScore = saveScorePayloadSchema.parse(score);
1298
+ } catch (error) {
1299
+ throw new MastraError(
1300
+ {
1301
+ id: "STORAGE_UPSTASH_STORAGE_SAVE_SCORE_VALIDATION_FAILED",
1302
+ domain: ErrorDomain.STORAGE,
1303
+ category: ErrorCategory.THIRD_PARTY
1304
+ },
1305
+ error
1306
+ );
1307
+ }
1308
+ const { key, processedRecord } = processRecord(TABLE_SCORERS, validatedScore);
1295
1309
  try {
1296
1310
  await this.client.set(key, processedRecord);
1297
1311
  return { score };
@@ -1377,6 +1391,44 @@ var ScoresUpstash = class extends ScoresStorage {
1377
1391
  }
1378
1392
  };
1379
1393
  }
1394
+ async getScoresBySpan({
1395
+ traceId,
1396
+ spanId,
1397
+ pagination = { page: 0, perPage: 20 }
1398
+ }) {
1399
+ const pattern = `${TABLE_SCORERS}:*`;
1400
+ const keys = await this.operations.scanKeys(pattern);
1401
+ if (keys.length === 0) {
1402
+ return {
1403
+ scores: [],
1404
+ pagination: { total: 0, page: pagination.page, perPage: pagination.perPage, hasMore: false }
1405
+ };
1406
+ }
1407
+ const pipeline = this.client.pipeline();
1408
+ keys.forEach((key) => pipeline.get(key));
1409
+ const results = await pipeline.exec();
1410
+ const filtered = results.map((row) => row).filter((row) => {
1411
+ if (!row || typeof row !== "object") return false;
1412
+ if (row.traceId !== traceId) return false;
1413
+ if (row.spanId !== spanId) return false;
1414
+ return true;
1415
+ });
1416
+ const total = filtered.length;
1417
+ const { page, perPage } = pagination;
1418
+ const start = page * perPage;
1419
+ const end = start + perPage;
1420
+ const paged = filtered.slice(start, end);
1421
+ const scores = paged.map((row) => transformScoreRow(row));
1422
+ return {
1423
+ scores,
1424
+ pagination: {
1425
+ total,
1426
+ page,
1427
+ perPage,
1428
+ hasMore: end < total
1429
+ }
1430
+ };
1431
+ }
1380
1432
  };
1381
1433
  var TracesUpstash = class extends TracesStorage {
1382
1434
  client;
@@ -1749,7 +1801,8 @@ var UpstashStore = class extends MastraStorage {
1749
1801
  resourceWorkingMemory: true,
1750
1802
  hasColumn: false,
1751
1803
  createTable: false,
1752
- deleteMessages: true
1804
+ deleteMessages: true,
1805
+ getScoresBySpan: true
1753
1806
  };
1754
1807
  }
1755
1808
  /**
@@ -1943,6 +1996,13 @@ var UpstashStore = class extends MastraStorage {
1943
1996
  }) {
1944
1997
  return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
1945
1998
  }
1999
+ async getScoresBySpan({
2000
+ traceId,
2001
+ spanId,
2002
+ pagination
2003
+ }) {
2004
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
2005
+ }
1946
2006
  };
1947
2007
  var UpstashFilterTranslator = class extends BaseFilterTranslator {
1948
2008
  getSupportedOperators() {