@mastra/mongodb 0.14.9 → 0.14.10

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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 0.14.10
4
+
5
+ ### Patch Changes
6
+
7
+ - deleteVectors, deleteFilter when upserting, updateVector filter (#10244) ([#10526](https://github.com/mastra-ai/mastra/pull/10526))
8
+
9
+ - fix: ensure score responses match saved payloads for Mastra Stores. ([#10570](https://github.com/mastra-ai/mastra/pull/10570))
10
+
11
+ - Fix message sorting in getMessagesPaginated when using semantic recall (include parameter). Messages are now always sorted by createdAt after combining paginated and included messages, ensuring correct chronological ordering of conversation history. All stores now consistently use MessageList for deduplication followed by explicit sorting. ([#10573](https://github.com/mastra-ai/mastra/pull/10573))
12
+
13
+ - Updated dependencies [[`5657314`](https://github.com/mastra-ai/mastra/commit/5657314a1f9d49019bb53f357fa48f75a69247ca), [`e5aca78`](https://github.com/mastra-ai/mastra/commit/e5aca78bb7f263bb8b470bedae81efe9805d7544), [`33a607a`](https://github.com/mastra-ai/mastra/commit/33a607a1f716c2029d4a1ff1603dd756129a33b3), [`cc10fc1`](https://github.com/mastra-ai/mastra/commit/cc10fc192d9f527c71a23cc9def10d8718935ee1), [`1f7ee84`](https://github.com/mastra-ai/mastra/commit/1f7ee841a643ef12d90392125881f06fdf877293), [`e7d5149`](https://github.com/mastra-ai/mastra/commit/e7d514995260b63b2108308e85c64de37dcd0f71), [`f195082`](https://github.com/mastra-ai/mastra/commit/f1950822a2425d5ccae78c5d010e02ddb027a869), [`d9986dd`](https://github.com/mastra-ai/mastra/commit/d9986dd3513f7ca3244a8e599a440ccf4d8bc28b), [`a45b0f0`](https://github.com/mastra-ai/mastra/commit/a45b0f0cd19eab1fe4deceae3abf029442c22f74), [`f6e8eb3`](https://github.com/mastra-ai/mastra/commit/f6e8eb3dac53b70b06e906b2818b1d2a5b0486d7), [`ce57a2b`](https://github.com/mastra-ai/mastra/commit/ce57a2b62fd0d5f6532e4ecd1ba9ba93ac9b95fc), [`3236f35`](https://github.com/mastra-ai/mastra/commit/3236f352ae13cc8552c2965164e97bd125dae48d), [`ce57a2b`](https://github.com/mastra-ai/mastra/commit/ce57a2b62fd0d5f6532e4ecd1ba9ba93ac9b95fc), [`0230321`](https://github.com/mastra-ai/mastra/commit/02303217870bedea0ef009bea9a952f24ed38aaf), [`7b541f4`](https://github.com/mastra-ai/mastra/commit/7b541f49eda6f5a87b738198edbd136927599475), [`0eea842`](https://github.com/mastra-ai/mastra/commit/0eea8423cbdd37f2111593c6f7d2efcde4b7e4ce), [`63ae8a2`](https://github.com/mastra-ai/mastra/commit/63ae8a22c0c09bbb8b9779f5f38934cd75f616af), [`bf810c5`](https://github.com/mastra-ai/mastra/commit/bf810c5c561bd8ef221c0f6bd84e69770b9a38cc), [`ac7ef07`](https://github.com/mastra-ai/mastra/commit/ac7ef07633caee89707142171d2873c888ffef85), [`522f0b4`](https://github.com/mastra-ai/mastra/commit/522f0b45330719858794eabffffde4f343f55549), [`bf810c5`](https://github.com/mastra-ai/mastra/commit/bf810c5c561bd8ef221c0f6bd84e69770b9a38cc), [`8b51d55`](https://github.com/mastra-ai/mastra/commit/8b51d55bae531edf7e383958d7ecee04df31f5d5), [`2131ac5`](https://github.com/mastra-ai/mastra/commit/2131ac571d5065f0a656c57494bca98691bb7609)]:
14
+ - @mastra/core@0.24.6
15
+
16
+ ## 0.14.10-alpha.0
17
+
18
+ ### Patch Changes
19
+
20
+ - deleteVectors, deleteFilter when upserting, updateVector filter (#10244) ([#10526](https://github.com/mastra-ai/mastra/pull/10526))
21
+
22
+ - fix: ensure score responses match saved payloads for Mastra Stores. ([#10570](https://github.com/mastra-ai/mastra/pull/10570))
23
+
24
+ - Fix message sorting in getMessagesPaginated when using semantic recall (include parameter). Messages are now always sorted by createdAt after combining paginated and included messages, ensuring correct chronological ordering of conversation history. All stores now consistently use MessageList for deduplication followed by explicit sorting. ([#10573](https://github.com/mastra-ai/mastra/pull/10573))
25
+
26
+ - Updated dependencies [[`5657314`](https://github.com/mastra-ai/mastra/commit/5657314a1f9d49019bb53f357fa48f75a69247ca), [`e5aca78`](https://github.com/mastra-ai/mastra/commit/e5aca78bb7f263bb8b470bedae81efe9805d7544), [`33a607a`](https://github.com/mastra-ai/mastra/commit/33a607a1f716c2029d4a1ff1603dd756129a33b3), [`cc10fc1`](https://github.com/mastra-ai/mastra/commit/cc10fc192d9f527c71a23cc9def10d8718935ee1), [`1f7ee84`](https://github.com/mastra-ai/mastra/commit/1f7ee841a643ef12d90392125881f06fdf877293), [`e7d5149`](https://github.com/mastra-ai/mastra/commit/e7d514995260b63b2108308e85c64de37dcd0f71), [`f195082`](https://github.com/mastra-ai/mastra/commit/f1950822a2425d5ccae78c5d010e02ddb027a869), [`d9986dd`](https://github.com/mastra-ai/mastra/commit/d9986dd3513f7ca3244a8e599a440ccf4d8bc28b), [`a45b0f0`](https://github.com/mastra-ai/mastra/commit/a45b0f0cd19eab1fe4deceae3abf029442c22f74), [`f6e8eb3`](https://github.com/mastra-ai/mastra/commit/f6e8eb3dac53b70b06e906b2818b1d2a5b0486d7), [`ce57a2b`](https://github.com/mastra-ai/mastra/commit/ce57a2b62fd0d5f6532e4ecd1ba9ba93ac9b95fc), [`3236f35`](https://github.com/mastra-ai/mastra/commit/3236f352ae13cc8552c2965164e97bd125dae48d), [`ce57a2b`](https://github.com/mastra-ai/mastra/commit/ce57a2b62fd0d5f6532e4ecd1ba9ba93ac9b95fc), [`0230321`](https://github.com/mastra-ai/mastra/commit/02303217870bedea0ef009bea9a952f24ed38aaf), [`7b541f4`](https://github.com/mastra-ai/mastra/commit/7b541f49eda6f5a87b738198edbd136927599475), [`0eea842`](https://github.com/mastra-ai/mastra/commit/0eea8423cbdd37f2111593c6f7d2efcde4b7e4ce), [`63ae8a2`](https://github.com/mastra-ai/mastra/commit/63ae8a22c0c09bbb8b9779f5f38934cd75f616af), [`bf810c5`](https://github.com/mastra-ai/mastra/commit/bf810c5c561bd8ef221c0f6bd84e69770b9a38cc), [`ac7ef07`](https://github.com/mastra-ai/mastra/commit/ac7ef07633caee89707142171d2873c888ffef85), [`522f0b4`](https://github.com/mastra-ai/mastra/commit/522f0b45330719858794eabffffde4f343f55549), [`bf810c5`](https://github.com/mastra-ai/mastra/commit/bf810c5c561bd8ef221c0f6bd84e69770b9a38cc), [`8b51d55`](https://github.com/mastra-ai/mastra/commit/8b51d55bae531edf7e383958d7ecee04df31f5d5), [`2131ac5`](https://github.com/mastra-ai/mastra/commit/2131ac571d5065f0a656c57494bca98691bb7609)]:
27
+ - @mastra/core@0.24.6-alpha.0
28
+
3
29
  ## 0.14.9
4
30
 
5
31
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -13,7 +13,7 @@ var scores = require('@mastra/core/scores');
13
13
 
14
14
  // package.json
15
15
  var package_default = {
16
- version: "0.14.9"};
16
+ version: "0.14.10"};
17
17
  var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
18
18
  getSupportedOperators() {
19
19
  return {
@@ -355,12 +355,17 @@ var MongoDBVector = class extends vector.MastraVector {
355
355
  limit: topK
356
356
  };
357
357
  if (Object.keys(combinedFilter).length > 0) {
358
- const candidateIds = await collection.aggregate([{ $match: combinedFilter }, { $project: { _id: 1 } }]).map((doc) => doc._id).toArray();
358
+ const filterWithExclusion = {
359
+ $and: [{ _id: { $ne: "__index_metadata__" } }, combinedFilter]
360
+ };
361
+ const candidateIds = await collection.aggregate([{ $match: filterWithExclusion }, { $project: { _id: 1 } }]).map((doc) => doc._id).toArray();
359
362
  if (candidateIds.length > 0) {
360
363
  vectorSearch.filter = { _id: { $in: candidateIds } };
361
364
  } else {
362
365
  return [];
363
366
  }
367
+ } else {
368
+ vectorSearch.filter = { _id: { $ne: "__index_metadata__" } };
364
369
  }
365
370
  const pipeline = [
366
371
  {
@@ -481,7 +486,26 @@ var MongoDBVector = class extends vector.MastraVector {
481
486
  * @returns A promise that resolves when the update is complete.
482
487
  * @throws Will throw an error if no updates are provided or if the update operation fails.
483
488
  */
484
- async updateVector({ indexName, id, update }) {
489
+ async updateVector(params) {
490
+ const { indexName, update } = params;
491
+ if ("id" in params && params.id && "filter" in params && params.filter) {
492
+ throw new error.MastraError({
493
+ id: "STORAGE_MONGODB_VECTOR_UPDATE_MUTUALLY_EXCLUSIVE_PARAMS",
494
+ domain: error.ErrorDomain.STORAGE,
495
+ category: error.ErrorCategory.USER,
496
+ details: { indexName },
497
+ text: "id and filter are mutually exclusive - provide only one"
498
+ });
499
+ }
500
+ if (!("id" in params || "filter" in params) || !params.id && !params.filter) {
501
+ throw new error.MastraError({
502
+ id: "STORAGE_MONGODB_VECTOR_UPDATE_MISSING_PARAMS",
503
+ domain: error.ErrorDomain.STORAGE,
504
+ category: error.ErrorCategory.USER,
505
+ text: "Either id or filter must be provided",
506
+ details: { indexName }
507
+ });
508
+ }
485
509
  try {
486
510
  if (!update.vector && !update.metadata) {
487
511
  throw new Error("No updates provided");
@@ -503,17 +527,49 @@ var MongoDBVector = class extends vector.MastraVector {
503
527
  );
504
528
  updateDoc[this.metadataFieldName] = normalizedMeta;
505
529
  }
506
- await collection.findOneAndUpdate({ _id: id }, { $set: updateDoc });
530
+ if ("id" in params && params.id) {
531
+ await collection.findOneAndUpdate({ _id: params.id }, { $set: updateDoc });
532
+ } else if ("filter" in params && params.filter) {
533
+ const filter = params.filter;
534
+ if (!filter || Object.keys(filter).length === 0) {
535
+ throw new error.MastraError({
536
+ id: "STORAGE_MONGODB_VECTOR_UPDATE_EMPTY_FILTER",
537
+ domain: error.ErrorDomain.STORAGE,
538
+ category: error.ErrorCategory.USER,
539
+ details: { indexName },
540
+ text: "Cannot update with empty filter"
541
+ });
542
+ }
543
+ const mongoFilter = this.transformFilter(filter);
544
+ const transformedFilter = this.transformMetadataFilter(mongoFilter);
545
+ if (!transformedFilter || Object.keys(transformedFilter).length === 0) {
546
+ throw new error.MastraError({
547
+ id: "STORAGE_MONGODB_VECTOR_UPDATE_INVALID_FILTER",
548
+ domain: error.ErrorDomain.STORAGE,
549
+ category: error.ErrorCategory.USER,
550
+ details: { indexName },
551
+ text: "Filter produced empty query"
552
+ });
553
+ }
554
+ await collection.updateMany(transformedFilter, { $set: updateDoc });
555
+ }
507
556
  } catch (error$1) {
557
+ if (error$1 instanceof error.MastraError) {
558
+ throw error$1;
559
+ }
560
+ const errorDetails = { indexName };
561
+ if ("id" in params && params.id) {
562
+ errorDetails.id = params.id;
563
+ }
564
+ if ("filter" in params && params.filter) {
565
+ errorDetails.filter = JSON.stringify(params.filter);
566
+ }
508
567
  throw new error.MastraError(
509
568
  {
510
569
  id: "STORAGE_MONGODB_VECTOR_UPDATE_VECTOR_FAILED",
511
570
  domain: error.ErrorDomain.STORAGE,
512
571
  category: error.ErrorCategory.THIRD_PARTY,
513
- details: {
514
- indexName,
515
- id
516
- }
572
+ details: errorDetails
517
573
  },
518
574
  error$1
519
575
  );
@@ -545,6 +601,83 @@ var MongoDBVector = class extends vector.MastraVector {
545
601
  );
546
602
  }
547
603
  }
604
+ async deleteVectors({ indexName, filter, ids }) {
605
+ if (!filter && !ids) {
606
+ throw new error.MastraError({
607
+ id: "STORAGE_MONGODB_VECTOR_DELETE_MISSING_PARAMS",
608
+ domain: error.ErrorDomain.STORAGE,
609
+ category: error.ErrorCategory.USER,
610
+ details: { indexName },
611
+ text: "Either filter or ids must be provided"
612
+ });
613
+ }
614
+ if (filter && ids) {
615
+ throw new error.MastraError({
616
+ id: "STORAGE_MONGODB_VECTOR_DELETE_CONFLICTING_PARAMS",
617
+ domain: error.ErrorDomain.STORAGE,
618
+ category: error.ErrorCategory.USER,
619
+ details: { indexName },
620
+ text: "Cannot provide both filter and ids - they are mutually exclusive"
621
+ });
622
+ }
623
+ try {
624
+ const collection = await this.getCollection(indexName, true);
625
+ if (ids) {
626
+ if (ids.length === 0) {
627
+ throw new error.MastraError({
628
+ id: "STORAGE_MONGODB_VECTOR_DELETE_EMPTY_IDS",
629
+ domain: error.ErrorDomain.STORAGE,
630
+ category: error.ErrorCategory.USER,
631
+ details: { indexName },
632
+ text: "Cannot delete with empty ids array"
633
+ });
634
+ }
635
+ await collection.deleteMany({ _id: { $in: ids } });
636
+ } else {
637
+ if (!filter || Object.keys(filter).length === 0) {
638
+ throw new error.MastraError({
639
+ id: "STORAGE_MONGODB_VECTOR_DELETE_EMPTY_FILTER",
640
+ domain: error.ErrorDomain.STORAGE,
641
+ category: error.ErrorCategory.USER,
642
+ details: { indexName },
643
+ text: "Cannot delete with empty filter"
644
+ });
645
+ }
646
+ const mongoFilter = this.transformFilter(filter);
647
+ const transformedFilter = this.transformMetadataFilter(mongoFilter);
648
+ if (!transformedFilter || Object.keys(transformedFilter).length === 0) {
649
+ throw new error.MastraError({
650
+ id: "STORAGE_MONGODB_VECTOR_DELETE_INVALID_FILTER",
651
+ domain: error.ErrorDomain.STORAGE,
652
+ category: error.ErrorCategory.USER,
653
+ details: { indexName },
654
+ text: "Filter produced empty query"
655
+ });
656
+ }
657
+ const finalFilter = {
658
+ $and: [{ _id: { $ne: "__index_metadata__" } }, transformedFilter]
659
+ };
660
+ await collection.deleteMany(finalFilter);
661
+ }
662
+ } catch (error$1) {
663
+ if (error$1 instanceof error.MastraError) {
664
+ throw error$1;
665
+ }
666
+ throw new error.MastraError(
667
+ {
668
+ id: "STORAGE_MONGODB_VECTOR_DELETE_VECTORS_FAILED",
669
+ domain: error.ErrorDomain.STORAGE,
670
+ category: error.ErrorCategory.THIRD_PARTY,
671
+ details: {
672
+ indexName,
673
+ ...filter && { filter: JSON.stringify(filter) },
674
+ ...ids && { idsCount: ids.length }
675
+ }
676
+ },
677
+ error$1
678
+ );
679
+ }
680
+ }
548
681
  // Private methods
549
682
  async getCollection(indexName, throwIfNotExists = true) {
550
683
  if (this.collections.has(indexName)) {
@@ -592,16 +725,26 @@ var MongoDBVector = class extends vector.MastraVector {
592
725
  */
593
726
  transformMetadataFilter(filter) {
594
727
  if (!filter || typeof filter !== "object") return filter;
728
+ if (Array.isArray(filter)) {
729
+ return filter.map((item) => this.transformMetadataFilter(item));
730
+ }
595
731
  const transformed = {};
596
732
  for (const [key, value] of Object.entries(filter)) {
597
733
  if (key.startsWith("$")) {
598
734
  if (Array.isArray(value)) {
599
735
  transformed[key] = value.map((item) => this.transformMetadataFilter(item));
600
- } else {
736
+ } else if (typeof value === "object" && value !== null) {
601
737
  transformed[key] = this.transformMetadataFilter(value);
738
+ } else {
739
+ transformed[key] = value;
602
740
  }
603
741
  } else if (key.startsWith("metadata.")) {
604
- transformed[key] = value;
742
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
743
+ const hasOperator = Object.keys(value).some((k) => k.startsWith("$"));
744
+ transformed[key] = hasOperator ? value : value;
745
+ } else {
746
+ transformed[key] = value;
747
+ }
605
748
  } else if (this.isMetadataField(key)) {
606
749
  transformed[`metadata.${key}`] = value;
607
750
  } else {
@@ -844,11 +987,27 @@ var LegacyEvalsMongoDB = class extends storage.LegacyEvalsStorage {
844
987
  }
845
988
  }
846
989
  };
847
-
848
- // src/storage/domains/utils.ts
849
990
  function formatDateForMongoDB(date) {
850
991
  return typeof date === "string" ? new Date(date) : date;
851
992
  }
993
+ var transformRow = ({ row, tableName }) => {
994
+ const tableSchema = storage.TABLE_SCHEMAS[tableName];
995
+ const result = {};
996
+ Object.entries(tableSchema).forEach(([key, columnSchema]) => {
997
+ const value = row[key];
998
+ if (value === void 0 || value === null) {
999
+ return;
1000
+ }
1001
+ if (columnSchema.type === "jsonb" && typeof value === "string") {
1002
+ result[key] = storage.safelyParseJSON(value);
1003
+ } else if (columnSchema.type === "timestamp" && typeof value === "string") {
1004
+ result[key] = new Date(value);
1005
+ } else {
1006
+ result[key] = value;
1007
+ }
1008
+ });
1009
+ return result;
1010
+ };
852
1011
 
853
1012
  // src/storage/domains/memory/index.ts
854
1013
  var MemoryStorageMongoDB = class extends storage.MemoryStorage {
@@ -1022,7 +1181,11 @@ var MemoryStorageMongoDB = class extends storage.MemoryStorage {
1022
1181
  }
1023
1182
  const dataResult = await collection.find(query).sort({ createdAt: -1 }).skip(currentOffset).limit(perPage).toArray();
1024
1183
  messages.push(...dataResult.map((row) => this.parseRow(row)));
1025
- const messagesToReturn = format === "v1" ? new agent.MessageList().add(messages, "memory").get.all.v1() : new agent.MessageList().add(messages, "memory").get.all.v2();
1184
+ const list = new agent.MessageList().add(messages, "memory");
1185
+ let messagesToReturn = format === "v1" ? list.get.all.v1() : list.get.all.v2();
1186
+ messagesToReturn = messagesToReturn.sort(
1187
+ (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
1188
+ );
1026
1189
  return {
1027
1190
  messages: messagesToReturn,
1028
1191
  total,
@@ -1907,98 +2070,8 @@ var StoreOperationsMongoDB = class extends storage.StoreOperations {
1907
2070
  }
1908
2071
  };
1909
2072
  function transformScoreRow(row) {
1910
- let scorerValue = null;
1911
- if (row.scorer) {
1912
- try {
1913
- scorerValue = typeof row.scorer === "string" ? storage.safelyParseJSON(row.scorer) : row.scorer;
1914
- } catch (e) {
1915
- console.warn("Failed to parse scorer:", e);
1916
- }
1917
- }
1918
- let preprocessStepResultValue = null;
1919
- if (row.preprocessStepResult) {
1920
- try {
1921
- preprocessStepResultValue = typeof row.preprocessStepResult === "string" ? storage.safelyParseJSON(row.preprocessStepResult) : row.preprocessStepResult;
1922
- } catch (e) {
1923
- console.warn("Failed to parse preprocessStepResult:", e);
1924
- }
1925
- }
1926
- let analyzeStepResultValue = null;
1927
- if (row.analyzeStepResult) {
1928
- try {
1929
- analyzeStepResultValue = typeof row.analyzeStepResult === "string" ? storage.safelyParseJSON(row.analyzeStepResult) : row.analyzeStepResult;
1930
- } catch (e) {
1931
- console.warn("Failed to parse analyzeStepResult:", e);
1932
- }
1933
- }
1934
- let inputValue = null;
1935
- if (row.input) {
1936
- try {
1937
- inputValue = typeof row.input === "string" ? storage.safelyParseJSON(row.input) : row.input;
1938
- } catch (e) {
1939
- console.warn("Failed to parse input:", e);
1940
- }
1941
- }
1942
- let outputValue = null;
1943
- if (row.output) {
1944
- try {
1945
- outputValue = typeof row.output === "string" ? storage.safelyParseJSON(row.output) : row.output;
1946
- } catch (e) {
1947
- console.warn("Failed to parse output:", e);
1948
- }
1949
- }
1950
- let entityValue = null;
1951
- if (row.entity) {
1952
- try {
1953
- entityValue = typeof row.entity === "string" ? storage.safelyParseJSON(row.entity) : row.entity;
1954
- } catch (e) {
1955
- console.warn("Failed to parse entity:", e);
1956
- }
1957
- }
1958
- let runtimeContextValue = null;
1959
- if (row.runtimeContext) {
1960
- try {
1961
- runtimeContextValue = typeof row.runtimeContext === "string" ? storage.safelyParseJSON(row.runtimeContext) : row.runtimeContext;
1962
- } catch (e) {
1963
- console.warn("Failed to parse runtimeContext:", e);
1964
- }
1965
- }
1966
- let metadataValue = null;
1967
- if (row.metadata) {
1968
- try {
1969
- metadataValue = typeof row.metadata === "string" ? storage.safelyParseJSON(row.metadata) : row.metadata;
1970
- } catch (e) {
1971
- console.warn("Failed to parse metadata:", e);
1972
- }
1973
- }
1974
- return {
1975
- id: row.id,
1976
- entityId: row.entityId,
1977
- entityType: row.entityType,
1978
- scorerId: row.scorerId,
1979
- traceId: row.traceId,
1980
- spanId: row.spanId,
1981
- runId: row.runId,
1982
- scorer: scorerValue,
1983
- preprocessStepResult: preprocessStepResultValue,
1984
- preprocessPrompt: row.preprocessPrompt,
1985
- analyzeStepResult: analyzeStepResultValue,
1986
- generateScorePrompt: row.generateScorePrompt,
1987
- score: row.score,
1988
- analyzePrompt: row.analyzePrompt,
1989
- reasonPrompt: row.reasonPrompt,
1990
- metadata: metadataValue,
1991
- input: inputValue,
1992
- output: outputValue,
1993
- additionalContext: row.additionalContext,
1994
- runtimeContext: runtimeContextValue,
1995
- entity: entityValue,
1996
- source: row.source,
1997
- resourceId: row.resourceId,
1998
- threadId: row.threadId,
1999
- createdAt: new Date(row.createdAt),
2000
- updatedAt: new Date(row.updatedAt)
2001
- };
2073
+ const transformedRow = transformRow({ row, tableName: storage.TABLE_SCORERS });
2074
+ return transformedRow;
2002
2075
  }
2003
2076
  var ScoresStorageMongoDB = class extends storage.ScoresStorage {
2004
2077
  operations;
@@ -2043,36 +2116,29 @@ var ScoresStorageMongoDB = class extends storage.ScoresStorage {
2043
2116
  try {
2044
2117
  const now = /* @__PURE__ */ new Date();
2045
2118
  const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2046
- const scoreData = {
2047
- id: scoreId,
2048
- entityId: validatedScore.entityId,
2049
- entityType: validatedScore.entityType,
2050
- scorerId: validatedScore.scorerId,
2051
- traceId: validatedScore.traceId || "",
2052
- spanId: validatedScore.spanId || "",
2053
- runId: validatedScore.runId,
2054
- scorer: typeof validatedScore.scorer === "string" ? storage.safelyParseJSON(validatedScore.scorer) : validatedScore.scorer,
2055
- preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? storage.safelyParseJSON(validatedScore.preprocessStepResult) : validatedScore.preprocessStepResult,
2056
- analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? storage.safelyParseJSON(validatedScore.analyzeStepResult) : validatedScore.analyzeStepResult,
2057
- score: validatedScore.score,
2058
- reason: validatedScore.reason,
2059
- preprocessPrompt: validatedScore.preprocessPrompt,
2060
- generateScorePrompt: validatedScore.generateScorePrompt,
2061
- generateReasonPrompt: validatedScore.generateReasonPrompt,
2062
- analyzePrompt: validatedScore.analyzePrompt,
2063
- input: typeof validatedScore.input === "string" ? storage.safelyParseJSON(validatedScore.input) : validatedScore.input,
2064
- output: typeof validatedScore.output === "string" ? storage.safelyParseJSON(validatedScore.output) : validatedScore.output,
2065
- additionalContext: validatedScore.additionalContext,
2066
- runtimeContext: typeof validatedScore.runtimeContext === "string" ? storage.safelyParseJSON(validatedScore.runtimeContext) : validatedScore.runtimeContext,
2067
- entity: typeof validatedScore.entity === "string" ? storage.safelyParseJSON(validatedScore.entity) : validatedScore.entity,
2068
- source: validatedScore.source,
2069
- resourceId: validatedScore.resourceId || "",
2070
- threadId: validatedScore.threadId || "",
2071
- createdAt: now,
2072
- updatedAt: now
2119
+ const scorer = typeof validatedScore.scorer === "string" ? storage.safelyParseJSON(validatedScore.scorer) : validatedScore.scorer;
2120
+ const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? storage.safelyParseJSON(validatedScore.preprocessStepResult) : validatedScore.preprocessStepResult;
2121
+ const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? storage.safelyParseJSON(validatedScore.analyzeStepResult) : validatedScore.analyzeStepResult;
2122
+ const input = typeof validatedScore.input === "string" ? storage.safelyParseJSON(validatedScore.input) : validatedScore.input;
2123
+ const output = typeof validatedScore.output === "string" ? storage.safelyParseJSON(validatedScore.output) : validatedScore.output;
2124
+ const runtimeContext = typeof validatedScore.runtimeContext === "string" ? storage.safelyParseJSON(validatedScore.runtimeContext) : validatedScore.runtimeContext;
2125
+ const entity = typeof validatedScore.entity === "string" ? storage.safelyParseJSON(validatedScore.entity) : validatedScore.entity;
2126
+ const createdAt = now;
2127
+ const updatedAt = now;
2128
+ const dataToSave = {
2129
+ ...validatedScore,
2130
+ scorer,
2131
+ preprocessStepResult,
2132
+ analyzeStepResult,
2133
+ input,
2134
+ output,
2135
+ runtimeContext,
2136
+ entity,
2137
+ createdAt,
2138
+ updatedAt
2073
2139
  };
2074
2140
  const collection = await this.operations.getCollection(storage.TABLE_SCORERS);
2075
- await collection.insertOne(scoreData);
2141
+ await collection.insertOne(dataToSave);
2076
2142
  const savedScore = {
2077
2143
  ...score,
2078
2144
  id: scoreId,