@mastra/lance 0.0.0-mcp-changeset-20250707162621 → 0.0.0-memory-system-message-error-20250813233316

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +177 -9
  2. package/LICENSE.md +11 -42
  3. package/dist/index.cjs +1649 -643
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +1584 -578
  8. package/dist/index.js.map +1 -0
  9. package/dist/storage/domains/legacy-evals/index.d.ts +25 -0
  10. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  11. package/dist/storage/domains/memory/index.d.ts +94 -0
  12. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  13. package/dist/storage/domains/operations/index.d.ts +40 -0
  14. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  15. package/dist/storage/domains/scores/index.d.ts +42 -0
  16. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  17. package/dist/storage/domains/traces/index.d.ts +34 -0
  18. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  19. package/dist/storage/domains/utils.d.ts +10 -0
  20. package/dist/storage/domains/utils.d.ts.map +1 -0
  21. package/dist/storage/domains/workflows/index.d.ts +38 -0
  22. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  23. package/dist/storage/index.d.ts +236 -0
  24. package/dist/storage/index.d.ts.map +1 -0
  25. package/dist/vector/filter.d.ts +41 -0
  26. package/dist/vector/filter.d.ts.map +1 -0
  27. package/dist/vector/index.d.ts +85 -0
  28. package/dist/vector/index.d.ts.map +1 -0
  29. package/dist/vector/types.d.ts +15 -0
  30. package/dist/vector/types.d.ts.map +1 -0
  31. package/package.json +11 -10
  32. package/src/storage/domains/legacy-evals/index.ts +156 -0
  33. package/src/storage/domains/memory/index.ts +947 -0
  34. package/src/storage/domains/operations/index.ts +489 -0
  35. package/src/storage/domains/scores/index.ts +243 -0
  36. package/src/storage/domains/traces/index.ts +212 -0
  37. package/src/storage/domains/utils.ts +158 -0
  38. package/src/storage/domains/workflows/index.ts +207 -0
  39. package/src/storage/index.test.ts +6 -1332
  40. package/src/storage/index.ts +163 -1162
  41. package/tsconfig.build.json +9 -0
  42. package/tsconfig.json +1 -1
  43. package/tsup.config.ts +17 -0
  44. package/dist/_tsup-dts-rollup.d.cts +0 -409
  45. package/dist/_tsup-dts-rollup.d.ts +0 -409
  46. package/dist/index.d.cts +0 -2
@@ -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';
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","sourceRo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Y,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiExE;;;OAGG;IACH,OAAO,CAAC,eAAe;CAgCxB"}
@@ -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-mcp-changeset-20250707162621",
3
+ "version": "0.0.0-memory-system-message-error-20250813233316",
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,33 +12,34 @@
12
12
  "default": "./dist/index.js"
13
13
  },
14
14
  "require": {
15
- "types": "./dist/index.d.cts",
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.18.2",
22
+ "@lancedb/lancedb": "^0.21.2",
23
23
  "apache-arrow": "^18.1.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.52.8",
27
27
  "@types/node": "^20.19.0",
28
- "eslint": "^9.29.0",
28
+ "eslint": "^9.30.1",
29
29
  "tsup": "^8.5.0",
30
30
  "typescript": "^5.8.3",
31
31
  "vitest": "^3.2.4",
32
- "@internal/lint": "0.0.0-mcp-changeset-20250707162621",
33
- "@mastra/core": "0.0.0-mcp-changeset-20250707162621",
34
- "@internal/storage-test-utils": "0.0.13"
32
+ "@internal/lint": "0.0.0-memory-system-message-error-20250813233316",
33
+ "@internal/storage-test-utils": "0.0.25",
34
+ "@mastra/core": "0.0.0-memory-system-message-error-20250813233316",
35
+ "@internal/types-builder": "0.0.0-memory-system-message-error-20250813233316"
35
36
  },
36
37
  "peerDependencies": {
37
- "@mastra/core": "0.0.0-mcp-changeset-20250707162621"
38
+ "@mastra/core": "0.0.0-memory-system-message-error-20250813233316"
38
39
  },
39
40
  "scripts": {
40
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
41
- "build:watch": "pnpm 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 ."
@@ -0,0 +1,156 @@
1
+ import type { Connection } from '@lancedb/lancedb';
2
+ import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
3
+ import { LegacyEvalsStorage, TABLE_EVALS } from '@mastra/core/storage';
4
+ import type { EvalRow, PaginationInfo } from '@mastra/core/storage';
5
+
6
+ export class StoreLegacyEvalsLance extends LegacyEvalsStorage {
7
+ private client: Connection;
8
+ constructor({ client }: { client: Connection }) {
9
+ super();
10
+ this.client = client;
11
+ }
12
+
13
+ async getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]> {
14
+ try {
15
+ const table = await this.client.openTable(TABLE_EVALS);
16
+ const query = table.query().where(`agent_name = '${agentName}'`);
17
+ const records = await query.toArray();
18
+
19
+ // Filter by type if specified
20
+ let filteredRecords = records;
21
+ if (type === 'live') {
22
+ // Live evals have test_info as null
23
+ filteredRecords = records.filter(record => record.test_info === null);
24
+ } else if (type === 'test') {
25
+ // Test evals have test_info as a JSON string
26
+ filteredRecords = records.filter(record => record.test_info !== null);
27
+ }
28
+
29
+ return filteredRecords.map(record => {
30
+ return {
31
+ id: record.id,
32
+ input: record.input,
33
+ output: record.output,
34
+ agentName: record.agent_name,
35
+ metricName: record.metric_name,
36
+ result: JSON.parse(record.result),
37
+ instructions: record.instructions,
38
+ testInfo: record.test_info ? JSON.parse(record.test_info) : null,
39
+ globalRunId: record.global_run_id,
40
+ runId: record.run_id,
41
+ createdAt: new Date(record.created_at).toString(),
42
+ };
43
+ }) as EvalRow[];
44
+ } catch (error: any) {
45
+ throw new MastraError(
46
+ {
47
+ id: 'LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED',
48
+ domain: ErrorDomain.STORAGE,
49
+ category: ErrorCategory.THIRD_PARTY,
50
+ details: { agentName },
51
+ },
52
+ error,
53
+ );
54
+ }
55
+ }
56
+
57
+ async getEvals(options: {
58
+ agentName?: string;
59
+ type?: 'test' | 'live';
60
+ page?: number;
61
+ perPage?: number;
62
+ fromDate?: Date;
63
+ toDate?: Date;
64
+ dateRange?: { start?: Date; end?: Date };
65
+ }): Promise<PaginationInfo & { evals: EvalRow[] }> {
66
+ try {
67
+ const table = await this.client.openTable(TABLE_EVALS);
68
+
69
+ // Build combined where clause
70
+ const conditions: string[] = [];
71
+
72
+ if (options.agentName) {
73
+ conditions.push(`agent_name = '${options.agentName}'`);
74
+ }
75
+
76
+ // Apply type filtering
77
+ if (options.type === 'live') {
78
+ conditions.push('length(test_info) = 0');
79
+ } else if (options.type === 'test') {
80
+ conditions.push('length(test_info) > 0');
81
+ }
82
+
83
+ // Apply date filtering
84
+ const startDate = options.dateRange?.start || options.fromDate;
85
+ const endDate = options.dateRange?.end || options.toDate;
86
+
87
+ if (startDate) {
88
+ conditions.push(`\`created_at\` >= ${startDate.getTime()}`);
89
+ }
90
+
91
+ if (endDate) {
92
+ conditions.push(`\`created_at\` <= ${endDate.getTime()}`);
93
+ }
94
+
95
+ // Get total count with the same conditions
96
+ let total = 0;
97
+ if (conditions.length > 0) {
98
+ total = await table.countRows(conditions.join(' AND '));
99
+ } else {
100
+ total = await table.countRows();
101
+ }
102
+
103
+ // Build query for fetching records
104
+ const query = table.query();
105
+
106
+ // Apply combined where clause if we have conditions
107
+ if (conditions.length > 0) {
108
+ const whereClause = conditions.join(' AND ');
109
+ query.where(whereClause);
110
+ }
111
+
112
+ const records = await query.toArray();
113
+
114
+ const evals = records
115
+ .sort((a, b) => b.created_at - a.created_at)
116
+ .map(record => {
117
+ return {
118
+ id: record.id,
119
+ input: record.input,
120
+ output: record.output,
121
+ agentName: record.agent_name,
122
+ metricName: record.metric_name,
123
+ result: JSON.parse(record.result),
124
+ instructions: record.instructions,
125
+ testInfo: record.test_info ? JSON.parse(record.test_info) : null,
126
+ globalRunId: record.global_run_id,
127
+ runId: record.run_id,
128
+ createdAt: new Date(record.created_at).toISOString(),
129
+ };
130
+ }) as EvalRow[];
131
+
132
+ // Apply pagination after filtering
133
+ const page = options.page || 0;
134
+ const perPage = options.perPage || 10;
135
+ const pagedEvals = evals.slice(page * perPage, (page + 1) * perPage);
136
+
137
+ return {
138
+ evals: pagedEvals,
139
+ total: total,
140
+ page,
141
+ perPage,
142
+ hasMore: total > (page + 1) * perPage,
143
+ };
144
+ } catch (error: any) {
145
+ throw new MastraError(
146
+ {
147
+ id: 'LANCE_STORE_GET_EVALS_FAILED',
148
+ domain: ErrorDomain.STORAGE,
149
+ category: ErrorCategory.THIRD_PARTY,
150
+ details: { agentName: options.agentName ?? '' },
151
+ },
152
+ error,
153
+ );
154
+ }
155
+ }
156
+ }