@mastra/mongodb 1.14.0 → 1.15.0-alpha.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/CHANGELOG.md +25 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +38 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -15
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v4 } from '@lukeed/uuid';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, DatasetsStorage, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, ensureDate, safelyParseJSON, hasErrorCode, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, ExperimentsStorage, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, NotificationsStorage, TABLE_NOTIFICATIONS, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SkillsStorage, TABLE_SKILLS, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, TraceStatus, parseDuration, normalizeScheduleTarget, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
|
|
3
|
+
import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, DatasetsStorage, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, ensureDate, safelyParseJSON, hasErrorCode, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, ExperimentsStorage, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, validateStorageMetadataFilter, storageMessageMatchesMetadataFilter, NotificationsStorage, TABLE_NOTIFICATIONS, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, SchedulesStorage, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SkillsStorage, TABLE_SKILLS, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, TraceStatus, parseDuration, normalizeScheduleTarget, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
|
|
4
4
|
import { MastraVector, validateUpsertInput, validateVectorValues } from '@mastra/core/vector';
|
|
5
5
|
import { MongoClient, MongoBulkWriteError } from 'mongodb';
|
|
6
6
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
@@ -13,7 +13,7 @@ import { skillSnapshotFieldValuesEqual } from '@mastra/core/storage/domains/skil
|
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
15
|
var package_default = {
|
|
16
|
-
version: "1.
|
|
16
|
+
version: "1.15.0-alpha.0"};
|
|
17
17
|
var MongoDBFilterTranslator = class extends BaseFilterTranslator {
|
|
18
18
|
getSupportedOperators() {
|
|
19
19
|
return {
|
|
@@ -5271,6 +5271,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5271
5271
|
}
|
|
5272
5272
|
async listMessages(args) {
|
|
5273
5273
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
5274
|
+
const metadataFilter = validateStorageMetadataFilter(filter?.metadata);
|
|
5274
5275
|
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
5275
5276
|
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
5276
5277
|
throw new MastraError(
|
|
@@ -5326,16 +5327,27 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5326
5327
|
hasMore: false
|
|
5327
5328
|
};
|
|
5328
5329
|
}
|
|
5329
|
-
const total = await collection.countDocuments(query);
|
|
5330
5330
|
const messages = [];
|
|
5331
|
+
let total = 0;
|
|
5331
5332
|
if (perPage !== 0) {
|
|
5332
5333
|
const sortObj = { [field]: sortOrder };
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5334
|
+
if (metadataFilter) {
|
|
5335
|
+
const candidates = (await collection.find(query).sort(sortObj).toArray()).map((row) => this.parseRow(row)).filter((message) => storageMessageMatchesMetadataFilter(message.content, metadataFilter));
|
|
5336
|
+
total = candidates.length;
|
|
5337
|
+
messages.push(...perPageInput === false ? candidates : candidates.slice(offset, offset + perPage));
|
|
5338
|
+
} else {
|
|
5339
|
+
total = await collection.countDocuments(query);
|
|
5340
|
+
let cursor = collection.find(query).sort(sortObj).skip(offset);
|
|
5341
|
+
if (perPageInput !== false) {
|
|
5342
|
+
cursor = cursor.limit(perPage);
|
|
5343
|
+
}
|
|
5344
|
+
const dataResult = await cursor.toArray();
|
|
5345
|
+
messages.push(...dataResult.map((row) => this.parseRow(row)));
|
|
5336
5346
|
}
|
|
5337
|
-
|
|
5338
|
-
|
|
5347
|
+
} else if (metadataFilter) {
|
|
5348
|
+
total = (await collection.find(query).toArray()).map((row) => this.parseRow(row)).filter((message) => storageMessageMatchesMetadataFilter(message.content, metadataFilter)).length;
|
|
5349
|
+
} else {
|
|
5350
|
+
total = await collection.countDocuments(query);
|
|
5339
5351
|
}
|
|
5340
5352
|
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
5341
5353
|
return {
|
|
@@ -5365,7 +5377,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5365
5377
|
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
5366
5378
|
);
|
|
5367
5379
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
5368
|
-
const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
5380
|
+
const hasMore = metadataFilter ? perPageInput !== false && offset + perPage < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
5369
5381
|
return {
|
|
5370
5382
|
messages: finalMessages,
|
|
5371
5383
|
total,
|
|
@@ -5399,6 +5411,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5399
5411
|
}
|
|
5400
5412
|
async listMessagesByResourceId(args) {
|
|
5401
5413
|
const { resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
5414
|
+
const metadataFilter = validateStorageMetadataFilter(filter?.metadata);
|
|
5402
5415
|
if (!resourceId || typeof resourceId !== "string" || resourceId.trim().length === 0) {
|
|
5403
5416
|
throw new MastraError(
|
|
5404
5417
|
{
|
|
@@ -5454,16 +5467,27 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends MemoryStorage {
|
|
|
5454
5467
|
hasMore: false
|
|
5455
5468
|
};
|
|
5456
5469
|
}
|
|
5457
|
-
const total = await collection.countDocuments(query);
|
|
5458
5470
|
const messages = [];
|
|
5471
|
+
let total = 0;
|
|
5459
5472
|
if (perPage !== 0) {
|
|
5460
5473
|
const sortObj = { [field]: sortOrder };
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5474
|
+
if (metadataFilter) {
|
|
5475
|
+
const candidates = (await collection.find(query).sort(sortObj).toArray()).map((row) => this.parseRow(row)).filter((message) => storageMessageMatchesMetadataFilter(message.content, metadataFilter));
|
|
5476
|
+
total = candidates.length;
|
|
5477
|
+
messages.push(...perPageInput === false ? candidates : candidates.slice(offset, offset + perPage));
|
|
5478
|
+
} else {
|
|
5479
|
+
total = await collection.countDocuments(query);
|
|
5480
|
+
let cursor = collection.find(query).sort(sortObj).skip(offset);
|
|
5481
|
+
if (perPageInput !== false) {
|
|
5482
|
+
cursor = cursor.limit(perPage);
|
|
5483
|
+
}
|
|
5484
|
+
const dataResult = await cursor.toArray();
|
|
5485
|
+
messages.push(...dataResult.map((row) => this.parseRow(row)));
|
|
5464
5486
|
}
|
|
5465
|
-
|
|
5466
|
-
|
|
5487
|
+
} else if (metadataFilter) {
|
|
5488
|
+
total = (await collection.find(query).toArray()).map((row) => this.parseRow(row)).filter((message) => storageMessageMatchesMetadataFilter(message.content, metadataFilter)).length;
|
|
5489
|
+
} else {
|
|
5490
|
+
total = await collection.countDocuments(query);
|
|
5467
5491
|
}
|
|
5468
5492
|
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
5469
5493
|
return {
|