@mastra/mongodb 1.26.0-alpha.0 → 1.26.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/dist/_types/{@internal_core → @internal_core@0.1.4}/dist/knowledge-compat/index.d.ts +12 -2
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +103 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +103 -29
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/knowledge/index.d.ts +2 -1
- package/dist/storage/domains/knowledge/index.d.ts.map +1 -1
- package/dist/storage/domains/knowledge/pages.d.ts +5 -1
- package/dist/storage/domains/knowledge/pages.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -1
- package/package.json +5 -5
- /package/dist/_types/{@internal_core → @internal_core@0.1.4}/dist/memory/index.d.ts +0 -0
- /package/dist/_types/{@internal_core → @internal_core@0.1.4}/package.json +0 -0
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { MessageList } from "@mastra/core/agent";
|
|
|
10
10
|
import { saveScorePayloadSchema } from "@mastra/core/evals";
|
|
11
11
|
import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
|
|
12
12
|
// package.json
|
|
13
|
-
var version = "1.26.0-alpha.
|
|
13
|
+
var version = "1.26.0-alpha.1";
|
|
14
14
|
// src/vector/filter.ts
|
|
15
15
|
/**
|
|
16
16
|
* Translator for MongoDB filter queries.
|
|
@@ -1729,6 +1729,7 @@ const SNAPSHOT_FIELDS$6 = [
|
|
|
1729
1729
|
"description",
|
|
1730
1730
|
"instructions",
|
|
1731
1731
|
"model",
|
|
1732
|
+
"modelList",
|
|
1732
1733
|
"tools",
|
|
1733
1734
|
"defaultOptions",
|
|
1734
1735
|
"workflows",
|
|
@@ -4894,13 +4895,23 @@ function createKnowledgePagesCoreLoader(features, loadStorageModule) {
|
|
|
4894
4895
|
};
|
|
4895
4896
|
}
|
|
4896
4897
|
/**
|
|
4897
|
-
* Keyword-search words: the query split on whitespace, lowercased, deduplicated.
|
|
4898
|
-
*
|
|
4898
|
+
* Keyword-search words: the query split on whitespace, lowercased, deduplicated. A hit needs at
|
|
4899
|
+
* least one of them (as a case-insensitive substring); an empty list means the search returns nothing.
|
|
4899
4900
|
*/
|
|
4900
4901
|
function knowledgeSearchWords(query) {
|
|
4901
4902
|
return [...new Set(query.toLowerCase().split(/\s+/).filter(Boolean))];
|
|
4902
4903
|
}
|
|
4903
4904
|
/**
|
|
4905
|
+
* Points one matched search word earns on a page, by the best field it appears in: name, then
|
|
4906
|
+
* description, then body. Pages rank by how many query words they match first; these points only
|
|
4907
|
+
* break ties between pages that match the same number of words.
|
|
4908
|
+
*/
|
|
4909
|
+
const KNOWLEDGE_SEARCH_WEIGHTS = {
|
|
4910
|
+
name: 3,
|
|
4911
|
+
description: 2,
|
|
4912
|
+
body: 1
|
|
4913
|
+
};
|
|
4914
|
+
/**
|
|
4904
4915
|
* Why `key` can't be a Knowledge page key, or undefined when it can. Keys are one path segment:
|
|
4905
4916
|
* non-empty, with no `/` (path separator), `#` (scope/path separator) or `%` (escape character).
|
|
4906
4917
|
*/
|
|
@@ -6016,6 +6027,23 @@ var MongoKnowledgePages = class {
|
|
|
6016
6027
|
}).limit(limit + 1).toArray();
|
|
6017
6028
|
return this.#noteOutput(rows, limit);
|
|
6018
6029
|
}
|
|
6030
|
+
async countChildPages(input) {
|
|
6031
|
+
const ids = [...new Set(input.parentIds)];
|
|
6032
|
+
const counts = Object.fromEntries(ids.map((id) => [id, 0]));
|
|
6033
|
+
if (!ids.length) return counts;
|
|
6034
|
+
const readable = await this.#readable(input.read);
|
|
6035
|
+
const rows = await (await this.#c("pages")).aggregate([{ $match: {
|
|
6036
|
+
parentId: { $in: ids },
|
|
6037
|
+
...notScope,
|
|
6038
|
+
...live,
|
|
6039
|
+
...this.#inScopes("scopeId", readable)
|
|
6040
|
+
} }, { $group: {
|
|
6041
|
+
_id: "$parentId",
|
|
6042
|
+
count: { $sum: 1 }
|
|
6043
|
+
} }]).toArray();
|
|
6044
|
+
for (const row of rows) counts[row._id] = row.count;
|
|
6045
|
+
return counts;
|
|
6046
|
+
}
|
|
6019
6047
|
async countNotes(input) {
|
|
6020
6048
|
const ids = [...new Set(input.pageIds)];
|
|
6021
6049
|
const counts = Object.fromEntries(ids.map((id) => [id, 0]));
|
|
@@ -6271,38 +6299,67 @@ var MongoKnowledgePages = class {
|
|
|
6271
6299
|
...live,
|
|
6272
6300
|
...notScope,
|
|
6273
6301
|
...inScope("scopeId"),
|
|
6274
|
-
$
|
|
6302
|
+
$or: words.flatMap((word) => [
|
|
6275
6303
|
{ name: matcher(word) },
|
|
6276
6304
|
{ description: matcher(word) },
|
|
6277
6305
|
{ body: matcher(word) }
|
|
6278
|
-
]
|
|
6306
|
+
])
|
|
6279
6307
|
};
|
|
6308
|
+
const has = (field, word) => ({ $regexMatch: {
|
|
6309
|
+
input: { $ifNull: [`$${field}`, ""] },
|
|
6310
|
+
regex: escapeRegex(word),
|
|
6311
|
+
options: "i"
|
|
6312
|
+
} });
|
|
6280
6313
|
const hits = (await pages.aggregate([
|
|
6281
6314
|
{ $match: pageFilter },
|
|
6282
|
-
{ $addFields: {
|
|
6283
|
-
{ $
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6315
|
+
{ $addFields: {
|
|
6316
|
+
searchTier: { $cond: [
|
|
6317
|
+
{ $regexMatch: {
|
|
6318
|
+
input: "$canonicalName",
|
|
6319
|
+
regex: escapeRegex(phrase)
|
|
6320
|
+
} },
|
|
6321
|
+
0,
|
|
6322
|
+
1
|
|
6323
|
+
] },
|
|
6324
|
+
searchCount: { $add: words.map((word) => ({ $cond: [
|
|
6325
|
+
{ $or: [
|
|
6326
|
+
has("name", word),
|
|
6327
|
+
has("description", word),
|
|
6328
|
+
has("body", word)
|
|
6329
|
+
] },
|
|
6294
6330
|
1,
|
|
6295
|
-
|
|
6296
|
-
] }
|
|
6297
|
-
|
|
6331
|
+
0
|
|
6332
|
+
] })) },
|
|
6333
|
+
searchScore: { $add: words.map((word) => ({ $switch: {
|
|
6334
|
+
branches: [
|
|
6335
|
+
{
|
|
6336
|
+
case: has("name", word),
|
|
6337
|
+
then: KNOWLEDGE_SEARCH_WEIGHTS.name
|
|
6338
|
+
},
|
|
6339
|
+
{
|
|
6340
|
+
case: has("description", word),
|
|
6341
|
+
then: KNOWLEDGE_SEARCH_WEIGHTS.description
|
|
6342
|
+
},
|
|
6343
|
+
{
|
|
6344
|
+
case: has("body", word),
|
|
6345
|
+
then: KNOWLEDGE_SEARCH_WEIGHTS.body
|
|
6346
|
+
}
|
|
6347
|
+
],
|
|
6348
|
+
default: 0
|
|
6349
|
+
} })) }
|
|
6350
|
+
} },
|
|
6298
6351
|
{ $sort: {
|
|
6299
6352
|
searchTier: 1,
|
|
6353
|
+
searchCount: -1,
|
|
6354
|
+
searchScore: -1,
|
|
6300
6355
|
updatedAt: -1,
|
|
6301
6356
|
id: 1
|
|
6302
6357
|
} },
|
|
6303
6358
|
{ $limit: limit },
|
|
6304
6359
|
{ $project: {
|
|
6305
6360
|
searchTier: 0,
|
|
6361
|
+
searchCount: 0,
|
|
6362
|
+
searchScore: 0,
|
|
6306
6363
|
_id: 0
|
|
6307
6364
|
} }
|
|
6308
6365
|
]).toArray()).map((row) => ({
|
|
@@ -6310,15 +6367,29 @@ var MongoKnowledgePages = class {
|
|
|
6310
6367
|
page: toPage(row)
|
|
6311
6368
|
}));
|
|
6312
6369
|
if (hits.length >= limit) return hits;
|
|
6313
|
-
const noteRows = await (await this.#c("notes")).
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6370
|
+
const noteRows = await (await this.#c("notes")).aggregate([
|
|
6371
|
+
{ $match: {
|
|
6372
|
+
...live,
|
|
6373
|
+
...this.#visibleNotes(ids),
|
|
6374
|
+
...scopes ? { pageScopeId: { $in: ids === null ? scopes : scopes.filter((id) => ids.includes(id)) } } : {},
|
|
6375
|
+
$or: words.map((word) => ({ text: matcher(word) }))
|
|
6376
|
+
} },
|
|
6377
|
+
{ $addFields: { searchScore: { $add: words.map((word) => ({ $cond: [
|
|
6378
|
+
has("text", word),
|
|
6379
|
+
1,
|
|
6380
|
+
0
|
|
6381
|
+
] })) } } },
|
|
6382
|
+
{ $sort: {
|
|
6383
|
+
searchScore: -1,
|
|
6384
|
+
updatedAt: -1,
|
|
6385
|
+
id: -1
|
|
6386
|
+
} },
|
|
6387
|
+
{ $limit: limit - hits.length },
|
|
6388
|
+
{ $project: {
|
|
6389
|
+
searchScore: 0,
|
|
6390
|
+
_id: 0
|
|
6391
|
+
} }
|
|
6392
|
+
]).toArray();
|
|
6322
6393
|
const notePages = new Map((await pages.find({
|
|
6323
6394
|
id: { $in: [...new Set(noteRows.map((row) => String(row.pageId)))] },
|
|
6324
6395
|
...live
|
|
@@ -6684,6 +6755,9 @@ var KnowledgeMongoDB = class extends KnowledgeStorage {
|
|
|
6684
6755
|
listNotes(input) {
|
|
6685
6756
|
return this.#pages.listNotes(input);
|
|
6686
6757
|
}
|
|
6758
|
+
countChildPages(input) {
|
|
6759
|
+
return this.#pages.countChildPages(input);
|
|
6760
|
+
}
|
|
6687
6761
|
countNotes(input) {
|
|
6688
6762
|
return this.#pages.countNotes(input);
|
|
6689
6763
|
}
|