@mastra/dynamodb 0.15.3 → 0.15.4-alpha.0
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 +11 -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 +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @mastra/dynamodb
|
|
2
2
|
|
|
3
|
+
## 0.15.4-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
|
|
8
|
+
|
|
9
|
+
- Dynamodb support fetch scores by trace and span id ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
|
|
12
|
+
- @mastra/core@0.19.0-alpha.1
|
|
13
|
+
|
|
3
14
|
## 0.15.3
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -534,6 +534,10 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
|
|
|
534
534
|
type: "string";
|
|
535
535
|
required: false;
|
|
536
536
|
};
|
|
537
|
+
spanId: {
|
|
538
|
+
type: "string";
|
|
539
|
+
required: false;
|
|
540
|
+
};
|
|
537
541
|
runId: {
|
|
538
542
|
type: "string";
|
|
539
543
|
required: true;
|
|
@@ -740,6 +744,17 @@ export declare function getElectroDbService(client: DynamoDBDocumentClient, tabl
|
|
|
740
744
|
composite: "createdAt"[];
|
|
741
745
|
};
|
|
742
746
|
};
|
|
747
|
+
bySpan: {
|
|
748
|
+
index: string;
|
|
749
|
+
pk: {
|
|
750
|
+
field: string;
|
|
751
|
+
composite: ("entity" | "traceId" | "spanId")[];
|
|
752
|
+
};
|
|
753
|
+
sk: {
|
|
754
|
+
field: string;
|
|
755
|
+
composite: "createdAt"[];
|
|
756
|
+
};
|
|
757
|
+
};
|
|
743
758
|
};
|
|
744
759
|
}>;
|
|
745
760
|
}>;
|
|
@@ -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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgBpF"}
|
package/dist/entities/score.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export declare const scoreEntity: Entity<string, string, string, {
|
|
|
18
18
|
type: "string";
|
|
19
19
|
required: false;
|
|
20
20
|
};
|
|
21
|
+
spanId: {
|
|
22
|
+
type: "string";
|
|
23
|
+
required: false;
|
|
24
|
+
};
|
|
21
25
|
runId: {
|
|
22
26
|
type: "string";
|
|
23
27
|
required: true;
|
|
@@ -224,6 +228,17 @@ export declare const scoreEntity: Entity<string, string, string, {
|
|
|
224
228
|
composite: "createdAt"[];
|
|
225
229
|
};
|
|
226
230
|
};
|
|
231
|
+
bySpan: {
|
|
232
|
+
index: string;
|
|
233
|
+
pk: {
|
|
234
|
+
field: string;
|
|
235
|
+
composite: ("entity" | "traceId" | "spanId")[];
|
|
236
|
+
};
|
|
237
|
+
sk: {
|
|
238
|
+
field: string;
|
|
239
|
+
composite: "createdAt"[];
|
|
240
|
+
};
|
|
241
|
+
};
|
|
227
242
|
};
|
|
228
243
|
}>;
|
|
229
244
|
//# sourceMappingURL=score.d.ts.map
|
|
@@ -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
|
|
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,MAAM;;;;;0BAgBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;0BAoBN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;0BAMhC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuExB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var error = require('@mastra/core/error');
|
|
|
6
6
|
var storage = require('@mastra/core/storage');
|
|
7
7
|
var electrodb = require('electrodb');
|
|
8
8
|
var agent = require('@mastra/core/agent');
|
|
9
|
+
var scores = require('@mastra/core/scores');
|
|
9
10
|
|
|
10
11
|
// src/storage/index.ts
|
|
11
12
|
|
|
@@ -372,6 +373,10 @@ var scoreEntity = new electrodb.Entity({
|
|
|
372
373
|
type: "string",
|
|
373
374
|
required: false
|
|
374
375
|
},
|
|
376
|
+
spanId: {
|
|
377
|
+
type: "string",
|
|
378
|
+
required: false
|
|
379
|
+
},
|
|
375
380
|
runId: {
|
|
376
381
|
type: "string",
|
|
377
382
|
required: true
|
|
@@ -658,6 +663,11 @@ var scoreEntity = new electrodb.Entity({
|
|
|
658
663
|
index: "gsi6",
|
|
659
664
|
pk: { field: "gsi6pk", composite: ["entity", "threadId"] },
|
|
660
665
|
sk: { field: "gsi6sk", composite: ["createdAt"] }
|
|
666
|
+
},
|
|
667
|
+
bySpan: {
|
|
668
|
+
index: "gsi7",
|
|
669
|
+
pk: { field: "gsi7pk", composite: ["entity", "traceId", "spanId"] },
|
|
670
|
+
sk: { field: "gsi7sk", composite: ["createdAt"] }
|
|
661
671
|
}
|
|
662
672
|
}
|
|
663
673
|
});
|
|
@@ -2178,34 +2188,47 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2178
2188
|
}
|
|
2179
2189
|
}
|
|
2180
2190
|
async saveScore(score) {
|
|
2181
|
-
|
|
2191
|
+
let validatedScore;
|
|
2192
|
+
try {
|
|
2193
|
+
validatedScore = scores.saveScorePayloadSchema.parse(score);
|
|
2194
|
+
} catch (error$1) {
|
|
2195
|
+
throw new error.MastraError(
|
|
2196
|
+
{
|
|
2197
|
+
id: "STORAGE_DYNAMODB_STORE_SAVE_SCORE_FAILED",
|
|
2198
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2199
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
2200
|
+
},
|
|
2201
|
+
error$1
|
|
2202
|
+
);
|
|
2203
|
+
}
|
|
2182
2204
|
const now = /* @__PURE__ */ new Date();
|
|
2183
2205
|
const scoreId = `score-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
2184
2206
|
const scoreData = {
|
|
2185
2207
|
entity: "score",
|
|
2186
2208
|
id: scoreId,
|
|
2187
|
-
scorerId:
|
|
2188
|
-
traceId:
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
+
scorerId: validatedScore.scorerId,
|
|
2210
|
+
traceId: validatedScore.traceId || "",
|
|
2211
|
+
spanId: validatedScore.spanId || "",
|
|
2212
|
+
runId: validatedScore.runId,
|
|
2213
|
+
scorer: typeof validatedScore.scorer === "string" ? validatedScore.scorer : JSON.stringify(validatedScore.scorer),
|
|
2214
|
+
preprocessStepResult: typeof validatedScore.preprocessStepResult === "string" ? validatedScore.preprocessStepResult : JSON.stringify(validatedScore.preprocessStepResult),
|
|
2215
|
+
analyzeStepResult: typeof validatedScore.analyzeStepResult === "string" ? validatedScore.analyzeStepResult : JSON.stringify(validatedScore.analyzeStepResult),
|
|
2216
|
+
score: validatedScore.score,
|
|
2217
|
+
reason: validatedScore.reason,
|
|
2218
|
+
preprocessPrompt: validatedScore.preprocessPrompt,
|
|
2219
|
+
generateScorePrompt: validatedScore.generateScorePrompt,
|
|
2220
|
+
generateReasonPrompt: validatedScore.generateReasonPrompt,
|
|
2221
|
+
analyzePrompt: validatedScore.analyzePrompt,
|
|
2222
|
+
input: typeof validatedScore.input === "string" ? validatedScore.input : JSON.stringify(validatedScore.input),
|
|
2223
|
+
output: typeof validatedScore.output === "string" ? validatedScore.output : JSON.stringify(validatedScore.output),
|
|
2224
|
+
additionalContext: typeof validatedScore.additionalContext === "string" ? validatedScore.additionalContext : JSON.stringify(validatedScore.additionalContext),
|
|
2225
|
+
runtimeContext: typeof validatedScore.runtimeContext === "string" ? validatedScore.runtimeContext : JSON.stringify(validatedScore.runtimeContext),
|
|
2226
|
+
entityType: validatedScore.entityType,
|
|
2227
|
+
entityData: typeof validatedScore.entity === "string" ? validatedScore.entity : JSON.stringify(validatedScore.entity),
|
|
2228
|
+
entityId: validatedScore.entityId,
|
|
2229
|
+
source: validatedScore.source,
|
|
2230
|
+
resourceId: validatedScore.resourceId || "",
|
|
2231
|
+
threadId: validatedScore.threadId || "",
|
|
2209
2232
|
createdAt: now.toISOString(),
|
|
2210
2233
|
updatedAt: now.toISOString()
|
|
2211
2234
|
};
|
|
@@ -2358,6 +2381,43 @@ var ScoresStorageDynamoDB = class extends storage.ScoresStorage {
|
|
|
2358
2381
|
);
|
|
2359
2382
|
}
|
|
2360
2383
|
}
|
|
2384
|
+
async getScoresBySpan({
|
|
2385
|
+
traceId,
|
|
2386
|
+
spanId,
|
|
2387
|
+
pagination
|
|
2388
|
+
}) {
|
|
2389
|
+
this.logger.debug("Getting scores by span", { traceId, spanId, pagination });
|
|
2390
|
+
try {
|
|
2391
|
+
const query = this.service.entities.score.query.bySpan({ entity: "score", traceId, spanId });
|
|
2392
|
+
const results = await query.go();
|
|
2393
|
+
const allScores = results.data.map((data) => this.parseScoreData(data));
|
|
2394
|
+
allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
2395
|
+
const startIndex = pagination.page * pagination.perPage;
|
|
2396
|
+
const endIndex = startIndex + pagination.perPage;
|
|
2397
|
+
const paginatedScores = allScores.slice(startIndex, endIndex);
|
|
2398
|
+
const total = allScores.length;
|
|
2399
|
+
const hasMore = endIndex < total;
|
|
2400
|
+
return {
|
|
2401
|
+
scores: paginatedScores,
|
|
2402
|
+
pagination: {
|
|
2403
|
+
total,
|
|
2404
|
+
page: pagination.page,
|
|
2405
|
+
perPage: pagination.perPage,
|
|
2406
|
+
hasMore
|
|
2407
|
+
}
|
|
2408
|
+
};
|
|
2409
|
+
} catch (error$1) {
|
|
2410
|
+
throw new error.MastraError(
|
|
2411
|
+
{
|
|
2412
|
+
id: "STORAGE_DYNAMODB_STORE_GET_SCORES_BY_SPAN_FAILED",
|
|
2413
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2414
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
2415
|
+
details: { traceId, spanId, page: pagination.page, perPage: pagination.perPage }
|
|
2416
|
+
},
|
|
2417
|
+
error$1
|
|
2418
|
+
);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2361
2421
|
};
|
|
2362
2422
|
var TracesStorageDynamoDB = class extends storage.TracesStorage {
|
|
2363
2423
|
service;
|
|
@@ -2871,7 +2931,8 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
2871
2931
|
resourceWorkingMemory: true,
|
|
2872
2932
|
hasColumn: false,
|
|
2873
2933
|
createTable: false,
|
|
2874
|
-
deleteMessages: false
|
|
2934
|
+
deleteMessages: false,
|
|
2935
|
+
getScoresBySpan: true
|
|
2875
2936
|
};
|
|
2876
2937
|
}
|
|
2877
2938
|
/**
|
|
@@ -3130,6 +3191,13 @@ var DynamoDBStore = class extends storage.MastraStorage {
|
|
|
3130
3191
|
}) {
|
|
3131
3192
|
return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
|
|
3132
3193
|
}
|
|
3194
|
+
async getScoresBySpan({
|
|
3195
|
+
traceId,
|
|
3196
|
+
spanId,
|
|
3197
|
+
pagination
|
|
3198
|
+
}) {
|
|
3199
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
3200
|
+
}
|
|
3133
3201
|
};
|
|
3134
3202
|
|
|
3135
3203
|
exports.DynamoDBStore = DynamoDBStore;
|