@mastra/mongodb 1.26.0-alpha.1 → 1.26.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.
@@ -318,6 +318,7 @@ export interface KnowledgePagesCore {
318
318
  MAX_KNOWLEDGE_MOVE_PAGES: number;
319
319
  MAX_KNOWLEDGE_PAGE_DEPTH: number;
320
320
  MAX_KNOWLEDGE_PAGE_LIST_LIMIT: number;
321
+ MAX_KNOWLEDGE_PAGE_LINKS: number;
321
322
  KnowledgeMoveTooLargeError: new (pageId: string, pages: number) => Error;
322
323
  KnowledgePageDepthError: new (pageId: string) => Error;
323
324
  KnowledgePageHasChildrenError: new (pageId: string) => Error;
@@ -325,15 +326,19 @@ export interface KnowledgePagesCore {
325
326
  }
326
327
  /** Loads core's page-store runtime once, after checking core advertises `knowledge-pages`. */
327
328
  export declare function createKnowledgePagesCoreLoader(features: ReadonlySet<string>, loadStorageModule: () => Promise<unknown>): () => Promise<KnowledgePagesCore>;
329
+ /** Most words one keyword search uses; every word adds a substring check per page in each store. */
330
+ export declare const KNOWLEDGE_SEARCH_MAX_WORDS = 16;
328
331
  /**
329
- * Keyword-search words: the query split on whitespace, lowercased, deduplicated. A hit needs at
330
- * least one of them (as a case-insensitive substring); an empty list means the search returns nothing.
332
+ * Keyword-search words: the query split on whitespace, lowercased, deduplicated, keeping the first
333
+ * {@link KNOWLEDGE_SEARCH_MAX_WORDS}. A hit needs at least one of them (as a case-insensitive
334
+ * substring); an empty list means the search returns nothing.
331
335
  */
332
336
  export declare function knowledgeSearchWords(query: string): string[];
333
337
  /**
334
338
  * Points one matched search word earns on a page, by the best field it appears in: name, then
335
- * description, then body. Pages rank by how many query words they match first; these points only
336
- * break ties between pages that match the same number of words.
339
+ * description, then body. A page whose name contains the whole query ranks first; below that, pages
340
+ * rank by how many query words they match, and these points only break ties between pages that
341
+ * match the same number of words.
337
342
  */
338
343
  export declare const KNOWLEDGE_SEARCH_WEIGHTS: {
339
344
  readonly name: 3;
@@ -3,7 +3,7 @@ name: mastra-mongodb
3
3
  description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mongodb"
6
- version: "1.26.0-alpha.1"
6
+ version: "1.26.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.26.0-alpha.1",
2
+ "version": "1.26.0-alpha.2",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -11,7 +11,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
11
11
  let _mastra_core_evals = require("@mastra/core/evals");
12
12
  let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
13
13
  // package.json
14
- var version = "1.26.0-alpha.1";
14
+ var version = "1.26.0-alpha.2";
15
15
  // src/vector/filter.ts
16
16
  /**
17
17
  * Translator for MongoDB filter queries.
@@ -4875,7 +4875,8 @@ const KNOWLEDGE_PAGES_CORE_FUNCTIONS = [
4875
4875
  const KNOWLEDGE_PAGES_CORE_NUMBERS = [
4876
4876
  "MAX_KNOWLEDGE_MOVE_PAGES",
4877
4877
  "MAX_KNOWLEDGE_PAGE_DEPTH",
4878
- "MAX_KNOWLEDGE_PAGE_LIST_LIMIT"
4878
+ "MAX_KNOWLEDGE_PAGE_LIST_LIMIT",
4879
+ "MAX_KNOWLEDGE_PAGE_LINKS"
4879
4880
  ];
4880
4881
  function resolveKnowledgePagesCore(storageModule) {
4881
4882
  const module = typeof storageModule === "object" && storageModule !== null ? storageModule : {};
@@ -4896,16 +4897,18 @@ function createKnowledgePagesCoreLoader(features, loadStorageModule) {
4896
4897
  };
4897
4898
  }
4898
4899
  /**
4899
- * Keyword-search words: the query split on whitespace, lowercased, deduplicated. A hit needs at
4900
- * least one of them (as a case-insensitive substring); an empty list means the search returns nothing.
4900
+ * Keyword-search words: the query split on whitespace, lowercased, deduplicated, keeping the first
4901
+ * {@link KNOWLEDGE_SEARCH_MAX_WORDS}. A hit needs at least one of them (as a case-insensitive
4902
+ * substring); an empty list means the search returns nothing.
4901
4903
  */
4902
4904
  function knowledgeSearchWords(query) {
4903
- return [...new Set(query.toLowerCase().split(/\s+/).filter(Boolean))];
4905
+ return [...new Set(query.toLowerCase().split(/\s+/).filter(Boolean))].slice(0, 16);
4904
4906
  }
4905
4907
  /**
4906
4908
  * Points one matched search word earns on a page, by the best field it appears in: name, then
4907
- * description, then body. Pages rank by how many query words they match first; these points only
4908
- * break ties between pages that match the same number of words.
4909
+ * description, then body. A page whose name contains the whole query ranks first; below that, pages
4910
+ * rank by how many query words they match, and these points only break ties between pages that
4911
+ * match the same number of words.
4909
4912
  */
4910
4913
  const KNOWLEDGE_SEARCH_WEIGHTS = {
4911
4914
  name: 3,
@@ -4924,11 +4927,13 @@ function knowledgePageKeyProblem(key) {
4924
4927
  const loadPagesCore = createKnowledgePagesCoreLoader(_mastra_core_features.coreFeatures, () => import("@mastra/core/storage"));
4925
4928
  const DEFAULT_LIST_LIMIT = 50;
4926
4929
  const MONGO_DUPLICATE_KEY = 11e3;
4930
+ const DEFAULT_LINK_LIMIT = 1e3;
4927
4931
  const MONGO_KNOWLEDGE_PAGES_COLLECTIONS = {
4928
4932
  pages: "mastra_knowledge_pages",
4929
4933
  notes: "mastra_knowledge_notes",
4930
4934
  pins: "mastra_knowledge_pins",
4931
4935
  activity: "mastra_knowledge_activity",
4936
+ links: "mastra_knowledge_page_links",
4932
4937
  state: "mastra_knowledge_access_state"
4933
4938
  };
4934
4939
  /** Thrown when existing Knowledge collections can't be used as schema 4 without a reset. */
@@ -5024,10 +5029,17 @@ function toListedPin(row) {
5024
5029
  pageName: String(row.pageName)
5025
5030
  };
5026
5031
  }
5032
+ /** IndexNotFound, or NamespaceNotFound when the collection doesn't exist yet. */
5033
+ function isMissingIndex(error) {
5034
+ const code = error?.code;
5035
+ return code === 27 || code === 26;
5036
+ }
5027
5037
  function toPin(row) {
5028
5038
  return {
5029
5039
  id: String(row.id),
5030
5040
  pageId: String(row.pageId),
5041
+ kind: row.kind ?? "page",
5042
+ ...row.depth == null ? {} : { depth: Number(row.depth) },
5031
5043
  audience: [...row.audience ?? []],
5032
5044
  createdBy: String(row.createdBy),
5033
5045
  createdAt: new Date(row.createdAt),
@@ -5090,12 +5102,17 @@ var MongoKnowledgePages = class {
5090
5102
  } }, { upsert: true });
5091
5103
  const inspection = await this.inspectSchema();
5092
5104
  if (inspection.status === "incompatible-reset-required") throw new MongoKnowledgeResetRequiredError(inspection);
5093
- const [pages, notes, pins, activity] = await Promise.all([
5105
+ const [pages, notes, pins, activity, links] = await Promise.all([
5094
5106
  this.#c("pages"),
5095
5107
  this.#c("notes"),
5096
5108
  this.#c("pins"),
5097
- this.#c("activity")
5109
+ this.#c("activity"),
5110
+ this.#c("links")
5098
5111
  ]);
5112
+ await pins.updateMany({ kind: { $exists: false } }, { $set: { kind: "page" } });
5113
+ await pins.dropIndex("pageId_1").catch((error) => {
5114
+ if (!isMissingIndex(error)) throw error;
5115
+ });
5099
5116
  await Promise.all([
5100
5117
  pages.createIndex({ id: 1 }, { unique: true }),
5101
5118
  pages.createIndex({ address: 1 }, {
@@ -5135,7 +5152,10 @@ var MongoKnowledgePages = class {
5135
5152
  notes.createIndex({ pageScopeId: 1 }),
5136
5153
  notes.createIndex({ stampScopeIds: 1 }),
5137
5154
  pins.createIndex({ id: 1 }, { unique: true }),
5138
- pins.createIndex({ pageId: 1 }, { unique: true }),
5155
+ pins.createIndex({
5156
+ pageId: 1,
5157
+ kind: 1
5158
+ }, { unique: true }),
5139
5159
  pins.createIndex({ audience: 1 }),
5140
5160
  activity.createIndex({ id: 1 }, { unique: true }),
5141
5161
  activity.createIndex({
@@ -5147,12 +5167,19 @@ var MongoKnowledgePages = class {
5147
5167
  pageId: 1,
5148
5168
  createdAt: -1,
5149
5169
  id: -1
5150
- })
5170
+ }),
5171
+ links.createIndex({
5172
+ fromPageId: 1,
5173
+ ref: 1
5174
+ }, { unique: true }),
5175
+ links.createIndex({ toPageId: 1 }),
5176
+ links.createIndex({ ref: 1 })
5151
5177
  ]);
5152
5178
  }
5153
5179
  /** Drops exactly the Knowledge collections (never Memory's) and recreates schema 4. */
5154
5180
  async reset() {
5155
5181
  for (const name of KNOWLEDGE_RESETTABLE_TABLE_NAMES) await this.#drop(name);
5182
+ await this.#drop(MONGO_KNOWLEDGE_PAGES_COLLECTIONS.links);
5156
5183
  await this.init();
5157
5184
  }
5158
5185
  /** The ids of every scope page the read scope can see; `null` means everything. */
@@ -5545,10 +5572,12 @@ var MongoKnowledgePages = class {
5545
5572
  async listChildScopes(input) {
5546
5573
  const core = await loadPagesCore();
5547
5574
  const limit = clampLimit(input.limit, core.MAX_KNOWLEDGE_PAGE_LIST_LIMIT);
5575
+ const readable = input.read ? await this.#readable(input.read) : null;
5548
5576
  const filter = {
5549
5577
  isScope: true,
5550
5578
  parentId: input.parentId,
5551
- ...live
5579
+ ...live,
5580
+ ...this.#inScopes("id", readable)
5552
5581
  };
5553
5582
  if (input.cursor) {
5554
5583
  const [position, id] = decodeCursor(input.cursor);
@@ -5930,12 +5959,20 @@ var MongoKnowledgePages = class {
5930
5959
  } }] } } }], { session });
5931
5960
  await this.#refreshMentionScopes([target.id, ...tree.ids], session);
5932
5961
  const pins = await this.#c("pins");
5933
- const sourcePin = await pins.findOne({ pageId: source.id }, {
5962
+ const sourcePins = await pins.find({ pageId: source.id }, {
5934
5963
  ...noProjection,
5935
5964
  session
5936
- });
5937
- if (sourcePin) {
5938
- await this.#upsertPinAudience(session, target.id, sourcePin.audience ?? [], String(sourcePin.createdBy), now);
5965
+ }).sort({ kind: 1 }).toArray();
5966
+ for (const sourcePin of sourcePins) {
5967
+ await this.#upsertPinAudience(session, {
5968
+ pageId: target.id,
5969
+ kind: sourcePin.kind ?? "page",
5970
+ depth: sourcePin.depth == null ? null : Number(sourcePin.depth),
5971
+ audience: sourcePin.audience ?? [],
5972
+ createdBy: String(sourcePin.createdBy),
5973
+ now,
5974
+ keepDepth: true
5975
+ });
5939
5976
  await pins.deleteOne({ id: sourcePin.id }, { session });
5940
5977
  }
5941
5978
  await (await this.#c("activity")).updateMany({ pageId: source.id }, { $set: { pageScopeId: target.scopeId } }, { session });
@@ -6028,6 +6065,23 @@ var MongoKnowledgePages = class {
6028
6065
  }).limit(limit + 1).toArray();
6029
6066
  return this.#noteOutput(rows, limit);
6030
6067
  }
6068
+ async countChildScopes(input) {
6069
+ const ids = [...new Set(input.parentIds)];
6070
+ const counts = Object.fromEntries(ids.map((id) => [id, 0]));
6071
+ if (!ids.length) return counts;
6072
+ const readable = await this.#readable(input.read);
6073
+ const rows = await (await this.#c("pages")).aggregate([{ $match: {
6074
+ parentId: { $in: ids },
6075
+ isScope: true,
6076
+ ...live,
6077
+ ...this.#inScopes("id", readable)
6078
+ } }, { $group: {
6079
+ _id: "$parentId",
6080
+ count: { $sum: 1 }
6081
+ } }]).toArray();
6082
+ for (const row of rows) counts[row._id] = row.count;
6083
+ return counts;
6084
+ }
6031
6085
  async countChildPages(input) {
6032
6086
  const ids = [...new Set(input.parentIds)];
6033
6087
  const counts = Object.fromEntries(ids.map((id) => [id, 0]));
@@ -6045,6 +6099,117 @@ var MongoKnowledgePages = class {
6045
6099
  for (const row of rows) counts[row._id] = row.count;
6046
6100
  return counts;
6047
6101
  }
6102
+ async replacePageBodyLinks(input) {
6103
+ await this.#tx(async (session) => {
6104
+ const links = await this.#c("links");
6105
+ await links.deleteMany({ fromPageId: input.pageId }, { session });
6106
+ if (!input.links.length) return;
6107
+ await links.insertMany(input.links.map((link) => ({
6108
+ fromPageId: input.pageId,
6109
+ ref: link.ref,
6110
+ toPageId: link.toPageId,
6111
+ count: link.count
6112
+ })), { session });
6113
+ });
6114
+ }
6115
+ async listPageBodyLinkSources(input) {
6116
+ const any = [];
6117
+ if (input.refs?.length) any.push({
6118
+ toPageId: null,
6119
+ ref: { $in: input.refs }
6120
+ });
6121
+ if (input.toPageIds?.length) any.push({ toPageId: { $in: input.toPageIds } });
6122
+ if (!any.length) return [];
6123
+ return (await (await this.#c("links")).distinct("fromPageId", { $or: any })).map(String);
6124
+ }
6125
+ /** Resolved links touching `pageIds`, both ends live and readable, notes only through visible notes. */
6126
+ async #visibleLinks(pageIds, read, direction, kinds) {
6127
+ const ids = [...new Set(pageIds)];
6128
+ if (!ids.length) return [];
6129
+ const wanted = new Set(kinds ?? ["body", "note"]);
6130
+ const touching = (from, to) => direction !== "in" && ids.includes(from) || direction !== "out" && !!to && ids.includes(to);
6131
+ const readable = await this.#readable(read);
6132
+ const raw = /* @__PURE__ */ new Map();
6133
+ const add = (fromPageId, toPageId, kind, count) => {
6134
+ if (fromPageId === toPageId) return;
6135
+ const key = `${fromPageId}\u0000${toPageId}\u0000${kind}`;
6136
+ const edge = raw.get(key);
6137
+ if (edge) edge.count += count;
6138
+ else raw.set(key, {
6139
+ fromPageId,
6140
+ toPageId,
6141
+ kind,
6142
+ count
6143
+ });
6144
+ };
6145
+ const side = [];
6146
+ if (direction !== "in") side.push({ fromPageId: { $in: ids } });
6147
+ if (direction !== "out") side.push({ toPageId: { $in: ids } });
6148
+ if (wanted.has("body")) {
6149
+ const rows = await (await this.#c("links")).find({
6150
+ toPageId: { $ne: null },
6151
+ $or: side
6152
+ }, { projection: {
6153
+ _id: 0,
6154
+ fromPageId: 1,
6155
+ toPageId: 1,
6156
+ count: 1
6157
+ } }).toArray();
6158
+ for (const row of rows) if (touching(String(row.fromPageId), String(row.toPageId))) add(String(row.fromPageId), String(row.toPageId), "body", Number(row.count));
6159
+ }
6160
+ if (wanted.has("note")) {
6161
+ const noteSide = [];
6162
+ if (direction !== "in") noteSide.push({ pageId: { $in: ids } });
6163
+ if (direction !== "out") noteSide.push({ mentions: { $in: ids } });
6164
+ const rows = await (await this.#c("notes")).find({
6165
+ ...live,
6166
+ ...this.#visibleNotes(readable),
6167
+ mentions: {
6168
+ $exists: true,
6169
+ $ne: []
6170
+ },
6171
+ $or: noteSide
6172
+ }, { projection: {
6173
+ _id: 0,
6174
+ pageId: 1,
6175
+ mentions: 1
6176
+ } }).toArray();
6177
+ for (const row of rows) for (const mentioned of new Set(row.mentions ?? [])) if (touching(String(row.pageId), mentioned)) add(String(row.pageId), mentioned, "note", 1);
6178
+ }
6179
+ if (!raw.size) return [];
6180
+ const ends = [...new Set([...raw.values()].flatMap((edge) => [edge.fromPageId, edge.toPageId]))];
6181
+ const visible = new Set((await (await this.#c("pages")).find({
6182
+ id: { $in: ends },
6183
+ ...live,
6184
+ ...this.#inScopes("scopeId", readable)
6185
+ }, { projection: {
6186
+ _id: 0,
6187
+ id: 1
6188
+ } }).toArray()).map((row) => String(row.id)));
6189
+ return [...raw.values()].filter((edge) => visible.has(edge.fromPageId) && visible.has(edge.toPageId));
6190
+ }
6191
+ async countPageLinks(input) {
6192
+ const linked = new Map(input.pageIds.map((id) => [id, {
6193
+ in: /* @__PURE__ */ new Set(),
6194
+ out: /* @__PURE__ */ new Set()
6195
+ }]));
6196
+ for (const edge of await this.#visibleLinks(input.pageIds, input.read, "both", input.kinds)) {
6197
+ linked.get(edge.fromPageId)?.out.add(edge.toPageId);
6198
+ linked.get(edge.toPageId)?.in.add(edge.fromPageId);
6199
+ }
6200
+ return Object.fromEntries([...linked].map(([id, sets]) => [id, {
6201
+ in: sets.in.size,
6202
+ out: sets.out.size
6203
+ }]));
6204
+ }
6205
+ async listPageLinks(input) {
6206
+ const limit = input.limit ?? DEFAULT_LINK_LIMIT;
6207
+ if (!Number.isInteger(limit) || limit < 1) throw new RangeError("Knowledge link limit must be a positive integer");
6208
+ const core = await loadPagesCore();
6209
+ const kindOrder = (kind) => kind === "body" ? 0 : 1;
6210
+ const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
6211
+ return (await this.#visibleLinks(input.pageIds, input.read, input.direction ?? "both", input.kinds)).sort((a, b) => compare(a.fromPageId, b.fromPageId) || compare(a.toPageId, b.toPageId) || kindOrder(a.kind) - kindOrder(b.kind)).slice(0, Math.min(limit, core.MAX_KNOWLEDGE_PAGE_LINKS));
6212
+ }
6048
6213
  async countNotes(input) {
6049
6214
  const ids = [...new Set(input.pageIds)];
6050
6215
  const counts = Object.fromEntries(ids.map((id) => [id, 0]));
@@ -6225,7 +6390,7 @@ var MongoKnowledgePages = class {
6225
6390
  async removeNote(input) {
6226
6391
  return this.#tx(async (session) => {
6227
6392
  const note = await this.#requireNote(input.id, session);
6228
- if (note.deletedAt) return toNote(note);
6393
+ if (note.deletedAt) throw new _mastra_core_storage.KnowledgeNotFoundError("note", input.id);
6229
6394
  const now = /* @__PURE__ */ new Date();
6230
6395
  const updated = await (await this.#c("notes")).findOneAndUpdate({ id: input.id }, {
6231
6396
  $set: {
@@ -6479,15 +6644,24 @@ var MongoKnowledgePages = class {
6479
6644
  "activity",
6480
6645
  "pins",
6481
6646
  "notes",
6647
+ "links",
6482
6648
  "pages"
6483
6649
  ]) await (await this.#c(name)).deleteMany({}, { session });
6484
6650
  });
6485
6651
  }
6486
6652
  async addPinAudience(input) {
6653
+ const kind = input.kind ?? "page";
6487
6654
  return this.#tx(async (session) => {
6488
6655
  const page = await this.#requireLivePage(input.pageId, session);
6489
6656
  const now = /* @__PURE__ */ new Date();
6490
- const { pin, changed } = await this.#upsertPinAudience(session, page.id, input.audience, input.createdBy, now);
6657
+ const { pin, changed } = await this.#upsertPinAudience(session, {
6658
+ pageId: page.id,
6659
+ kind,
6660
+ depth: kind === "list" ? input.depth ?? 1 : null,
6661
+ audience: input.audience,
6662
+ createdBy: input.createdBy,
6663
+ now
6664
+ });
6491
6665
  if (changed) await this.#log(session, {
6492
6666
  action: "pin-added",
6493
6667
  scopeId: page.scopeId,
@@ -6498,9 +6672,14 @@ var MongoKnowledgePages = class {
6498
6672
  return pin;
6499
6673
  });
6500
6674
  }
6501
- async #upsertPinAudience(session, pageId, audience, createdBy, now) {
6675
+ /** `keepDepth` (merges) leaves an existing pin's depth as it is instead of setting `depth`. */
6676
+ async #upsertPinAudience(session, input) {
6677
+ const { pageId, kind, audience, now } = input;
6502
6678
  const pins = await this.#c("pins");
6503
- const existing = await pins.findOne({ pageId }, {
6679
+ const existing = await pins.findOne({
6680
+ pageId,
6681
+ kind
6682
+ }, {
6504
6683
  ...noProjection,
6505
6684
  session
6506
6685
  });
@@ -6508,8 +6687,10 @@ var MongoKnowledgePages = class {
6508
6687
  const doc = {
6509
6688
  id: (0, _mastra_core_storage.createKnowledgeUlid)(),
6510
6689
  pageId,
6690
+ kind,
6691
+ ...input.depth === null ? {} : { depth: input.depth },
6511
6692
  audience: [...new Set(audience)],
6512
- createdBy,
6693
+ createdBy: input.createdBy,
6513
6694
  createdAt: now,
6514
6695
  updatedAt: now
6515
6696
  };
@@ -6526,13 +6707,22 @@ var MongoKnowledgePages = class {
6526
6707
  }
6527
6708
  const current = existing.audience ?? [];
6528
6709
  const merged = [.../* @__PURE__ */ new Set([...current, ...audience])];
6529
- if (merged.length === current.length) return {
6710
+ const currentDepth = existing.depth == null ? null : Number(existing.depth);
6711
+ const depth = input.keepDepth ? currentDepth : input.depth;
6712
+ if (merged.length === current.length && depth === currentDepth) return {
6530
6713
  pin: toPin(existing),
6531
6714
  changed: false
6532
6715
  };
6533
6716
  return {
6534
- pin: toPin(await pins.findOneAndUpdate({ id: existing.id }, { $set: {
6717
+ pin: toPin(await pins.findOneAndUpdate({ id: existing.id }, depth === null ? {
6718
+ $set: {
6719
+ audience: merged,
6720
+ updatedAt: now
6721
+ },
6722
+ $unset: { depth: "" }
6723
+ } : { $set: {
6535
6724
  audience: merged,
6725
+ depth,
6536
6726
  updatedAt: now
6537
6727
  } }, {
6538
6728
  returnDocument: "after",
@@ -6545,7 +6735,10 @@ var MongoKnowledgePages = class {
6545
6735
  async removePinAudience(input) {
6546
6736
  return this.#tx(async (session) => {
6547
6737
  const pins = await this.#c("pins");
6548
- const existing = await pins.findOne({ pageId: input.pageId }, {
6738
+ const existing = await pins.findOne({
6739
+ pageId: input.pageId,
6740
+ kind: input.kind ?? "page"
6741
+ }, {
6549
6742
  ...noProjection,
6550
6743
  session
6551
6744
  });
@@ -6605,10 +6798,11 @@ var MongoKnowledgePages = class {
6605
6798
  const ids = await this.#readable(input.read);
6606
6799
  const match = {};
6607
6800
  if (input.audience !== "all") match.audience = { $in: input.audience };
6608
- const pageId = {};
6609
- if (input.pageIds) pageId.$in = input.pageIds;
6610
- if (input.excludePageIds?.length) pageId.$nin = input.excludePageIds;
6611
- if (Object.keys(pageId).length) match.pageId = pageId;
6801
+ if (input.kind) match.kind = input.kind;
6802
+ if (input.pageIds) match.pageId = { $in: input.pageIds };
6803
+ const pageOnly = [];
6804
+ if (input.excludePageIds?.length) pageOnly.push({ $or: [{ kind: { $ne: "page" } }, { pageId: { $nin: input.excludePageIds } }] });
6805
+ if (input.withBody) pageOnly.push({ $or: [{ kind: { $ne: "page" } }, { "page.body": { $regex: "\\S" } }] });
6612
6806
  const pins = await this.#c("pins");
6613
6807
  const base = [
6614
6808
  { $match: match },
@@ -6621,7 +6815,7 @@ var MongoKnowledgePages = class {
6621
6815
  { $match: {
6622
6816
  "page.deletedAt": { $exists: false },
6623
6817
  ...ids === null ? {} : { "page.scopeId": { $in: ids } },
6624
- ...input.withBody ? { "page.body": { $regex: "\\S" } } : {}
6818
+ ...pageOnly.length ? { $and: pageOnly } : {}
6625
6819
  } }
6626
6820
  ];
6627
6821
  const pageMatch = [];
@@ -6687,7 +6881,8 @@ var KnowledgeMongoDB = class extends _mastra_core_storage.KnowledgeStorage {
6687
6881
  ...super.getCapabilities(),
6688
6882
  schemaVersion: 4,
6689
6883
  supportsSchemaInspection: true,
6690
- supportsExplicitReset: true
6884
+ supportsExplicitReset: true,
6885
+ supportsPinKinds: true
6691
6886
  };
6692
6887
  }
6693
6888
  async init() {
@@ -6717,6 +6912,9 @@ var KnowledgeMongoDB = class extends _mastra_core_storage.KnowledgeStorage {
6717
6912
  listChildScopes(input) {
6718
6913
  return this.#pages.listChildScopes(input);
6719
6914
  }
6915
+ countChildScopes(input) {
6916
+ return this.#pages.countChildScopes(input);
6917
+ }
6720
6918
  getPages(input) {
6721
6919
  return this.#pages.getPages(input);
6722
6920
  }
@@ -6756,6 +6954,18 @@ var KnowledgeMongoDB = class extends _mastra_core_storage.KnowledgeStorage {
6756
6954
  listNotes(input) {
6757
6955
  return this.#pages.listNotes(input);
6758
6956
  }
6957
+ replacePageBodyLinks(input) {
6958
+ return this.#pages.replacePageBodyLinks(input);
6959
+ }
6960
+ listPageBodyLinkSources(input) {
6961
+ return this.#pages.listPageBodyLinkSources(input);
6962
+ }
6963
+ countPageLinks(input) {
6964
+ return this.#pages.countPageLinks(input);
6965
+ }
6966
+ listPageLinks(input) {
6967
+ return this.#pages.listPageLinks(input);
6968
+ }
6759
6969
  countChildPages(input) {
6760
6970
  return this.#pages.countChildPages(input);
6761
6971
  }