@mastra/dynamodb 1.0.0-beta.1 → 1.0.0-beta.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @mastra/dynamodb
2
2
 
3
+ ## 1.0.0-beta.2
4
+
5
+ ### Patch Changes
6
+
7
+ - feat(storage): support querying messages from multiple threads ([#10663](https://github.com/mastra-ai/mastra/pull/10663))
8
+ - Fixed TypeScript errors where `threadId: string | string[]` was being passed to places expecting `Scalar` type
9
+ - Added proper multi-thread support for `listMessages` across all adapters when `threadId` is an array
10
+ - Updated `_getIncludedMessages` to look up message threadId by ID (since message IDs are globally unique)
11
+ - **upstash**: Added `msg-idx:{messageId}` index for O(1) message lookups (backwards compatible with fallback to scan for old messages, with automatic backfill)
12
+
13
+ - fix: ensure score responses match saved payloads for Mastra Stores. ([#10557](https://github.com/mastra-ai/mastra/pull/10557))
14
+
15
+ - Unify transformScoreRow functions across storage adapters ([#10648](https://github.com/mastra-ai/mastra/pull/10648))
16
+
17
+ Added a unified `transformScoreRow` function in `@mastra/core/storage` that provides schema-driven row transformation for score data. This eliminates code duplication across 10 storage adapters while maintaining store-specific behavior through configurable options:
18
+ - `preferredTimestampFields`: Preferred source fields for timestamps (PostgreSQL, Cloudflare D1)
19
+ - `convertTimestamps`: Convert timestamp strings to Date objects (MSSQL, MongoDB, ClickHouse)
20
+ - `nullValuePattern`: Skip values matching pattern (ClickHouse's `'_null_'`)
21
+ - `fieldMappings`: Map source column names to schema fields (LibSQL's `additionalLLMContext`)
22
+
23
+ Each store adapter now uses the unified function with appropriate options, reducing ~200 lines of duplicate transformation logic while ensuring consistent behavior across all storage backends.
24
+
25
+ - Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749)]:
26
+ - @mastra/core@1.0.0-beta.6
27
+
3
28
  ## 1.0.0-beta.1
4
29
 
5
30
  ### Patch Changes
@@ -554,6 +554,10 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
554
554
  set: (value?: Record<string, unknown> | string) => string | undefined;
555
555
  get: (value?: string) => any;
556
556
  };
557
+ preprocessPrompt: {
558
+ type: "string";
559
+ required: false;
560
+ };
557
561
  preprocessStepResult: {
558
562
  type: "string";
559
563
  required: false;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgBpF"}
@@ -38,6 +38,10 @@ export declare const scoreEntity: Entity<string, string, string, {
38
38
  set: (value?: Record<string, unknown> | string) => string | undefined;
39
39
  get: (value?: string) => any;
40
40
  };
41
+ preprocessPrompt: {
42
+ type: "string";
43
+ required: false;
44
+ };
41
45
  preprocessStepResult: {
42
46
  type: "string";
43
47
  required: false;
@@ -1 +1 @@
1
- {"version":3,"file":"score.d.ts","sourceRoot":"","sources":["../../src/entities/score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAmCJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA8CN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,M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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuExB,CAAC"}
package/dist/index.cjs CHANGED
@@ -425,6 +425,10 @@ var scoreEntity = new electrodb.Entity({
425
425
  return value;
426
426
  }
427
427
  },
428
+ preprocessPrompt: {
429
+ type: "string",
430
+ required: false
431
+ },
428
432
  preprocessStepResult: {
429
433
  type: "string",
430
434
  required: false,
@@ -1130,15 +1134,16 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1130
1134
  }
1131
1135
  async listMessages(args) {
1132
1136
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
1133
- if (!threadId.trim()) {
1137
+ const threadIds = Array.isArray(threadId) ? threadId : [threadId];
1138
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
1134
1139
  throw new error.MastraError(
1135
1140
  {
1136
1141
  id: "STORAGE_DYNAMODB_LIST_MESSAGES_INVALID_THREAD_ID",
1137
1142
  domain: error.ErrorDomain.STORAGE,
1138
1143
  category: error.ErrorCategory.THIRD_PARTY,
1139
- details: { threadId }
1144
+ details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
1140
1145
  },
1141
- new Error("threadId must be a non-empty string")
1146
+ new Error("threadId must be a non-empty string or array of non-empty strings")
1142
1147
  );
1143
1148
  }
1144
1149
  const perPage = storage.normalizePerPage(perPageInput, 40);
@@ -1211,7 +1216,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1211
1216
  let includeMessages = [];
1212
1217
  if (include && include.length > 0) {
1213
1218
  const selectBy = { include };
1214
- includeMessages = await this._getIncludedMessages(threadId, selectBy);
1219
+ includeMessages = await this._getIncludedMessages(selectBy);
1215
1220
  for (const includeMsg of includeMessages) {
1216
1221
  if (!messageIds.has(includeMsg.id)) {
1217
1222
  paginatedMessages.push(includeMsg);
@@ -1249,7 +1254,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1249
1254
  domain: error.ErrorDomain.STORAGE,
1250
1255
  category: error.ErrorCategory.THIRD_PARTY,
1251
1256
  details: {
1252
- threadId,
1257
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
1253
1258
  resourceId: resourceId ?? ""
1254
1259
  }
1255
1260
  },
@@ -1388,19 +1393,23 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1388
1393
  }
1389
1394
  }
1390
1395
  // Helper method to get included messages with context
1391
- async _getIncludedMessages(threadId, selectBy) {
1392
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1396
+ async _getIncludedMessages(selectBy) {
1393
1397
  if (!selectBy?.include?.length) {
1394
1398
  return [];
1395
1399
  }
1396
1400
  const includeMessages = [];
1397
1401
  for (const includeItem of selectBy.include) {
1398
1402
  try {
1399
- const { id, threadId: targetThreadId, withPreviousMessages = 0, withNextMessages = 0 } = includeItem;
1400
- const searchThreadId = targetThreadId || threadId;
1403
+ const { id, withPreviousMessages = 0, withNextMessages = 0 } = includeItem;
1404
+ const targetResult = await this.service.entities.message.get({ entity: "message", id }).go();
1405
+ if (!targetResult.data) {
1406
+ this.logger.warn("Target message not found", { id });
1407
+ continue;
1408
+ }
1409
+ const targetMessageData = targetResult.data;
1410
+ const searchThreadId = targetMessageData.threadId;
1401
1411
  this.logger.debug("Getting included messages for", {
1402
1412
  id,
1403
- targetThreadId,
1404
1413
  searchThreadId,
1405
1414
  withPreviousMessages,
1406
1415
  withNextMessages
@@ -1423,7 +1432,7 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
1423
1432
  });
1424
1433
  const targetIndex = allMessages.findIndex((msg) => msg.id === id);
1425
1434
  if (targetIndex === -1) {
1426
- this.logger.warn("Target message not found", { id, threadId: searchThreadId });
1435
+ this.logger.warn("Target message not found in thread", { id, threadId: searchThreadId });
1427
1436
  continue;
1428
1437
  }
1429
1438
  this.logger.debug("Found target message at index", { id, targetIndex, totalMessages: allMessages.length });
@@ -1956,14 +1965,28 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
1956
1965
  super();
1957
1966
  this.service = service;
1958
1967
  }
1959
- // Helper function to parse score data (handle JSON fields)
1968
+ /**
1969
+ * DynamoDB-specific score row transformation.
1970
+ *
1971
+ * Note: This implementation does NOT use coreTransformScoreRow because:
1972
+ * 1. ElectroDB already parses JSON fields via its entity getters
1973
+ * 2. DynamoDB stores empty strings for null values (which need special handling)
1974
+ * 3. 'entity' is a reserved ElectroDB key, so we use 'entityData' column
1975
+ */
1960
1976
  parseScoreData(data) {
1977
+ const result = {};
1978
+ for (const key of Object.keys(storage.SCORERS_SCHEMA)) {
1979
+ if (["traceId", "resourceId", "threadId", "spanId"].includes(key)) {
1980
+ result[key] = data[key] === "" ? null : data[key];
1981
+ continue;
1982
+ }
1983
+ result[key] = data[key];
1984
+ }
1985
+ result.entity = data.entityData ?? null;
1961
1986
  return {
1962
- ...data,
1963
- // Convert date strings back to Date objects for consistency
1987
+ ...result,
1964
1988
  createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
1965
1989
  updatedAt: data.updatedAt ? new Date(data.updatedAt) : /* @__PURE__ */ new Date()
1966
- // JSON fields are already transformed by the entity's getters
1967
1990
  };
1968
1991
  }
1969
1992
  async getScoreById({ id }) {
@@ -2002,35 +2025,33 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
2002
2025
  }
2003
2026
  const now = /* @__PURE__ */ new Date();
2004
2027
  const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2005
- const scoreData = {
2006
- entity: "score",
2007
- id: scoreId,
2008
- scorerId: validatedScore.scorerId,
2009
- traceId: validatedScore.traceId || "",
2010
- spanId: validatedScore.spanId || "",
2011
- runId: validatedScore.runId,
2012
- scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
2013
- preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
2014
- analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
2015
- score: validatedScore.score,
2016
- reason: validatedScore.reason,
2017
- preprocessPrompt: validatedScore.preprocessPrompt,
2018
- generateScorePrompt: validatedScore.generateScorePrompt,
2019
- generateReasonPrompt: validatedScore.generateReasonPrompt,
2020
- analyzePrompt: validatedScore.analyzePrompt,
2021
- input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
2022
- output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
2023
- additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
2024
- requestContext: typeof validatedScore.requestContext === "string" ? validatedScore.requestContext : JSON.stringify(validatedScore.requestContext),
2025
- entityType: validatedScore.entityType,
2026
- entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
2027
- entityId: validatedScore.entityId,
2028
- source: validatedScore.source,
2029
- resourceId: validatedScore.resourceId || "",
2030
- threadId: validatedScore.threadId || "",
2031
- createdAt: now.toISOString(),
2032
- updatedAt: now.toISOString()
2033
- };
2028
+ const scorer = typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer);
2029
+ const preprocessStepResult = typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult);
2030
+ const analyzeStepResult = typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult);
2031
+ const input = typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input);
2032
+ const output = typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output);
2033
+ const requestContext = typeof validatedScore.requestContext === "string" ? validatedScore.requestContext : JSON.stringify(validatedScore.requestContext);
2034
+ const entity = typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity);
2035
+ const scoreData = Object.fromEntries(
2036
+ Object.entries({
2037
+ ...validatedScore,
2038
+ entity: "score",
2039
+ id: scoreId,
2040
+ scorer,
2041
+ preprocessStepResult,
2042
+ analyzeStepResult,
2043
+ input,
2044
+ output,
2045
+ requestContext,
2046
+ entityData: entity,
2047
+ traceId: validatedScore.traceId || "",
2048
+ resourceId: validatedScore.resourceId || "",
2049
+ threadId: validatedScore.threadId || "",
2050
+ spanId: validatedScore.spanId || "",
2051
+ createdAt: now.toISOString(),
2052
+ updatedAt: now.toISOString()
2053
+ }).filter(([_, value]) => value !== void 0 && value !== null)
2054
+ );
2034
2055
  try {
2035
2056
  await this.service.entities.score.upsert(scoreData).go();
2036
2057
  const savedScore = {