@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/CHANGELOG.md +56 -0
- package/dist/index.cjs +183 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +184 -125
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +4 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +20 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MastraStorage, StoreOperations, ScoresStorage, TABLE_SCORERS, normalizePerPage, calculatePagination, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, MemoryStorage, TABLE_THREADS, TABLE_RESOURCES, TABLE_MESSAGES, serializeDate } from '@mastra/core/storage';
|
|
1
|
+
import { MastraStorage, createVectorErrorId, StoreOperations, createStorageErrorId, ScoresStorage, TABLE_SCORERS, normalizePerPage, calculatePagination, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, MemoryStorage, TABLE_THREADS, TABLE_RESOURCES, TABLE_MESSAGES, serializeDate, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
|
|
2
2
|
import { Redis } from '@upstash/redis';
|
|
3
3
|
import { MessageList } from '@mastra/core/agent';
|
|
4
4
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
@@ -52,6 +52,9 @@ function getMessageKey(threadId, messageId) {
|
|
|
52
52
|
const key = getKey(TABLE_MESSAGES, { threadId, id: messageId });
|
|
53
53
|
return key;
|
|
54
54
|
}
|
|
55
|
+
function getMessageIndexKey(messageId) {
|
|
56
|
+
return `msg-idx:${messageId}`;
|
|
57
|
+
}
|
|
55
58
|
var StoreMemoryUpstash = class extends MemoryStorage {
|
|
56
59
|
client;
|
|
57
60
|
operations;
|
|
@@ -76,7 +79,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
76
79
|
} catch (error) {
|
|
77
80
|
throw new MastraError(
|
|
78
81
|
{
|
|
79
|
-
id: "
|
|
82
|
+
id: createStorageErrorId("UPSTASH", "GET_THREAD_BY_ID", "FAILED"),
|
|
80
83
|
domain: ErrorDomain.STORAGE,
|
|
81
84
|
category: ErrorCategory.THIRD_PARTY,
|
|
82
85
|
details: {
|
|
@@ -94,7 +97,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
94
97
|
if (page < 0) {
|
|
95
98
|
throw new MastraError(
|
|
96
99
|
{
|
|
97
|
-
id: "
|
|
100
|
+
id: createStorageErrorId("UPSTASH", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
98
101
|
domain: ErrorDomain.STORAGE,
|
|
99
102
|
category: ErrorCategory.USER,
|
|
100
103
|
details: { page }
|
|
@@ -136,7 +139,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
136
139
|
} catch (error) {
|
|
137
140
|
const mastraError = new MastraError(
|
|
138
141
|
{
|
|
139
|
-
id: "
|
|
142
|
+
id: createStorageErrorId("UPSTASH", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
|
|
140
143
|
domain: ErrorDomain.STORAGE,
|
|
141
144
|
category: ErrorCategory.THIRD_PARTY,
|
|
142
145
|
details: {
|
|
@@ -168,7 +171,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
168
171
|
} catch (error) {
|
|
169
172
|
const mastraError = new MastraError(
|
|
170
173
|
{
|
|
171
|
-
id: "
|
|
174
|
+
id: createStorageErrorId("UPSTASH", "SAVE_THREAD", "FAILED"),
|
|
172
175
|
domain: ErrorDomain.STORAGE,
|
|
173
176
|
category: ErrorCategory.THIRD_PARTY,
|
|
174
177
|
details: {
|
|
@@ -190,7 +193,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
190
193
|
const thread = await this.getThreadById({ threadId: id });
|
|
191
194
|
if (!thread) {
|
|
192
195
|
throw new MastraError({
|
|
193
|
-
id: "
|
|
196
|
+
id: createStorageErrorId("UPSTASH", "UPDATE_THREAD", "FAILED"),
|
|
194
197
|
domain: ErrorDomain.STORAGE,
|
|
195
198
|
category: ErrorCategory.USER,
|
|
196
199
|
text: `Thread ${id} not found`,
|
|
@@ -213,7 +216,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
213
216
|
} catch (error) {
|
|
214
217
|
throw new MastraError(
|
|
215
218
|
{
|
|
216
|
-
id: "
|
|
219
|
+
id: createStorageErrorId("UPSTASH", "UPDATE_THREAD", "FAILED"),
|
|
217
220
|
domain: ErrorDomain.STORAGE,
|
|
218
221
|
category: ErrorCategory.THIRD_PARTY,
|
|
219
222
|
details: {
|
|
@@ -242,7 +245,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
242
245
|
} catch (error) {
|
|
243
246
|
throw new MastraError(
|
|
244
247
|
{
|
|
245
|
-
id: "
|
|
248
|
+
id: createStorageErrorId("UPSTASH", "DELETE_THREAD", "FAILED"),
|
|
246
249
|
domain: ErrorDomain.STORAGE,
|
|
247
250
|
category: ErrorCategory.THIRD_PARTY,
|
|
248
251
|
details: {
|
|
@@ -268,7 +271,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
268
271
|
} catch (error) {
|
|
269
272
|
throw new MastraError(
|
|
270
273
|
{
|
|
271
|
-
id: "
|
|
274
|
+
id: createStorageErrorId("UPSTASH", "SAVE_MESSAGES", "INVALID_ARGS"),
|
|
272
275
|
domain: ErrorDomain.STORAGE,
|
|
273
276
|
category: ErrorCategory.USER
|
|
274
277
|
},
|
|
@@ -318,6 +321,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
318
321
|
}
|
|
319
322
|
}
|
|
320
323
|
pipeline.set(key, message);
|
|
324
|
+
pipeline.set(getMessageIndexKey(message.id), message.threadId);
|
|
321
325
|
pipeline.zadd(getThreadMessagesKey(message.threadId), {
|
|
322
326
|
score,
|
|
323
327
|
member: message.id
|
|
@@ -337,7 +341,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
337
341
|
} catch (error) {
|
|
338
342
|
throw new MastraError(
|
|
339
343
|
{
|
|
340
|
-
id: "
|
|
344
|
+
id: createStorageErrorId("UPSTASH", "SAVE_MESSAGES", "FAILED"),
|
|
341
345
|
domain: ErrorDomain.STORAGE,
|
|
342
346
|
category: ErrorCategory.THIRD_PARTY,
|
|
343
347
|
details: {
|
|
@@ -348,43 +352,60 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
348
352
|
);
|
|
349
353
|
}
|
|
350
354
|
}
|
|
351
|
-
|
|
352
|
-
|
|
355
|
+
/**
|
|
356
|
+
* Lookup threadId for a message - tries index first (O(1)), falls back to scan (backwards compatible)
|
|
357
|
+
*/
|
|
358
|
+
async _getThreadIdForMessage(messageId) {
|
|
359
|
+
const indexedThreadId = await this.client.get(getMessageIndexKey(messageId));
|
|
360
|
+
if (indexedThreadId) {
|
|
361
|
+
return indexedThreadId;
|
|
362
|
+
}
|
|
363
|
+
const existingKeyPattern = getMessageKey("*", messageId);
|
|
364
|
+
const keys = await this.operations.scanKeys(existingKeyPattern);
|
|
365
|
+
if (keys.length === 0) return null;
|
|
366
|
+
const messageData = await this.client.get(keys[0]);
|
|
367
|
+
if (!messageData) return null;
|
|
368
|
+
if (messageData.threadId) {
|
|
369
|
+
await this.client.set(getMessageIndexKey(messageId), messageData.threadId);
|
|
370
|
+
}
|
|
371
|
+
return messageData.threadId || null;
|
|
372
|
+
}
|
|
373
|
+
async _getIncludedMessages(include) {
|
|
374
|
+
if (!include?.length) return [];
|
|
353
375
|
const messageIds = /* @__PURE__ */ new Set();
|
|
354
376
|
const messageIdToThreadIds = {};
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
377
|
+
for (const item of include) {
|
|
378
|
+
const itemThreadId = await this._getThreadIdForMessage(item.id);
|
|
379
|
+
if (!itemThreadId) continue;
|
|
380
|
+
messageIds.add(item.id);
|
|
381
|
+
messageIdToThreadIds[item.id] = itemThreadId;
|
|
382
|
+
const itemThreadMessagesKey = getThreadMessagesKey(itemThreadId);
|
|
383
|
+
const rank = await this.client.zrank(itemThreadMessagesKey, item.id);
|
|
384
|
+
if (rank === null) continue;
|
|
385
|
+
if (item.withPreviousMessages) {
|
|
386
|
+
const start = Math.max(0, rank - item.withPreviousMessages);
|
|
387
|
+
const prevIds = rank === 0 ? [] : await this.client.zrange(itemThreadMessagesKey, start, rank - 1);
|
|
388
|
+
prevIds.forEach((id) => {
|
|
389
|
+
messageIds.add(id);
|
|
390
|
+
messageIdToThreadIds[id] = itemThreadId;
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
if (item.withNextMessages) {
|
|
394
|
+
const nextIds = await this.client.zrange(itemThreadMessagesKey, rank + 1, rank + item.withNextMessages);
|
|
395
|
+
nextIds.forEach((id) => {
|
|
396
|
+
messageIds.add(id);
|
|
397
|
+
messageIdToThreadIds[id] = itemThreadId;
|
|
398
|
+
});
|
|
378
399
|
}
|
|
379
|
-
const pipeline = this.client.pipeline();
|
|
380
|
-
Array.from(messageIds).forEach((id) => {
|
|
381
|
-
const tId = messageIdToThreadIds[id] || threadId;
|
|
382
|
-
pipeline.get(getMessageKey(tId, id));
|
|
383
|
-
});
|
|
384
|
-
const results = await pipeline.exec();
|
|
385
|
-
return results.filter((result) => result !== null);
|
|
386
400
|
}
|
|
387
|
-
return [];
|
|
401
|
+
if (messageIds.size === 0) return [];
|
|
402
|
+
const pipeline = this.client.pipeline();
|
|
403
|
+
Array.from(messageIds).forEach((id) => {
|
|
404
|
+
const tId = messageIdToThreadIds[id];
|
|
405
|
+
pipeline.get(getMessageKey(tId, id));
|
|
406
|
+
});
|
|
407
|
+
const results = await pipeline.exec();
|
|
408
|
+
return results.filter((result) => result !== null);
|
|
388
409
|
}
|
|
389
410
|
parseStoredMessage(storedMessage) {
|
|
390
411
|
const defaultMessageContent = { format: 2, parts: [{ type: "text", text: "" }] };
|
|
@@ -398,23 +419,55 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
398
419
|
async listMessagesById({ messageIds }) {
|
|
399
420
|
if (messageIds.length === 0) return { messages: [] };
|
|
400
421
|
try {
|
|
401
|
-
const
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
422
|
+
const rawMessages = [];
|
|
423
|
+
const indexPipeline = this.client.pipeline();
|
|
424
|
+
messageIds.forEach((id) => indexPipeline.get(getMessageIndexKey(id)));
|
|
425
|
+
const indexResults = await indexPipeline.exec();
|
|
426
|
+
const indexedIds = [];
|
|
427
|
+
const unindexedIds = [];
|
|
428
|
+
messageIds.forEach((id, i) => {
|
|
429
|
+
const threadId = indexResults[i];
|
|
430
|
+
if (threadId) {
|
|
431
|
+
indexedIds.push({ messageId: id, threadId });
|
|
432
|
+
} else {
|
|
433
|
+
unindexedIds.push(id);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
if (indexedIds.length > 0) {
|
|
437
|
+
const messagePipeline = this.client.pipeline();
|
|
438
|
+
indexedIds.forEach(({ messageId, threadId }) => messagePipeline.get(getMessageKey(threadId, messageId)));
|
|
439
|
+
const messageResults = await messagePipeline.exec();
|
|
440
|
+
rawMessages.push(...messageResults.filter((msg) => msg !== null));
|
|
441
|
+
}
|
|
442
|
+
if (unindexedIds.length > 0) {
|
|
443
|
+
const threadKeys = await this.client.keys("thread:*");
|
|
444
|
+
const result = await Promise.all(
|
|
445
|
+
threadKeys.map((threadKey) => {
|
|
446
|
+
const threadId = threadKey.split(":")[1];
|
|
447
|
+
if (!threadId) throw new Error(`Failed to parse thread ID from thread key "${threadKey}"`);
|
|
448
|
+
return this.client.mget(
|
|
449
|
+
unindexedIds.map((id) => getMessageKey(threadId, id))
|
|
450
|
+
);
|
|
451
|
+
})
|
|
452
|
+
);
|
|
453
|
+
const foundMessages = result.flat(1).filter((msg) => !!msg);
|
|
454
|
+
rawMessages.push(...foundMessages);
|
|
455
|
+
if (foundMessages.length > 0) {
|
|
456
|
+
const backfillPipeline = this.client.pipeline();
|
|
457
|
+
foundMessages.forEach((msg) => {
|
|
458
|
+
if (msg.threadId) {
|
|
459
|
+
backfillPipeline.set(getMessageIndexKey(msg.id), msg.threadId);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
await backfillPipeline.exec();
|
|
463
|
+
}
|
|
464
|
+
}
|
|
412
465
|
const list = new MessageList().add(rawMessages.map(this.parseStoredMessage), "memory");
|
|
413
466
|
return { messages: list.get.all.db() };
|
|
414
467
|
} catch (error) {
|
|
415
468
|
throw new MastraError(
|
|
416
469
|
{
|
|
417
|
-
id: "
|
|
470
|
+
id: createStorageErrorId("UPSTASH", "LIST_MESSAGES_BY_ID", "FAILED"),
|
|
418
471
|
domain: ErrorDomain.STORAGE,
|
|
419
472
|
category: ErrorCategory.THIRD_PARTY,
|
|
420
473
|
details: {
|
|
@@ -427,25 +480,25 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
427
480
|
}
|
|
428
481
|
async listMessages(args) {
|
|
429
482
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
430
|
-
|
|
483
|
+
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
484
|
+
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
431
485
|
throw new MastraError(
|
|
432
486
|
{
|
|
433
|
-
id: "
|
|
487
|
+
id: createStorageErrorId("UPSTASH", "LIST_MESSAGES", "INVALID_THREAD_ID"),
|
|
434
488
|
domain: ErrorDomain.STORAGE,
|
|
435
489
|
category: ErrorCategory.THIRD_PARTY,
|
|
436
|
-
details: { threadId }
|
|
490
|
+
details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
|
|
437
491
|
},
|
|
438
|
-
new Error("threadId must be a non-empty string")
|
|
492
|
+
new Error("threadId must be a non-empty string or array of non-empty strings")
|
|
439
493
|
);
|
|
440
494
|
}
|
|
441
|
-
const threadMessagesKey = getThreadMessagesKey(threadId);
|
|
442
495
|
const perPage = normalizePerPage(perPageInput, 40);
|
|
443
496
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
444
497
|
try {
|
|
445
498
|
if (page < 0) {
|
|
446
499
|
throw new MastraError(
|
|
447
500
|
{
|
|
448
|
-
id: "
|
|
501
|
+
id: createStorageErrorId("UPSTASH", "LIST_MESSAGES", "INVALID_PAGE"),
|
|
449
502
|
domain: ErrorDomain.STORAGE,
|
|
450
503
|
category: ErrorCategory.USER,
|
|
451
504
|
details: { page }
|
|
@@ -455,11 +508,18 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
455
508
|
}
|
|
456
509
|
let includedMessages = [];
|
|
457
510
|
if (include && include.length > 0) {
|
|
458
|
-
const included = await this._getIncludedMessages(
|
|
511
|
+
const included = await this._getIncludedMessages(include);
|
|
459
512
|
includedMessages = included.map(this.parseStoredMessage);
|
|
460
513
|
}
|
|
461
|
-
const
|
|
462
|
-
|
|
514
|
+
const allMessageIdsWithThreads = [];
|
|
515
|
+
for (const tid of threadIds) {
|
|
516
|
+
const threadMessagesKey = getThreadMessagesKey(tid);
|
|
517
|
+
const messageIds2 = await this.client.zrange(threadMessagesKey, 0, -1);
|
|
518
|
+
for (const mid of messageIds2) {
|
|
519
|
+
allMessageIdsWithThreads.push({ threadId: tid, messageId: mid });
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (allMessageIdsWithThreads.length === 0) {
|
|
463
523
|
return {
|
|
464
524
|
messages: [],
|
|
465
525
|
total: 0,
|
|
@@ -469,7 +529,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
469
529
|
};
|
|
470
530
|
}
|
|
471
531
|
const pipeline = this.client.pipeline();
|
|
472
|
-
|
|
532
|
+
allMessageIdsWithThreads.forEach(({ threadId: tid, messageId }) => pipeline.get(getMessageKey(tid, messageId)));
|
|
473
533
|
const results = await pipeline.exec();
|
|
474
534
|
let messagesData = results.filter((msg) => msg !== null).map(this.parseStoredMessage);
|
|
475
535
|
if (resourceId) {
|
|
@@ -541,11 +601,11 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
541
601
|
} catch (error) {
|
|
542
602
|
const mastraError = new MastraError(
|
|
543
603
|
{
|
|
544
|
-
id: "
|
|
604
|
+
id: createStorageErrorId("UPSTASH", "LIST_MESSAGES", "FAILED"),
|
|
545
605
|
domain: ErrorDomain.STORAGE,
|
|
546
606
|
category: ErrorCategory.THIRD_PARTY,
|
|
547
607
|
details: {
|
|
548
|
-
threadId,
|
|
608
|
+
threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
|
|
549
609
|
resourceId: resourceId ?? ""
|
|
550
610
|
}
|
|
551
611
|
},
|
|
@@ -732,7 +792,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
732
792
|
} catch (error) {
|
|
733
793
|
throw new MastraError(
|
|
734
794
|
{
|
|
735
|
-
id: "
|
|
795
|
+
id: createStorageErrorId("UPSTASH", "UPDATE_MESSAGES", "FAILED"),
|
|
736
796
|
domain: ErrorDomain.STORAGE,
|
|
737
797
|
category: ErrorCategory.THIRD_PARTY,
|
|
738
798
|
details: {
|
|
@@ -750,13 +810,33 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
750
810
|
try {
|
|
751
811
|
const threadIds = /* @__PURE__ */ new Set();
|
|
752
812
|
const messageKeys = [];
|
|
753
|
-
|
|
813
|
+
const foundMessageIds = [];
|
|
814
|
+
const indexPipeline = this.client.pipeline();
|
|
815
|
+
messageIds.forEach((id) => indexPipeline.get(getMessageIndexKey(id)));
|
|
816
|
+
const indexResults = await indexPipeline.exec();
|
|
817
|
+
const indexedMessages = [];
|
|
818
|
+
const unindexedMessageIds = [];
|
|
819
|
+
messageIds.forEach((id, i) => {
|
|
820
|
+
const threadId = indexResults[i];
|
|
821
|
+
if (threadId) {
|
|
822
|
+
indexedMessages.push({ messageId: id, threadId });
|
|
823
|
+
} else {
|
|
824
|
+
unindexedMessageIds.push(id);
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
for (const { messageId, threadId } of indexedMessages) {
|
|
828
|
+
messageKeys.push(getMessageKey(threadId, messageId));
|
|
829
|
+
foundMessageIds.push(messageId);
|
|
830
|
+
threadIds.add(threadId);
|
|
831
|
+
}
|
|
832
|
+
for (const messageId of unindexedMessageIds) {
|
|
754
833
|
const pattern = getMessageKey("*", messageId);
|
|
755
834
|
const keys = await this.operations.scanKeys(pattern);
|
|
756
835
|
for (const key of keys) {
|
|
757
836
|
const message = await this.client.get(key);
|
|
758
837
|
if (message && message.id === messageId) {
|
|
759
838
|
messageKeys.push(key);
|
|
839
|
+
foundMessageIds.push(messageId);
|
|
760
840
|
if (message.threadId) {
|
|
761
841
|
threadIds.add(message.threadId);
|
|
762
842
|
}
|
|
@@ -771,6 +851,9 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
771
851
|
for (const key of messageKeys) {
|
|
772
852
|
pipeline.del(key);
|
|
773
853
|
}
|
|
854
|
+
for (const messageId of foundMessageIds) {
|
|
855
|
+
pipeline.del(getMessageIndexKey(messageId));
|
|
856
|
+
}
|
|
774
857
|
if (threadIds.size > 0) {
|
|
775
858
|
for (const threadId of threadIds) {
|
|
776
859
|
const threadKey = getKey(TABLE_THREADS, { id: threadId });
|
|
@@ -788,7 +871,7 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
788
871
|
} catch (error) {
|
|
789
872
|
throw new MastraError(
|
|
790
873
|
{
|
|
791
|
-
id: "
|
|
874
|
+
id: createStorageErrorId("UPSTASH", "DELETE_MESSAGES", "FAILED"),
|
|
792
875
|
domain: ErrorDomain.STORAGE,
|
|
793
876
|
category: ErrorCategory.THIRD_PARTY,
|
|
794
877
|
details: { messageIds: messageIds.join(", ") }
|
|
@@ -833,7 +916,7 @@ var StoreOperationsUpstash = class extends StoreOperations {
|
|
|
833
916
|
} catch (error) {
|
|
834
917
|
throw new MastraError(
|
|
835
918
|
{
|
|
836
|
-
id: "
|
|
919
|
+
id: createStorageErrorId("UPSTASH", "CLEAR_TABLE", "FAILED"),
|
|
837
920
|
domain: ErrorDomain.STORAGE,
|
|
838
921
|
category: ErrorCategory.THIRD_PARTY,
|
|
839
922
|
details: {
|
|
@@ -854,7 +937,7 @@ var StoreOperationsUpstash = class extends StoreOperations {
|
|
|
854
937
|
} catch (error) {
|
|
855
938
|
throw new MastraError(
|
|
856
939
|
{
|
|
857
|
-
id: "
|
|
940
|
+
id: createStorageErrorId("UPSTASH", "INSERT", "FAILED"),
|
|
858
941
|
domain: ErrorDomain.STORAGE,
|
|
859
942
|
category: ErrorCategory.THIRD_PARTY,
|
|
860
943
|
details: {
|
|
@@ -882,7 +965,7 @@ var StoreOperationsUpstash = class extends StoreOperations {
|
|
|
882
965
|
} catch (error) {
|
|
883
966
|
throw new MastraError(
|
|
884
967
|
{
|
|
885
|
-
id: "
|
|
968
|
+
id: createStorageErrorId("UPSTASH", "BATCH_INSERT", "FAILED"),
|
|
886
969
|
domain: ErrorDomain.STORAGE,
|
|
887
970
|
category: ErrorCategory.THIRD_PARTY,
|
|
888
971
|
details: {
|
|
@@ -901,7 +984,7 @@ var StoreOperationsUpstash = class extends StoreOperations {
|
|
|
901
984
|
} catch (error) {
|
|
902
985
|
throw new MastraError(
|
|
903
986
|
{
|
|
904
|
-
id: "
|
|
987
|
+
id: createStorageErrorId("UPSTASH", "LOAD", "FAILED"),
|
|
905
988
|
domain: ErrorDomain.STORAGE,
|
|
906
989
|
category: ErrorCategory.THIRD_PARTY,
|
|
907
990
|
details: {
|
|
@@ -946,32 +1029,7 @@ var StoreOperationsUpstash = class extends StoreOperations {
|
|
|
946
1029
|
}
|
|
947
1030
|
};
|
|
948
1031
|
function transformScoreRow(row) {
|
|
949
|
-
|
|
950
|
-
if (typeof v === "string") {
|
|
951
|
-
try {
|
|
952
|
-
return JSON.parse(v);
|
|
953
|
-
} catch {
|
|
954
|
-
return v;
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
return v;
|
|
958
|
-
};
|
|
959
|
-
return {
|
|
960
|
-
...row,
|
|
961
|
-
scorer: parseField(row.scorer),
|
|
962
|
-
preprocessStepResult: parseField(row.preprocessStepResult),
|
|
963
|
-
generateScorePrompt: row.generateScorePrompt,
|
|
964
|
-
generateReasonPrompt: row.generateReasonPrompt,
|
|
965
|
-
analyzeStepResult: parseField(row.analyzeStepResult),
|
|
966
|
-
metadata: parseField(row.metadata),
|
|
967
|
-
input: parseField(row.input),
|
|
968
|
-
output: parseField(row.output),
|
|
969
|
-
additionalContext: parseField(row.additionalContext),
|
|
970
|
-
requestContext: parseField(row.requestContext),
|
|
971
|
-
entity: parseField(row.entity),
|
|
972
|
-
createdAt: row.createdAt,
|
|
973
|
-
updatedAt: row.updatedAt
|
|
974
|
-
};
|
|
1032
|
+
return transformScoreRow$1(row);
|
|
975
1033
|
}
|
|
976
1034
|
var ScoresUpstash = class extends ScoresStorage {
|
|
977
1035
|
client;
|
|
@@ -992,7 +1050,7 @@ var ScoresUpstash = class extends ScoresStorage {
|
|
|
992
1050
|
} catch (error) {
|
|
993
1051
|
throw new MastraError(
|
|
994
1052
|
{
|
|
995
|
-
id: "
|
|
1053
|
+
id: createStorageErrorId("UPSTASH", "GET_SCORE_BY_ID", "FAILED"),
|
|
996
1054
|
domain: ErrorDomain.STORAGE,
|
|
997
1055
|
category: ErrorCategory.THIRD_PARTY,
|
|
998
1056
|
details: {
|
|
@@ -1063,7 +1121,7 @@ var ScoresUpstash = class extends ScoresStorage {
|
|
|
1063
1121
|
} catch (error) {
|
|
1064
1122
|
throw new MastraError(
|
|
1065
1123
|
{
|
|
1066
|
-
id: "
|
|
1124
|
+
id: createStorageErrorId("UPSTASH", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
1067
1125
|
domain: ErrorDomain.STORAGE,
|
|
1068
1126
|
category: ErrorCategory.THIRD_PARTY
|
|
1069
1127
|
},
|
|
@@ -1077,7 +1135,7 @@ var ScoresUpstash = class extends ScoresStorage {
|
|
|
1077
1135
|
} catch (error) {
|
|
1078
1136
|
throw new MastraError(
|
|
1079
1137
|
{
|
|
1080
|
-
id: "
|
|
1138
|
+
id: createStorageErrorId("UPSTASH", "SAVE_SCORE", "FAILED"),
|
|
1081
1139
|
domain: ErrorDomain.STORAGE,
|
|
1082
1140
|
category: ErrorCategory.THIRD_PARTY,
|
|
1083
1141
|
details: { id: score.id }
|
|
@@ -1288,7 +1346,7 @@ var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
|
1288
1346
|
} catch (error) {
|
|
1289
1347
|
throw new MastraError(
|
|
1290
1348
|
{
|
|
1291
|
-
id: "
|
|
1349
|
+
id: createStorageErrorId("UPSTASH", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1292
1350
|
domain: ErrorDomain.STORAGE,
|
|
1293
1351
|
category: ErrorCategory.THIRD_PARTY,
|
|
1294
1352
|
details: {
|
|
@@ -1315,7 +1373,7 @@ var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
|
1315
1373
|
} catch (error) {
|
|
1316
1374
|
throw new MastraError(
|
|
1317
1375
|
{
|
|
1318
|
-
id: "
|
|
1376
|
+
id: createStorageErrorId("UPSTASH", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1319
1377
|
domain: ErrorDomain.STORAGE,
|
|
1320
1378
|
category: ErrorCategory.THIRD_PARTY,
|
|
1321
1379
|
details: {
|
|
@@ -1347,7 +1405,7 @@ var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
|
1347
1405
|
} catch (error) {
|
|
1348
1406
|
throw new MastraError(
|
|
1349
1407
|
{
|
|
1350
|
-
id: "
|
|
1408
|
+
id: createStorageErrorId("UPSTASH", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
1351
1409
|
domain: ErrorDomain.STORAGE,
|
|
1352
1410
|
category: ErrorCategory.THIRD_PARTY,
|
|
1353
1411
|
details: {
|
|
@@ -1373,7 +1431,7 @@ var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
|
1373
1431
|
if (page !== void 0 && page < 0) {
|
|
1374
1432
|
throw new MastraError(
|
|
1375
1433
|
{
|
|
1376
|
-
id: "
|
|
1434
|
+
id: createStorageErrorId("UPSTASH", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
|
|
1377
1435
|
domain: ErrorDomain.STORAGE,
|
|
1378
1436
|
category: ErrorCategory.USER,
|
|
1379
1437
|
details: { page }
|
|
@@ -1433,9 +1491,10 @@ var WorkflowsUpstash = class extends WorkflowsStorage {
|
|
|
1433
1491
|
}
|
|
1434
1492
|
return { runs, total };
|
|
1435
1493
|
} catch (error) {
|
|
1494
|
+
if (error instanceof MastraError) throw error;
|
|
1436
1495
|
throw new MastraError(
|
|
1437
1496
|
{
|
|
1438
|
-
id: "
|
|
1497
|
+
id: createStorageErrorId("UPSTASH", "LIST_WORKFLOW_RUNS", "FAILED"),
|
|
1439
1498
|
domain: ErrorDomain.STORAGE,
|
|
1440
1499
|
category: ErrorCategory.THIRD_PARTY,
|
|
1441
1500
|
details: {
|
|
@@ -1455,7 +1514,7 @@ var UpstashStore = class extends MastraStorage {
|
|
|
1455
1514
|
redis;
|
|
1456
1515
|
stores;
|
|
1457
1516
|
constructor(config) {
|
|
1458
|
-
super({ id: config.id, name: "Upstash" });
|
|
1517
|
+
super({ id: config.id, name: "Upstash", disableInit: config.disableInit });
|
|
1459
1518
|
this.redis = new Redis({
|
|
1460
1519
|
url: config.url,
|
|
1461
1520
|
token: config.token
|
|
@@ -1861,7 +1920,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
1861
1920
|
} catch (error) {
|
|
1862
1921
|
throw new MastraError(
|
|
1863
1922
|
{
|
|
1864
|
-
id: "
|
|
1923
|
+
id: createVectorErrorId("UPSTASH", "UPSERT", "FAILED"),
|
|
1865
1924
|
domain: ErrorDomain.STORAGE,
|
|
1866
1925
|
category: ErrorCategory.THIRD_PARTY,
|
|
1867
1926
|
details: { namespace, vectorCount: vectors.length }
|
|
@@ -1924,7 +1983,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
1924
1983
|
} catch (error) {
|
|
1925
1984
|
throw new MastraError(
|
|
1926
1985
|
{
|
|
1927
|
-
id: "
|
|
1986
|
+
id: createVectorErrorId("UPSTASH", "QUERY", "FAILED"),
|
|
1928
1987
|
domain: ErrorDomain.STORAGE,
|
|
1929
1988
|
category: ErrorCategory.THIRD_PARTY,
|
|
1930
1989
|
details: { namespace, topK }
|
|
@@ -1944,7 +2003,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
1944
2003
|
} catch (error) {
|
|
1945
2004
|
throw new MastraError(
|
|
1946
2005
|
{
|
|
1947
|
-
id: "
|
|
2006
|
+
id: createVectorErrorId("UPSTASH", "LIST_INDEXES", "FAILED"),
|
|
1948
2007
|
domain: ErrorDomain.STORAGE,
|
|
1949
2008
|
category: ErrorCategory.THIRD_PARTY
|
|
1950
2009
|
},
|
|
@@ -1969,7 +2028,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
1969
2028
|
} catch (error) {
|
|
1970
2029
|
throw new MastraError(
|
|
1971
2030
|
{
|
|
1972
|
-
id: "
|
|
2031
|
+
id: createVectorErrorId("UPSTASH", "DESCRIBE_INDEX", "FAILED"),
|
|
1973
2032
|
domain: ErrorDomain.STORAGE,
|
|
1974
2033
|
category: ErrorCategory.THIRD_PARTY,
|
|
1975
2034
|
details: { namespace }
|
|
@@ -1994,7 +2053,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
1994
2053
|
}
|
|
1995
2054
|
throw new MastraError(
|
|
1996
2055
|
{
|
|
1997
|
-
id: "
|
|
2056
|
+
id: createVectorErrorId("UPSTASH", "DELETE_INDEX", "FAILED"),
|
|
1998
2057
|
domain: ErrorDomain.STORAGE,
|
|
1999
2058
|
category: ErrorCategory.THIRD_PARTY,
|
|
2000
2059
|
details: { namespace }
|
|
@@ -2019,7 +2078,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2019
2078
|
const sparseVector = upstashUpdate.sparseVector;
|
|
2020
2079
|
if ("id" in params && params.id && "filter" in params && params.filter) {
|
|
2021
2080
|
throw new MastraError({
|
|
2022
|
-
id: "
|
|
2081
|
+
id: createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
|
|
2023
2082
|
text: "Cannot specify both id and filter - they are mutually exclusive",
|
|
2024
2083
|
domain: ErrorDomain.STORAGE,
|
|
2025
2084
|
category: ErrorCategory.USER,
|
|
@@ -2028,7 +2087,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2028
2087
|
}
|
|
2029
2088
|
if (!("id" in params && params.id) && !("filter" in params && params.filter)) {
|
|
2030
2089
|
throw new MastraError({
|
|
2031
|
-
id: "
|
|
2090
|
+
id: createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "NO_TARGET"),
|
|
2032
2091
|
text: "Either id or filter must be provided",
|
|
2033
2092
|
domain: ErrorDomain.STORAGE,
|
|
2034
2093
|
category: ErrorCategory.USER,
|
|
@@ -2037,7 +2096,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2037
2096
|
}
|
|
2038
2097
|
if (!update.vector && !update.metadata && !sparseVector) {
|
|
2039
2098
|
throw new MastraError({
|
|
2040
|
-
id: "
|
|
2099
|
+
id: createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "NO_PAYLOAD"),
|
|
2041
2100
|
text: "No update data provided",
|
|
2042
2101
|
domain: ErrorDomain.STORAGE,
|
|
2043
2102
|
category: ErrorCategory.USER,
|
|
@@ -2046,7 +2105,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2046
2105
|
}
|
|
2047
2106
|
if ("filter" in params && params.filter && Object.keys(params.filter).length === 0) {
|
|
2048
2107
|
throw new MastraError({
|
|
2049
|
-
id: "
|
|
2108
|
+
id: createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "EMPTY_FILTER"),
|
|
2050
2109
|
text: "Filter cannot be an empty filter object",
|
|
2051
2110
|
domain: ErrorDomain.STORAGE,
|
|
2052
2111
|
category: ErrorCategory.USER,
|
|
@@ -2114,7 +2173,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2114
2173
|
if (error instanceof MastraError) throw error;
|
|
2115
2174
|
throw new MastraError(
|
|
2116
2175
|
{
|
|
2117
|
-
id: "
|
|
2176
|
+
id: createVectorErrorId("UPSTASH", "UPDATE_VECTOR", "FAILED"),
|
|
2118
2177
|
domain: ErrorDomain.STORAGE,
|
|
2119
2178
|
category: ErrorCategory.THIRD_PARTY,
|
|
2120
2179
|
details: {
|
|
@@ -2141,7 +2200,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2141
2200
|
} catch (error) {
|
|
2142
2201
|
const mastraError = new MastraError(
|
|
2143
2202
|
{
|
|
2144
|
-
id: "
|
|
2203
|
+
id: createVectorErrorId("UPSTASH", "DELETE_VECTOR", "FAILED"),
|
|
2145
2204
|
domain: ErrorDomain.STORAGE,
|
|
2146
2205
|
category: ErrorCategory.THIRD_PARTY,
|
|
2147
2206
|
details: {
|
|
@@ -2165,7 +2224,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2165
2224
|
async deleteVectors({ indexName: namespace, filter, ids }) {
|
|
2166
2225
|
if (ids && filter) {
|
|
2167
2226
|
throw new MastraError({
|
|
2168
|
-
id: "
|
|
2227
|
+
id: createVectorErrorId("UPSTASH", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
|
|
2169
2228
|
text: "Cannot specify both ids and filter - they are mutually exclusive",
|
|
2170
2229
|
domain: ErrorDomain.STORAGE,
|
|
2171
2230
|
category: ErrorCategory.USER,
|
|
@@ -2174,7 +2233,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2174
2233
|
}
|
|
2175
2234
|
if (!ids && !filter) {
|
|
2176
2235
|
throw new MastraError({
|
|
2177
|
-
id: "
|
|
2236
|
+
id: createVectorErrorId("UPSTASH", "DELETE_VECTORS", "NO_TARGET"),
|
|
2178
2237
|
text: "Either filter or ids must be provided",
|
|
2179
2238
|
domain: ErrorDomain.STORAGE,
|
|
2180
2239
|
category: ErrorCategory.USER,
|
|
@@ -2183,7 +2242,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2183
2242
|
}
|
|
2184
2243
|
if (ids && ids.length === 0) {
|
|
2185
2244
|
throw new MastraError({
|
|
2186
|
-
id: "
|
|
2245
|
+
id: createVectorErrorId("UPSTASH", "DELETE_VECTORS", "EMPTY_IDS"),
|
|
2187
2246
|
text: "Cannot delete with empty ids array",
|
|
2188
2247
|
domain: ErrorDomain.STORAGE,
|
|
2189
2248
|
category: ErrorCategory.USER,
|
|
@@ -2192,7 +2251,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2192
2251
|
}
|
|
2193
2252
|
if (filter && Object.keys(filter).length === 0) {
|
|
2194
2253
|
throw new MastraError({
|
|
2195
|
-
id: "
|
|
2254
|
+
id: createVectorErrorId("UPSTASH", "DELETE_VECTORS", "EMPTY_FILTER"),
|
|
2196
2255
|
text: "Cannot delete with empty filter object",
|
|
2197
2256
|
domain: ErrorDomain.STORAGE,
|
|
2198
2257
|
category: ErrorCategory.USER,
|
|
@@ -2226,7 +2285,7 @@ var UpstashVector = class extends MastraVector {
|
|
|
2226
2285
|
if (error instanceof MastraError) throw error;
|
|
2227
2286
|
throw new MastraError(
|
|
2228
2287
|
{
|
|
2229
|
-
id: "
|
|
2288
|
+
id: createVectorErrorId("UPSTASH", "DELETE_VECTORS", "FAILED"),
|
|
2230
2289
|
domain: ErrorDomain.STORAGE,
|
|
2231
2290
|
category: ErrorCategory.THIRD_PARTY,
|
|
2232
2291
|
details: {
|