@mastra/lance 0.0.0-working-memory-per-user-20250620163010 → 0.0.0-zod-v4-compat-part-2-20250822105954

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