@mastra/mongodb 0.0.0-working-memory-per-user-20250620161509 → 0.0.0-zod-v4-compat-part-2-20250820135355

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +251 -2
  2. package/LICENSE.md +11 -42
  3. package/dist/index.cjs +1846 -505
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +5 -7
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +1815 -474
  8. package/dist/index.js.map +1 -0
  9. package/dist/storage/MongoDBConnector.d.ts +23 -0
  10. package/dist/storage/MongoDBConnector.d.ts.map +1 -0
  11. package/dist/storage/connectors/MongoDBConnector.d.ts +23 -0
  12. package/dist/storage/connectors/MongoDBConnector.d.ts.map +1 -0
  13. package/dist/storage/connectors/base.d.ts +6 -0
  14. package/dist/storage/connectors/base.d.ts.map +1 -0
  15. package/dist/storage/domains/legacy-evals/index.d.ts +18 -0
  16. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  17. package/dist/storage/domains/memory/index.d.ts +80 -0
  18. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  19. package/dist/storage/domains/operations/index.d.ts +38 -0
  20. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  21. package/dist/storage/domains/scores/index.d.ts +41 -0
  22. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  23. package/dist/storage/domains/traces/index.d.ts +18 -0
  24. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  25. package/dist/storage/domains/utils.d.ts +8 -0
  26. package/dist/storage/domains/utils.d.ts.map +1 -0
  27. package/dist/storage/domains/workflows/index.d.ts +33 -0
  28. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  29. package/dist/storage/index.d.ts +178 -0
  30. package/dist/storage/index.d.ts.map +1 -0
  31. package/dist/storage/types.d.ts +11 -0
  32. package/dist/storage/types.d.ts.map +1 -0
  33. package/dist/vector/filter.d.ts +21 -0
  34. package/dist/vector/filter.d.ts.map +1 -0
  35. package/dist/vector/index.d.ts +78 -0
  36. package/dist/vector/index.d.ts.map +1 -0
  37. package/dist/vector/prompt.d.ts +6 -0
  38. package/dist/vector/prompt.d.ts.map +1 -0
  39. package/docker-compose.yaml +1 -1
  40. package/package.json +10 -10
  41. package/src/index.ts +1 -0
  42. package/src/storage/MongoDBConnector.ts +93 -0
  43. package/src/storage/connectors/MongoDBConnector.ts +93 -0
  44. package/src/storage/connectors/base.ts +7 -0
  45. package/src/storage/domains/legacy-evals/index.ts +193 -0
  46. package/src/storage/domains/memory/index.ts +741 -0
  47. package/src/storage/domains/operations/index.ts +155 -0
  48. package/src/storage/domains/scores/index.ts +379 -0
  49. package/src/storage/domains/traces/index.ts +142 -0
  50. package/src/storage/domains/utils.ts +43 -0
  51. package/src/storage/domains/workflows/index.ts +196 -0
  52. package/src/storage/index.test.ts +27 -989
  53. package/src/storage/index.ts +241 -605
  54. package/src/storage/types.ts +14 -0
  55. package/src/vector/filter.test.ts +40 -30
  56. package/src/vector/filter.ts +25 -4
  57. package/src/vector/index.test.ts +48 -3
  58. package/src/vector/index.ts +301 -131
  59. package/tsconfig.build.json +9 -0
  60. package/tsconfig.json +1 -1
  61. package/tsup.config.ts +22 -0
  62. package/dist/_tsup-dts-rollup.d.cts +0 -274
  63. package/dist/_tsup-dts-rollup.d.ts +0 -274
  64. package/dist/index.d.cts +0 -7
@@ -1,274 +0,0 @@
1
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
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';
6
- import type { EvalRow } from '@mastra/core/storage';
7
- import type { IndexStats } from '@mastra/core/vector';
8
- import type { MastraMessageContentV2 } from '@mastra/core/agent';
9
- import type { MastraMessageV1 } from '@mastra/core/memory';
10
- import type { MastraMessageV2 } from '@mastra/core/memory';
11
- import { MastraStorage } from '@mastra/core/storage';
12
- import { MastraVector } from '@mastra/core/vector';
13
- import type { MongoClientOptions } from 'mongodb';
14
- import type { OperatorSupport } from '@mastra/core/vector/filter';
15
- import type { PaginationInfo } from '@mastra/core/storage';
16
- import type { QueryResult } from '@mastra/core/vector';
17
- import type { QueryVectorParams } from '@mastra/core/vector';
18
- import type { StorageColumn } from '@mastra/core/storage';
19
- import type { StorageGetMessagesArg } from '@mastra/core/storage';
20
- import type { StorageGetTracesArg } from '@mastra/core/storage';
21
- import type { StorageThreadType } from '@mastra/core/memory';
22
- import type { TABLE_NAMES } from '@mastra/core/storage';
23
- import type { Trace } from '@mastra/core/telemetry';
24
- import type { UpdateVectorParams } from '@mastra/core/vector';
25
- import type { UpsertVectorParams } from '@mastra/core/vector';
26
- import type { VectorFilter } from '@mastra/core/vector/filter';
27
- import type { WorkflowRun } from '@mastra/core/storage';
28
- import type { WorkflowRunState } from '@mastra/core/workflows';
29
-
30
- /**
31
- * Vector store specific prompt that details supported operators and examples.
32
- * This prompt helps users construct valid filters for MongoDB Vector.
33
- */
34
- declare const MONGODB_PROMPT = "When querying MongoDB 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- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $size: Match arrays with specific length\n Example: { \"tags\": { \"$size\": 3 } }\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- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $type: Check field type\n Example: { \"price\": { \"$type\": \"number\" } }\n\nText Search Operators:\n- $text: Full text search\n Example: { \"$text\": { \"$search\": \"gaming laptop\" } }\n- $regex: Regular expression match\n Example: { \"name\": { \"$regex\": \"^Gaming\" } }\n\nRestrictions:\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- Empty arrays in array operators will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported\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, $not, $nor):\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 { \"tags\": { \"$all\": [\"premium\", \"sale\"] } },\n { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 50 }, \"inStock\": true } } },\n { \"$text\": { \"$search\": \"gaming laptop\" } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]},\n { \"$not\": { \"status\": \"discontinued\" } }\n ]\n}";
35
- export { MONGODB_PROMPT }
36
- export { MONGODB_PROMPT as MONGODB_PROMPT_alias_1 }
37
-
38
- declare interface MongoDBConfig {
39
- url: string;
40
- dbName: string;
41
- options?: MongoClientOptions;
42
- }
43
- export { MongoDBConfig }
44
- export { MongoDBConfig as MongoDBConfig_alias_1 }
45
-
46
- /**
47
- * Translator for MongoDB filter queries.
48
- * Maintains MongoDB-compatible syntax while ensuring proper validation
49
- * and normalization of values.
50
- */
51
- export declare class MongoDBFilterTranslator extends BaseFilterTranslator {
52
- protected getSupportedOperators(): OperatorSupport;
53
- translate(filter?: VectorFilter): any;
54
- private translateNode;
55
- private translateOperatorValue;
56
- isEmpty(filter: any): boolean;
57
- }
58
-
59
- declare interface MongoDBIndexReadyParams {
60
- indexName: string;
61
- timeoutMs?: number;
62
- checkIntervalMs?: number;
63
- }
64
- export { MongoDBIndexReadyParams }
65
- export { MongoDBIndexReadyParams as MongoDBIndexReadyParams_alias_1 }
66
-
67
- declare interface MongoDBQueryVectorParams extends QueryVectorParams {
68
- documentFilter?: VectorFilter;
69
- }
70
- export { MongoDBQueryVectorParams }
71
- export { MongoDBQueryVectorParams as MongoDBQueryVectorParams_alias_1 }
72
-
73
- declare class MongoDBStore extends MastraStorage {
74
- #private;
75
- constructor(config: MongoDBConfig);
76
- private getConnection;
77
- private getCollection;
78
- createTable(): Promise<void>;
79
- /**
80
- * No-op: This backend is schemaless and does not require schema changes.
81
- * @param tableName Name of the table
82
- * @param schema Schema of the table
83
- * @param ifNotExists Array of column names to add if they don't exist
84
- */
85
- alterTable(_args: {
86
- tableName: TABLE_NAMES;
87
- schema: Record<string, StorageColumn>;
88
- ifNotExists: string[];
89
- }): Promise<void>;
90
- clearTable({ tableName }: {
91
- tableName: TABLE_NAMES;
92
- }): Promise<void>;
93
- insert({ tableName, record }: {
94
- tableName: TABLE_NAMES;
95
- record: Record<string, any>;
96
- }): Promise<void>;
97
- batchInsert({ tableName, records }: {
98
- tableName: TABLE_NAMES;
99
- records: Record<string, any>[];
100
- }): Promise<void>;
101
- load<R>({ tableName, keys }: {
102
- tableName: TABLE_NAMES;
103
- keys: Record<string, string>;
104
- }): Promise<R | null>;
105
- getThreadById({ threadId }: {
106
- threadId: string;
107
- }): Promise<StorageThreadType | null>;
108
- getThreadsByResourceId({ resourceId }: {
109
- resourceId: string;
110
- }): Promise<StorageThreadType[]>;
111
- saveThread({ thread }: {
112
- thread: StorageThreadType;
113
- }): Promise<StorageThreadType>;
114
- updateThread({ id, title, metadata, }: {
115
- id: string;
116
- title: string;
117
- metadata: Record<string, unknown>;
118
- }): Promise<StorageThreadType>;
119
- deleteThread({ threadId }: {
120
- threadId: string;
121
- }): Promise<void>;
122
- getMessages(args: StorageGetMessagesArg & {
123
- format?: 'v1';
124
- }): Promise<MastraMessageV1[]>;
125
- getMessages(args: StorageGetMessagesArg & {
126
- format: 'v2';
127
- }): Promise<MastraMessageV2[]>;
128
- saveMessages(args: {
129
- messages: MastraMessageV1[];
130
- format?: undefined | 'v1';
131
- }): Promise<MastraMessageV1[]>;
132
- saveMessages(args: {
133
- messages: MastraMessageV2[];
134
- format: 'v2';
135
- }): Promise<MastraMessageV2[]>;
136
- getTraces({ name, scope, page, perPage, attributes, filters, }?: {
137
- name?: string;
138
- scope?: string;
139
- page: number;
140
- perPage: number;
141
- attributes?: Record<string, string>;
142
- filters?: Record<string, any>;
143
- }): Promise<any[]>;
144
- getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
145
- workflowName?: string;
146
- fromDate?: Date;
147
- toDate?: Date;
148
- limit?: number;
149
- offset?: number;
150
- }): Promise<{
151
- runs: Array<{
152
- workflowName: string;
153
- runId: string;
154
- snapshot: WorkflowRunState | string;
155
- createdAt: Date;
156
- updatedAt: Date;
157
- }>;
158
- total: number;
159
- }>;
160
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
161
- persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
162
- workflowName: string;
163
- runId: string;
164
- snapshot: WorkflowRunState;
165
- }): Promise<void>;
166
- loadWorkflowSnapshot({ workflowName, runId, }: {
167
- workflowName: string;
168
- runId: string;
169
- }): Promise<WorkflowRunState | null>;
170
- getWorkflowRunById({ runId, workflowName, }: {
171
- runId: string;
172
- workflowName?: string;
173
- }): Promise<WorkflowRun | null>;
174
- private parseWorkflowRun;
175
- private parseRow;
176
- private transformEvalRow;
177
- getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
178
- traces: Trace[];
179
- }>;
180
- getThreadsByResourceIdPaginated(_args: {
181
- resourceId: string;
182
- page?: number;
183
- perPage?: number;
184
- }): Promise<PaginationInfo & {
185
- threads: StorageThreadType[];
186
- }>;
187
- getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
188
- messages: MastraMessageV1[] | MastraMessageV2[];
189
- }>;
190
- close(): Promise<void>;
191
- updateMessages(_args: {
192
- messages: Partial<Omit<MastraMessageV2, 'createdAt'>> & {
193
- id: string;
194
- content?: {
195
- metadata?: MastraMessageContentV2['metadata'];
196
- content?: MastraMessageContentV2['content'];
197
- };
198
- }[];
199
- }): Promise<MastraMessageV2[]>;
200
- }
201
- export { MongoDBStore }
202
- export { MongoDBStore as MongoDBStore_alias_1 }
203
-
204
- declare interface MongoDBUpsertVectorParams extends UpsertVectorParams {
205
- documents?: string[];
206
- }
207
- export { MongoDBUpsertVectorParams }
208
- export { MongoDBUpsertVectorParams as MongoDBUpsertVectorParams_alias_1 }
209
-
210
- declare class MongoDBVector extends MastraVector {
211
- private client;
212
- private db;
213
- private collections;
214
- private readonly embeddingFieldName;
215
- private readonly metadataFieldName;
216
- private readonly documentFieldName;
217
- private collectionForValidation;
218
- private mongoMetricMap;
219
- constructor({ uri, dbName, options }: {
220
- uri: string;
221
- dbName: string;
222
- options?: MongoClientOptions;
223
- });
224
- connect(): Promise<void>;
225
- disconnect(): Promise<void>;
226
- createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
227
- /**
228
- * Waits for the index to be ready.
229
- *
230
- * @param {string} indexName - The name of the index to wait for
231
- * @param {number} timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
232
- * @param {number} checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
233
- * @returns A promise that resolves when the index is ready
234
- */
235
- waitForIndexReady({ indexName, timeoutMs, checkIntervalMs, }: MongoDBIndexReadyParams): Promise<void>;
236
- upsert({ indexName, vectors, metadata, ids, documents }: MongoDBUpsertVectorParams): Promise<string[]>;
237
- query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: MongoDBQueryVectorParams): Promise<QueryResult[]>;
238
- listIndexes(): Promise<string[]>;
239
- /**
240
- * Retrieves statistics about a vector index.
241
- *
242
- * @param {string} indexName - The name of the index to describe
243
- * @returns A promise that resolves to the index statistics including dimension, count and metric
244
- */
245
- describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
246
- deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
247
- /**
248
- * Updates a vector by its ID with the provided vector and/or metadata.
249
- * @param indexName - The name of the index containing the vector.
250
- * @param id - The ID of the vector to update.
251
- * @param update - An object containing the vector and/or metadata to update.
252
- * @param update.vector - An optional array of numbers representing the new vector.
253
- * @param update.metadata - An optional record containing the new metadata.
254
- * @returns A promise that resolves when the update is complete.
255
- * @throws Will throw an error if no updates are provided or if the update operation fails.
256
- */
257
- updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
258
- /**
259
- * Deletes a vector by its ID.
260
- * @param indexName - The name of the index containing the vector.
261
- * @param id - The ID of the vector to delete.
262
- * @returns A promise that resolves when the deletion is complete.
263
- * @throws Will throw an error if the deletion operation fails.
264
- */
265
- deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
266
- private getCollection;
267
- private validateVectorDimensions;
268
- private setIndexDimension;
269
- private transformFilter;
270
- }
271
- export { MongoDBVector }
272
- export { MongoDBVector as MongoDBVector_alias_1 }
273
-
274
- export { }
@@ -1,274 +0,0 @@
1
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
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';
6
- import type { EvalRow } from '@mastra/core/storage';
7
- import type { IndexStats } from '@mastra/core/vector';
8
- import type { MastraMessageContentV2 } from '@mastra/core/agent';
9
- import type { MastraMessageV1 } from '@mastra/core/memory';
10
- import type { MastraMessageV2 } from '@mastra/core/memory';
11
- import { MastraStorage } from '@mastra/core/storage';
12
- import { MastraVector } from '@mastra/core/vector';
13
- import type { MongoClientOptions } from 'mongodb';
14
- import type { OperatorSupport } from '@mastra/core/vector/filter';
15
- import type { PaginationInfo } from '@mastra/core/storage';
16
- import type { QueryResult } from '@mastra/core/vector';
17
- import type { QueryVectorParams } from '@mastra/core/vector';
18
- import type { StorageColumn } from '@mastra/core/storage';
19
- import type { StorageGetMessagesArg } from '@mastra/core/storage';
20
- import type { StorageGetTracesArg } from '@mastra/core/storage';
21
- import type { StorageThreadType } from '@mastra/core/memory';
22
- import type { TABLE_NAMES } from '@mastra/core/storage';
23
- import type { Trace } from '@mastra/core/telemetry';
24
- import type { UpdateVectorParams } from '@mastra/core/vector';
25
- import type { UpsertVectorParams } from '@mastra/core/vector';
26
- import type { VectorFilter } from '@mastra/core/vector/filter';
27
- import type { WorkflowRun } from '@mastra/core/storage';
28
- import type { WorkflowRunState } from '@mastra/core/workflows';
29
-
30
- /**
31
- * Vector store specific prompt that details supported operators and examples.
32
- * This prompt helps users construct valid filters for MongoDB Vector.
33
- */
34
- declare const MONGODB_PROMPT = "When querying MongoDB 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- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $size: Match arrays with specific length\n Example: { \"tags\": { \"$size\": 3 } }\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- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n- $type: Check field type\n Example: { \"price\": { \"$type\": \"number\" } }\n\nText Search Operators:\n- $text: Full text search\n Example: { \"$text\": { \"$search\": \"gaming laptop\" } }\n- $regex: Regular expression match\n Example: { \"name\": { \"$regex\": \"^Gaming\" } }\n\nRestrictions:\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- Empty arrays in array operators will return no results\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported\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, $not, $nor):\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 { \"tags\": { \"$all\": [\"premium\", \"sale\"] } },\n { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 50 }, \"inStock\": true } } },\n { \"$text\": { \"$search\": \"gaming laptop\" } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]},\n { \"$not\": { \"status\": \"discontinued\" } }\n ]\n}";
35
- export { MONGODB_PROMPT }
36
- export { MONGODB_PROMPT as MONGODB_PROMPT_alias_1 }
37
-
38
- declare interface MongoDBConfig {
39
- url: string;
40
- dbName: string;
41
- options?: MongoClientOptions;
42
- }
43
- export { MongoDBConfig }
44
- export { MongoDBConfig as MongoDBConfig_alias_1 }
45
-
46
- /**
47
- * Translator for MongoDB filter queries.
48
- * Maintains MongoDB-compatible syntax while ensuring proper validation
49
- * and normalization of values.
50
- */
51
- export declare class MongoDBFilterTranslator extends BaseFilterTranslator {
52
- protected getSupportedOperators(): OperatorSupport;
53
- translate(filter?: VectorFilter): any;
54
- private translateNode;
55
- private translateOperatorValue;
56
- isEmpty(filter: any): boolean;
57
- }
58
-
59
- declare interface MongoDBIndexReadyParams {
60
- indexName: string;
61
- timeoutMs?: number;
62
- checkIntervalMs?: number;
63
- }
64
- export { MongoDBIndexReadyParams }
65
- export { MongoDBIndexReadyParams as MongoDBIndexReadyParams_alias_1 }
66
-
67
- declare interface MongoDBQueryVectorParams extends QueryVectorParams {
68
- documentFilter?: VectorFilter;
69
- }
70
- export { MongoDBQueryVectorParams }
71
- export { MongoDBQueryVectorParams as MongoDBQueryVectorParams_alias_1 }
72
-
73
- declare class MongoDBStore extends MastraStorage {
74
- #private;
75
- constructor(config: MongoDBConfig);
76
- private getConnection;
77
- private getCollection;
78
- createTable(): Promise<void>;
79
- /**
80
- * No-op: This backend is schemaless and does not require schema changes.
81
- * @param tableName Name of the table
82
- * @param schema Schema of the table
83
- * @param ifNotExists Array of column names to add if they don't exist
84
- */
85
- alterTable(_args: {
86
- tableName: TABLE_NAMES;
87
- schema: Record<string, StorageColumn>;
88
- ifNotExists: string[];
89
- }): Promise<void>;
90
- clearTable({ tableName }: {
91
- tableName: TABLE_NAMES;
92
- }): Promise<void>;
93
- insert({ tableName, record }: {
94
- tableName: TABLE_NAMES;
95
- record: Record<string, any>;
96
- }): Promise<void>;
97
- batchInsert({ tableName, records }: {
98
- tableName: TABLE_NAMES;
99
- records: Record<string, any>[];
100
- }): Promise<void>;
101
- load<R>({ tableName, keys }: {
102
- tableName: TABLE_NAMES;
103
- keys: Record<string, string>;
104
- }): Promise<R | null>;
105
- getThreadById({ threadId }: {
106
- threadId: string;
107
- }): Promise<StorageThreadType | null>;
108
- getThreadsByResourceId({ resourceId }: {
109
- resourceId: string;
110
- }): Promise<StorageThreadType[]>;
111
- saveThread({ thread }: {
112
- thread: StorageThreadType;
113
- }): Promise<StorageThreadType>;
114
- updateThread({ id, title, metadata, }: {
115
- id: string;
116
- title: string;
117
- metadata: Record<string, unknown>;
118
- }): Promise<StorageThreadType>;
119
- deleteThread({ threadId }: {
120
- threadId: string;
121
- }): Promise<void>;
122
- getMessages(args: StorageGetMessagesArg & {
123
- format?: 'v1';
124
- }): Promise<MastraMessageV1[]>;
125
- getMessages(args: StorageGetMessagesArg & {
126
- format: 'v2';
127
- }): Promise<MastraMessageV2[]>;
128
- saveMessages(args: {
129
- messages: MastraMessageV1[];
130
- format?: undefined | 'v1';
131
- }): Promise<MastraMessageV1[]>;
132
- saveMessages(args: {
133
- messages: MastraMessageV2[];
134
- format: 'v2';
135
- }): Promise<MastraMessageV2[]>;
136
- getTraces({ name, scope, page, perPage, attributes, filters, }?: {
137
- name?: string;
138
- scope?: string;
139
- page: number;
140
- perPage: number;
141
- attributes?: Record<string, string>;
142
- filters?: Record<string, any>;
143
- }): Promise<any[]>;
144
- getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
145
- workflowName?: string;
146
- fromDate?: Date;
147
- toDate?: Date;
148
- limit?: number;
149
- offset?: number;
150
- }): Promise<{
151
- runs: Array<{
152
- workflowName: string;
153
- runId: string;
154
- snapshot: WorkflowRunState | string;
155
- createdAt: Date;
156
- updatedAt: Date;
157
- }>;
158
- total: number;
159
- }>;
160
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
161
- persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
162
- workflowName: string;
163
- runId: string;
164
- snapshot: WorkflowRunState;
165
- }): Promise<void>;
166
- loadWorkflowSnapshot({ workflowName, runId, }: {
167
- workflowName: string;
168
- runId: string;
169
- }): Promise<WorkflowRunState | null>;
170
- getWorkflowRunById({ runId, workflowName, }: {
171
- runId: string;
172
- workflowName?: string;
173
- }): Promise<WorkflowRun | null>;
174
- private parseWorkflowRun;
175
- private parseRow;
176
- private transformEvalRow;
177
- getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
178
- traces: Trace[];
179
- }>;
180
- getThreadsByResourceIdPaginated(_args: {
181
- resourceId: string;
182
- page?: number;
183
- perPage?: number;
184
- }): Promise<PaginationInfo & {
185
- threads: StorageThreadType[];
186
- }>;
187
- getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
188
- messages: MastraMessageV1[] | MastraMessageV2[];
189
- }>;
190
- close(): Promise<void>;
191
- updateMessages(_args: {
192
- messages: Partial<Omit<MastraMessageV2, 'createdAt'>> & {
193
- id: string;
194
- content?: {
195
- metadata?: MastraMessageContentV2['metadata'];
196
- content?: MastraMessageContentV2['content'];
197
- };
198
- }[];
199
- }): Promise<MastraMessageV2[]>;
200
- }
201
- export { MongoDBStore }
202
- export { MongoDBStore as MongoDBStore_alias_1 }
203
-
204
- declare interface MongoDBUpsertVectorParams extends UpsertVectorParams {
205
- documents?: string[];
206
- }
207
- export { MongoDBUpsertVectorParams }
208
- export { MongoDBUpsertVectorParams as MongoDBUpsertVectorParams_alias_1 }
209
-
210
- declare class MongoDBVector extends MastraVector {
211
- private client;
212
- private db;
213
- private collections;
214
- private readonly embeddingFieldName;
215
- private readonly metadataFieldName;
216
- private readonly documentFieldName;
217
- private collectionForValidation;
218
- private mongoMetricMap;
219
- constructor({ uri, dbName, options }: {
220
- uri: string;
221
- dbName: string;
222
- options?: MongoClientOptions;
223
- });
224
- connect(): Promise<void>;
225
- disconnect(): Promise<void>;
226
- createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
227
- /**
228
- * Waits for the index to be ready.
229
- *
230
- * @param {string} indexName - The name of the index to wait for
231
- * @param {number} timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
232
- * @param {number} checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
233
- * @returns A promise that resolves when the index is ready
234
- */
235
- waitForIndexReady({ indexName, timeoutMs, checkIntervalMs, }: MongoDBIndexReadyParams): Promise<void>;
236
- upsert({ indexName, vectors, metadata, ids, documents }: MongoDBUpsertVectorParams): Promise<string[]>;
237
- query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: MongoDBQueryVectorParams): Promise<QueryResult[]>;
238
- listIndexes(): Promise<string[]>;
239
- /**
240
- * Retrieves statistics about a vector index.
241
- *
242
- * @param {string} indexName - The name of the index to describe
243
- * @returns A promise that resolves to the index statistics including dimension, count and metric
244
- */
245
- describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
246
- deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
247
- /**
248
- * Updates a vector by its ID with the provided vector and/or metadata.
249
- * @param indexName - The name of the index containing the vector.
250
- * @param id - The ID of the vector to update.
251
- * @param update - An object containing the vector and/or metadata to update.
252
- * @param update.vector - An optional array of numbers representing the new vector.
253
- * @param update.metadata - An optional record containing the new metadata.
254
- * @returns A promise that resolves when the update is complete.
255
- * @throws Will throw an error if no updates are provided or if the update operation fails.
256
- */
257
- updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
258
- /**
259
- * Deletes a vector by its ID.
260
- * @param indexName - The name of the index containing the vector.
261
- * @param id - The ID of the vector to delete.
262
- * @returns A promise that resolves when the deletion is complete.
263
- * @throws Will throw an error if the deletion operation fails.
264
- */
265
- deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
266
- private getCollection;
267
- private validateVectorDimensions;
268
- private setIndexDimension;
269
- private transformFilter;
270
- }
271
- export { MongoDBVector }
272
- export { MongoDBVector as MongoDBVector_alias_1 }
273
-
274
- export { }
package/dist/index.d.cts DELETED
@@ -1,7 +0,0 @@
1
- export { MONGODB_PROMPT } from './_tsup-dts-rollup.cjs';
2
- export { MongoDBUpsertVectorParams } from './_tsup-dts-rollup.cjs';
3
- export { MongoDBQueryVectorParams } from './_tsup-dts-rollup.cjs';
4
- export { MongoDBIndexReadyParams } from './_tsup-dts-rollup.cjs';
5
- export { MongoDBVector } from './_tsup-dts-rollup.cjs';
6
- export { MongoDBConfig } from './_tsup-dts-rollup.cjs';
7
- export { MongoDBStore } from './_tsup-dts-rollup.cjs';