@mastra/mongodb 1.16.0-alpha.1 → 1.16.0-alpha.3
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 +70 -0
- package/dist/docs/SKILL.md +6 -3
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/{docs-rag-retrieval.md → guides-rag-retrieval.md} +1 -1
- package/dist/docs/references/reference-storage-composite.md +2 -0
- package/dist/docs/references/reference-vectors-mongodb.md +13 -13
- package/dist/index.cjs +150 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +151 -5
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/workflow-definitions/index.d.ts +20 -0
- package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
- /package/dist/docs/references/{docs-rag-vector-databases.md → guides-rag-vector-databases.md} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,75 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 1.16.0-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Dataset item scorer selections now persist across MongoDB writes and reads. Setting `scorerIds` to `null` clears an item override, while `[]` remains an explicit override with no scorers. ([#20191](https://github.com/mastra-ai/mastra/pull/20191))
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
await dataset.addItem({
|
|
11
|
+
input: 'Evaluate this response',
|
|
12
|
+
scorerIds: [],
|
|
13
|
+
});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- Fixed nine storage adapters declaring a `@mastra/core` peer range that permitted core versions too old to load them. Each adapter imports `storageMessageMatchesMetadataFilter` from `@mastra/core/storage`, which core only exports from 1.53.0, but every one of them still advertised a floor below that — as low as `>=1.0.0-0`. Package managers accepted the incompatible pair without a warning and the install then failed at import time: ([#20591](https://github.com/mastra-ai/mastra/pull/20591))
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
SyntaxError: The requested module '@mastra/core/storage' does not provide an export named 'storageMessageMatchesMetadataFilter'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
All nine now declare `>=1.53.0-0 <2.0.0-0`, so npm and pnpm surface a peer conflict at install time instead of letting the project break on first import.
|
|
23
|
+
|
|
24
|
+
Fixes [#20586](https://github.com/mastra-ai/mastra/issues/20586).
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [[`82201f7`](https://github.com/mastra-ai/mastra/commit/82201f75fae8e050a8de2df08b74875ee74c6b83), [`fb18da5`](https://github.com/mastra-ai/mastra/commit/fb18da56fc35689ae370621a8f10b5b0d8606e20), [`fb18da5`](https://github.com/mastra-ai/mastra/commit/fb18da56fc35689ae370621a8f10b5b0d8606e20), [`0a6598b`](https://github.com/mastra-ai/mastra/commit/0a6598bde80bde008986ad6616bed9632b9294cb), [`9e1dad8`](https://github.com/mastra-ai/mastra/commit/9e1dad8f7b1cab2bb7ade90e5b7561f24577b88a), [`2f43145`](https://github.com/mastra-ai/mastra/commit/2f4314504c03cbba280414ac81ba3197448ee6b0), [`34d34d8`](https://github.com/mastra-ai/mastra/commit/34d34d8c811df512fef4dd5459f79b7821be1866)]:
|
|
27
|
+
- @mastra/core@1.56.0-alpha.6
|
|
28
|
+
|
|
29
|
+
## 1.16.0-alpha.2
|
|
30
|
+
|
|
31
|
+
### Minor Changes
|
|
32
|
+
|
|
33
|
+
- Stored workflow definitions now persist across restarts on every major database backend. ([#20471](https://github.com/mastra-ai/mastra/pull/20471))
|
|
34
|
+
|
|
35
|
+
Implement the `workflowDefinitions` storage domain for libsql, pg, mysql, mssql, mongodb, and spanner. Previously the stored-workflow persistence path (`POST /stored/workflows`, `Mastra.addStoredWorkflow`) only worked against `@mastra/core`'s in-memory store. Persistent adapters returned `undefined` from `storage.getStore('workflowDefinitions')` and threw when the HTTP handler tried to read/write a workflow.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const workflowDefinitions = await storage.getStore('workflowDefinitions');
|
|
39
|
+
if (!workflowDefinitions) {
|
|
40
|
+
throw new Error('This storage adapter does not support the workflowDefinitions domain');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await workflowDefinitions.upsert({
|
|
44
|
+
id: 'greeting-workflow',
|
|
45
|
+
inputSchema: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },
|
|
46
|
+
outputSchema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
|
|
47
|
+
graph: [{ type: 'agent', id: 'greet', agentId: 'greeter-agent' }],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const { definitions, total } = await workflowDefinitions.list({ status: 'active' });
|
|
51
|
+
const definition = await workflowDefinitions.get('greeting-workflow');
|
|
52
|
+
await workflowDefinitions.delete('greeting-workflow');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Each adapter now ships a `WorkflowDefinitions*` domain that:
|
|
56
|
+
|
|
57
|
+
- Creates the shared `mastra_workflow_definitions` table (or Mongo collection) from `WORKFLOW_DEFINITIONS_SCHEMA` during `init()`, plus a default index on `status`.
|
|
58
|
+
- Implements `upsert` / `get` / `list` / `delete` matching `WorkflowDefinitionsStorage` semantics (`list` supports `status` and `authorId` filters and orders by `updatedAt` desc). Partial upserts preserve unspecified fields, including `authorId` updates and `createdAt` / `updatedAt` semantics.
|
|
59
|
+
- Handles concurrent first-writes race-safely: if two callers upsert the same new id simultaneously, the losing insert detects the duplicate key, re-reads the row, and applies the partial-update path instead of failing.
|
|
60
|
+
- Round-trips the JSON columns (`inputSchema`, `outputSchema`, `stateSchema`, `requestContextSchema`, `metadata`, `graph`) through each adapter's JSON handling, so declarative workflow graphs rehydrate identically no matter which backend they were stored in. Malformed persisted JSON surfaces as an actionable error naming the row and column instead of hydrating raw strings.
|
|
61
|
+
|
|
62
|
+
Exported class names by adapter: `WorkflowDefinitionsLibSQL`, `WorkflowDefinitionsPG`, `WorkflowDefinitionsMySQL`, `WorkflowDefinitionsMSSQL`, `MongoDBWorkflowDefinitionsStore`, `WorkflowDefinitionsSpanner`. The composite stores (`LibSQLStore`, `PostgresStore`, `MySQLStore`, `MSSQLStore`, `MongoDBStore`, `SpannerStore`) auto-wire the new domain, so callers do not need to construct it manually — `storage.getStore('workflowDefinitions')` now returns a live handle.
|
|
63
|
+
|
|
64
|
+
The pg adapter reads `createdAt` / `updatedAt` from the auto-added `createdAtZ` / `updatedAtZ` `timestamptz` companion columns to avoid the naive-timestamp / local-TZ drift that a plain `TIMESTAMP` read exhibits under node-pg.
|
|
65
|
+
|
|
66
|
+
`@mastra/clickhouse` and `@mastra/cloudflare` register the new `mastra_workflow_definitions` table in their table/type maps so shared table constants stay exhaustive (no workflow-definitions domain implementation yet).
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- Updated dependencies [[`4844167`](https://github.com/mastra-ai/mastra/commit/4844167cff2d5ec5004e94edd34970833040fa3f), [`5faf93f`](https://github.com/mastra-ai/mastra/commit/5faf93f03e19daea394b9e2a923f2e4f833407f2), [`80ad891`](https://github.com/mastra-ai/mastra/commit/80ad891f8cd10379aa5b5af7510c763783b2ab56), [`a1cb98d`](https://github.com/mastra-ai/mastra/commit/a1cb98d11990b560b98482292a1f34aa1a2d9092), [`598ad82`](https://github.com/mastra-ai/mastra/commit/598ad82d41c41389a686338a1d0e50b7400e1938), [`1fd6aad`](https://github.com/mastra-ai/mastra/commit/1fd6aad1ea4a9d32f65efa832307c35e981a4c0a)]:
|
|
71
|
+
- @mastra/core@1.56.0-alpha.4
|
|
72
|
+
|
|
3
73
|
## 1.16.0-alpha.1
|
|
4
74
|
|
|
5
75
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-mongodb
|
|
|
3
3
|
description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/mongodb"
|
|
6
|
-
version: "1.16.0-alpha.
|
|
6
|
+
version: "1.16.0-alpha.3"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -18,10 +18,13 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
18
18
|
|
|
19
19
|
- [Semantic recall](references/docs-memory-semantic-recall.md) - Learn how to use semantic recall in Mastra to retrieve relevant messages from past conversations using vector search and embeddings.
|
|
20
20
|
- [Working memory](references/docs-memory-working-memory.md) - Learn how to configure working memory in Mastra to store persistent user data, preferences.
|
|
21
|
-
- [Retrieval, semantic search, reranking](references/docs-rag-retrieval.md) - Guide on retrieval processes in Mastra's RAG systems, including semantic search, filtering, and re-ranking.
|
|
22
|
-
- [Storing embeddings in a vector database](references/docs-rag-vector-databases.md) - Guide on vector storage options in Mastra, including embedded and dedicated vector databases for similarity search.
|
|
23
21
|
- [Storage overview](references/docs-storage-overview.md) - Configure storage for Mastra to persist runtime state across agents, workflows, observability, evals, schedules, and memory.
|
|
24
22
|
|
|
23
|
+
### Guides
|
|
24
|
+
|
|
25
|
+
- [Retrieval, semantic search, reranking](references/guides-rag-retrieval.md) - Guide on retrieval processes in Mastra's RAG systems, including semantic search, filtering, and re-ranking.
|
|
26
|
+
- [Storing embeddings in a vector database](references/guides-rag-vector-databases.md) - Guide on vector storage options in Mastra, including embedded and dedicated vector databases for similarity search.
|
|
27
|
+
|
|
25
28
|
### Reference
|
|
26
29
|
|
|
27
30
|
- [Reference: Composite storage](references/reference-storage-composite.md) - Documentation for combining multiple storage backends in Mastra.
|
|
@@ -517,4 +517,4 @@ The re-ranked results combine vector similarity with semantic understanding to i
|
|
|
517
517
|
|
|
518
518
|
For more details about re-ranking, see the [rerank()](https://mastra.ai/reference/rag/rerankWithScorer) method.
|
|
519
519
|
|
|
520
|
-
For graph-based retrieval that follows connections between chunks, see the [GraphRAG](https://mastra.ai/
|
|
520
|
+
For graph-based retrieval that follows connections between chunks, see the [GraphRAG](https://mastra.ai/guides/rag/graph-rag) documentation.
|
|
@@ -188,6 +188,8 @@ export const mastra = new Mastra({
|
|
|
188
188
|
|
|
189
189
|
**default** (`MastraCompositeStore`): Default storage adapter. Domains not explicitly specified in domains will use this storage's domains as fallbacks.
|
|
190
190
|
|
|
191
|
+
**editor** (`MastraCompositeStore`): Storage adapter for Editor-owned domains, including agents, prompt blocks, scorers, MCP clients and servers, workspaces, and skills. Takes precedence over default storage but not explicit domain overrides.
|
|
192
|
+
|
|
191
193
|
**disableInit** (`boolean`): When true, automatic initialization is disabled. You must call init() explicitly.
|
|
192
194
|
|
|
193
195
|
**domains** (`object`): Individual domain overrides. Each domain can come from a different storage adapter. These take precedence over both editor and default storage. Set a domain to false to disable it entirely; a disabled domain does not fall back to editor or default.
|
|
@@ -109,7 +109,7 @@ Waits for an index to become ready after creation. Useful when you need to ensur
|
|
|
109
109
|
|
|
110
110
|
### `upsert()`
|
|
111
111
|
|
|
112
|
-
Adds or updates vectors and their metadata in the collection. On a bring-your-own index this requires `allowWrites: true` at `createIndex()` time
|
|
112
|
+
Adds or updates vectors and their metadata in the collection. On a bring-your-own index, this requires `allowWrites: true` at `createIndex()` time because BYO collections are read-only by default.
|
|
113
113
|
|
|
114
114
|
**indexName** (`string`): Name of the collection to insert into
|
|
115
115
|
|
|
@@ -148,12 +148,12 @@ Provisions an Atlas Search (BM25/full-text) index on the collection backing an i
|
|
|
148
148
|
**Managed vs. bring-your-own collections:**
|
|
149
149
|
|
|
150
150
|
- For a **managed** index (created without `collectionName`), `createIndex()` already provisions a _dynamic_ full-text index named `${collectionName}_search_index` (covering all string fields). `createSearchIndex()` is therefore only needed when you want a **field-restricted** mapping or a **custom index name**.
|
|
151
|
-
- For a **bring-your-own** index (created with `collectionName`), `createIndex()`
|
|
151
|
+
- For a **bring-your-own** index (created with `collectionName`), `createIndex()` doesn't auto-create any full-text index. Enabling `textQuery()`/`hybridQuery()` on a caller-owned operational collection is opt-in. Call `createSearchIndex()` explicitly to provision the (billable) text index. Until you do, `textQuery()`/`hybridQuery()` throw a clear error rather than querying a non-existent index.
|
|
152
152
|
|
|
153
153
|
Naming:
|
|
154
154
|
|
|
155
|
-
- When `fields` is provided **without** an explicit `searchIndexName`, the field-mapped index is created under a **distinct** default name (`${collectionName}_${indexName}_search_fields_index`, unique per logical index) so it
|
|
156
|
-
- When `searchIndexName` is provided, that exact name is used and persisted. `textQuery()`/`hybridQuery()` resolve the persisted name automatically
|
|
155
|
+
- When `fields` is provided **without** an explicit `searchIndexName`, the field-mapped index is created under a **distinct** default name (`${collectionName}_${indexName}_search_fields_index`, unique per logical index) so it doesn't collide with a managed collection's auto-created dynamic index and get silently ignored. This distinct index is persisted as the text-search index, so `textQuery()`/`hybridQuery()` use the restricted mapping automatically.
|
|
156
|
+
- When `searchIndexName` is provided, that exact name is used and persisted. `textQuery()`/`hybridQuery()` resolve the persisted name automatically. You can also override the name per call via their `searchIndexName` / `textSearchIndexName` parameters.
|
|
157
157
|
|
|
158
158
|
**indexName** (`string`): Name of the Mastra index whose collection will have the search index
|
|
159
159
|
|
|
@@ -170,7 +170,7 @@ await store.createSearchIndex({
|
|
|
170
170
|
})
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
The field-mapped index name includes the logical `indexName`, so two logical indexes on the same collection get distinct text indexes. Recreating the _same_ logical index with different `fields` still requires dropping the existing index first (`IndexAlreadyExists`).
|
|
174
174
|
|
|
175
175
|
### `waitForSearchIndexReady()`
|
|
176
176
|
|
|
@@ -193,7 +193,7 @@ await store.waitForSearchIndexReady({ indexName: 'precedents' })
|
|
|
193
193
|
|
|
194
194
|
Runs a full-text (BM25) search against an Atlas Search index. By default it targets the text-search index recorded for this index (set by `createSearchIndex()`, or the dynamic `${collectionName}_search_index` auto-created by `createIndex()`). Pass `searchIndexName` to target a specific index for this call.
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
Metadata filters here (like `hybridQuery()`) are applied via a `$match` stage. For the vector branch of `hybridQuery()`, filters on fields not declared via `filterFields` at index creation are transparently materialised as candidate `_id`s (the same fallback `query()` uses), so undeclared-field filters don't error.
|
|
197
197
|
|
|
198
198
|
**indexName** (`string`): Name of the Mastra index to search
|
|
199
199
|
|
|
@@ -220,7 +220,7 @@ const results = await store.textQuery({
|
|
|
220
220
|
|
|
221
221
|
### `hybridQuery()`
|
|
222
222
|
|
|
223
|
-
Runs a hybrid search that fuses vector similarity and full-text results using MongoDB's server-side `$rankFusion
|
|
223
|
+
Runs a hybrid search that fuses vector similarity and full-text results using MongoDB's server-side `$rankFusion`. It requires MongoDB >= 8.0 and is generally available from 8.1. On 8.0.x, it may need a MongoDB support case to enable, and it runs where enabled, such as Atlas 8.0.x. A full-text search index must exist: it's auto-created for managed indexes, but for a bring-your-own collection you must call `createSearchIndex()` first (opt-in).
|
|
224
224
|
|
|
225
225
|
**indexName** (`string`): Name of the Mastra index to search
|
|
226
226
|
|
|
@@ -253,7 +253,7 @@ const results = await store.hybridQuery({
|
|
|
253
253
|
})
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
`hybridQuery()` requires MongoDB >= 8.0 for the `$rankFusion` stage. The stage is generally available from 8.1. On 8.0.x, it may need a MongoDB support case to enable and runs where enabled, such as Atlas 8.0.x. If you're running an older version, or `$rankFusion` isn't enabled on your 8.0.x deployment, use `query()` and `textQuery()` separately and merge the results client-side.
|
|
257
257
|
|
|
258
258
|
### `describeIndex()`
|
|
259
259
|
|
|
@@ -276,15 +276,15 @@ interface IndexStats {
|
|
|
276
276
|
Deletes a vector index. Behavior depends on how the index was created:
|
|
277
277
|
|
|
278
278
|
- **Managed index** (created without `collectionName`): drops the entire collection and all its data.
|
|
279
|
-
- **Bring-your-own index** (created with `collectionName`): drops the Atlas vectorSearch index
|
|
279
|
+
- **Bring-your-own index** (created with `collectionName`): drops the Atlas vectorSearch index and, if one was provisioned via `createSearchIndex()`, the companion full-text search index. The caller's operational collection and its documents are preserved. This store never drops a collection it didn't create.
|
|
280
280
|
|
|
281
|
-
The BYO classification is recorded durably when the index is created, so it
|
|
281
|
+
The BYO classification is recorded durably when the index is created, so it's applied correctly even by a different process (e.g. an index created by a setup job and later deleted by a long-lived service). Always pass the **logical index name** (the `indexName` used at `createIndex`), not the physical collection name.
|
|
282
282
|
|
|
283
283
|
**indexName** (`string`): Logical name of the index to delete
|
|
284
284
|
|
|
285
285
|
### `listIndexes()`
|
|
286
286
|
|
|
287
|
-
Lists the **logical** Mastra index names (the `indexName` values passed to `createIndex`), not physical collection names. For a bring-your-own index whose data lives in an operational collection, the logical index name is returned
|
|
287
|
+
Lists the **logical** Mastra index names (the `indexName` values passed to `createIndex`), not physical collection names. For a bring-your-own index whose data lives in an operational collection, the logical index name is returned instead of the physical collection name. The value can be passed straight back into `deleteIndex()` / `describeIndex()`. Managed indexes created before durable metadata was introduced are still discovered via their `${name}_vector_index` search index. The internal registry collection is never listed.
|
|
288
288
|
|
|
289
289
|
Returns: `Promise<string[]>`
|
|
290
290
|
|
|
@@ -408,12 +408,12 @@ await store.createSearchIndex({ indexName: 'precedents', fields: ['note'] })
|
|
|
408
408
|
|
|
409
409
|
- The collection must already exist and contain documents with an `embedding` field (or the custom `embeddingFieldPath` you configured)
|
|
410
410
|
- The collection is never created or dropped when using `collectionName`
|
|
411
|
-
- **A BYO index is read-only by default.** `upsert()`, `updateVector()`, `deleteVector()`, and `deleteVectors()` throw a clear error rather than mutating caller-owned operational documents. To let the store write embeddings into (or delete documents from) your collection, opt in explicitly with `createIndex({ ..., allowWrites: true })`. The policy is persisted and survives restarts
|
|
411
|
+
- **A BYO index is read-only by default.** `upsert()`, `updateVector()`, `deleteVector()`, and `deleteVectors()` throw a clear error rather than mutating caller-owned operational documents. To let the store write embeddings into (or delete documents from) your collection, opt in explicitly with `createIndex({ ..., allowWrites: true })`. The policy is persisted and survives restarts. Entries written by older versions without the flag are treated as read-only (fail closed).
|
|
412
412
|
- Use `metadataMode: 'document'` when querying to retrieve the full source document as `metadata`
|
|
413
413
|
- In `'document'` mode the embedding is omitted from `metadata` by default; pass `includeVector: true` to retain it (and also expose it as a top-level `vector`)
|
|
414
414
|
- **Filtering in `'document'` mode operates on root document fields**, not a nested `metadata.` subdocument. `filter: { lane: 'fraud' }` matches the top-level `lane` field of your operational documents (in the default `'field'` mode, bare fields are rewritten to `metadata.<field>` for managed collections). Both the pushdown and `$match` fallback paths honor this.
|
|
415
415
|
- **Native `ObjectId` `_id`s are supported.** Operational collections commonly key on `ObjectId`; query results coerce `_id` to a string (the `QueryResult.id` contract), and `deleteVector()`/`updateVector()`/`deleteVectors()` accept that string and match the underlying `ObjectId` document. Managed collections (string `_id`s) are unaffected.
|
|
416
|
-
- Full-text and hybrid search on a BYO collection are **opt-in**: no full-text index is auto-created, so call `createSearchIndex()` before `textQuery()`/`hybridQuery()`. The full-text index builds asynchronously
|
|
416
|
+
- Full-text and hybrid search on a BYO collection are **opt-in**: no full-text index is auto-created, so call `createSearchIndex()` before `textQuery()`/`hybridQuery()`. The full-text index builds asynchronously. Call `waitForSearchIndexReady()` (or pass `waitUntilReady: true`) before an immediate text/hybrid query.
|
|
417
417
|
- `deleteIndex()` on a BYO index drops the vector index (and the text index if one was created) but **preserves** the collection and its documents
|
|
418
418
|
|
|
419
419
|
## Best practices
|
package/dist/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
|
|
|
10
10
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
11
11
|
let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
|
|
12
12
|
//#region package.json
|
|
13
|
-
var version = "1.16.0-alpha.
|
|
13
|
+
var version = "1.16.0-alpha.3";
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/vector/filter.ts
|
|
16
16
|
/**
|
|
@@ -2800,6 +2800,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
2800
2800
|
expectedTrajectory: typeof row.expectedTrajectory === "string" ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) : row.expectedTrajectory,
|
|
2801
2801
|
toolMocks: (typeof row.toolMocks === "string" ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) : row.toolMocks) ?? void 0,
|
|
2802
2802
|
unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
|
|
2803
|
+
scorerIds: (typeof row.scorerIds === "string" ? (0, _mastra_core_storage.safelyParseJSON)(row.scorerIds) : row.scorerIds) ?? void 0,
|
|
2803
2804
|
requestContext: typeof row.requestContext === "string" ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) : row.requestContext,
|
|
2804
2805
|
metadata: typeof row.metadata === "string" ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : row.metadata,
|
|
2805
2806
|
source: typeof row.source === "string" ? (0, _mastra_core_storage.safelyParseJSON)(row.source) : row.source,
|
|
@@ -3043,6 +3044,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3043
3044
|
expectedTrajectory: args.expectedTrajectory ?? null,
|
|
3044
3045
|
toolMocks: args.toolMocks ?? null,
|
|
3045
3046
|
unmockedToolPolicy: args.unmockedToolPolicy ?? null,
|
|
3047
|
+
scorerIds: args.scorerIds ?? null,
|
|
3046
3048
|
requestContext: args.requestContext ?? null,
|
|
3047
3049
|
metadata: args.metadata ?? null,
|
|
3048
3050
|
source: args.source ?? null,
|
|
@@ -3067,6 +3069,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3067
3069
|
expectedTrajectory: args.expectedTrajectory,
|
|
3068
3070
|
toolMocks: args.toolMocks,
|
|
3069
3071
|
unmockedToolPolicy: args.unmockedToolPolicy,
|
|
3072
|
+
scorerIds: args.scorerIds,
|
|
3070
3073
|
requestContext: args.requestContext,
|
|
3071
3074
|
metadata: args.metadata,
|
|
3072
3075
|
source: args.source,
|
|
@@ -3101,7 +3104,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3101
3104
|
actualDatasetId: existing.datasetId
|
|
3102
3105
|
}
|
|
3103
3106
|
});
|
|
3104
|
-
if (!(args.input !== void 0 || args.groundTruth !== void 0 || args.expectedTrajectory !== void 0 || args.toolMocks !== void 0 || args.unmockedToolPolicy !== void 0 || args.requestContext !== void 0 || args.metadata !== void 0 || args.source !== void 0)) return existing;
|
|
3107
|
+
if (!(args.input !== void 0 || args.groundTruth !== void 0 || args.expectedTrajectory !== void 0 || args.toolMocks !== void 0 || args.unmockedToolPolicy !== void 0 || args.scorerIds !== void 0 || args.requestContext !== void 0 || args.metadata !== void 0 || args.source !== void 0)) return existing;
|
|
3105
3108
|
const now = /* @__PURE__ */ new Date();
|
|
3106
3109
|
const versionId = (0, crypto$1.randomUUID)();
|
|
3107
3110
|
const mergedInput = args.input !== void 0 ? args.input : existing.input;
|
|
@@ -3109,6 +3112,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3109
3112
|
const mergedExpectedTrajectory = args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory;
|
|
3110
3113
|
const mergedToolMocks = args.toolMocks !== void 0 ? args.toolMocks : existing.toolMocks;
|
|
3111
3114
|
const mergedUnmockedToolPolicy = args.unmockedToolPolicy !== void 0 ? args.unmockedToolPolicy : existing.unmockedToolPolicy;
|
|
3115
|
+
const mergedScorerIds = args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds;
|
|
3112
3116
|
const mergedRequestContext = args.requestContext !== void 0 ? args.requestContext : existing.requestContext;
|
|
3113
3117
|
const mergedMetadata = args.metadata !== void 0 ? args.metadata : existing.metadata;
|
|
3114
3118
|
const mergedSource = args.source !== void 0 ? args.source : existing.source;
|
|
@@ -3151,6 +3155,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3151
3155
|
expectedTrajectory: mergedExpectedTrajectory ?? null,
|
|
3152
3156
|
toolMocks: mergedToolMocks ?? null,
|
|
3153
3157
|
unmockedToolPolicy: mergedUnmockedToolPolicy ?? null,
|
|
3158
|
+
scorerIds: mergedScorerIds ?? null,
|
|
3154
3159
|
requestContext: mergedRequestContext,
|
|
3155
3160
|
metadata: mergedMetadata,
|
|
3156
3161
|
source: mergedSource,
|
|
@@ -3174,6 +3179,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3174
3179
|
expectedTrajectory: mergedExpectedTrajectory,
|
|
3175
3180
|
toolMocks: mergedToolMocks,
|
|
3176
3181
|
unmockedToolPolicy: mergedUnmockedToolPolicy,
|
|
3182
|
+
scorerIds: mergedScorerIds,
|
|
3177
3183
|
requestContext: mergedRequestContext,
|
|
3178
3184
|
metadata: mergedMetadata,
|
|
3179
3185
|
source: mergedSource,
|
|
@@ -3240,6 +3246,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3240
3246
|
expectedTrajectory: existing.expectedTrajectory ?? null,
|
|
3241
3247
|
toolMocks: existing.toolMocks ?? null,
|
|
3242
3248
|
unmockedToolPolicy: existing.unmockedToolPolicy ?? null,
|
|
3249
|
+
scorerIds: existing.scorerIds ?? null,
|
|
3243
3250
|
requestContext: existing.requestContext,
|
|
3244
3251
|
metadata: existing.metadata,
|
|
3245
3252
|
source: existing.source,
|
|
@@ -3313,6 +3320,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3313
3320
|
expectedTrajectory: insert.item.expectedTrajectory,
|
|
3314
3321
|
toolMocks: insert.item.toolMocks,
|
|
3315
3322
|
unmockedToolPolicy: insert.item.unmockedToolPolicy,
|
|
3323
|
+
scorerIds: insert.item.scorerIds,
|
|
3316
3324
|
requestContext: insert.item.requestContext,
|
|
3317
3325
|
metadata: insert.item.metadata,
|
|
3318
3326
|
source: insert.item.source,
|
|
@@ -3394,6 +3402,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
|
|
|
3394
3402
|
expectedTrajectory: item.expectedTrajectory ?? null,
|
|
3395
3403
|
toolMocks: item.toolMocks ?? null,
|
|
3396
3404
|
unmockedToolPolicy: item.unmockedToolPolicy ?? null,
|
|
3405
|
+
scorerIds: item.scorerIds ?? null,
|
|
3397
3406
|
requestContext: item.requestContext,
|
|
3398
3407
|
metadata: item.metadata,
|
|
3399
3408
|
source: item.source,
|
|
@@ -9936,6 +9945,141 @@ var MongoDBSkillsStorage = class MongoDBSkillsStorage extends _mastra_core_stora
|
|
|
9936
9945
|
}
|
|
9937
9946
|
};
|
|
9938
9947
|
//#endregion
|
|
9948
|
+
//#region src/storage/domains/workflow-definitions/index.ts
|
|
9949
|
+
function docToDefinition(doc) {
|
|
9950
|
+
const def = {
|
|
9951
|
+
id: String(doc.id),
|
|
9952
|
+
inputSchema: doc.inputSchema,
|
|
9953
|
+
outputSchema: doc.outputSchema,
|
|
9954
|
+
graph: doc.graph,
|
|
9955
|
+
status: doc.status,
|
|
9956
|
+
source: doc.source,
|
|
9957
|
+
createdAt: doc.createdAt instanceof Date ? doc.createdAt : new Date(doc.createdAt),
|
|
9958
|
+
updatedAt: doc.updatedAt instanceof Date ? doc.updatedAt : new Date(doc.updatedAt)
|
|
9959
|
+
};
|
|
9960
|
+
if (doc.description != null) def.description = doc.description;
|
|
9961
|
+
if (doc.metadata != null) def.metadata = doc.metadata;
|
|
9962
|
+
if (doc.stateSchema != null) def.stateSchema = doc.stateSchema;
|
|
9963
|
+
if (doc.requestContextSchema != null) def.requestContextSchema = doc.requestContextSchema;
|
|
9964
|
+
if (doc.authorId != null) def.authorId = doc.authorId;
|
|
9965
|
+
return def;
|
|
9966
|
+
}
|
|
9967
|
+
var MongoDBWorkflowDefinitionsStore = class MongoDBWorkflowDefinitionsStore extends _mastra_core_storage.WorkflowDefinitionsStorage {
|
|
9968
|
+
#connector;
|
|
9969
|
+
#skipDefaultIndexes;
|
|
9970
|
+
#indexes;
|
|
9971
|
+
static MANAGED_COLLECTIONS = [_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS];
|
|
9972
|
+
constructor(config) {
|
|
9973
|
+
super();
|
|
9974
|
+
this.#connector = resolveMongoDBConfig(config);
|
|
9975
|
+
this.#skipDefaultIndexes = config.skipDefaultIndexes;
|
|
9976
|
+
this.#indexes = config.indexes?.filter((idx) => MongoDBWorkflowDefinitionsStore.MANAGED_COLLECTIONS.includes(idx.collection));
|
|
9977
|
+
}
|
|
9978
|
+
async getCollection(name) {
|
|
9979
|
+
return this.#connector.getCollection(name);
|
|
9980
|
+
}
|
|
9981
|
+
getDefaultIndexDefinitions() {
|
|
9982
|
+
return [{
|
|
9983
|
+
collection: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
9984
|
+
keys: { id: 1 },
|
|
9985
|
+
options: { unique: true }
|
|
9986
|
+
}, {
|
|
9987
|
+
collection: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
9988
|
+
keys: { status: 1 }
|
|
9989
|
+
}];
|
|
9990
|
+
}
|
|
9991
|
+
async createDefaultIndexes() {
|
|
9992
|
+
if (this.#skipDefaultIndexes) return;
|
|
9993
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) try {
|
|
9994
|
+
await (await this.getCollection(indexDef.collection)).createIndex(indexDef.keys, indexDef.options);
|
|
9995
|
+
} catch (error) {
|
|
9996
|
+
this.logger?.warn?.(`Failed to create index on ${indexDef.collection}:`, error);
|
|
9997
|
+
}
|
|
9998
|
+
}
|
|
9999
|
+
async createCustomIndexes() {
|
|
10000
|
+
if (!this.#indexes || this.#indexes.length === 0) return;
|
|
10001
|
+
for (const indexDef of this.#indexes) try {
|
|
10002
|
+
await (await this.getCollection(indexDef.collection)).createIndex(indexDef.keys, indexDef.options);
|
|
10003
|
+
} catch (error) {
|
|
10004
|
+
this.logger?.warn?.(`Failed to create custom index on ${indexDef.collection}:`, error);
|
|
10005
|
+
}
|
|
10006
|
+
}
|
|
10007
|
+
async init() {
|
|
10008
|
+
await this.createDefaultIndexes();
|
|
10009
|
+
await this.createCustomIndexes();
|
|
10010
|
+
}
|
|
10011
|
+
async dangerouslyClearAll() {
|
|
10012
|
+
await (await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS)).deleteMany({});
|
|
10013
|
+
}
|
|
10014
|
+
async upsert(input) {
|
|
10015
|
+
const now = /* @__PURE__ */ new Date();
|
|
10016
|
+
const collection = await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS);
|
|
10017
|
+
if (!await collection.findOne({ id: input.id })) {
|
|
10018
|
+
if (!("inputSchema" in input) || input.inputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
|
|
10019
|
+
if (!("outputSchema" in input) || input.outputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
|
|
10020
|
+
if (!("graph" in input) || input.graph === void 0) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
|
|
10021
|
+
const doc = {
|
|
10022
|
+
id: input.id,
|
|
10023
|
+
description: input.description ?? null,
|
|
10024
|
+
metadata: input.metadata ?? null,
|
|
10025
|
+
inputSchema: input.inputSchema,
|
|
10026
|
+
outputSchema: input.outputSchema,
|
|
10027
|
+
stateSchema: input.stateSchema ?? null,
|
|
10028
|
+
requestContextSchema: input.requestContextSchema ?? null,
|
|
10029
|
+
graph: input.graph,
|
|
10030
|
+
status: "active",
|
|
10031
|
+
source: "storage",
|
|
10032
|
+
authorId: "authorId" in input ? input.authorId ?? null : null,
|
|
10033
|
+
createdAt: now,
|
|
10034
|
+
updatedAt: now
|
|
10035
|
+
};
|
|
10036
|
+
try {
|
|
10037
|
+
await collection.insertOne(doc);
|
|
10038
|
+
} catch (error) {
|
|
10039
|
+
if (!(error?.code === 11e3) || !await collection.findOne({ id: input.id })) throw error;
|
|
10040
|
+
return this.applyUpdate(input, now);
|
|
10041
|
+
}
|
|
10042
|
+
return docToDefinition(doc);
|
|
10043
|
+
}
|
|
10044
|
+
return this.applyUpdate(input, now);
|
|
10045
|
+
}
|
|
10046
|
+
async applyUpdate(input, now) {
|
|
10047
|
+
const collection = await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS);
|
|
10048
|
+
const update = { updatedAt: now };
|
|
10049
|
+
if ("description" in input && input.description !== void 0) update.description = input.description;
|
|
10050
|
+
if ("metadata" in input && input.metadata !== void 0) update.metadata = input.metadata;
|
|
10051
|
+
if ("inputSchema" in input && input.inputSchema !== void 0) update.inputSchema = input.inputSchema;
|
|
10052
|
+
if ("outputSchema" in input && input.outputSchema !== void 0) update.outputSchema = input.outputSchema;
|
|
10053
|
+
if ("stateSchema" in input && input.stateSchema !== void 0) update.stateSchema = input.stateSchema;
|
|
10054
|
+
if ("requestContextSchema" in input && input.requestContextSchema !== void 0) update.requestContextSchema = input.requestContextSchema;
|
|
10055
|
+
if ("graph" in input && input.graph !== void 0) update.graph = input.graph;
|
|
10056
|
+
if ("status" in input && input.status !== void 0) update.status = input.status;
|
|
10057
|
+
if ("authorId" in input && input.authorId !== void 0) update.authorId = input.authorId;
|
|
10058
|
+
await collection.updateOne({ id: input.id }, { $set: update });
|
|
10059
|
+
const updated = await collection.findOne({ id: input.id });
|
|
10060
|
+
if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
|
|
10061
|
+
return docToDefinition(updated);
|
|
10062
|
+
}
|
|
10063
|
+
async get(id) {
|
|
10064
|
+
const doc = await (await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS)).findOne({ id });
|
|
10065
|
+
return doc ? docToDefinition(doc) : null;
|
|
10066
|
+
}
|
|
10067
|
+
async list(args) {
|
|
10068
|
+
const collection = await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS);
|
|
10069
|
+
const filter = {};
|
|
10070
|
+
if (args?.status) filter.status = args.status;
|
|
10071
|
+
if (args?.authorId !== void 0) filter.authorId = args.authorId;
|
|
10072
|
+
const definitions = (await collection.find(filter).sort({ updatedAt: -1 }).toArray()).map(docToDefinition);
|
|
10073
|
+
return {
|
|
10074
|
+
definitions,
|
|
10075
|
+
total: definitions.length
|
|
10076
|
+
};
|
|
10077
|
+
}
|
|
10078
|
+
async delete(id) {
|
|
10079
|
+
await (await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS)).deleteOne({ id });
|
|
10080
|
+
}
|
|
10081
|
+
};
|
|
10082
|
+
//#endregion
|
|
9939
10083
|
//#region src/storage/domains/workflows/index.ts
|
|
9940
10084
|
var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core_storage.WorkflowsStorage {
|
|
9941
10085
|
#connector;
|
|
@@ -10824,6 +10968,7 @@ var MongoDBStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
10824
10968
|
const experiments = new MongoDBExperimentsStorage(domainConfig);
|
|
10825
10969
|
const backgroundTasks = new BackgroundTasksStorageMongoDB(domainConfig);
|
|
10826
10970
|
const schedules = new SchedulesMongoDB(domainConfig);
|
|
10971
|
+
const workflowDefinitions = new MongoDBWorkflowDefinitionsStore(domainConfig);
|
|
10827
10972
|
this.stores = {
|
|
10828
10973
|
memory,
|
|
10829
10974
|
notifications,
|
|
@@ -10841,7 +10986,8 @@ var MongoDBStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
10841
10986
|
backgroundTasks,
|
|
10842
10987
|
datasets,
|
|
10843
10988
|
experiments,
|
|
10844
|
-
schedules
|
|
10989
|
+
schedules,
|
|
10990
|
+
workflowDefinitions
|
|
10845
10991
|
};
|
|
10846
10992
|
}
|
|
10847
10993
|
/**
|
|
@@ -10975,6 +11121,7 @@ exports.MongoDBScorerDefinitionsStorage = MongoDBScorerDefinitionsStorage;
|
|
|
10975
11121
|
exports.MongoDBSkillsStorage = MongoDBSkillsStorage;
|
|
10976
11122
|
exports.MongoDBStore = MongoDBStore;
|
|
10977
11123
|
exports.MongoDBVector = MongoDBVector;
|
|
11124
|
+
exports.MongoDBWorkflowDefinitionsStore = MongoDBWorkflowDefinitionsStore;
|
|
10978
11125
|
exports.MongoDBWorkspacesStorage = MongoDBWorkspacesStorage;
|
|
10979
11126
|
exports.NotificationsMongoDB = NotificationsMongoDB;
|
|
10980
11127
|
exports.ObservabilityMongoDB = ObservabilityMongoDB;
|