@mastra/lance 0.3.2 → 0.3.3-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/index.cjs +63 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +63 -2
- package/dist/index.js.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 +4 -4
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
|
3
3
|
import { MastraStorage, StoreOperations, LegacyEvalsStorage, TABLE_EVALS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, resolveMessageLimit, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS, TracesStorage, TABLE_TRACES, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, ensureDate } from '@mastra/core/storage';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
5
|
import { Utf8, Float64, Binary, Float32, Int32, Field, Schema } from 'apache-arrow';
|
|
6
|
+
import { saveScorePayloadSchema } from '@mastra/core/scores';
|
|
6
7
|
import { MastraVector } from '@mastra/core/vector';
|
|
7
8
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
8
9
|
|
|
@@ -1396,13 +1397,27 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1396
1397
|
this.client = client;
|
|
1397
1398
|
}
|
|
1398
1399
|
async saveScore(score) {
|
|
1400
|
+
let validatedScore;
|
|
1401
|
+
try {
|
|
1402
|
+
validatedScore = saveScorePayloadSchema.parse(score);
|
|
1403
|
+
} catch (error) {
|
|
1404
|
+
throw new MastraError(
|
|
1405
|
+
{
|
|
1406
|
+
id: "LANCE_STORAGE_SAVE_SCORE_FAILED",
|
|
1407
|
+
text: "Failed to save score in LanceStorage",
|
|
1408
|
+
domain: ErrorDomain.STORAGE,
|
|
1409
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1410
|
+
},
|
|
1411
|
+
error
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1399
1414
|
try {
|
|
1400
1415
|
const id = crypto.randomUUID();
|
|
1401
1416
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1402
1417
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
1403
1418
|
const allowedFields = new Set(schema.fields.map((f) => f.name));
|
|
1404
1419
|
const filteredScore = {};
|
|
1405
|
-
Object.keys(
|
|
1420
|
+
Object.keys(validatedScore).forEach((key) => {
|
|
1406
1421
|
if (allowedFields.has(key)) {
|
|
1407
1422
|
filteredScore[key] = score[key];
|
|
1408
1423
|
}
|
|
@@ -1578,6 +1593,44 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1578
1593
|
);
|
|
1579
1594
|
}
|
|
1580
1595
|
}
|
|
1596
|
+
async getScoresBySpan({
|
|
1597
|
+
traceId,
|
|
1598
|
+
spanId,
|
|
1599
|
+
pagination
|
|
1600
|
+
}) {
|
|
1601
|
+
try {
|
|
1602
|
+
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1603
|
+
const { page = 0, perPage = 10 } = pagination || {};
|
|
1604
|
+
const offset = page * perPage;
|
|
1605
|
+
const query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).limit(perPage);
|
|
1606
|
+
if (offset > 0) query.offset(offset);
|
|
1607
|
+
const records = await query.toArray();
|
|
1608
|
+
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
1609
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1610
|
+
const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
|
|
1611
|
+
const total = allRecords.length;
|
|
1612
|
+
return {
|
|
1613
|
+
pagination: {
|
|
1614
|
+
page,
|
|
1615
|
+
perPage,
|
|
1616
|
+
total,
|
|
1617
|
+
hasMore: offset + scores.length < total
|
|
1618
|
+
},
|
|
1619
|
+
scores
|
|
1620
|
+
};
|
|
1621
|
+
} catch (error) {
|
|
1622
|
+
throw new MastraError(
|
|
1623
|
+
{
|
|
1624
|
+
id: "LANCE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
|
|
1625
|
+
text: "Failed to get scores by traceId and spanId in LanceStorage",
|
|
1626
|
+
domain: ErrorDomain.STORAGE,
|
|
1627
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1628
|
+
details: { error: error?.message }
|
|
1629
|
+
},
|
|
1630
|
+
error
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1581
1634
|
};
|
|
1582
1635
|
var StoreTracesLance = class extends TracesStorage {
|
|
1583
1636
|
client;
|
|
@@ -2070,7 +2123,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2070
2123
|
resourceWorkingMemory: true,
|
|
2071
2124
|
hasColumn: true,
|
|
2072
2125
|
createTable: true,
|
|
2073
|
-
deleteMessages: false
|
|
2126
|
+
deleteMessages: false,
|
|
2127
|
+
getScoresBySpan: true
|
|
2074
2128
|
};
|
|
2075
2129
|
}
|
|
2076
2130
|
async getResourceById({ resourceId }) {
|
|
@@ -2240,6 +2294,13 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2240
2294
|
}) {
|
|
2241
2295
|
return this.stores.scores.getScoresByEntityId({ entityId, entityType, pagination });
|
|
2242
2296
|
}
|
|
2297
|
+
async getScoresBySpan({
|
|
2298
|
+
traceId,
|
|
2299
|
+
spanId,
|
|
2300
|
+
pagination
|
|
2301
|
+
}) {
|
|
2302
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2303
|
+
}
|
|
2243
2304
|
};
|
|
2244
2305
|
var LanceFilterTranslator = class extends BaseFilterTranslator {
|
|
2245
2306
|
translate(filter) {
|