@mastra/mongodb 1.22.1-alpha.0 → 1.23.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 +1 -1
- package/dist/docs/references/reference-storage-retention.md +21 -18
- package/dist/index.cjs +56 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -65
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/knowledge/index.d.ts +12 -8
- package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/docs/SKILL.md
CHANGED
|
@@ -95,29 +95,32 @@ Set the `retention` field on the store config.
|
|
|
95
95
|
|
|
96
96
|
Each domain specifies its age-prunable tables and the timestamp column that anchors comparison, chosen so `maxAge` matches the meaning of the data. Append-only logs use creation time, live state uses last activity, and jobs or runs use completion time so in-flight work isn't pruned.
|
|
97
97
|
|
|
98
|
-
| Domain | Table key | Anchor column | `maxAge` measures
|
|
99
|
-
| ----------------- | ------------------ | ---------------- |
|
|
100
|
-
| `memory` | `threads` | `createdAt` | Thread age
|
|
101
|
-
| `memory` | `messages` | `createdAt` | Message age
|
|
102
|
-
| `memory` | `resources` | `createdAt` | Resource age
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `observability` | `
|
|
106
|
-
| `observability` | `
|
|
107
|
-
| `observability` | `
|
|
108
|
-
| `observability` | `
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
98
|
+
| Domain | Table key | Anchor column | `maxAge` measures |
|
|
99
|
+
| ----------------- | ------------------ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
100
|
+
| `memory` | `threads` | `createdAt` | Thread age |
|
|
101
|
+
| `memory` | `messages` | `createdAt` | Message age |
|
|
102
|
+
| `memory` | `resources` | `createdAt` | Resource age |
|
|
103
|
+
| `memory` | `runFences` | `retiredAt` | Time since the durable agent execution holding the fence settled. Fences of running executions (`NULL`) are never pruned |
|
|
104
|
+
| `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
|
|
105
|
+
| `observability` | `spans` | `startedAt` | Span age |
|
|
106
|
+
| `observability` | `metrics` | `timestamp` | Metric event age (vNext only) |
|
|
107
|
+
| `observability` | `logs` | `timestamp` | Log event age (vNext only) |
|
|
108
|
+
| `observability` | `scores` | `timestamp` | Score event age (vNext only) |
|
|
109
|
+
| `observability` | `feedback` | `timestamp` | Feedback event age (vNext only) |
|
|
110
|
+
| `scores` | `scorers` | `createdAt` | Score record age |
|
|
111
|
+
| `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
|
|
112
|
+
| `workflows` | `runOwnership` | `updatedAt` | Inactivity. A running durable agent execution renews its claim every 10 seconds, so keep `maxAge` well above its 30-second lease |
|
|
113
|
+
| `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
|
|
114
|
+
| `experiments` | `experiments` | `completedAt` | Time since completion, running experiments are never pruned |
|
|
115
|
+
| `notifications` | `notifications` | `createdAt` | Notification age |
|
|
116
|
+
| `harness` | `sessions` | `createdAt` | Session record age |
|
|
117
|
+
| `schedules` | `triggers` | `actual_fire_at` | Fire-history age (epoch-ms column) |
|
|
116
118
|
|
|
117
119
|
> **Note:**
|
|
118
120
|
>
|
|
119
121
|
> - The memory `observational_memory` table has no timestamp anchor, so it can't be age-pruned and isn't a valid retention key.
|
|
120
122
|
> - Experiments prune as whole units: an aged experiment's result rows are deleted together with it (results cascade with their parent), so a run is never left partially deleted. Retention doesn't have a separate `results` key.
|
|
123
|
+
> - `runOwnership` and `runFences` hold the run fencing records of durable agents, one small record per run in each. If the `runOwnership` `maxAge` is too short, a running execution can lose its run, but an execution that lost a run still can't write. A fence is retired only when its execution settles, so the fence of a run that crashed and was never recovered is never pruned.
|
|
121
124
|
> - For `schedules`, the growth table is the fire history (`schedule_triggers`, one row per fire): schedule definitions are config and aren't pruned.
|
|
122
125
|
> - On PostgreSQL, timestamp anchors use the timezone-aware mirror columns (for example `createdAtZ`, `completedAtZ`).
|
|
123
126
|
> - DuckDB observability stores append-only events for all five signals. Its `spans` policy uses the event `timestamp` column rather than `startedAt`.
|
package/dist/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
|
|
|
9
9
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
10
10
|
let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "1.
|
|
12
|
+
var version = "1.23.0";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/vector/filter.ts
|
|
15
15
|
/**
|
|
@@ -4764,13 +4764,26 @@ async function assertKnowledgeDescriptionWithinBoundCompat(description) {
|
|
|
4764
4764
|
}
|
|
4765
4765
|
assertWithinBound(description);
|
|
4766
4766
|
}
|
|
4767
|
+
let assertRecordTextWithinBound;
|
|
4768
|
+
async function assertKnowledgeRecordTextWithinBoundCompat(text) {
|
|
4769
|
+
if (!assertRecordTextWithinBound) assertRecordTextWithinBound = (await import("@mastra/core/storage")).assertKnowledgeRecordTextWithinBound ?? ((value) => {
|
|
4770
|
+
if (value.length > 1e3) throw new Error("Knowledge record text exceeds the 1000 UTF-16 code unit limit; split it into separate facts or summarize it");
|
|
4771
|
+
});
|
|
4772
|
+
assertRecordTextWithinBound(text);
|
|
4773
|
+
}
|
|
4767
4774
|
const cloneScope = (scope) => [...scope];
|
|
4768
4775
|
const canonicalName = (name) => name.trim().toLocaleLowerCase();
|
|
4769
4776
|
const nodeReferenceId = (node) => typeof node === "string" ? node : node.id;
|
|
4770
4777
|
const sessionOptions = (session) => session ? { session } : {};
|
|
4771
4778
|
function visibleScopeKeys(scope) {
|
|
4772
4779
|
const canonical = (0, _mastra_core_storage.canonicalizeKnowledgeScope)(scope);
|
|
4773
|
-
|
|
4780
|
+
const subsets = [[]];
|
|
4781
|
+
for (const entry of canonical) subsets.push(...subsets.map((subset) => [...subset, entry]));
|
|
4782
|
+
const keys = /* @__PURE__ */ new Set();
|
|
4783
|
+
for (const subset of subsets.slice(1)) try {
|
|
4784
|
+
keys.add((0, _mastra_core_storage.knowledgeScopeKey)(subset));
|
|
4785
|
+
} catch {}
|
|
4786
|
+
return [...keys];
|
|
4774
4787
|
}
|
|
4775
4788
|
function recordCursorFilter(cursor, expected) {
|
|
4776
4789
|
const parsed = (0, _mastra_core_storage.parseKnowledgeNodeCursor)(cursor, expected);
|
|
@@ -4806,7 +4819,6 @@ function recordFromDocument(row) {
|
|
|
4806
4819
|
sourceThreadId: String(row.sourceThreadId),
|
|
4807
4820
|
capturedAt: new Date(row.capturedAt),
|
|
4808
4821
|
when: row.when ? new Date(row.when) : void 0,
|
|
4809
|
-
maxScope: row.maxScope ?? void 0,
|
|
4810
4822
|
metadata: row.metadata ?? void 0,
|
|
4811
4823
|
deletedAt: row.deletedAt ? new Date(row.deletedAt) : void 0,
|
|
4812
4824
|
deletedBy: row.deletedBy ?? void 0
|
|
@@ -4829,12 +4841,12 @@ function outboxFromDocument(row) {
|
|
|
4829
4841
|
completedAt: row.completedAt ? new Date(row.completedAt) : void 0
|
|
4830
4842
|
};
|
|
4831
4843
|
}
|
|
4844
|
+
const KNOWLEDGE_CURATION_CURSOR_REMOVED_MESSAGE = "Knowledge curation cursors were removed: observation-time curate is the only Knowledge writer and needs no cursor.";
|
|
4832
4845
|
var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.KnowledgeStorage {
|
|
4833
4846
|
static MANAGED_COLLECTIONS = [
|
|
4834
4847
|
_mastra_core_storage.TABLE_KNOWLEDGE_NODES,
|
|
4835
4848
|
_mastra_core_storage.TABLE_KNOWLEDGE_RECORDS,
|
|
4836
4849
|
_mastra_core_storage.TABLE_KNOWLEDGE_MENTIONS,
|
|
4837
|
-
_mastra_core_storage.TABLE_KNOWLEDGE_CURSORS,
|
|
4838
4850
|
_mastra_core_storage.TABLE_KNOWLEDGE_ACTIVITY,
|
|
4839
4851
|
_mastra_core_storage.TABLE_KNOWLEDGE_SEMANTIC_OUTBOX
|
|
4840
4852
|
];
|
|
@@ -4847,7 +4859,6 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
4847
4859
|
const nodes = await this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_NODES);
|
|
4848
4860
|
const knowledge = await this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_RECORDS);
|
|
4849
4861
|
const mentions = await this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_MENTIONS);
|
|
4850
|
-
const cursors = await this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_CURSORS);
|
|
4851
4862
|
const activity = await this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_ACTIVITY);
|
|
4852
4863
|
const outbox = await this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_SEMANTIC_OUTBOX);
|
|
4853
4864
|
await Promise.all([
|
|
@@ -4860,6 +4871,10 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
4860
4871
|
scopeKey: 1,
|
|
4861
4872
|
type: 1
|
|
4862
4873
|
}),
|
|
4874
|
+
nodes.createIndex({
|
|
4875
|
+
type: 1,
|
|
4876
|
+
canonicalName: 1
|
|
4877
|
+
}),
|
|
4863
4878
|
knowledge.createIndex({
|
|
4864
4879
|
node: 1,
|
|
4865
4880
|
id: -1
|
|
@@ -4868,6 +4883,10 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
4868
4883
|
sourceThreadId: 1,
|
|
4869
4884
|
id: -1
|
|
4870
4885
|
}),
|
|
4886
|
+
knowledge.createIndex({
|
|
4887
|
+
scopeKey: 1,
|
|
4888
|
+
id: -1
|
|
4889
|
+
}),
|
|
4871
4890
|
mentions.createIndex({
|
|
4872
4891
|
sourceType: 1,
|
|
4873
4892
|
sourceId: 1,
|
|
@@ -4878,11 +4897,11 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
4878
4897
|
sourceType: 1,
|
|
4879
4898
|
sourceId: 1
|
|
4880
4899
|
}),
|
|
4881
|
-
cursors.createIndex({
|
|
4882
|
-
sourceThreadId: 1,
|
|
4883
|
-
agent: 1
|
|
4884
|
-
}, { unique: true }),
|
|
4885
4900
|
activity.createIndex({ id: -1 }),
|
|
4901
|
+
activity.createIndex({
|
|
4902
|
+
scopeKey: 1,
|
|
4903
|
+
id: -1
|
|
4904
|
+
}),
|
|
4886
4905
|
outbox.createIndex({ idempotencyKey: 1 }, { unique: true }),
|
|
4887
4906
|
outbox.createIndex({
|
|
4888
4907
|
status: 1,
|
|
@@ -4898,6 +4917,11 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
4898
4917
|
}
|
|
4899
4918
|
async createNode(input) {
|
|
4900
4919
|
await assertKnowledgeDescriptionWithinBoundCompat(input.description);
|
|
4920
|
+
if (input.scopeAddresses?.length) {
|
|
4921
|
+
const error = /* @__PURE__ */ new Error("This Knowledge storage adapter does not expose structural scope placement.");
|
|
4922
|
+
error.name = "KnowledgeUnsupportedCapabilityError";
|
|
4923
|
+
throw error;
|
|
4924
|
+
}
|
|
4901
4925
|
const scope = (0, _mastra_core_storage.canonicalizeKnowledgeScope)(input.scope);
|
|
4902
4926
|
return this.#connector.withTransaction(async (session) => {
|
|
4903
4927
|
const existing = await this.#getNodeByName(input.name, scope, session);
|
|
@@ -5090,9 +5114,9 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
5090
5114
|
});
|
|
5091
5115
|
}
|
|
5092
5116
|
async appendKnowledge(input) {
|
|
5117
|
+
await assertKnowledgeRecordTextWithinBoundCompat(input.text);
|
|
5093
5118
|
const scope = (0, _mastra_core_storage.canonicalizeKnowledgeScope)(input.scope);
|
|
5094
5119
|
const defaultScope = (0, _mastra_core_storage.canonicalizeKnowledgeScope)(input.defaultScope);
|
|
5095
|
-
(0, _mastra_core_storage.assertKnowledgeScopeWithinCeiling)(scope, input.maxScope);
|
|
5096
5120
|
return this.#connector.withTransaction(async (session) => {
|
|
5097
5121
|
const parent = await this.#resolveTerminalNode(nodeReferenceId(input.node), session);
|
|
5098
5122
|
if (!parent) throw new _mastra_core_storage.KnowledgeNotFoundError("node", nodeReferenceId(input.node));
|
|
@@ -5107,14 +5131,12 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
5107
5131
|
sourceThreadId: input.sourceThreadId,
|
|
5108
5132
|
capturedAt: /* @__PURE__ */ new Date(),
|
|
5109
5133
|
when: input.when,
|
|
5110
|
-
maxScope: input.maxScope,
|
|
5111
5134
|
metadata: input.metadata
|
|
5112
5135
|
};
|
|
5113
5136
|
await (await this.#knowledge()).insertOne({
|
|
5114
5137
|
...record,
|
|
5115
5138
|
scopeKey: (0, _mastra_core_storage.knowledgeScopeKey)(scope),
|
|
5116
5139
|
when: record.when ?? null,
|
|
5117
|
-
maxScope: record.maxScope ?? null,
|
|
5118
5140
|
deletedAt: null,
|
|
5119
5141
|
deletedBy: null
|
|
5120
5142
|
}, sessionOptions(session));
|
|
@@ -5199,7 +5221,6 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
5199
5221
|
return this.#connector.withTransaction(async (session) => {
|
|
5200
5222
|
const record = await this.#getKnowledge(input.id, true, session);
|
|
5201
5223
|
if (!record) throw new _mastra_core_storage.KnowledgeNotFoundError("record", input.id);
|
|
5202
|
-
(0, _mastra_core_storage.assertKnowledgeScopeWithinCeiling)(scope, record.maxScope);
|
|
5203
5224
|
await (await this.#knowledge()).updateOne({ id: input.id }, { $set: {
|
|
5204
5225
|
scope,
|
|
5205
5226
|
scopeKey: (0, _mastra_core_storage.knowledgeScopeKey)(scope)
|
|
@@ -5213,17 +5234,6 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
5213
5234
|
};
|
|
5214
5235
|
});
|
|
5215
5236
|
}
|
|
5216
|
-
async raiseKnowledgeCeiling(input) {
|
|
5217
|
-
const record = await this.#getKnowledge(input.id, true);
|
|
5218
|
-
if (!record) throw new _mastra_core_storage.KnowledgeNotFoundError("record", input.id);
|
|
5219
|
-
(0, _mastra_core_storage.assertKnowledgeScopeWithinCeiling)(record.scope, input.maxScope);
|
|
5220
|
-
(0, _mastra_core_storage.assertKnowledgeCeilingRaised)(record.maxScope, input.maxScope);
|
|
5221
|
-
await (await this.#knowledge()).updateOne({ id: input.id }, { $set: { maxScope: input.maxScope ?? null } });
|
|
5222
|
-
return {
|
|
5223
|
-
...record,
|
|
5224
|
-
maxScope: input.maxScope
|
|
5225
|
-
};
|
|
5226
|
-
}
|
|
5227
5237
|
async search(input) {
|
|
5228
5238
|
const scope = (0, _mastra_core_storage.canonicalizeKnowledgeScope)(input.scope);
|
|
5229
5239
|
const query = input.query.trim();
|
|
@@ -5263,7 +5273,7 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
5263
5273
|
results.push({
|
|
5264
5274
|
type: "record",
|
|
5265
5275
|
id: record.id,
|
|
5266
|
-
recordId: record.node,
|
|
5276
|
+
recordId: parentVisible ? record.node : record.id,
|
|
5267
5277
|
name: parentVisible ? parent.name : "(private node)",
|
|
5268
5278
|
text: record.text,
|
|
5269
5279
|
scope: cloneScope(record.scope)
|
|
@@ -5272,36 +5282,19 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
5272
5282
|
}
|
|
5273
5283
|
return results.slice(0, limit);
|
|
5274
5284
|
}
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
}, {
|
|
5289
|
-
$max: { lastKnowledgeId: input.lastKnowledgeId },
|
|
5290
|
-
$set: { updatedAt: /* @__PURE__ */ new Date() },
|
|
5291
|
-
$setOnInsert: {
|
|
5292
|
-
sourceThreadId: input.sourceThreadId,
|
|
5293
|
-
agent: input.agent
|
|
5294
|
-
}
|
|
5295
|
-
}, {
|
|
5296
|
-
upsert: true,
|
|
5297
|
-
returnDocument: "after"
|
|
5298
|
-
});
|
|
5299
|
-
return {
|
|
5300
|
-
sourceThreadId: row.sourceThreadId,
|
|
5301
|
-
agent: row.agent,
|
|
5302
|
-
lastKnowledgeId: row.lastKnowledgeId,
|
|
5303
|
-
updatedAt: new Date(row.updatedAt)
|
|
5304
|
-
};
|
|
5285
|
+
/**
|
|
5286
|
+
* @deprecated Curation cursors were removed. Observation-time curate is the only Knowledge writer and needs no
|
|
5287
|
+
* cursor. Always throws.
|
|
5288
|
+
*/
|
|
5289
|
+
async getCurationCursor(_input) {
|
|
5290
|
+
throw new Error(KNOWLEDGE_CURATION_CURSOR_REMOVED_MESSAGE);
|
|
5291
|
+
}
|
|
5292
|
+
/**
|
|
5293
|
+
* @deprecated Curation cursors were removed. Observation-time curate is the only Knowledge writer and needs no
|
|
5294
|
+
* cursor. Always throws.
|
|
5295
|
+
*/
|
|
5296
|
+
async advanceCurationCursor(_input) {
|
|
5297
|
+
throw new Error(KNOWLEDGE_CURATION_CURSOR_REMOVED_MESSAGE);
|
|
5305
5298
|
}
|
|
5306
5299
|
async listActivity(input) {
|
|
5307
5300
|
const scope = (0, _mastra_core_storage.canonicalizeKnowledgeScope)(input.scope);
|
|
@@ -5422,9 +5415,6 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
5422
5415
|
#mentions() {
|
|
5423
5416
|
return this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_MENTIONS);
|
|
5424
5417
|
}
|
|
5425
|
-
#cursors() {
|
|
5426
|
-
return this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_CURSORS);
|
|
5427
|
-
}
|
|
5428
5418
|
#activityCollection() {
|
|
5429
5419
|
return this.#collection(_mastra_core_storage.TABLE_KNOWLEDGE_ACTIVITY);
|
|
5430
5420
|
}
|
|
@@ -5447,12 +5437,14 @@ var KnowledgeMongoDB = class KnowledgeMongoDB extends _mastra_core_storage.Knowl
|
|
|
5447
5437
|
return row ? nodeFromDocument(row) : null;
|
|
5448
5438
|
}
|
|
5449
5439
|
async #resolveNode(name, scope, session) {
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5440
|
+
const candidates = (await (await this.#nodes()).find({
|
|
5441
|
+
type: "node",
|
|
5442
|
+
canonicalName: canonicalName(name),
|
|
5443
|
+
$or: [{ scopeKey: { $in: visibleScopeKeys(scope) } }, { mergedInto: { $ne: null } }]
|
|
5444
|
+
}, sessionOptions(session)).toArray()).map(nodeFromDocument).sort((left, right) => right.scope.length - left.scope.length);
|
|
5445
|
+
for (const candidate of candidates) {
|
|
5446
|
+
const terminal = await this.#resolveTerminalNode(candidate.id, session);
|
|
5447
|
+
if (terminal && (0, _mastra_core_storage.isKnowledgeScopeVisible)(terminal.scope, scope)) return terminal;
|
|
5456
5448
|
}
|
|
5457
5449
|
return null;
|
|
5458
5450
|
}
|