@mastra/mongodb 0.10.0 → 0.10.1-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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +9 -0
- package/README.md +50 -0
- package/dist/_tsup-dts-rollup.d.cts +103 -0
- package/dist/_tsup-dts-rollup.d.ts +103 -0
- package/dist/index.cjs +520 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +520 -1
- package/docker-compose.yaml +30 -0
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/storage/index.test.ts +779 -0
- package/src/storage/index.ts +674 -0
- package/docker-compose.yml +0 -8
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/mongodb@0.10.
|
|
2
|
+
> @mastra/mongodb@0.10.1-alpha.0 build /home/runner/work/mastra/mastra/stores/mongodb
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 11126ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 13746ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m32.81 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 1273ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m32.93 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 1273ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 0.10.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fcc915f: Support MongoDB database as store
|
|
8
|
+
- Updated dependencies [6d16390]
|
|
9
|
+
- Updated dependencies [1e4a421]
|
|
10
|
+
- @mastra/core@0.10.1-alpha.0
|
|
11
|
+
|
|
3
12
|
## 0.10.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -56,6 +56,40 @@ const results = await vectorDB.query({
|
|
|
56
56
|
await vectorDB.disconnect();
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
### Storage
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { MongoDBStore } from '@mastra/mongodb';
|
|
63
|
+
|
|
64
|
+
const store = new MongoDBStore({
|
|
65
|
+
uri: 'mongodb://mongodb:mongodb@localhost:27018/?authSource=admin&directConnection=true',
|
|
66
|
+
dbName: 'mastra',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Create a thread
|
|
70
|
+
await store.saveThread({
|
|
71
|
+
id: 'thread-123',
|
|
72
|
+
resourceId: 'resource-456',
|
|
73
|
+
title: 'My Thread',
|
|
74
|
+
metadata: { key: 'value' },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Add messages to thread
|
|
78
|
+
await store.saveMessages([
|
|
79
|
+
{
|
|
80
|
+
id: 'msg-789',
|
|
81
|
+
threadId: 'thread-123',
|
|
82
|
+
role: 'user',
|
|
83
|
+
type: 'text',
|
|
84
|
+
content: [{ type: 'text', text: 'Hello' }],
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
// Query threads and messages
|
|
89
|
+
const savedThread = await store.getThread('thread-123');
|
|
90
|
+
const messages = await store.getMessages('thread-123');
|
|
91
|
+
```
|
|
92
|
+
|
|
59
93
|
## Configuration
|
|
60
94
|
|
|
61
95
|
The MongoDB vector store is initialized with:
|
|
@@ -83,6 +117,13 @@ const vectorDB = new MongoDBVector({
|
|
|
83
117
|
- Collection (index) management: create, list, describe, delete
|
|
84
118
|
- Atlas Search readiness checks for reliable testing
|
|
85
119
|
|
|
120
|
+
### Storage Features
|
|
121
|
+
|
|
122
|
+
- Thread and message storage with JSON support
|
|
123
|
+
- Efficient batch operations
|
|
124
|
+
- Rich metadata support
|
|
125
|
+
- Timestamp tracking
|
|
126
|
+
|
|
86
127
|
## Supported Filter Operators
|
|
87
128
|
|
|
88
129
|
- Comparison: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
|
|
@@ -121,6 +162,15 @@ The following distance metrics are supported:
|
|
|
121
162
|
- `deleteIndex(indexName)`: Delete a collection
|
|
122
163
|
- `disconnect()`: Close the MongoDB connection
|
|
123
164
|
|
|
165
|
+
## Storage Methods
|
|
166
|
+
|
|
167
|
+
- `saveThread(thread)`: Create or update a thread
|
|
168
|
+
- `getThread(threadId)`: Get a thread by ID
|
|
169
|
+
- `deleteThread(threadId)`: Delete a thread and its messages
|
|
170
|
+
- `saveMessages(messages)`: Save multiple messages in a transaction
|
|
171
|
+
- `getMessages(threadId)`: Get all messages for a thread
|
|
172
|
+
- `deleteMessages(messageIds)`: Delete specific messages
|
|
173
|
+
|
|
124
174
|
## Query Response Format
|
|
125
175
|
|
|
126
176
|
Each query result includes:
|
|
@@ -3,15 +3,23 @@ import type { CreateIndexParams } from '@mastra/core/vector';
|
|
|
3
3
|
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
4
|
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
5
|
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
6
|
+
import type { EvalRow } from '@mastra/core/storage';
|
|
6
7
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
|
+
import { MastraStorage } from '@mastra/core/storage';
|
|
7
9
|
import { MastraVector } from '@mastra/core/vector';
|
|
10
|
+
import type { MessageType } from '@mastra/core/memory';
|
|
8
11
|
import type { MongoClientOptions } from 'mongodb';
|
|
9
12
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
10
13
|
import type { QueryResult } from '@mastra/core/vector';
|
|
11
14
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
15
|
+
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
16
|
+
import type { StorageThreadType } from '@mastra/core/memory';
|
|
17
|
+
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
12
18
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
13
19
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
14
20
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
21
|
+
import type { WorkflowRun } from '@mastra/core/storage';
|
|
22
|
+
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
15
23
|
|
|
16
24
|
/**
|
|
17
25
|
* Vector store specific prompt that details supported operators and examples.
|
|
@@ -21,6 +29,13 @@ declare const MONGODB_PROMPT = "When querying MongoDB Vector, you can ONLY use t
|
|
|
21
29
|
export { MONGODB_PROMPT }
|
|
22
30
|
export { MONGODB_PROMPT as MONGODB_PROMPT_alias_1 }
|
|
23
31
|
|
|
32
|
+
declare interface MongoDBConfig {
|
|
33
|
+
url: string;
|
|
34
|
+
dbName: string;
|
|
35
|
+
}
|
|
36
|
+
export { MongoDBConfig }
|
|
37
|
+
export { MongoDBConfig as MongoDBConfig_alias_1 }
|
|
38
|
+
|
|
24
39
|
/**
|
|
25
40
|
* Translator for MongoDB filter queries.
|
|
26
41
|
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
|
@@ -48,6 +63,94 @@ declare interface MongoDBQueryVectorParams extends QueryVectorParams {
|
|
|
48
63
|
export { MongoDBQueryVectorParams }
|
|
49
64
|
export { MongoDBQueryVectorParams as MongoDBQueryVectorParams_alias_1 }
|
|
50
65
|
|
|
66
|
+
declare class MongoDBStore extends MastraStorage {
|
|
67
|
+
#private;
|
|
68
|
+
constructor(config: MongoDBConfig);
|
|
69
|
+
private getConnection;
|
|
70
|
+
private getCollection;
|
|
71
|
+
createTable(): Promise<void>;
|
|
72
|
+
clearTable({ tableName }: {
|
|
73
|
+
tableName: TABLE_NAMES;
|
|
74
|
+
}): Promise<void>;
|
|
75
|
+
insert({ tableName, record }: {
|
|
76
|
+
tableName: TABLE_NAMES;
|
|
77
|
+
record: Record<string, any>;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
batchInsert({ tableName, records }: {
|
|
80
|
+
tableName: TABLE_NAMES;
|
|
81
|
+
records: Record<string, any>[];
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
load<R>({ tableName, keys }: {
|
|
84
|
+
tableName: TABLE_NAMES;
|
|
85
|
+
keys: Record<string, string>;
|
|
86
|
+
}): Promise<R | null>;
|
|
87
|
+
getThreadById({ threadId }: {
|
|
88
|
+
threadId: string;
|
|
89
|
+
}): Promise<StorageThreadType | null>;
|
|
90
|
+
getThreadsByResourceId({ resourceId }: {
|
|
91
|
+
resourceId: string;
|
|
92
|
+
}): Promise<StorageThreadType[]>;
|
|
93
|
+
saveThread({ thread }: {
|
|
94
|
+
thread: StorageThreadType;
|
|
95
|
+
}): Promise<StorageThreadType>;
|
|
96
|
+
updateThread({ id, title, metadata, }: {
|
|
97
|
+
id: string;
|
|
98
|
+
title: string;
|
|
99
|
+
metadata: Record<string, unknown>;
|
|
100
|
+
}): Promise<StorageThreadType>;
|
|
101
|
+
deleteThread({ threadId }: {
|
|
102
|
+
threadId: string;
|
|
103
|
+
}): Promise<void>;
|
|
104
|
+
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
|
|
105
|
+
saveMessages({ messages }: {
|
|
106
|
+
messages: MessageType[];
|
|
107
|
+
}): Promise<MessageType[]>;
|
|
108
|
+
getTraces({ name, scope, page, perPage, attributes, filters, }?: {
|
|
109
|
+
name?: string;
|
|
110
|
+
scope?: string;
|
|
111
|
+
page: number;
|
|
112
|
+
perPage: number;
|
|
113
|
+
attributes?: Record<string, string>;
|
|
114
|
+
filters?: Record<string, any>;
|
|
115
|
+
}): Promise<any[]>;
|
|
116
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
|
|
117
|
+
workflowName?: string;
|
|
118
|
+
fromDate?: Date;
|
|
119
|
+
toDate?: Date;
|
|
120
|
+
limit?: number;
|
|
121
|
+
offset?: number;
|
|
122
|
+
}): Promise<{
|
|
123
|
+
runs: Array<{
|
|
124
|
+
workflowName: string;
|
|
125
|
+
runId: string;
|
|
126
|
+
snapshot: WorkflowRunState | string;
|
|
127
|
+
createdAt: Date;
|
|
128
|
+
updatedAt: Date;
|
|
129
|
+
}>;
|
|
130
|
+
total: number;
|
|
131
|
+
}>;
|
|
132
|
+
getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
|
133
|
+
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
134
|
+
workflowName: string;
|
|
135
|
+
runId: string;
|
|
136
|
+
snapshot: WorkflowRunState;
|
|
137
|
+
}): Promise<void>;
|
|
138
|
+
loadWorkflowSnapshot({ workflowName, runId, }: {
|
|
139
|
+
workflowName: string;
|
|
140
|
+
runId: string;
|
|
141
|
+
}): Promise<WorkflowRunState | null>;
|
|
142
|
+
getWorkflowRunById({ runId, workflowName, }: {
|
|
143
|
+
runId: string;
|
|
144
|
+
workflowName?: string;
|
|
145
|
+
}): Promise<WorkflowRun | null>;
|
|
146
|
+
private parseWorkflowRun;
|
|
147
|
+
private parseRow;
|
|
148
|
+
private transformEvalRow;
|
|
149
|
+
close(): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
export { MongoDBStore }
|
|
152
|
+
export { MongoDBStore as MongoDBStore_alias_1 }
|
|
153
|
+
|
|
51
154
|
declare interface MongoDBUpsertVectorParams extends UpsertVectorParams {
|
|
52
155
|
documents?: string[];
|
|
53
156
|
}
|
|
@@ -3,15 +3,23 @@ import type { CreateIndexParams } from '@mastra/core/vector';
|
|
|
3
3
|
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
4
|
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
5
|
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
6
|
+
import type { EvalRow } from '@mastra/core/storage';
|
|
6
7
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
|
+
import { MastraStorage } from '@mastra/core/storage';
|
|
7
9
|
import { MastraVector } from '@mastra/core/vector';
|
|
10
|
+
import type { MessageType } from '@mastra/core/memory';
|
|
8
11
|
import type { MongoClientOptions } from 'mongodb';
|
|
9
12
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
10
13
|
import type { QueryResult } from '@mastra/core/vector';
|
|
11
14
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
15
|
+
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
16
|
+
import type { StorageThreadType } from '@mastra/core/memory';
|
|
17
|
+
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
12
18
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
13
19
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
14
20
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
21
|
+
import type { WorkflowRun } from '@mastra/core/storage';
|
|
22
|
+
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
15
23
|
|
|
16
24
|
/**
|
|
17
25
|
* Vector store specific prompt that details supported operators and examples.
|
|
@@ -21,6 +29,13 @@ declare const MONGODB_PROMPT = "When querying MongoDB Vector, you can ONLY use t
|
|
|
21
29
|
export { MONGODB_PROMPT }
|
|
22
30
|
export { MONGODB_PROMPT as MONGODB_PROMPT_alias_1 }
|
|
23
31
|
|
|
32
|
+
declare interface MongoDBConfig {
|
|
33
|
+
url: string;
|
|
34
|
+
dbName: string;
|
|
35
|
+
}
|
|
36
|
+
export { MongoDBConfig }
|
|
37
|
+
export { MongoDBConfig as MongoDBConfig_alias_1 }
|
|
38
|
+
|
|
24
39
|
/**
|
|
25
40
|
* Translator for MongoDB filter queries.
|
|
26
41
|
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
|
@@ -48,6 +63,94 @@ declare interface MongoDBQueryVectorParams extends QueryVectorParams {
|
|
|
48
63
|
export { MongoDBQueryVectorParams }
|
|
49
64
|
export { MongoDBQueryVectorParams as MongoDBQueryVectorParams_alias_1 }
|
|
50
65
|
|
|
66
|
+
declare class MongoDBStore extends MastraStorage {
|
|
67
|
+
#private;
|
|
68
|
+
constructor(config: MongoDBConfig);
|
|
69
|
+
private getConnection;
|
|
70
|
+
private getCollection;
|
|
71
|
+
createTable(): Promise<void>;
|
|
72
|
+
clearTable({ tableName }: {
|
|
73
|
+
tableName: TABLE_NAMES;
|
|
74
|
+
}): Promise<void>;
|
|
75
|
+
insert({ tableName, record }: {
|
|
76
|
+
tableName: TABLE_NAMES;
|
|
77
|
+
record: Record<string, any>;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
batchInsert({ tableName, records }: {
|
|
80
|
+
tableName: TABLE_NAMES;
|
|
81
|
+
records: Record<string, any>[];
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
load<R>({ tableName, keys }: {
|
|
84
|
+
tableName: TABLE_NAMES;
|
|
85
|
+
keys: Record<string, string>;
|
|
86
|
+
}): Promise<R | null>;
|
|
87
|
+
getThreadById({ threadId }: {
|
|
88
|
+
threadId: string;
|
|
89
|
+
}): Promise<StorageThreadType | null>;
|
|
90
|
+
getThreadsByResourceId({ resourceId }: {
|
|
91
|
+
resourceId: string;
|
|
92
|
+
}): Promise<StorageThreadType[]>;
|
|
93
|
+
saveThread({ thread }: {
|
|
94
|
+
thread: StorageThreadType;
|
|
95
|
+
}): Promise<StorageThreadType>;
|
|
96
|
+
updateThread({ id, title, metadata, }: {
|
|
97
|
+
id: string;
|
|
98
|
+
title: string;
|
|
99
|
+
metadata: Record<string, unknown>;
|
|
100
|
+
}): Promise<StorageThreadType>;
|
|
101
|
+
deleteThread({ threadId }: {
|
|
102
|
+
threadId: string;
|
|
103
|
+
}): Promise<void>;
|
|
104
|
+
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
|
|
105
|
+
saveMessages({ messages }: {
|
|
106
|
+
messages: MessageType[];
|
|
107
|
+
}): Promise<MessageType[]>;
|
|
108
|
+
getTraces({ name, scope, page, perPage, attributes, filters, }?: {
|
|
109
|
+
name?: string;
|
|
110
|
+
scope?: string;
|
|
111
|
+
page: number;
|
|
112
|
+
perPage: number;
|
|
113
|
+
attributes?: Record<string, string>;
|
|
114
|
+
filters?: Record<string, any>;
|
|
115
|
+
}): Promise<any[]>;
|
|
116
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
|
|
117
|
+
workflowName?: string;
|
|
118
|
+
fromDate?: Date;
|
|
119
|
+
toDate?: Date;
|
|
120
|
+
limit?: number;
|
|
121
|
+
offset?: number;
|
|
122
|
+
}): Promise<{
|
|
123
|
+
runs: Array<{
|
|
124
|
+
workflowName: string;
|
|
125
|
+
runId: string;
|
|
126
|
+
snapshot: WorkflowRunState | string;
|
|
127
|
+
createdAt: Date;
|
|
128
|
+
updatedAt: Date;
|
|
129
|
+
}>;
|
|
130
|
+
total: number;
|
|
131
|
+
}>;
|
|
132
|
+
getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
|
133
|
+
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
134
|
+
workflowName: string;
|
|
135
|
+
runId: string;
|
|
136
|
+
snapshot: WorkflowRunState;
|
|
137
|
+
}): Promise<void>;
|
|
138
|
+
loadWorkflowSnapshot({ workflowName, runId, }: {
|
|
139
|
+
workflowName: string;
|
|
140
|
+
runId: string;
|
|
141
|
+
}): Promise<WorkflowRunState | null>;
|
|
142
|
+
getWorkflowRunById({ runId, workflowName, }: {
|
|
143
|
+
runId: string;
|
|
144
|
+
workflowName?: string;
|
|
145
|
+
}): Promise<WorkflowRun | null>;
|
|
146
|
+
private parseWorkflowRun;
|
|
147
|
+
private parseRow;
|
|
148
|
+
private transformEvalRow;
|
|
149
|
+
close(): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
export { MongoDBStore }
|
|
152
|
+
export { MongoDBStore as MongoDBStore_alias_1 }
|
|
153
|
+
|
|
51
154
|
declare interface MongoDBUpsertVectorParams extends UpsertVectorParams {
|
|
52
155
|
documents?: string[];
|
|
53
156
|
}
|