@mastra/dynamodb 0.0.0-stream-vnext-usage-20250908171242 → 0.0.0-suspendRuntimeContextTypeFix-20250930142630

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
@@ -4,6 +4,7 @@ import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
4
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';
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
@@ -656,6 +661,11 @@ var scoreEntity = new Entity({
656
661
  index: "gsi6",
657
662
  pk: { field: "gsi6pk", composite: ["entity", "threadId"] },
658
663
  sk: { field: "gsi6sk", composite: ["createdAt"] }
664
+ },
665
+ bySpan: {
666
+ index: "gsi7",
667
+ pk: { field: "gsi7pk", composite: ["entity", "traceId", "spanId"] },
668
+ sk: { field: "gsi7sk", composite: ["createdAt"] }
659
669
  }
660
670
  }
661
671
  });
@@ -2176,34 +2186,47 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2176
2186
  }
2177
2187
  }
2178
2188
  async saveScore(score) {
2179
- this.logger.debug("Saving score", { scorerId: score.scorerId, runId: score.runId });
2189
+ let validatedScore;
2190
+ try {
2191
+ validatedScore = saveScorePayloadSchema.parse(score);
2192
+ } catch (error) {
2193
+ throw new MastraError(
2194
+ {
2195
+ id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
2196
+ domain: ErrorDomain.STORAGE,
2197
+ category: ErrorCategory.THIRD_PARTY
2198
+ },
2199
+ error
2200
+ );
2201
+ }
2180
2202
  const now = /* @__PURE__ */ new Date();
2181
2203
  const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
2182
2204
  const scoreData = {
2183
2205
  entity: "score",
2184
2206
  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 || "",
2207
+ scorerId: validatedScore.scorerId,
2208
+ traceId: validatedScore.traceId || "",
2209
+ spanId: validatedScore.spanId || "",
2210
+ runId: validatedScore.runId,
2211
+ scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
2212
+ preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
2213
+ analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
2214
+ score: validatedScore.score,
2215
+ reason: validatedScore.reason,
2216
+ preprocessPrompt: validatedScore.preprocessPrompt,
2217
+ generateScorePrompt: validatedScore.generateScorePrompt,
2218
+ generateReasonPrompt: validatedScore.generateReasonPrompt,
2219
+ analyzePrompt: validatedScore.analyzePrompt,
2220
+ input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
2221
+ output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
2222
+ additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
2223
+ runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
2224
+ entityType: validatedScore.entityType,
2225
+ entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
2226
+ entityId: validatedScore.entityId,
2227
+ source: validatedScore.source,
2228
+ resourceId: validatedScore.resourceId || "",
2229
+ threadId: validatedScore.threadId || "",
2207
2230
  createdAt: now.toISOString(),
2208
2231
  updatedAt: now.toISOString()
2209
2232
  };
@@ -2356,6 +2379,43 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2356
2379
  );
2357
2380
  }
2358
2381
  }
2382
+ async getScoresBySpan({
2383
+ traceId,
2384
+ spanId,
2385
+ pagination
2386
+ }) {
2387
+ this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
2388
+ try {
2389
+ const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
2390
+ const results = await query.go();
2391
+ const allScores = results.data.map((data) => this.parseScoreData(data));
2392
+ allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2393
+ const startIndex = pagination.page * pagination.perPage;
2394
+ const endIndex = startIndex + pagination.perPage;
2395
+ const paginatedScores = allScores.slice(startIndex, endIndex);
2396
+ const total = allScores.length;
2397
+ const hasMore = endIndex < total;
2398
+ return {
2399
+ scores: paginatedScores,
2400
+ pagination: {
2401
+ total,
2402
+ page: pagination.page,
2403
+ perPage: pagination.perPage,
2404
+ hasMore
2405
+ }
2406
+ };
2407
+ } catch (error) {
2408
+ throw new MastraError(
2409
+ {
2410
+ id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
2411
+ domain: ErrorDomain.STORAGE,
2412
+ category: ErrorCategory.THIRD_PARTY,
2413
+ details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
2414
+ },
2415
+ error
2416
+ );
2417
+ }
2418
+ }
2359
2419
  };
2360
2420
  var TracesStorageDynamoDB = class extends TracesStorage {
2361
2421
  service;
@@ -2626,11 +2686,11 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2626
2686
  async persistWorkflowSnapshot({
2627
2687
  workflowName,
2628
2688
  runId,
2689
+ resourceId,
2629
2690
  snapshot
2630
2691
  }) {
2631
2692
  this.logger.debug("Persisting workflow snapshot", { workflowName, runId });
2632
2693
  try {
2633
- const resourceId = "resourceId" in snapshot ? snapshot.resourceId : void 0;
2634
2694
  const now = (/* @__PURE__ */ new Date()).toISOString();
2635
2695
  const data = {
2636
2696
  entity: "workflow_snapshot",
@@ -2756,8 +2816,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2756
2816
  async getWorkflowRunById(args) {
2757
2817
  const { runId, workflowName } = args;
2758
2818
  this.logger.debug("Getting workflow run by ID", { runId, workflowName });
2759
- console.log("workflowName", workflowName);
2760
- console.log("runId", runId);
2761
2819
  try {
2762
2820
  if (workflowName) {
2763
2821
  this.logger.debug("WorkflowName provided, using direct GET operation.");
@@ -2767,7 +2825,6 @@ var WorkflowStorageDynamoDB = class extends WorkflowsStorage {
2767
2825
  workflow_name: workflowName,
2768
2826
  run_id: runId
2769
2827
  }).go();
2770
- console.log("result", result2);
2771
2828
  if (!result2.data) {
2772
2829
  return null;
2773
2830
  }
@@ -2872,7 +2929,8 @@ var DynamoDBStore = class extends MastraStorage {
2872
2929
  resourceWorkingMemory: true,
2873
2930
  hasColumn: false,
2874
2931
  createTable: false,
2875
- deleteMessages: false
2932
+ deleteMessages: false,
2933
+ getScoresBySpan: true
2876
2934
  };
2877
2935
  }
2878
2936
  /**
@@ -3039,9 +3097,10 @@ var DynamoDBStore = class extends MastraStorage {
3039
3097
  async persistWorkflowSnapshot({
3040
3098
  workflowName,
3041
3099
  runId,
3100
+ resourceId,
3042
3101
  snapshot
3043
3102
  }) {
3044
- return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
3103
+ return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
3045
3104
  }
3046
3105
  async loadWorkflowSnapshot({
3047
3106
  workflowName,
@@ -3130,6 +3189,13 @@ var DynamoDBStore = class extends MastraStorage {
3130
3189
  }) {
3131
3190
  return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
3132
3191
  }
3192
+ async getScoresBySpan({
3193
+ traceId,
3194
+ spanId,
3195
+ pagination
3196
+ }) {
3197
+ return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
3198
+ }
3133
3199
  };
3134
3200
 
3135
3201
  export { DynamoDBStore };