@mastra/libsql 0.10.1-alpha.1 → 0.10.1-alpha.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +15 -0
- package/dist/_tsup-dts-rollup.d.cts +13 -2
- package/dist/_tsup-dts-rollup.d.ts +13 -2
- package/dist/index.cjs +21 -4
- package/dist/index.js +21 -4
- package/package.json +2 -2
- package/src/storage/index.ts +29 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/libsql@0.10.1-alpha.
|
|
2
|
+
> @mastra/libsql@0.10.1-alpha.3 build /home/runner/work/mastra/mastra/stores/libsql
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 7652ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/libsql/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/libsql/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 9163ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
21
|
-
[32mCJS[39m ⚡️ Build success in
|
|
22
|
-
[32mESM[39m [1mdist/index.js [22m[32m48.
|
|
23
|
-
[32mESM[39m ⚡️ Build success in
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m49.10 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1091ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m48.89 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 1091ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 0.10.1-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a3f1b39: feat(libsql): update thread timestamp when saving messages
|
|
8
|
+
|
|
9
|
+
## 0.10.1-alpha.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- c5bf1ce: Add backwards compat code for new MessageList in storage
|
|
14
|
+
- Updated dependencies [c5bf1ce]
|
|
15
|
+
- Updated dependencies [12b7002]
|
|
16
|
+
- @mastra/core@0.10.2-alpha.4
|
|
17
|
+
|
|
3
18
|
## 0.10.1-alpha.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -6,6 +6,7 @@ import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
|
6
6
|
import type { EvalRow } from '@mastra/core/storage';
|
|
7
7
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
8
|
import type { InValue } from '@libsql/client';
|
|
9
|
+
import type { MastraMessageV1 } from '@mastra/core/memory';
|
|
9
10
|
import type { MastraMessageV2 } from '@mastra/core/agent';
|
|
10
11
|
import { MastraStorage } from '@mastra/core/storage';
|
|
11
12
|
import { MastraVector } from '@mastra/core/vector';
|
|
@@ -122,9 +123,19 @@ declare class LibSQLStore extends MastraStorage {
|
|
|
122
123
|
threadId: string;
|
|
123
124
|
}): Promise<void>;
|
|
124
125
|
private parseRow;
|
|
125
|
-
getMessages
|
|
126
|
-
|
|
126
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
127
|
+
format?: 'v1';
|
|
128
|
+
}): Promise<MastraMessageV1[]>;
|
|
129
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
130
|
+
format: 'v2';
|
|
131
|
+
}): Promise<MastraMessageV2[]>;
|
|
132
|
+
saveMessages(args: {
|
|
133
|
+
messages: MastraMessageV1[];
|
|
134
|
+
format?: undefined | 'v1';
|
|
135
|
+
}): Promise<MastraMessageV1[]>;
|
|
136
|
+
saveMessages(args: {
|
|
127
137
|
messages: MastraMessageV2[];
|
|
138
|
+
format: 'v2';
|
|
128
139
|
}): Promise<MastraMessageV2[]>;
|
|
129
140
|
private transformEvalRow;
|
|
130
141
|
getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
|
@@ -6,6 +6,7 @@ import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
|
6
6
|
import type { EvalRow } from '@mastra/core/storage';
|
|
7
7
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
8
|
import type { InValue } from '@libsql/client';
|
|
9
|
+
import type { MastraMessageV1 } from '@mastra/core/memory';
|
|
9
10
|
import type { MastraMessageV2 } from '@mastra/core/agent';
|
|
10
11
|
import { MastraStorage } from '@mastra/core/storage';
|
|
11
12
|
import { MastraVector } from '@mastra/core/vector';
|
|
@@ -122,9 +123,19 @@ declare class LibSQLStore extends MastraStorage {
|
|
|
122
123
|
threadId: string;
|
|
123
124
|
}): Promise<void>;
|
|
124
125
|
private parseRow;
|
|
125
|
-
getMessages
|
|
126
|
-
|
|
126
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
127
|
+
format?: 'v1';
|
|
128
|
+
}): Promise<MastraMessageV1[]>;
|
|
129
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
130
|
+
format: 'v2';
|
|
131
|
+
}): Promise<MastraMessageV2[]>;
|
|
132
|
+
saveMessages(args: {
|
|
133
|
+
messages: MastraMessageV1[];
|
|
134
|
+
format?: undefined | 'v1';
|
|
135
|
+
}): Promise<MastraMessageV1[]>;
|
|
136
|
+
saveMessages(args: {
|
|
127
137
|
messages: MastraMessageV2[];
|
|
138
|
+
format: 'v2';
|
|
128
139
|
}): Promise<MastraMessageV2[]>;
|
|
129
140
|
private transformEvalRow;
|
|
130
141
|
getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var client = require('@libsql/client');
|
|
|
4
4
|
var utils = require('@mastra/core/utils');
|
|
5
5
|
var vector = require('@mastra/core/vector');
|
|
6
6
|
var filter = require('@mastra/core/vector/filter');
|
|
7
|
+
var agent = require('@mastra/core/agent');
|
|
7
8
|
var storage = require('@mastra/core/storage');
|
|
8
9
|
|
|
9
10
|
// src/vector/index.ts
|
|
@@ -1035,7 +1036,11 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1035
1036
|
if (row.type && row.type !== `v2`) result.type = row.type;
|
|
1036
1037
|
return result;
|
|
1037
1038
|
}
|
|
1038
|
-
async getMessages({
|
|
1039
|
+
async getMessages({
|
|
1040
|
+
threadId,
|
|
1041
|
+
selectBy,
|
|
1042
|
+
format
|
|
1043
|
+
}) {
|
|
1039
1044
|
try {
|
|
1040
1045
|
const messages = [];
|
|
1041
1046
|
const limit = typeof selectBy?.last === `number` ? selectBy.last : 40;
|
|
@@ -1098,13 +1103,18 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1098
1103
|
messages.push(...remainingResult.rows.map((row) => this.parseRow(row)));
|
|
1099
1104
|
}
|
|
1100
1105
|
messages.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
1101
|
-
|
|
1106
|
+
const list = new agent.MessageList().add(messages, "memory");
|
|
1107
|
+
if (format === `v2`) return list.get.all.v2();
|
|
1108
|
+
return list.get.all.v1();
|
|
1102
1109
|
} catch (error) {
|
|
1103
1110
|
this.logger.error("Error getting messages:", error);
|
|
1104
1111
|
throw error;
|
|
1105
1112
|
}
|
|
1106
1113
|
}
|
|
1107
|
-
async saveMessages({
|
|
1114
|
+
async saveMessages({
|
|
1115
|
+
messages,
|
|
1116
|
+
format
|
|
1117
|
+
}) {
|
|
1108
1118
|
if (messages.length === 0) return messages;
|
|
1109
1119
|
try {
|
|
1110
1120
|
const threadId = messages[0]?.threadId;
|
|
@@ -1126,8 +1136,15 @@ var LibSQLStore = class extends storage.MastraStorage {
|
|
|
1126
1136
|
]
|
|
1127
1137
|
};
|
|
1128
1138
|
});
|
|
1139
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1140
|
+
batchStatements.push({
|
|
1141
|
+
sql: `UPDATE ${storage.TABLE_THREADS} SET updatedAt = ? WHERE id = ?`,
|
|
1142
|
+
args: [now, threadId]
|
|
1143
|
+
});
|
|
1129
1144
|
await this.client.batch(batchStatements, "write");
|
|
1130
|
-
|
|
1145
|
+
const list = new agent.MessageList().add(messages, "memory");
|
|
1146
|
+
if (format === `v2`) return list.get.all.v2();
|
|
1147
|
+
return list.get.all.v1();
|
|
1131
1148
|
} catch (error) {
|
|
1132
1149
|
this.logger.error("Failed to save messages in database: " + error?.message);
|
|
1133
1150
|
throw error;
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createClient } from '@libsql/client';
|
|
|
2
2
|
import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
|
|
3
3
|
import { MastraVector } from '@mastra/core/vector';
|
|
4
4
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
5
|
+
import { MessageList } from '@mastra/core/agent';
|
|
5
6
|
import { MastraStorage, TABLE_WORKFLOW_SNAPSHOT, TABLE_THREADS, TABLE_MESSAGES, TABLE_EVALS, TABLE_TRACES } from '@mastra/core/storage';
|
|
6
7
|
|
|
7
8
|
// src/vector/index.ts
|
|
@@ -1033,7 +1034,11 @@ var LibSQLStore = class extends MastraStorage {
|
|
|
1033
1034
|
if (row.type && row.type !== `v2`) result.type = row.type;
|
|
1034
1035
|
return result;
|
|
1035
1036
|
}
|
|
1036
|
-
async getMessages({
|
|
1037
|
+
async getMessages({
|
|
1038
|
+
threadId,
|
|
1039
|
+
selectBy,
|
|
1040
|
+
format
|
|
1041
|
+
}) {
|
|
1037
1042
|
try {
|
|
1038
1043
|
const messages = [];
|
|
1039
1044
|
const limit = typeof selectBy?.last === `number` ? selectBy.last : 40;
|
|
@@ -1096,13 +1101,18 @@ var LibSQLStore = class extends MastraStorage {
|
|
|
1096
1101
|
messages.push(...remainingResult.rows.map((row) => this.parseRow(row)));
|
|
1097
1102
|
}
|
|
1098
1103
|
messages.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
1099
|
-
|
|
1104
|
+
const list = new MessageList().add(messages, "memory");
|
|
1105
|
+
if (format === `v2`) return list.get.all.v2();
|
|
1106
|
+
return list.get.all.v1();
|
|
1100
1107
|
} catch (error) {
|
|
1101
1108
|
this.logger.error("Error getting messages:", error);
|
|
1102
1109
|
throw error;
|
|
1103
1110
|
}
|
|
1104
1111
|
}
|
|
1105
|
-
async saveMessages({
|
|
1112
|
+
async saveMessages({
|
|
1113
|
+
messages,
|
|
1114
|
+
format
|
|
1115
|
+
}) {
|
|
1106
1116
|
if (messages.length === 0) return messages;
|
|
1107
1117
|
try {
|
|
1108
1118
|
const threadId = messages[0]?.threadId;
|
|
@@ -1124,8 +1134,15 @@ var LibSQLStore = class extends MastraStorage {
|
|
|
1124
1134
|
]
|
|
1125
1135
|
};
|
|
1126
1136
|
});
|
|
1137
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1138
|
+
batchStatements.push({
|
|
1139
|
+
sql: `UPDATE ${TABLE_THREADS} SET updatedAt = ? WHERE id = ?`,
|
|
1140
|
+
args: [now, threadId]
|
|
1141
|
+
});
|
|
1127
1142
|
await this.client.batch(batchStatements, "write");
|
|
1128
|
-
|
|
1143
|
+
const list = new MessageList().add(messages, "memory");
|
|
1144
|
+
if (format === `v2`) return list.get.all.v2();
|
|
1145
|
+
return list.get.all.v1();
|
|
1129
1146
|
} catch (error) {
|
|
1130
1147
|
this.logger.error("Failed to save messages in database: " + error?.message);
|
|
1131
1148
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/libsql",
|
|
3
|
-
"version": "0.10.1-alpha.
|
|
3
|
+
"version": "0.10.1-alpha.3",
|
|
4
4
|
"description": "Libsql provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"vitest": "^3.1.2",
|
|
32
32
|
"@internal/lint": "0.0.7",
|
|
33
33
|
"@internal/storage-test-utils": "0.0.3",
|
|
34
|
-
"@mastra/core": "0.10.2-alpha.
|
|
34
|
+
"@mastra/core": "0.10.2-alpha.6"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@mastra/core": "^0.10.0-alpha.0"
|
package/src/storage/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createClient } from '@libsql/client';
|
|
2
2
|
import type { Client, InValue } from '@libsql/client';
|
|
3
|
+
import { MessageList } from '@mastra/core/agent';
|
|
3
4
|
import type { MastraMessageV2 } from '@mastra/core/agent';
|
|
4
5
|
import type { MetricResult, TestInfo } from '@mastra/core/eval';
|
|
5
|
-
import type { StorageThreadType } from '@mastra/core/memory';
|
|
6
|
+
import type { MastraMessageV1, StorageThreadType } from '@mastra/core/memory';
|
|
6
7
|
import {
|
|
7
8
|
MastraStorage,
|
|
8
9
|
TABLE_MESSAGES,
|
|
@@ -362,7 +363,13 @@ export class LibSQLStore extends MastraStorage {
|
|
|
362
363
|
return result;
|
|
363
364
|
}
|
|
364
365
|
|
|
365
|
-
async getMessages
|
|
366
|
+
public async getMessages(args: StorageGetMessagesArg & { format?: 'v1' }): Promise<MastraMessageV1[]>;
|
|
367
|
+
public async getMessages(args: StorageGetMessagesArg & { format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
368
|
+
public async getMessages({
|
|
369
|
+
threadId,
|
|
370
|
+
selectBy,
|
|
371
|
+
format,
|
|
372
|
+
}: StorageGetMessagesArg & { format?: 'v1' | 'v2' }): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
366
373
|
try {
|
|
367
374
|
const messages: MastraMessageV2[] = [];
|
|
368
375
|
const limit = typeof selectBy?.last === `number` ? selectBy.last : 40;
|
|
@@ -437,14 +444,23 @@ export class LibSQLStore extends MastraStorage {
|
|
|
437
444
|
// Sort all messages by creation date
|
|
438
445
|
messages.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
439
446
|
|
|
440
|
-
|
|
447
|
+
const list = new MessageList().add(messages, 'memory');
|
|
448
|
+
if (format === `v2`) return list.get.all.v2();
|
|
449
|
+
return list.get.all.v1();
|
|
441
450
|
} catch (error) {
|
|
442
451
|
this.logger.error('Error getting messages:', error as Error);
|
|
443
452
|
throw error;
|
|
444
453
|
}
|
|
445
454
|
}
|
|
446
455
|
|
|
447
|
-
async saveMessages(
|
|
456
|
+
async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
|
|
457
|
+
async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
458
|
+
async saveMessages({
|
|
459
|
+
messages,
|
|
460
|
+
format,
|
|
461
|
+
}:
|
|
462
|
+
| { messages: MastraMessageV1[]; format?: undefined | 'v1' }
|
|
463
|
+
| { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[] | MastraMessageV1[]> {
|
|
448
464
|
if (messages.length === 0) return messages;
|
|
449
465
|
|
|
450
466
|
try {
|
|
@@ -470,10 +486,18 @@ export class LibSQLStore extends MastraStorage {
|
|
|
470
486
|
};
|
|
471
487
|
});
|
|
472
488
|
|
|
489
|
+
const now = new Date().toISOString();
|
|
490
|
+
batchStatements.push({
|
|
491
|
+
sql: `UPDATE ${TABLE_THREADS} SET updatedAt = ? WHERE id = ?`,
|
|
492
|
+
args: [now, threadId],
|
|
493
|
+
});
|
|
494
|
+
|
|
473
495
|
// Execute all inserts in a single batch
|
|
474
496
|
await this.client.batch(batchStatements, 'write');
|
|
475
497
|
|
|
476
|
-
|
|
498
|
+
const list = new MessageList().add(messages, 'memory');
|
|
499
|
+
if (format === `v2`) return list.get.all.v2();
|
|
500
|
+
return list.get.all.v1();
|
|
477
501
|
} catch (error) {
|
|
478
502
|
this.logger.error('Failed to save messages in database: ' + (error as { message: string })?.message);
|
|
479
503
|
throw error;
|