@mastra/lance 0.0.0-new-scorer-api-20250801075530 → 0.0.0-playground-studio-cloud-20251031080052
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 +430 -3
- package/README.md +3 -3
- package/dist/index.cjs +182 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +183 -225
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +10 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +13 -2
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +21 -2
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +45 -20
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +3 -3
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +22 -8
- package/dist/storage/domains/traces/index.d.ts +0 -34
- package/dist/storage/domains/traces/index.d.ts.map +0 -1
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -2
- package/src/storage/domains/legacy-evals/index.ts +0 -156
- package/src/storage/domains/memory/index.ts +0 -947
- package/src/storage/domains/operations/index.ts +0 -489
- package/src/storage/domains/scores/index.ts +0 -221
- package/src/storage/domains/traces/index.ts +0 -212
- package/src/storage/domains/utils.ts +0 -158
- package/src/storage/domains/workflows/index.ts +0 -207
- package/src/storage/index.test.ts +0 -10
- package/src/storage/index.ts +0 -442
- package/src/vector/filter.test.ts +0 -295
- package/src/vector/filter.ts +0 -443
- package/src/vector/index.test.ts +0 -1493
- package/src/vector/index.ts +0 -941
- package/src/vector/types.ts +0 -16
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -22
- package/vitest.config.ts +0 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './storage';
|
|
2
|
-
export * from './vector';
|
|
1
|
+
export * from './storage/index.js';
|
|
2
|
+
export * from './vector/index.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { connect, Index } from '@lancedb/lancedb';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { MastraStorage, StoreOperations, LegacyEvalsStorage, TABLE_EVALS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, resolveMessageLimit, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS,
|
|
3
|
+
import { MastraStorage, StoreOperations, LegacyEvalsStorage, TABLE_EVALS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, resolveMessageLimit, TABLE_RESOURCES, ScoresStorage, TABLE_SCORERS, 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
|
|
|
@@ -59,9 +60,9 @@ var StoreLegacyEvalsLance = class extends LegacyEvalsStorage {
|
|
|
59
60
|
conditions.push(`agent_name = '${options.agentName}'`);
|
|
60
61
|
}
|
|
61
62
|
if (options.type === "live") {
|
|
62
|
-
conditions.push("
|
|
63
|
+
conditions.push("test_info IS NULL");
|
|
63
64
|
} else if (options.type === "test") {
|
|
64
|
-
conditions.push("
|
|
65
|
+
conditions.push("test_info IS NOT NULL");
|
|
65
66
|
}
|
|
66
67
|
const startDate = options.dateRange?.start || options.fromDate;
|
|
67
68
|
const endDate = options.dateRange?.end || options.toDate;
|
|
@@ -187,7 +188,6 @@ function processResultWithTypeConversion(rawResult, tableSchema) {
|
|
|
187
188
|
} else if (fieldTypeStr.includes("float64") && ["createdAt", "updatedAt"].includes(key)) {
|
|
188
189
|
processedResult[key] = new Date(processedResult[key]);
|
|
189
190
|
}
|
|
190
|
-
console.log(key, "processedResult", processedResult);
|
|
191
191
|
}
|
|
192
192
|
return processedResult;
|
|
193
193
|
}
|
|
@@ -379,6 +379,20 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
379
379
|
);
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
+
normalizeMessage(message) {
|
|
383
|
+
const { thread_id, ...rest } = message;
|
|
384
|
+
return {
|
|
385
|
+
...rest,
|
|
386
|
+
threadId: thread_id,
|
|
387
|
+
content: typeof message.content === "string" ? (() => {
|
|
388
|
+
try {
|
|
389
|
+
return JSON.parse(message.content);
|
|
390
|
+
} catch {
|
|
391
|
+
return message.content;
|
|
392
|
+
}
|
|
393
|
+
})() : message.content
|
|
394
|
+
};
|
|
395
|
+
}
|
|
382
396
|
async getMessages({
|
|
383
397
|
threadId,
|
|
384
398
|
resourceId,
|
|
@@ -387,6 +401,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
387
401
|
threadConfig
|
|
388
402
|
}) {
|
|
389
403
|
try {
|
|
404
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
390
405
|
if (threadConfig) {
|
|
391
406
|
throw new Error("ThreadConfig is not supported by LanceDB storage");
|
|
392
407
|
}
|
|
@@ -419,21 +434,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
419
434
|
allRecords,
|
|
420
435
|
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
|
|
421
436
|
);
|
|
422
|
-
const
|
|
423
|
-
const { thread_id, ...rest } = msg;
|
|
424
|
-
return {
|
|
425
|
-
...rest,
|
|
426
|
-
threadId: thread_id,
|
|
427
|
-
content: typeof msg.content === "string" ? (() => {
|
|
428
|
-
try {
|
|
429
|
-
return JSON.parse(msg.content);
|
|
430
|
-
} catch {
|
|
431
|
-
return msg.content;
|
|
432
|
-
}
|
|
433
|
-
})() : msg.content
|
|
434
|
-
};
|
|
435
|
-
});
|
|
436
|
-
const list = new MessageList({ threadId, resourceId }).add(normalized, "memory");
|
|
437
|
+
const list = new MessageList({ threadId, resourceId }).add(messages.map(this.normalizeMessage), "memory");
|
|
437
438
|
if (format === "v2") return list.get.all.v2();
|
|
438
439
|
return list.get.all.v1();
|
|
439
440
|
} catch (error) {
|
|
@@ -441,7 +442,41 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
441
442
|
{
|
|
442
443
|
id: "LANCE_STORE_GET_MESSAGES_FAILED",
|
|
443
444
|
domain: ErrorDomain.STORAGE,
|
|
444
|
-
category: ErrorCategory.THIRD_PARTY
|
|
445
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
446
|
+
details: {
|
|
447
|
+
threadId,
|
|
448
|
+
resourceId: resourceId ?? ""
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
error
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async getMessagesById({
|
|
456
|
+
messageIds,
|
|
457
|
+
format
|
|
458
|
+
}) {
|
|
459
|
+
if (messageIds.length === 0) return [];
|
|
460
|
+
try {
|
|
461
|
+
const table = await this.client.openTable(TABLE_MESSAGES);
|
|
462
|
+
const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
|
|
463
|
+
const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
|
|
464
|
+
const messages = processResultWithTypeConversion(
|
|
465
|
+
allRecords,
|
|
466
|
+
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
|
|
467
|
+
);
|
|
468
|
+
const list = new MessageList().add(messages.map(this.normalizeMessage), "memory");
|
|
469
|
+
if (format === `v1`) return list.get.all.v1();
|
|
470
|
+
return list.get.all.v2();
|
|
471
|
+
} catch (error) {
|
|
472
|
+
throw new MastraError(
|
|
473
|
+
{
|
|
474
|
+
id: "LANCE_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
475
|
+
domain: ErrorDomain.STORAGE,
|
|
476
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
477
|
+
details: {
|
|
478
|
+
messageIds: JSON.stringify(messageIds)
|
|
479
|
+
}
|
|
445
480
|
},
|
|
446
481
|
error
|
|
447
482
|
);
|
|
@@ -582,13 +617,11 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
582
617
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
583
618
|
}
|
|
584
619
|
async getMessagesPaginated(args) {
|
|
620
|
+
const { threadId, resourceId, selectBy, format = "v1" } = args;
|
|
621
|
+
const page = selectBy?.pagination?.page ?? 0;
|
|
622
|
+
const perPage = selectBy?.pagination?.perPage ?? 10;
|
|
585
623
|
try {
|
|
586
|
-
|
|
587
|
-
if (!threadId) {
|
|
588
|
-
throw new Error("Thread ID is required for getMessagesPaginated");
|
|
589
|
-
}
|
|
590
|
-
const page = selectBy?.pagination?.page ?? 0;
|
|
591
|
-
const perPage = selectBy?.pagination?.perPage ?? 10;
|
|
624
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
592
625
|
const dateRange = selectBy?.pagination?.dateRange;
|
|
593
626
|
const fromDate = dateRange?.start;
|
|
594
627
|
const toDate = dateRange?.end;
|
|
@@ -690,14 +723,21 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
690
723
|
hasMore: total > (page + 1) * perPage
|
|
691
724
|
};
|
|
692
725
|
} catch (error) {
|
|
693
|
-
|
|
726
|
+
const mastraError = new MastraError(
|
|
694
727
|
{
|
|
695
728
|
id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
696
729
|
domain: ErrorDomain.STORAGE,
|
|
697
|
-
category: ErrorCategory.THIRD_PARTY
|
|
730
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
731
|
+
details: {
|
|
732
|
+
threadId,
|
|
733
|
+
resourceId: resourceId ?? ""
|
|
734
|
+
}
|
|
698
735
|
},
|
|
699
736
|
error
|
|
700
737
|
);
|
|
738
|
+
this.logger?.trackException?.(mastraError);
|
|
739
|
+
this.logger?.error?.(mastraError.toString());
|
|
740
|
+
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
701
741
|
}
|
|
702
742
|
}
|
|
703
743
|
/**
|
|
@@ -1224,7 +1264,7 @@ var StoreOperationsLance = class extends StoreOperations {
|
|
|
1224
1264
|
processedRecord[key] = JSON.stringify(processedRecord[key]);
|
|
1225
1265
|
}
|
|
1226
1266
|
}
|
|
1227
|
-
console.
|
|
1267
|
+
console.info(await table.schema());
|
|
1228
1268
|
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
|
|
1229
1269
|
} catch (error) {
|
|
1230
1270
|
throw new MastraError(
|
|
@@ -1274,7 +1314,6 @@ var StoreOperationsLance = class extends StoreOperations {
|
|
|
1274
1314
|
}
|
|
1275
1315
|
return processedRecord;
|
|
1276
1316
|
});
|
|
1277
|
-
console.log(processedRecords);
|
|
1278
1317
|
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(processedRecords);
|
|
1279
1318
|
} catch (error) {
|
|
1280
1319
|
throw new MastraError(
|
|
@@ -1358,12 +1397,27 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1358
1397
|
this.client = client;
|
|
1359
1398
|
}
|
|
1360
1399
|
async saveScore(score) {
|
|
1400
|
+
let validatedScore;
|
|
1361
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
|
+
}
|
|
1414
|
+
try {
|
|
1415
|
+
const id = crypto.randomUUID();
|
|
1362
1416
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1363
1417
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
1364
1418
|
const allowedFields = new Set(schema.fields.map((f) => f.name));
|
|
1365
1419
|
const filteredScore = {};
|
|
1366
|
-
Object.keys(
|
|
1420
|
+
Object.keys(validatedScore).forEach((key) => {
|
|
1367
1421
|
if (allowedFields.has(key)) {
|
|
1368
1422
|
filteredScore[key] = score[key];
|
|
1369
1423
|
}
|
|
@@ -1373,7 +1427,7 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1373
1427
|
filteredScore[key] = JSON.stringify(filteredScore[key]);
|
|
1374
1428
|
}
|
|
1375
1429
|
}
|
|
1376
|
-
|
|
1430
|
+
filteredScore.id = id;
|
|
1377
1431
|
await table.add([filteredScore], { mode: "append" });
|
|
1378
1432
|
return { score };
|
|
1379
1433
|
} catch (error) {
|
|
@@ -1412,18 +1466,35 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1412
1466
|
}
|
|
1413
1467
|
async getScoresByScorerId({
|
|
1414
1468
|
scorerId,
|
|
1415
|
-
pagination
|
|
1469
|
+
pagination,
|
|
1470
|
+
entityId,
|
|
1471
|
+
entityType,
|
|
1472
|
+
source
|
|
1416
1473
|
}) {
|
|
1417
1474
|
try {
|
|
1418
1475
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1419
1476
|
const { page = 0, perPage = 10 } = pagination || {};
|
|
1420
1477
|
const offset = page * perPage;
|
|
1421
|
-
|
|
1478
|
+
let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1479
|
+
if (source) {
|
|
1480
|
+
query = query.where(`\`source\` = '${source}'`);
|
|
1481
|
+
}
|
|
1482
|
+
if (entityId) {
|
|
1483
|
+
query = query.where(`\`entityId\` = '${entityId}'`);
|
|
1484
|
+
}
|
|
1485
|
+
if (entityType) {
|
|
1486
|
+
query = query.where(`\`entityType\` = '${entityType}'`);
|
|
1487
|
+
}
|
|
1488
|
+
query = query.limit(perPage);
|
|
1422
1489
|
if (offset > 0) query.offset(offset);
|
|
1423
1490
|
const records = await query.toArray();
|
|
1424
1491
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
1425
1492
|
const scores = processResultWithTypeConversion(records, schema);
|
|
1426
|
-
|
|
1493
|
+
let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1494
|
+
if (source) {
|
|
1495
|
+
totalQuery = totalQuery.where(`\`source\` = '${source}'`);
|
|
1496
|
+
}
|
|
1497
|
+
const allRecords = await totalQuery.toArray();
|
|
1427
1498
|
const total = allRecords.length;
|
|
1428
1499
|
return {
|
|
1429
1500
|
pagination: {
|
|
@@ -1522,198 +1593,44 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1522
1593
|
);
|
|
1523
1594
|
}
|
|
1524
1595
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
constructor({ client, operations }) {
|
|
1530
|
-
super();
|
|
1531
|
-
this.client = client;
|
|
1532
|
-
this.operations = operations;
|
|
1533
|
-
}
|
|
1534
|
-
async saveTrace({ trace }) {
|
|
1535
|
-
try {
|
|
1536
|
-
const table = await this.client.openTable(TABLE_TRACES);
|
|
1537
|
-
const record = {
|
|
1538
|
-
...trace,
|
|
1539
|
-
attributes: JSON.stringify(trace.attributes),
|
|
1540
|
-
status: JSON.stringify(trace.status),
|
|
1541
|
-
events: JSON.stringify(trace.events),
|
|
1542
|
-
links: JSON.stringify(trace.links),
|
|
1543
|
-
other: JSON.stringify(trace.other)
|
|
1544
|
-
};
|
|
1545
|
-
await table.add([record], { mode: "append" });
|
|
1546
|
-
return trace;
|
|
1547
|
-
} catch (error) {
|
|
1548
|
-
throw new MastraError(
|
|
1549
|
-
{
|
|
1550
|
-
id: "LANCE_STORE_SAVE_TRACE_FAILED",
|
|
1551
|
-
domain: ErrorDomain.STORAGE,
|
|
1552
|
-
category: ErrorCategory.THIRD_PARTY
|
|
1553
|
-
},
|
|
1554
|
-
error
|
|
1555
|
-
);
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
async getTraceById({ traceId }) {
|
|
1559
|
-
try {
|
|
1560
|
-
const table = await this.client.openTable(TABLE_TRACES);
|
|
1561
|
-
const query = table.query().where(`id = '${traceId}'`);
|
|
1562
|
-
const records = await query.toArray();
|
|
1563
|
-
return records[0];
|
|
1564
|
-
} catch (error) {
|
|
1565
|
-
throw new MastraError(
|
|
1566
|
-
{
|
|
1567
|
-
id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
|
|
1568
|
-
domain: ErrorDomain.STORAGE,
|
|
1569
|
-
category: ErrorCategory.THIRD_PARTY
|
|
1570
|
-
},
|
|
1571
|
-
error
|
|
1572
|
-
);
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
async getTraces({
|
|
1576
|
-
name,
|
|
1577
|
-
scope,
|
|
1578
|
-
page = 1,
|
|
1579
|
-
perPage = 10,
|
|
1580
|
-
attributes
|
|
1596
|
+
async getScoresBySpan({
|
|
1597
|
+
traceId,
|
|
1598
|
+
spanId,
|
|
1599
|
+
pagination
|
|
1581
1600
|
}) {
|
|
1582
1601
|
try {
|
|
1583
|
-
const table = await this.client.openTable(
|
|
1584
|
-
const
|
|
1585
|
-
if (name) {
|
|
1586
|
-
query.where(`name = '${name}'`);
|
|
1587
|
-
}
|
|
1588
|
-
if (scope) {
|
|
1589
|
-
query.where(`scope = '${scope}'`);
|
|
1590
|
-
}
|
|
1591
|
-
if (attributes) {
|
|
1592
|
-
query.where(`attributes = '${JSON.stringify(attributes)}'`);
|
|
1593
|
-
}
|
|
1594
|
-
const offset = (page - 1) * perPage;
|
|
1595
|
-
query.limit(perPage);
|
|
1596
|
-
if (offset > 0) {
|
|
1597
|
-
query.offset(offset);
|
|
1598
|
-
}
|
|
1599
|
-
const records = await query.toArray();
|
|
1600
|
-
return records.map((record) => {
|
|
1601
|
-
const processed = {
|
|
1602
|
-
...record,
|
|
1603
|
-
attributes: record.attributes ? JSON.parse(record.attributes) : {},
|
|
1604
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1605
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1606
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1607
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1608
|
-
startTime: new Date(record.startTime),
|
|
1609
|
-
endTime: new Date(record.endTime),
|
|
1610
|
-
createdAt: new Date(record.createdAt)
|
|
1611
|
-
};
|
|
1612
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1613
|
-
processed.parentSpanId = "";
|
|
1614
|
-
} else {
|
|
1615
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1616
|
-
}
|
|
1617
|
-
return processed;
|
|
1618
|
-
});
|
|
1619
|
-
} catch (error) {
|
|
1620
|
-
throw new MastraError(
|
|
1621
|
-
{
|
|
1622
|
-
id: "LANCE_STORE_GET_TRACES_FAILED",
|
|
1623
|
-
domain: ErrorDomain.STORAGE,
|
|
1624
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
1625
|
-
details: { name: name ?? "", scope: scope ?? "" }
|
|
1626
|
-
},
|
|
1627
|
-
error
|
|
1628
|
-
);
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
async getTracesPaginated(args) {
|
|
1632
|
-
try {
|
|
1633
|
-
const table = await this.client.openTable(TABLE_TRACES);
|
|
1634
|
-
const query = table.query();
|
|
1635
|
-
const conditions = [];
|
|
1636
|
-
if (args.name) {
|
|
1637
|
-
conditions.push(`name = '${args.name}'`);
|
|
1638
|
-
}
|
|
1639
|
-
if (args.scope) {
|
|
1640
|
-
conditions.push(`scope = '${args.scope}'`);
|
|
1641
|
-
}
|
|
1642
|
-
if (args.attributes) {
|
|
1643
|
-
const attributesStr = JSON.stringify(args.attributes);
|
|
1644
|
-
conditions.push(`attributes LIKE '%${attributesStr.replace(/"/g, '\\"')}%'`);
|
|
1645
|
-
}
|
|
1646
|
-
if (args.dateRange?.start) {
|
|
1647
|
-
conditions.push(`\`createdAt\` >= ${args.dateRange.start.getTime()}`);
|
|
1648
|
-
}
|
|
1649
|
-
if (args.dateRange?.end) {
|
|
1650
|
-
conditions.push(`\`createdAt\` <= ${args.dateRange.end.getTime()}`);
|
|
1651
|
-
}
|
|
1652
|
-
if (conditions.length > 0) {
|
|
1653
|
-
const whereClause = conditions.join(" AND ");
|
|
1654
|
-
query.where(whereClause);
|
|
1655
|
-
}
|
|
1656
|
-
let total = 0;
|
|
1657
|
-
if (conditions.length > 0) {
|
|
1658
|
-
const countQuery = table.query().where(conditions.join(" AND "));
|
|
1659
|
-
const allRecords = await countQuery.toArray();
|
|
1660
|
-
total = allRecords.length;
|
|
1661
|
-
} else {
|
|
1662
|
-
total = await table.countRows();
|
|
1663
|
-
}
|
|
1664
|
-
const page = args.page || 0;
|
|
1665
|
-
const perPage = args.perPage || 10;
|
|
1602
|
+
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1603
|
+
const { page = 0, perPage = 10 } = pagination || {};
|
|
1666
1604
|
const offset = page * perPage;
|
|
1667
|
-
query.limit(perPage);
|
|
1668
|
-
if (offset > 0)
|
|
1669
|
-
query.offset(offset);
|
|
1670
|
-
}
|
|
1605
|
+
const query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).limit(perPage);
|
|
1606
|
+
if (offset > 0) query.offset(offset);
|
|
1671
1607
|
const records = await query.toArray();
|
|
1672
|
-
const
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
status: record.status ? JSON.parse(record.status) : {},
|
|
1677
|
-
events: record.events ? JSON.parse(record.events) : [],
|
|
1678
|
-
links: record.links ? JSON.parse(record.links) : [],
|
|
1679
|
-
other: record.other ? JSON.parse(record.other) : {},
|
|
1680
|
-
startTime: new Date(record.startTime),
|
|
1681
|
-
endTime: new Date(record.endTime),
|
|
1682
|
-
createdAt: new Date(record.createdAt)
|
|
1683
|
-
};
|
|
1684
|
-
if (processed.parentSpanId === null || processed.parentSpanId === void 0) {
|
|
1685
|
-
processed.parentSpanId = "";
|
|
1686
|
-
} else {
|
|
1687
|
-
processed.parentSpanId = String(processed.parentSpanId);
|
|
1688
|
-
}
|
|
1689
|
-
return processed;
|
|
1690
|
-
});
|
|
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;
|
|
1691
1612
|
return {
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1613
|
+
pagination: {
|
|
1614
|
+
page,
|
|
1615
|
+
perPage,
|
|
1616
|
+
total,
|
|
1617
|
+
hasMore: offset + scores.length < total
|
|
1618
|
+
},
|
|
1619
|
+
scores
|
|
1697
1620
|
};
|
|
1698
1621
|
} catch (error) {
|
|
1699
1622
|
throw new MastraError(
|
|
1700
1623
|
{
|
|
1701
|
-
id: "
|
|
1624
|
+
id: "LANCE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
|
|
1625
|
+
text: "Failed to get scores by traceId and spanId in LanceStorage",
|
|
1702
1626
|
domain: ErrorDomain.STORAGE,
|
|
1703
1627
|
category: ErrorCategory.THIRD_PARTY,
|
|
1704
|
-
details: {
|
|
1628
|
+
details: { error: error?.message }
|
|
1705
1629
|
},
|
|
1706
1630
|
error
|
|
1707
1631
|
);
|
|
1708
1632
|
}
|
|
1709
1633
|
}
|
|
1710
|
-
async batchTraceInsert({ records }) {
|
|
1711
|
-
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
1712
|
-
await this.operations.batchInsert({
|
|
1713
|
-
tableName: TABLE_TRACES,
|
|
1714
|
-
records
|
|
1715
|
-
});
|
|
1716
|
-
}
|
|
1717
1634
|
};
|
|
1718
1635
|
function parseWorkflowRun(row) {
|
|
1719
1636
|
let parsedSnapshot = row.snapshot;
|
|
@@ -1739,9 +1656,26 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1739
1656
|
super();
|
|
1740
1657
|
this.client = client;
|
|
1741
1658
|
}
|
|
1659
|
+
updateWorkflowResults({
|
|
1660
|
+
// workflowName,
|
|
1661
|
+
// runId,
|
|
1662
|
+
// stepId,
|
|
1663
|
+
// result,
|
|
1664
|
+
// runtimeContext,
|
|
1665
|
+
}) {
|
|
1666
|
+
throw new Error("Method not implemented.");
|
|
1667
|
+
}
|
|
1668
|
+
updateWorkflowState({
|
|
1669
|
+
// workflowName,
|
|
1670
|
+
// runId,
|
|
1671
|
+
// opts,
|
|
1672
|
+
}) {
|
|
1673
|
+
throw new Error("Method not implemented.");
|
|
1674
|
+
}
|
|
1742
1675
|
async persistWorkflowSnapshot({
|
|
1743
1676
|
workflowName,
|
|
1744
1677
|
runId,
|
|
1678
|
+
resourceId,
|
|
1745
1679
|
snapshot
|
|
1746
1680
|
}) {
|
|
1747
1681
|
try {
|
|
@@ -1758,6 +1692,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1758
1692
|
const record = {
|
|
1759
1693
|
workflow_name: workflowName,
|
|
1760
1694
|
run_id: runId,
|
|
1695
|
+
resourceId,
|
|
1761
1696
|
snapshot: JSON.stringify(snapshot),
|
|
1762
1697
|
createdAt,
|
|
1763
1698
|
updatedAt: now
|
|
@@ -1903,7 +1838,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1903
1838
|
instance.stores = {
|
|
1904
1839
|
operations: new StoreOperationsLance({ client: instance.lanceClient }),
|
|
1905
1840
|
workflows: new StoreWorkflowsLance({ client: instance.lanceClient }),
|
|
1906
|
-
traces: new StoreTracesLance({ client: instance.lanceClient, operations }),
|
|
1907
1841
|
scores: new StoreScoresLance({ client: instance.lanceClient }),
|
|
1908
1842
|
memory: new StoreMemoryLance({ client: instance.lanceClient, operations }),
|
|
1909
1843
|
legacyEvals: new StoreLegacyEvalsLance({ client: instance.lanceClient })
|
|
@@ -1932,7 +1866,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1932
1866
|
this.stores = {
|
|
1933
1867
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
1934
1868
|
workflows: new StoreWorkflowsLance({ client: this.lanceClient }),
|
|
1935
|
-
traces: new StoreTracesLance({ client: this.lanceClient, operations }),
|
|
1936
1869
|
scores: new StoreScoresLance({ client: this.lanceClient }),
|
|
1937
1870
|
legacyEvals: new StoreLegacyEvalsLance({ client: this.lanceClient }),
|
|
1938
1871
|
memory: new StoreMemoryLance({ client: this.lanceClient, operations })
|
|
@@ -1996,7 +1929,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1996
1929
|
resourceWorkingMemory: true,
|
|
1997
1930
|
hasColumn: true,
|
|
1998
1931
|
createTable: true,
|
|
1999
|
-
deleteMessages: false
|
|
1932
|
+
deleteMessages: false,
|
|
1933
|
+
getScoresBySpan: true
|
|
2000
1934
|
};
|
|
2001
1935
|
}
|
|
2002
1936
|
async getResourceById({ resourceId }) {
|
|
@@ -2069,6 +2003,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2069
2003
|
}) {
|
|
2070
2004
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2071
2005
|
}
|
|
2006
|
+
async getMessagesById({
|
|
2007
|
+
messageIds,
|
|
2008
|
+
format
|
|
2009
|
+
}) {
|
|
2010
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2011
|
+
}
|
|
2072
2012
|
async saveMessages(args) {
|
|
2073
2013
|
return this.stores.memory.saveMessages(args);
|
|
2074
2014
|
}
|
|
@@ -2081,15 +2021,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2081
2021
|
async updateMessages(_args) {
|
|
2082
2022
|
return this.stores.memory.updateMessages(_args);
|
|
2083
2023
|
}
|
|
2084
|
-
async getTraceById(args) {
|
|
2085
|
-
return this.stores.traces.getTraceById(args);
|
|
2086
|
-
}
|
|
2087
|
-
async getTraces(args) {
|
|
2088
|
-
return this.stores.traces.getTraces(args);
|
|
2089
|
-
}
|
|
2090
|
-
async getTracesPaginated(args) {
|
|
2091
|
-
return this.stores.traces.getTracesPaginated(args);
|
|
2092
|
-
}
|
|
2093
2024
|
async getEvalsByAgentName(agentName, type) {
|
|
2094
2025
|
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
2095
2026
|
}
|
|
@@ -2102,12 +2033,29 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2102
2033
|
async getWorkflowRunById(args) {
|
|
2103
2034
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
2104
2035
|
}
|
|
2036
|
+
async updateWorkflowResults({
|
|
2037
|
+
workflowName,
|
|
2038
|
+
runId,
|
|
2039
|
+
stepId,
|
|
2040
|
+
result,
|
|
2041
|
+
runtimeContext
|
|
2042
|
+
}) {
|
|
2043
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
2044
|
+
}
|
|
2045
|
+
async updateWorkflowState({
|
|
2046
|
+
workflowName,
|
|
2047
|
+
runId,
|
|
2048
|
+
opts
|
|
2049
|
+
}) {
|
|
2050
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
2051
|
+
}
|
|
2105
2052
|
async persistWorkflowSnapshot({
|
|
2106
2053
|
workflowName,
|
|
2107
2054
|
runId,
|
|
2055
|
+
resourceId,
|
|
2108
2056
|
snapshot
|
|
2109
2057
|
}) {
|
|
2110
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
2058
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2111
2059
|
}
|
|
2112
2060
|
async loadWorkflowSnapshot({
|
|
2113
2061
|
workflowName,
|
|
@@ -2120,9 +2068,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2120
2068
|
}
|
|
2121
2069
|
async getScoresByScorerId({
|
|
2122
2070
|
scorerId,
|
|
2071
|
+
source,
|
|
2072
|
+
entityId,
|
|
2073
|
+
entityType,
|
|
2123
2074
|
pagination
|
|
2124
2075
|
}) {
|
|
2125
|
-
return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
|
|
2076
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
|
|
2126
2077
|
}
|
|
2127
2078
|
async saveScore(_score) {
|
|
2128
2079
|
return this.stores.scores.saveScore(_score);
|
|
@@ -2140,6 +2091,13 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2140
2091
|
}) {
|
|
2141
2092
|
return this.stores.scores.getScoresByEntityId({ entityId, entityType, pagination });
|
|
2142
2093
|
}
|
|
2094
|
+
async getScoresBySpan({
|
|
2095
|
+
traceId,
|
|
2096
|
+
spanId,
|
|
2097
|
+
pagination
|
|
2098
|
+
}) {
|
|
2099
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2100
|
+
}
|
|
2143
2101
|
};
|
|
2144
2102
|
var LanceFilterTranslator = class extends BaseFilterTranslator {
|
|
2145
2103
|
translate(filter) {
|