@mastra/lance 0.2.5 → 0.2.7-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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +40 -0
- package/dist/index.cjs +51 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -15
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +9 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +8 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/storage/domains/memory/index.ts +71 -18
- package/src/storage/index.ts +12 -0
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;
|
|
@@ -2087,6 +2117,12 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
2087
2117
|
}) {
|
|
2088
2118
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
2089
2119
|
}
|
|
2120
|
+
async getMessagesById({
|
|
2121
|
+
messageIds,
|
|
2122
|
+
format
|
|
2123
|
+
}) {
|
|
2124
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2125
|
+
}
|
|
2090
2126
|
async saveMessages(args) {
|
|
2091
2127
|
return this.stores.memory.saveMessages(args);
|
|
2092
2128
|
}
|