@mastra/dynamodb 0.0.0-roamin-openaivoice-speak-options-passing-20250926163614 → 0.0.0-safe-stringify-telemetry-20251205024938

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/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { DynamoDBClient, DescribeTableCommand } from '@aws-sdk/client-dynamodb';
2
2
  import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
3
3
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
4
- import { MastraStorage, StoreOperations, TracesStorage, TABLE_TRACES, WorkflowsStorage, MemoryStorage, resolveMessageLimit, ScoresStorage, LegacyEvalsStorage, TABLE_AI_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
4
+ import { MastraStorage, StoreOperations, TracesStorage, TABLE_TRACES, WorkflowsStorage, MemoryStorage, resolveMessageLimit, ScoresStorage, SCORERS_SCHEMA, LegacyEvalsStorage, TABLE_AI_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS } from '@mastra/core/storage';
5
5
  import { Entity, Service } from 'electrodb';
6
6
  import { MessageList } from '@mastra/core/agent';
7
+ import { saveScorePayloadSchema } from '@mastra/core/scores';
7
8
 
8
9
  // src/storage/index.ts
9
10
 
@@ -370,6 +371,10 @@ var scoreEntity = new Entity({
370
371
  type: "string",
371
372
  required: false
372
373
  },
374
+ spanId: {
375
+ type: "string",
376
+ required: false
377
+ },
373
378
  runId: {
374
379
  type: "string",
375
380
  required: true
@@ -418,6 +423,10 @@ var scoreEntity = new Entity({
418
423
  return value;
419
424
  }
420
425
  },
426
+ preprocessPrompt: {
427
+ type: "string",
428
+ required: false
429
+ },
421
430
  preprocessStepResult: {
422
431
  type: "string",
423
432
  required: false,
@@ -656,6 +665,11 @@ var scoreEntity = new Entity({
656
665
  index: "gsi6",
657
666
  pk: { field: "gsi6pk", composite: ["entity", "threadId"] },
658
667
  sk: { field: "gsi6sk", composite: ["createdAt"] }
668
+ },
669
+ bySpan: {
670
+ index: "gsi7",
671
+ pk: { field: "gsi7pk", composite: ["entity", "traceId", "spanId"] },
672
+ sk: { field: "gsi7sk", composite: ["createdAt"] }
659
673
  }
660
674
  }
661
675
  });
@@ -1556,7 +1570,8 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1556
1570
  const paginatedMessages = messages.slice(start, end);
1557
1571
  const hasMore = end < total;
1558
1572
  const list = new MessageList({ threadId, resourceId }).add(paginatedMessages, "memory");
1559
- const finalMessages = format === "v2" ? list.get.all.v2() : list.get.all.v1();
1573
+ let finalMessages = format === "v2" ? list.get.all.v2() : list.get.all.v1();
1574
+ finalMessages = finalMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
1560
1575
  return {
1561
1576
  messages: finalMessages,
1562
1577
  total,
@@ -2147,8 +2162,17 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2147
2162
  }
2148
2163
  // Helper function to parse score data (handle JSON fields)
2149
2164
  parseScoreData(data) {
2165
+ const result = {};
2166
+ for (const key of Object.keys(SCORERS_SCHEMA)) {
2167
+ if (["traceId", "resourceId", "threadId", "spanId"].includes(key)) {
2168
+ result[key] = data[key] === "" ? null : data[key];
2169
+ continue;
2170
+ }
2171
+ result[key] = data[key];
2172
+ }
2173
+ result.entity = data.entityData ? data.entityData : null;
2150
2174
  return {
2151
- ...data,
2175
+ ...result,
2152
2176
  // Convert date strings back to Date objects for consistency
2153
2177
  createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
2154
2178
  updatedAt: data.updatedAt ? new Date(data.updatedAt) : /* @__PURE__ */ new Date()
@@ -2176,34 +2200,47 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2176
2200
  }
2177
2201
  }
2178
2202
  async saveScore(score) {
2179
- this.logger.debug("Saving score", { scorerId: score.scorerId, runId: score.runId });
2203
+ let validatedScore;
2204
+ try {
2205
+ validatedScore = saveScorePayloadSchema.parse(score);
2206
+ } catch (error) {
2207
+ throw new MastraError(
2208
+ {
2209
+ id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
2210
+ domain: ErrorDomain.STORAGE,
2211
+ category: ErrorCategory.THIRD_PARTY
2212
+ },
2213
+ error
2214
+ );
2215
+ }
2180
2216
  const now = /* @__PURE__ */ new Date();
2181
2217
  const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2182
2218
  const scoreData = {
2183
2219
  entity: "score",
2184
2220
  id: scoreId,
2185
- scorerId: score.scorerId,
2186
- traceId: score.traceId || "",
2187
- runId: score.runId,
2188
- scorer: typeof score.scorer === "string" ? score.scorer : JSON.stringify(score.scorer),
2189
- preprocessStepResult: typeof score.preprocessStepResult === "string" ? score.preprocessStepResult : JSON.stringify(score.preprocessStepResult),
2190
- analyzeStepResult: typeof score.analyzeStepResult === "string" ? score.analyzeStepResult : JSON.stringify(score.analyzeStepResult),
2191
- score: score.score,
2192
- reason: score.reason,
2193
- preprocessPrompt: score.preprocessPrompt,
2194
- generateScorePrompt: score.generateScorePrompt,
2195
- analyzePrompt: score.analyzePrompt,
2196
- reasonPrompt: score.reasonPrompt,
2197
- input: typeof score.input === "string" ? score.input : JSON.stringify(score.input),
2198
- output: typeof score.output === "string" ? score.output : JSON.stringify(score.output),
2199
- additionalContext: typeof score.additionalContext === "string" ? score.additionalContext : JSON.stringify(score.additionalContext),
2200
- runtimeContext: typeof score.runtimeContext === "string" ? score.runtimeContext : JSON.stringify(score.runtimeContext),
2201
- entityType: score.entityType,
2202
- entityData: typeof score.entity === "string" ? score.entity : JSON.stringify(score.entity),
2203
- entityId: score.entityId,
2204
- source: score.source,
2205
- resourceId: score.resourceId || "",
2206
- threadId: score.threadId || "",
2221
+ scorerId: validatedScore.scorerId,
2222
+ traceId: validatedScore.traceId || "",
2223
+ spanId: validatedScore.spanId || "",
2224
+ runId: validatedScore.runId,
2225
+ scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
2226
+ preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
2227
+ analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
2228
+ score: validatedScore.score,
2229
+ reason: validatedScore.reason,
2230
+ preprocessPrompt: validatedScore.preprocessPrompt,
2231
+ generateScorePrompt: validatedScore.generateScorePrompt,
2232
+ generateReasonPrompt: validatedScore.generateReasonPrompt,
2233
+ analyzePrompt: validatedScore.analyzePrompt,
2234
+ input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
2235
+ output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
2236
+ additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
2237
+ runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
2238
+ entityType: validatedScore.entityType,
2239
+ entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
2240
+ entityId: validatedScore.entityId,
2241
+ source: validatedScore.source,
2242
+ resourceId: validatedScore.resourceId || "",
2243
+ threadId: validatedScore.threadId || "",
2207
2244
  createdAt: now.toISOString(),
2208
2245
  updatedAt: now.toISOString()
2209
2246
  };
@@ -2356,6 +2393,43 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2356
2393
  );
2357
2394
  }
2358
2395
  }
2396
+ async getScoresBySpan({
2397
+ traceId,
2398
+ spanId,
2399
+ pagination
2400
+ }) {
2401
+ this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
2402
+ try {
2403
+ const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
2404
+ const results = await query.go();
2405
+ const allScores = results.data.map((data) => this.parseScoreData(data));
2406
+ allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2407
+ const startIndex = pagination.page * pagination.perPage;
2408
+ const endIndex = startIndex + pagination.perPage;
2409
+ const paginatedScores = allScores.slice(startIndex, endIndex);
2410
+ const total = allScores.length;
2411
+ const hasMore = endIndex < total;
2412
+ return {
2413
+ scores: paginatedScores,
2414
+ pagination: {
2415
+ total,
2416
+ page: pagination.page,
2417
+ perPage: pagination.perPage,
2418
+ hasMore
2419
+ }
2420
+ };
2421
+ } catch (error) {
2422
+ throw new MastraError(
2423
+ {
2424
+ id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
2425
+ domain: ErrorDomain.STORAGE,
2426
+ category: ErrorCategory.THIRD_PARTY,
2427
+ details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
2428
+ },
2429
+ error
2430
+ );
2431
+ }
2432
+ }
2359
2433
  };
2360
2434
  var TracesStorageDynamoDB = class extends TracesStorage {
2361
2435
  service;
@@ -2638,7 +2712,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2638
2712
  workflow_name: workflowName,
2639
2713
  run_id: runId,
2640
2714
  snapshot: JSON.stringify(snapshot),
2641
- // Stringify the snapshot object
2642
2715
  createdAt: now,
2643
2716
  updatedAt: now,
2644
2717
  resourceId
@@ -2710,6 +2783,11 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2710
2783
  });
2711
2784
  if (pageResults.data && pageResults.data.length > 0) {
2712
2785
  let pageFilteredData = pageResults.data;
2786
+ if (args?.status) {
2787
+ pageFilteredData = pageFilteredData.filter((snapshot) => {
2788
+ return snapshot.snapshot.status === args.status;
2789
+ });
2790
+ }
2713
2791
  if (args?.fromDate || args?.toDate) {
2714
2792
  pageFilteredData = pageFilteredData.filter((snapshot) => {
2715
2793
  const createdAt = new Date(snapshot.createdAt);
@@ -2869,7 +2947,8 @@ var DynamoDBStore = class extends MastraStorage {
2869
2947
  resourceWorkingMemory: true,
2870
2948
  hasColumn: false,
2871
2949
  createTable: false,
2872
- deleteMessages: false
2950
+ deleteMessages: false,
2951
+ getScoresBySpan: true
2873
2952
  };
2874
2953
  }
2875
2954
  /**
@@ -3128,6 +3207,13 @@ var DynamoDBStore = class extends MastraStorage {
3128
3207
  }) {
3129
3208
  return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
3130
3209
  }
3210
+ async getScoresBySpan({
3211
+ traceId,
3212
+ spanId,
3213
+ pagination
3214
+ }) {
3215
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
3216
+ }
3131
3217
  };
3132
3218
 
3133
3219
  export { DynamoDBStore };