MCPcopy
hub / github.com/mastra-ai/mastra / ScoresLibSQL

Class ScoresLibSQL

stores/libsql/src/storage/domains/scores/index.ts:39–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39export class ScoresLibSQL extends ScoresStorage {
40 /**
41 * Scorer results accumulate as evals run. Single table, anchored on `createdAt`.
42 */
43 static override readonly retentionTables: RetentionTablesDescriptor = {
44 scorers: { table: TABLE_SCORERS, column: 'createdAt', indexed: true },
45 };
46
47 #db: LibSQLDB;
48 #client: Client;
49
50 constructor(config: LibSQLDomainConfig) {
51 super();
52 const client = resolveClient(config);
53 this.#client = client;
54 this.#db = new LibSQLDB({ client, maxRetries: config.maxRetries, initialBackoffMs: config.initialBackoffMs });
55 }
56
57 async init(): Promise<void> {
58 await this.#db.createTable({ tableName: TABLE_SCORERS, schema: SCORERS_SCHEMA });
59 // Add columns for backwards compatibility
60 await this.#db.alterTable({
61 tableName: TABLE_SCORERS,
62 schema: SCORERS_SCHEMA,
63 ifNotExists: ['spanId', 'requestContext', 'organizationId', 'projectId', 'batchId', 'datasetId', 'datasetItemId'],
64 });
65 }
66
67 async dangerouslyClearAll(): Promise<void> {
68 await this.#db.deleteData({ tableName: TABLE_SCORERS });
69 }
70
71 /** Delete scorer results older than the `scorers` policy's `maxAge`, batched. */
72 async prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]> {
73 const targets = resolveTargets({
74 policies,
75 descriptor: ScoresLibSQL.retentionTables,
76 order: ['scorers'],
77 });
78 return runPrune({ db: this.#db, domain: 'scores', targets, options, logger: this.logger });
79 }
80
81 async listScoresByRunId({
82 runId,
83 pagination,
84 filters,
85 }: {
86 runId: string;
87 pagination: StoragePagination;
88 filters?: ScoreTenancyFilters;
89 }): Promise<ListScoresResponse> {
90 try {
91 const { page, perPage: perPageInput } = pagination;
92
93 const conditions: string[] = [`runId = ?`];
94 const queryParams: InValue[] = [runId];
95 appendTenancyConditions(conditions, queryParams, filters);
96 const whereClause = `WHERE ${conditions.join(' AND ')}`;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…