@mastra/lance 0.0.0-update-stores-peerDeps-20250723031338 → 0.0.0-vector-query-tool-provider-options-20250828222356
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 +201 -2
- package/README.md +3 -3
- package/dist/index.cjs +113 -21
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +113 -21
- package/dist/index.js.map +1 -0
- package/dist/storage/domains/legacy-evals/index.d.ts +25 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +103 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/operations/index.d.ts +40 -0
- package/dist/storage/domains/operations/index.d.ts.map +1 -0
- package/dist/storage/domains/scores/index.d.ts +42 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -0
- package/dist/storage/domains/traces/index.d.ts +34 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +10 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +56 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +262 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/vector/filter.d.ts +41 -0
- package/dist/vector/filter.d.ts.map +1 -0
- package/dist/vector/index.d.ts +85 -0
- package/dist/vector/index.d.ts.map +1 -0
- package/dist/vector/types.d.ts +15 -0
- package/dist/vector/types.d.ts.map +1 -0
- package/package.json +10 -9
- package/src/storage/domains/memory/index.ts +71 -18
- package/src/storage/domains/scores/index.ts +29 -7
- package/src/storage/domains/workflows/index.ts +39 -1
- package/src/storage/index.ts +56 -3
- package/src/vector/index.ts +2 -2
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +17 -0
- package/dist/_tsup-dts-rollup.d.cts +0 -680
- package/dist/_tsup-dts-rollup.d.ts +0 -680
- package/dist/index.d.cts +0 -2
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
+
import type { VectorFilter, OperatorValueMap, LogicalOperatorValueMap, BlacklistedRootOperators } from '@mastra/core/vector/filter';
|
|
3
|
+
type LanceOperatorValueMap = OperatorValueMap & {
|
|
4
|
+
$like: string;
|
|
5
|
+
$notLike: string;
|
|
6
|
+
$contains: string;
|
|
7
|
+
};
|
|
8
|
+
type LanceBlacklisted = BlacklistedRootOperators | '$like' | '$notLike' | '$contains';
|
|
9
|
+
export type LanceVectorFilter = VectorFilter<keyof LanceOperatorValueMap, LanceOperatorValueMap, LogicalOperatorValueMap, LanceBlacklisted>;
|
|
10
|
+
export declare class LanceFilterTranslator extends BaseFilterTranslator<LanceVectorFilter, string> {
|
|
11
|
+
translate(filter: LanceVectorFilter): string;
|
|
12
|
+
private processFilter;
|
|
13
|
+
private processLogicalOperator;
|
|
14
|
+
private processNestedObject;
|
|
15
|
+
private processField;
|
|
16
|
+
private processOperators;
|
|
17
|
+
private formatValue;
|
|
18
|
+
private formatArrayValues;
|
|
19
|
+
normalizeArrayValues(array: unknown[]): unknown[];
|
|
20
|
+
normalizeComparisonValue(value: unknown): unknown;
|
|
21
|
+
private isOperatorObject;
|
|
22
|
+
private isNestedObject;
|
|
23
|
+
private isNormalNestedField;
|
|
24
|
+
private escapeFieldName;
|
|
25
|
+
private isSqlKeyword;
|
|
26
|
+
private isDateObject;
|
|
27
|
+
/**
|
|
28
|
+
* Override getSupportedOperators to add custom operators for LanceDB
|
|
29
|
+
*/
|
|
30
|
+
protected getSupportedOperators(): {
|
|
31
|
+
custom: string[];
|
|
32
|
+
logical: import("@mastra/core/vector/filter").LogicalOperator[];
|
|
33
|
+
basic: import("@mastra/core/vector/filter").BasicOperator[];
|
|
34
|
+
numeric: import("@mastra/core/vector/filter").NumericOperator[];
|
|
35
|
+
array: import("@mastra/core/vector/filter").ArrayOperator[];
|
|
36
|
+
element: "$exists"[];
|
|
37
|
+
regex: import("@mastra/core/vector/filter").RegexOperator[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/vector/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAEpC,KAAK,qBAAqB,GAAG,gBAAgB,GAAG;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,gBAAgB,GAAG,wBAAwB,GAAG,OAAO,GAAG,UAAU,GAAG,WAAW,CAAC;AAEtF,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAC1C,MAAM,qBAAqB,EAC3B,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,CACjB,CAAC;AAEF,qBAAa,qBAAsB,SAAQ,oBAAoB,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACxF,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM;IAkB5C,OAAO,CAAC,aAAa;IAoErB,OAAO,CAAC,sBAAsB;IAuC9B,OAAO,CAAC,mBAAmB;IAkC3B,OAAO,CAAC,YAAY;IAqCpB,OAAO,CAAC,gBAAgB;IA6DxB,OAAO,CAAC,WAAW;IAgCnB,OAAO,CAAC,iBAAiB;IAIzB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;IASjD,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IASjD,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,YAAY;IAwDpB,OAAO,CAAC,YAAY;IAIpB;;OAEG;cACgB,qBAAqB;;;;;;;;;CAMzC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ConnectionOptions, CreateTableOptions, Table, TableLike } from '@lancedb/lancedb';
|
|
2
|
+
import type { CreateIndexParams, DeleteIndexParams, DeleteVectorParams, DescribeIndexParams, IndexStats, QueryResult, QueryVectorParams, UpdateVectorParams, UpsertVectorParams } from '@mastra/core/vector';
|
|
3
|
+
import { MastraVector } from '@mastra/core/vector';
|
|
4
|
+
import type { LanceVectorFilter } from './filter.js';
|
|
5
|
+
import type { IndexConfig } from './types.js';
|
|
6
|
+
interface LanceCreateIndexParams extends CreateIndexParams {
|
|
7
|
+
indexConfig?: LanceIndexConfig;
|
|
8
|
+
tableName?: string;
|
|
9
|
+
}
|
|
10
|
+
interface LanceIndexConfig extends IndexConfig {
|
|
11
|
+
numPartitions?: number;
|
|
12
|
+
numSubVectors?: number;
|
|
13
|
+
}
|
|
14
|
+
interface LanceUpsertVectorParams extends UpsertVectorParams {
|
|
15
|
+
tableName: string;
|
|
16
|
+
}
|
|
17
|
+
interface LanceQueryVectorParams extends QueryVectorParams<LanceVectorFilter> {
|
|
18
|
+
tableName: string;
|
|
19
|
+
columns?: string[];
|
|
20
|
+
includeAllColumns?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare class LanceVectorStore extends MastraVector<LanceVectorFilter> {
|
|
23
|
+
private lanceClient;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new instance of LanceVectorStore
|
|
26
|
+
* @param uri The URI to connect to LanceDB
|
|
27
|
+
* @param options connection options
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
*
|
|
31
|
+
* Connect to a local database
|
|
32
|
+
* ```ts
|
|
33
|
+
* const store = await LanceVectorStore.create('/path/to/db');
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Connect to a LanceDB cloud database
|
|
37
|
+
* ```ts
|
|
38
|
+
* const store = await LanceVectorStore.create('db://host:port');
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Connect to a cloud database
|
|
42
|
+
* ```ts
|
|
43
|
+
* const store = await LanceVectorStore.create('s3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
static create(uri: string, options?: ConnectionOptions): Promise<LanceVectorStore>;
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
* Private constructor to enforce using the create factory method
|
|
50
|
+
*/
|
|
51
|
+
private constructor();
|
|
52
|
+
close(): void;
|
|
53
|
+
query({ tableName, queryVector, filter, includeVector, topK, columns, includeAllColumns, }: LanceQueryVectorParams): Promise<QueryResult[]>;
|
|
54
|
+
private filterTranslator;
|
|
55
|
+
upsert({ tableName, vectors, metadata, ids }: LanceUpsertVectorParams): Promise<string[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Flattens a nested object, creating new keys with underscores for nested properties.
|
|
58
|
+
* Example: { metadata: { text: 'test' } } → { metadata_text: 'test' }
|
|
59
|
+
*/
|
|
60
|
+
private flattenObject;
|
|
61
|
+
createTable(tableName: string, data: Record<string, unknown>[] | TableLike, options?: Partial<CreateTableOptions>): Promise<Table>;
|
|
62
|
+
listTables(): Promise<string[]>;
|
|
63
|
+
getTableSchema(tableName: string): Promise<any>;
|
|
64
|
+
/**
|
|
65
|
+
* indexName is actually a column name in a table in lanceDB
|
|
66
|
+
*/
|
|
67
|
+
createIndex({ tableName, indexName, dimension, metric, indexConfig, }: LanceCreateIndexParams): Promise<void>;
|
|
68
|
+
listIndexes(): Promise<string[]>;
|
|
69
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
70
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Deletes all tables in the database
|
|
73
|
+
*/
|
|
74
|
+
deleteAllTables(): Promise<void>;
|
|
75
|
+
deleteTable(tableName: string): Promise<void>;
|
|
76
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
77
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Converts a flattened object with keys using underscore notation back to a nested object.
|
|
80
|
+
* Example: { name: 'test', details_text: 'test' } → { name: 'test', details: { text: 'test' } }
|
|
81
|
+
*/
|
|
82
|
+
private unflattenObject;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type IndexType = 'ivfflat' | 'hnsw';
|
|
2
|
+
interface IVFConfig {
|
|
3
|
+
lists?: number;
|
|
4
|
+
}
|
|
5
|
+
interface HNSWConfig {
|
|
6
|
+
m?: number;
|
|
7
|
+
efConstruction?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface IndexConfig {
|
|
10
|
+
type?: IndexType;
|
|
11
|
+
ivf?: IVFConfig;
|
|
12
|
+
hnsw?: HNSWConfig;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vector/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAE3C,UAAU,SAAS;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,UAAU;IAClB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/lance",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-vector-query-tool-provider-options-20250828222356",
|
|
4
4
|
"description": "Lance provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"require": {
|
|
15
|
-
"types": "./dist/index.d.
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
16
|
"default": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@lancedb/lancedb": "^0.
|
|
22
|
+
"@lancedb/lancedb": "^0.21.2",
|
|
23
23
|
"apache-arrow": "^18.1.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
@@ -29,16 +29,17 @@
|
|
|
29
29
|
"tsup": "^8.5.0",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"vitest": "^3.2.4",
|
|
32
|
-
"@internal/storage-test-utils": "0.0.
|
|
33
|
-
"@internal/lint": "0.0.0-
|
|
34
|
-
"@mastra/core": "0.
|
|
32
|
+
"@internal/storage-test-utils": "0.0.30",
|
|
33
|
+
"@internal/lint": "0.0.0-vector-query-tool-provider-options-20250828222356",
|
|
34
|
+
"@mastra/core": "0.0.0-vector-query-tool-provider-options-20250828222356",
|
|
35
|
+
"@internal/types-builder": "0.0.0-vector-query-tool-provider-options-20250828222356"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
|
-
"@mastra/core": "0.
|
|
38
|
+
"@mastra/core": "0.0.0-vector-query-tool-provider-options-20250828222356"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
|
-
"build": "tsup
|
|
41
|
-
"build:watch": "
|
|
41
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
42
|
+
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
42
43
|
"test": "vitest run",
|
|
43
44
|
"test:watch": "vitest watch",
|
|
44
45
|
"lint": "eslint ."
|
|
@@ -185,6 +185,24 @@ export class StoreMemoryLance extends MemoryStorage {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
private normalizeMessage(message: any): MastraMessageV1 | MastraMessageV2 {
|
|
189
|
+
const { thread_id, ...rest } = message;
|
|
190
|
+
return {
|
|
191
|
+
...rest,
|
|
192
|
+
threadId: thread_id,
|
|
193
|
+
content:
|
|
194
|
+
typeof message.content === 'string'
|
|
195
|
+
? (() => {
|
|
196
|
+
try {
|
|
197
|
+
return JSON.parse(message.content);
|
|
198
|
+
} catch {
|
|
199
|
+
return message.content;
|
|
200
|
+
}
|
|
201
|
+
})()
|
|
202
|
+
: message.content,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
188
206
|
public async getMessages(args: StorageGetMessagesArg & { format?: 'v1' }): Promise<MastraMessageV1[]>;
|
|
189
207
|
public async getMessages(args: StorageGetMessagesArg & { format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
190
208
|
public async getMessages({
|
|
@@ -241,24 +259,8 @@ export class StoreMemoryLance extends MemoryStorage {
|
|
|
241
259
|
allRecords,
|
|
242
260
|
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client }),
|
|
243
261
|
);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
...rest,
|
|
248
|
-
threadId: thread_id,
|
|
249
|
-
content:
|
|
250
|
-
typeof msg.content === 'string'
|
|
251
|
-
? (() => {
|
|
252
|
-
try {
|
|
253
|
-
return JSON.parse(msg.content);
|
|
254
|
-
} catch {
|
|
255
|
-
return msg.content;
|
|
256
|
-
}
|
|
257
|
-
})()
|
|
258
|
-
: msg.content,
|
|
259
|
-
};
|
|
260
|
-
});
|
|
261
|
-
const list = new MessageList({ threadId, resourceId }).add(normalized, 'memory');
|
|
262
|
+
|
|
263
|
+
const list = new MessageList({ threadId, resourceId }).add(messages.map(this.normalizeMessage), 'memory');
|
|
262
264
|
if (format === 'v2') return list.get.all.v2();
|
|
263
265
|
return list.get.all.v1();
|
|
264
266
|
} catch (error: any) {
|
|
@@ -273,6 +275,57 @@ export class StoreMemoryLance extends MemoryStorage {
|
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
277
|
|
|
278
|
+
public async getMessagesById({
|
|
279
|
+
messageIds,
|
|
280
|
+
format,
|
|
281
|
+
}: {
|
|
282
|
+
messageIds: string[];
|
|
283
|
+
format: 'v1';
|
|
284
|
+
}): Promise<MastraMessageV1[]>;
|
|
285
|
+
public async getMessagesById({
|
|
286
|
+
messageIds,
|
|
287
|
+
format,
|
|
288
|
+
}: {
|
|
289
|
+
messageIds: string[];
|
|
290
|
+
format?: 'v2';
|
|
291
|
+
}): Promise<MastraMessageV2[]>;
|
|
292
|
+
public async getMessagesById({
|
|
293
|
+
messageIds,
|
|
294
|
+
format,
|
|
295
|
+
}: {
|
|
296
|
+
messageIds: string[];
|
|
297
|
+
format?: 'v1' | 'v2';
|
|
298
|
+
}): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
299
|
+
if (messageIds.length === 0) return [];
|
|
300
|
+
try {
|
|
301
|
+
const table = await this.client.openTable(TABLE_MESSAGES);
|
|
302
|
+
|
|
303
|
+
const quotedIds = messageIds.map(id => `'${id}'`).join(', ');
|
|
304
|
+
const allRecords = await table.query().where(`id IN (${quotedIds})`).toArray();
|
|
305
|
+
|
|
306
|
+
const messages = processResultWithTypeConversion(
|
|
307
|
+
allRecords,
|
|
308
|
+
await getTableSchema({ tableName: TABLE_MESSAGES, client: this.client }),
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const list = new MessageList().add(messages.map(this.normalizeMessage), 'memory');
|
|
312
|
+
if (format === `v1`) return list.get.all.v1();
|
|
313
|
+
return list.get.all.v2();
|
|
314
|
+
} catch (error: any) {
|
|
315
|
+
throw new MastraError(
|
|
316
|
+
{
|
|
317
|
+
id: 'LANCE_STORE_GET_MESSAGES_BY_ID_FAILED',
|
|
318
|
+
domain: ErrorDomain.STORAGE,
|
|
319
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
320
|
+
details: {
|
|
321
|
+
messageIds: JSON.stringify(messageIds),
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
error,
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
276
329
|
async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
|
|
277
330
|
async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
278
331
|
async saveMessages(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Connection } from '@lancedb/lancedb';
|
|
2
2
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
3
|
-
import type { ScoreRowData } from '@mastra/core/scores';
|
|
3
|
+
import type { ScoreRowData, ScoringSource } from '@mastra/core/scores';
|
|
4
4
|
import { ScoresStorage, TABLE_SCORERS } from '@mastra/core/storage';
|
|
5
5
|
import type { PaginationInfo, StoragePagination } from '@mastra/core/storage';
|
|
6
6
|
import { getTableSchema, processResultWithTypeConversion } from '../utils';
|
|
@@ -14,6 +14,7 @@ export class StoreScoresLance extends ScoresStorage {
|
|
|
14
14
|
|
|
15
15
|
async saveScore(score: ScoreRowData): Promise<{ score: ScoreRowData }> {
|
|
16
16
|
try {
|
|
17
|
+
const id = crypto.randomUUID();
|
|
17
18
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
18
19
|
// Fetch schema fields for mastra_scorers
|
|
19
20
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
@@ -36,8 +37,7 @@ export class StoreScoresLance extends ScoresStorage {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
filteredScore.id = id;
|
|
41
41
|
await table.add([filteredScore], { mode: 'append' });
|
|
42
42
|
return { score };
|
|
43
43
|
} catch (error: any) {
|
|
@@ -82,24 +82,46 @@ export class StoreScoresLance extends ScoresStorage {
|
|
|
82
82
|
async getScoresByScorerId({
|
|
83
83
|
scorerId,
|
|
84
84
|
pagination,
|
|
85
|
+
entityId,
|
|
86
|
+
entityType,
|
|
87
|
+
source,
|
|
85
88
|
}: {
|
|
86
89
|
scorerId: string;
|
|
87
90
|
pagination: StoragePagination;
|
|
91
|
+
entityId?: string;
|
|
92
|
+
entityType?: string;
|
|
93
|
+
source?: ScoringSource;
|
|
88
94
|
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
89
95
|
try {
|
|
90
96
|
const table = await this.client.openTable(TABLE_SCORERS);
|
|
91
97
|
// Use zero-based pagination (default page = 0)
|
|
92
98
|
const { page = 0, perPage = 10 } = pagination || {};
|
|
93
99
|
const offset = page * perPage;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
|
|
101
|
+
let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
102
|
+
|
|
103
|
+
if (source) {
|
|
104
|
+
query = query.where(`\`source\` = '${source}'`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (entityId) {
|
|
108
|
+
query = query.where(`\`entityId\` = '${entityId}'`);
|
|
109
|
+
}
|
|
110
|
+
if (entityType) {
|
|
111
|
+
query = query.where(`\`entityType\` = '${entityType}'`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
query = query.limit(perPage);
|
|
97
115
|
if (offset > 0) query.offset(offset);
|
|
98
116
|
const records = await query.toArray();
|
|
99
117
|
const schema = await getTableSchema({ tableName: TABLE_SCORERS, client: this.client });
|
|
100
118
|
const scores = processResultWithTypeConversion(records, schema) as ScoreRowData[];
|
|
101
119
|
|
|
102
|
-
|
|
120
|
+
let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
|
|
121
|
+
if (source) {
|
|
122
|
+
totalQuery = totalQuery.where(`\`source\` = '${source}'`);
|
|
123
|
+
}
|
|
124
|
+
const allRecords = await totalQuery.toArray();
|
|
103
125
|
const total = allRecords.length;
|
|
104
126
|
|
|
105
127
|
return {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Connection } from '@lancedb/lancedb';
|
|
2
|
-
import type {
|
|
2
|
+
import type { StepResult, WorkflowRunState, WorkflowRuns } from '@mastra/core';
|
|
3
3
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
4
|
+
import type { WorkflowRun } from '@mastra/core/storage';
|
|
4
5
|
import { ensureDate, TABLE_WORKFLOW_SNAPSHOT, WorkflowsStorage } from '@mastra/core/storage';
|
|
5
6
|
|
|
6
7
|
function parseWorkflowRun(row: any): WorkflowRun {
|
|
@@ -31,6 +32,43 @@ export class StoreWorkflowsLance extends WorkflowsStorage {
|
|
|
31
32
|
this.client = client;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
updateWorkflowResults(
|
|
36
|
+
{
|
|
37
|
+
// workflowName,
|
|
38
|
+
// runId,
|
|
39
|
+
// stepId,
|
|
40
|
+
// result,
|
|
41
|
+
// runtimeContext,
|
|
42
|
+
}: {
|
|
43
|
+
workflowName: string;
|
|
44
|
+
runId: string;
|
|
45
|
+
stepId: string;
|
|
46
|
+
result: StepResult<any, any, any, any>;
|
|
47
|
+
runtimeContext: Record<string, any>;
|
|
48
|
+
},
|
|
49
|
+
): Promise<Record<string, StepResult<any, any, any, any>>> {
|
|
50
|
+
throw new Error('Method not implemented.');
|
|
51
|
+
}
|
|
52
|
+
updateWorkflowState(
|
|
53
|
+
{
|
|
54
|
+
// workflowName,
|
|
55
|
+
// runId,
|
|
56
|
+
// opts,
|
|
57
|
+
}: {
|
|
58
|
+
workflowName: string;
|
|
59
|
+
runId: string;
|
|
60
|
+
opts: {
|
|
61
|
+
status: string;
|
|
62
|
+
result?: StepResult<any, any, any, any>;
|
|
63
|
+
error?: string;
|
|
64
|
+
suspendedPaths?: Record<string, number[]>;
|
|
65
|
+
waitingPaths?: Record<string, number[]>;
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
): Promise<WorkflowRunState | undefined> {
|
|
69
|
+
throw new Error('Method not implemented.');
|
|
70
|
+
}
|
|
71
|
+
|
|
34
72
|
async persistWorkflowSnapshot({
|
|
35
73
|
workflowName,
|
|
36
74
|
runId,
|
package/src/storage/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Connection, ConnectionOptions } from '@lancedb/lancedb';
|
|
|
3
3
|
import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
4
4
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
5
5
|
import type { MastraMessageV1, MastraMessageV2, StorageThreadType, TraceType } from '@mastra/core/memory';
|
|
6
|
-
import type { ScoreRowData } from '@mastra/core/scores';
|
|
6
|
+
import type { ScoreRowData, ScoringSource } from '@mastra/core/scores';
|
|
7
7
|
import { MastraStorage } from '@mastra/core/storage';
|
|
8
8
|
import type {
|
|
9
9
|
TABLE_NAMES,
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
StorageResourceType,
|
|
19
19
|
} from '@mastra/core/storage';
|
|
20
20
|
import type { Trace } from '@mastra/core/telemetry';
|
|
21
|
-
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
21
|
+
import type { StepResult, WorkflowRunState } from '@mastra/core/workflows';
|
|
22
22
|
import { StoreLegacyEvalsLance } from './domains/legacy-evals';
|
|
23
23
|
import { StoreMemoryLance } from './domains/memory';
|
|
24
24
|
import { StoreOperationsLance } from './domains/operations';
|
|
@@ -178,6 +178,7 @@ export class LanceStorage extends MastraStorage {
|
|
|
178
178
|
resourceWorkingMemory: true,
|
|
179
179
|
hasColumn: true,
|
|
180
180
|
createTable: true,
|
|
181
|
+
deleteMessages: false,
|
|
181
182
|
};
|
|
182
183
|
}
|
|
183
184
|
|
|
@@ -290,6 +291,18 @@ export class LanceStorage extends MastraStorage {
|
|
|
290
291
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format, threadConfig });
|
|
291
292
|
}
|
|
292
293
|
|
|
294
|
+
async getMessagesById({ messageIds, format }: { messageIds: string[]; format: 'v1' }): Promise<MastraMessageV1[]>;
|
|
295
|
+
async getMessagesById({ messageIds, format }: { messageIds: string[]; format?: 'v2' }): Promise<MastraMessageV2[]>;
|
|
296
|
+
async getMessagesById({
|
|
297
|
+
messageIds,
|
|
298
|
+
format,
|
|
299
|
+
}: {
|
|
300
|
+
messageIds: string[];
|
|
301
|
+
format?: 'v1' | 'v2';
|
|
302
|
+
}): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
303
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
304
|
+
}
|
|
305
|
+
|
|
293
306
|
async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
|
|
294
307
|
async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
295
308
|
async saveMessages(
|
|
@@ -377,6 +390,40 @@ export class LanceStorage extends MastraStorage {
|
|
|
377
390
|
return this.stores.workflows.getWorkflowRunById(args);
|
|
378
391
|
}
|
|
379
392
|
|
|
393
|
+
async updateWorkflowResults({
|
|
394
|
+
workflowName,
|
|
395
|
+
runId,
|
|
396
|
+
stepId,
|
|
397
|
+
result,
|
|
398
|
+
runtimeContext,
|
|
399
|
+
}: {
|
|
400
|
+
workflowName: string;
|
|
401
|
+
runId: string;
|
|
402
|
+
stepId: string;
|
|
403
|
+
result: StepResult<any, any, any, any>;
|
|
404
|
+
runtimeContext: Record<string, any>;
|
|
405
|
+
}): Promise<Record<string, StepResult<any, any, any, any>>> {
|
|
406
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async updateWorkflowState({
|
|
410
|
+
workflowName,
|
|
411
|
+
runId,
|
|
412
|
+
opts,
|
|
413
|
+
}: {
|
|
414
|
+
workflowName: string;
|
|
415
|
+
runId: string;
|
|
416
|
+
opts: {
|
|
417
|
+
status: string;
|
|
418
|
+
result?: StepResult<any, any, any, any>;
|
|
419
|
+
error?: string;
|
|
420
|
+
suspendedPaths?: Record<string, number[]>;
|
|
421
|
+
waitingPaths?: Record<string, number[]>;
|
|
422
|
+
};
|
|
423
|
+
}): Promise<WorkflowRunState | undefined> {
|
|
424
|
+
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
425
|
+
}
|
|
426
|
+
|
|
380
427
|
async persistWorkflowSnapshot({
|
|
381
428
|
workflowName,
|
|
382
429
|
runId,
|
|
@@ -405,12 +452,18 @@ export class LanceStorage extends MastraStorage {
|
|
|
405
452
|
|
|
406
453
|
async getScoresByScorerId({
|
|
407
454
|
scorerId,
|
|
455
|
+
source,
|
|
456
|
+
entityId,
|
|
457
|
+
entityType,
|
|
408
458
|
pagination,
|
|
409
459
|
}: {
|
|
410
460
|
scorerId: string;
|
|
411
461
|
pagination: StoragePagination;
|
|
462
|
+
source?: ScoringSource;
|
|
463
|
+
entityId?: string;
|
|
464
|
+
entityType?: string;
|
|
412
465
|
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
413
|
-
return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
|
|
466
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, source, pagination, entityId, entityType });
|
|
414
467
|
}
|
|
415
468
|
|
|
416
469
|
async saveScore(_score: ScoreRowData): Promise<{ score: ScoreRowData }> {
|
package/src/vector/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { connect, Index } from '@lancedb/lancedb';
|
|
2
2
|
import type { Connection, ConnectionOptions, CreateTableOptions, Table, TableLike } from '@lancedb/lancedb';
|
|
3
3
|
|
|
4
|
+
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
4
5
|
import type {
|
|
5
6
|
CreateIndexParams,
|
|
6
7
|
DeleteIndexParams,
|
|
@@ -11,8 +12,7 @@ import type {
|
|
|
11
12
|
QueryVectorParams,
|
|
12
13
|
UpdateVectorParams,
|
|
13
14
|
UpsertVectorParams,
|
|
14
|
-
} from '@mastra/core';
|
|
15
|
-
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
15
|
+
} from '@mastra/core/vector';
|
|
16
16
|
|
|
17
17
|
import { MastraVector } from '@mastra/core/vector';
|
|
18
18
|
import type { LanceVectorFilter } from './filter';
|
package/tsconfig.json
CHANGED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { generateTypes } from '@internal/types-builder';
|
|
2
|
+
import { defineConfig } from 'tsup';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
entry: ['src/index.ts'],
|
|
6
|
+
format: ['esm', 'cjs'],
|
|
7
|
+
clean: true,
|
|
8
|
+
dts: false,
|
|
9
|
+
splitting: true,
|
|
10
|
+
treeshake: {
|
|
11
|
+
preset: 'smallest',
|
|
12
|
+
},
|
|
13
|
+
sourcemap: true,
|
|
14
|
+
onSuccess: async () => {
|
|
15
|
+
await generateTypes(process.cwd());
|
|
16
|
+
},
|
|
17
|
+
});
|