@mastra/lance 0.0.0-vnext-20251104230439 → 0.0.0-vnext-20251119160359
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 +294 -3
- package/README.md +61 -4
- package/dist/index.cjs +20 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -81
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -4
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +7 -8
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +3 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +13 -8
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { connect, Index } from '@lancedb/lancedb';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { MastraStorage, StoreOperations, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES,
|
|
3
|
+
import { MastraStorage, StoreOperations, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, normalizePerPage, calculatePagination, 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
6
|
import { saveScorePayloadSchema } from '@mastra/core/evals';
|
|
@@ -261,66 +261,6 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
261
261
|
})() : message.content
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
|
-
async getMessages({
|
|
265
|
-
threadId,
|
|
266
|
-
resourceId,
|
|
267
|
-
selectBy,
|
|
268
|
-
threadConfig
|
|
269
|
-
}) {
|
|
270
|
-
try {
|
|
271
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
272
|
-
if (threadConfig) {
|
|
273
|
-
throw new Error("ThreadConfig is not supported by LanceDB storage");
|
|
274
|
-
}
|
|
275
|
-
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
276
|
-
const table = await this.client.openTable(TABLE_MESSAGES);
|
|
277
|
-
let allRecords = [];
|
|
278
|
-
if (selectBy?.include && selectBy.include.length > 0) {
|
|
279
|
-
const threadIds = [...new Set(selectBy.include.map((item) => item.threadId))];
|
|
280
|
-
for (const threadId2 of threadIds) {
|
|
281
|
-
const threadQuery = table.query().where(`thread_id = '${threadId2}'`);
|
|
282
|
-
let threadRecords = await threadQuery.toArray();
|
|
283
|
-
allRecords.push(...threadRecords);
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
let query = table.query().where(`\`thread_id\` = '${threadId}'`);
|
|
287
|
-
allRecords = await query.toArray();
|
|
288
|
-
}
|
|
289
|
-
allRecords.sort((a, b) => {
|
|
290
|
-
const dateA = new Date(a.createdAt).getTime();
|
|
291
|
-
const dateB = new Date(b.createdAt).getTime();
|
|
292
|
-
return dateA - dateB;
|
|
293
|
-
});
|
|
294
|
-
if (selectBy?.include && selectBy.include.length > 0) {
|
|
295
|
-
allRecords = this.processMessagesWithContext(allRecords, selectBy.include);
|
|
296
|
-
}
|
|
297
|
-
if (limit !== Number.MAX_SAFE_INTEGER) {
|
|
298
|
-
allRecords = allRecords.slice(-limit);
|
|
299
|
-
}
|
|
300
|
-
const messages = processResultWithTypeConversion(
|
|
301
|
-
allRecords,
|
|
302
|
-
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client })
|
|
303
|
-
);
|
|
304
|
-
const list = new MessageList({ threadId, resourceId }).add(
|
|
305
|
-
messages.map(this.normalizeMessage),
|
|
306
|
-
"memory"
|
|
307
|
-
);
|
|
308
|
-
return { messages: list.get.all.db() };
|
|
309
|
-
} catch (error) {
|
|
310
|
-
throw new MastraError(
|
|
311
|
-
{
|
|
312
|
-
id: "LANCE_STORE_GET_MESSAGES_FAILED",
|
|
313
|
-
domain: ErrorDomain.STORAGE,
|
|
314
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
315
|
-
details: {
|
|
316
|
-
threadId,
|
|
317
|
-
resourceId: resourceId ?? ""
|
|
318
|
-
}
|
|
319
|
-
},
|
|
320
|
-
error
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
264
|
async listMessagesById({ messageIds }) {
|
|
325
265
|
if (messageIds.length === 0) return { messages: [] };
|
|
326
266
|
try {
|
|
@@ -377,7 +317,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
377
317
|
new Error("page must be >= 0")
|
|
378
318
|
);
|
|
379
319
|
}
|
|
380
|
-
const { field, direction } = this.parseOrderBy(orderBy);
|
|
320
|
+
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
381
321
|
const table = await this.client.openTable(TABLE_MESSAGES);
|
|
382
322
|
const conditions = [`thread_id = '${this.escapeSql(threadId)}'`];
|
|
383
323
|
if (resourceId) {
|
|
@@ -1613,11 +1553,13 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1613
1553
|
} else {
|
|
1614
1554
|
createdAt = now;
|
|
1615
1555
|
}
|
|
1556
|
+
const { status, value, ...rest } = snapshot;
|
|
1616
1557
|
const record = {
|
|
1617
1558
|
workflow_name: workflowName,
|
|
1618
1559
|
run_id: runId,
|
|
1619
1560
|
resourceId,
|
|
1620
|
-
snapshot: JSON.stringify(
|
|
1561
|
+
snapshot: JSON.stringify({ status, value, ...rest }),
|
|
1562
|
+
// this is to ensure status is always just before value, for when querying the db by status
|
|
1621
1563
|
createdAt,
|
|
1622
1564
|
updatedAt: now
|
|
1623
1565
|
};
|
|
@@ -1687,6 +1629,10 @@ var StoreWorkflowsLance = class extends WorkflowsStorage {
|
|
|
1687
1629
|
if (args?.workflowName) {
|
|
1688
1630
|
conditions.push(`workflow_name = '${args.workflowName.replace(/'/g, "''")}'`);
|
|
1689
1631
|
}
|
|
1632
|
+
if (args?.status) {
|
|
1633
|
+
const escapedStatus = args.status.replace(/\\/g, "\\\\").replace(/'/g, "''").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
1634
|
+
conditions.push(`\`snapshot\` LIKE '%"status":"${escapedStatus}","value"%'`);
|
|
1635
|
+
}
|
|
1690
1636
|
if (args?.resourceId) {
|
|
1691
1637
|
conditions.push(`\`resourceId\` = '${args.resourceId}'`);
|
|
1692
1638
|
}
|
|
@@ -1745,6 +1691,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1745
1691
|
lanceClient;
|
|
1746
1692
|
/**
|
|
1747
1693
|
* Creates a new instance of LanceStorage
|
|
1694
|
+
* @param id The unique identifier for this storage instance
|
|
1695
|
+
* @param name The name for this storage instance
|
|
1748
1696
|
* @param uri The URI to connect to LanceDB
|
|
1749
1697
|
* @param options connection options
|
|
1750
1698
|
*
|
|
@@ -1752,21 +1700,21 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1752
1700
|
*
|
|
1753
1701
|
* Connect to a local database
|
|
1754
1702
|
* ```ts
|
|
1755
|
-
* const store = await LanceStorage.create('/path/to/db');
|
|
1703
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', '/path/to/db');
|
|
1756
1704
|
* ```
|
|
1757
1705
|
*
|
|
1758
1706
|
* Connect to a LanceDB cloud database
|
|
1759
1707
|
* ```ts
|
|
1760
|
-
* const store = await LanceStorage.create('db://host:port');
|
|
1708
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', 'db://host:port');
|
|
1761
1709
|
* ```
|
|
1762
1710
|
*
|
|
1763
1711
|
* Connect to a cloud database
|
|
1764
1712
|
* ```ts
|
|
1765
|
-
* const store = await LanceStorage.create('s3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
1713
|
+
* const store = await LanceStorage.create('my-storage-id', 'MyStorage', 's3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
1766
1714
|
* ```
|
|
1767
1715
|
*/
|
|
1768
|
-
static async create(name, uri, options) {
|
|
1769
|
-
const instance = new _LanceStorage(name);
|
|
1716
|
+
static async create(id, name, uri, options) {
|
|
1717
|
+
const instance = new _LanceStorage(id, name);
|
|
1770
1718
|
try {
|
|
1771
1719
|
instance.lanceClient = await connect(uri, options);
|
|
1772
1720
|
const operations = new StoreOperationsLance({ client: instance.lanceClient });
|
|
@@ -1794,8 +1742,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1794
1742
|
* @internal
|
|
1795
1743
|
* Private constructor to enforce using the create factory method
|
|
1796
1744
|
*/
|
|
1797
|
-
constructor(name) {
|
|
1798
|
-
super({ name });
|
|
1745
|
+
constructor(id, name) {
|
|
1746
|
+
super({ id, name });
|
|
1799
1747
|
const operations = new StoreOperationsLance({ client: this.lanceClient });
|
|
1800
1748
|
this.stores = {
|
|
1801
1749
|
operations: new StoreOperationsLance({ client: this.lanceClient }),
|
|
@@ -1924,14 +1872,6 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
1924
1872
|
});
|
|
1925
1873
|
return Array.from(allIndices).sort((a, b) => a - b).map((index) => records[index]);
|
|
1926
1874
|
}
|
|
1927
|
-
async getMessages({
|
|
1928
|
-
threadId,
|
|
1929
|
-
resourceId,
|
|
1930
|
-
selectBy,
|
|
1931
|
-
threadConfig
|
|
1932
|
-
}) {
|
|
1933
|
-
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, threadConfig });
|
|
1934
|
-
}
|
|
1935
1875
|
async listMessagesById({ messageIds }) {
|
|
1936
1876
|
return this.stores.memory.listMessagesById({ messageIds });
|
|
1937
1877
|
}
|
|
@@ -2359,7 +2299,7 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
2359
2299
|
* ```
|
|
2360
2300
|
*/
|
|
2361
2301
|
static async create(uri, options) {
|
|
2362
|
-
const instance = new _LanceVectorStore();
|
|
2302
|
+
const instance = new _LanceVectorStore(options?.id || crypto.randomUUID());
|
|
2363
2303
|
try {
|
|
2364
2304
|
instance.lanceClient = await connect(uri, options);
|
|
2365
2305
|
return instance;
|
|
@@ -2379,8 +2319,8 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
2379
2319
|
* @internal
|
|
2380
2320
|
* Private constructor to enforce using the create factory method
|
|
2381
2321
|
*/
|
|
2382
|
-
constructor() {
|
|
2383
|
-
super();
|
|
2322
|
+
constructor(id) {
|
|
2323
|
+
super({ id });
|
|
2384
2324
|
}
|
|
2385
2325
|
close() {
|
|
2386
2326
|
if (this.lanceClient) {
|