@mastra/mongodb 1.18.2 → 1.18.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 +18 -0
- package/LICENSE.md +6 -4
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +2 -0
- package/dist/docs/references/docs-memory-working-memory.md +2 -0
- package/dist/docs/references/docs-storage.md +2 -0
- package/dist/docs/references/integrations-databases-mongodb.md +2 -0
- package/dist/docs/references/reference-rag-retrieval.md +2 -0
- package/dist/docs/references/reference-rag-vector-databases.md +2 -0
- package/dist/docs/references/reference-storage-composite.md +2 -0
- package/dist/docs/references/reference-vectors-mongodb.md +2 -0
- package/dist/index.cjs +40 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +41 -6
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
- package/package.json +5 -5
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, KnowledgeConflictError, KnowledgeNotFoundError, KnowledgeStorage, 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_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_CURSORS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, 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, assertKnowledgeCeilingRaised, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, safelyParseJSON, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
3
|
+
import { AgentsStorage, BackgroundTasksStorage, BlobStore, DatasetsStorage, ExperimentsStorage, KnowledgeConflictError, KnowledgeNotFoundError, KnowledgeStorage, 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_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_CURSORS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, 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, assertKnowledgeCeilingRaised, assertKnowledgeDescriptionWithinBound, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, createVectorErrorId, ensureDate, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, parseDuration, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, 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.18.
|
|
12
|
+
var version = "1.18.3";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/vector/filter.ts
|
|
15
15
|
/**
|
|
@@ -4376,6 +4376,7 @@ function nodeFromDocument(row) {
|
|
|
4376
4376
|
name: String(row.name),
|
|
4377
4377
|
kind: String(row.kind),
|
|
4378
4378
|
content: row.content == null ? void 0 : String(row.content),
|
|
4379
|
+
description: row.description == null ? void 0 : String(row.description),
|
|
4379
4380
|
scope: cloneScope(row.scope),
|
|
4380
4381
|
version: Number(row.version),
|
|
4381
4382
|
mergedInto: row.mergedInto ?? void 0,
|
|
@@ -4483,6 +4484,7 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends KnowledgeStorage {
|
|
|
4483
4484
|
});
|
|
4484
4485
|
}
|
|
4485
4486
|
async createNode(input) {
|
|
4487
|
+
assertKnowledgeDescriptionWithinBound(input.description);
|
|
4486
4488
|
const scope = canonicalizeKnowledgeScope(input.scope);
|
|
4487
4489
|
return this.#connector.withTransaction(async (session) => {
|
|
4488
4490
|
const existing = await this.#getNodeByName(input.name, scope, session);
|
|
@@ -4498,6 +4500,7 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends KnowledgeStorage {
|
|
|
4498
4500
|
name: input.name.trim(),
|
|
4499
4501
|
kind: input.kind,
|
|
4500
4502
|
content: input.content,
|
|
4503
|
+
description: input.description,
|
|
4501
4504
|
scope,
|
|
4502
4505
|
version: 1,
|
|
4503
4506
|
createdAt: now,
|
|
@@ -4559,6 +4562,7 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends KnowledgeStorage {
|
|
|
4559
4562
|
}).limit(input.limit ?? 100).toArray()).map(nodeFromDocument);
|
|
4560
4563
|
}
|
|
4561
4564
|
async updateNode(input) {
|
|
4565
|
+
assertKnowledgeDescriptionWithinBound(input.description);
|
|
4562
4566
|
return this.#connector.withTransaction(async (session) => {
|
|
4563
4567
|
const existing = await this.#getNode(input.id, session);
|
|
4564
4568
|
if (!existing) throw new KnowledgeNotFoundError("node", input.id);
|
|
@@ -4566,6 +4570,7 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends KnowledgeStorage {
|
|
|
4566
4570
|
const scope = input.scope ? canonicalizeKnowledgeScope(input.scope) : existing.scope;
|
|
4567
4571
|
const name = input.name?.trim() ?? existing.name;
|
|
4568
4572
|
const content = input.content ?? existing.content;
|
|
4573
|
+
const description = input.description ?? existing.description;
|
|
4569
4574
|
const now = /* @__PURE__ */ new Date();
|
|
4570
4575
|
const result = await (await this.#nodes()).findOneAndUpdate({
|
|
4571
4576
|
id: input.id,
|
|
@@ -4577,6 +4582,7 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends KnowledgeStorage {
|
|
|
4577
4582
|
canonicalName: canonicalName(name),
|
|
4578
4583
|
kind: input.kind ?? existing.kind,
|
|
4579
4584
|
content: content ?? null,
|
|
4585
|
+
description: description ?? null,
|
|
4580
4586
|
scope,
|
|
4581
4587
|
scopeKey: knowledgeScopeKey(scope),
|
|
4582
4588
|
updatedAt: now
|
|
@@ -4640,10 +4646,34 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends KnowledgeStorage {
|
|
|
4640
4646
|
}, sessionOptions(session)))?.scope;
|
|
4641
4647
|
if (scope) await this.#outbox(mention.sourceType, mention.sourceId, "upsert", createKnowledgeUlid(), scope, session);
|
|
4642
4648
|
}
|
|
4649
|
+
let mergedTarget = target;
|
|
4650
|
+
if (target.description === void 0 && source.description) {
|
|
4651
|
+
const adoptedAt = /* @__PURE__ */ new Date();
|
|
4652
|
+
if ((await (await this.#nodes()).updateOne({
|
|
4653
|
+
id: target.id,
|
|
4654
|
+
type: "node",
|
|
4655
|
+
version: target.version,
|
|
4656
|
+
description: null
|
|
4657
|
+
}, {
|
|
4658
|
+
$set: {
|
|
4659
|
+
description: source.description,
|
|
4660
|
+
updatedAt: adoptedAt
|
|
4661
|
+
},
|
|
4662
|
+
$inc: { version: 1 }
|
|
4663
|
+
}, sessionOptions(session))).modifiedCount > 0) {
|
|
4664
|
+
mergedTarget = {
|
|
4665
|
+
...target,
|
|
4666
|
+
description: source.description,
|
|
4667
|
+
version: target.version + 1,
|
|
4668
|
+
updatedAt: adoptedAt
|
|
4669
|
+
};
|
|
4670
|
+
await this.#activity("node-updated", "node", target.id, target.scope, void 0, session);
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4643
4673
|
await this.#activity("node-merged", "node", source.id, source.scope, void 0, session);
|
|
4644
4674
|
await this.#outbox("node", source.id, "delete", input.sourceVersion + 1, source.scope, session);
|
|
4645
|
-
await this.#outbox("node", target.id, "upsert", createKnowledgeUlid(),
|
|
4646
|
-
return
|
|
4675
|
+
await this.#outbox("node", target.id, "upsert", createKnowledgeUlid(), mergedTarget.scope, session);
|
|
4676
|
+
return mergedTarget;
|
|
4647
4677
|
});
|
|
4648
4678
|
}
|
|
4649
4679
|
async appendKnowledge(input) {
|
|
@@ -4793,14 +4823,19 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends KnowledgeStorage {
|
|
|
4793
4823
|
$or: [
|
|
4794
4824
|
{ name: regex },
|
|
4795
4825
|
{ kind: regex },
|
|
4796
|
-
{ content: regex }
|
|
4826
|
+
{ content: regex },
|
|
4827
|
+
{ description: regex }
|
|
4797
4828
|
]
|
|
4798
4829
|
}).sort({ updatedAt: -1 }).limit(limit).toArray()).map((row) => ({
|
|
4799
4830
|
type: "node",
|
|
4800
4831
|
id: row.id,
|
|
4801
4832
|
recordId: row.id,
|
|
4802
4833
|
name: row.name,
|
|
4803
|
-
text:
|
|
4834
|
+
text: [
|
|
4835
|
+
row.name,
|
|
4836
|
+
...row.description ? [row.description] : [],
|
|
4837
|
+
...row.content ? [row.content] : []
|
|
4838
|
+
].join("\n"),
|
|
4804
4839
|
scope: cloneScope(row.scope)
|
|
4805
4840
|
}));
|
|
4806
4841
|
if (results.length < limit) {
|