@mastra/upstash 0.14.5 → 0.14.6-alpha.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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/upstash
2
2
 
3
+ ## 0.14.6-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
8
+
9
+ - Updated dependencies [[`85ef90b`](https://github.com/mastra-ai/mastra/commit/85ef90bb2cd4ae4df855c7ac175f7d392c55c1bf), [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e)]:
10
+ - @mastra/core@0.15.3-alpha.5
11
+
3
12
  ## 0.14.5
4
13
 
5
14
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/upstash",
3
- "version": "0.14.5",
3
+ "version": "0.14.6-alpha.0",
4
4
  "description": "Upstash provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "./package.json": "./package.json"
20
20
  },
21
- "license": "MIT",
21
+ "license": "Apache-2.0",
22
22
  "dependencies": {
23
23
  "@upstash/redis": "^1.35.3",
24
24
  "@upstash/vector": "^1.2.2"
@@ -32,13 +32,26 @@
32
32
  "typescript": "^5.8.3",
33
33
  "vitest": "^3.2.4",
34
34
  "@internal/lint": "0.0.34",
35
- "@internal/storage-test-utils": "0.0.30",
35
+ "@mastra/core": "0.15.3-alpha.5",
36
36
  "@internal/types-builder": "0.0.9",
37
- "@mastra/core": "0.15.2"
37
+ "@internal/storage-test-utils": "0.0.30"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@mastra/core": ">=0.13.0-0 <0.16.0-0"
41
41
  },
42
+ "files": [
43
+ "dist",
44
+ "CHANGELOG.md"
45
+ ],
46
+ "homepage": "https://mastra.ai",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/mastra-ai/mastra.git",
50
+ "directory": "stores/upstash"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/mastra-ai/mastra/issues"
54
+ },
42
55
  "scripts": {
43
56
  "pretest": "docker compose up -d",
44
57
  "test": "vitest run",
@@ -1,4 +0,0 @@
1
-
2
- > @mastra/upstash@0.14.4 build /home/runner/work/mastra/mastra/stores/upstash
3
- > tsup --silent --config tsup.config.ts
4
-
package/PAGINATION.md DELETED
@@ -1,397 +0,0 @@
1
- # Upstash Store Pagination Features
2
-
3
- This document describes the pagination capabilities added to the UpstashStore class for efficient data retrieval from Upstash Redis.
4
-
5
- ## Overview
6
-
7
- The UpstashStore now supports comprehensive pagination across all major data retrieval methods. Pagination helps manage large datasets by:
8
-
9
- - Reducing memory usage by loading data in chunks
10
- - Improving response times for large collections
11
- - Supporting both cursor-based and offset-based pagination patterns
12
- - Providing total count information for UI pagination controls
13
-
14
- ## Pagination Patterns
15
-
16
- The implementation supports two pagination patterns to match different use cases:
17
-
18
- ### 1. Page-based Pagination (page/perPage)
19
-
20
- ```typescript
21
- const result = await store.getEvals({
22
- agentName: 'my-agent',
23
- page: 0, // First page (0-based)
24
- perPage: 20, // 20 items per page
25
- });
26
- ```
27
-
28
- ### 2. Offset-based Pagination (limit/offset)
29
-
30
- ```typescript
31
- const result = await store.getEvals({
32
- agentName: 'my-agent',
33
- limit: 20, // Maximum items to return
34
- offset: 40, // Skip first 40 items
35
- });
36
- ```
37
-
38
- ## Enhanced Methods
39
-
40
- ### 1. getEvals() - New Comprehensive Evaluation Retrieval
41
-
42
- ```typescript
43
- const result = await store.getEvals({
44
- agentName?: string; // Filter by agent name
45
- type?: 'test' | 'live'; // Filter by evaluation type
46
- page?: number; // Page number (0-based)
47
- perPage?: number; // Items per page
48
- limit?: number; // Alternative: max items
49
- offset?: number; // Alternative: items to skip
50
- fromDate?: Date; // Filter by date range
51
- toDate?: Date;
52
- });
53
-
54
- // Returns:
55
- {
56
- evals: EvalRow[]; // Evaluation results
57
- total: number; // Total count (before pagination)
58
- page?: number; // Current page (page-based)
59
- perPage?: number; // Items per page (page-based)
60
- hasMore: boolean; // Whether more data exists
61
- }
62
- ```
63
-
64
- ### 2. getMessages() - Enhanced with Pagination Support
65
-
66
- The existing `getMessages` function now supports pagination while maintaining full backward compatibility:
67
-
68
- ```typescript
69
- // Original usage (backward compatible) - returns message array
70
- const messages = await store.getMessages({
71
- threadId: 'thread-id',
72
- format: 'v2'
73
- });
74
-
75
- // New paginated usage - returns pagination object
76
- const result = await store.getMessages({
77
- threadId: 'thread-id',
78
- page: 0, // Page number (0-based)
79
- perPage: 20, // Items per page (default: 40)
80
- format: 'v2', // Message format
81
- fromDate?: Date, // Filter by creation date
82
- toDate?: Date, // Filter by creation date
83
- });
84
-
85
- // Paginated result format:
86
- {
87
- messages: MastraMessageV1[] | MastraMessageV2[];
88
- total: number; // Total count
89
- page: number; // Current page
90
- perPage: number; // Items per page
91
- hasMore: boolean; // Whether more data exists
92
- }
93
- ```
94
-
95
- **Key Features:**
96
-
97
- - **Backward Compatible**: Existing code continues to work unchanged
98
- - **Conditional Return Type**: Returns array when no pagination params, object when paginated
99
- - **Date Filtering**: Combine pagination with date range filtering
100
- - **Maintains Message Order**: Preserves chronological order from Redis sorted sets
101
- - **Efficient Pipelines**: Uses Redis pipelines for batch operations
102
-
103
- ### 3. getThreads() - New Comprehensive Thread Retrieval
104
-
105
- ```typescript
106
- const result = await store.getThreads({
107
- resourceId?: string; // Filter by resource ID
108
- page?: number; // Page number (0-based)
109
- perPage?: number; // Items per page
110
- limit?: number; // Alternative: max items
111
- offset?: number; // Alternative: items to skip
112
- fromDate?: Date; // Filter by creation date
113
- toDate?: Date;
114
- });
115
-
116
- // Returns:
117
- {
118
- threads: StorageThreadType[]; // Thread results
119
- total: number; // Total count
120
- page?: number;
121
- perPage?: number;
122
- hasMore: boolean;
123
- }
124
- ```
125
-
126
- ### 4. getTracesWithCount() - Enhanced Trace Retrieval
127
-
128
- ```typescript
129
- const result = await store.getTracesWithCount({
130
- name?: string; // Filter by trace name
131
- scope?: string; // Filter by scope
132
- page?: number; // Page number (0-based)
133
- perPage?: number; // Items per page (default: 100)
134
- attributes?: Record<string, string>; // Filter by attributes
135
- filters?: Record<string, any>; // Custom filters
136
- fromDate?: Date; // Date range filtering
137
- toDate?: Date;
138
- });
139
-
140
- // Returns:
141
- {
142
- traces: any[]; // Trace results
143
- total: number; // Total count
144
- page: number;
145
- perPage: number;
146
- hasMore: boolean;
147
- }
148
- ```
149
-
150
- ## Enhanced Existing Methods
151
-
152
- ### 1. getEvalsByAgentName() - Now with Pagination
153
-
154
- ```typescript
155
- const evals = await store.getEvalsByAgentName(
156
- 'agent-name',
157
- 'test' | 'live',
158
- {
159
- page?: number;
160
- perPage?: number;
161
- limit?: number;
162
- offset?: number;
163
- }
164
- );
165
- ```
166
-
167
- ### 2. getThreadsByResourceId() - Now with Pagination
168
-
169
- ```typescript
170
- const threads = await store.getThreadsByResourceId({
171
- resourceId: 'resource-id',
172
- page?: number;
173
- perPage?: number;
174
- limit?: number;
175
- offset?: number;
176
- });
177
- ```
178
-
179
- ### 3. getWorkflowRuns() - Improved Performance
180
-
181
- The existing method now uses Redis pipelines for better performance:
182
-
183
- ```typescript
184
- const result = await store.getWorkflowRuns({
185
- namespace?: string; // Default: 'workflows'
186
- workflowName?: string;
187
- fromDate?: Date;
188
- toDate?: Date;
189
- limit?: number;
190
- offset?: number;
191
- resourceId?: string;
192
- });
193
- ```
194
-
195
- ## Utility Methods
196
-
197
- ### 1. scanWithCursor() - Cursor-based Key Scanning
198
-
199
- ```typescript
200
- const result = await store.scanWithCursor(
201
- 'pattern:*', // Redis key pattern
202
- '0', // Cursor (use '0' for first scan)
203
- 1000 // Count hint
204
- );
205
-
206
- // Returns:
207
- {
208
- keys: string[]; // Found keys
209
- nextCursor: string; // Cursor for next iteration
210
- hasMore: boolean; // Whether more keys exist
211
- }
212
- ```
213
-
214
- ### 2. getPaginatedResults() - Generic Pagination Utility
215
-
216
- ```typescript
217
- const result = await store.getPaginatedResults<TransformedType>(
218
- 'pattern:*', // Redis key pattern
219
- 0, // Page number
220
- 20, // Items per page
221
- (record) => ({ // Optional transformer function
222
- // Transform raw record to desired format
223
- id: record.id,
224
- name: record.name
225
- })
226
- );
227
-
228
- // Returns:
229
- {
230
- data: TransformedType[];
231
- total: number;
232
- page: number;
233
- perPage: number;
234
- hasMore: boolean;
235
- }
236
- ```
237
-
238
- ## Performance Optimizations
239
-
240
- ### Redis Pipeline Usage
241
-
242
- All pagination methods use Redis pipelines to batch multiple GET operations, significantly improving performance when retrieving multiple records.
243
-
244
- ```typescript
245
- // Instead of multiple individual calls:
246
- // const result1 = await redis.get(key1);
247
- // const result2 = await redis.get(key2);
248
-
249
- // We use pipelines:
250
- const pipeline = redis.pipeline();
251
- keys.forEach(key => pipeline.get(key));
252
- const results = await pipeline.exec();
253
- ```
254
-
255
- ### Efficient Scanning
256
-
257
- The implementation uses Redis SCAN operations with cursor-based iteration to efficiently handle large key spaces without blocking the Redis server.
258
-
259
- ### Memory Management
260
-
261
- - Results are filtered and transformed only after pagination is applied
262
- - Large datasets are processed in chunks to prevent memory issues
263
- - Unnecessary data transformations are avoided for better performance
264
-
265
- ## Example Usage
266
-
267
- ### Basic Message Pagination
268
-
269
- ```typescript
270
- // Get first page of messages with pagination metadata
271
- const page1 = await store.getMessages({
272
- threadId: 'thread-123',
273
- page: 0,
274
- perPage: 20,
275
- format: 'v2',
276
- });
277
-
278
- console.log(`Showing ${page1.messages.length} of ${page1.total} messages`);
279
- console.log(`Has more: ${page1.hasMore}`);
280
-
281
- // Backward compatible usage (no pagination metadata)
282
- const allMessages = await store.getMessages({
283
- threadId: 'thread-123',
284
- format: 'v2',
285
- });
286
- console.log(`Retrieved ${allMessages.length} messages`);
287
- ```
288
-
289
- ### Basic Evaluation Pagination
290
-
291
- ```typescript
292
- // Get first page of evaluations for an agent
293
- const page1 = await store.getEvals({
294
- agentName: 'my-agent',
295
- page: 0,
296
- perPage: 20,
297
- });
298
-
299
- console.log(`Showing ${page1.evals.length} of ${page1.total} evaluations`);
300
- console.log(`Has more: ${page1.hasMore}`);
301
- ```
302
-
303
- ### Date Range with Pagination
304
-
305
- ```typescript
306
- // Get recent threads with pagination
307
- const recentThreads = await store.getThreads({
308
- fromDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), // Last 7 days
309
- page: 0,
310
- perPage: 10,
311
- });
312
- ```
313
-
314
- ### Filtered Traces with Pagination
315
-
316
- ```typescript
317
- // Get production traces with specific attributes
318
- const prodTraces = await store.getTracesWithCount({
319
- scope: 'production',
320
- attributes: { environment: 'prod', service: 'api' },
321
- page: 1,
322
- perPage: 50,
323
- });
324
- ```
325
-
326
- ### Message Date Filtering
327
-
328
- ```typescript
329
- // Get recent messages from a thread
330
- const recentMessages = await store.getMessages({
331
- threadId: 'thread-123',
332
- page: 0,
333
- perPage: 10,
334
- fromDate: new Date(Date.now() - 24 * 60 * 60 * 1000), // Last 24 hours
335
- format: 'v2',
336
- });
337
- ```
338
-
339
- ## Best Practices
340
-
341
- 1. **Use appropriate page sizes**: Start with 20-100 items per page depending on data size
342
- 2. **Implement client-side caching**: Cache paginated results to reduce server load
343
- 3. **Handle empty results**: Always check if the returned array is empty
344
- 4. **Use date filters**: Combine pagination with date filters for better performance
345
- 5. **Monitor total counts**: Use the `total` field to implement proper pagination UI
346
- 6. **Choose the right pattern**: Use page/perPage for UI pagination, limit/offset for data processing
347
- 7. **Leverage backward compatibility**: Existing `getMessages` calls work unchanged
348
- 8. **Check return types**: Use TypeScript overloads to get proper type inference
349
-
350
- ## Migration Guide
351
-
352
- The enhanced `getMessages` function is fully backward compatible. No changes are required for existing code, but you can opt into pagination features:
353
-
354
- ### For Messages
355
-
356
- ```typescript
357
- // Existing code (continues to work unchanged)
358
- const messages = await store.getMessages({
359
- threadId: 'thread-123',
360
- format: 'v2',
361
- });
362
-
363
- // Enhanced with pagination (new functionality)
364
- const result = await store.getMessages({
365
- threadId: 'thread-123',
366
- page: 0,
367
- perPage: 20,
368
- format: 'v2',
369
- });
370
- const messages = result.messages;
371
- const total = result.total;
372
- ```
373
-
374
- ### For Other Methods
375
-
376
- If you're using existing methods, they remain backward compatible. To take advantage of new pagination features:
377
-
378
- 1. **Replace** `getEvalsByAgentName()` calls with `getEvals()` for better filtering and pagination
379
- 2. **Replace** `getThreadsByResourceId()` calls with `getThreads()` for date filtering and total counts
380
- 3. **Use** `getMessages()` with pagination parameters instead of complex `selectBy` logic when appropriate
381
- 4. **Use** `getTracesWithCount()` instead of `getTraces()` when you need total counts
382
-
383
- Example migration:
384
-
385
- ```typescript
386
- // Before:
387
- const evals = await store.getEvalsByAgentName('agent-name');
388
-
389
- // After:
390
- const result = await store.getEvals({
391
- agentName: 'agent-name',
392
- page: 0,
393
- perPage: 20,
394
- });
395
- const evals = result.evals;
396
- const total = result.total;
397
- ```
@@ -1,15 +0,0 @@
1
- version: '3'
2
- services:
3
- redis:
4
- image: redis:8-alpine
5
- ports:
6
- - '6379:6379'
7
- command: redis-server --requirepass redis_password
8
- serverless-redis-http:
9
- image: hiett/serverless-redis-http:latest
10
- ports:
11
- - '8079:80'
12
- environment:
13
- SRH_MODE: env
14
- SRH_TOKEN: test_token
15
- SRH_CONNECTION_STRING: 'redis://:redis_password@redis:6379'
package/eslint.config.js DELETED
@@ -1,6 +0,0 @@
1
- import { createConfig } from '@internal/lint/eslint';
2
-
3
- const config = await createConfig();
4
-
5
- /** @type {import("eslint").Linter.Config[]} */
6
- export default [...config];
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './storage';
2
- export * from './vector';
3
- export { UPSTASH_PROMPT } from './vector/prompt';