@mastra/lance 0.0.0-update-scorers-api-20250801170445 → 0.0.0-vector-extension-schema-20250922130418
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 +313 -3
- package/README.md +3 -3
- package/dist/index.cjs +133 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +133 -33
- 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 +5 -2
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +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 +34 -4
- 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/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
|
@@ -187,7 +187,6 @@ function processResultWithTypeConversion(rawResult, tableSchema) {
|
|
|
187
187
|
} else if (fieldTypeStr.includes("float64") && ["createdAt", "updatedAt"].includes(key)) {
|
|
188
188
|
processedResult[key] = new Date(processedResult[key]);
|
|
189
189
|
}
|
|
190
|
-
console.log(key, "processedResult", processedResult);
|
|
191
190
|
}
|
|
192
191
|
return processedResult;
|
|
193
192
|
}
|
|
@@ -379,6 +378,20 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
379
378
|
);
|
|
380
379
|
}
|
|
381
380
|
}
|
|
381
|
+
normalizeMessage(message) {
|
|
382
|
+
const { thread_id, ...rest } = message;
|
|
383
|
+
return {
|
|
384
|
+
...rest,
|
|
385
|
+
threadId: thread_id,
|
|
386
|
+
content: typeof message.content === "string" ? (() => {
|
|
387
|
+
try {
|
|
388
|
+
return JSON.parse(message.content);
|
|
389
|
+
} catch {
|
|
390
|
+
return message.content;
|
|
391
|
+
}
|
|
392
|
+
})() : message.content
|
|
393
|
+
};
|
|
394
|
+
}
|
|
382
395
|
async getMessages({
|
|
383
396
|
threadId,
|
|
384
397
|
resourceId,
|
|
@@ -387,6 +400,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
387
400
|
threadConfig
|
|
388
401
|
}) {
|
|
389
402
|
try {
|
|
403
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
390
404
|
if (threadConfig) {
|
|
391
405
|
throw new Error("ThreadConfig is not supported by LanceDB storage");
|
|
392
406
|
}
|
|
@@ -419,21 +433,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
419
433
|
allRecords,
|
|
420
434
|
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
|
|
421
435
|
);
|
|
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");
|
|
436
|
+
const list = new MessageList({ threadId, resourceId }).add(messages.map(this.normalizeMessage), "memory");
|
|
437
437
|
if (format === "v2") return list.get.all.v2();
|
|
438
438
|
return list.get.all.v1();
|
|
439
439
|
} catch (error) {
|
|
@@ -441,7 +441,41 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
441
441
|
{
|
|
442
442
|
id: "LANCE_STORE_GET_MESSAGES_FAILED",
|
|
443
443
|
domain: ErrorDomain.STORAGE,
|
|
444
|
-
category: ErrorCategory.THIRD_PARTY
|
|
444
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
445
|
+
details: {
|
|
446
|
+
threadId,
|
|
447
|
+
resourceId: resourceId ?? ""
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
error
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
async getMessagesById({
|
|
455
|
+
messageIds,
|
|
456
|
+
format
|
|
457
|
+
}) {
|
|
458
|
+
if (messageIds.length === 0) return [];
|
|
459
|
+
try {
|
|
460
|
+
const table = await this.client.openTable(TABLE_MESSAGES);
|
|
461
|
+
const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
|
|
462
|
+
const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
|
|
463
|
+
const messages = processResultWithTypeConversion(
|
|
464
|
+
allRecords,
|
|
465
|
+
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
|
|
466
|
+
);
|
|
467
|
+
const list = new MessageList().add(messages.map(this.normalizeMessage), "memory");
|
|
468
|
+
if (format === `v1`) return list.get.all.v1();
|
|
469
|
+
return list.get.all.v2();
|
|
470
|
+
} catch (error) {
|
|
471
|
+
throw new MastraError(
|
|
472
|
+
{
|
|
473
|
+
id: "LANCE_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
474
|
+
domain: ErrorDomain.STORAGE,
|
|
475
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
476
|
+
details: {
|
|
477
|
+
messageIds: JSON.stringify(messageIds)
|
|
478
|
+
}
|
|
445
479
|
},
|
|
446
480
|
error
|
|
447
481
|
);
|
|
@@ -582,13 +616,11 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
582
616
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
583
617
|
}
|
|
584
618
|
async getMessagesPaginated(args) {
|
|
619
|
+
const { threadId, resourceId, selectBy, format = "v1" } = args;
|
|
620
|
+
const page = selectBy?.pagination?.page ?? 0;
|
|
621
|
+
const perPage = selectBy?.pagination?.perPage ?? 10;
|
|
585
622
|
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;
|
|
623
|
+
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
592
624
|
const dateRange = selectBy?.pagination?.dateRange;
|
|
593
625
|
const fromDate = dateRange?.start;
|
|
594
626
|
const toDate = dateRange?.end;
|
|
@@ -690,14 +722,21 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
690
722
|
hasMore: total > (page + 1) * perPage
|
|
691
723
|
};
|
|
692
724
|
} catch (error) {
|
|
693
|
-
|
|
725
|
+
const mastraError = new MastraError(
|
|
694
726
|
{
|
|
695
727
|
id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
696
728
|
domain: ErrorDomain.STORAGE,
|
|
697
|
-
category: ErrorCategory.THIRD_PARTY
|
|
729
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
730
|
+
details: {
|
|
731
|
+
threadId,
|
|
732
|
+
resourceId: resourceId ?? ""
|
|
733
|
+
}
|
|
698
734
|
},
|
|
699
735
|
error
|
|
700
736
|
);
|
|
737
|
+
this.logger?.trackException?.(mastraError);
|
|
738
|
+
this.logger?.error?.(mastraError.toString());
|
|
739
|
+
return { messages: [], total: 0, page, perPage, hasMore: false };
|
|
701
740
|
}
|
|
702
741
|
}
|
|
703
742
|
/**
|
|
@@ -1224,7 +1263,7 @@ var StoreOperationsLance = class extends StoreOperations {
|
|
|
1224
1263
|
processedRecord[key] = JSON.stringify(processedRecord[key]);
|
|
1225
1264
|
}
|
|
1226
1265
|
}
|
|
1227
|
-
console.
|
|
1266
|
+
console.info(await table.schema());
|
|
1228
1267
|
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
|
|
1229
1268
|
} catch (error) {
|
|
1230
1269
|
throw new MastraError(
|
|
@@ -1274,7 +1313,6 @@ var StoreOperationsLance = class extends StoreOperations {
|
|
|
1274
1313
|
}
|
|
1275
1314
|
return processedRecord;
|
|
1276
1315
|
});
|
|
1277
|
-
console.log(processedRecords);
|
|
1278
1316
|
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(processedRecords);
|
|
1279
1317
|
} catch (error) {
|
|
1280
1318
|
throw new MastraError(
|
|
@@ -1359,6 +1397,7 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1359
1397
|
}
|
|
1360
1398
|
async saveScore(score) {
|
|
1361
1399
|
try {
|
|
1400
|
+
const id = crypto.randomUUID();
|
|
1362
1401
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1363
1402
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
1364
1403
|
const allowedFields = new Set(schema.fields.map((f) => f.name));
|
|
@@ -1373,7 +1412,7 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1373
1412
|
filteredScore[key] = JSON.stringify(filteredScore[key]);
|
|
1374
1413
|
}
|
|
1375
1414
|
}
|
|
1376
|
-
|
|
1415
|
+
filteredScore.id = id;
|
|
1377
1416
|
await table.add([filteredScore], { mode: "append" });
|
|
1378
1417
|
return { score };
|
|
1379
1418
|
} catch (error) {
|
|
@@ -1412,18 +1451,35 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1412
1451
|
}
|
|
1413
1452
|
async getScoresByScorerId({
|
|
1414
1453
|
scorerId,
|
|
1415
|
-
pagination
|
|
1454
|
+
pagination,
|
|
1455
|
+
entityId,
|
|
1456
|
+
entityType,
|
|
1457
|
+
source
|
|
1416
1458
|
}) {
|
|
1417
1459
|
try {
|
|
1418
1460
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1419
1461
|
const { page = 0, perPage = 10 } = pagination || {};
|
|
1420
1462
|
const offset = page * perPage;
|
|
1421
|
-
|
|
1463
|
+
let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1464
|
+
if (source) {
|
|
1465
|
+
query = query.where(`\`source\` = '${source}'`);
|
|
1466
|
+
}
|
|
1467
|
+
if (entityId) {
|
|
1468
|
+
query = query.where(`\`entityId\` = '${entityId}'`);
|
|
1469
|
+
}
|
|
1470
|
+
if (entityType) {
|
|
1471
|
+
query = query.where(`\`entityType\` = '${entityType}'`);
|
|
1472
|
+
}
|
|
1473
|
+
query = query.limit(perPage);
|
|
1422
1474
|
if (offset > 0) query.offset(offset);
|
|
1423
1475
|
const records = await query.toArray();
|
|
1424
1476
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
1425
1477
|
const scores = processResultWithTypeConversion(records, schema);
|
|
1426
|
-
|
|
1478
|
+
let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1479
|
+
if (source) {
|
|
1480
|
+
totalQuery = totalQuery.where(`\`source\` = '${source}'`);
|
|
1481
|
+
}
|
|
1482
|
+
const allRecords = await totalQuery.toArray();
|
|
1427
1483
|
const total = allRecords.length;
|
|
1428
1484
|
return {
|
|
1429
1485
|
pagination: {
|
|
@@ -1739,9 +1795,26 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1739
1795
|
super();
|
|
1740
1796
|
this.client = client;
|
|
1741
1797
|
}
|
|
1798
|
+
updateWorkflowResults({
|
|
1799
|
+
// workflowName,
|
|
1800
|
+
// runId,
|
|
1801
|
+
// stepId,
|
|
1802
|
+
// result,
|
|
1803
|
+
// runtimeContext,
|
|
1804
|
+
}) {
|
|
1805
|
+
throw new Error("Method not implemented.");
|
|
1806
|
+
}
|
|
1807
|
+
updateWorkflowState({
|
|
1808
|
+
// workflowName,
|
|
1809
|
+
// runId,
|
|
1810
|
+
// opts,
|
|
1811
|
+
}) {
|
|
1812
|
+
throw new Error("Method not implemented.");
|
|
1813
|
+
}
|
|
1742
1814
|
async persistWorkflowSnapshot({
|
|
1743
1815
|
workflowName,
|
|
1744
1816
|
runId,
|
|
1817
|
+
resourceId,
|
|
1745
1818
|
snapshot
|
|
1746
1819
|
}) {
|
|
1747
1820
|
try {
|
|
@@ -1758,6 +1831,7 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1758
1831
|
const record = {
|
|
1759
1832
|
workflow_name: workflowName,
|
|
1760
1833
|
run_id: runId,
|
|
1834
|
+
resourceId,
|
|
1761
1835
|
snapshot: JSON.stringify(snapshot),
|
|
1762
1836
|
createdAt,
|
|
1763
1837
|
updatedAt: now
|
|
@@ -2069,6 +2143,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2069
2143
|
}) {
|
|
2070
2144
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2071
2145
|
}
|
|
2146
|
+
async getMessagesById({
|
|
2147
|
+
messageIds,
|
|
2148
|
+
format
|
|
2149
|
+
}) {
|
|
2150
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2151
|
+
}
|
|
2072
2152
|
async saveMessages(args) {
|
|
2073
2153
|
return this.stores.memory.saveMessages(args);
|
|
2074
2154
|
}
|
|
@@ -2102,12 +2182,29 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2102
2182
|
async getWorkflowRunById(args) {
|
|
2103
2183
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
2104
2184
|
}
|
|
2185
|
+
async updateWorkflowResults({
|
|
2186
|
+
workflowName,
|
|
2187
|
+
runId,
|
|
2188
|
+
stepId,
|
|
2189
|
+
result,
|
|
2190
|
+
runtimeContext
|
|
2191
|
+
}) {
|
|
2192
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
2193
|
+
}
|
|
2194
|
+
async updateWorkflowState({
|
|
2195
|
+
workflowName,
|
|
2196
|
+
runId,
|
|
2197
|
+
opts
|
|
2198
|
+
}) {
|
|
2199
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
2200
|
+
}
|
|
2105
2201
|
async persistWorkflowSnapshot({
|
|
2106
2202
|
workflowName,
|
|
2107
2203
|
runId,
|
|
2204
|
+
resourceId,
|
|
2108
2205
|
snapshot
|
|
2109
2206
|
}) {
|
|
2110
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
2207
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
2111
2208
|
}
|
|
2112
2209
|
async loadWorkflowSnapshot({
|
|
2113
2210
|
workflowName,
|
|
@@ -2120,9 +2217,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2120
2217
|
}
|
|
2121
2218
|
async getScoresByScorerId({
|
|
2122
2219
|
scorerId,
|
|
2220
|
+
source,
|
|
2221
|
+
entityId,
|
|
2222
|
+
entityType,
|
|
2123
2223
|
pagination
|
|
2124
2224
|
}) {
|
|
2125
|
-
return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
|
|
2225
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
|
|
2126
2226
|
}
|
|
2127
2227
|
async saveScore(_score) {
|
|
2128
2228
|
return this.stores.scores.saveScore(_score);
|