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