@mastra/upstash 1.0.0-beta.2 → 1.0.0-beta.4

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
@@ -54,6 +54,9 @@ function getMessageKey(threadId, messageId) {
54
54
  const key = getKey(storage.TABLE_MESSAGES, { threadId, id: messageId });
55
55
  return key;
56
56
  }
57
+ function getMessageIndexKey(messageId) {
58
+ return `msg-idx:${messageId}`;
59
+ }
57
60
  var StoreMemoryUpstash = class extends storage.MemoryStorage {
58
61
  client;
59
62
  operations;
@@ -78,7 +81,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
78
81
  } catch (error$1) {
79
82
  throw new error.MastraError(
80
83
  {
81
- id: "STORAGE_UPSTASH_STORAGE_GET_THREAD_BY_ID_FAILED",
84
+ id: storage.createStorageErrorId("UPSTASH", "GET_THREAD_BY_ID", "FAILED"),
82
85
  domain: error.ErrorDomain.STORAGE,
83
86
  category: error.ErrorCategory.THIRD_PARTY,
84
87
  details: {
@@ -96,7 +99,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
96
99
  if (page < 0) {
97
100
  throw new error.MastraError(
98
101
  {
99
- id: "STORAGE_UPSTASH_LIST_THREADS_BY_RESOURCE_ID_INVALID_PAGE",
102
+ id: storage.createStorageErrorId("UPSTASH", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
100
103
  domain: error.ErrorDomain.STORAGE,
101
104
  category: error.ErrorCategory.USER,
102
105
  details: { page }
@@ -138,7 +141,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
138
141
  } catch (error$1) {
139
142
  const mastraError = new error.MastraError(
140
143
  {
141
- id: "STORAGE_UPSTASH_STORAGE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
144
+ id: storage.createStorageErrorId("UPSTASH", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
142
145
  domain: error.ErrorDomain.STORAGE,
143
146
  category: error.ErrorCategory.THIRD_PARTY,
144
147
  details: {
@@ -170,7 +173,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
170
173
  } catch (error$1) {
171
174
  const mastraError = new error.MastraError(
172
175
  {
173
- id: "STORAGE_UPSTASH_STORAGE_SAVE_THREAD_FAILED",
176
+ id: storage.createStorageErrorId("UPSTASH", "SAVE_THREAD", "FAILED"),
174
177
  domain: error.ErrorDomain.STORAGE,
175
178
  category: error.ErrorCategory.THIRD_PARTY,
176
179
  details: {
@@ -192,7 +195,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
192
195
  const thread = await this.getThreadById({ threadId: id });
193
196
  if (!thread) {
194
197
  throw new error.MastraError({
195
- id: "STORAGE_UPSTASH_STORAGE_UPDATE_THREAD_FAILED",
198
+ id: storage.createStorageErrorId("UPSTASH", "UPDATE_THREAD", "FAILED"),
196
199
  domain: error.ErrorDomain.STORAGE,
197
200
  category: error.ErrorCategory.USER,
198
201
  text: `Thread ${id} not found`,
@@ -215,7 +218,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
215
218
  } catch (error$1) {
216
219
  throw new error.MastraError(
217
220
  {
218
- id: "STORAGE_UPSTASH_STORAGE_UPDATE_THREAD_FAILED",
221
+ id: storage.createStorageErrorId("UPSTASH", "UPDATE_THREAD", "FAILED"),
219
222
  domain: error.ErrorDomain.STORAGE,
220
223
  category: error.ErrorCategory.THIRD_PARTY,
221
224
  details: {
@@ -244,7 +247,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
244
247
  } catch (error$1) {
245
248
  throw new error.MastraError(
246
249
  {
247
- id: "STORAGE_UPSTASH_STORAGE_DELETE_THREAD_FAILED",
250
+ id: storage.createStorageErrorId("UPSTASH", "DELETE_THREAD", "FAILED"),
248
251
  domain: error.ErrorDomain.STORAGE,
249
252
  category: error.ErrorCategory.THIRD_PARTY,
250
253
  details: {
@@ -270,7 +273,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
270
273
  } catch (error$1) {
271
274
  throw new error.MastraError(
272
275
  {
273
- id: "STORAGE_UPSTASH_STORAGE_SAVE_MESSAGES_INVALID_ARGS",
276
+ id: storage.createStorageErrorId("UPSTASH", "SAVE_MESSAGES", "INVALID_ARGS"),
274
277
  domain: error.ErrorDomain.STORAGE,
275
278
  category: error.ErrorCategory.USER
276
279
  },
@@ -320,6 +323,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
320
323
  }
321
324
  }
322
325
  pipeline.set(key, message);
326
+ pipeline.set(getMessageIndexKey(message.id), message.threadId);
323
327
  pipeline.zadd(getThreadMessagesKey(message.threadId), {
324
328
  score,
325
329
  member: message.id
@@ -339,7 +343,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
339
343
  } catch (error$1) {
340
344
  throw new error.MastraError(
341
345
  {
342
- id: "STORAGE_UPSTASH_STORAGE_SAVE_MESSAGES_FAILED",
346
+ id: storage.createStorageErrorId("UPSTASH", "SAVE_MESSAGES", "FAILED"),
343
347
  domain: error.ErrorDomain.STORAGE,
344
348
  category: error.ErrorCategory.THIRD_PARTY,
345
349
  details: {
@@ -350,43 +354,60 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
350
354
  );
351
355
  }
352
356
  }
353
- async _getIncludedMessages(threadId, include) {
354
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
357
+ /**
358
+ * Lookup threadId for a message - tries index first (O(1)), falls back to scan (backwards compatible)
359
+ */
360
+ async _getThreadIdForMessage(messageId) {
361
+ const indexedThreadId = await this.client.get(getMessageIndexKey(messageId));
362
+ if (indexedThreadId) {
363
+ return indexedThreadId;
364
+ }
365
+ const existingKeyPattern = getMessageKey("*", messageId);
366
+ const keys = await this.operations.scanKeys(existingKeyPattern);
367
+ if (keys.length === 0) return null;
368
+ const messageData = await this.client.get(keys[0]);
369
+ if (!messageData) return null;
370
+ if (messageData.threadId) {
371
+ await this.client.set(getMessageIndexKey(messageId), messageData.threadId);
372
+ }
373
+ return messageData.threadId || null;
374
+ }
375
+ async _getIncludedMessages(include) {
376
+ if (!include?.length) return [];
355
377
  const messageIds = /* @__PURE__ */ new Set();
356
378
  const messageIdToThreadIds = {};
357
- if (include?.length) {
358
- for (const item of include) {
359
- messageIds.add(item.id);
360
- const itemThreadId = item.threadId || threadId;
361
- messageIdToThreadIds[item.id] = itemThreadId;
362
- const itemThreadMessagesKey = getThreadMessagesKey(itemThreadId);
363
- const rank = await this.client.zrank(itemThreadMessagesKey, item.id);
364
- if (rank === null) continue;
365
- if (item.withPreviousMessages) {
366
- const start = Math.max(0, rank - item.withPreviousMessages);
367
- const prevIds = rank === 0 ? [] : await this.client.zrange(itemThreadMessagesKey, start, rank - 1);
368
- prevIds.forEach((id) => {
369
- messageIds.add(id);
370
- messageIdToThreadIds[id] = itemThreadId;
371
- });
372
- }
373
- if (item.withNextMessages) {
374
- const nextIds = await this.client.zrange(itemThreadMessagesKey, rank + 1, rank + item.withNextMessages);
375
- nextIds.forEach((id) => {
376
- messageIds.add(id);
377
- messageIdToThreadIds[id] = itemThreadId;
378
- });
379
- }
379
+ for (const item of include) {
380
+ const itemThreadId = await this._getThreadIdForMessage(item.id);
381
+ if (!itemThreadId) continue;
382
+ messageIds.add(item.id);
383
+ messageIdToThreadIds[item.id] = itemThreadId;
384
+ const itemThreadMessagesKey = getThreadMessagesKey(itemThreadId);
385
+ const rank = await this.client.zrank(itemThreadMessagesKey, item.id);
386
+ if (rank === null) continue;
387
+ if (item.withPreviousMessages) {
388
+ const start = Math.max(0, rank - item.withPreviousMessages);
389
+ const prevIds = rank === 0 ? [] : await this.client.zrange(itemThreadMessagesKey, start, rank - 1);
390
+ prevIds.forEach((id) => {
391
+ messageIds.add(id);
392
+ messageIdToThreadIds[id] = itemThreadId;
393
+ });
394
+ }
395
+ if (item.withNextMessages) {
396
+ const nextIds = await this.client.zrange(itemThreadMessagesKey, rank + 1, rank + item.withNextMessages);
397
+ nextIds.forEach((id) => {
398
+ messageIds.add(id);
399
+ messageIdToThreadIds[id] = itemThreadId;
400
+ });
380
401
  }
381
- const pipeline = this.client.pipeline();
382
- Array.from(messageIds).forEach((id) => {
383
- const tId = messageIdToThreadIds[id] || threadId;
384
- pipeline.get(getMessageKey(tId, id));
385
- });
386
- const results = await pipeline.exec();
387
- return results.filter((result) => result !== null);
388
402
  }
389
- return [];
403
+ if (messageIds.size === 0) return [];
404
+ const pipeline = this.client.pipeline();
405
+ Array.from(messageIds).forEach((id) => {
406
+ const tId = messageIdToThreadIds[id];
407
+ pipeline.get(getMessageKey(tId, id));
408
+ });
409
+ const results = await pipeline.exec();
410
+ return results.filter((result) => result !== null);
390
411
  }
391
412
  parseStoredMessage(storedMessage) {
392
413
  const defaultMessageContent = { format: 2, parts: [{ type: "text", text: "" }] };
@@ -400,23 +421,55 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
400
421
  async listMessagesById({ messageIds }) {
401
422
  if (messageIds.length === 0) return { messages: [] };
402
423
  try {
403
- const threadKeys = await this.client.keys("thread:*");
404
- const result = await Promise.all(
405
- threadKeys.map((threadKey) => {
406
- const threadId = threadKey.split(":")[1];
407
- if (!threadId) throw new Error(`Failed to parse thread ID from thread key "${threadKey}"`);
408
- return this.client.mget(
409
- messageIds.map((id) => getMessageKey(threadId, id))
410
- );
411
- })
412
- );
413
- const rawMessages = result.flat(1).filter((msg) => !!msg);
424
+ const rawMessages = [];
425
+ const indexPipeline = this.client.pipeline();
426
+ messageIds.forEach((id) => indexPipeline.get(getMessageIndexKey(id)));
427
+ const indexResults = await indexPipeline.exec();
428
+ const indexedIds = [];
429
+ const unindexedIds = [];
430
+ messageIds.forEach((id, i) => {
431
+ const threadId = indexResults[i];
432
+ if (threadId) {
433
+ indexedIds.push({ messageId: id, threadId });
434
+ } else {
435
+ unindexedIds.push(id);
436
+ }
437
+ });
438
+ if (indexedIds.length > 0) {
439
+ const messagePipeline = this.client.pipeline();
440
+ indexedIds.forEach(({ messageId, threadId }) => messagePipeline.get(getMessageKey(threadId, messageId)));
441
+ const messageResults = await messagePipeline.exec();
442
+ rawMessages.push(...messageResults.filter((msg) => msg !== null));
443
+ }
444
+ if (unindexedIds.length > 0) {
445
+ const threadKeys = await this.client.keys("thread:*");
446
+ const result = await Promise.all(
447
+ threadKeys.map((threadKey) => {
448
+ const threadId = threadKey.split(":")[1];
449
+ if (!threadId) throw new Error(`Failed to parse thread ID from thread key "${threadKey}"`);
450
+ return this.client.mget(
451
+ unindexedIds.map((id) => getMessageKey(threadId, id))
452
+ );
453
+ })
454
+ );
455
+ const foundMessages = result.flat(1).filter((msg) => !!msg);
456
+ rawMessages.push(...foundMessages);
457
+ if (foundMessages.length > 0) {
458
+ const backfillPipeline = this.client.pipeline();
459
+ foundMessages.forEach((msg) => {
460
+ if (msg.threadId) {
461
+ backfillPipeline.set(getMessageIndexKey(msg.id), msg.threadId);
462
+ }
463
+ });
464
+ await backfillPipeline.exec();
465
+ }
466
+ }
414
467
  const list = new agent.MessageList().add(rawMessages.map(this.parseStoredMessage), "memory");
415
468
  return { messages: list.get.all.db() };
416
469
  } catch (error$1) {
417
470
  throw new error.MastraError(
418
471
  {
419
- id: "STORAGE_UPSTASH_STORAGE_LIST_MESSAGES_BY_ID_FAILED",
472
+ id: storage.createStorageErrorId("UPSTASH", "LIST_MESSAGES_BY_ID", "FAILED"),
420
473
  domain: error.ErrorDomain.STORAGE,
421
474
  category: error.ErrorCategory.THIRD_PARTY,
422
475
  details: {
@@ -429,25 +482,25 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
429
482
  }
430
483
  async listMessages(args) {
431
484
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
432
- if (!threadId.trim()) {
485
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
486
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
433
487
  throw new error.MastraError(
434
488
  {
435
- id: "STORAGE_UPSTASH_LIST_MESSAGES_INVALID_THREAD_ID",
489
+ id: storage.createStorageErrorId("UPSTASH", "LIST_MESSAGES", "INVALID_THREAD_ID"),
436
490
  domain: error.ErrorDomain.STORAGE,
437
491
  category: error.ErrorCategory.THIRD_PARTY,
438
- details: { threadId }
492
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
439
493
  },
440
- new Error("threadId must be a non-empty string")
494
+ new Error("threadId must be a non-empty string or array of non-empty strings")
441
495
  );
442
496
  }
443
- const threadMessagesKey = getThreadMessagesKey(threadId);
444
497
  const perPage = storage.normalizePerPage(perPageInput, 40);
445
498
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
446
499
  try {
447
500
  if (page < 0) {
448
501
  throw new error.MastraError(
449
502
  {
450
- id: "STORAGE_UPSTASH_LIST_MESSAGES_INVALID_PAGE",
503
+ id: storage.createStorageErrorId("UPSTASH", "LIST_MESSAGES", "INVALID_PAGE"),
451
504
  domain: error.ErrorDomain.STORAGE,
452
505
  category: error.ErrorCategory.USER,
453
506
  details: { page }
@@ -457,11 +510,18 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
457
510
  }
458
511
  let includedMessages = [];
459
512
  if (include && include.length > 0) {
460
- const included = await this._getIncludedMessages(threadId, include);
513
+ const included = await this._getIncludedMessages(include);
461
514
  includedMessages = included.map(this.parseStoredMessage);
462
515
  }
463
- const allMessageIds = await this.client.zrange(threadMessagesKey, 0, -1);
464
- if (allMessageIds.length === 0) {
516
+ const allMessageIdsWithThreads = [];
517
+ for (const tid of threadIds) {
518
+ const threadMessagesKey = getThreadMessagesKey(tid);
519
+ const messageIds2 = await this.client.zrange(threadMessagesKey, 0, -1);
520
+ for (const mid of messageIds2) {
521
+ allMessageIdsWithThreads.push({ threadId: tid, messageId: mid });
522
+ }
523
+ }
524
+ if (allMessageIdsWithThreads.length === 0) {
465
525
  return {
466
526
  messages: [],
467
527
  total: 0,
@@ -471,7 +531,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
471
531
  };
472
532
  }
473
533
  const pipeline = this.client.pipeline();
474
- allMessageIds.forEach((id) => pipeline.get(getMessageKey(threadId, id)));
534
+ allMessageIdsWithThreads.forEach(({ threadId: tid, messageId }) => pipeline.get(getMessageKey(tid, messageId)));
475
535
  const results = await pipeline.exec();
476
536
  let messagesData = results.filter((msg) => msg !== null).map(this.parseStoredMessage);
477
537
  if (resourceId) {
@@ -543,11 +603,11 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
543
603
  } catch (error$1) {
544
604
  const mastraError = new error.MastraError(
545
605
  {
546
- id: "STORAGE_UPSTASH_STORAGE_LIST_MESSAGES_FAILED",
606
+ id: storage.createStorageErrorId("UPSTASH", "LIST_MESSAGES", "FAILED"),
547
607
  domain: error.ErrorDomain.STORAGE,
548
608
  category: error.ErrorCategory.THIRD_PARTY,
549
609
  details: {
550
- threadId,
610
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
551
611
  resourceId: resourceId ?? ""
552
612
  }
553
613
  },
@@ -734,7 +794,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
734
794
  } catch (error$1) {
735
795
  throw new error.MastraError(
736
796
  {
737
- id: "STORAGE_UPSTASH_STORAGE_UPDATE_MESSAGES_FAILED",
797
+ id: storage.createStorageErrorId("UPSTASH", "UPDATE_MESSAGES", "FAILED"),
738
798
  domain: error.ErrorDomain.STORAGE,
739
799
  category: error.ErrorCategory.THIRD_PARTY,
740
800
  details: {
@@ -752,13 +812,33 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
752
812
  try {
753
813
  const threadIds = /* @__PURE__ */ new Set();
754
814
  const messageKeys = [];
755
- for (const messageId of messageIds) {
815
+ const foundMessageIds = [];
816
+ const indexPipeline = this.client.pipeline();
817
+ messageIds.forEach((id) => indexPipeline.get(getMessageIndexKey(id)));
818
+ const indexResults = await indexPipeline.exec();
819
+ const indexedMessages = [];
820
+ const unindexedMessageIds = [];
821
+ messageIds.forEach((id, i) => {
822
+ const threadId = indexResults[i];
823
+ if (threadId) {
824
+ indexedMessages.push({ messageId: id, threadId });
825
+ } else {
826
+ unindexedMessageIds.push(id);
827
+ }
828
+ });
829
+ for (const { messageId, threadId } of indexedMessages) {
830
+ messageKeys.push(getMessageKey(threadId, messageId));
831
+ foundMessageIds.push(messageId);
832
+ threadIds.add(threadId);
833
+ }
834
+ for (const messageId of unindexedMessageIds) {
756
835
  const pattern = getMessageKey("*", messageId);
757
836
  const keys = await this.operations.scanKeys(pattern);
758
837
  for (const key of keys) {
759
838
  const message = await this.client.get(key);
760
839
  if (message && message.id === messageId) {
761
840
  messageKeys.push(key);
841
+ foundMessageIds.push(messageId);
762
842
  if (message.threadId) {
763
843
  threadIds.add(message.threadId);
764
844
  }
@@ -773,6 +853,9 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
773
853
  for (const key of messageKeys) {
774
854
  pipeline.del(key);
775
855
  }
856
+ for (const messageId of foundMessageIds) {
857
+ pipeline.del(getMessageIndexKey(messageId));
858
+ }
776
859
  if (threadIds.size > 0) {
777
860
  for (const threadId of threadIds) {
778
861
  const threadKey = getKey(storage.TABLE_THREADS, { id: threadId });
@@ -790,7 +873,7 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
790
873
  } catch (error$1) {
791
874
  throw new error.MastraError(
792
875
  {
793
- id: "STORAGE_UPSTASH_DELETE_MESSAGES_FAILED",
876
+ id: storage.createStorageErrorId("UPSTASH", "DELETE_MESSAGES", "FAILED"),
794
877
  domain: error.ErrorDomain.STORAGE,
795
878
  category: error.ErrorCategory.THIRD_PARTY,
796
879
  details: { messageIds: messageIds.join(", ") }
@@ -835,7 +918,7 @@ var StoreOperationsUpstash = class extends storage.StoreOperations {
835
918
  } catch (error$1) {
836
919
  throw new error.MastraError(
837
920
  {
838
- id: "STORAGE_UPSTASH_STORAGE_CLEAR_TABLE_FAILED",
921
+ id: storage.createStorageErrorId("UPSTASH", "CLEAR_TABLE", "FAILED"),
839
922
  domain: error.ErrorDomain.STORAGE,
840
923
  category: error.ErrorCategory.THIRD_PARTY,
841
924
  details: {
@@ -856,7 +939,7 @@ var StoreOperationsUpstash = class extends storage.StoreOperations {
856
939
  } catch (error$1) {
857
940
  throw new error.MastraError(
858
941
  {
859
- id: "STORAGE_UPSTASH_STORAGE_INSERT_FAILED",
942
+ id: storage.createStorageErrorId("UPSTASH", "INSERT", "FAILED"),
860
943
  domain: error.ErrorDomain.STORAGE,
861
944
  category: error.ErrorCategory.THIRD_PARTY,
862
945
  details: {
@@ -884,7 +967,7 @@ var StoreOperationsUpstash = class extends storage.StoreOperations {
884
967
  } catch (error$1) {
885
968
  throw new error.MastraError(
886
969
  {
887
- id: "STORAGE_UPSTASH_STORAGE_BATCH_INSERT_FAILED",
970
+ id: storage.createStorageErrorId("UPSTASH", "BATCH_INSERT", "FAILED"),
888
971
  domain: error.ErrorDomain.STORAGE,
889
972
  category: error.ErrorCategory.THIRD_PARTY,
890
973
  details: {
@@ -903,7 +986,7 @@ var StoreOperationsUpstash = class extends storage.StoreOperations {
903
986
  } catch (error$1) {
904
987
  throw new error.MastraError(
905
988
  {
906
- id: "STORAGE_UPSTASH_STORAGE_LOAD_FAILED",
989
+ id: storage.createStorageErrorId("UPSTASH", "LOAD", "FAILED"),
907
990
  domain: error.ErrorDomain.STORAGE,
908
991
  category: error.ErrorCategory.THIRD_PARTY,
909
992
  details: {
@@ -948,32 +1031,7 @@ var StoreOperationsUpstash = class extends storage.StoreOperations {
948
1031
  }
949
1032
  };
950
1033
  function transformScoreRow(row) {
951
- const parseField = (v) => {
952
- if (typeof v === "string") {
953
- try {
954
- return JSON.parse(v);
955
- } catch {
956
- return v;
957
- }
958
- }
959
- return v;
960
- };
961
- return {
962
- ...row,
963
- scorer: parseField(row.scorer),
964
- preprocessStepResult: parseField(row.preprocessStepResult),
965
- generateScorePrompt: row.generateScorePrompt,
966
- generateReasonPrompt: row.generateReasonPrompt,
967
- analyzeStepResult: parseField(row.analyzeStepResult),
968
- metadata: parseField(row.metadata),
969
- input: parseField(row.input),
970
- output: parseField(row.output),
971
- additionalContext: parseField(row.additionalContext),
972
- requestContext: parseField(row.requestContext),
973
- entity: parseField(row.entity),
974
- createdAt: row.createdAt,
975
- updatedAt: row.updatedAt
976
- };
1034
+ return storage.transformScoreRow(row);
977
1035
  }
978
1036
  var ScoresUpstash = class extends storage.ScoresStorage {
979
1037
  client;
@@ -994,7 +1052,7 @@ var ScoresUpstash = class extends storage.ScoresStorage {
994
1052
  } catch (error$1) {
995
1053
  throw new error.MastraError(
996
1054
  {
997
- id: "STORAGE_UPSTASH_STORAGE_GET_SCORE_BY_ID_FAILED",
1055
+ id: storage.createStorageErrorId("UPSTASH", "GET_SCORE_BY_ID", "FAILED"),
998
1056
  domain: error.ErrorDomain.STORAGE,
999
1057
  category: error.ErrorCategory.THIRD_PARTY,
1000
1058
  details: {
@@ -1065,7 +1123,7 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1065
1123
  } catch (error$1) {
1066
1124
  throw new error.MastraError(
1067
1125
  {
1068
- id: "STORAGE_UPSTASH_STORAGE_SAVE_SCORE_VALIDATION_FAILED",
1126
+ id: storage.createStorageErrorId("UPSTASH", "SAVE_SCORE", "VALIDATION_FAILED"),
1069
1127
  domain: error.ErrorDomain.STORAGE,
1070
1128
  category: error.ErrorCategory.THIRD_PARTY
1071
1129
  },
@@ -1079,7 +1137,7 @@ var ScoresUpstash = class extends storage.ScoresStorage {
1079
1137
  } catch (error$1) {
1080
1138
  throw new error.MastraError(
1081
1139
  {
1082
- id: "STORAGE_UPSTASH_STORAGE_SAVE_SCORE_FAILED",
1140
+ id: storage.createStorageErrorId("UPSTASH", "SAVE_SCORE", "FAILED"),
1083
1141
  domain: error.ErrorDomain.STORAGE,
1084
1142
  category: error.ErrorCategory.THIRD_PARTY,
1085
1143
  details: { id: score.id }
@@ -1290,7 +1348,7 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1290
1348
  } catch (error$1) {
1291
1349
  throw new error.MastraError(
1292
1350
  {
1293
- id: "STORAGE_UPSTASH_STORAGE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
1351
+ id: storage.createStorageErrorId("UPSTASH", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
1294
1352
  domain: error.ErrorDomain.STORAGE,
1295
1353
  category: error.ErrorCategory.THIRD_PARTY,
1296
1354
  details: {
@@ -1317,7 +1375,7 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1317
1375
  } catch (error$1) {
1318
1376
  throw new error.MastraError(
1319
1377
  {
1320
- id: "STORAGE_UPSTASH_STORAGE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
1378
+ id: storage.createStorageErrorId("UPSTASH", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
1321
1379
  domain: error.ErrorDomain.STORAGE,
1322
1380
  category: error.ErrorCategory.THIRD_PARTY,
1323
1381
  details: {
@@ -1349,7 +1407,7 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1349
1407
  } catch (error$1) {
1350
1408
  throw new error.MastraError(
1351
1409
  {
1352
- id: "STORAGE_UPSTASH_STORAGE_GET_WORKFLOW_RUN_BY_ID_FAILED",
1410
+ id: storage.createStorageErrorId("UPSTASH", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
1353
1411
  domain: error.ErrorDomain.STORAGE,
1354
1412
  category: error.ErrorCategory.THIRD_PARTY,
1355
1413
  details: {
@@ -1375,7 +1433,7 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1375
1433
  if (page !== void 0 && page < 0) {
1376
1434
  throw new error.MastraError(
1377
1435
  {
1378
- id: "UPSTASH_STORE_INVALID_PAGE",
1436
+ id: storage.createStorageErrorId("UPSTASH", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
1379
1437
  domain: error.ErrorDomain.STORAGE,
1380
1438
  category: error.ErrorCategory.USER,
1381
1439
  details: { page }
@@ -1435,9 +1493,10 @@ var WorkflowsUpstash = class extends storage.WorkflowsStorage {
1435
1493
  }
1436
1494
  return { runs, total };
1437
1495
  } catch (error$1) {
1496
+ if (error$1 instanceof error.MastraError) throw error$1;
1438
1497
  throw new error.MastraError(
1439
1498
  {
1440
- id: "STORAGE_UPSTASH_STORAGE_LIST_WORKFLOW_RUNS_FAILED",
1499
+ id: storage.createStorageErrorId("UPSTASH", "LIST_WORKFLOW_RUNS", "FAILED"),
1441
1500
  domain: error.ErrorDomain.STORAGE,
1442
1501
  category: error.ErrorCategory.THIRD_PARTY,
1443
1502
  details: {
@@ -1457,7 +1516,7 @@ var UpstashStore = class extends storage.MastraStorage {
1457
1516
  redis;
1458
1517
  stores;
1459
1518
  constructor(config) {
1460
- super({ id: config.id, name: "Upstash" });
1519
+ super({ id: config.id, name: "Upstash", disableInit: config.disableInit });
1461
1520
  this.redis = new redis.Redis({
1462
1521
  url: config.url,
1463
1522
  token: config.token
@@ -1863,7 +1922,7 @@ var UpstashVector = class extends vector.MastraVector {
1863
1922
  } catch (error$1) {
1864
1923
  throw new error.MastraError(
1865
1924
  {
1866
- id: "STORAGE_UPSTASH_VECTOR_UPSERT_FAILED",
1925
+ id: storage.createVectorErrorId("UPSTASH", "UPSERT", "FAILED"),
1867
1926
  domain: error.ErrorDomain.STORAGE,
1868
1927
  category: error.ErrorCategory.THIRD_PARTY,
1869
1928
  details: { namespace, vectorCount: vectors.length }
@@ -1926,7 +1985,7 @@ var UpstashVector = class extends vector.MastraVector {
1926
1985
  } catch (error$1) {
1927
1986
  throw new error.MastraError(
1928
1987
  {
1929
- id: "STORAGE_UPSTASH_VECTOR_QUERY_FAILED",
1988
+ id: storage.createVectorErrorId("UPSTASH", "QUERY", "FAILED"),
1930
1989
  domain: error.ErrorDomain.STORAGE,
1931
1990
  category: error.ErrorCategory.THIRD_PARTY,
1932
1991
  details: { namespace, topK }
@@ -1946,7 +2005,7 @@ var UpstashVector = class extends vector.MastraVector {
1946
2005
  } catch (error$1) {
1947
2006
  throw new error.MastraError(
1948
2007
  {
1949
- id: "STORAGE_UPSTASH_VECTOR_LIST_INDEXES_FAILED",
2008
+ id: storage.createVectorErrorId("UPSTASH", "LIST_INDEXES", "FAILED"),
1950
2009
  domain: error.ErrorDomain.STORAGE,
1951
2010
  category: error.ErrorCategory.THIRD_PARTY
1952
2011
  },
@@ -1971,7 +2030,7 @@ var UpstashVector = class extends vector.MastraVector {
1971
2030
  } catch (error$1) {
1972
2031
  throw new error.MastraError(
1973
2032
  {
1974
- id: "STORAGE_UPSTASH_VECTOR_DESCRIBE_INDEX_FAILED",
2033
+ id: storage.createVectorErrorId("UPSTASH", "DESCRIBE_INDEX", "FAILED"),
1975
2034
  domain: error.ErrorDomain.STORAGE,
1976
2035
  category: error.ErrorCategory.THIRD_PARTY,
1977
2036
  details: { namespace }
@@ -1996,7 +2055,7 @@ var UpstashVector = class extends vector.MastraVector {
1996
2055
  }
1997
2056
  throw new error.MastraError(
1998
2057
  {
1999
- id: "STORAGE_UPSTASH_VECTOR_DELETE_INDEX_FAILED",
2058
+ id: storage.createVectorErrorId("UPSTASH", "DELETE_INDEX", "FAILED"),
2000
2059
  domain: error.ErrorDomain.STORAGE,
2001
2060
  category: error.ErrorCategory.THIRD_PARTY,
2002
2061
  details: { namespace }
@@ -2021,7 +2080,7 @@ var UpstashVector = class extends vector.MastraVector {
2021
2080
  const sparseVector = upstashUpdate.sparseVector;
2022
2081
  if ("id" in params && params.id && "filter" in params && params.filter) {
2023
2082
  throw new error.MastraError({
2024
- id: "STORAGE_UPSTASH_VECTOR_UPDATE_MUTUALLY_EXCLUSIVE",
2083
+ id: storage.createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
2025
2084
  text: "Cannot specify both id and filter - they are mutually exclusive",
2026
2085
  domain: error.ErrorDomain.STORAGE,
2027
2086
  category: error.ErrorCategory.USER,
@@ -2030,7 +2089,7 @@ var UpstashVector = class extends vector.MastraVector {
2030
2089
  }
2031
2090
  if (!("id" in params && params.id) && !("filter" in params && params.filter)) {
2032
2091
  throw new error.MastraError({
2033
- id: "STORAGE_UPSTASH_VECTOR_UPDATE_NO_TARGET",
2092
+ id: storage.createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "NO_TARGET"),
2034
2093
  text: "Either id or filter must be provided",
2035
2094
  domain: error.ErrorDomain.STORAGE,
2036
2095
  category: error.ErrorCategory.USER,
@@ -2039,7 +2098,7 @@ var UpstashVector = class extends vector.MastraVector {
2039
2098
  }
2040
2099
  if (!update.vector && !update.metadata && !sparseVector) {
2041
2100
  throw new error.MastraError({
2042
- id: "STORAGE_UPSTASH_VECTOR_UPDATE_NO_PAYLOAD",
2101
+ id: storage.createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "NO_PAYLOAD"),
2043
2102
  text: "No update data provided",
2044
2103
  domain: error.ErrorDomain.STORAGE,
2045
2104
  category: error.ErrorCategory.USER,
@@ -2048,7 +2107,7 @@ var UpstashVector = class extends vector.MastraVector {
2048
2107
  }
2049
2108
  if ("filter" in params && params.filter && Object.keys(params.filter).length === 0) {
2050
2109
  throw new error.MastraError({
2051
- id: "STORAGE_UPSTASH_VECTOR_UPDATE_EMPTY_FILTER",
2110
+ id: storage.createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "EMPTY_FILTER"),
2052
2111
  text: "Filter cannot be an empty filter object",
2053
2112
  domain: error.ErrorDomain.STORAGE,
2054
2113
  category: error.ErrorCategory.USER,
@@ -2116,7 +2175,7 @@ var UpstashVector = class extends vector.MastraVector {
2116
2175
  if (error$1 instanceof error.MastraError) throw error$1;
2117
2176
  throw new error.MastraError(
2118
2177
  {
2119
- id: "STORAGE_UPSTASH_VECTOR_UPDATE_VECTOR_FAILED",
2178
+ id: storage.createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "FAILED"),
2120
2179
  domain: error.ErrorDomain.STORAGE,
2121
2180
  category: error.ErrorCategory.THIRD_PARTY,
2122
2181
  details: {
@@ -2143,7 +2202,7 @@ var UpstashVector = class extends vector.MastraVector {
2143
2202
  } catch (error$1) {
2144
2203
  const mastraError = new error.MastraError(
2145
2204
  {
2146
- id: "STORAGE_UPSTASH_VECTOR_DELETE_VECTOR_FAILED",
2205
+ id: storage.createVectorErrorId("UPSTASH", "DELETE_VECTOR", "FAILED"),
2147
2206
  domain: error.ErrorDomain.STORAGE,
2148
2207
  category: error.ErrorCategory.THIRD_PARTY,
2149
2208
  details: {
@@ -2167,7 +2226,7 @@ var UpstashVector = class extends vector.MastraVector {
2167
2226
  async deleteVectors({ indexName: namespace, filter, ids }) {
2168
2227
  if (ids && filter) {
2169
2228
  throw new error.MastraError({
2170
- id: "STORAGE_UPSTASH_VECTOR_DELETE_VECTORS_MUTUALLY_EXCLUSIVE",
2229
+ id: storage.createVectorErrorId("UPSTASH", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
2171
2230
  text: "Cannot specify both ids and filter - they are mutually exclusive",
2172
2231
  domain: error.ErrorDomain.STORAGE,
2173
2232
  category: error.ErrorCategory.USER,
@@ -2176,7 +2235,7 @@ var UpstashVector = class extends vector.MastraVector {
2176
2235
  }
2177
2236
  if (!ids && !filter) {
2178
2237
  throw new error.MastraError({
2179
- id: "STORAGE_UPSTASH_VECTOR_DELETE_VECTORS_NO_TARGET",
2238
+ id: storage.createVectorErrorId("UPSTASH", "DELETE_VECTORS", "NO_TARGET"),
2180
2239
  text: "Either filter or ids must be provided",
2181
2240
  domain: error.ErrorDomain.STORAGE,
2182
2241
  category: error.ErrorCategory.USER,
@@ -2185,7 +2244,7 @@ var UpstashVector = class extends vector.MastraVector {
2185
2244
  }
2186
2245
  if (ids && ids.length === 0) {
2187
2246
  throw new error.MastraError({
2188
- id: "STORAGE_UPSTASH_VECTOR_DELETE_VECTORS_EMPTY_IDS",
2247
+ id: storage.createVectorErrorId("UPSTASH", "DELETE_VECTORS", "EMPTY_IDS"),
2189
2248
  text: "Cannot delete with empty ids array",
2190
2249
  domain: error.ErrorDomain.STORAGE,
2191
2250
  category: error.ErrorCategory.USER,
@@ -2194,7 +2253,7 @@ var UpstashVector = class extends vector.MastraVector {
2194
2253
  }
2195
2254
  if (filter && Object.keys(filter).length === 0) {
2196
2255
  throw new error.MastraError({
2197
- id: "STORAGE_UPSTASH_VECTOR_DELETE_VECTORS_EMPTY_FILTER",
2256
+ id: storage.createVectorErrorId("UPSTASH", "DELETE_VECTORS", "EMPTY_FILTER"),
2198
2257
  text: "Cannot delete with empty filter object",
2199
2258
  domain: error.ErrorDomain.STORAGE,
2200
2259
  category: error.ErrorCategory.USER,
@@ -2228,7 +2287,7 @@ var UpstashVector = class extends vector.MastraVector {
2228
2287
  if (error$1 instanceof error.MastraError) throw error$1;
2229
2288
  throw new error.MastraError(
2230
2289
  {
2231
- id: "STORAGE_UPSTASH_VECTOR_DELETE_VECTORS_FAILED",
2290
+ id: storage.createVectorErrorId("UPSTASH", "DELETE_VECTORS", "FAILED"),
2232
2291
  domain: error.ErrorDomain.STORAGE,
2233
2292
  category: error.ErrorCategory.THIRD_PARTY,
2234
2293
  details: {