@mastra/upstash 1.0.0-beta.11 → 1.0.0-beta.12
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 +46 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/docs/rag/01-vector-databases.md +3 -3
- package/dist/index.cjs +47 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -15
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +2 -2
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -190,19 +190,34 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
190
190
|
);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
async
|
|
194
|
-
const {
|
|
193
|
+
async listThreads(args) {
|
|
194
|
+
const { page = 0, perPage: perPageInput, orderBy, filter } = args;
|
|
195
195
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
196
|
+
try {
|
|
197
|
+
this.validatePaginationInput(page, perPageInput ?? 100);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
throw new MastraError(
|
|
200
|
+
{
|
|
201
|
+
id: createStorageErrorId("UPSTASH", "LIST_THREADS", "INVALID_PAGE"),
|
|
202
|
+
domain: ErrorDomain.STORAGE,
|
|
203
|
+
category: ErrorCategory.USER,
|
|
204
|
+
details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
|
|
205
|
+
},
|
|
206
|
+
error instanceof Error ? error : new Error("Invalid pagination parameters")
|
|
207
|
+
);
|
|
208
|
+
}
|
|
196
209
|
const perPage = normalizePerPage(perPageInput, 100);
|
|
197
|
-
|
|
210
|
+
try {
|
|
211
|
+
this.validateMetadataKeys(filter?.metadata);
|
|
212
|
+
} catch (error) {
|
|
198
213
|
throw new MastraError(
|
|
199
214
|
{
|
|
200
|
-
id: createStorageErrorId("UPSTASH", "
|
|
215
|
+
id: createStorageErrorId("UPSTASH", "LIST_THREADS", "INVALID_METADATA_KEY"),
|
|
201
216
|
domain: ErrorDomain.STORAGE,
|
|
202
217
|
category: ErrorCategory.USER,
|
|
203
|
-
details: {
|
|
218
|
+
details: { metadataKeys: filter?.metadata ? Object.keys(filter.metadata).join(", ") : "" }
|
|
204
219
|
},
|
|
205
|
-
new Error("
|
|
220
|
+
error instanceof Error ? error : new Error("Invalid metadata key")
|
|
206
221
|
);
|
|
207
222
|
}
|
|
208
223
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
@@ -210,19 +225,35 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
210
225
|
let allThreads = [];
|
|
211
226
|
const pattern = `${TABLE_THREADS}:*`;
|
|
212
227
|
const keys = await this.#db.scanKeys(pattern);
|
|
228
|
+
if (keys.length === 0) {
|
|
229
|
+
return {
|
|
230
|
+
threads: [],
|
|
231
|
+
total: 0,
|
|
232
|
+
page,
|
|
233
|
+
perPage: perPageForResponse,
|
|
234
|
+
hasMore: false
|
|
235
|
+
};
|
|
236
|
+
}
|
|
213
237
|
const pipeline = this.client.pipeline();
|
|
214
238
|
keys.forEach((key) => pipeline.get(key));
|
|
215
239
|
const results = await pipeline.exec();
|
|
216
240
|
for (let i = 0; i < results.length; i++) {
|
|
217
241
|
const thread = results[i];
|
|
218
|
-
if (thread
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
createdAt: ensureDate(thread.createdAt),
|
|
222
|
-
updatedAt: ensureDate(thread.updatedAt),
|
|
223
|
-
metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata
|
|
224
|
-
});
|
|
242
|
+
if (!thread) continue;
|
|
243
|
+
if (filter?.resourceId && thread.resourceId !== filter.resourceId) {
|
|
244
|
+
continue;
|
|
225
245
|
}
|
|
246
|
+
if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
|
|
247
|
+
const threadMetadata = typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata;
|
|
248
|
+
const matches = Object.entries(filter.metadata).every(([key, value]) => threadMetadata?.[key] === value);
|
|
249
|
+
if (!matches) continue;
|
|
250
|
+
}
|
|
251
|
+
allThreads.push({
|
|
252
|
+
...thread,
|
|
253
|
+
createdAt: ensureDate(thread.createdAt),
|
|
254
|
+
updatedAt: ensureDate(thread.updatedAt),
|
|
255
|
+
metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata
|
|
256
|
+
});
|
|
226
257
|
}
|
|
227
258
|
const sortedThreads = this.sortThreads(allThreads, field, direction);
|
|
228
259
|
const total = sortedThreads.length;
|
|
@@ -239,11 +270,12 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
239
270
|
} catch (error) {
|
|
240
271
|
const mastraError = new MastraError(
|
|
241
272
|
{
|
|
242
|
-
id: createStorageErrorId("UPSTASH", "
|
|
273
|
+
id: createStorageErrorId("UPSTASH", "LIST_THREADS", "FAILED"),
|
|
243
274
|
domain: ErrorDomain.STORAGE,
|
|
244
275
|
category: ErrorCategory.THIRD_PARTY,
|
|
245
276
|
details: {
|
|
246
|
-
resourceId,
|
|
277
|
+
...filter?.resourceId && { resourceId: filter.resourceId },
|
|
278
|
+
hasMetadataFilter: !!filter?.metadata,
|
|
247
279
|
page,
|
|
248
280
|
perPage
|
|
249
281
|
}
|