@mastra/lance 0.0.0-zod-v4-compat-part-2-20250820135355 → 0.0.0-zod-v4-stuff-20250825154219
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 +117 -2
- package/dist/index.cjs +77 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +77 -20
- 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/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/index.d.ts +13 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +2 -2
- package/package.json +8 -7
- package/src/storage/domains/memory/index.ts +71 -18
- package/src/storage/domains/scores/index.ts +29 -7
- package/src/storage/index.ts +20 -2
- package/tsup.config.ts +2 -7
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
|
@@ -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,
|
|
@@ -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) {
|
|
@@ -447,6 +447,36 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
447
447
|
);
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
|
+
async getMessagesById({
|
|
451
|
+
messageIds,
|
|
452
|
+
format
|
|
453
|
+
}) {
|
|
454
|
+
if (messageIds.length === 0) return [];
|
|
455
|
+
try {
|
|
456
|
+
const table = await this.client.openTable(TABLE_MESSAGES);
|
|
457
|
+
const quotedIds = messageIds.map((id) => `'${id}'`).join(", ");
|
|
458
|
+
const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
|
|
459
|
+
const messages = processResultWithTypeConversion(
|
|
460
|
+
allRecords,
|
|
461
|
+
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
|
|
462
|
+
);
|
|
463
|
+
const list = new MessageList().add(messages.map(this.normalizeMessage), "memory");
|
|
464
|
+
if (format === `v1`) return list.get.all.v1();
|
|
465
|
+
return list.get.all.v2();
|
|
466
|
+
} catch (error) {
|
|
467
|
+
throw new MastraError(
|
|
468
|
+
{
|
|
469
|
+
id: "LANCE_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
470
|
+
domain: ErrorDomain.STORAGE,
|
|
471
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
472
|
+
details: {
|
|
473
|
+
messageIds: JSON.stringify(messageIds)
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
error
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
450
480
|
async saveMessages(args) {
|
|
451
481
|
try {
|
|
452
482
|
const { messages, format = "v1" } = args;
|
|
@@ -1359,6 +1389,7 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1359
1389
|
}
|
|
1360
1390
|
async saveScore(score) {
|
|
1361
1391
|
try {
|
|
1392
|
+
const id = crypto.randomUUID();
|
|
1362
1393
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1363
1394
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
1364
1395
|
const allowedFields = new Set(schema.fields.map((f) => f.name));
|
|
@@ -1373,7 +1404,7 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1373
1404
|
filteredScore[key] = JSON.stringify(filteredScore[key]);
|
|
1374
1405
|
}
|
|
1375
1406
|
}
|
|
1376
|
-
|
|
1407
|
+
filteredScore.id = id;
|
|
1377
1408
|
await table.add([filteredScore], { mode: "append" });
|
|
1378
1409
|
return { score };
|
|
1379
1410
|
} catch (error) {
|
|
@@ -1412,18 +1443,35 @@ var StoreScoresLance = class extends ScoresStorage {
|
|
|
1412
1443
|
}
|
|
1413
1444
|
async getScoresByScorerId({
|
|
1414
1445
|
scorerId,
|
|
1415
|
-
pagination
|
|
1446
|
+
pagination,
|
|
1447
|
+
entityId,
|
|
1448
|
+
entityType,
|
|
1449
|
+
source
|
|
1416
1450
|
}) {
|
|
1417
1451
|
try {
|
|
1418
1452
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
1419
1453
|
const { page = 0, perPage = 10 } = pagination || {};
|
|
1420
1454
|
const offset = page * perPage;
|
|
1421
|
-
|
|
1455
|
+
let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1456
|
+
if (source) {
|
|
1457
|
+
query = query.where(`\`source\` = '${source}'`);
|
|
1458
|
+
}
|
|
1459
|
+
if (entityId) {
|
|
1460
|
+
query = query.where(`\`entityId\` = '${entityId}'`);
|
|
1461
|
+
}
|
|
1462
|
+
if (entityType) {
|
|
1463
|
+
query = query.where(`\`entityType\` = '${entityType}'`);
|
|
1464
|
+
}
|
|
1465
|
+
query = query.limit(perPage);
|
|
1422
1466
|
if (offset > 0) query.offset(offset);
|
|
1423
1467
|
const records = await query.toArray();
|
|
1424
1468
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
1425
1469
|
const scores = processResultWithTypeConversion(records, schema);
|
|
1426
|
-
|
|
1470
|
+
let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
1471
|
+
if (source) {
|
|
1472
|
+
totalQuery = totalQuery.where(`\`source\` = '${source}'`);
|
|
1473
|
+
}
|
|
1474
|
+
const allRecords = await totalQuery.toArray();
|
|
1427
1475
|
const total = allRecords.length;
|
|
1428
1476
|
return {
|
|
1429
1477
|
pagination: {
|
|
@@ -2069,6 +2117,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2069
2117
|
}) {
|
|
2070
2118
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2071
2119
|
}
|
|
2120
|
+
async getMessagesById({
|
|
2121
|
+
messageIds,
|
|
2122
|
+
format
|
|
2123
|
+
}) {
|
|
2124
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2125
|
+
}
|
|
2072
2126
|
async saveMessages(args) {
|
|
2073
2127
|
return this.stores.memory.saveMessages(args);
|
|
2074
2128
|
}
|
|
@@ -2120,9 +2174,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2120
2174
|
}
|
|
2121
2175
|
async getScoresByScorerId({
|
|
2122
2176
|
scorerId,
|
|
2177
|
+
source,
|
|
2178
|
+
entityId,
|
|
2179
|
+
entityType,
|
|
2123
2180
|
pagination
|
|
2124
2181
|
}) {
|
|
2125
|
-
return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
|
|
2182
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
|
|
2126
2183
|
}
|
|
2127
2184
|
async saveScore(_score) {
|
|
2128
2185
|
return this.stores.scores.saveScore(_score);
|