@mastra/upstash 0.0.0-vnextWorkflows-20250422142014 → 0.0.0-workflow-deno-20250616115451

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.
@@ -1,21 +1,39 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { EvalRow } from '@mastra/core/storage';
7
+ import type { IndexStats } from '@mastra/core/vector';
8
+ import type { MastraMessageV1 } from '@mastra/core/memory';
9
+ import type { MastraMessageV2 } from '@mastra/core/memory';
4
10
  import { MastraStorage } from '@mastra/core/storage';
5
11
  import { MastraVector } from '@mastra/core/vector';
6
- import type { MessageType } from '@mastra/core/memory';
7
12
  import type { OperatorSupport } from '@mastra/core/vector/filter';
8
- import type { ParamsToArgs } from '@mastra/core/vector';
13
+ import type { PaginationArgs } from '@mastra/core/storage';
14
+ import type { PaginationInfo } from '@mastra/core/storage';
9
15
  import type { QueryResult } from '@mastra/core/vector';
10
16
  import type { QueryVectorParams } from '@mastra/core/vector';
11
17
  import type { StorageColumn } from '@mastra/core/storage';
12
18
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
19
+ import type { StorageGetTracesArg } from '@mastra/core/storage';
13
20
  import type { StorageThreadType } from '@mastra/core/memory';
14
21
  import type { TABLE_NAMES } from '@mastra/core/storage';
22
+ import type { UpdateVectorParams } from '@mastra/core/vector';
15
23
  import type { UpsertVectorParams } from '@mastra/core/vector';
16
24
  import type { VectorFilter } from '@mastra/core/vector/filter';
25
+ import type { WorkflowRun } from '@mastra/core/storage';
26
+ import type { WorkflowRuns } from '@mastra/core/storage';
17
27
  import type { WorkflowRunState } from '@mastra/core/workflows';
18
28
 
29
+ /**
30
+ * Vector store specific prompt that details supported operators and examples.
31
+ * This prompt helps users construct valid filters for Upstash Vector.
32
+ */
33
+ declare const UPSTASH_PROMPT = "When querying Upstash Vector, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (can be implicit or explicit)\n Implicit Example: { \"price\": { \"$gt\": 100 }, \"category\": \"electronics\" }\n Explicit Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nRestrictions:\n- Regex patterns are not supported\n- Only $and and $or logical operators are supported at the top level\n- Empty arrays in $in/$nin will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- At least one key-value pair is required in filter object\n- Empty objects and undefined values are treated as no filter\n- Invalid types in comparison operators will throw errors\n- All non-logical operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
34
+ export { UPSTASH_PROMPT }
35
+ export { UPSTASH_PROMPT as UPSTASH_PROMPT_alias_1 }
36
+
19
37
  declare interface UpstashConfig {
20
38
  url: string;
21
39
  token: string;
@@ -38,30 +56,61 @@ export declare class UpstashFilterTranslator extends BaseFilterTranslator {
38
56
  }
39
57
 
40
58
  declare class UpstashStore extends MastraStorage {
41
- batchInsert(_input: {
42
- tableName: TABLE_NAMES;
43
- records: Record<string, any>[];
44
- }): Promise<void>;
45
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
59
+ private redis;
60
+ constructor(config: UpstashConfig);
61
+ get supports(): {
62
+ selectByIncludeResourceScope: boolean;
63
+ };
46
64
  private transformEvalRecord;
47
- getTraces({ name, scope, page, perPage, attributes, filters, }?: {
65
+ private parseJSON;
66
+ private getKey;
67
+ /**
68
+ * Scans for keys matching the given pattern using SCAN and returns them as an array.
69
+ * @param pattern Redis key pattern, e.g. "table:*"
70
+ * @param batchSize Number of keys to scan per batch (default: 1000)
71
+ */
72
+ private scanKeys;
73
+ /**
74
+ * Deletes all keys matching the given pattern using SCAN and DEL in batches.
75
+ * @param pattern Redis key pattern, e.g. "table:*"
76
+ * @param batchSize Number of keys to delete per batch (default: 1000)
77
+ */
78
+ private scanAndDelete;
79
+ private getMessageKey;
80
+ private getThreadMessagesKey;
81
+ private parseWorkflowRun;
82
+ private processRecord;
83
+ /**
84
+ * @deprecated Use getEvals instead
85
+ */
86
+ getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
87
+ /**
88
+ * @deprecated use getTracesPaginated instead
89
+ */
90
+ getTraces(args: StorageGetTracesArg): Promise<any[]>;
91
+ getTracesPaginated(args: {
48
92
  name?: string;
49
93
  scope?: string;
50
- page: number;
51
- perPage: number;
52
94
  attributes?: Record<string, string>;
53
95
  filters?: Record<string, any>;
54
- }): Promise<any[]>;
55
- private parseJSON;
56
- private redis;
57
- constructor(config: UpstashConfig);
58
- private getKey;
59
- private ensureDate;
60
- private serializeDate;
96
+ } & PaginationArgs): Promise<PaginationInfo & {
97
+ traces: any[];
98
+ }>;
61
99
  createTable({ tableName, schema, }: {
62
100
  tableName: TABLE_NAMES;
63
101
  schema: Record<string, StorageColumn>;
64
102
  }): Promise<void>;
103
+ /**
104
+ * No-op: This backend is schemaless and does not require schema changes.
105
+ * @param tableName Name of the table
106
+ * @param schema Schema of the table
107
+ * @param ifNotExists Array of column names to add if they don't exist
108
+ */
109
+ alterTable(_args: {
110
+ tableName: TABLE_NAMES;
111
+ schema: Record<string, StorageColumn>;
112
+ ifNotExists: string[];
113
+ }): Promise<void>;
65
114
  clearTable({ tableName }: {
66
115
  tableName: TABLE_NAMES;
67
116
  }): Promise<void>;
@@ -69,6 +118,10 @@ declare class UpstashStore extends MastraStorage {
69
118
  tableName: TABLE_NAMES;
70
119
  record: Record<string, any>;
71
120
  }): Promise<void>;
121
+ batchInsert(input: {
122
+ tableName: TABLE_NAMES;
123
+ records: Record<string, any>[];
124
+ }): Promise<void>;
72
125
  load<R>({ tableName, keys }: {
73
126
  tableName: TABLE_NAMES;
74
127
  keys: Record<string, string>;
@@ -76,9 +129,17 @@ declare class UpstashStore extends MastraStorage {
76
129
  getThreadById({ threadId }: {
77
130
  threadId: string;
78
131
  }): Promise<StorageThreadType | null>;
132
+ /**
133
+ * @deprecated use getThreadsByResourceIdPaginated instead
134
+ */
79
135
  getThreadsByResourceId({ resourceId }: {
80
136
  resourceId: string;
81
137
  }): Promise<StorageThreadType[]>;
138
+ getThreadsByResourceIdPaginated(args: {
139
+ resourceId: string;
140
+ } & PaginationArgs): Promise<PaginationInfo & {
141
+ threads: StorageThreadType[];
142
+ }>;
82
143
  saveThread({ thread }: {
83
144
  thread: StorageThreadType;
84
145
  }): Promise<StorageThreadType>;
@@ -90,12 +151,29 @@ declare class UpstashStore extends MastraStorage {
90
151
  deleteThread({ threadId }: {
91
152
  threadId: string;
92
153
  }): Promise<void>;
93
- private getMessageKey;
94
- private getThreadMessagesKey;
95
- saveMessages({ messages }: {
96
- messages: MessageType[];
97
- }): Promise<MessageType[]>;
98
- getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
154
+ saveMessages(args: {
155
+ messages: MastraMessageV1[];
156
+ format?: undefined | 'v1';
157
+ }): Promise<MastraMessageV1[]>;
158
+ saveMessages(args: {
159
+ messages: MastraMessageV2[];
160
+ format: 'v2';
161
+ }): Promise<MastraMessageV2[]>;
162
+ private _getIncludedMessages;
163
+ /**
164
+ * @deprecated use getMessagesPaginated instead
165
+ */
166
+ getMessages(args: StorageGetMessagesArg & {
167
+ format?: 'v1';
168
+ }): Promise<MastraMessageV1[]>;
169
+ getMessages(args: StorageGetMessagesArg & {
170
+ format: 'v2';
171
+ }): Promise<MastraMessageV2[]>;
172
+ getMessagesPaginated(args: StorageGetMessagesArg & {
173
+ format?: 'v1' | 'v2';
174
+ }): Promise<PaginationInfo & {
175
+ messages: MastraMessageV1[] | MastraMessageV2[];
176
+ }>;
99
177
  persistWorkflowSnapshot(params: {
100
178
  namespace: string;
101
179
  workflowName: string;
@@ -107,23 +185,31 @@ declare class UpstashStore extends MastraStorage {
107
185
  workflowName: string;
108
186
  runId: string;
109
187
  }): Promise<WorkflowRunState | null>;
110
- getWorkflowRuns({ namespace, workflowName, fromDate, toDate, limit, offset, }?: {
188
+ /**
189
+ * Get all evaluations with pagination and total count
190
+ * @param options Pagination and filtering options
191
+ * @returns Object with evals array and total count
192
+ */
193
+ getEvals(options?: {
194
+ agentName?: string;
195
+ type?: 'test' | 'live';
196
+ } & PaginationArgs): Promise<PaginationInfo & {
197
+ evals: EvalRow[];
198
+ }>;
199
+ getWorkflowRuns({ namespace, workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
111
200
  namespace: string;
112
201
  workflowName?: string;
113
202
  fromDate?: Date;
114
203
  toDate?: Date;
115
204
  limit?: number;
116
205
  offset?: number;
117
- }): Promise<{
118
- runs: Array<{
119
- workflowName: string;
120
- runId: string;
121
- snapshot: WorkflowRunState | string;
122
- createdAt: Date;
123
- updatedAt: Date;
124
- }>;
125
- total: number;
126
- }>;
206
+ resourceId?: string;
207
+ }): Promise<WorkflowRuns>;
208
+ getWorkflowRunById({ namespace, runId, workflowName, }: {
209
+ namespace: string;
210
+ runId: string;
211
+ workflowName?: string;
212
+ }): Promise<WorkflowRun | null>;
127
213
  close(): Promise<void>;
128
214
  }
129
215
  export { UpstashStore }
@@ -135,22 +221,38 @@ declare class UpstashVector extends MastraVector {
135
221
  url: string;
136
222
  token: string;
137
223
  });
138
- upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
224
+ upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
139
225
  transformFilter(filter?: VectorFilter): string | undefined;
140
- createIndex(..._args: ParamsToArgs<CreateIndexParams>): Promise<void>;
141
- query(...args: ParamsToArgs<QueryVectorParams>): Promise<QueryResult[]>;
226
+ createIndex(_params: CreateIndexParams): Promise<void>;
227
+ query({ indexName, queryVector, topK, filter, includeVector, }: QueryVectorParams): Promise<QueryResult[]>;
142
228
  listIndexes(): Promise<string[]>;
143
- describeIndex(indexName: string): Promise<{
144
- dimension: number;
145
- count: number;
146
- metric: "cosine" | "euclidean" | "dotproduct";
147
- }>;
148
- deleteIndex(indexName: string): Promise<void>;
149
- updateIndexById(indexName: string, id: string, update: {
150
- vector?: number[];
151
- metadata?: Record<string, any>;
152
- }): Promise<void>;
153
- deleteIndexById(indexName: string, id: string): Promise<void>;
229
+ /**
230
+ * Retrieves statistics about a vector index.
231
+ *
232
+ * @param {string} indexName - The name of the index to describe
233
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
234
+ */
235
+ describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
236
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
237
+ /**
238
+ * Updates a vector by its ID with the provided vector and/or metadata.
239
+ * @param indexName - The name of the index containing the vector.
240
+ * @param id - The ID of the vector to update.
241
+ * @param update - An object containing the vector and/or metadata to update.
242
+ * @param update.vector - An optional array of numbers representing the new vector.
243
+ * @param update.metadata - An optional record containing the new metadata.
244
+ * @returns A promise that resolves when the update is complete.
245
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
246
+ */
247
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
248
+ /**
249
+ * Deletes a vector by its ID.
250
+ * @param indexName - The name of the index containing the vector.
251
+ * @param id - The ID of the vector to delete.
252
+ * @returns A promise that resolves when the deletion is complete.
253
+ * @throws Will throw an error if the deletion operation fails.
254
+ */
255
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
154
256
  }
155
257
  export { UpstashVector }
156
258
  export { UpstashVector as UpstashVector_alias_1 }