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