@mastra/mongodb 1.27.0-alpha.0 → 1.27.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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +5 -5
- package/dist/index.cjs +70 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -5
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +12 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +6 -6
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.27.
|
|
6
|
+
version: "1.27.1-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.27.
|
|
2
|
+
"version": "1.27.1-alpha.0",
|
|
3
3
|
"package": "@mastra/mongodb",
|
|
4
4
|
"exports": {
|
|
5
5
|
"BackgroundTasksStorageMongoDB": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"MONGODB_PROMPT": {
|
|
16
16
|
"types": "dist/vector/prompt.d.ts",
|
|
17
17
|
"implementation": "dist/index.js",
|
|
18
|
-
"line":
|
|
18
|
+
"line": 14515
|
|
19
19
|
},
|
|
20
20
|
"MemoryStorageMongoDB": {
|
|
21
21
|
"types": "dist/storage/domains/memory/index.d.ts",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"MongoDBStore": {
|
|
71
71
|
"types": "dist/storage/index.d.ts",
|
|
72
72
|
"implementation": "dist/index.js",
|
|
73
|
-
"line":
|
|
73
|
+
"line": 14436
|
|
74
74
|
},
|
|
75
75
|
"MongoDBVector": {
|
|
76
76
|
"types": "dist/vector/index.d.ts",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"MongoDBWorkspacesStorage": {
|
|
86
86
|
"types": "dist/storage/domains/workspaces/index.d.ts",
|
|
87
87
|
"implementation": "dist/index.js",
|
|
88
|
-
"line":
|
|
88
|
+
"line": 13934
|
|
89
89
|
},
|
|
90
90
|
"NotificationsMongoDB": {
|
|
91
91
|
"types": "dist/storage/domains/notifications/index.d.ts",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"WorkflowsStorageMongoDB": {
|
|
111
111
|
"types": "dist/storage/domains/workflows/index.d.ts",
|
|
112
112
|
"implementation": "dist/index.js",
|
|
113
|
-
"line":
|
|
113
|
+
"line": 13396
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
116
|
"modules": {}
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
|
|
|
11
11
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
12
12
|
let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
|
|
13
13
|
// package.json
|
|
14
|
-
var version = "1.27.
|
|
14
|
+
var version = "1.27.1-alpha.0";
|
|
15
15
|
// src/vector/filter.ts
|
|
16
16
|
/**
|
|
17
17
|
* Translator for MongoDB filter queries.
|
|
@@ -13348,7 +13348,43 @@ const RUN_OWNER_PROJECTION = {
|
|
|
13348
13348
|
leaseExpiresAt: 1,
|
|
13349
13349
|
live: { $gt: ["$leaseExpiresAt", "$$NOW"] }
|
|
13350
13350
|
};
|
|
13351
|
+
/** Run ids per query in `getRunOwnerships`, keeping each query document small. */
|
|
13352
|
+
const RUN_OWNERSHIP_BATCH_SIZE = 1e3;
|
|
13351
13353
|
const NOT_LIVE = { $or: [{ leaseExpiresAt: null }, { $expr: { $lte: ["$leaseExpiresAt", "$$NOW"] } }] };
|
|
13354
|
+
/**
|
|
13355
|
+
* Fields a `listWorkflowRuns({ summary: true })` document carries: the run columns plus the
|
|
13356
|
+
* snapshot fields a summary returns, so the rest of the snapshot is never sent.
|
|
13357
|
+
*/
|
|
13358
|
+
const SUMMARY_PROJECTION = {
|
|
13359
|
+
workflow_name: 1,
|
|
13360
|
+
run_id: 1,
|
|
13361
|
+
resourceId: 1,
|
|
13362
|
+
createdAt: 1,
|
|
13363
|
+
updatedAt: 1,
|
|
13364
|
+
"snapshot.status": 1,
|
|
13365
|
+
"snapshot.timestamp": 1,
|
|
13366
|
+
"snapshot.parentWorkflow.workflowId": 1,
|
|
13367
|
+
"snapshot.parentWorkflow.runId": 1
|
|
13368
|
+
};
|
|
13369
|
+
/**
|
|
13370
|
+
* The reduced snapshot of a `SUMMARY_PROJECTION` document: `status` and `timestamp` when set, and
|
|
13371
|
+
* `parentWorkflow` only when both of its IDs are non-empty strings. A missing snapshot reduces
|
|
13372
|
+
* to `{}`, and so does a legacy snapshot stored as a JSON string, since the projection can't
|
|
13373
|
+
* read fields inside a string.
|
|
13374
|
+
*/
|
|
13375
|
+
function summarySnapshot(projected) {
|
|
13376
|
+
const { status, timestamp, parentWorkflow } = projected !== null && typeof projected === "object" ? projected : {};
|
|
13377
|
+
const summary = {};
|
|
13378
|
+
if (status !== void 0 && status !== null) summary.status = status;
|
|
13379
|
+
if (timestamp !== void 0 && timestamp !== null) summary.timestamp = timestamp;
|
|
13380
|
+
const workflowId = parentWorkflow?.workflowId;
|
|
13381
|
+
const runId = parentWorkflow?.runId;
|
|
13382
|
+
if (typeof workflowId === "string" && workflowId !== "" && typeof runId === "string" && runId !== "") summary.parentWorkflow = {
|
|
13383
|
+
workflowId,
|
|
13384
|
+
runId
|
|
13385
|
+
};
|
|
13386
|
+
return summary;
|
|
13387
|
+
}
|
|
13352
13388
|
function toRunOwnershipRecord(doc) {
|
|
13353
13389
|
return {
|
|
13354
13390
|
runId: doc._id,
|
|
@@ -13538,6 +13574,27 @@ var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core
|
|
|
13538
13574
|
throw this.#ownershipError("GET_RUN_OWNERSHIP", runId, error);
|
|
13539
13575
|
}
|
|
13540
13576
|
}
|
|
13577
|
+
/** Reads the records with one query per {@link RUN_OWNERSHIP_BATCH_SIZE} runs. */
|
|
13578
|
+
async getRunOwnerships({ runIds }) {
|
|
13579
|
+
const records = /* @__PURE__ */ new Map();
|
|
13580
|
+
const ids = [...new Set(runIds)];
|
|
13581
|
+
try {
|
|
13582
|
+
const owners = await getRunClaims(this.#connector, _mastra_core_storage.TABLE_WORKFLOW_RUN_OWNERS);
|
|
13583
|
+
for (let start = 0; start < ids.length; start += RUN_OWNERSHIP_BATCH_SIZE) {
|
|
13584
|
+
const chunk = ids.slice(start, start + RUN_OWNERSHIP_BATCH_SIZE);
|
|
13585
|
+
const docs = await owners.find({ _id: { $in: chunk } }, { projection: RUN_OWNER_PROJECTION }).toArray();
|
|
13586
|
+
for (const doc of docs) records.set(doc._id, toRunOwnershipRecord(doc));
|
|
13587
|
+
}
|
|
13588
|
+
return records;
|
|
13589
|
+
} catch (error) {
|
|
13590
|
+
throw new _mastra_core_error.MastraError({
|
|
13591
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("MONGODB", "GET_RUN_OWNERSHIPS", "FAILED"),
|
|
13592
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
13593
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
13594
|
+
details: { runCount: ids.length }
|
|
13595
|
+
}, error);
|
|
13596
|
+
}
|
|
13597
|
+
}
|
|
13541
13598
|
/**
|
|
13542
13599
|
* Returns default index definitions for the workflows domain collections.
|
|
13543
13600
|
*/
|
|
@@ -13750,6 +13807,10 @@ var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core
|
|
|
13750
13807
|
}, error);
|
|
13751
13808
|
}
|
|
13752
13809
|
}
|
|
13810
|
+
/**
|
|
13811
|
+
* Lists runs newest first, with optional filters and pagination. With `summary`, each run's
|
|
13812
|
+
* snapshot holds only `status`, `timestamp` and `parentWorkflow`.
|
|
13813
|
+
*/
|
|
13753
13814
|
async listWorkflowRuns(args) {
|
|
13754
13815
|
const options = args || {};
|
|
13755
13816
|
try {
|
|
@@ -13764,7 +13825,7 @@ var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core
|
|
|
13764
13825
|
if (options.resourceId) query["resourceId"] = options.resourceId;
|
|
13765
13826
|
const collection = await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT);
|
|
13766
13827
|
let total = 0;
|
|
13767
|
-
let cursor = collection.find(query).sort({ createdAt: -1 });
|
|
13828
|
+
let cursor = collection.find(query, options.summary ? { projection: SUMMARY_PROJECTION } : void 0).sort({ createdAt: -1 });
|
|
13768
13829
|
if (options.page !== void 0 && typeof options.perPage === "number") {
|
|
13769
13830
|
if (options.page < 0) throw new _mastra_core_error.MastraError({
|
|
13770
13831
|
id: (0, _mastra_core_storage.createStorageErrorId)("MONGODB", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
|
|
@@ -13782,7 +13843,7 @@ var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core
|
|
|
13782
13843
|
cursor = cursor.skip(offset);
|
|
13783
13844
|
cursor = cursor.limit(Math.min(normalizedPerPage, 2147483647));
|
|
13784
13845
|
}
|
|
13785
|
-
const runs = (await cursor.toArray()).map((row) => this.parseWorkflowRun(row));
|
|
13846
|
+
const runs = (await cursor.toArray()).map((row) => this.parseWorkflowRun(row, { summary: options.summary }));
|
|
13786
13847
|
return {
|
|
13787
13848
|
runs,
|
|
13788
13849
|
total: total || runs.length
|
|
@@ -13834,8 +13895,12 @@ var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core
|
|
|
13834
13895
|
}, error);
|
|
13835
13896
|
}
|
|
13836
13897
|
}
|
|
13837
|
-
|
|
13838
|
-
|
|
13898
|
+
/**
|
|
13899
|
+
* Maps a document to a workflow run. With `summary`, the document comes from
|
|
13900
|
+
* `SUMMARY_PROJECTION` and its snapshot holds only the projected fields.
|
|
13901
|
+
*/
|
|
13902
|
+
parseWorkflowRun(row, { summary } = {}) {
|
|
13903
|
+
let parsedSnapshot = summary ? summarySnapshot(row.snapshot) : row.snapshot;
|
|
13839
13904
|
if (typeof parsedSnapshot === "string") try {
|
|
13840
13905
|
parsedSnapshot = typeof row.snapshot === "string" ? (0, _mastra_core_storage.safelyParseJSON)(row.snapshot) : row.snapshot;
|
|
13841
13906
|
} catch (e) {
|