@mastra/libsql 0.14.3-alpha.0 → 0.15.0-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 +28 -0
- package/README.md +2 -2
- package/dist/index.cjs +79 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -5
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +5 -5
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +8 -0
- package/dist/storage/domains/scores/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
|
@@ -5,6 +5,7 @@ import { MastraVector } from '@mastra/core/vector';
|
|
|
5
5
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
6
6
|
import { MastraStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, TABLE_AI_SPANS, ScoresStorage, TABLE_SCORERS, safelyParseJSON, TracesStorage, TABLE_TRACES, WorkflowsStorage, MemoryStorage, resolveMessageLimit, TABLE_MESSAGES, TABLE_THREADS, TABLE_RESOURCES, LegacyEvalsStorage, TABLE_EVALS, ObservabilityStorage, TABLE_SCHEMAS, AI_SPAN_SCHEMA } from '@mastra/core/storage';
|
|
7
7
|
import { MessageList } from '@mastra/core/agent';
|
|
8
|
+
import { saveScorePayloadSchema } from '@mastra/core/scores';
|
|
8
9
|
|
|
9
10
|
// src/vector/index.ts
|
|
10
11
|
var LibSQLFilterTranslator = class extends BaseFilterTranslator {
|
|
@@ -1949,7 +1950,13 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
|
|
|
1949
1950
|
}
|
|
1950
1951
|
async createAISpan(span) {
|
|
1951
1952
|
try {
|
|
1952
|
-
|
|
1953
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1954
|
+
const record = {
|
|
1955
|
+
...span,
|
|
1956
|
+
createdAt: now,
|
|
1957
|
+
updatedAt: now
|
|
1958
|
+
};
|
|
1959
|
+
return this.operations.insert({ tableName: TABLE_AI_SPANS, record });
|
|
1953
1960
|
} catch (error) {
|
|
1954
1961
|
throw new MastraError(
|
|
1955
1962
|
{
|
|
@@ -2123,12 +2130,13 @@ var ObservabilityLibSQL = class extends ObservabilityStorage {
|
|
|
2123
2130
|
}
|
|
2124
2131
|
async batchCreateAISpans(args) {
|
|
2125
2132
|
try {
|
|
2133
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2126
2134
|
return this.operations.batchInsert({
|
|
2127
2135
|
tableName: TABLE_AI_SPANS,
|
|
2128
2136
|
records: args.records.map((record) => ({
|
|
2129
2137
|
...record,
|
|
2130
|
-
createdAt:
|
|
2131
|
-
updatedAt:
|
|
2138
|
+
createdAt: now,
|
|
2139
|
+
updatedAt: now
|
|
2132
2140
|
}))
|
|
2133
2141
|
});
|
|
2134
2142
|
} catch (error) {
|
|
@@ -2669,6 +2677,7 @@ var ScoresLibSQL = class extends ScoresStorage {
|
|
|
2669
2677
|
return {
|
|
2670
2678
|
id: row.id,
|
|
2671
2679
|
traceId: row.traceId,
|
|
2680
|
+
spanId: row.spanId,
|
|
2672
2681
|
runId: row.runId,
|
|
2673
2682
|
scorer: scorerValue,
|
|
2674
2683
|
score: row.score,
|
|
@@ -2703,6 +2712,26 @@ var ScoresLibSQL = class extends ScoresStorage {
|
|
|
2703
2712
|
return result.rows?.[0] ? this.transformScoreRow(result.rows[0]) : null;
|
|
2704
2713
|
}
|
|
2705
2714
|
async saveScore(score) {
|
|
2715
|
+
let parsedScore;
|
|
2716
|
+
try {
|
|
2717
|
+
parsedScore = saveScorePayloadSchema.parse(score);
|
|
2718
|
+
} catch (error) {
|
|
2719
|
+
throw new MastraError(
|
|
2720
|
+
{
|
|
2721
|
+
id: "LIBSQL_STORE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
|
|
2722
|
+
domain: ErrorDomain.STORAGE,
|
|
2723
|
+
category: ErrorCategory.USER,
|
|
2724
|
+
details: {
|
|
2725
|
+
scorer: score.scorer.name,
|
|
2726
|
+
entityId: score.entityId,
|
|
2727
|
+
entityType: score.entityType,
|
|
2728
|
+
traceId: score.traceId || "",
|
|
2729
|
+
spanId: score.spanId || ""
|
|
2730
|
+
}
|
|
2731
|
+
},
|
|
2732
|
+
error
|
|
2733
|
+
);
|
|
2734
|
+
}
|
|
2706
2735
|
try {
|
|
2707
2736
|
const id = crypto.randomUUID();
|
|
2708
2737
|
await this.operations.insert({
|
|
@@ -2711,7 +2740,7 @@ var ScoresLibSQL = class extends ScoresStorage {
|
|
|
2711
2740
|
id,
|
|
2712
2741
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2713
2742
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2714
|
-
...
|
|
2743
|
+
...parsedScore
|
|
2715
2744
|
}
|
|
2716
2745
|
});
|
|
2717
2746
|
const scoreFromDb = await this.getScoreById({ id });
|
|
@@ -2757,6 +2786,43 @@ var ScoresLibSQL = class extends ScoresStorage {
|
|
|
2757
2786
|
);
|
|
2758
2787
|
}
|
|
2759
2788
|
}
|
|
2789
|
+
async getScoresBySpan({
|
|
2790
|
+
traceId,
|
|
2791
|
+
spanId,
|
|
2792
|
+
pagination
|
|
2793
|
+
}) {
|
|
2794
|
+
try {
|
|
2795
|
+
const countSQLResult = await this.client.execute({
|
|
2796
|
+
sql: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} WHERE traceId = ? AND spanId = ?`,
|
|
2797
|
+
args: [traceId, spanId]
|
|
2798
|
+
});
|
|
2799
|
+
const total = Number(countSQLResult.rows?.[0]?.count ?? 0);
|
|
2800
|
+
const result = await this.client.execute({
|
|
2801
|
+
sql: `SELECT * FROM ${TABLE_SCORERS} WHERE traceId = ? AND spanId = ? ORDER BY createdAt DESC LIMIT ? OFFSET ?`,
|
|
2802
|
+
args: [traceId, spanId, pagination.perPage + 1, pagination.page * pagination.perPage]
|
|
2803
|
+
});
|
|
2804
|
+
const hasMore = result.rows?.length > pagination.perPage;
|
|
2805
|
+
const scores = result.rows?.slice(0, pagination.perPage).map((row) => this.transformScoreRow(row)) ?? [];
|
|
2806
|
+
return {
|
|
2807
|
+
scores,
|
|
2808
|
+
pagination: {
|
|
2809
|
+
total,
|
|
2810
|
+
page: pagination.page,
|
|
2811
|
+
perPage: pagination.perPage,
|
|
2812
|
+
hasMore
|
|
2813
|
+
}
|
|
2814
|
+
};
|
|
2815
|
+
} catch (error) {
|
|
2816
|
+
throw new MastraError(
|
|
2817
|
+
{
|
|
2818
|
+
id: "LIBSQL_STORE_GET_SCORES_BY_SPAN_FAILED",
|
|
2819
|
+
domain: ErrorDomain.STORAGE,
|
|
2820
|
+
category: ErrorCategory.THIRD_PARTY
|
|
2821
|
+
},
|
|
2822
|
+
error
|
|
2823
|
+
);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2760
2826
|
};
|
|
2761
2827
|
var TracesLibSQL = class extends TracesStorage {
|
|
2762
2828
|
client;
|
|
@@ -3246,7 +3312,8 @@ var LibSQLStore = class extends MastraStorage {
|
|
|
3246
3312
|
hasColumn: true,
|
|
3247
3313
|
createTable: true,
|
|
3248
3314
|
deleteMessages: true,
|
|
3249
|
-
aiTracing: true
|
|
3315
|
+
aiTracing: true,
|
|
3316
|
+
getScoresBySpan: true
|
|
3250
3317
|
};
|
|
3251
3318
|
}
|
|
3252
3319
|
async createTable({
|
|
@@ -3459,6 +3526,13 @@ var LibSQLStore = class extends MastraStorage {
|
|
|
3459
3526
|
async getAITracesPaginated(args) {
|
|
3460
3527
|
return this.stores.observability.getAITracesPaginated(args);
|
|
3461
3528
|
}
|
|
3529
|
+
async getScoresBySpan({
|
|
3530
|
+
traceId,
|
|
3531
|
+
spanId,
|
|
3532
|
+
pagination
|
|
3533
|
+
}) {
|
|
3534
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
3535
|
+
}
|
|
3462
3536
|
async batchCreateAISpans(args) {
|
|
3463
3537
|
return this.stores.observability.batchCreateAISpans(args);
|
|
3464
3538
|
}
|