@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,9 @@
1
+ {
2
+ "extends": ["./tsconfig.json", "../../tsconfig.build.json"],
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "**/*.test.ts", "src/**/*.mock.ts"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
3
+ "include": ["src/**/*", "tsup.config.ts"],
4
4
  "exclude": ["node_modules", "**/*.test.ts"]
5
5
  }
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
+ });
@@ -1,409 +0,0 @@
1
- import { ArrayOperator } from '@mastra/core/vector/filter';
2
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
3
- import { BasicOperator } from '@mastra/core/vector/filter';
4
- import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
5
- import type { ConnectionOptions } from '@lancedb/lancedb';
6
- import type { CreateIndexParams } from '@mastra/core';
7
- import type { CreateTableOptions } from '@lancedb/lancedb';
8
- import type { DeleteIndexParams } from '@mastra/core';
9
- import type { DeleteVectorParams } from '@mastra/core';
10
- import type { DescribeIndexParams } from '@mastra/core';
11
- import type { EvalRow } from '@mastra/core/storage';
12
- import type { IndexStats } from '@mastra/core';
13
- import { LogicalOperator } from '@mastra/core/vector/filter';
14
- import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
15
- import type { MastraMessageContentV2 } from '@mastra/core/agent';
16
- import type { MastraMessageV1 } from '@mastra/core/memory';
17
- import type { MastraMessageV2 } from '@mastra/core/memory';
18
- import { MastraStorage } from '@mastra/core/storage';
19
- import { MastraVector } from '@mastra/core/vector';
20
- import { NumericOperator } from '@mastra/core/vector/filter';
21
- import type { OperatorValueMap } from '@mastra/core/vector/filter';
22
- import type { PaginationInfo } from '@mastra/core/storage';
23
- import type { QueryResult } from '@mastra/core';
24
- import type { QueryVectorParams } from '@mastra/core';
25
- import { RegexOperator } from '@mastra/core/vector/filter';
26
- import type { SchemaLike } from '@lancedb/lancedb';
27
- import type { StorageColumn } from '@mastra/core/storage';
28
- import type { StorageGetMessagesArg } from '@mastra/core/storage';
29
- import type { StorageGetTracesArg } from '@mastra/core/storage';
30
- import type { StorageThreadType } from '@mastra/core/memory';
31
- import type { Table } from '@lancedb/lancedb';
32
- import type { TABLE_NAMES } from '@mastra/core/storage';
33
- import type { TableLike } from '@lancedb/lancedb';
34
- import type { Trace } from '@mastra/core/telemetry';
35
- import type { TraceType } from '@mastra/core/memory';
36
- import type { UpdateVectorParams } from '@mastra/core';
37
- import type { UpsertVectorParams } from '@mastra/core';
38
- import type { VectorFilter } from '@mastra/core/vector/filter';
39
- import type { WorkflowRuns } from '@mastra/core/storage';
40
- import type { WorkflowRunState } from '@mastra/core/workflows';
41
-
42
- declare interface HNSWConfig {
43
- m?: number;
44
- efConstruction?: number;
45
- }
46
-
47
- export declare interface IndexConfig {
48
- type?: IndexType;
49
- ivf?: IVFConfig;
50
- hnsw?: HNSWConfig;
51
- }
52
-
53
- export declare type IndexType = 'ivfflat' | 'hnsw';
54
-
55
- declare interface IVFConfig {
56
- lists?: number;
57
- }
58
-
59
- declare type LanceBlacklisted = BlacklistedRootOperators | '$like' | '$notLike' | '$contains';
60
-
61
- declare interface LanceCreateIndexParams extends CreateIndexParams {
62
- indexConfig?: LanceIndexConfig;
63
- tableName?: string;
64
- }
65
-
66
- export declare class LanceFilterTranslator extends BaseFilterTranslator<LanceVectorFilter, string> {
67
- translate(filter: LanceVectorFilter): string;
68
- private processFilter;
69
- private processLogicalOperator;
70
- private processNestedObject;
71
- private processField;
72
- private processOperators;
73
- private formatValue;
74
- private formatArrayValues;
75
- normalizeArrayValues(array: unknown[]): unknown[];
76
- normalizeComparisonValue(value: unknown): unknown;
77
- private isOperatorObject;
78
- private isNestedObject;
79
- private isNormalNestedField;
80
- private escapeFieldName;
81
- private isSqlKeyword;
82
- private isDateObject;
83
- /**
84
- * Override getSupportedOperators to add custom operators for LanceDB
85
- */
86
- protected getSupportedOperators(): {
87
- custom: string[];
88
- logical: LogicalOperator[];
89
- basic: BasicOperator[];
90
- numeric: NumericOperator[];
91
- array: ArrayOperator[];
92
- element: "$exists"[];
93
- regex: RegexOperator[];
94
- };
95
- }
96
-
97
- declare interface LanceIndexConfig extends IndexConfig {
98
- numPartitions?: number;
99
- numSubVectors?: number;
100
- }
101
-
102
- declare type LanceOperatorValueMap = OperatorValueMap & {
103
- $like: string;
104
- $notLike: string;
105
- $contains: string;
106
- };
107
-
108
- declare interface LanceQueryVectorParams extends QueryVectorParams<LanceVectorFilter> {
109
- tableName: string;
110
- columns?: string[];
111
- includeAllColumns?: boolean;
112
- }
113
-
114
- declare class LanceStorage extends MastraStorage {
115
- private lanceClient;
116
- /**
117
- * Creates a new instance of LanceStorage
118
- * @param uri The URI to connect to LanceDB
119
- * @param options connection options
120
- *
121
- * Usage:
122
- *
123
- * Connect to a local database
124
- * ```ts
125
- * const store = await LanceStorage.create('/path/to/db');
126
- * ```
127
- *
128
- * Connect to a LanceDB cloud database
129
- * ```ts
130
- * const store = await LanceStorage.create('db://host:port');
131
- * ```
132
- *
133
- * Connect to a cloud database
134
- * ```ts
135
- * const store = await LanceStorage.create('s3://bucket/db', { storageOptions: { timeout: '60s' } });
136
- * ```
137
- */
138
- static create(name: string, uri: string, options?: ConnectionOptions): Promise<LanceStorage>;
139
- private getPrimaryKeys;
140
- /**
141
- * @internal
142
- * Private constructor to enforce using the create factory method
143
- */
144
- private constructor();
145
- createTable({ tableName, schema, }: {
146
- tableName: TABLE_NAMES;
147
- schema: Record<string, StorageColumn>;
148
- }): Promise<void>;
149
- private translateSchema;
150
- /**
151
- * Drop a table if it exists
152
- * @param tableName Name of the table to drop
153
- */
154
- dropTable(tableName: TABLE_NAMES): Promise<void>;
155
- /**
156
- * Get table schema
157
- * @param tableName Name of the table
158
- * @returns Table schema
159
- */
160
- getTableSchema(tableName: TABLE_NAMES): Promise<SchemaLike>;
161
- protected getDefaultValue(type: StorageColumn['type']): string;
162
- /**
163
- * Alters table schema to add columns if they don't exist
164
- * @param tableName Name of the table
165
- * @param schema Schema of the table
166
- * @param ifNotExists Array of column names to add if they don't exist
167
- */
168
- alterTable({ tableName, schema, ifNotExists, }: {
169
- tableName: string;
170
- schema: Record<string, StorageColumn>;
171
- ifNotExists: string[];
172
- }): Promise<void>;
173
- clearTable({ tableName }: {
174
- tableName: TABLE_NAMES;
175
- }): Promise<void>;
176
- /**
177
- * Insert a single record into a table. This function overwrites the existing record if it exists. Use this function for inserting records into tables with custom schemas.
178
- * @param tableName The name of the table to insert into.
179
- * @param record The record to insert.
180
- */
181
- insert({ tableName, record }: {
182
- tableName: string;
183
- record: Record<string, any>;
184
- }): Promise<void>;
185
- /**
186
- * Insert multiple records into a table. This function overwrites the existing records if they exist. Use this function for inserting records into tables with custom schemas.
187
- * @param tableName The name of the table to insert into.
188
- * @param records The records to insert.
189
- */
190
- batchInsert({ tableName, records }: {
191
- tableName: string;
192
- records: Record<string, any>[];
193
- }): Promise<void>;
194
- /**
195
- * Load a record from the database by its key(s)
196
- * @param tableName The name of the table to query
197
- * @param keys Record of key-value pairs to use for lookup
198
- * @throws Error if invalid types are provided for keys
199
- * @returns The loaded record with proper type conversions, or null if not found
200
- */
201
- load({ tableName, keys }: {
202
- tableName: TABLE_NAMES;
203
- keys: Record<string, any>;
204
- }): Promise<any>;
205
- /**
206
- * Validates that key types match the schema definition
207
- * @param keys The keys to validate
208
- * @param tableSchema The table schema to validate against
209
- * @throws Error if a key has an incompatible type
210
- */
211
- private validateKeyTypes;
212
- /**
213
- * Process a database result with appropriate type conversions based on the table schema
214
- * @param rawResult The raw result object from the database
215
- * @param tableSchema The schema of the table containing type information
216
- * @returns Processed result with correct data types
217
- */
218
- private processResultWithTypeConversion;
219
- getThreadById({ threadId }: {
220
- threadId: string;
221
- }): Promise<StorageThreadType | null>;
222
- getThreadsByResourceId({ resourceId }: {
223
- resourceId: string;
224
- }): Promise<StorageThreadType[]>;
225
- /**
226
- * Saves a thread to the database. This function doesn't overwrite existing threads.
227
- * @param thread - The thread to save
228
- * @returns The saved thread
229
- */
230
- saveThread({ thread }: {
231
- thread: StorageThreadType;
232
- }): Promise<StorageThreadType>;
233
- updateThread({ id, title, metadata, }: {
234
- id: string;
235
- title: string;
236
- metadata: Record<string, unknown>;
237
- }): Promise<StorageThreadType>;
238
- deleteThread({ threadId }: {
239
- threadId: string;
240
- }): Promise<void>;
241
- /**
242
- * Processes messages to include context messages based on withPreviousMessages and withNextMessages
243
- * @param records - The sorted array of records to process
244
- * @param include - The array of include specifications with context parameters
245
- * @returns The processed array with context messages included
246
- */
247
- private processMessagesWithContext;
248
- getMessages(args: StorageGetMessagesArg & {
249
- format?: 'v1';
250
- }): Promise<MastraMessageV1[]>;
251
- getMessages(args: StorageGetMessagesArg & {
252
- format: 'v2';
253
- }): Promise<MastraMessageV2[]>;
254
- saveMessages(args: {
255
- messages: MastraMessageV1[];
256
- format?: undefined | 'v1';
257
- }): Promise<MastraMessageV1[]>;
258
- saveMessages(args: {
259
- messages: MastraMessageV2[];
260
- format: 'v2';
261
- }): Promise<MastraMessageV2[]>;
262
- saveTrace({ trace }: {
263
- trace: TraceType;
264
- }): Promise<TraceType>;
265
- getTraceById({ traceId }: {
266
- traceId: string;
267
- }): Promise<TraceType>;
268
- getTraces({ name, scope, page, perPage, attributes, }: {
269
- name?: string;
270
- scope?: string;
271
- page: number;
272
- perPage: number;
273
- attributes?: Record<string, string>;
274
- }): Promise<TraceType[]>;
275
- saveEvals({ evals }: {
276
- evals: EvalRow[];
277
- }): Promise<EvalRow[]>;
278
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
279
- private parseWorkflowRun;
280
- getWorkflowRuns(args?: {
281
- namespace?: string;
282
- workflowName?: string;
283
- fromDate?: Date;
284
- toDate?: Date;
285
- limit?: number;
286
- offset?: number;
287
- }): Promise<WorkflowRuns>;
288
- /**
289
- * Retrieve a single workflow run by its runId.
290
- * @param args The ID of the workflow run to retrieve
291
- * @returns The workflow run object or null if not found
292
- */
293
- getWorkflowRunById(args: {
294
- runId: string;
295
- workflowName?: string;
296
- }): Promise<{
297
- workflowName: string;
298
- runId: string;
299
- snapshot: any;
300
- createdAt: Date;
301
- updatedAt: Date;
302
- } | null>;
303
- persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
304
- workflowName: string;
305
- runId: string;
306
- snapshot: WorkflowRunState;
307
- }): Promise<void>;
308
- loadWorkflowSnapshot({ workflowName, runId, }: {
309
- workflowName: string;
310
- runId: string;
311
- }): Promise<WorkflowRunState | null>;
312
- getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
313
- traces: Trace[];
314
- }>;
315
- getThreadsByResourceIdPaginated(_args: {
316
- resourceId: string;
317
- page?: number;
318
- perPage?: number;
319
- }): Promise<PaginationInfo & {
320
- threads: StorageThreadType[];
321
- }>;
322
- getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
323
- messages: MastraMessageV1[] | MastraMessageV2[];
324
- }>;
325
- updateMessages(_args: {
326
- messages: Partial<Omit<MastraMessageV2, 'createdAt'>> & {
327
- id: string;
328
- content?: {
329
- metadata?: MastraMessageContentV2['metadata'];
330
- content?: MastraMessageContentV2['content'];
331
- };
332
- }[];
333
- }): Promise<MastraMessageV2[]>;
334
- }
335
- export { LanceStorage }
336
- export { LanceStorage as LanceStorage_alias_1 }
337
-
338
- declare interface LanceUpsertVectorParams extends UpsertVectorParams {
339
- tableName: string;
340
- }
341
-
342
- export declare type LanceVectorFilter = VectorFilter<keyof LanceOperatorValueMap, LanceOperatorValueMap, LogicalOperatorValueMap, LanceBlacklisted>;
343
-
344
- declare class LanceVectorStore extends MastraVector<LanceVectorFilter> {
345
- private lanceClient;
346
- /**
347
- * Creates a new instance of LanceVectorStore
348
- * @param uri The URI to connect to LanceDB
349
- * @param options connection options
350
- *
351
- * Usage:
352
- *
353
- * Connect to a local database
354
- * ```ts
355
- * const store = await LanceVectorStore.create('/path/to/db');
356
- * ```
357
- *
358
- * Connect to a LanceDB cloud database
359
- * ```ts
360
- * const store = await LanceVectorStore.create('db://host:port');
361
- * ```
362
- *
363
- * Connect to a cloud database
364
- * ```ts
365
- * const store = await LanceVectorStore.create('s3://bucket/db', { storageOptions: { timeout: '60s' } });
366
- * ```
367
- */
368
- static create(uri: string, options?: ConnectionOptions): Promise<LanceVectorStore>;
369
- /**
370
- * @internal
371
- * Private constructor to enforce using the create factory method
372
- */
373
- private constructor();
374
- close(): void;
375
- query({ tableName, queryVector, filter, includeVector, topK, columns, includeAllColumns, }: LanceQueryVectorParams): Promise<QueryResult[]>;
376
- private filterTranslator;
377
- upsert({ tableName, vectors, metadata, ids }: LanceUpsertVectorParams): Promise<string[]>;
378
- /**
379
- * Flattens a nested object, creating new keys with underscores for nested properties.
380
- * Example: { metadata: { text: 'test' } } → { metadata_text: 'test' }
381
- */
382
- private flattenObject;
383
- createTable(tableName: string, data: Record<string, unknown>[] | TableLike, options?: Partial<CreateTableOptions>): Promise<Table>;
384
- listTables(): Promise<string[]>;
385
- getTableSchema(tableName: string): Promise<any>;
386
- /**
387
- * indexName is actually a column name in a table in lanceDB
388
- */
389
- createIndex({ tableName, indexName, dimension, metric, indexConfig, }: LanceCreateIndexParams): Promise<void>;
390
- listIndexes(): Promise<string[]>;
391
- describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
392
- deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
393
- /**
394
- * Deletes all tables in the database
395
- */
396
- deleteAllTables(): Promise<void>;
397
- deleteTable(tableName: string): Promise<void>;
398
- updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
399
- deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
400
- /**
401
- * Converts a flattened object with keys using underscore notation back to a nested object.
402
- * Example: { name: 'test', details_text: 'test' } → { name: 'test', details: { text: 'test' } }
403
- */
404
- private unflattenObject;
405
- }
406
- export { LanceVectorStore }
407
- export { LanceVectorStore as LanceVectorStore_alias_1 }
408
-
409
- export { }