@mastra/mongodb 1.7.4 → 1.8.0-alpha.1
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 +28 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +254 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +228 -4
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts +25 -0
- package/dist/storage/domains/schedules/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 +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 1.8.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Extend the schedules storage schema to support owned schedules and richer trigger audit. This is a breaking schema change to `mastra_schedules` and `mastra_schedule_triggers`; scheduled workflows are still in alpha so no compat shim is provided. ([#16166](https://github.com/mastra-ai/mastra/pull/16166))
|
|
8
|
+
- `Schedule` gains optional `ownerType` / `ownerId` so a schedule row can be attributed to an owning subsystem (e.g. an agent that owns a heartbeat schedule). Workflow schedules leave both fields unset.
|
|
9
|
+
- `ScheduleTrigger.status` is renamed to `outcome` and the type is widened to `ScheduleTriggerOutcome` so future outcome values can be added without another rename.
|
|
10
|
+
- `ScheduleTrigger` gains a stable `id` primary key and new `triggerKind`, `parentTriggerId`, and `metadata` fields. `triggerKind` distinguishes `schedule-fire` rows from later `queue-drain` rows (used by upcoming heartbeat work); `parentTriggerId` links related rows; `metadata` carries outcome-specific context.
|
|
11
|
+
- The libsql, pg, and mongodb adapters all add the new columns/indexes. Their `@mastra/core` peer dependency is tightened to `>=1.32.0-0 <2.0.0-0` so installing a new storage adapter against an older core (or vice-versa) surfaces a peer-dependency warning at install time instead of silently writing/reading the wrong field.
|
|
12
|
+
- Scheduler producer, server schemas/handler, and client SDK types are updated to use the new fields. The `triggers` response on `GET /api/schedules/:id/triggers` now returns `outcome` instead of `status`.
|
|
13
|
+
- The bundled Studio (Mastra CLI) is updated to read `outcome` so the schedule detail page keeps polling and rendering publish-failure rows correctly.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`ca28c23`](https://github.com/mastra-ai/mastra/commit/ca28c232a2f18801a6cf20fe053479237b4d4fb0)]:
|
|
18
|
+
- @mastra/core@1.32.0-alpha.3
|
|
19
|
+
|
|
20
|
+
## 1.8.0-alpha.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- Added the `schedules` storage domain so MongoDB-backed Mastra apps can use scheduled workflows. Creates `mastra_schedules` and `mastra_schedule_triggers` collections on init, with default indexes on `(status, next_fire_at)` for due-schedule polling and `(schedule_id, actual_fire_at)` for trigger-history queries. ([#15830](https://github.com/mastra-ai/mastra/pull/15830))
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [[`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
|
|
29
|
+
- @mastra/core@1.32.0-alpha.1
|
|
30
|
+
|
|
3
31
|
## 1.7.4
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var storage = require('@mastra/core/storage');
|
|
|
6
6
|
var vector = require('@mastra/core/vector');
|
|
7
7
|
var mongodb = require('mongodb');
|
|
8
8
|
var filter = require('@mastra/core/vector/filter');
|
|
9
|
-
var crypto = require('crypto');
|
|
9
|
+
var crypto$1 = require('crypto');
|
|
10
10
|
var agent = require('@mastra/core/agent');
|
|
11
11
|
var evals = require('@mastra/core/evals');
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ var evals = require('@mastra/core/evals');
|
|
|
14
14
|
|
|
15
15
|
// package.json
|
|
16
16
|
var package_default = {
|
|
17
|
-
version: "1.
|
|
17
|
+
version: "1.8.0-alpha.1"};
|
|
18
18
|
var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
19
19
|
getSupportedOperators() {
|
|
20
20
|
return {
|
|
@@ -1076,7 +1076,7 @@ var MongoDBAgentsStorage = class _MongoDBAgentsStorage extends storage.AgentsSto
|
|
|
1076
1076
|
};
|
|
1077
1077
|
await collection.insertOne(this.serializeAgent(newAgent));
|
|
1078
1078
|
const { id: _id, authorId: _authorId, metadata: _metadata, ...snapshotConfig } = agent;
|
|
1079
|
-
const versionId = crypto.randomUUID();
|
|
1079
|
+
const versionId = crypto$1.randomUUID();
|
|
1080
1080
|
await this.createVersion({
|
|
1081
1081
|
id: versionId,
|
|
1082
1082
|
agentId: agent.id,
|
|
@@ -2021,7 +2021,7 @@ var MongoDBDatasetsStorage = class extends storage.DatasetsStorage {
|
|
|
2021
2021
|
// --- Dataset CRUD ---
|
|
2022
2022
|
async createDataset(input) {
|
|
2023
2023
|
try {
|
|
2024
|
-
const id = crypto.randomUUID();
|
|
2024
|
+
const id = crypto$1.randomUUID();
|
|
2025
2025
|
const now = /* @__PURE__ */ new Date();
|
|
2026
2026
|
const collection = await this.getCollection(storage.TABLE_DATASETS);
|
|
2027
2027
|
const record = {
|
|
@@ -2180,8 +2180,8 @@ var MongoDBDatasetsStorage = class extends storage.DatasetsStorage {
|
|
|
2180
2180
|
// --- Item mutations (SCD-2) ---
|
|
2181
2181
|
async _doAddItem(args) {
|
|
2182
2182
|
try {
|
|
2183
|
-
const id = crypto.randomUUID();
|
|
2184
|
-
const versionId = crypto.randomUUID();
|
|
2183
|
+
const id = crypto$1.randomUUID();
|
|
2184
|
+
const versionId = crypto$1.randomUUID();
|
|
2185
2185
|
const now = /* @__PURE__ */ new Date();
|
|
2186
2186
|
const datasetsCollection = await this.getCollection(storage.TABLE_DATASETS);
|
|
2187
2187
|
const itemsCollection = await this.getCollection(storage.TABLE_DATASET_ITEMS);
|
|
@@ -2270,7 +2270,7 @@ var MongoDBDatasetsStorage = class extends storage.DatasetsStorage {
|
|
|
2270
2270
|
return existing;
|
|
2271
2271
|
}
|
|
2272
2272
|
const now = /* @__PURE__ */ new Date();
|
|
2273
|
-
const versionId = crypto.randomUUID();
|
|
2273
|
+
const versionId = crypto$1.randomUUID();
|
|
2274
2274
|
const mergedInput = args.input !== void 0 ? args.input : existing.input;
|
|
2275
2275
|
const mergedGroundTruth = args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth;
|
|
2276
2276
|
const mergedExpectedTrajectory = args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory;
|
|
@@ -2355,7 +2355,7 @@ var MongoDBDatasetsStorage = class extends storage.DatasetsStorage {
|
|
|
2355
2355
|
});
|
|
2356
2356
|
}
|
|
2357
2357
|
const now = /* @__PURE__ */ new Date();
|
|
2358
|
-
const versionId = crypto.randomUUID();
|
|
2358
|
+
const versionId = crypto$1.randomUUID();
|
|
2359
2359
|
const datasetsCollection = await this.getCollection(storage.TABLE_DATASETS);
|
|
2360
2360
|
const itemsCollection = await this.getCollection(storage.TABLE_DATASET_ITEMS);
|
|
2361
2361
|
const versionsCollection = await this.getCollection(storage.TABLE_DATASET_VERSIONS);
|
|
@@ -2422,9 +2422,9 @@ var MongoDBDatasetsStorage = class extends storage.DatasetsStorage {
|
|
|
2422
2422
|
return [];
|
|
2423
2423
|
}
|
|
2424
2424
|
const now = /* @__PURE__ */ new Date();
|
|
2425
|
-
const versionId = crypto.randomUUID();
|
|
2425
|
+
const versionId = crypto$1.randomUUID();
|
|
2426
2426
|
const itemsWithIds = input.items.map((itemInput) => ({
|
|
2427
|
-
generatedId: crypto.randomUUID(),
|
|
2427
|
+
generatedId: crypto$1.randomUUID(),
|
|
2428
2428
|
itemInput
|
|
2429
2429
|
}));
|
|
2430
2430
|
const datasetsCollection = await this.getCollection(storage.TABLE_DATASETS);
|
|
@@ -2514,7 +2514,7 @@ var MongoDBDatasetsStorage = class extends storage.DatasetsStorage {
|
|
|
2514
2514
|
const currentItems = currentRows.map((row) => this.transformItemRow(row));
|
|
2515
2515
|
if (currentItems.length === 0) return;
|
|
2516
2516
|
const now = /* @__PURE__ */ new Date();
|
|
2517
|
-
const versionId = crypto.randomUUID();
|
|
2517
|
+
const versionId = crypto$1.randomUUID();
|
|
2518
2518
|
const datasetsCollection = await this.getCollection(storage.TABLE_DATASETS);
|
|
2519
2519
|
const versionsCollection = await this.getCollection(storage.TABLE_DATASET_VERSIONS);
|
|
2520
2520
|
const result = await datasetsCollection.findOneAndUpdate(
|
|
@@ -2701,7 +2701,7 @@ var MongoDBDatasetsStorage = class extends storage.DatasetsStorage {
|
|
|
2701
2701
|
// --- Dataset versions ---
|
|
2702
2702
|
async createDatasetVersion(datasetId, version) {
|
|
2703
2703
|
try {
|
|
2704
|
-
const id = crypto.randomUUID();
|
|
2704
|
+
const id = crypto$1.randomUUID();
|
|
2705
2705
|
const now = /* @__PURE__ */ new Date();
|
|
2706
2706
|
const collection = await this.getCollection(storage.TABLE_DATASET_VERSIONS);
|
|
2707
2707
|
await collection.insertOne({ id, datasetId, version, createdAt: now });
|
|
@@ -2893,7 +2893,7 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends storage
|
|
|
2893
2893
|
// Experiment CRUD
|
|
2894
2894
|
// -------------------------------------------------------------------------
|
|
2895
2895
|
async createExperiment(input) {
|
|
2896
|
-
const id = input.id ?? crypto.randomUUID();
|
|
2896
|
+
const id = input.id ?? crypto$1.randomUUID();
|
|
2897
2897
|
const now = /* @__PURE__ */ new Date();
|
|
2898
2898
|
const doc = {
|
|
2899
2899
|
id,
|
|
@@ -3079,7 +3079,7 @@ var MongoDBExperimentsStorage = class _MongoDBExperimentsStorage extends storage
|
|
|
3079
3079
|
// Experiment Results
|
|
3080
3080
|
// -------------------------------------------------------------------------
|
|
3081
3081
|
async addExperimentResult(input) {
|
|
3082
|
-
const id = input.id ?? crypto.randomUUID();
|
|
3082
|
+
const id = input.id ?? crypto$1.randomUUID();
|
|
3083
3083
|
const now = /* @__PURE__ */ new Date();
|
|
3084
3084
|
const doc = {
|
|
3085
3085
|
id,
|
|
@@ -3423,7 +3423,7 @@ var MongoDBMCPClientsStorage = class _MongoDBMCPClientsStorage extends storage.M
|
|
|
3423
3423
|
snapshotConfig[field] = mcpClient[field];
|
|
3424
3424
|
}
|
|
3425
3425
|
}
|
|
3426
|
-
const versionId = crypto.randomUUID();
|
|
3426
|
+
const versionId = crypto$1.randomUUID();
|
|
3427
3427
|
try {
|
|
3428
3428
|
await this.createVersion({
|
|
3429
3429
|
id: versionId,
|
|
@@ -3975,7 +3975,7 @@ var MongoDBMCPServersStorage = class _MongoDBMCPServersStorage extends storage.M
|
|
|
3975
3975
|
snapshotConfig[field] = mcpServer[field];
|
|
3976
3976
|
}
|
|
3977
3977
|
}
|
|
3978
|
-
const versionId = crypto.randomUUID();
|
|
3978
|
+
const versionId = crypto$1.randomUUID();
|
|
3979
3979
|
try {
|
|
3980
3980
|
await this.createVersion({
|
|
3981
3981
|
id: versionId,
|
|
@@ -5283,7 +5283,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5283
5283
|
details: { sourceThreadId }
|
|
5284
5284
|
});
|
|
5285
5285
|
}
|
|
5286
|
-
const newThreadId = providedThreadId || crypto.randomUUID();
|
|
5286
|
+
const newThreadId = providedThreadId || crypto$1.randomUUID();
|
|
5287
5287
|
const existingThread = await this.getThreadById({ threadId: newThreadId });
|
|
5288
5288
|
if (existingThread) {
|
|
5289
5289
|
throw new error.MastraError({
|
|
@@ -5342,7 +5342,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5342
5342
|
if (sourceMessages.length > 0) {
|
|
5343
5343
|
const messageDocs = [];
|
|
5344
5344
|
for (const sourceMsg of sourceMessages) {
|
|
5345
|
-
const newMessageId = crypto.randomUUID();
|
|
5345
|
+
const newMessageId = crypto$1.randomUUID();
|
|
5346
5346
|
messageIdMap[sourceMsg.id] = newMessageId;
|
|
5347
5347
|
let parsedContent = sourceMsg.content;
|
|
5348
5348
|
if (typeof parsedContent === "string") {
|
|
@@ -5500,7 +5500,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5500
5500
|
}
|
|
5501
5501
|
async initializeObservationalMemory(input) {
|
|
5502
5502
|
try {
|
|
5503
|
-
const id = crypto.randomUUID();
|
|
5503
|
+
const id = crypto$1.randomUUID();
|
|
5504
5504
|
const now = /* @__PURE__ */ new Date();
|
|
5505
5505
|
const lookupKey = this.getOMKey(input.threadId, input.resourceId);
|
|
5506
5506
|
const record = {
|
|
@@ -5661,7 +5661,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5661
5661
|
}
|
|
5662
5662
|
async createReflectionGeneration(input) {
|
|
5663
5663
|
try {
|
|
5664
|
-
const id = crypto.randomUUID();
|
|
5664
|
+
const id = crypto$1.randomUUID();
|
|
5665
5665
|
const now = /* @__PURE__ */ new Date();
|
|
5666
5666
|
const lookupKey = this.getOMKey(input.currentRecord.threadId, input.currentRecord.resourceId);
|
|
5667
5667
|
const record = {
|
|
@@ -5948,7 +5948,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5948
5948
|
try {
|
|
5949
5949
|
const collection = await this.getCollection(OM_TABLE);
|
|
5950
5950
|
const newChunk = {
|
|
5951
|
-
id: `ombuf-${crypto.randomUUID()}`,
|
|
5951
|
+
id: `ombuf-${crypto$1.randomUUID()}`,
|
|
5952
5952
|
cycleId: input.chunk.cycleId,
|
|
5953
5953
|
observations: input.chunk.observations,
|
|
5954
5954
|
tokenCount: input.chunk.tokenCount,
|
|
@@ -7181,7 +7181,7 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends stora
|
|
|
7181
7181
|
snapshotConfig[field] = promptBlock[field];
|
|
7182
7182
|
}
|
|
7183
7183
|
}
|
|
7184
|
-
const versionId = crypto.randomUUID();
|
|
7184
|
+
const versionId = crypto$1.randomUUID();
|
|
7185
7185
|
await this.createVersion({
|
|
7186
7186
|
id: versionId,
|
|
7187
7187
|
blockId: promptBlock.id,
|
|
@@ -7595,6 +7595,228 @@ var MongoDBPromptBlocksStorage = class _MongoDBPromptBlocksStorage extends stora
|
|
|
7595
7595
|
return result;
|
|
7596
7596
|
}
|
|
7597
7597
|
};
|
|
7598
|
+
function scheduleToDoc(schedule) {
|
|
7599
|
+
return {
|
|
7600
|
+
id: schedule.id,
|
|
7601
|
+
target: schedule.target,
|
|
7602
|
+
cron: schedule.cron,
|
|
7603
|
+
timezone: schedule.timezone ?? null,
|
|
7604
|
+
status: schedule.status,
|
|
7605
|
+
next_fire_at: schedule.nextFireAt,
|
|
7606
|
+
last_fire_at: schedule.lastFireAt ?? null,
|
|
7607
|
+
last_run_id: schedule.lastRunId ?? null,
|
|
7608
|
+
created_at: schedule.createdAt,
|
|
7609
|
+
updated_at: schedule.updatedAt,
|
|
7610
|
+
metadata: schedule.metadata ?? null,
|
|
7611
|
+
owner_type: schedule.ownerType ?? null,
|
|
7612
|
+
owner_id: schedule.ownerId ?? null
|
|
7613
|
+
};
|
|
7614
|
+
}
|
|
7615
|
+
function docToSchedule(doc) {
|
|
7616
|
+
const target = doc.target;
|
|
7617
|
+
if (!target) {
|
|
7618
|
+
throw new Error(`Schedule ${doc.id} has invalid target`);
|
|
7619
|
+
}
|
|
7620
|
+
const schedule = {
|
|
7621
|
+
id: String(doc.id),
|
|
7622
|
+
target,
|
|
7623
|
+
cron: String(doc.cron),
|
|
7624
|
+
status: String(doc.status),
|
|
7625
|
+
nextFireAt: Number(doc.next_fire_at),
|
|
7626
|
+
createdAt: Number(doc.created_at),
|
|
7627
|
+
updatedAt: Number(doc.updated_at)
|
|
7628
|
+
};
|
|
7629
|
+
if (doc.timezone != null) schedule.timezone = String(doc.timezone);
|
|
7630
|
+
if (doc.last_fire_at != null) schedule.lastFireAt = Number(doc.last_fire_at);
|
|
7631
|
+
if (doc.last_run_id != null) schedule.lastRunId = String(doc.last_run_id);
|
|
7632
|
+
if (doc.metadata != null) schedule.metadata = doc.metadata;
|
|
7633
|
+
if (doc.owner_type != null) schedule.ownerType = String(doc.owner_type);
|
|
7634
|
+
if (doc.owner_id != null) schedule.ownerId = String(doc.owner_id);
|
|
7635
|
+
return schedule;
|
|
7636
|
+
}
|
|
7637
|
+
function triggerToDoc(trigger) {
|
|
7638
|
+
return {
|
|
7639
|
+
id: trigger.id ?? crypto.randomUUID(),
|
|
7640
|
+
schedule_id: trigger.scheduleId,
|
|
7641
|
+
run_id: trigger.runId,
|
|
7642
|
+
scheduled_fire_at: trigger.scheduledFireAt,
|
|
7643
|
+
actual_fire_at: trigger.actualFireAt,
|
|
7644
|
+
outcome: trigger.outcome,
|
|
7645
|
+
error: trigger.error ?? null,
|
|
7646
|
+
trigger_kind: trigger.triggerKind ?? "schedule-fire",
|
|
7647
|
+
parent_trigger_id: trigger.parentTriggerId ?? null,
|
|
7648
|
+
metadata: trigger.metadata ?? null
|
|
7649
|
+
};
|
|
7650
|
+
}
|
|
7651
|
+
function docToTrigger(doc) {
|
|
7652
|
+
const trigger = {
|
|
7653
|
+
id: doc.id != null ? String(doc.id) : void 0,
|
|
7654
|
+
scheduleId: String(doc.schedule_id),
|
|
7655
|
+
runId: doc.run_id != null ? String(doc.run_id) : null,
|
|
7656
|
+
scheduledFireAt: Number(doc.scheduled_fire_at),
|
|
7657
|
+
actualFireAt: Number(doc.actual_fire_at),
|
|
7658
|
+
outcome: String(doc.outcome),
|
|
7659
|
+
triggerKind: doc.trigger_kind != null ? String(doc.trigger_kind) : "schedule-fire"
|
|
7660
|
+
};
|
|
7661
|
+
if (doc.error != null) trigger.error = String(doc.error);
|
|
7662
|
+
if (doc.parent_trigger_id != null) trigger.parentTriggerId = String(doc.parent_trigger_id);
|
|
7663
|
+
if (doc.metadata != null) trigger.metadata = doc.metadata;
|
|
7664
|
+
return trigger;
|
|
7665
|
+
}
|
|
7666
|
+
var SchedulesMongoDB = class _SchedulesMongoDB extends storage.SchedulesStorage {
|
|
7667
|
+
#connector;
|
|
7668
|
+
#skipDefaultIndexes;
|
|
7669
|
+
#indexes;
|
|
7670
|
+
static MANAGED_COLLECTIONS = [storage.TABLE_SCHEDULES, storage.TABLE_SCHEDULE_TRIGGERS];
|
|
7671
|
+
constructor(config) {
|
|
7672
|
+
super();
|
|
7673
|
+
this.#connector = resolveMongoDBConfig(config);
|
|
7674
|
+
this.#skipDefaultIndexes = config.skipDefaultIndexes;
|
|
7675
|
+
this.#indexes = config.indexes?.filter(
|
|
7676
|
+
(idx) => _SchedulesMongoDB.MANAGED_COLLECTIONS.includes(idx.collection)
|
|
7677
|
+
);
|
|
7678
|
+
}
|
|
7679
|
+
getSchedulesCollection() {
|
|
7680
|
+
return this.#connector.getCollection(storage.TABLE_SCHEDULES);
|
|
7681
|
+
}
|
|
7682
|
+
getTriggersCollection() {
|
|
7683
|
+
return this.#connector.getCollection(storage.TABLE_SCHEDULE_TRIGGERS);
|
|
7684
|
+
}
|
|
7685
|
+
getDefaultIndexDefinitions() {
|
|
7686
|
+
return [
|
|
7687
|
+
{ collection: storage.TABLE_SCHEDULES, keys: { id: 1 }, options: { unique: true } },
|
|
7688
|
+
{ collection: storage.TABLE_SCHEDULES, keys: { status: 1, next_fire_at: 1 } },
|
|
7689
|
+
{ collection: storage.TABLE_SCHEDULES, keys: { "target.workflowId": 1 } },
|
|
7690
|
+
{ collection: storage.TABLE_SCHEDULES, keys: { owner_type: 1, owner_id: 1 } },
|
|
7691
|
+
{ collection: storage.TABLE_SCHEDULE_TRIGGERS, keys: { id: 1 }, options: { unique: true } },
|
|
7692
|
+
{ collection: storage.TABLE_SCHEDULE_TRIGGERS, keys: { schedule_id: 1, actual_fire_at: -1 } },
|
|
7693
|
+
{ collection: storage.TABLE_SCHEDULE_TRIGGERS, keys: { parent_trigger_id: 1 } }
|
|
7694
|
+
];
|
|
7695
|
+
}
|
|
7696
|
+
async createDefaultIndexes() {
|
|
7697
|
+
if (this.#skipDefaultIndexes) return;
|
|
7698
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) {
|
|
7699
|
+
try {
|
|
7700
|
+
const collection = await this.#connector.getCollection(indexDef.collection);
|
|
7701
|
+
await collection.createIndex(indexDef.keys, indexDef.options);
|
|
7702
|
+
} catch (error) {
|
|
7703
|
+
this.logger?.warn?.(`Failed to create index on ${indexDef.collection}:`, error);
|
|
7704
|
+
}
|
|
7705
|
+
}
|
|
7706
|
+
}
|
|
7707
|
+
async createCustomIndexes() {
|
|
7708
|
+
if (!this.#indexes || this.#indexes.length === 0) return;
|
|
7709
|
+
for (const indexDef of this.#indexes) {
|
|
7710
|
+
try {
|
|
7711
|
+
const collection = await this.#connector.getCollection(indexDef.collection);
|
|
7712
|
+
await collection.createIndex(indexDef.keys, indexDef.options);
|
|
7713
|
+
} catch (error) {
|
|
7714
|
+
this.logger?.warn?.(`Failed to create custom index on ${indexDef.collection}:`, error);
|
|
7715
|
+
}
|
|
7716
|
+
}
|
|
7717
|
+
}
|
|
7718
|
+
async init() {
|
|
7719
|
+
await this.createDefaultIndexes();
|
|
7720
|
+
await this.createCustomIndexes();
|
|
7721
|
+
}
|
|
7722
|
+
async dangerouslyClearAll() {
|
|
7723
|
+
const triggers = await this.getTriggersCollection();
|
|
7724
|
+
await triggers.deleteMany({});
|
|
7725
|
+
const schedules = await this.getSchedulesCollection();
|
|
7726
|
+
await schedules.deleteMany({});
|
|
7727
|
+
}
|
|
7728
|
+
async createSchedule(schedule) {
|
|
7729
|
+
const collection = await this.getSchedulesCollection();
|
|
7730
|
+
const existing = await collection.findOne({ id: schedule.id });
|
|
7731
|
+
if (existing) {
|
|
7732
|
+
throw new Error(`Schedule with id "${schedule.id}" already exists`);
|
|
7733
|
+
}
|
|
7734
|
+
await collection.insertOne(scheduleToDoc(schedule));
|
|
7735
|
+
return schedule;
|
|
7736
|
+
}
|
|
7737
|
+
async getSchedule(id) {
|
|
7738
|
+
const collection = await this.getSchedulesCollection();
|
|
7739
|
+
const doc = await collection.findOne({ id });
|
|
7740
|
+
return doc ? docToSchedule(doc) : null;
|
|
7741
|
+
}
|
|
7742
|
+
async listSchedules(filter) {
|
|
7743
|
+
const query = {};
|
|
7744
|
+
if (filter?.status) query.status = filter.status;
|
|
7745
|
+
if (filter?.workflowId) query["target.workflowId"] = filter.workflowId;
|
|
7746
|
+
if (filter?.ownerType !== void 0) {
|
|
7747
|
+
query.owner_type = filter.ownerType === null ? null : filter.ownerType;
|
|
7748
|
+
}
|
|
7749
|
+
if (filter?.ownerId !== void 0) {
|
|
7750
|
+
query.owner_id = filter.ownerId === null ? null : filter.ownerId;
|
|
7751
|
+
}
|
|
7752
|
+
const collection = await this.getSchedulesCollection();
|
|
7753
|
+
const docs = await collection.find(query).sort({ created_at: 1 }).toArray();
|
|
7754
|
+
return docs.map(docToSchedule);
|
|
7755
|
+
}
|
|
7756
|
+
async listDueSchedules(now, limit) {
|
|
7757
|
+
const cap = limit ?? 100;
|
|
7758
|
+
const collection = await this.getSchedulesCollection();
|
|
7759
|
+
const docs = await collection.find({ status: "active", next_fire_at: { $lte: now } }).sort({ next_fire_at: 1 }).limit(cap).toArray();
|
|
7760
|
+
return docs.map(docToSchedule);
|
|
7761
|
+
}
|
|
7762
|
+
async updateSchedule(id, patch) {
|
|
7763
|
+
const $set = {};
|
|
7764
|
+
if ("cron" in patch && patch.cron !== void 0) $set.cron = patch.cron;
|
|
7765
|
+
if ("timezone" in patch) $set.timezone = patch.timezone ?? null;
|
|
7766
|
+
if ("status" in patch && patch.status !== void 0) $set.status = patch.status;
|
|
7767
|
+
if ("nextFireAt" in patch && patch.nextFireAt !== void 0) $set.next_fire_at = patch.nextFireAt;
|
|
7768
|
+
if ("target" in patch && patch.target !== void 0) $set.target = patch.target;
|
|
7769
|
+
if ("metadata" in patch) $set.metadata = patch.metadata ?? null;
|
|
7770
|
+
if ("ownerType" in patch) $set.owner_type = patch.ownerType ?? null;
|
|
7771
|
+
if ("ownerId" in patch) $set.owner_id = patch.ownerId ?? null;
|
|
7772
|
+
$set.updated_at = Date.now();
|
|
7773
|
+
const collection = await this.getSchedulesCollection();
|
|
7774
|
+
const result = await collection.findOneAndUpdate({ id }, { $set }, { returnDocument: "after" });
|
|
7775
|
+
if (!result) throw new Error(`Schedule ${id} not found`);
|
|
7776
|
+
return docToSchedule(result);
|
|
7777
|
+
}
|
|
7778
|
+
async updateScheduleNextFire(id, expectedNextFireAt, newNextFireAt, lastFireAt, lastRunId) {
|
|
7779
|
+
const collection = await this.getSchedulesCollection();
|
|
7780
|
+
const result = await collection.updateOne(
|
|
7781
|
+
{ id, next_fire_at: expectedNextFireAt, status: "active" },
|
|
7782
|
+
{
|
|
7783
|
+
$set: {
|
|
7784
|
+
next_fire_at: newNextFireAt,
|
|
7785
|
+
last_fire_at: lastFireAt,
|
|
7786
|
+
last_run_id: lastRunId,
|
|
7787
|
+
updated_at: Date.now()
|
|
7788
|
+
}
|
|
7789
|
+
}
|
|
7790
|
+
);
|
|
7791
|
+
return result.matchedCount > 0;
|
|
7792
|
+
}
|
|
7793
|
+
async deleteSchedule(id) {
|
|
7794
|
+
const triggers = await this.getTriggersCollection();
|
|
7795
|
+
await triggers.deleteMany({ schedule_id: id });
|
|
7796
|
+
const schedules = await this.getSchedulesCollection();
|
|
7797
|
+
await schedules.deleteOne({ id });
|
|
7798
|
+
}
|
|
7799
|
+
async recordTrigger(trigger) {
|
|
7800
|
+
const collection = await this.getTriggersCollection();
|
|
7801
|
+
await collection.insertOne(triggerToDoc(trigger));
|
|
7802
|
+
}
|
|
7803
|
+
async listTriggers(scheduleId, opts) {
|
|
7804
|
+
const query = { schedule_id: scheduleId };
|
|
7805
|
+
if (opts?.fromActualFireAt != null || opts?.toActualFireAt != null) {
|
|
7806
|
+
const range = {};
|
|
7807
|
+
if (opts?.fromActualFireAt != null) range.$gte = opts.fromActualFireAt;
|
|
7808
|
+
if (opts?.toActualFireAt != null) range.$lt = opts.toActualFireAt;
|
|
7809
|
+
query.actual_fire_at = range;
|
|
7810
|
+
}
|
|
7811
|
+
const collection = await this.getTriggersCollection();
|
|
7812
|
+
let cursor = collection.find(query).sort({ actual_fire_at: -1 });
|
|
7813
|
+
if (opts?.limit != null) {
|
|
7814
|
+
cursor = cursor.limit(Math.floor(opts.limit));
|
|
7815
|
+
}
|
|
7816
|
+
const docs = await cursor.toArray();
|
|
7817
|
+
return docs.map(docToTrigger);
|
|
7818
|
+
}
|
|
7819
|
+
};
|
|
7598
7820
|
var SNAPSHOT_FIELDS5 = [
|
|
7599
7821
|
"name",
|
|
7600
7822
|
"description",
|
|
@@ -7726,7 +7948,7 @@ var MongoDBScorerDefinitionsStorage = class _MongoDBScorerDefinitionsStorage ext
|
|
|
7726
7948
|
snapshotConfig[field] = scorerDefinition[field];
|
|
7727
7949
|
}
|
|
7728
7950
|
}
|
|
7729
|
-
const versionId = crypto.randomUUID();
|
|
7951
|
+
const versionId = crypto$1.randomUUID();
|
|
7730
7952
|
await this.createVersion({
|
|
7731
7953
|
id: versionId,
|
|
7732
7954
|
scorerDefinitionId: scorerDefinition.id,
|
|
@@ -8257,7 +8479,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends storage.ScoresSto
|
|
|
8257
8479
|
}
|
|
8258
8480
|
try {
|
|
8259
8481
|
const now = /* @__PURE__ */ new Date();
|
|
8260
|
-
const scoreId = crypto.randomUUID();
|
|
8482
|
+
const scoreId = crypto$1.randomUUID();
|
|
8261
8483
|
const scorer = typeof validatedScore.scorer === "string" ? storage.safelyParseJSON(validatedScore.scorer) : validatedScore.scorer;
|
|
8262
8484
|
const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? storage.safelyParseJSON(validatedScore.preprocessStepResult) : validatedScore.preprocessStepResult;
|
|
8263
8485
|
const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? storage.safelyParseJSON(validatedScore.analyzeStepResult) : validatedScore.analyzeStepResult;
|
|
@@ -8642,7 +8864,7 @@ var MongoDBSkillsStorage = class _MongoDBSkillsStorage extends storage.SkillsSto
|
|
|
8642
8864
|
snapshotConfig[field] = skill[field];
|
|
8643
8865
|
}
|
|
8644
8866
|
}
|
|
8645
|
-
const versionId = crypto.randomUUID();
|
|
8867
|
+
const versionId = crypto$1.randomUUID();
|
|
8646
8868
|
try {
|
|
8647
8869
|
await this.createVersion({
|
|
8648
8870
|
id: versionId,
|
|
@@ -8713,7 +8935,7 @@ var MongoDBSkillsStorage = class _MongoDBSkillsStorage extends storage.SkillsSto
|
|
|
8713
8935
|
}
|
|
8714
8936
|
const existingSnapshot = this.extractSnapshotFields(latestVersion);
|
|
8715
8937
|
await this.createVersion({
|
|
8716
|
-
id: crypto.randomUUID(),
|
|
8938
|
+
id: crypto$1.randomUUID(),
|
|
8717
8939
|
skillId: id,
|
|
8718
8940
|
versionNumber: latestVersion.versionNumber + 1,
|
|
8719
8941
|
...existingSnapshot,
|
|
@@ -9623,7 +9845,7 @@ var MongoDBWorkspacesStorage = class _MongoDBWorkspacesStorage extends storage.W
|
|
|
9623
9845
|
snapshotConfig[field] = workspace[field];
|
|
9624
9846
|
}
|
|
9625
9847
|
}
|
|
9626
|
-
const versionId = crypto.randomUUID();
|
|
9848
|
+
const versionId = crypto$1.randomUUID();
|
|
9627
9849
|
try {
|
|
9628
9850
|
await this.createVersion({
|
|
9629
9851
|
id: versionId,
|
|
@@ -9695,7 +9917,7 @@ var MongoDBWorkspacesStorage = class _MongoDBWorkspacesStorage extends storage.W
|
|
|
9695
9917
|
}
|
|
9696
9918
|
const existingSnapshot = this.extractSnapshotFields(latestVersion);
|
|
9697
9919
|
await this.createVersion({
|
|
9698
|
-
id: crypto.randomUUID(),
|
|
9920
|
+
id: crypto$1.randomUUID(),
|
|
9699
9921
|
workspaceId: id,
|
|
9700
9922
|
versionNumber: latestVersion.versionNumber + 1,
|
|
9701
9923
|
...existingSnapshot,
|
|
@@ -10107,6 +10329,7 @@ var MongoDBStore = class extends storage.MastraCompositeStore {
|
|
|
10107
10329
|
const datasets = new MongoDBDatasetsStorage(domainConfig);
|
|
10108
10330
|
const experiments = new MongoDBExperimentsStorage(domainConfig);
|
|
10109
10331
|
const backgroundTasks = new BackgroundTasksStorageMongoDB(domainConfig);
|
|
10332
|
+
const schedules = new SchedulesMongoDB(domainConfig);
|
|
10110
10333
|
this.stores = {
|
|
10111
10334
|
memory,
|
|
10112
10335
|
scores,
|
|
@@ -10122,7 +10345,8 @@ var MongoDBStore = class extends storage.MastraCompositeStore {
|
|
|
10122
10345
|
blobs,
|
|
10123
10346
|
backgroundTasks,
|
|
10124
10347
|
datasets,
|
|
10125
|
-
experiments
|
|
10348
|
+
experiments,
|
|
10349
|
+
schedules
|
|
10126
10350
|
};
|
|
10127
10351
|
}
|
|
10128
10352
|
/**
|
|
@@ -10257,6 +10481,7 @@ exports.MongoDBStore = MongoDBStore;
|
|
|
10257
10481
|
exports.MongoDBVector = MongoDBVector;
|
|
10258
10482
|
exports.MongoDBWorkspacesStorage = MongoDBWorkspacesStorage;
|
|
10259
10483
|
exports.ObservabilityMongoDB = ObservabilityMongoDB;
|
|
10484
|
+
exports.SchedulesMongoDB = SchedulesMongoDB;
|
|
10260
10485
|
exports.ScoresStorageMongoDB = ScoresStorageMongoDB;
|
|
10261
10486
|
exports.WorkflowsStorageMongoDB = WorkflowsStorageMongoDB;
|
|
10262
10487
|
//# sourceMappingURL=index.cjs.map
|