@mastra/upstash 0.15.8-alpha.0 → 1.0.0-beta.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.cjs CHANGED
@@ -2,224 +2,15 @@
2
2
 
3
3
  var storage = require('@mastra/core/storage');
4
4
  var redis = require('@upstash/redis');
5
- var error = require('@mastra/core/error');
6
5
  var agent = require('@mastra/core/agent');
7
- var scores = require('@mastra/core/scores');
6
+ var error = require('@mastra/core/error');
7
+ var evals = require('@mastra/core/evals');
8
8
  var crypto = require('crypto');
9
9
  var vector = require('@mastra/core/vector');
10
10
  var vector$1 = require('@upstash/vector');
11
11
  var filter = require('@mastra/core/vector/filter');
12
12
 
13
13
  // src/storage/index.ts
14
- function transformEvalRecord(record) {
15
- let result = record.result;
16
- if (typeof result === "string") {
17
- try {
18
- result = JSON.parse(result);
19
- } catch {
20
- console.warn("Failed to parse result JSON:");
21
- }
22
- }
23
- let testInfo = record.test_info;
24
- if (typeof testInfo === "string") {
25
- try {
26
- testInfo = JSON.parse(testInfo);
27
- } catch {
28
- console.warn("Failed to parse test_info JSON:");
29
- }
30
- }
31
- return {
32
- agentName: record.agent_name,
33
- input: record.input,
34
- output: record.output,
35
- result,
36
- metricName: record.metric_name,
37
- instructions: record.instructions,
38
- testInfo,
39
- globalRunId: record.global_run_id,
40
- runId: record.run_id,
41
- createdAt: typeof record.created_at === "string" ? record.created_at : record.created_at instanceof Date ? record.created_at.toISOString() : (/* @__PURE__ */ new Date()).toISOString()
42
- };
43
- }
44
- var StoreLegacyEvalsUpstash = class extends storage.LegacyEvalsStorage {
45
- client;
46
- operations;
47
- constructor({ client, operations }) {
48
- super();
49
- this.client = client;
50
- this.operations = operations;
51
- }
52
- /**
53
- * @deprecated Use getEvals instead
54
- */
55
- async getEvalsByAgentName(agentName, type) {
56
- try {
57
- const pattern = `${storage.TABLE_EVALS}:*`;
58
- const keys = await this.operations.scanKeys(pattern);
59
- if (keys.length === 0) {
60
- return [];
61
- }
62
- const pipeline = this.client.pipeline();
63
- keys.forEach((key) => pipeline.get(key));
64
- const results = await pipeline.exec();
65
- const nonNullRecords = results.filter(
66
- (record) => record !== null && typeof record === "object" && "agent_name" in record && record.agent_name === agentName
67
- );
68
- let filteredEvals = nonNullRecords;
69
- if (type === "test") {
70
- filteredEvals = filteredEvals.filter((record) => {
71
- if (!record.test_info) return false;
72
- try {
73
- if (typeof record.test_info === "string") {
74
- const parsedTestInfo = JSON.parse(record.test_info);
75
- return parsedTestInfo && typeof parsedTestInfo === "object" && "testPath" in parsedTestInfo;
76
- }
77
- return typeof record.test_info === "object" && "testPath" in record.test_info;
78
- } catch {
79
- return false;
80
- }
81
- });
82
- } else if (type === "live") {
83
- filteredEvals = filteredEvals.filter((record) => {
84
- if (!record.test_info) return true;
85
- try {
86
- if (typeof record.test_info === "string") {
87
- const parsedTestInfo = JSON.parse(record.test_info);
88
- return !(parsedTestInfo && typeof parsedTestInfo === "object" && "testPath" in parsedTestInfo);
89
- }
90
- return !(typeof record.test_info === "object" && "testPath" in record.test_info);
91
- } catch {
92
- return true;
93
- }
94
- });
95
- }
96
- return filteredEvals.map((record) => transformEvalRecord(record));
97
- } catch (error$1) {
98
- const mastraError = new error.MastraError(
99
- {
100
- id: "STORAGE_UPSTASH_STORAGE_GET_EVALS_BY_AGENT_NAME_FAILED",
101
- domain: error.ErrorDomain.STORAGE,
102
- category: error.ErrorCategory.THIRD_PARTY,
103
- details: { agentName }
104
- },
105
- error$1
106
- );
107
- this.logger?.trackException(mastraError);
108
- this.logger.error(mastraError.toString());
109
- return [];
110
- }
111
- }
112
- /**
113
- * Get all evaluations with pagination and total count
114
- * @param options Pagination and filtering options
115
- * @returns Object with evals array and total count
116
- */
117
- async getEvals(options) {
118
- try {
119
- const { agentName, type, page = 0, perPage = 100, dateRange } = options || {};
120
- const fromDate = dateRange?.start;
121
- const toDate = dateRange?.end;
122
- const pattern = `${storage.TABLE_EVALS}:*`;
123
- const keys = await this.operations.scanKeys(pattern);
124
- if (keys.length === 0) {
125
- return {
126
- evals: [],
127
- total: 0,
128
- page,
129
- perPage,
130
- hasMore: false
131
- };
132
- }
133
- const pipeline = this.client.pipeline();
134
- keys.forEach((key) => pipeline.get(key));
135
- const results = await pipeline.exec();
136
- let filteredEvals = results.map((result) => result).filter((record) => record !== null && typeof record === "object");
137
- if (agentName) {
138
- filteredEvals = filteredEvals.filter((record) => record.agent_name === agentName);
139
- }
140
- if (type === "test") {
141
- filteredEvals = filteredEvals.filter((record) => {
142
- if (!record.test_info) return false;
143
- try {
144
- if (typeof record.test_info === "string") {
145
- const parsedTestInfo = JSON.parse(record.test_info);
146
- return parsedTestInfo && typeof parsedTestInfo === "object" && "testPath" in parsedTestInfo;
147
- }
148
- return typeof record.test_info === "object" && "testPath" in record.test_info;
149
- } catch {
150
- return false;
151
- }
152
- });
153
- } else if (type === "live") {
154
- filteredEvals = filteredEvals.filter((record) => {
155
- if (!record.test_info) return true;
156
- try {
157
- if (typeof record.test_info === "string") {
158
- const parsedTestInfo = JSON.parse(record.test_info);
159
- return !(parsedTestInfo && typeof parsedTestInfo === "object" && "testPath" in parsedTestInfo);
160
- }
161
- return !(typeof record.test_info === "object" && "testPath" in record.test_info);
162
- } catch {
163
- return true;
164
- }
165
- });
166
- }
167
- if (fromDate) {
168
- filteredEvals = filteredEvals.filter((record) => {
169
- const createdAt = new Date(record.created_at || record.createdAt || 0);
170
- return createdAt.getTime() >= fromDate.getTime();
171
- });
172
- }
173
- if (toDate) {
174
- filteredEvals = filteredEvals.filter((record) => {
175
- const createdAt = new Date(record.created_at || record.createdAt || 0);
176
- return createdAt.getTime() <= toDate.getTime();
177
- });
178
- }
179
- filteredEvals.sort((a, b) => {
180
- const dateA = new Date(a.created_at || a.createdAt || 0).getTime();
181
- const dateB = new Date(b.created_at || b.createdAt || 0).getTime();
182
- return dateB - dateA;
183
- });
184
- const total = filteredEvals.length;
185
- const start = page * perPage;
186
- const end = start + perPage;
187
- const paginatedEvals = filteredEvals.slice(start, end);
188
- const hasMore = end < total;
189
- const evals = paginatedEvals.map((record) => transformEvalRecord(record));
190
- return {
191
- evals,
192
- total,
193
- page,
194
- perPage,
195
- hasMore
196
- };
197
- } catch (error$1) {
198
- const { page = 0, perPage = 100 } = options || {};
199
- const mastraError = new error.MastraError(
200
- {
201
- id: "STORAGE_UPSTASH_STORAGE_GET_EVALS_FAILED",
202
- domain: error.ErrorDomain.STORAGE,
203
- category: error.ErrorCategory.THIRD_PARTY,
204
- details: {
205
- page,
206
- perPage
207
- }
208
- },
209
- error$1
210
- );
211
- this.logger.error(mastraError.toString());
212
- this.logger?.trackException(mastraError);
213
- return {
214
- evals: [],
215
- total: 0,
216
- page,
217
- perPage,
218
- hasMore: false
219
- };
220
- }
221
- }
222
- };
223
14
  function ensureDate(value) {
224
15
  if (!value) return null;
225
16
  if (value instanceof Date) return value;
@@ -227,16 +18,6 @@ function ensureDate(value) {
227
18
  if (typeof value === "number") return new Date(value);
228
19
  return null;
229
20
  }
230
- function parseJSON(value) {
231
- if (typeof value === "string") {
232
- try {
233
- return JSON.parse(value);
234
- } catch {
235
- return value;
236
- }
237
- }
238
- return value;
239
- }
240
21
  function getKey(tableName, keys) {
241
22
  const keyParts = Object.entries(keys).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}:${value}`);
242
23
  return `${tableName}:${keyParts.join(":")}`;
@@ -252,8 +33,6 @@ function processRecord(tableName, record) {
252
33
  run_id: record.run_id,
253
34
  ...record.resourceId ? { resourceId: record.resourceId } : {}
254
35
  });
255
- } else if (tableName === storage.TABLE_EVALS) {
256
- key = getKey(tableName, { id: record.run_id });
257
36
  } else if (tableName === storage.TABLE_SCORERS) {
258
37
  key = getKey(tableName, { runId: record.runId });
259
38
  } else {
@@ -310,17 +89,26 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
310
89
  );
311
90
  }
312
91
  }
313
- /**
314
- * @deprecated use getThreadsByResourceIdPaginated instead
315
- */
316
- async getThreadsByResourceId({ resourceId }) {
92
+ async listThreadsByResourceId(args) {
93
+ const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
94
+ const { field, direction } = this.parseOrderBy(orderBy);
95
+ const perPage = storage.normalizePerPage(perPageInput, 100);
96
+ if (page < 0) {
97
+ throw new error.MastraError(
98
+ {
99
+ id: "STORAGE_UPSTASH_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
100
+ domain: error.ErrorDomain.STORAGE,
101
+ category: error.ErrorCategory.USER,
102
+ details: { page }
103
+ },
104
+ new Error("page must be >= 0")
105
+ );
106
+ }
107
+ const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
317
108
  try {
109
+ let allThreads = [];
318
110
  const pattern = `${storage.TABLE_THREADS}:*`;
319
111
  const keys = await this.operations.scanKeys(pattern);
320
- if (keys.length === 0) {
321
- return [];
322
- }
323
- const allThreads = [];
324
112
  const pipeline = this.client.pipeline();
325
113
  keys.forEach((key) => pipeline.get(key));
326
114
  const results = await pipeline.exec();
@@ -335,45 +123,22 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
335
123
  });
336
124
  }
337
125
  }
338
- allThreads.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
339
- return allThreads;
340
- } catch (error$1) {
341
- const mastraError = new error.MastraError(
342
- {
343
- id: "STORAGE_UPSTASH_STORAGE_GET_THREADS_BY_RESOURCE_ID_FAILED",
344
- domain: error.ErrorDomain.STORAGE,
345
- category: error.ErrorCategory.THIRD_PARTY,
346
- details: {
347
- resourceId
348
- }
349
- },
350
- error$1
351
- );
352
- this.logger?.trackException(mastraError);
353
- this.logger.error(mastraError.toString());
354
- return [];
355
- }
356
- }
357
- async getThreadsByResourceIdPaginated(args) {
358
- const { resourceId, page = 0, perPage = 100 } = args;
359
- try {
360
- const allThreads = await this.getThreadsByResourceId({ resourceId });
361
- const total = allThreads.length;
362
- const start = page * perPage;
363
- const end = start + perPage;
364
- const paginatedThreads = allThreads.slice(start, end);
365
- const hasMore = end < total;
126
+ const sortedThreads = this.sortThreads(allThreads, field, direction);
127
+ const total = sortedThreads.length;
128
+ const end = perPageInput === false ? total : offset + perPage;
129
+ const paginatedThreads = sortedThreads.slice(offset, end);
130
+ const hasMore = perPageInput === false ? false : end < total;
366
131
  return {
367
132
  threads: paginatedThreads,
368
133
  total,
369
134
  page,
370
- perPage,
135
+ perPage: perPageForResponse,
371
136
  hasMore
372
137
  };
373
138
  } catch (error$1) {
374
139
  const mastraError = new error.MastraError(
375
140
  {
376
- id: "STORAGE_UPSTASH_STORAGE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
141
+ id: "STORAGE_UPSTASH_STORAGE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
377
142
  domain: error.ErrorDomain.STORAGE,
378
143
  category: error.ErrorCategory.THIRD_PARTY,
379
144
  details: {
@@ -390,7 +155,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
390
155
  threads: [],
391
156
  total: 0,
392
157
  page,
393
- perPage,
158
+ perPage: perPageForResponse,
394
159
  hasMore: false
395
160
  };
396
161
  }
@@ -491,8 +256,8 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
491
256
  }
492
257
  }
493
258
  async saveMessages(args) {
494
- const { messages, format = "v1" } = args;
495
- if (messages.length === 0) return [];
259
+ const { messages } = args;
260
+ if (messages.length === 0) return { messages: [] };
496
261
  const threadId = messages[0]?.threadId;
497
262
  try {
498
263
  if (!threadId) {
@@ -545,9 +310,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
545
310
  const pipeline2 = this.client.pipeline();
546
311
  keys.forEach((key2) => pipeline2.get(key2));
547
312
  const results = await pipeline2.exec();
548
- const existingMessages = results.filter(
549
- (msg) => msg !== null
550
- );
313
+ const existingMessages = results.filter((msg) => msg !== null);
551
314
  for (const existingMessage of existingMessages) {
552
315
  const existingMessageKey = getMessageKey(existingMessage.threadId, existingMessage.id);
553
316
  if (existingMessage && existingMessage.threadId !== message.threadId) {
@@ -572,8 +335,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
572
335
  await pipeline.exec();
573
336
  }
574
337
  const list = new agent.MessageList().add(messages, "memory");
575
- if (format === `v2`) return list.get.all.v2();
576
- return list.get.all.v1();
338
+ return { messages: list.get.all.db() };
577
339
  } catch (error$1) {
578
340
  throw new error.MastraError(
579
341
  {
@@ -588,12 +350,12 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
588
350
  );
589
351
  }
590
352
  }
591
- async _getIncludedMessages(threadId, selectBy) {
353
+ async _getIncludedMessages(threadId, include) {
592
354
  if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
593
355
  const messageIds = /* @__PURE__ */ new Set();
594
356
  const messageIdToThreadIds = {};
595
- if (selectBy?.include?.length) {
596
- for (const item of selectBy.include) {
357
+ if (include?.length) {
358
+ for (const item of include) {
597
359
  messageIds.add(item.id);
598
360
  const itemThreadId = item.threadId || threadId;
599
361
  messageIdToThreadIds[item.id] = itemThreadId;
@@ -635,89 +397,8 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
635
397
  content: rest.content || defaultMessageContent
636
398
  };
637
399
  }
638
- async getMessages({
639
- threadId,
640
- resourceId,
641
- selectBy,
642
- format
643
- }) {
644
- try {
645
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
646
- const threadMessagesKey = getThreadMessagesKey(threadId);
647
- const allMessageIds = await this.client.zrange(threadMessagesKey, 0, -1);
648
- const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
649
- const messageIds = /* @__PURE__ */ new Set();
650
- const messageIdToThreadIds = {};
651
- if (limit === 0 && !selectBy?.include) {
652
- return [];
653
- }
654
- if (limit === Number.MAX_SAFE_INTEGER) {
655
- const allIds = await this.client.zrange(threadMessagesKey, 0, -1);
656
- allIds.forEach((id) => {
657
- messageIds.add(id);
658
- messageIdToThreadIds[id] = threadId;
659
- });
660
- } else if (limit > 0) {
661
- const latestIds = await this.client.zrange(threadMessagesKey, -limit, -1);
662
- latestIds.forEach((id) => {
663
- messageIds.add(id);
664
- messageIdToThreadIds[id] = threadId;
665
- });
666
- }
667
- const includedMessages = await this._getIncludedMessages(threadId, selectBy);
668
- const messages = [
669
- ...includedMessages,
670
- ...(await Promise.all(
671
- Array.from(messageIds).map(async (id) => {
672
- const tId = messageIdToThreadIds[id] || threadId;
673
- const byThreadId = await this.client.get(getMessageKey(tId, id));
674
- if (byThreadId) return byThreadId;
675
- return null;
676
- })
677
- )).filter((msg) => msg !== null)
678
- ];
679
- messages.sort((a, b) => allMessageIds.indexOf(a.id) - allMessageIds.indexOf(b.id));
680
- const seen = /* @__PURE__ */ new Set();
681
- const dedupedMessages = messages.filter((row) => {
682
- if (seen.has(row.id)) return false;
683
- seen.add(row.id);
684
- return true;
685
- });
686
- const prepared = dedupedMessages.filter((message) => message !== null && message !== void 0).map((message) => {
687
- const { _index, ...messageWithoutIndex } = message;
688
- return messageWithoutIndex;
689
- });
690
- if (format === "v2") {
691
- return prepared.map((msg) => ({
692
- ...msg,
693
- createdAt: new Date(msg.createdAt),
694
- content: msg.content || { format: 2, parts: [{ type: "text", text: "" }] }
695
- }));
696
- }
697
- return prepared.map((msg) => ({
698
- ...msg,
699
- createdAt: new Date(msg.createdAt)
700
- }));
701
- } catch (error$1) {
702
- throw new error.MastraError(
703
- {
704
- id: "STORAGE_UPSTASH_STORAGE_GET_MESSAGES_FAILED",
705
- domain: error.ErrorDomain.STORAGE,
706
- category: error.ErrorCategory.THIRD_PARTY,
707
- details: {
708
- threadId,
709
- resourceId: resourceId ?? ""
710
- }
711
- },
712
- error$1
713
- );
714
- }
715
- }
716
- async getMessagesById({
717
- messageIds,
718
- format
719
- }) {
720
- if (messageIds.length === 0) return [];
400
+ async listMessagesById({ messageIds }) {
401
+ if (messageIds.length === 0) return { messages: [] };
721
402
  try {
722
403
  const threadKeys = await this.client.keys("thread:*");
723
404
  const result = await Promise.all(
@@ -731,12 +412,11 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
731
412
  );
732
413
  const rawMessages = result.flat(1).filter((msg) => !!msg);
733
414
  const list = new agent.MessageList().add(rawMessages.map(this.parseStoredMessage), "memory");
734
- if (format === `v1`) return list.get.all.v1();
735
- return list.get.all.v2();
415
+ return { messages: list.get.all.db() };
736
416
  } catch (error$1) {
737
417
  throw new error.MastraError(
738
418
  {
739
- id: "STORAGE_UPSTASH_STORAGE_GET_MESSAGES_BY_ID_FAILED",
419
+ id: "STORAGE_UPSTASH_STORAGE_LIST_MESSAGES_BY_ID_FAILED",
740
420
  domain: error.ErrorDomain.STORAGE,
741
421
  category: error.ErrorCategory.THIRD_PARTY,
742
422
  details: {
@@ -747,61 +427,137 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
747
427
  );
748
428
  }
749
429
  }
750
- async getMessagesPaginated(args) {
751
- const { threadId, resourceId, selectBy, format } = args;
752
- const { page = 0, perPage = 40, dateRange } = selectBy?.pagination || {};
753
- const fromDate = dateRange?.start;
754
- const toDate = dateRange?.end;
430
+ async listMessages(args) {
431
+ const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
432
+ if (!threadId.trim()) {
433
+ throw new error.MastraError(
434
+ {
435
+ id: "STORAGE_UPSTASH_LIST_MESSAGES_INVALID_THREAD_ID",
436
+ domain: error.ErrorDomain.STORAGE,
437
+ category: error.ErrorCategory.THIRD_PARTY,
438
+ details: { threadId }
439
+ },
440
+ new Error("threadId must be a non-empty string")
441
+ );
442
+ }
755
443
  const threadMessagesKey = getThreadMessagesKey(threadId);
756
- const messages = [];
444
+ const perPage = storage.normalizePerPage(perPageInput, 40);
445
+ const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
757
446
  try {
758
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
759
- const includedMessages = await this._getIncludedMessages(threadId, selectBy);
760
- messages.push(...includedMessages);
761
- const allMessageIds = await this.client.zrange(
762
- threadMessagesKey,
763
- args?.selectBy?.last ? -args.selectBy.last : 0,
764
- -1
765
- );
447
+ if (page < 0) {
448
+ throw new error.MastraError(
449
+ {
450
+ id: "STORAGE_UPSTASH_LIST_MESSAGES_INVALID_PAGE",
451
+ domain: error.ErrorDomain.STORAGE,
452
+ category: error.ErrorCategory.USER,
453
+ details: { page }
454
+ },
455
+ new Error("page must be >= 0")
456
+ );
457
+ }
458
+ let includedMessages = [];
459
+ if (include && include.length > 0) {
460
+ const included = await this._getIncludedMessages(threadId, include);
461
+ includedMessages = included.map(this.parseStoredMessage);
462
+ }
463
+ const allMessageIds = await this.client.zrange(threadMessagesKey, 0, -1);
766
464
  if (allMessageIds.length === 0) {
767
465
  return {
768
466
  messages: [],
769
467
  total: 0,
770
468
  page,
771
- perPage,
469
+ perPage: perPageForResponse,
772
470
  hasMore: false
773
471
  };
774
472
  }
775
473
  const pipeline = this.client.pipeline();
776
474
  allMessageIds.forEach((id) => pipeline.get(getMessageKey(threadId, id)));
777
475
  const results = await pipeline.exec();
778
- let messagesData = results.filter((msg) => msg !== null);
779
- if (fromDate) {
780
- messagesData = messagesData.filter((msg) => msg && new Date(msg.createdAt).getTime() >= fromDate.getTime());
476
+ let messagesData = results.filter((msg) => msg !== null).map(this.parseStoredMessage);
477
+ if (resourceId) {
478
+ messagesData = messagesData.filter((msg) => msg.resourceId === resourceId);
479
+ }
480
+ const dateRange = filter?.dateRange;
481
+ if (dateRange?.start) {
482
+ const fromDate = dateRange.start;
483
+ messagesData = messagesData.filter((msg) => new Date(msg.createdAt).getTime() >= fromDate.getTime());
781
484
  }
782
- if (toDate) {
783
- messagesData = messagesData.filter((msg) => msg && new Date(msg.createdAt).getTime() <= toDate.getTime());
485
+ if (dateRange?.end) {
486
+ const toDate = dateRange.end;
487
+ messagesData = messagesData.filter((msg) => new Date(msg.createdAt).getTime() <= toDate.getTime());
488
+ }
489
+ const { field, direction } = this.parseOrderBy(orderBy, "ASC");
490
+ const getFieldValue = (msg) => {
491
+ if (field === "createdAt") {
492
+ return new Date(msg.createdAt).getTime();
493
+ }
494
+ const value = msg[field];
495
+ if (typeof value === "number") {
496
+ return value;
497
+ }
498
+ if (value instanceof Date) {
499
+ return value.getTime();
500
+ }
501
+ return 0;
502
+ };
503
+ if (orderBy) {
504
+ messagesData.sort((a, b) => {
505
+ const aValue = getFieldValue(a);
506
+ const bValue = getFieldValue(b);
507
+ return direction === "ASC" ? aValue - bValue : bValue - aValue;
508
+ });
784
509
  }
785
- messagesData.sort((a, b) => allMessageIds.indexOf(a.id) - allMessageIds.indexOf(b.id));
786
510
  const total = messagesData.length;
787
- const start = page * perPage;
788
- const end = start + perPage;
789
- const hasMore = end < total;
511
+ const start = offset;
512
+ const end = perPageInput === false ? total : start + perPage;
790
513
  const paginatedMessages = messagesData.slice(start, end);
791
- messages.push(...paginatedMessages);
792
- const list = new agent.MessageList().add(messages, "memory");
793
- const finalMessages = format === `v2` ? list.get.all.v2() : list.get.all.v1();
514
+ const messageIds = /* @__PURE__ */ new Set();
515
+ const allMessages = [];
516
+ for (const msg of paginatedMessages) {
517
+ if (!messageIds.has(msg.id)) {
518
+ allMessages.push(msg);
519
+ messageIds.add(msg.id);
520
+ }
521
+ }
522
+ for (const msg of includedMessages) {
523
+ if (!messageIds.has(msg.id)) {
524
+ allMessages.push(msg);
525
+ messageIds.add(msg.id);
526
+ }
527
+ }
528
+ const list = new agent.MessageList().add(allMessages, "memory");
529
+ let finalMessages = list.get.all.db();
530
+ if (orderBy) {
531
+ finalMessages = finalMessages.sort((a, b) => {
532
+ const aValue = getFieldValue(a);
533
+ const bValue = getFieldValue(b);
534
+ return direction === "ASC" ? aValue - bValue : bValue - aValue;
535
+ });
536
+ } else {
537
+ const messageIdToPosition = /* @__PURE__ */ new Map();
538
+ allMessageIds.forEach((id, index) => {
539
+ messageIdToPosition.set(id, index);
540
+ });
541
+ finalMessages = finalMessages.sort((a, b) => {
542
+ const aPos = messageIdToPosition.get(a.id) ?? Number.MAX_SAFE_INTEGER;
543
+ const bPos = messageIdToPosition.get(b.id) ?? Number.MAX_SAFE_INTEGER;
544
+ return aPos - bPos;
545
+ });
546
+ }
547
+ const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
548
+ const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
549
+ const hasMore = perPageInput !== false && !allThreadMessagesReturned && end < total;
794
550
  return {
795
551
  messages: finalMessages,
796
552
  total,
797
553
  page,
798
- perPage,
554
+ perPage: perPageForResponse,
799
555
  hasMore
800
556
  };
801
557
  } catch (error$1) {
802
558
  const mastraError = new error.MastraError(
803
559
  {
804
- id: "STORAGE_UPSTASH_STORAGE_GET_MESSAGES_PAGINATED_FAILED",
560
+ id: "STORAGE_UPSTASH_STORAGE_LIST_MESSAGES_FAILED",
805
561
  domain: error.ErrorDomain.STORAGE,
806
562
  category: error.ErrorCategory.THIRD_PARTY,
807
563
  details: {
@@ -817,7 +573,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
817
573
  messages: [],
818
574
  total: 0,
819
575
  page,
820
- perPage,
576
+ perPage: perPageForResponse,
821
577
  hasMore: false
822
578
  };
823
579
  }
@@ -984,8 +740,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
984
740
  if (key) {
985
741
  const updatedMessage = await this.client.get(key);
986
742
  if (updatedMessage) {
987
- const v2e = updatedMessage;
988
- updatedMessages.push(v2e);
743
+ updatedMessages.push(updatedMessage);
989
744
  }
990
745
  }
991
746
  }
@@ -1058,6 +813,17 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
1058
813
  );
1059
814
  }
1060
815
  }
816
+ sortThreads(threads, field, direction) {
817
+ return threads.sort((a, b) => {
818
+ const aValue = new Date(a[field]).getTime();
819
+ const bValue = new Date(b[field]).getTime();
820
+ if (direction === "ASC") {
821
+ return aValue - bValue;
822
+ } else {
823
+ return bValue - aValue;
824
+ }
825
+ });
826
+ }
1061
827
  };
1062
828
  var StoreOperationsUpstash = class extends storage.StoreOperations {
1063
829
  client;
@@ -1217,7 +983,7 @@ function transformScoreRow(row) {
1217
983
  input: parseField(row.input),
1218
984
  output: parseField(row.output),
1219
985
  additionalContext: parseField(row.additionalContext),
1220
- runtimeContext: parseField(row.runtimeContext),
986
+ requestContext: parseField(row.requestContext),
1221
987
  entity: parseField(row.entity),
1222
988
  createdAt: row.createdAt,
1223
989
  updatedAt: row.updatedAt
@@ -1251,7 +1017,7 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1251
1017
  );
1252
1018
  }
1253
1019
  }
1254
- async getScoresByScorerId({
1020
+ async listScoresByScorerId({
1255
1021
  scorerId,
1256
1022
  entityId,
1257
1023
  entityType,
@@ -1260,16 +1026,27 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1260
1026
  }) {
1261
1027
  const pattern = `${storage.TABLE_SCORERS}:*`;
1262
1028
  const keys = await this.operations.scanKeys(pattern);
1029
+ const { page, perPage: perPageInput } = pagination;
1263
1030
  if (keys.length === 0) {
1264
1031
  return {
1265
1032
  scores: [],
1266
- pagination: { total: 0, page: pagination.page, perPage: pagination.perPage, hasMore: false }
1033
+ pagination: { total: 0, page, perPage: perPageInput, hasMore: false }
1267
1034
  };
1268
1035
  }
1269
1036
  const pipeline = this.client.pipeline();
1270
1037
  keys.forEach((key) => pipeline.get(key));
1271
1038
  const results = await pipeline.exec();
1272
- const filtered = results.map((row) => row).filter((row) => {
1039
+ const filtered = results.map((raw) => {
1040
+ if (!raw) return null;
1041
+ if (typeof raw === "string") {
1042
+ try {
1043
+ return JSON.parse(raw);
1044
+ } catch {
1045
+ return null;
1046
+ }
1047
+ }
1048
+ return raw;
1049
+ }).filter((row) => {
1273
1050
  if (!row || typeof row !== "object") return false;
1274
1051
  if (row.scorerId !== scorerId) return false;
1275
1052
  if (entityId && row.entityId !== entityId) return false;
@@ -1277,10 +1054,10 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1277
1054
  if (source && row.source !== source) return false;
1278
1055
  return true;
1279
1056
  });
1057
+ const perPage = storage.normalizePerPage(perPageInput, 100);
1058
+ const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1059
+ const end = perPageInput === false ? filtered.length : start + perPage;
1280
1060
  const total = filtered.length;
1281
- const { page, perPage } = pagination;
1282
- const start = page * perPage;
1283
- const end = start + perPage;
1284
1061
  const paged = filtered.slice(start, end);
1285
1062
  const scores = paged.map((row) => transformScoreRow(row));
1286
1063
  return {
@@ -1288,7 +1065,7 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1288
1065
  pagination: {
1289
1066
  total,
1290
1067
  page,
1291
- perPage,
1068
+ perPage: perPageForResponse,
1292
1069
  hasMore: end < total
1293
1070
  }
1294
1071
  };
@@ -1296,7 +1073,7 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1296
1073
  async saveScore(score) {
1297
1074
  let validatedScore;
1298
1075
  try {
1299
- validatedScore = scores.saveScorePayloadSchema.parse(score);
1076
+ validatedScore = evals.saveScorePayloadSchema.parse(score);
1300
1077
  } catch (error$1) {
1301
1078
  throw new error.MastraError(
1302
1079
  {
@@ -1323,26 +1100,37 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1323
1100
  );
1324
1101
  }
1325
1102
  }
1326
- async getScoresByRunId({
1103
+ async listScoresByRunId({
1327
1104
  runId,
1328
1105
  pagination = { page: 0, perPage: 20 }
1329
1106
  }) {
1330
1107
  const pattern = `${storage.TABLE_SCORERS}:*`;
1331
1108
  const keys = await this.operations.scanKeys(pattern);
1109
+ const { page, perPage: perPageInput } = pagination;
1332
1110
  if (keys.length === 0) {
1333
1111
  return {
1334
1112
  scores: [],
1335
- pagination: { total: 0, page: pagination.page, perPage: pagination.perPage, hasMore: false }
1113
+ pagination: { total: 0, page, perPage: perPageInput, hasMore: false }
1336
1114
  };
1337
1115
  }
1338
1116
  const pipeline = this.client.pipeline();
1339
1117
  keys.forEach((key) => pipeline.get(key));
1340
1118
  const results = await pipeline.exec();
1341
- const filtered = results.map((row) => row).filter((row) => !!row && typeof row === "object" && row.runId === runId);
1119
+ const filtered = results.map((raw) => {
1120
+ if (!raw) return null;
1121
+ if (typeof raw === "string") {
1122
+ try {
1123
+ return JSON.parse(raw);
1124
+ } catch {
1125
+ return null;
1126
+ }
1127
+ }
1128
+ return raw;
1129
+ }).filter((row) => !!row && typeof row === "object" && row.runId === runId);
1342
1130
  const total = filtered.length;
1343
- const { page, perPage } = pagination;
1344
- const start = page * perPage;
1345
- const end = start + perPage;
1131
+ const perPage = storage.normalizePerPage(perPageInput, 100);
1132
+ const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1133
+ const end = perPageInput === false ? filtered.length : start + perPage;
1346
1134
  const paged = filtered.slice(start, end);
1347
1135
  const scores = paged.map((row) => transformScoreRow(row));
1348
1136
  return {
@@ -1350,37 +1138,48 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1350
1138
  pagination: {
1351
1139
  total,
1352
1140
  page,
1353
- perPage,
1141
+ perPage: perPageForResponse,
1354
1142
  hasMore: end < total
1355
1143
  }
1356
1144
  };
1357
1145
  }
1358
- async getScoresByEntityId({
1146
+ async listScoresByEntityId({
1359
1147
  entityId,
1360
1148
  entityType,
1361
1149
  pagination = { page: 0, perPage: 20 }
1362
1150
  }) {
1363
1151
  const pattern = `${storage.TABLE_SCORERS}:*`;
1364
1152
  const keys = await this.operations.scanKeys(pattern);
1153
+ const { page, perPage: perPageInput } = pagination;
1365
1154
  if (keys.length === 0) {
1366
1155
  return {
1367
1156
  scores: [],
1368
- pagination: { total: 0, page: pagination.page, perPage: pagination.perPage, hasMore: false }
1157
+ pagination: { total: 0, page, perPage: perPageInput, hasMore: false }
1369
1158
  };
1370
1159
  }
1371
1160
  const pipeline = this.client.pipeline();
1372
1161
  keys.forEach((key) => pipeline.get(key));
1373
1162
  const results = await pipeline.exec();
1374
- const filtered = results.map((row) => row).filter((row) => {
1163
+ const filtered = results.map((raw) => {
1164
+ if (!raw) return null;
1165
+ if (typeof raw === "string") {
1166
+ try {
1167
+ return JSON.parse(raw);
1168
+ } catch {
1169
+ return null;
1170
+ }
1171
+ }
1172
+ return raw;
1173
+ }).filter((row) => {
1375
1174
  if (!row || typeof row !== "object") return false;
1376
1175
  if (row.entityId !== entityId) return false;
1377
1176
  if (entityType && row.entityType !== entityType) return false;
1378
1177
  return true;
1379
1178
  });
1380
1179
  const total = filtered.length;
1381
- const { page, perPage } = pagination;
1382
- const start = page * perPage;
1383
- const end = start + perPage;
1180
+ const perPage = storage.normalizePerPage(perPageInput, 100);
1181
+ const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1182
+ const end = perPageInput === false ? filtered.length : start + perPage;
1384
1183
  const paged = filtered.slice(start, end);
1385
1184
  const scores = paged.map((row) => transformScoreRow(row));
1386
1185
  return {
@@ -1388,37 +1187,48 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1388
1187
  pagination: {
1389
1188
  total,
1390
1189
  page,
1391
- perPage,
1190
+ perPage: perPageForResponse,
1392
1191
  hasMore: end < total
1393
1192
  }
1394
1193
  };
1395
1194
  }
1396
- async getScoresBySpan({
1195
+ async listScoresBySpan({
1397
1196
  traceId,
1398
1197
  spanId,
1399
1198
  pagination = { page: 0, perPage: 20 }
1400
1199
  }) {
1401
1200
  const pattern = `${storage.TABLE_SCORERS}:*`;
1402
1201
  const keys = await this.operations.scanKeys(pattern);
1202
+ const { page, perPage: perPageInput } = pagination;
1403
1203
  if (keys.length === 0) {
1404
1204
  return {
1405
1205
  scores: [],
1406
- pagination: { total: 0, page: pagination.page, perPage: pagination.perPage, hasMore: false }
1206
+ pagination: { total: 0, page, perPage: perPageInput, hasMore: false }
1407
1207
  };
1408
1208
  }
1409
1209
  const pipeline = this.client.pipeline();
1410
1210
  keys.forEach((key) => pipeline.get(key));
1411
1211
  const results = await pipeline.exec();
1412
- const filtered = results.map((row) => row).filter((row) => {
1212
+ const filtered = results.map((raw) => {
1213
+ if (!raw) return null;
1214
+ if (typeof raw === "string") {
1215
+ try {
1216
+ return JSON.parse(raw);
1217
+ } catch {
1218
+ return null;
1219
+ }
1220
+ }
1221
+ return raw;
1222
+ }).filter((row) => {
1413
1223
  if (!row || typeof row !== "object") return false;
1414
1224
  if (row.traceId !== traceId) return false;
1415
1225
  if (row.spanId !== spanId) return false;
1416
1226
  return true;
1417
1227
  });
1418
1228
  const total = filtered.length;
1419
- const { page, perPage } = pagination;
1420
- const start = page * perPage;
1421
- const end = start + perPage;
1229
+ const perPage = storage.normalizePerPage(perPageInput, 100);
1230
+ const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1231
+ const end = perPageInput === false ? filtered.length : start + perPage;
1422
1232
  const paged = filtered.slice(start, end);
1423
1233
  const scores = paged.map((row) => transformScoreRow(row));
1424
1234
  return {
@@ -1426,156 +1236,12 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1426
1236
  pagination: {
1427
1237
  total,
1428
1238
  page,
1429
- perPage,
1239
+ perPage: perPageForResponse,
1430
1240
  hasMore: end < total
1431
1241
  }
1432
1242
  };
1433
1243
  }
1434
1244
  };
1435
- var TracesUpstash = class extends storage.TracesStorage {
1436
- client;
1437
- operations;
1438
- constructor({ client, operations }) {
1439
- super();
1440
- this.client = client;
1441
- this.operations = operations;
1442
- }
1443
- /**
1444
- * @deprecated use getTracesPaginated instead
1445
- */
1446
- async getTraces(args) {
1447
- if (args.fromDate || args.toDate) {
1448
- args.dateRange = {
1449
- start: args.fromDate,
1450
- end: args.toDate
1451
- };
1452
- }
1453
- try {
1454
- const { traces } = await this.getTracesPaginated(args);
1455
- return traces;
1456
- } catch (error$1) {
1457
- throw new error.MastraError(
1458
- {
1459
- id: "STORAGE_UPSTASH_STORAGE_GET_TRACES_FAILED",
1460
- domain: error.ErrorDomain.STORAGE,
1461
- category: error.ErrorCategory.THIRD_PARTY
1462
- },
1463
- error$1
1464
- );
1465
- }
1466
- }
1467
- async getTracesPaginated(args) {
1468
- const { name, scope, page = 0, perPage = 100, attributes, filters, dateRange } = args;
1469
- const fromDate = dateRange?.start;
1470
- const toDate = dateRange?.end;
1471
- try {
1472
- const pattern = `${storage.TABLE_TRACES}:*`;
1473
- const keys = await this.operations.scanKeys(pattern);
1474
- if (keys.length === 0) {
1475
- return {
1476
- traces: [],
1477
- total: 0,
1478
- page,
1479
- perPage: perPage || 100,
1480
- hasMore: false
1481
- };
1482
- }
1483
- const pipeline = this.client.pipeline();
1484
- keys.forEach((key) => pipeline.get(key));
1485
- const results = await pipeline.exec();
1486
- let filteredTraces = results.filter(
1487
- (record) => record !== null && typeof record === "object"
1488
- );
1489
- if (name) {
1490
- filteredTraces = filteredTraces.filter((record) => record.name?.toLowerCase().startsWith(name.toLowerCase()));
1491
- }
1492
- if (scope) {
1493
- filteredTraces = filteredTraces.filter((record) => record.scope === scope);
1494
- }
1495
- if (attributes) {
1496
- filteredTraces = filteredTraces.filter((record) => {
1497
- const recordAttributes = record.attributes;
1498
- if (!recordAttributes) return false;
1499
- const parsedAttributes = typeof recordAttributes === "string" ? JSON.parse(recordAttributes) : recordAttributes;
1500
- return Object.entries(attributes).every(([key, value]) => parsedAttributes[key] === value);
1501
- });
1502
- }
1503
- if (filters) {
1504
- filteredTraces = filteredTraces.filter(
1505
- (record) => Object.entries(filters).every(([key, value]) => record[key] === value)
1506
- );
1507
- }
1508
- if (fromDate) {
1509
- filteredTraces = filteredTraces.filter(
1510
- (record) => new Date(record.createdAt).getTime() >= new Date(fromDate).getTime()
1511
- );
1512
- }
1513
- if (toDate) {
1514
- filteredTraces = filteredTraces.filter(
1515
- (record) => new Date(record.createdAt).getTime() <= new Date(toDate).getTime()
1516
- );
1517
- }
1518
- filteredTraces.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
1519
- const transformedTraces = filteredTraces.map((record) => ({
1520
- id: record.id,
1521
- parentSpanId: record.parentSpanId,
1522
- traceId: record.traceId,
1523
- name: record.name,
1524
- scope: record.scope,
1525
- kind: record.kind,
1526
- status: parseJSON(record.status),
1527
- events: parseJSON(record.events),
1528
- links: parseJSON(record.links),
1529
- attributes: parseJSON(record.attributes),
1530
- startTime: record.startTime,
1531
- endTime: record.endTime,
1532
- other: parseJSON(record.other),
1533
- createdAt: ensureDate(record.createdAt)
1534
- }));
1535
- const total = transformedTraces.length;
1536
- const resolvedPerPage = perPage || 100;
1537
- const start = page * resolvedPerPage;
1538
- const end = start + resolvedPerPage;
1539
- const paginatedTraces = transformedTraces.slice(start, end);
1540
- const hasMore = end < total;
1541
- return {
1542
- traces: paginatedTraces,
1543
- total,
1544
- page,
1545
- perPage: resolvedPerPage,
1546
- hasMore
1547
- };
1548
- } catch (error$1) {
1549
- const mastraError = new error.MastraError(
1550
- {
1551
- id: "STORAGE_UPSTASH_STORAGE_GET_TRACES_PAGINATED_FAILED",
1552
- domain: error.ErrorDomain.STORAGE,
1553
- category: error.ErrorCategory.THIRD_PARTY,
1554
- details: {
1555
- name: args.name || "",
1556
- scope: args.scope || ""
1557
- }
1558
- },
1559
- error$1
1560
- );
1561
- this.logger?.trackException(mastraError);
1562
- this.logger.error(mastraError.toString());
1563
- return {
1564
- traces: [],
1565
- total: 0,
1566
- page,
1567
- perPage: perPage || 100,
1568
- hasMore: false
1569
- };
1570
- }
1571
- }
1572
- async batchTraceInsert(args) {
1573
- return this.operations.batchInsert({
1574
- tableName: storage.TABLE_TRACES,
1575
- records: args.records
1576
- });
1577
- }
1578
- };
1579
1245
  function parseWorkflowRun(row) {
1580
1246
  let parsedSnapshot = row.snapshot;
1581
1247
  if (typeof parsedSnapshot === "string") {
@@ -1607,7 +1273,7 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1607
1273
  // runId,
1608
1274
  // stepId,
1609
1275
  // result,
1610
- // runtimeContext,
1276
+ // requestContext,
1611
1277
  }) {
1612
1278
  throw new Error("Method not implemented.");
1613
1279
  }
@@ -1708,15 +1374,26 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1708
1374
  );
1709
1375
  }
1710
1376
  }
1711
- async getWorkflowRuns({
1377
+ async listWorkflowRuns({
1712
1378
  workflowName,
1713
1379
  fromDate,
1714
1380
  toDate,
1715
- limit,
1716
- offset,
1381
+ perPage,
1382
+ page,
1717
1383
  resourceId
1718
1384
  }) {
1719
1385
  try {
1386
+ if (page !== void 0 && page < 0) {
1387
+ throw new error.MastraError(
1388
+ {
1389
+ id: "UPSTASH_STORE_INVALID_PAGE",
1390
+ domain: error.ErrorDomain.STORAGE,
1391
+ category: error.ErrorCategory.USER,
1392
+ details: { page }
1393
+ },
1394
+ new Error("page must be >= 0")
1395
+ );
1396
+ }
1720
1397
  let pattern = getKey(storage.TABLE_WORKFLOW_SNAPSHOT, { namespace: "workflows" }) + ":*";
1721
1398
  if (workflowName && resourceId) {
1722
1399
  pattern = getKey(storage.TABLE_WORKFLOW_SNAPSHOT, {
@@ -1750,14 +1427,16 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1750
1427
  return true;
1751
1428
  }).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
1752
1429
  const total = runs.length;
1753
- if (limit !== void 0 && offset !== void 0) {
1754
- runs = runs.slice(offset, offset + limit);
1430
+ if (typeof perPage === "number" && typeof page === "number") {
1431
+ const normalizedPerPage = storage.normalizePerPage(perPage, Number.MAX_SAFE_INTEGER);
1432
+ const offset = page * normalizedPerPage;
1433
+ runs = runs.slice(offset, offset + normalizedPerPage);
1755
1434
  }
1756
1435
  return { runs, total };
1757
1436
  } catch (error$1) {
1758
1437
  throw new error.MastraError(
1759
1438
  {
1760
- id: "STORAGE_UPSTASH_STORAGE_GET_WORKFLOW_RUNS_FAILED",
1439
+ id: "STORAGE_UPSTASH_STORAGE_LIST_WORKFLOW_RUNS_FAILED",
1761
1440
  domain: error.ErrorDomain.STORAGE,
1762
1441
  category: error.ErrorCategory.THIRD_PARTY,
1763
1442
  details: {
@@ -1777,24 +1456,20 @@ var UpstashStore = class extends storage.MastraStorage {
1777
1456
  redis;
1778
1457
  stores;
1779
1458
  constructor(config) {
1780
- super({ name: "Upstash" });
1459
+ super({ id: config.id, name: "Upstash" });
1781
1460
  this.redis = new redis.Redis({
1782
1461
  url: config.url,
1783
1462
  token: config.token
1784
1463
  });
1785
1464
  const operations = new StoreOperationsUpstash({ client: this.redis });
1786
- const traces = new TracesUpstash({ client: this.redis, operations });
1787
1465
  const scores = new ScoresUpstash({ client: this.redis, operations });
1788
1466
  const workflows = new WorkflowsUpstash({ client: this.redis, operations });
1789
1467
  const memory = new StoreMemoryUpstash({ client: this.redis, operations });
1790
- const legacyEvals = new StoreLegacyEvalsUpstash({ client: this.redis, operations });
1791
1468
  this.stores = {
1792
1469
  operations,
1793
- traces,
1794
1470
  scores,
1795
1471
  workflows,
1796
- memory,
1797
- legacyEvals
1472
+ memory
1798
1473
  };
1799
1474
  }
1800
1475
  get supports() {
@@ -1804,35 +1479,9 @@ var UpstashStore = class extends storage.MastraStorage {
1804
1479
  hasColumn: false,
1805
1480
  createTable: false,
1806
1481
  deleteMessages: true,
1807
- getScoresBySpan: true
1482
+ listScoresBySpan: true
1808
1483
  };
1809
1484
  }
1810
- /**
1811
- * @deprecated Use getEvals instead
1812
- */
1813
- async getEvalsByAgentName(agentName, type) {
1814
- return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
1815
- }
1816
- /**
1817
- * Get all evaluations with pagination and total count
1818
- * @param options Pagination and filtering options
1819
- * @returns Object with evals array and total count
1820
- */
1821
- async getEvals(options) {
1822
- return this.stores.legacyEvals.getEvals(options);
1823
- }
1824
- /**
1825
- * @deprecated use getTracesPaginated instead
1826
- */
1827
- async getTraces(args) {
1828
- return this.stores.traces.getTraces(args);
1829
- }
1830
- async getTracesPaginated(args) {
1831
- return this.stores.traces.getTracesPaginated(args);
1832
- }
1833
- async batchTraceInsert(args) {
1834
- return this.stores.traces.batchTraceInsert(args);
1835
- }
1836
1485
  async createTable({
1837
1486
  tableName,
1838
1487
  schema
@@ -1866,15 +1515,6 @@ var UpstashStore = class extends storage.MastraStorage {
1866
1515
  async getThreadById({ threadId }) {
1867
1516
  return this.stores.memory.getThreadById({ threadId });
1868
1517
  }
1869
- /**
1870
- * @deprecated use getThreadsByResourceIdPaginated instead
1871
- */
1872
- async getThreadsByResourceId({ resourceId }) {
1873
- return this.stores.memory.getThreadsByResourceId({ resourceId });
1874
- }
1875
- async getThreadsByResourceIdPaginated(args) {
1876
- return this.stores.memory.getThreadsByResourceIdPaginated(args);
1877
- }
1878
1518
  async saveThread({ thread }) {
1879
1519
  return this.stores.memory.saveThread({ thread });
1880
1520
  }
@@ -1891,30 +1531,17 @@ var UpstashStore = class extends storage.MastraStorage {
1891
1531
  async saveMessages(args) {
1892
1532
  return this.stores.memory.saveMessages(args);
1893
1533
  }
1894
- async getMessages({
1895
- threadId,
1896
- selectBy,
1897
- format
1898
- }) {
1899
- return this.stores.memory.getMessages({ threadId, selectBy, format });
1900
- }
1901
- async getMessagesById({
1902
- messageIds,
1903
- format
1904
- }) {
1905
- return this.stores.memory.getMessagesById({ messageIds, format });
1906
- }
1907
- async getMessagesPaginated(args) {
1908
- return this.stores.memory.getMessagesPaginated(args);
1534
+ async listMessagesById({ messageIds }) {
1535
+ return this.stores.memory.listMessagesById({ messageIds });
1909
1536
  }
1910
1537
  async updateWorkflowResults({
1911
1538
  workflowName,
1912
1539
  runId,
1913
1540
  stepId,
1914
1541
  result,
1915
- runtimeContext
1542
+ requestContext
1916
1543
  }) {
1917
- return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
1544
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
1918
1545
  }
1919
1546
  async updateWorkflowState({
1920
1547
  workflowName,
@@ -1929,15 +1556,15 @@ var UpstashStore = class extends storage.MastraStorage {
1929
1556
  async loadWorkflowSnapshot(params) {
1930
1557
  return this.stores.workflows.loadWorkflowSnapshot(params);
1931
1558
  }
1932
- async getWorkflowRuns({
1559
+ async listWorkflowRuns({
1933
1560
  workflowName,
1934
1561
  fromDate,
1935
1562
  toDate,
1936
- limit,
1937
- offset,
1563
+ perPage,
1564
+ page,
1938
1565
  resourceId
1939
1566
  } = {}) {
1940
- return this.stores.workflows.getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId });
1567
+ return this.stores.workflows.listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId });
1941
1568
  }
1942
1569
  async getWorkflowRunById({
1943
1570
  runId,
@@ -1972,38 +1599,38 @@ var UpstashStore = class extends storage.MastraStorage {
1972
1599
  async saveScore(score) {
1973
1600
  return this.stores.scores.saveScore(score);
1974
1601
  }
1975
- async getScoresByRunId({
1602
+ async listScoresByRunId({
1976
1603
  runId,
1977
1604
  pagination
1978
1605
  }) {
1979
- return this.stores.scores.getScoresByRunId({ runId, pagination });
1606
+ return this.stores.scores.listScoresByRunId({ runId, pagination });
1980
1607
  }
1981
- async getScoresByEntityId({
1608
+ async listScoresByEntityId({
1982
1609
  entityId,
1983
1610
  entityType,
1984
1611
  pagination
1985
1612
  }) {
1986
- return this.stores.scores.getScoresByEntityId({
1613
+ return this.stores.scores.listScoresByEntityId({
1987
1614
  entityId,
1988
1615
  entityType,
1989
1616
  pagination
1990
1617
  });
1991
1618
  }
1992
- async getScoresByScorerId({
1619
+ async listScoresByScorerId({
1993
1620
  scorerId,
1994
1621
  pagination,
1995
1622
  entityId,
1996
1623
  entityType,
1997
1624
  source
1998
1625
  }) {
1999
- return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
1626
+ return this.stores.scores.listScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
2000
1627
  }
2001
- async getScoresBySpan({
1628
+ async listScoresBySpan({
2002
1629
  traceId,
2003
1630
  spanId,
2004
1631
  pagination
2005
1632
  }) {
2006
- return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
1633
+ return this.stores.scores.listScoresBySpan({ traceId, spanId, pagination });
2007
1634
  }
2008
1635
  };
2009
1636
  var UpstashFilterTranslator = class extends filter.BaseFilterTranslator {
@@ -2204,11 +1831,12 @@ var UpstashVector = class extends vector.MastraVector {
2204
1831
  /**
2205
1832
  * Creates a new UpstashVector instance.
2206
1833
  * @param {object} params - The parameters for the UpstashVector.
1834
+ * @param {string} params.id - The unique identifier for this vector store instance.
2207
1835
  * @param {string} params.url - The URL of the Upstash vector index.
2208
1836
  * @param {string} params.token - The token for the Upstash vector index.
2209
1837
  */
2210
- constructor({ url, token }) {
2211
- super();
1838
+ constructor({ url, token, id }) {
1839
+ super({ id });
2212
1840
  this.client = new vector$1.Index({
2213
1841
  url,
2214
1842
  token