@mastra/mongodb 1.0.0 → 1.1.0-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 +77 -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/memory/01-working-memory.md +22 -1
- package/dist/docs/rag/01-vector-databases.md +1 -1
- package/dist/docs/rag/02-retrieval.md +4 -4
- package/dist/docs/storage/01-reference.md +2 -2
- package/dist/docs/vectors/01-reference.md +4 -4
- package/dist/index.cjs +222 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +223 -8
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +11 -1
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +2 -5
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,82 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 1.1.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added dynamic agent management with CRUD operations and version tracking ([#12038](https://github.com/mastra-ai/mastra/pull/12038))
|
|
8
|
+
|
|
9
|
+
**New Features:**
|
|
10
|
+
- Create, edit, and delete agents directly from the Mastra Studio UI
|
|
11
|
+
- Full version history for agents with compare and restore capabilities
|
|
12
|
+
- Visual diff viewer to compare agent configurations across versions
|
|
13
|
+
- Agent creation modal with comprehensive configuration options (model selection, instructions, tools, workflows, sub-agents, memory)
|
|
14
|
+
- AI-powered instruction enhancement
|
|
15
|
+
|
|
16
|
+
**Storage:**
|
|
17
|
+
- New storage interfaces for stored agents and agent versions
|
|
18
|
+
- PostgreSQL, LibSQL, and MongoDB implementations included
|
|
19
|
+
- In-memory storage for development and testing
|
|
20
|
+
|
|
21
|
+
**API:**
|
|
22
|
+
- RESTful endpoints for agent CRUD operations
|
|
23
|
+
- Version management endpoints (create, list, activate, restore, delete, compare)
|
|
24
|
+
- Automatic versioning on agent updates when enabled
|
|
25
|
+
|
|
26
|
+
**Client SDK:**
|
|
27
|
+
- JavaScript client with full support for stored agents and versions
|
|
28
|
+
- Type-safe methods for all CRUD and version operations
|
|
29
|
+
|
|
30
|
+
**Usage Example:**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
// Server-side: Configure storage
|
|
34
|
+
import { Mastra } from '@mastra/core';
|
|
35
|
+
import { PgAgentsStorage } from '@mastra/pg';
|
|
36
|
+
|
|
37
|
+
const mastra = new Mastra({
|
|
38
|
+
agents: { agentOne },
|
|
39
|
+
storage: {
|
|
40
|
+
agents: new PgAgentsStorage({
|
|
41
|
+
connectionString: process.env.DATABASE_URL,
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Client-side: Use the SDK
|
|
47
|
+
import { MastraClient } from '@mastra/client-js';
|
|
48
|
+
|
|
49
|
+
const client = new MastraClient({ baseUrl: 'http://localhost:3000' });
|
|
50
|
+
|
|
51
|
+
// Create a stored agent
|
|
52
|
+
const agent = await client.createStoredAgent({
|
|
53
|
+
name: 'Customer Support Agent',
|
|
54
|
+
description: 'Handles customer inquiries',
|
|
55
|
+
model: { provider: 'ANTHROPIC', name: 'claude-sonnet-4-5' },
|
|
56
|
+
instructions: 'You are a helpful customer support agent...',
|
|
57
|
+
tools: ['search', 'email'],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Create a version snapshot
|
|
61
|
+
await client.storedAgent(agent.id).createVersion({
|
|
62
|
+
name: 'v1.0 - Initial release',
|
|
63
|
+
changeMessage: 'First production version',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Compare versions
|
|
67
|
+
const diff = await client.storedAgent(agent.id).compareVersions('version-1', 'version-2');
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Why:**
|
|
71
|
+
This feature enables teams to manage agents dynamically without code changes, making it easier to iterate on agent configurations and maintain a complete audit trail of changes.
|
|
72
|
+
|
|
73
|
+
- Added `status` field to `listTraces` response. The status field indicates the trace state: `success` (completed without error), `error` (has error), or `running` (still in progress). This makes it easier to filter and display traces by their current state without having to derive it from the `error` and `endedAt` fields. ([#12213](https://github.com/mastra-ai/mastra/pull/12213))
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- Updated dependencies [[`90fc0e5`](https://github.com/mastra-ai/mastra/commit/90fc0e5717cb280c2d4acf4f0410b510bb4c0a72), [`1cf5d2e`](https://github.com/mastra-ai/mastra/commit/1cf5d2ea1b085be23e34fb506c80c80a4e6d9c2b), [`833ae96`](https://github.com/mastra-ai/mastra/commit/833ae96c3e34370e58a1e979571c41f39a720592), [`943772b`](https://github.com/mastra-ai/mastra/commit/943772b4378f625f0f4e19ea2b7c392bd8e71786), [`b5c711b`](https://github.com/mastra-ai/mastra/commit/b5c711b281dd1fb81a399a766bc9f86c55efc13e), [`3efbe5a`](https://github.com/mastra-ai/mastra/commit/3efbe5ae20864c4f3143457f4f3ee7dc2fa5ca76), [`1e49e7a`](https://github.com/mastra-ai/mastra/commit/1e49e7ab5f173582154cb26b29d424de67d09aef), [`751eaab`](https://github.com/mastra-ai/mastra/commit/751eaab4e0d3820a94e4c3d39a2ff2663ded3d91), [`69d8156`](https://github.com/mastra-ai/mastra/commit/69d81568bcf062557c24471ce26812446bec465d), [`60d9d89`](https://github.com/mastra-ai/mastra/commit/60d9d899e44b35bc43f1bcd967a74e0ce010b1af), [`5c544c8`](https://github.com/mastra-ai/mastra/commit/5c544c8d12b08ab40d64d8f37b3c4215bee95b87), [`771ad96`](https://github.com/mastra-ai/mastra/commit/771ad962441996b5c43549391a3e6a02c6ddedc2), [`2b0936b`](https://github.com/mastra-ai/mastra/commit/2b0936b0c9a43eeed9bef63e614d7e02ee803f7e), [`3b04f30`](https://github.com/mastra-ai/mastra/commit/3b04f3010604f3cdfc8a0674731700ad66471cee), [`97e26de`](https://github.com/mastra-ai/mastra/commit/97e26deaebd9836647a67b96423281d66421ca07), [`10523f4`](https://github.com/mastra-ai/mastra/commit/10523f4882d9b874b40ce6e3715f66dbcd4947d2), [`cb72d20`](https://github.com/mastra-ai/mastra/commit/cb72d2069d7339bda8a0e76d4f35615debb07b84), [`42856b1`](https://github.com/mastra-ai/mastra/commit/42856b1c8aeea6371c9ee77ae2f5f5fe34400933), [`66f33ff`](https://github.com/mastra-ai/mastra/commit/66f33ff68620018513e499c394411d1d39b3aa5c), [`ab3c190`](https://github.com/mastra-ai/mastra/commit/ab3c1901980a99910ca9b96a7090c22e24060113), [`d4f06c8`](https://github.com/mastra-ai/mastra/commit/d4f06c85ffa5bb0da38fb82ebf3b040cc6b4ec4e), [`0350626`](https://github.com/mastra-ai/mastra/commit/03506267ec41b67add80d994c0c0fcce93bbc75f), [`bc9fa00`](https://github.com/mastra-ai/mastra/commit/bc9fa00859c5c4a796d53a0a5cae46ab4a3072e4), [`f46a478`](https://github.com/mastra-ai/mastra/commit/f46a4782f595949c696569e891f81c8d26338508), [`90fc0e5`](https://github.com/mastra-ai/mastra/commit/90fc0e5717cb280c2d4acf4f0410b510bb4c0a72), [`f05a3a5`](https://github.com/mastra-ai/mastra/commit/f05a3a5cf2b9a9c2d40c09cb8c762a4b6cd5d565), [`a291da9`](https://github.com/mastra-ai/mastra/commit/a291da9363efd92dafd8775dccb4f2d0511ece7a), [`c5d71da`](https://github.com/mastra-ai/mastra/commit/c5d71da1c680ce5640b1a7f8ca0e024a4ab1cfed), [`07042f9`](https://github.com/mastra-ai/mastra/commit/07042f9f89080f38b8f72713ba1c972d5b1905b8), [`0423442`](https://github.com/mastra-ai/mastra/commit/0423442b7be2dfacba95890bea8f4a810db4d603)]:
|
|
78
|
+
- @mastra/core@1.1.0-alpha.0
|
|
79
|
+
|
|
3
80
|
## 1.0.0
|
|
4
81
|
|
|
5
82
|
### Major Changes
|
package/dist/docs/README.md
CHANGED
package/dist/docs/SKILL.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Working Memory
|
|
4
4
|
|
|
5
|
-
While [message history](https://mastra.ai/docs/
|
|
5
|
+
While [message history](https://mastra.ai/docs/memory/message-history) and [semantic recall](./semantic-recall) help agents remember conversations, working memory allows them to maintain persistent information about users across interactions.
|
|
6
6
|
|
|
7
7
|
Think of it as the agent's active thoughts or scratchpad – the key information they keep available about the user or task. It's similar to how a person would naturally remember someone's name, preferences, or important details during a conversation.
|
|
8
8
|
|
|
@@ -383,6 +383,27 @@ await memory.updateWorkingMemory({
|
|
|
383
383
|
});
|
|
384
384
|
```
|
|
385
385
|
|
|
386
|
+
## Read-Only Working Memory
|
|
387
|
+
|
|
388
|
+
In some scenarios, you may want an agent to have access to working memory data without the ability to modify it. This is useful for:
|
|
389
|
+
|
|
390
|
+
- **Routing agents** that need context but shouldn't update user profiles
|
|
391
|
+
- **Sub agents** in a multi-agent system that should reference but not own the memory
|
|
392
|
+
|
|
393
|
+
To enable read-only mode, set `readOnly: true` in the memory options:
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
const response = await agent.generate("What do you know about me?", {
|
|
397
|
+
memory: {
|
|
398
|
+
thread: "conversation-123",
|
|
399
|
+
resource: "user-alice-456",
|
|
400
|
+
options: {
|
|
401
|
+
readOnly: true, // Working memory is provided but cannot be updated
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
```
|
|
406
|
+
|
|
386
407
|
## Examples
|
|
387
408
|
|
|
388
409
|
- [Working memory with template](https://github.com/mastra-ai/mastra/tree/main/examples/memory-with-template)
|
|
@@ -376,7 +376,7 @@ The dimension size must match the output dimension of your chosen embedding mode
|
|
|
376
376
|
|
|
377
377
|
- OpenAI text-embedding-3-small: 1536 dimensions (or custom, e.g., 256)
|
|
378
378
|
- Cohere embed-multilingual-v3: 1024 dimensions
|
|
379
|
-
- Google
|
|
379
|
+
- Google gemini-embedding-001: 768 dimensions (or custom)
|
|
380
380
|
|
|
381
381
|
> **Note:**
|
|
382
382
|
Index dimensions cannot be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
|
|
@@ -73,7 +73,7 @@ Filter results based on metadata fields to narrow down the search space. This ap
|
|
|
73
73
|
|
|
74
74
|
This is useful when you have documents from different sources, time periods, or with specific attributes. Mastra provides a unified MongoDB-style query syntax that works across all supported vector stores.
|
|
75
75
|
|
|
76
|
-
For detailed information about available operators and syntax, see the [Metadata Filters Reference](https://mastra.ai/reference/
|
|
76
|
+
For detailed information about available operators and syntax, see the [Metadata Filters Reference](https://mastra.ai/reference/rag/metadata-filters).
|
|
77
77
|
|
|
78
78
|
Basic filtering examples:
|
|
79
79
|
|
|
@@ -264,7 +264,7 @@ await pineconeQueryTool.execute(
|
|
|
264
264
|
);
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
-
For detailed configuration options and advanced usage, see the [Vector Query Tool Reference](https://mastra.ai/reference/
|
|
267
|
+
For detailed configuration options and advanced usage, see the [Vector Query Tool Reference](https://mastra.ai/reference/tools/vector-query-tool).
|
|
268
268
|
|
|
269
269
|
### Vector Store Prompts
|
|
270
270
|
|
|
@@ -543,6 +543,6 @@ const relevanceProvider = new ZeroEntropyRelevanceScorer("zerank-1");
|
|
|
543
543
|
|
|
544
544
|
The re-ranked results combine vector similarity with semantic understanding to improve retrieval quality.
|
|
545
545
|
|
|
546
|
-
For more details about re-ranking, see the [rerank()](https://mastra.ai/reference/
|
|
546
|
+
For more details about re-ranking, see the [rerank()](https://mastra.ai/reference/rag/rerankWithScorer) method.
|
|
547
547
|
|
|
548
|
-
For graph-based retrieval that follows connections between chunks, see the [GraphRAG](https://mastra.ai/docs/
|
|
548
|
+
For graph-based retrieval that follows connections between chunks, see the [GraphRAG](https://mastra.ai/docs/rag/graph-rag) documentation.
|
|
@@ -13,8 +13,8 @@ The `MongoDBVector` class provides vector search using [MongoDB Atlas Vector Sea
|
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
16
|
-
```bash
|
|
17
|
-
npm install @mastra/mongodb@
|
|
16
|
+
```bash npm2yarn
|
|
17
|
+
npm install @mastra/mongodb@latest
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Usage Example
|
|
@@ -154,8 +154,8 @@ Embeddings are numeric vectors used by memory's `semanticRecall` to retrieve rel
|
|
|
154
154
|
This setup uses FastEmbed, a local embedding model, to generate vector embeddings.
|
|
155
155
|
To use this, install `@mastra/fastembed`:
|
|
156
156
|
|
|
157
|
-
```bash
|
|
158
|
-
npm install @mastra/fastembed@
|
|
157
|
+
```bash npm2yarn
|
|
158
|
+
npm install @mastra/fastembed@latest
|
|
159
159
|
```
|
|
160
160
|
|
|
161
161
|
Add the following to your agent:
|
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,7 @@ var evals = require('@mastra/core/evals');
|
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
15
|
var package_default = {
|
|
16
|
-
version: "1.0.0"};
|
|
16
|
+
version: "1.1.0-alpha.0"};
|
|
17
17
|
var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
18
18
|
getSupportedOperators() {
|
|
19
19
|
return {
|
|
@@ -899,7 +899,7 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
899
899
|
#skipDefaultIndexes;
|
|
900
900
|
#indexes;
|
|
901
901
|
/** Collections managed by this domain */
|
|
902
|
-
static MANAGED_COLLECTIONS = [storage.TABLE_AGENTS];
|
|
902
|
+
static MANAGED_COLLECTIONS = [storage.TABLE_AGENTS, storage.TABLE_AGENT_VERSIONS];
|
|
903
903
|
constructor(config) {
|
|
904
904
|
super();
|
|
905
905
|
this.#connector = resolveMongoDBConfig(config);
|
|
@@ -919,7 +919,10 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
919
919
|
return [
|
|
920
920
|
{ collection: storage.TABLE_AGENTS, keys: { id: 1 }, options: { unique: true } },
|
|
921
921
|
{ collection: storage.TABLE_AGENTS, keys: { createdAt: -1 } },
|
|
922
|
-
{ collection: storage.TABLE_AGENTS, keys: { updatedAt: -1 } }
|
|
922
|
+
{ collection: storage.TABLE_AGENTS, keys: { updatedAt: -1 } },
|
|
923
|
+
{ collection: storage.TABLE_AGENT_VERSIONS, keys: { id: 1 }, options: { unique: true } },
|
|
924
|
+
{ collection: storage.TABLE_AGENT_VERSIONS, keys: { agentId: 1, versionNumber: -1 }, options: { unique: true } },
|
|
925
|
+
{ collection: storage.TABLE_AGENT_VERSIONS, keys: { agentId: 1, createdAt: -1 } }
|
|
923
926
|
];
|
|
924
927
|
}
|
|
925
928
|
async createDefaultIndexes() {
|
|
@@ -956,8 +959,10 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
956
959
|
await this.createCustomIndexes();
|
|
957
960
|
}
|
|
958
961
|
async dangerouslyClearAll() {
|
|
959
|
-
const
|
|
960
|
-
await
|
|
962
|
+
const versionsCollection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
963
|
+
await versionsCollection.deleteMany({});
|
|
964
|
+
const agentsCollection = await this.getCollection(storage.TABLE_AGENTS);
|
|
965
|
+
await agentsCollection.deleteMany({});
|
|
961
966
|
}
|
|
962
967
|
async getAgentById({ id }) {
|
|
963
968
|
try {
|
|
@@ -1043,6 +1048,9 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1043
1048
|
if (updates.outputProcessors !== void 0) updateDoc.outputProcessors = updates.outputProcessors;
|
|
1044
1049
|
if (updates.memory !== void 0) updateDoc.memory = updates.memory;
|
|
1045
1050
|
if (updates.scorers !== void 0) updateDoc.scorers = updates.scorers;
|
|
1051
|
+
if (updates.integrationTools !== void 0) updateDoc.integrationTools = updates.integrationTools;
|
|
1052
|
+
if (updates.ownerId !== void 0) updateDoc.ownerId = updates.ownerId;
|
|
1053
|
+
if (updates.activeVersionId !== void 0) updateDoc.activeVersionId = updates.activeVersionId;
|
|
1046
1054
|
if (updates.metadata !== void 0) {
|
|
1047
1055
|
const existingMetadata = existingAgent.metadata || {};
|
|
1048
1056
|
updateDoc.metadata = { ...existingMetadata, ...updates.metadata };
|
|
@@ -1076,6 +1084,7 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1076
1084
|
}
|
|
1077
1085
|
async deleteAgent({ id }) {
|
|
1078
1086
|
try {
|
|
1087
|
+
await this.deleteVersionsByAgentId(id);
|
|
1079
1088
|
const collection = await this.getCollection(storage.TABLE_AGENTS);
|
|
1080
1089
|
await collection.deleteOne({ id });
|
|
1081
1090
|
} catch (error$1) {
|
|
@@ -1159,6 +1168,212 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1159
1168
|
...agent
|
|
1160
1169
|
};
|
|
1161
1170
|
}
|
|
1171
|
+
// ==========================================================================
|
|
1172
|
+
// Agent Version Methods
|
|
1173
|
+
// ==========================================================================
|
|
1174
|
+
async createVersion(input) {
|
|
1175
|
+
try {
|
|
1176
|
+
const collection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
1177
|
+
const now = /* @__PURE__ */ new Date();
|
|
1178
|
+
const versionDoc = {
|
|
1179
|
+
id: input.id,
|
|
1180
|
+
agentId: input.agentId,
|
|
1181
|
+
versionNumber: input.versionNumber,
|
|
1182
|
+
name: input.name ?? void 0,
|
|
1183
|
+
snapshot: input.snapshot,
|
|
1184
|
+
changedFields: input.changedFields ?? void 0,
|
|
1185
|
+
changeMessage: input.changeMessage ?? void 0,
|
|
1186
|
+
createdAt: now
|
|
1187
|
+
};
|
|
1188
|
+
await collection.insertOne(versionDoc);
|
|
1189
|
+
return {
|
|
1190
|
+
...input,
|
|
1191
|
+
createdAt: now
|
|
1192
|
+
};
|
|
1193
|
+
} catch (error$1) {
|
|
1194
|
+
throw new error.MastraError(
|
|
1195
|
+
{
|
|
1196
|
+
id: storage.createStorageErrorId("MONGODB", "CREATE_VERSION", "FAILED"),
|
|
1197
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1198
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1199
|
+
details: { versionId: input.id, agentId: input.agentId }
|
|
1200
|
+
},
|
|
1201
|
+
error$1
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
async getVersion(id) {
|
|
1206
|
+
try {
|
|
1207
|
+
const collection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
1208
|
+
const result = await collection.findOne({ id });
|
|
1209
|
+
if (!result) {
|
|
1210
|
+
return null;
|
|
1211
|
+
}
|
|
1212
|
+
return this.transformVersion(result);
|
|
1213
|
+
} catch (error$1) {
|
|
1214
|
+
throw new error.MastraError(
|
|
1215
|
+
{
|
|
1216
|
+
id: storage.createStorageErrorId("MONGODB", "GET_VERSION", "FAILED"),
|
|
1217
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1218
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1219
|
+
details: { versionId: id }
|
|
1220
|
+
},
|
|
1221
|
+
error$1
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
async getVersionByNumber(agentId, versionNumber) {
|
|
1226
|
+
try {
|
|
1227
|
+
const collection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
1228
|
+
const result = await collection.findOne({ agentId, versionNumber });
|
|
1229
|
+
if (!result) {
|
|
1230
|
+
return null;
|
|
1231
|
+
}
|
|
1232
|
+
return this.transformVersion(result);
|
|
1233
|
+
} catch (error$1) {
|
|
1234
|
+
throw new error.MastraError(
|
|
1235
|
+
{
|
|
1236
|
+
id: storage.createStorageErrorId("MONGODB", "GET_VERSION_BY_NUMBER", "FAILED"),
|
|
1237
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1238
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1239
|
+
details: { agentId, versionNumber }
|
|
1240
|
+
},
|
|
1241
|
+
error$1
|
|
1242
|
+
);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
async getLatestVersion(agentId) {
|
|
1246
|
+
try {
|
|
1247
|
+
const collection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
1248
|
+
const result = await collection.find({ agentId }).sort({ versionNumber: -1 }).limit(1).toArray();
|
|
1249
|
+
if (!result || result.length === 0) {
|
|
1250
|
+
return null;
|
|
1251
|
+
}
|
|
1252
|
+
return this.transformVersion(result[0]);
|
|
1253
|
+
} catch (error$1) {
|
|
1254
|
+
throw new error.MastraError(
|
|
1255
|
+
{
|
|
1256
|
+
id: storage.createStorageErrorId("MONGODB", "GET_LATEST_VERSION", "FAILED"),
|
|
1257
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1258
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1259
|
+
details: { agentId }
|
|
1260
|
+
},
|
|
1261
|
+
error$1
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
async listVersions(input) {
|
|
1266
|
+
const { agentId, page = 0, perPage: perPageInput, orderBy } = input;
|
|
1267
|
+
if (page < 0) {
|
|
1268
|
+
throw new error.MastraError(
|
|
1269
|
+
{
|
|
1270
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_VERSIONS", "INVALID_PAGE"),
|
|
1271
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1272
|
+
category: error.ErrorCategory.USER,
|
|
1273
|
+
details: { page }
|
|
1274
|
+
},
|
|
1275
|
+
new Error("page must be >= 0")
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1278
|
+
const perPage = storage.normalizePerPage(perPageInput, 20);
|
|
1279
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
1280
|
+
try {
|
|
1281
|
+
const { field, direction } = this.parseVersionOrderBy(orderBy);
|
|
1282
|
+
const collection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
1283
|
+
const total = await collection.countDocuments({ agentId });
|
|
1284
|
+
if (total === 0 || perPage === 0) {
|
|
1285
|
+
return {
|
|
1286
|
+
versions: [],
|
|
1287
|
+
total,
|
|
1288
|
+
page,
|
|
1289
|
+
perPage: perPageForResponse,
|
|
1290
|
+
hasMore: false
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
const sortOrder = direction === "ASC" ? 1 : -1;
|
|
1294
|
+
let cursor = collection.find({ agentId }).sort({ [field]: sortOrder }).skip(offset);
|
|
1295
|
+
if (perPageInput !== false) {
|
|
1296
|
+
cursor = cursor.limit(perPage);
|
|
1297
|
+
}
|
|
1298
|
+
const results = await cursor.toArray();
|
|
1299
|
+
const versions = results.map((doc) => this.transformVersion(doc));
|
|
1300
|
+
return {
|
|
1301
|
+
versions,
|
|
1302
|
+
total,
|
|
1303
|
+
page,
|
|
1304
|
+
perPage: perPageForResponse,
|
|
1305
|
+
hasMore: perPageInput !== false && offset + perPage < total
|
|
1306
|
+
};
|
|
1307
|
+
} catch (error$1) {
|
|
1308
|
+
throw new error.MastraError(
|
|
1309
|
+
{
|
|
1310
|
+
id: storage.createStorageErrorId("MONGODB", "LIST_VERSIONS", "FAILED"),
|
|
1311
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1312
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1313
|
+
details: { agentId }
|
|
1314
|
+
},
|
|
1315
|
+
error$1
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
async deleteVersion(id) {
|
|
1320
|
+
try {
|
|
1321
|
+
const collection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
1322
|
+
await collection.deleteOne({ id });
|
|
1323
|
+
} catch (error$1) {
|
|
1324
|
+
throw new error.MastraError(
|
|
1325
|
+
{
|
|
1326
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_VERSION", "FAILED"),
|
|
1327
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1328
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1329
|
+
details: { versionId: id }
|
|
1330
|
+
},
|
|
1331
|
+
error$1
|
|
1332
|
+
);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
async deleteVersionsByAgentId(agentId) {
|
|
1336
|
+
try {
|
|
1337
|
+
const collection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
1338
|
+
await collection.deleteMany({ agentId });
|
|
1339
|
+
} catch (error$1) {
|
|
1340
|
+
throw new error.MastraError(
|
|
1341
|
+
{
|
|
1342
|
+
id: storage.createStorageErrorId("MONGODB", "DELETE_VERSIONS_BY_AGENT_ID", "FAILED"),
|
|
1343
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1344
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1345
|
+
details: { agentId }
|
|
1346
|
+
},
|
|
1347
|
+
error$1
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
async countVersions(agentId) {
|
|
1352
|
+
try {
|
|
1353
|
+
const collection = await this.getCollection(storage.TABLE_AGENT_VERSIONS);
|
|
1354
|
+
return await collection.countDocuments({ agentId });
|
|
1355
|
+
} catch (error$1) {
|
|
1356
|
+
throw new error.MastraError(
|
|
1357
|
+
{
|
|
1358
|
+
id: storage.createStorageErrorId("MONGODB", "COUNT_VERSIONS", "FAILED"),
|
|
1359
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1360
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1361
|
+
details: { agentId }
|
|
1362
|
+
},
|
|
1363
|
+
error$1
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
// ==========================================================================
|
|
1368
|
+
// Private Helper Methods
|
|
1369
|
+
// ==========================================================================
|
|
1370
|
+
transformVersion(doc) {
|
|
1371
|
+
const { _id, ...version } = doc;
|
|
1372
|
+
return {
|
|
1373
|
+
...version,
|
|
1374
|
+
createdAt: version.createdAt instanceof Date ? version.createdAt : new Date(version.createdAt)
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1162
1377
|
};
|
|
1163
1378
|
function formatDateForMongoDB(date) {
|
|
1164
1379
|
return typeof date === "string" ? new Date(date) : date;
|
|
@@ -2492,7 +2707,7 @@ Note: This migration may take some time for large collections.
|
|
|
2492
2707
|
perPage,
|
|
2493
2708
|
hasMore: (page + 1) * perPage < count2
|
|
2494
2709
|
},
|
|
2495
|
-
spans: spans2.map((span) => this.transformSpanFromMongo(span))
|
|
2710
|
+
spans: storage.toTraceSpans(spans2.map((span) => this.transformSpanFromMongo(span)))
|
|
2496
2711
|
};
|
|
2497
2712
|
}
|
|
2498
2713
|
const count = await collection.countDocuments(mongoFilter);
|
|
@@ -2535,7 +2750,7 @@ Note: This migration may take some time for large collections.
|
|
|
2535
2750
|
perPage,
|
|
2536
2751
|
hasMore: (page + 1) * perPage < count
|
|
2537
2752
|
},
|
|
2538
|
-
spans: spans.map((span) => this.transformSpanFromMongo(span))
|
|
2753
|
+
spans: storage.toTraceSpans(spans.map((span) => this.transformSpanFromMongo(span)))
|
|
2539
2754
|
};
|
|
2540
2755
|
} catch (error$1) {
|
|
2541
2756
|
throw new error.MastraError(
|