@mastra/dynamodb 0.15.3 → 0.15.4
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 +22 -0
- package/dist/entities/index.d.ts +15 -0
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/score.d.ts +15 -0
- package/dist/entities/score.d.ts.map +1 -1
- package/dist/index.cjs +92 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +92 -24
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/score/index.d.ts +8 -0
- package/dist/storage/domains/score/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +9 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
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
|
-
|
|
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:
|
|
2186
|
-
traceId:
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
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;
|
|
@@ -2869,7 +2929,8 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
2869
2929
|
resourceWorkingMemory: true,
|
|
2870
2930
|
hasColumn: false,
|
|
2871
2931
|
createTable: false,
|
|
2872
|
-
deleteMessages: false
|
|
2932
|
+
deleteMessages: false,
|
|
2933
|
+
getScoresBySpan: true
|
|
2873
2934
|
};
|
|
2874
2935
|
}
|
|
2875
2936
|
/**
|
|
@@ -3128,6 +3189,13 @@ var DynamoDBStore = class extends MastraStorage {
|
|
|
3128
3189
|
}) {
|
|
3129
3190
|
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
3130
3191
|
}
|
|
3192
|
+
async getScoresBySpan({
|
|
3193
|
+
traceId,
|
|
3194
|
+
spanId,
|
|
3195
|
+
pagination
|
|
3196
|
+
}) {
|
|
3197
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
3198
|
+
}
|
|
3131
3199
|
};
|
|
3132
3200
|
|
|
3133
3201
|
export { DynamoDBStore };
|