@mastra/libsql 1.22.3-alpha.2 → 1.22.3
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/README.md +13 -107
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-deployment-workers.md +6 -0
- package/dist/docs/references/docs-studio-editor.md +1 -1
- package/dist/docs/references/reference-core-mastra-class.md +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/vector/sql-builder.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -16,27 +16,30 @@ npm install @mastra/libsql
|
|
|
16
16
|
import { LibSQLVector } from '@mastra/libsql';
|
|
17
17
|
|
|
18
18
|
const vectorStore = new LibSQLVector({
|
|
19
|
-
url: 'file:./my-db.db'
|
|
19
|
+
url: 'file:./my-db.db',
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
// Create a new table with vector support
|
|
23
23
|
await vectorStore.createIndex({
|
|
24
24
|
indexName: 'my_vectors',
|
|
25
|
-
dimension:
|
|
25
|
+
dimension: 3,
|
|
26
26
|
metric: 'cosine',
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
// Add vectors
|
|
30
30
|
const ids = await vectorStore.upsert({
|
|
31
31
|
indexName: 'my_vectors',
|
|
32
|
-
vectors: [
|
|
32
|
+
vectors: [
|
|
33
|
+
[0.1, 0.2, 0.3],
|
|
34
|
+
[0.3, 0.4, 0.5],
|
|
35
|
+
],
|
|
33
36
|
metadata: [{ text: 'doc1' }, { text: 'doc2' }],
|
|
34
37
|
});
|
|
35
38
|
|
|
36
39
|
// Query vectors
|
|
37
40
|
const results = await vectorStore.query({
|
|
38
41
|
indexName: 'my_vectors',
|
|
39
|
-
queryVector: [0.1, 0.2,
|
|
42
|
+
queryVector: [0.1, 0.2, 0.3],
|
|
40
43
|
topK: 10, // topK
|
|
41
44
|
filter: { text: 'doc1' }, // filter
|
|
42
45
|
includeVector: false, // includeVector
|
|
@@ -44,111 +47,14 @@ const results = await vectorStore.query({
|
|
|
44
47
|
});
|
|
45
48
|
```
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { LibSQLStore } from '@mastra/libsql';
|
|
51
|
-
|
|
52
|
-
const store = new LibSQLStore({
|
|
53
|
-
id: 'libsql-storage',
|
|
54
|
-
url: 'file:./my-db.db',
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Create a thread
|
|
58
|
-
await store.saveThread({
|
|
59
|
-
thread: {
|
|
60
|
-
id: 'thread-123',
|
|
61
|
-
resourceId: 'resource-456',
|
|
62
|
-
title: 'My Thread',
|
|
63
|
-
metadata: { key: 'value' },
|
|
64
|
-
createdAt: new Date(),
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Add messages to thread
|
|
69
|
-
await store.saveMessages({
|
|
70
|
-
messages: [
|
|
71
|
-
{
|
|
72
|
-
id: 'msg-789',
|
|
73
|
-
threadId: 'thread-123',
|
|
74
|
-
role: 'user',
|
|
75
|
-
content: { content: 'Hello' },
|
|
76
|
-
resourceId: 'resource-456',
|
|
77
|
-
createdAt: new Date(),
|
|
78
|
-
},
|
|
79
|
-
],
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Query threads and messages
|
|
83
|
-
const savedThread = await store.getThreadById({ threadId: 'thread-123' });
|
|
84
|
-
const messages = await store.listMessages({ threadId: 'thread-123' });
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Configuration
|
|
88
|
-
|
|
89
|
-
The LibSQLStore store can be initialized with:
|
|
90
|
-
|
|
91
|
-
- Configuration object with url and auth. Auth is only necessary when using a provider like [Turso](https://turso.tech/)
|
|
92
|
-
|
|
93
|
-
## Features
|
|
94
|
-
|
|
95
|
-
### Vector Store Features
|
|
96
|
-
|
|
97
|
-
- Vector similarity search with cosine, euclidean, and dot product metrics
|
|
98
|
-
- Advanced metadata filtering with MongoDB-like query syntax
|
|
99
|
-
- Minimum score threshold for queries
|
|
100
|
-
- Automatic UUID generation for vectors
|
|
101
|
-
- Table management (create, list, describe, delete, truncate)
|
|
102
|
-
|
|
103
|
-
### Storage Features
|
|
104
|
-
|
|
105
|
-
- Thread and message storage with JSON support
|
|
106
|
-
- Atomic transactions for data consistency
|
|
107
|
-
- Efficient batch operations
|
|
108
|
-
- Rich metadata support
|
|
109
|
-
- Timestamp tracking
|
|
110
|
-
- Cascading deletes
|
|
111
|
-
|
|
112
|
-
## Supported Filter Operators
|
|
113
|
-
|
|
114
|
-
The following filter operators are supported for metadata queries:
|
|
115
|
-
|
|
116
|
-
- Comparison: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
|
|
117
|
-
- Logical: `$and`, `$or`
|
|
118
|
-
- Array: `$in`, `$nin`
|
|
119
|
-
- Text: `$regex`, `$like`
|
|
120
|
-
|
|
121
|
-
Example filter:
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
{
|
|
125
|
-
$and: [{ age: { $gt: 25 } }, { tags: { $in: ['tag1', 'tag2'] } }];
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Vector Store Methods
|
|
50
|
+
## Documentation
|
|
130
51
|
|
|
131
|
-
-
|
|
132
|
-
- `upsert({indexName, vectors, metadata?, ids?})`: Add or update vectors
|
|
133
|
-
- `query({indexName, queryVector, topK?, filter?, includeVector?, minScore?})`: Search for similar vectors
|
|
134
|
-
- `updateVector({ indexName, id?, filter?, update })`: Update a single vector by ID or metadata filter
|
|
135
|
-
- `deleteVector({ indexName, id })`: Delete a single vector by ID
|
|
136
|
-
- `deleteVectors({ indexName, ids?, filter? })`: Delete multiple vectors by IDs or metadata filter
|
|
137
|
-
- `defineIndex({indexName, metric?, indexConfig?})`: Define an index
|
|
138
|
-
- `listIndexes()`: List all vector-enabled tables
|
|
139
|
-
- `describeIndex(indexName)`: Get table statistics
|
|
140
|
-
- `deleteIndex(indexName)`: Delete a table
|
|
141
|
-
- `truncateIndex(indexName)`: Remove all data from a table
|
|
52
|
+
- [@mastra/libsql documentation](https://mastra.ai/reference/vectors/libsql)
|
|
142
53
|
|
|
143
|
-
##
|
|
54
|
+
## Changelog
|
|
144
55
|
|
|
145
|
-
|
|
146
|
-
- `getThreadById({ threadId })`: Get a thread by ID
|
|
147
|
-
- `deleteThread({ threadId })`: Delete a thread and its messages
|
|
148
|
-
- `saveMessages({ messages })`: Save multiple messages in a transaction
|
|
149
|
-
- `listMessages({ threadId, perPage?, page? })`: Get messages for a thread with pagination
|
|
150
|
-
- `deleteMessages(messageIds)`: Delete specific messages
|
|
56
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/stores/libsql/CHANGELOG.md) for version history and release notes.
|
|
151
57
|
|
|
152
|
-
##
|
|
58
|
+
## Support
|
|
153
59
|
|
|
154
|
-
|
|
60
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -39,6 +39,12 @@ Polls storage for due cron schedules and publishes `workflow.start` events. It's
|
|
|
39
39
|
|
|
40
40
|
The scheduler reads declarative `schedule` fields from your workflow definitions automatically. See [Scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows) for how to declare schedules.
|
|
41
41
|
|
|
42
|
+
The scheduler only polls storage once a schedule exists. At boot, a process with no declared schedules runs a single `listSchedules()` check. If that check finds no rows, the poll loop never starts, so idle deployments issue no recurring scheduler queries and can scale to zero.
|
|
43
|
+
|
|
44
|
+
When a schedule is created at runtime, Mastra publishes a wake event on the PubSub backend. Any process running the default worker set starts its scheduler in response, which is how a standalone worker discovers schedules created by the API process. This requires both processes to share the same PubSub backend.
|
|
45
|
+
|
|
46
|
+
To poll from startup regardless of whether schedules exist (for example, when your processes don't share a PubSub backend), set `scheduler: { enabled: true }` on the worker or run it with `MASTRA_WORKERS=scheduler`.
|
|
47
|
+
|
|
42
48
|
**Don't run more than one scheduler instance.** Multiple schedulers polling the same storage would fire duplicate events for the same schedule.
|
|
43
49
|
|
|
44
50
|
### Background task worker
|
|
@@ -316,7 +316,7 @@ See the [Editor versioning reference](https://mastra.ai/reference/editor/version
|
|
|
316
316
|
|
|
317
317
|
## Programmatic access
|
|
318
318
|
|
|
319
|
-
Everything available in Studio is also available programmatically through [`mastra.getEditor()`](https://mastra.ai/reference/core/getEditor), the REST API, or the Client SDK. Use it to script bulk updates or seed stored configurations from code. It can also power automation that tunes agents based on [evaluation results](https://mastra.ai/docs/
|
|
319
|
+
Everything available in Studio is also available programmatically through [`mastra.getEditor()`](https://mastra.ai/reference/core/getEditor), the REST API, or the Client SDK. Use it to script bulk updates or seed stored configurations from code. It can also power automation that tunes agents based on [evaluation results](https://mastra.ai/docs/evals/experiments).
|
|
320
320
|
|
|
321
321
|
Call `mastra.getEditor()` when application code has access to the Mastra instance:
|
|
322
322
|
|
|
@@ -125,7 +125,7 @@ Visit the [Configuration reference](https://mastra.ai/reference/configuration) f
|
|
|
125
125
|
|
|
126
126
|
**backgroundTasks.defaultRetries** (`RetryConfig`): Default retry configuration.
|
|
127
127
|
|
|
128
|
-
**scheduler** (`object`): Configure the scheduler worker for cron-driven workflow triggers. Auto-enables when any workflow declares a schedule. See Scheduled workflows.
|
|
128
|
+
**scheduler** (`object`): Configure the scheduler worker for cron-driven workflow triggers. Auto-enables when any workflow declares a schedule, when schedule rows already exist in storage, or when a schedule is created at runtime. Apps that never schedule anything run one listSchedules() check at boot and never poll after that. See Scheduled workflows.
|
|
129
129
|
|
|
130
130
|
**scheduler.enabled** (`boolean`): Explicitly enable or disable the scheduler.
|
|
131
131
|
|
package/dist/index.cjs
CHANGED
|
@@ -239,13 +239,13 @@ const FILTER_OPERATORS = {
|
|
|
239
239
|
sql: `NOT (${key})`,
|
|
240
240
|
needsValue: false
|
|
241
241
|
}),
|
|
242
|
-
$size: (key,
|
|
242
|
+
$size: (key, value) => {
|
|
243
243
|
const jsonPath = getJsonPath(key);
|
|
244
244
|
return {
|
|
245
245
|
sql: `(
|
|
246
246
|
CASE
|
|
247
|
-
WHEN json_type(json_extract(metadata, ${jsonPath})) = 'array' THEN
|
|
248
|
-
json_array_length(json_extract(metadata, ${jsonPath})) =
|
|
247
|
+
WHEN json_type(json_extract(metadata, ${jsonPath})) = 'array' THEN
|
|
248
|
+
json_array_length(json_extract(metadata, ${jsonPath})) = ?
|
|
249
249
|
ELSE FALSE
|
|
250
250
|
END
|
|
251
251
|
)`,
|