@mastra/mongodb 1.16.0-alpha.1 → 1.16.0-alpha.2
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 +44 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-vectors-mongodb.md +13 -13
- package/dist/index.cjs +140 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +141 -4
- package/dist/index.js.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 +4 -4
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v4 } from "@lukeed/uuid";
|
|
2
2
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
3
|
-
import { AgentsStorage, BackgroundTasksStorage, BlobStore, DatasetsStorage, ExperimentsStorage, MCPClientsStorage, MCPServersStorage, MastraCompositeStore, MemoryStorage, NotificationsStorage, ObservabilityStorage, PromptBlocksStorage, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_NOTIFICATIONS, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TraceStatus, WorkflowsStorage, WorkspacesStorage, calculatePagination, createStorageErrorId, createVectorErrorId, ensureDate, hasErrorCode, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, parseDuration, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
3
|
+
import { AgentsStorage, BackgroundTasksStorage, BlobStore, DatasetsStorage, ExperimentsStorage, MCPClientsStorage, MCPServersStorage, MastraCompositeStore, MemoryStorage, NotificationsStorage, ObservabilityStorage, PromptBlocksStorage, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_NOTIFICATIONS, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TraceStatus, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, calculatePagination, createStorageErrorId, createVectorErrorId, ensureDate, hasErrorCode, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, parseDuration, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
4
4
|
import { MastraVector, validateUpsertInput, validateVectorValues } from "@mastra/core/vector";
|
|
5
5
|
import { MongoBulkWriteError, MongoClient, ObjectId } from "mongodb";
|
|
6
6
|
import { BaseFilterTranslator } from "@mastra/core/vector/filter";
|
|
@@ -9,7 +9,7 @@ import { MessageList } from "@mastra/core/agent";
|
|
|
9
9
|
import { saveScorePayloadSchema } from "@mastra/core/evals";
|
|
10
10
|
import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "1.16.0-alpha.
|
|
12
|
+
var version = "1.16.0-alpha.2";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/vector/filter.ts
|
|
15
15
|
/**
|
|
@@ -9935,6 +9935,141 @@ var MongoDBSkillsStorage = class MongoDBSkillsStorage extends SkillsStorage {
|
|
|
9935
9935
|
}
|
|
9936
9936
|
};
|
|
9937
9937
|
//#endregion
|
|
9938
|
+
//#region src/storage/domains/workflow-definitions/index.ts
|
|
9939
|
+
function docToDefinition(doc) {
|
|
9940
|
+
const def = {
|
|
9941
|
+
id: String(doc.id),
|
|
9942
|
+
inputSchema: doc.inputSchema,
|
|
9943
|
+
outputSchema: doc.outputSchema,
|
|
9944
|
+
graph: doc.graph,
|
|
9945
|
+
status: doc.status,
|
|
9946
|
+
source: doc.source,
|
|
9947
|
+
createdAt: doc.createdAt instanceof Date ? doc.createdAt : new Date(doc.createdAt),
|
|
9948
|
+
updatedAt: doc.updatedAt instanceof Date ? doc.updatedAt : new Date(doc.updatedAt)
|
|
9949
|
+
};
|
|
9950
|
+
if (doc.description != null) def.description = doc.description;
|
|
9951
|
+
if (doc.metadata != null) def.metadata = doc.metadata;
|
|
9952
|
+
if (doc.stateSchema != null) def.stateSchema = doc.stateSchema;
|
|
9953
|
+
if (doc.requestContextSchema != null) def.requestContextSchema = doc.requestContextSchema;
|
|
9954
|
+
if (doc.authorId != null) def.authorId = doc.authorId;
|
|
9955
|
+
return def;
|
|
9956
|
+
}
|
|
9957
|
+
var MongoDBWorkflowDefinitionsStore = class MongoDBWorkflowDefinitionsStore extends WorkflowDefinitionsStorage {
|
|
9958
|
+
#connector;
|
|
9959
|
+
#skipDefaultIndexes;
|
|
9960
|
+
#indexes;
|
|
9961
|
+
static MANAGED_COLLECTIONS = [TABLE_WORKFLOW_DEFINITIONS];
|
|
9962
|
+
constructor(config) {
|
|
9963
|
+
super();
|
|
9964
|
+
this.#connector = resolveMongoDBConfig(config);
|
|
9965
|
+
this.#skipDefaultIndexes = config.skipDefaultIndexes;
|
|
9966
|
+
this.#indexes = config.indexes?.filter((idx) => MongoDBWorkflowDefinitionsStore.MANAGED_COLLECTIONS.includes(idx.collection));
|
|
9967
|
+
}
|
|
9968
|
+
async getCollection(name) {
|
|
9969
|
+
return this.#connector.getCollection(name);
|
|
9970
|
+
}
|
|
9971
|
+
getDefaultIndexDefinitions() {
|
|
9972
|
+
return [{
|
|
9973
|
+
collection: TABLE_WORKFLOW_DEFINITIONS,
|
|
9974
|
+
keys: { id: 1 },
|
|
9975
|
+
options: { unique: true }
|
|
9976
|
+
}, {
|
|
9977
|
+
collection: TABLE_WORKFLOW_DEFINITIONS,
|
|
9978
|
+
keys: { status: 1 }
|
|
9979
|
+
}];
|
|
9980
|
+
}
|
|
9981
|
+
async createDefaultIndexes() {
|
|
9982
|
+
if (this.#skipDefaultIndexes) return;
|
|
9983
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) try {
|
|
9984
|
+
await (await this.getCollection(indexDef.collection)).createIndex(indexDef.keys, indexDef.options);
|
|
9985
|
+
} catch (error) {
|
|
9986
|
+
this.logger?.warn?.(`Failed to create index on ${indexDef.collection}:`, error);
|
|
9987
|
+
}
|
|
9988
|
+
}
|
|
9989
|
+
async createCustomIndexes() {
|
|
9990
|
+
if (!this.#indexes || this.#indexes.length === 0) return;
|
|
9991
|
+
for (const indexDef of this.#indexes) try {
|
|
9992
|
+
await (await this.getCollection(indexDef.collection)).createIndex(indexDef.keys, indexDef.options);
|
|
9993
|
+
} catch (error) {
|
|
9994
|
+
this.logger?.warn?.(`Failed to create custom index on ${indexDef.collection}:`, error);
|
|
9995
|
+
}
|
|
9996
|
+
}
|
|
9997
|
+
async init() {
|
|
9998
|
+
await this.createDefaultIndexes();
|
|
9999
|
+
await this.createCustomIndexes();
|
|
10000
|
+
}
|
|
10001
|
+
async dangerouslyClearAll() {
|
|
10002
|
+
await (await this.getCollection(TABLE_WORKFLOW_DEFINITIONS)).deleteMany({});
|
|
10003
|
+
}
|
|
10004
|
+
async upsert(input) {
|
|
10005
|
+
const now = /* @__PURE__ */ new Date();
|
|
10006
|
+
const collection = await this.getCollection(TABLE_WORKFLOW_DEFINITIONS);
|
|
10007
|
+
if (!await collection.findOne({ id: input.id })) {
|
|
10008
|
+
if (!("inputSchema" in input) || input.inputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": inputSchema is required.`);
|
|
10009
|
+
if (!("outputSchema" in input) || input.outputSchema === void 0) throw new Error(`Cannot create workflow definition "${input.id}": outputSchema is required.`);
|
|
10010
|
+
if (!("graph" in input) || input.graph === void 0) throw new Error(`Cannot create workflow definition "${input.id}": graph is required.`);
|
|
10011
|
+
const doc = {
|
|
10012
|
+
id: input.id,
|
|
10013
|
+
description: input.description ?? null,
|
|
10014
|
+
metadata: input.metadata ?? null,
|
|
10015
|
+
inputSchema: input.inputSchema,
|
|
10016
|
+
outputSchema: input.outputSchema,
|
|
10017
|
+
stateSchema: input.stateSchema ?? null,
|
|
10018
|
+
requestContextSchema: input.requestContextSchema ?? null,
|
|
10019
|
+
graph: input.graph,
|
|
10020
|
+
status: "active",
|
|
10021
|
+
source: "storage",
|
|
10022
|
+
authorId: "authorId" in input ? input.authorId ?? null : null,
|
|
10023
|
+
createdAt: now,
|
|
10024
|
+
updatedAt: now
|
|
10025
|
+
};
|
|
10026
|
+
try {
|
|
10027
|
+
await collection.insertOne(doc);
|
|
10028
|
+
} catch (error) {
|
|
10029
|
+
if (!(error?.code === 11e3) || !await collection.findOne({ id: input.id })) throw error;
|
|
10030
|
+
return this.applyUpdate(input, now);
|
|
10031
|
+
}
|
|
10032
|
+
return docToDefinition(doc);
|
|
10033
|
+
}
|
|
10034
|
+
return this.applyUpdate(input, now);
|
|
10035
|
+
}
|
|
10036
|
+
async applyUpdate(input, now) {
|
|
10037
|
+
const collection = await this.getCollection(TABLE_WORKFLOW_DEFINITIONS);
|
|
10038
|
+
const update = { updatedAt: now };
|
|
10039
|
+
if ("description" in input && input.description !== void 0) update.description = input.description;
|
|
10040
|
+
if ("metadata" in input && input.metadata !== void 0) update.metadata = input.metadata;
|
|
10041
|
+
if ("inputSchema" in input && input.inputSchema !== void 0) update.inputSchema = input.inputSchema;
|
|
10042
|
+
if ("outputSchema" in input && input.outputSchema !== void 0) update.outputSchema = input.outputSchema;
|
|
10043
|
+
if ("stateSchema" in input && input.stateSchema !== void 0) update.stateSchema = input.stateSchema;
|
|
10044
|
+
if ("requestContextSchema" in input && input.requestContextSchema !== void 0) update.requestContextSchema = input.requestContextSchema;
|
|
10045
|
+
if ("graph" in input && input.graph !== void 0) update.graph = input.graph;
|
|
10046
|
+
if ("status" in input && input.status !== void 0) update.status = input.status;
|
|
10047
|
+
if ("authorId" in input && input.authorId !== void 0) update.authorId = input.authorId;
|
|
10048
|
+
await collection.updateOne({ id: input.id }, { $set: update });
|
|
10049
|
+
const updated = await collection.findOne({ id: input.id });
|
|
10050
|
+
if (!updated) throw new Error(`Failed to update workflow definition "${input.id}".`);
|
|
10051
|
+
return docToDefinition(updated);
|
|
10052
|
+
}
|
|
10053
|
+
async get(id) {
|
|
10054
|
+
const doc = await (await this.getCollection(TABLE_WORKFLOW_DEFINITIONS)).findOne({ id });
|
|
10055
|
+
return doc ? docToDefinition(doc) : null;
|
|
10056
|
+
}
|
|
10057
|
+
async list(args) {
|
|
10058
|
+
const collection = await this.getCollection(TABLE_WORKFLOW_DEFINITIONS);
|
|
10059
|
+
const filter = {};
|
|
10060
|
+
if (args?.status) filter.status = args.status;
|
|
10061
|
+
if (args?.authorId !== void 0) filter.authorId = args.authorId;
|
|
10062
|
+
const definitions = (await collection.find(filter).sort({ updatedAt: -1 }).toArray()).map(docToDefinition);
|
|
10063
|
+
return {
|
|
10064
|
+
definitions,
|
|
10065
|
+
total: definitions.length
|
|
10066
|
+
};
|
|
10067
|
+
}
|
|
10068
|
+
async delete(id) {
|
|
10069
|
+
await (await this.getCollection(TABLE_WORKFLOW_DEFINITIONS)).deleteOne({ id });
|
|
10070
|
+
}
|
|
10071
|
+
};
|
|
10072
|
+
//#endregion
|
|
9938
10073
|
//#region src/storage/domains/workflows/index.ts
|
|
9939
10074
|
var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends WorkflowsStorage {
|
|
9940
10075
|
#connector;
|
|
@@ -10823,6 +10958,7 @@ var MongoDBStore = class extends MastraCompositeStore {
|
|
|
10823
10958
|
const experiments = new MongoDBExperimentsStorage(domainConfig);
|
|
10824
10959
|
const backgroundTasks = new BackgroundTasksStorageMongoDB(domainConfig);
|
|
10825
10960
|
const schedules = new SchedulesMongoDB(domainConfig);
|
|
10961
|
+
const workflowDefinitions = new MongoDBWorkflowDefinitionsStore(domainConfig);
|
|
10826
10962
|
this.stores = {
|
|
10827
10963
|
memory,
|
|
10828
10964
|
notifications,
|
|
@@ -10840,7 +10976,8 @@ var MongoDBStore = class extends MastraCompositeStore {
|
|
|
10840
10976
|
backgroundTasks,
|
|
10841
10977
|
datasets,
|
|
10842
10978
|
experiments,
|
|
10843
|
-
schedules
|
|
10979
|
+
schedules,
|
|
10980
|
+
workflowDefinitions
|
|
10844
10981
|
};
|
|
10845
10982
|
}
|
|
10846
10983
|
/**
|
|
@@ -10960,6 +11097,6 @@ Example Complex Query:
|
|
|
10960
11097
|
]
|
|
10961
11098
|
}`;
|
|
10962
11099
|
//#endregion
|
|
10963
|
-
export { BackgroundTasksStorageMongoDB, MONGODB_PROMPT, MemoryStorageMongoDB, MongoDBAgentsStorage, MongoDBBlobStore, MongoDBDatasetsStorage, MongoDBExperimentsStorage, MongoDBMCPClientsStorage, MongoDBMCPServersStorage, MongoDBPromptBlocksStorage, MongoDBScorerDefinitionsStorage, MongoDBSkillsStorage, MongoDBStore, MongoDBVector, MongoDBWorkspacesStorage, NotificationsMongoDB, ObservabilityMongoDB, SchedulesMongoDB, ScoresStorageMongoDB, WorkflowsStorageMongoDB };
|
|
11100
|
+
export { BackgroundTasksStorageMongoDB, MONGODB_PROMPT, MemoryStorageMongoDB, MongoDBAgentsStorage, MongoDBBlobStore, MongoDBDatasetsStorage, MongoDBExperimentsStorage, MongoDBMCPClientsStorage, MongoDBMCPServersStorage, MongoDBPromptBlocksStorage, MongoDBScorerDefinitionsStorage, MongoDBSkillsStorage, MongoDBStore, MongoDBVector, MongoDBWorkflowDefinitionsStore, MongoDBWorkspacesStorage, NotificationsMongoDB, ObservabilityMongoDB, SchedulesMongoDB, ScoresStorageMongoDB, WorkflowsStorageMongoDB };
|
|
10964
11101
|
|
|
10965
11102
|
//# sourceMappingURL=index.js.map
|