@mastra/libsql 0.0.1-alpha.1
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/.turbo/turbo-build.log +23 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE.md +7 -0
- package/README.md +144 -0
- package/dist/_tsup-dts-rollup.d.cts +192 -0
- package/dist/_tsup-dts-rollup.d.ts +192 -0
- package/dist/index.cjs +1143 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1139 -0
- package/eslint.config.js +6 -0
- package/package.json +42 -0
- package/src/index.ts +2 -0
- package/src/storage/index.test.ts +15 -0
- package/src/storage/index.ts +624 -0
- package/src/vector/filter.test.ts +968 -0
- package/src/vector/filter.ts +117 -0
- package/src/vector/index.test.ts +1702 -0
- package/src/vector/index.ts +344 -0
- package/src/vector/sql-builder.ts +462 -0
- package/tsconfig.json +5 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
> @mastra/libsql@0.0.1-alpha.1 build /home/runner/work/mastra/mastra/stores/libsql
|
|
3
|
+
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.4.0
|
|
8
|
+
[34mTSC[39m Build start
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 7465ms
|
|
10
|
+
[34mDTS[39m Build start
|
|
11
|
+
[34mCLI[39m Target: es2022
|
|
12
|
+
Analysis will use the bundled TypeScript version 5.8.2
|
|
13
|
+
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/libsql/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
|
+
Analysis will use the bundled TypeScript version 5.8.2
|
|
15
|
+
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/libsql/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 5630ms
|
|
17
|
+
[34mCLI[39m Cleaning output folder
|
|
18
|
+
[34mESM[39m Build start
|
|
19
|
+
[34mCJS[39m Build start
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m35.92 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 625ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m35.84 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 626ms
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @mastra/libsql
|
|
2
|
+
|
|
3
|
+
## 0.0.1-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2d4001d: Add new @msstra/libsql package and use it in create-mastra
|
|
8
|
+
- Updated dependencies [20275d4]
|
|
9
|
+
- Updated dependencies [7d1892c]
|
|
10
|
+
- Updated dependencies [a90a082]
|
|
11
|
+
- Updated dependencies [35955b0]
|
|
12
|
+
- Updated dependencies [c1409ef]
|
|
13
|
+
- Updated dependencies [11d4485]
|
|
14
|
+
- Updated dependencies [2d4001d]
|
|
15
|
+
- @mastra/core@0.9.1-alpha.1
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Mastra AI, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @mastra/pg
|
|
2
|
+
|
|
3
|
+
SQLite implementation for Mastra, providing both vector similarity search and general storage capabilities with connection pooling and transaction support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/libsql
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Vector Store
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { LibSQLVector } from '@mastra/libsql';
|
|
17
|
+
|
|
18
|
+
const vectorStore = new LibSQLVector({
|
|
19
|
+
url: 'file:./my-db.db'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Create a new table with vector support
|
|
23
|
+
await vectorStore.createIndex({
|
|
24
|
+
indexName: 'my_vectors',
|
|
25
|
+
dimension: 1536,
|
|
26
|
+
metric: 'cosine',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Add vectors
|
|
30
|
+
const ids = await vectorStore.upsert({
|
|
31
|
+
indexName: 'my_vectors',
|
|
32
|
+
vectors: [[0.1, 0.2, ...], [0.3, 0.4, ...]],
|
|
33
|
+
metadata: [{ text: 'doc1' }, { text: 'doc2' }],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Query vectors
|
|
37
|
+
const results = await vectorStore.query({
|
|
38
|
+
indexName: 'my_vectors',
|
|
39
|
+
queryVector: [0.1, 0.2, ...],
|
|
40
|
+
topK: 10, // topK
|
|
41
|
+
filter: { text: 'doc1' }, // filter
|
|
42
|
+
includeVector: false, // includeVector
|
|
43
|
+
minScore: 0.5, // minScore
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Storage
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { LibSQLStore } from '@mastra/pg';
|
|
51
|
+
|
|
52
|
+
const store = new LibSQLStore({
|
|
53
|
+
url: 'file:./my-db.db',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Create a thread
|
|
57
|
+
await store.saveThread({
|
|
58
|
+
id: 'thread-123',
|
|
59
|
+
resourceId: 'resource-456',
|
|
60
|
+
title: 'My Thread',
|
|
61
|
+
metadata: { key: 'value' },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Add messages to thread
|
|
65
|
+
await store.saveMessages([
|
|
66
|
+
{
|
|
67
|
+
id: 'msg-789',
|
|
68
|
+
threadId: 'thread-123',
|
|
69
|
+
role: 'user',
|
|
70
|
+
type: 'text',
|
|
71
|
+
content: [{ type: 'text', text: 'Hello' }],
|
|
72
|
+
},
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
// Query threads and messages
|
|
76
|
+
const savedThread = await store.getThread('thread-123');
|
|
77
|
+
const messages = await store.getMessages('thread-123');
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Configuration
|
|
81
|
+
|
|
82
|
+
The LibSQLStore store can be initialized with:
|
|
83
|
+
|
|
84
|
+
- Configuration object with url and auth. Auth is only necessary when using a provider like [Turso](https://turso.tech/)
|
|
85
|
+
|
|
86
|
+
## Features
|
|
87
|
+
|
|
88
|
+
### Vector Store Features
|
|
89
|
+
|
|
90
|
+
- Vector similarity search with cosine, euclidean, and dot product metrics
|
|
91
|
+
- Advanced metadata filtering with MongoDB-like query syntax
|
|
92
|
+
- Minimum score threshold for queries
|
|
93
|
+
- Automatic UUID generation for vectors
|
|
94
|
+
- Table management (create, list, describe, delete, truncate)
|
|
95
|
+
|
|
96
|
+
### Storage Features
|
|
97
|
+
|
|
98
|
+
- Thread and message storage with JSON support
|
|
99
|
+
- Atomic transactions for data consistency
|
|
100
|
+
- Efficient batch operations
|
|
101
|
+
- Rich metadata support
|
|
102
|
+
- Timestamp tracking
|
|
103
|
+
- Cascading deletes
|
|
104
|
+
|
|
105
|
+
## Supported Filter Operators
|
|
106
|
+
|
|
107
|
+
The following filter operators are supported for metadata queries:
|
|
108
|
+
|
|
109
|
+
- Comparison: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
|
|
110
|
+
- Logical: `$and`, `$or`
|
|
111
|
+
- Array: `$in`, `$nin`
|
|
112
|
+
- Text: `$regex`, `$like`
|
|
113
|
+
|
|
114
|
+
Example filter:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
{
|
|
118
|
+
$and: [{ age: { $gt: 25 } }, { tags: { $in: ['tag1', 'tag2'] } }];
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Vector Store Methods
|
|
123
|
+
|
|
124
|
+
- `createIndex({indexName, dimension, metric?, indexConfig?, defineIndex?})`: Create a new table with vector support
|
|
125
|
+
- `upsert({indexName, vectors, metadata?, ids?})`: Add or update vectors
|
|
126
|
+
- `query({indexName, queryVector, topK?, filter?, includeVector?, minScore?})`: Search for similar vectors
|
|
127
|
+
- `defineIndex({indexName, metric?, indexConfig?})`: Define an index
|
|
128
|
+
- `listIndexes()`: List all vector-enabled tables
|
|
129
|
+
- `describeIndex(indexName)`: Get table statistics
|
|
130
|
+
- `deleteIndex(indexName)`: Delete a table
|
|
131
|
+
- `truncateIndex(indexName)`: Remove all data from a table
|
|
132
|
+
|
|
133
|
+
## Storage Methods
|
|
134
|
+
|
|
135
|
+
- `saveThread(thread)`: Create or update a thread
|
|
136
|
+
- `getThread(threadId)`: Get a thread by ID
|
|
137
|
+
- `deleteThread(threadId)`: Delete a thread and its messages
|
|
138
|
+
- `saveMessages(messages)`: Save multiple messages in a transaction
|
|
139
|
+
- `getMessages(threadId)`: Get all messages for a thread
|
|
140
|
+
- `deleteMessages(messageIds)`: Delete specific messages
|
|
141
|
+
|
|
142
|
+
## Related Links
|
|
143
|
+
|
|
144
|
+
- [LibSQL Documentation](https://docs.turso.tech/sdk/introductionh)
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { ArrayOperator } from '@mastra/core/vector/filter';
|
|
2
|
+
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
3
|
+
import type { BasicOperator } from '@mastra/core/vector/filter';
|
|
4
|
+
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
5
|
+
import type { ElementOperator } from '@mastra/core/vector/filter';
|
|
6
|
+
import type { EvalRow } from '@mastra/core/storage';
|
|
7
|
+
import type { IndexStats } from '@mastra/core/vector';
|
|
8
|
+
import type { InValue } from '@libsql/client';
|
|
9
|
+
import type { LogicalOperator } from '@mastra/core/vector/filter';
|
|
10
|
+
import { MastraStorage } from '@mastra/core/storage';
|
|
11
|
+
import { MastraVector } from '@mastra/core/vector';
|
|
12
|
+
import type { MessageType } from '@mastra/core/memory';
|
|
13
|
+
import type { NumericOperator } from '@mastra/core/vector/filter';
|
|
14
|
+
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
15
|
+
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
16
|
+
import type { QueryResult } from '@mastra/core/vector';
|
|
17
|
+
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
18
|
+
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
19
|
+
import type { RegexOperator } from '@mastra/core/vector/filter';
|
|
20
|
+
import type { StorageColumn } from '@mastra/core/storage';
|
|
21
|
+
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
22
|
+
import type { StorageThreadType } from '@mastra/core/memory';
|
|
23
|
+
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
24
|
+
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
25
|
+
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
26
|
+
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
27
|
+
|
|
28
|
+
export declare function buildFilterQuery(filter: VectorFilter): FilterResult;
|
|
29
|
+
|
|
30
|
+
export declare const FILTER_OPERATORS: Record<string, OperatorFn>;
|
|
31
|
+
|
|
32
|
+
declare type FilterOperator = {
|
|
33
|
+
sql: string;
|
|
34
|
+
needsValue: boolean;
|
|
35
|
+
transformValue?: (value: any) => any;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export declare interface FilterResult {
|
|
39
|
+
sql: string;
|
|
40
|
+
values: InValue[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare const handleKey: (key: string) => string;
|
|
44
|
+
|
|
45
|
+
declare interface LibSQLConfig {
|
|
46
|
+
url: string;
|
|
47
|
+
authToken?: string;
|
|
48
|
+
}
|
|
49
|
+
export { LibSQLConfig }
|
|
50
|
+
export { LibSQLConfig as LibSQLConfig_alias_1 }
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Translates MongoDB-style filters to LibSQL compatible filters.
|
|
54
|
+
*
|
|
55
|
+
* Key differences from MongoDB:
|
|
56
|
+
*
|
|
57
|
+
* Logical Operators ($and, $or, $nor):
|
|
58
|
+
* - Can be used at the top level or nested within fields
|
|
59
|
+
* - Can take either a single condition or an array of conditions
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
export declare class LibSQLFilterTranslator extends BaseFilterTranslator {
|
|
63
|
+
protected getSupportedOperators(): OperatorSupport;
|
|
64
|
+
translate(filter?: VectorFilter): VectorFilter;
|
|
65
|
+
private translateNode;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare type LibSQLQueryArgs = [...QueryVectorArgs, number?];
|
|
69
|
+
|
|
70
|
+
declare interface LibSQLQueryParams extends QueryVectorParams {
|
|
71
|
+
minScore?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare class LibSQLStore extends MastraStorage {
|
|
75
|
+
private client;
|
|
76
|
+
constructor(config: LibSQLConfig);
|
|
77
|
+
private getCreateTableSQL;
|
|
78
|
+
createTable({ tableName, schema, }: {
|
|
79
|
+
tableName: TABLE_NAMES;
|
|
80
|
+
schema: Record<string, StorageColumn>;
|
|
81
|
+
}): Promise<void>;
|
|
82
|
+
clearTable({ tableName }: {
|
|
83
|
+
tableName: TABLE_NAMES;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
private prepareStatement;
|
|
86
|
+
insert({ tableName, record }: {
|
|
87
|
+
tableName: TABLE_NAMES;
|
|
88
|
+
record: Record<string, any>;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
batchInsert({ tableName, records }: {
|
|
91
|
+
tableName: TABLE_NAMES;
|
|
92
|
+
records: Record<string, any>[];
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
load<R>({ tableName, keys }: {
|
|
95
|
+
tableName: TABLE_NAMES;
|
|
96
|
+
keys: Record<string, string>;
|
|
97
|
+
}): Promise<R | null>;
|
|
98
|
+
getThreadById({ threadId }: {
|
|
99
|
+
threadId: string;
|
|
100
|
+
}): Promise<StorageThreadType | null>;
|
|
101
|
+
getThreadsByResourceId({ resourceId }: {
|
|
102
|
+
resourceId: string;
|
|
103
|
+
}): Promise<StorageThreadType[]>;
|
|
104
|
+
saveThread({ thread }: {
|
|
105
|
+
thread: StorageThreadType;
|
|
106
|
+
}): Promise<StorageThreadType>;
|
|
107
|
+
updateThread({ id, title, metadata, }: {
|
|
108
|
+
id: string;
|
|
109
|
+
title: string;
|
|
110
|
+
metadata: Record<string, unknown>;
|
|
111
|
+
}): Promise<StorageThreadType>;
|
|
112
|
+
deleteThread({ threadId }: {
|
|
113
|
+
threadId: string;
|
|
114
|
+
}): Promise<void>;
|
|
115
|
+
private parseRow;
|
|
116
|
+
getMessages<T extends MessageType[]>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
|
|
117
|
+
saveMessages({ messages }: {
|
|
118
|
+
messages: MessageType[];
|
|
119
|
+
}): Promise<MessageType[]>;
|
|
120
|
+
private transformEvalRow;
|
|
121
|
+
getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
|
122
|
+
getTraces({ name, scope, page, perPage, attributes, filters, }?: {
|
|
123
|
+
name?: string;
|
|
124
|
+
scope?: string;
|
|
125
|
+
page: number;
|
|
126
|
+
perPage: number;
|
|
127
|
+
attributes?: Record<string, string>;
|
|
128
|
+
filters?: Record<string, any>;
|
|
129
|
+
}): Promise<any[]>;
|
|
130
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
|
|
131
|
+
workflowName?: string;
|
|
132
|
+
fromDate?: Date;
|
|
133
|
+
toDate?: Date;
|
|
134
|
+
limit?: number;
|
|
135
|
+
offset?: number;
|
|
136
|
+
}): Promise<{
|
|
137
|
+
runs: Array<{
|
|
138
|
+
workflowName: string;
|
|
139
|
+
runId: string;
|
|
140
|
+
snapshot: WorkflowRunState | string;
|
|
141
|
+
createdAt: Date;
|
|
142
|
+
updatedAt: Date;
|
|
143
|
+
}>;
|
|
144
|
+
total: number;
|
|
145
|
+
}>;
|
|
146
|
+
}
|
|
147
|
+
export { LibSQLStore as DefaultStorage }
|
|
148
|
+
export { LibSQLStore as DefaultStorage_alias_1 }
|
|
149
|
+
export { LibSQLStore }
|
|
150
|
+
export { LibSQLStore as LibSQLStore_alias_1 }
|
|
151
|
+
|
|
152
|
+
declare class LibSQLVector extends MastraVector {
|
|
153
|
+
private turso;
|
|
154
|
+
constructor({ connectionUrl, authToken, syncUrl, syncInterval, }: {
|
|
155
|
+
connectionUrl: string;
|
|
156
|
+
authToken?: string;
|
|
157
|
+
syncUrl?: string;
|
|
158
|
+
syncInterval?: number;
|
|
159
|
+
});
|
|
160
|
+
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
161
|
+
query(...args: ParamsToArgs<LibSQLQueryParams> | LibSQLQueryArgs): Promise<QueryResult[]>;
|
|
162
|
+
upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
|
|
163
|
+
createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
|
|
164
|
+
deleteIndex(indexName: string): Promise<void>;
|
|
165
|
+
listIndexes(): Promise<string[]>;
|
|
166
|
+
describeIndex(indexName: string): Promise<IndexStats>;
|
|
167
|
+
/**
|
|
168
|
+
* Updates an index entry by its ID with the provided vector and/or metadata.
|
|
169
|
+
*
|
|
170
|
+
* @param indexName - The name of the index to update.
|
|
171
|
+
* @param id - The ID of the index entry to update.
|
|
172
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
173
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
174
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
175
|
+
* @returns A promise that resolves when the update is complete.
|
|
176
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
177
|
+
*/
|
|
178
|
+
updateIndexById(indexName: string, id: string, update: {
|
|
179
|
+
vector?: number[];
|
|
180
|
+
metadata?: Record<string, any>;
|
|
181
|
+
}): Promise<void>;
|
|
182
|
+
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
183
|
+
truncateIndex(indexName: string): Promise<void>;
|
|
184
|
+
}
|
|
185
|
+
export { LibSQLVector }
|
|
186
|
+
export { LibSQLVector as LibSQLVector_alias_1 }
|
|
187
|
+
|
|
188
|
+
declare type OperatorFn = (key: string, value?: any) => FilterOperator;
|
|
189
|
+
|
|
190
|
+
export declare type OperatorType = BasicOperator | NumericOperator | ArrayOperator | ElementOperator | LogicalOperator | '$contains' | Exclude<RegexOperator, '$options'>;
|
|
191
|
+
|
|
192
|
+
export { }
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { ArrayOperator } from '@mastra/core/vector/filter';
|
|
2
|
+
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
3
|
+
import type { BasicOperator } from '@mastra/core/vector/filter';
|
|
4
|
+
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
5
|
+
import type { ElementOperator } from '@mastra/core/vector/filter';
|
|
6
|
+
import type { EvalRow } from '@mastra/core/storage';
|
|
7
|
+
import type { IndexStats } from '@mastra/core/vector';
|
|
8
|
+
import type { InValue } from '@libsql/client';
|
|
9
|
+
import type { LogicalOperator } from '@mastra/core/vector/filter';
|
|
10
|
+
import { MastraStorage } from '@mastra/core/storage';
|
|
11
|
+
import { MastraVector } from '@mastra/core/vector';
|
|
12
|
+
import type { MessageType } from '@mastra/core/memory';
|
|
13
|
+
import type { NumericOperator } from '@mastra/core/vector/filter';
|
|
14
|
+
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
15
|
+
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
16
|
+
import type { QueryResult } from '@mastra/core/vector';
|
|
17
|
+
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
18
|
+
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
19
|
+
import type { RegexOperator } from '@mastra/core/vector/filter';
|
|
20
|
+
import type { StorageColumn } from '@mastra/core/storage';
|
|
21
|
+
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
22
|
+
import type { StorageThreadType } from '@mastra/core/memory';
|
|
23
|
+
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
24
|
+
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
25
|
+
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
26
|
+
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
27
|
+
|
|
28
|
+
export declare function buildFilterQuery(filter: VectorFilter): FilterResult;
|
|
29
|
+
|
|
30
|
+
export declare const FILTER_OPERATORS: Record<string, OperatorFn>;
|
|
31
|
+
|
|
32
|
+
declare type FilterOperator = {
|
|
33
|
+
sql: string;
|
|
34
|
+
needsValue: boolean;
|
|
35
|
+
transformValue?: (value: any) => any;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export declare interface FilterResult {
|
|
39
|
+
sql: string;
|
|
40
|
+
values: InValue[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare const handleKey: (key: string) => string;
|
|
44
|
+
|
|
45
|
+
declare interface LibSQLConfig {
|
|
46
|
+
url: string;
|
|
47
|
+
authToken?: string;
|
|
48
|
+
}
|
|
49
|
+
export { LibSQLConfig }
|
|
50
|
+
export { LibSQLConfig as LibSQLConfig_alias_1 }
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Translates MongoDB-style filters to LibSQL compatible filters.
|
|
54
|
+
*
|
|
55
|
+
* Key differences from MongoDB:
|
|
56
|
+
*
|
|
57
|
+
* Logical Operators ($and, $or, $nor):
|
|
58
|
+
* - Can be used at the top level or nested within fields
|
|
59
|
+
* - Can take either a single condition or an array of conditions
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
export declare class LibSQLFilterTranslator extends BaseFilterTranslator {
|
|
63
|
+
protected getSupportedOperators(): OperatorSupport;
|
|
64
|
+
translate(filter?: VectorFilter): VectorFilter;
|
|
65
|
+
private translateNode;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare type LibSQLQueryArgs = [...QueryVectorArgs, number?];
|
|
69
|
+
|
|
70
|
+
declare interface LibSQLQueryParams extends QueryVectorParams {
|
|
71
|
+
minScore?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare class LibSQLStore extends MastraStorage {
|
|
75
|
+
private client;
|
|
76
|
+
constructor(config: LibSQLConfig);
|
|
77
|
+
private getCreateTableSQL;
|
|
78
|
+
createTable({ tableName, schema, }: {
|
|
79
|
+
tableName: TABLE_NAMES;
|
|
80
|
+
schema: Record<string, StorageColumn>;
|
|
81
|
+
}): Promise<void>;
|
|
82
|
+
clearTable({ tableName }: {
|
|
83
|
+
tableName: TABLE_NAMES;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
private prepareStatement;
|
|
86
|
+
insert({ tableName, record }: {
|
|
87
|
+
tableName: TABLE_NAMES;
|
|
88
|
+
record: Record<string, any>;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
batchInsert({ tableName, records }: {
|
|
91
|
+
tableName: TABLE_NAMES;
|
|
92
|
+
records: Record<string, any>[];
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
load<R>({ tableName, keys }: {
|
|
95
|
+
tableName: TABLE_NAMES;
|
|
96
|
+
keys: Record<string, string>;
|
|
97
|
+
}): Promise<R | null>;
|
|
98
|
+
getThreadById({ threadId }: {
|
|
99
|
+
threadId: string;
|
|
100
|
+
}): Promise<StorageThreadType | null>;
|
|
101
|
+
getThreadsByResourceId({ resourceId }: {
|
|
102
|
+
resourceId: string;
|
|
103
|
+
}): Promise<StorageThreadType[]>;
|
|
104
|
+
saveThread({ thread }: {
|
|
105
|
+
thread: StorageThreadType;
|
|
106
|
+
}): Promise<StorageThreadType>;
|
|
107
|
+
updateThread({ id, title, metadata, }: {
|
|
108
|
+
id: string;
|
|
109
|
+
title: string;
|
|
110
|
+
metadata: Record<string, unknown>;
|
|
111
|
+
}): Promise<StorageThreadType>;
|
|
112
|
+
deleteThread({ threadId }: {
|
|
113
|
+
threadId: string;
|
|
114
|
+
}): Promise<void>;
|
|
115
|
+
private parseRow;
|
|
116
|
+
getMessages<T extends MessageType[]>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
|
|
117
|
+
saveMessages({ messages }: {
|
|
118
|
+
messages: MessageType[];
|
|
119
|
+
}): Promise<MessageType[]>;
|
|
120
|
+
private transformEvalRow;
|
|
121
|
+
getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
|
122
|
+
getTraces({ name, scope, page, perPage, attributes, filters, }?: {
|
|
123
|
+
name?: string;
|
|
124
|
+
scope?: string;
|
|
125
|
+
page: number;
|
|
126
|
+
perPage: number;
|
|
127
|
+
attributes?: Record<string, string>;
|
|
128
|
+
filters?: Record<string, any>;
|
|
129
|
+
}): Promise<any[]>;
|
|
130
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
|
|
131
|
+
workflowName?: string;
|
|
132
|
+
fromDate?: Date;
|
|
133
|
+
toDate?: Date;
|
|
134
|
+
limit?: number;
|
|
135
|
+
offset?: number;
|
|
136
|
+
}): Promise<{
|
|
137
|
+
runs: Array<{
|
|
138
|
+
workflowName: string;
|
|
139
|
+
runId: string;
|
|
140
|
+
snapshot: WorkflowRunState | string;
|
|
141
|
+
createdAt: Date;
|
|
142
|
+
updatedAt: Date;
|
|
143
|
+
}>;
|
|
144
|
+
total: number;
|
|
145
|
+
}>;
|
|
146
|
+
}
|
|
147
|
+
export { LibSQLStore as DefaultStorage }
|
|
148
|
+
export { LibSQLStore as DefaultStorage_alias_1 }
|
|
149
|
+
export { LibSQLStore }
|
|
150
|
+
export { LibSQLStore as LibSQLStore_alias_1 }
|
|
151
|
+
|
|
152
|
+
declare class LibSQLVector extends MastraVector {
|
|
153
|
+
private turso;
|
|
154
|
+
constructor({ connectionUrl, authToken, syncUrl, syncInterval, }: {
|
|
155
|
+
connectionUrl: string;
|
|
156
|
+
authToken?: string;
|
|
157
|
+
syncUrl?: string;
|
|
158
|
+
syncInterval?: number;
|
|
159
|
+
});
|
|
160
|
+
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
161
|
+
query(...args: ParamsToArgs<LibSQLQueryParams> | LibSQLQueryArgs): Promise<QueryResult[]>;
|
|
162
|
+
upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
|
|
163
|
+
createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
|
|
164
|
+
deleteIndex(indexName: string): Promise<void>;
|
|
165
|
+
listIndexes(): Promise<string[]>;
|
|
166
|
+
describeIndex(indexName: string): Promise<IndexStats>;
|
|
167
|
+
/**
|
|
168
|
+
* Updates an index entry by its ID with the provided vector and/or metadata.
|
|
169
|
+
*
|
|
170
|
+
* @param indexName - The name of the index to update.
|
|
171
|
+
* @param id - The ID of the index entry to update.
|
|
172
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
173
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
174
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
175
|
+
* @returns A promise that resolves when the update is complete.
|
|
176
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
177
|
+
*/
|
|
178
|
+
updateIndexById(indexName: string, id: string, update: {
|
|
179
|
+
vector?: number[];
|
|
180
|
+
metadata?: Record<string, any>;
|
|
181
|
+
}): Promise<void>;
|
|
182
|
+
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
183
|
+
truncateIndex(indexName: string): Promise<void>;
|
|
184
|
+
}
|
|
185
|
+
export { LibSQLVector }
|
|
186
|
+
export { LibSQLVector as LibSQLVector_alias_1 }
|
|
187
|
+
|
|
188
|
+
declare type OperatorFn = (key: string, value?: any) => FilterOperator;
|
|
189
|
+
|
|
190
|
+
export declare type OperatorType = BasicOperator | NumericOperator | ArrayOperator | ElementOperator | LogicalOperator | '$contains' | Exclude<RegexOperator, '$options'>;
|
|
191
|
+
|
|
192
|
+
export { }
|