@mastra/core 0.5.0 → 0.6.0-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/dist/agent/index.cjs +2 -2
- package/dist/agent/index.d.cts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/{base-C_Oq53qk.d.ts → base-DA1J3qra.d.ts} +18 -8
- package/dist/{base-CIPKleAU.d.cts → base-zjGki2_Z.d.cts} +18 -8
- package/dist/{chunk-YPD6BQIM.js → chunk-22HQQDJZ.js} +36 -53
- package/dist/chunk-3LURIF6I.cjs +90 -0
- package/dist/{chunk-OD7ZMKHY.js → chunk-6ZHR5KIP.js} +93 -42
- package/dist/{chunk-KFQ7Z3PO.cjs → chunk-B3KTSEC5.cjs} +2 -2
- package/dist/{chunk-XF2FMJYK.js → chunk-DGYFNGOC.js} +1 -1
- package/dist/chunk-GMAMAKLH.js +88 -0
- package/dist/{chunk-OTFLHXHZ.cjs → chunk-L5BNMAC3.cjs} +2 -2
- package/dist/{chunk-KP5UAFLN.js → chunk-LTLNGEL2.js} +3 -1
- package/dist/{chunk-MLFXOST6.js → chunk-MLKXBAQG.js} +2 -2
- package/dist/{chunk-UZNQG7QO.cjs → chunk-N2G5ZI42.cjs} +93 -42
- package/dist/{chunk-3ASEZT7U.cjs → chunk-WX2ECXAE.cjs} +3 -1
- package/dist/{chunk-GXQRMKSN.cjs → chunk-XLZRGA3F.cjs} +35 -52
- package/dist/eval/index.d.cts +1 -1
- package/dist/eval/index.d.ts +1 -1
- package/dist/index.cjs +27 -27
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/integration/index.d.cts +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.cts +1 -1
- package/dist/mastra/index.d.ts +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +2 -2
- package/dist/memory/index.d.cts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.d.cts +1 -1
- package/dist/relevance/index.d.ts +1 -1
- package/dist/relevance/index.js +1 -1
- package/dist/storage/index.d.cts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/libsql/index.cjs +440 -10
- package/dist/storage/libsql/index.d.cts +1 -1
- package/dist/storage/libsql/index.d.ts +1 -1
- package/dist/storage/libsql/index.js +441 -1
- package/dist/telemetry/index.d.cts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/index.d.cts +2 -2
- package/dist/tools/index.d.ts +2 -2
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/workflows/index.cjs +17 -17
- package/dist/workflows/index.d.cts +2 -2
- package/dist/workflows/index.d.ts +2 -2
- package/dist/workflows/index.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-QAZ2ONKM.js +0 -441
- package/dist/chunk-VA4P7QJT.cjs +0 -443
|
@@ -1,14 +1,444 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkFL3GQXQ2_cjs = require('../../chunk-FL3GQXQ2.cjs');
|
|
4
|
+
var chunkF5UYWPV4_cjs = require('../../chunk-F5UYWPV4.cjs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var client = require('@libsql/client');
|
|
4
7
|
|
|
8
|
+
function safelyParseJSON(jsonString) {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(jsonString);
|
|
11
|
+
} catch {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
var LibSQLStore = class extends chunkFL3GQXQ2_cjs.MastraStorage {
|
|
16
|
+
client;
|
|
17
|
+
constructor({ config }) {
|
|
18
|
+
super({ name: `LibSQLStore` });
|
|
19
|
+
if (config.url === ":memory:" || config.url.startsWith("file::memory:")) {
|
|
20
|
+
this.shouldCacheInit = false;
|
|
21
|
+
}
|
|
22
|
+
this.client = client.createClient({
|
|
23
|
+
url: this.rewriteDbUrl(config.url),
|
|
24
|
+
authToken: config.authToken
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// If we're in the .mastra/output directory, use the dir outside .mastra dir
|
|
28
|
+
// reason we need to do this is libsql relative file paths are based on cwd, not current file path
|
|
29
|
+
// since mastra dev sets cwd to .mastra/output this means running an agent directly vs running with mastra dev
|
|
30
|
+
// will put db files in different locations, leading to an inconsistent experience between the two.
|
|
31
|
+
// Ex: with `file:ex.db`
|
|
32
|
+
// 1. `mastra dev`: ${cwd}/.mastra/output/ex.db
|
|
33
|
+
// 2. `tsx src/index.ts`: ${cwd}/ex.db
|
|
34
|
+
// so if we're in .mastra/output we need to rewrite the file url to be relative to the project root dir
|
|
35
|
+
// or the experience will be inconsistent
|
|
36
|
+
// this means `file:` urls are always relative to project root
|
|
37
|
+
// TODO: can we make this easier via bundling? https://github.com/mastra-ai/mastra/pull/2783#pullrequestreview-2662444241
|
|
38
|
+
rewriteDbUrl(url) {
|
|
39
|
+
if (url.startsWith("file:") && url !== "file::memory:") {
|
|
40
|
+
const pathPart = url.slice("file:".length);
|
|
41
|
+
if (path.isAbsolute(pathPart)) {
|
|
42
|
+
return url;
|
|
43
|
+
}
|
|
44
|
+
const cwd = process.cwd();
|
|
45
|
+
if (cwd.includes(".mastra") && (cwd.endsWith(`output`) || cwd.endsWith(`output/`) || cwd.endsWith(`output\\`))) {
|
|
46
|
+
const baseDir = path.join(cwd, `..`, `..`);
|
|
47
|
+
const fullPath = path.resolve(baseDir, pathPart);
|
|
48
|
+
this.logger.debug(
|
|
49
|
+
`Initializing LibSQL db with url ${url} with relative file path from inside .mastra/output directory. Rewriting relative file url to "file:${fullPath}". This ensures it's outside the .mastra/output directory.`
|
|
50
|
+
);
|
|
51
|
+
return `file:${fullPath}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return url;
|
|
55
|
+
}
|
|
56
|
+
getCreateTableSQL(tableName, schema) {
|
|
57
|
+
const columns = Object.entries(schema).map(([name, col]) => {
|
|
58
|
+
let type = col.type.toUpperCase();
|
|
59
|
+
if (type === "TEXT") type = "TEXT";
|
|
60
|
+
if (type === "TIMESTAMP") type = "TEXT";
|
|
61
|
+
const nullable = col.nullable ? "" : "NOT NULL";
|
|
62
|
+
const primaryKey = col.primaryKey ? "PRIMARY KEY" : "";
|
|
63
|
+
return `${name} ${type} ${nullable} ${primaryKey}`.trim();
|
|
64
|
+
});
|
|
65
|
+
if (tableName === chunkF5UYWPV4_cjs.TABLE_WORKFLOW_SNAPSHOT) {
|
|
66
|
+
const stmnt = `CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
67
|
+
${columns.join(",\n")},
|
|
68
|
+
PRIMARY KEY (workflow_name, run_id)
|
|
69
|
+
)`;
|
|
70
|
+
return stmnt;
|
|
71
|
+
}
|
|
72
|
+
return `CREATE TABLE IF NOT EXISTS ${tableName} (${columns.join(", ")})`;
|
|
73
|
+
}
|
|
74
|
+
async createTable({
|
|
75
|
+
tableName,
|
|
76
|
+
schema
|
|
77
|
+
}) {
|
|
78
|
+
try {
|
|
79
|
+
this.logger.debug(`Creating database table`, { tableName, operation: "schema init" });
|
|
80
|
+
const sql = this.getCreateTableSQL(tableName, schema);
|
|
81
|
+
await this.client.execute(sql);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
this.logger.error(`Error creating table ${tableName}: ${error}`);
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async clearTable({ tableName }) {
|
|
88
|
+
try {
|
|
89
|
+
await this.client.execute(`DELETE FROM ${tableName}`);
|
|
90
|
+
} catch (e) {
|
|
91
|
+
if (e instanceof Error) {
|
|
92
|
+
this.logger.error(e.message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
prepareStatement({ tableName, record }) {
|
|
97
|
+
const columns = Object.keys(record);
|
|
98
|
+
const values = Object.values(record).map((v) => {
|
|
99
|
+
if (typeof v === `undefined`) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (v instanceof Date) {
|
|
103
|
+
return v.toISOString();
|
|
104
|
+
}
|
|
105
|
+
return typeof v === "object" ? JSON.stringify(v) : v;
|
|
106
|
+
});
|
|
107
|
+
const placeholders = values.map(() => "?").join(", ");
|
|
108
|
+
return {
|
|
109
|
+
sql: `INSERT OR REPLACE INTO ${tableName} (${columns.join(", ")}) VALUES (${placeholders})`,
|
|
110
|
+
args: values
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async insert({ tableName, record }) {
|
|
114
|
+
try {
|
|
115
|
+
await this.client.execute(
|
|
116
|
+
this.prepareStatement({
|
|
117
|
+
tableName,
|
|
118
|
+
record
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
this.logger.error(`Error upserting into table ${tableName}: ${error}`);
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async batchInsert({ tableName, records }) {
|
|
127
|
+
if (records.length === 0) return;
|
|
128
|
+
try {
|
|
129
|
+
const batchStatements = records.map((r) => this.prepareStatement({ tableName, record: r }));
|
|
130
|
+
await this.client.batch(batchStatements, "write");
|
|
131
|
+
} catch (error) {
|
|
132
|
+
this.logger.error(`Error upserting into table ${tableName}: ${error}`);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async load({ tableName, keys }) {
|
|
137
|
+
const conditions = Object.entries(keys).map(([key]) => `${key} = ?`).join(" AND ");
|
|
138
|
+
const values = Object.values(keys);
|
|
139
|
+
const result = await this.client.execute({
|
|
140
|
+
sql: `SELECT * FROM ${tableName} WHERE ${conditions} ORDER BY createdAt DESC LIMIT 1`,
|
|
141
|
+
args: values
|
|
142
|
+
});
|
|
143
|
+
if (!result.rows || result.rows.length === 0) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const row = result.rows[0];
|
|
147
|
+
const parsed = Object.fromEntries(
|
|
148
|
+
Object.entries(row || {}).map(([k, v]) => {
|
|
149
|
+
try {
|
|
150
|
+
return [k, typeof v === "string" ? v.startsWith("{") || v.startsWith("[") ? JSON.parse(v) : v : v];
|
|
151
|
+
} catch {
|
|
152
|
+
return [k, v];
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
return parsed;
|
|
157
|
+
}
|
|
158
|
+
async getThreadById({ threadId }) {
|
|
159
|
+
const result = await this.load({
|
|
160
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_THREADS,
|
|
161
|
+
keys: { id: threadId }
|
|
162
|
+
});
|
|
163
|
+
if (!result) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...result,
|
|
168
|
+
metadata: typeof result.metadata === "string" ? JSON.parse(result.metadata) : result.metadata
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async getThreadsByResourceId({ resourceId }) {
|
|
172
|
+
const result = await this.client.execute({
|
|
173
|
+
sql: `SELECT * FROM ${chunkF5UYWPV4_cjs.TABLE_THREADS} WHERE resourceId = ?`,
|
|
174
|
+
args: [resourceId]
|
|
175
|
+
});
|
|
176
|
+
if (!result.rows) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
return result.rows.map((thread) => ({
|
|
180
|
+
id: thread.id,
|
|
181
|
+
resourceId: thread.resourceId,
|
|
182
|
+
title: thread.title,
|
|
183
|
+
createdAt: thread.createdAt,
|
|
184
|
+
updatedAt: thread.updatedAt,
|
|
185
|
+
metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
async saveThread({ thread }) {
|
|
189
|
+
await this.insert({
|
|
190
|
+
tableName: chunkF5UYWPV4_cjs.TABLE_THREADS,
|
|
191
|
+
record: {
|
|
192
|
+
...thread,
|
|
193
|
+
metadata: JSON.stringify(thread.metadata)
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return thread;
|
|
197
|
+
}
|
|
198
|
+
async updateThread({
|
|
199
|
+
id,
|
|
200
|
+
title,
|
|
201
|
+
metadata
|
|
202
|
+
}) {
|
|
203
|
+
const thread = await this.getThreadById({ threadId: id });
|
|
204
|
+
if (!thread) {
|
|
205
|
+
throw new Error(`Thread ${id} not found`);
|
|
206
|
+
}
|
|
207
|
+
const updatedThread = {
|
|
208
|
+
...thread,
|
|
209
|
+
title,
|
|
210
|
+
metadata: {
|
|
211
|
+
...thread.metadata,
|
|
212
|
+
...metadata
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
await this.client.execute({
|
|
216
|
+
sql: `UPDATE ${chunkF5UYWPV4_cjs.TABLE_THREADS} SET title = ?, metadata = ? WHERE id = ?`,
|
|
217
|
+
args: [title, JSON.stringify(updatedThread.metadata), id]
|
|
218
|
+
});
|
|
219
|
+
return updatedThread;
|
|
220
|
+
}
|
|
221
|
+
async deleteThread({ threadId }) {
|
|
222
|
+
await this.client.execute({
|
|
223
|
+
sql: `DELETE FROM ${chunkF5UYWPV4_cjs.TABLE_THREADS} WHERE id = ?`,
|
|
224
|
+
args: [threadId]
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
parseRow(row) {
|
|
228
|
+
let content = row.content;
|
|
229
|
+
try {
|
|
230
|
+
content = JSON.parse(row.content);
|
|
231
|
+
} catch {
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
id: row.id,
|
|
235
|
+
content,
|
|
236
|
+
role: row.role,
|
|
237
|
+
type: row.type,
|
|
238
|
+
createdAt: new Date(row.createdAt),
|
|
239
|
+
threadId: row.thread_id
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
async getMessages({ threadId, selectBy }) {
|
|
243
|
+
try {
|
|
244
|
+
const messages = [];
|
|
245
|
+
const limit = typeof selectBy?.last === `number` ? selectBy.last : 40;
|
|
246
|
+
if (selectBy?.include?.length) {
|
|
247
|
+
const includeIds = selectBy.include.map((i) => i.id);
|
|
248
|
+
const maxPrev = Math.max(...selectBy.include.map((i) => i.withPreviousMessages || 0));
|
|
249
|
+
const maxNext = Math.max(...selectBy.include.map((i) => i.withNextMessages || 0));
|
|
250
|
+
const includeResult = await this.client.execute({
|
|
251
|
+
sql: `
|
|
252
|
+
WITH numbered_messages AS (
|
|
253
|
+
SELECT
|
|
254
|
+
id,
|
|
255
|
+
content,
|
|
256
|
+
role,
|
|
257
|
+
type,
|
|
258
|
+
"createdAt",
|
|
259
|
+
thread_id,
|
|
260
|
+
ROW_NUMBER() OVER (ORDER BY "createdAt" ASC) as row_num
|
|
261
|
+
FROM "${chunkF5UYWPV4_cjs.TABLE_MESSAGES}"
|
|
262
|
+
WHERE thread_id = ?
|
|
263
|
+
),
|
|
264
|
+
target_positions AS (
|
|
265
|
+
SELECT row_num as target_pos
|
|
266
|
+
FROM numbered_messages
|
|
267
|
+
WHERE id IN (${includeIds.map(() => "?").join(", ")})
|
|
268
|
+
)
|
|
269
|
+
SELECT DISTINCT m.*
|
|
270
|
+
FROM numbered_messages m
|
|
271
|
+
CROSS JOIN target_positions t
|
|
272
|
+
WHERE m.row_num BETWEEN (t.target_pos - ?) AND (t.target_pos + ?)
|
|
273
|
+
ORDER BY m."createdAt" ASC
|
|
274
|
+
`,
|
|
275
|
+
args: [threadId, ...includeIds, maxPrev, maxNext]
|
|
276
|
+
});
|
|
277
|
+
if (includeResult.rows) {
|
|
278
|
+
messages.push(...includeResult.rows.map((row) => this.parseRow(row)));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const excludeIds = messages.map((m) => m.id);
|
|
282
|
+
const remainingSql = `
|
|
283
|
+
SELECT
|
|
284
|
+
id,
|
|
285
|
+
content,
|
|
286
|
+
role,
|
|
287
|
+
type,
|
|
288
|
+
"createdAt",
|
|
289
|
+
thread_id
|
|
290
|
+
FROM "${chunkF5UYWPV4_cjs.TABLE_MESSAGES}"
|
|
291
|
+
WHERE thread_id = ?
|
|
292
|
+
${excludeIds.length ? `AND id NOT IN (${excludeIds.map(() => "?").join(", ")})` : ""}
|
|
293
|
+
ORDER BY "createdAt" DESC
|
|
294
|
+
LIMIT ?
|
|
295
|
+
`;
|
|
296
|
+
const remainingArgs = [threadId, ...excludeIds.length ? excludeIds : [], limit];
|
|
297
|
+
const remainingResult = await this.client.execute({
|
|
298
|
+
sql: remainingSql,
|
|
299
|
+
args: remainingArgs
|
|
300
|
+
});
|
|
301
|
+
if (remainingResult.rows) {
|
|
302
|
+
messages.push(...remainingResult.rows.map((row) => this.parseRow(row)));
|
|
303
|
+
}
|
|
304
|
+
messages.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
305
|
+
return messages;
|
|
306
|
+
} catch (error) {
|
|
307
|
+
this.logger.error("Error getting messages:", error);
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async saveMessages({ messages }) {
|
|
312
|
+
if (messages.length === 0) return messages;
|
|
313
|
+
const tx = await this.client.transaction("write");
|
|
314
|
+
try {
|
|
315
|
+
const threadId = messages[0]?.threadId;
|
|
316
|
+
if (!threadId) {
|
|
317
|
+
throw new Error("Thread ID is required");
|
|
318
|
+
}
|
|
319
|
+
for (const message of messages) {
|
|
320
|
+
const time = message.createdAt || /* @__PURE__ */ new Date();
|
|
321
|
+
await tx.execute({
|
|
322
|
+
sql: `INSERT INTO ${chunkF5UYWPV4_cjs.TABLE_MESSAGES} (id, thread_id, content, role, type, createdAt)
|
|
323
|
+
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
324
|
+
args: [
|
|
325
|
+
message.id,
|
|
326
|
+
threadId,
|
|
327
|
+
typeof message.content === "object" ? JSON.stringify(message.content) : message.content,
|
|
328
|
+
message.role,
|
|
329
|
+
message.type,
|
|
330
|
+
time instanceof Date ? time.toISOString() : time
|
|
331
|
+
]
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
await tx.commit();
|
|
335
|
+
return messages;
|
|
336
|
+
} catch (error) {
|
|
337
|
+
this.logger.error("Failed to save messages in database: " + error?.message);
|
|
338
|
+
await tx.rollback();
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
transformEvalRow(row) {
|
|
343
|
+
const resultValue = JSON.parse(row.result);
|
|
344
|
+
const testInfoValue = row.test_info ? JSON.parse(row.test_info) : void 0;
|
|
345
|
+
if (!resultValue || typeof resultValue !== "object" || !("score" in resultValue)) {
|
|
346
|
+
throw new Error(`Invalid MetricResult format: ${JSON.stringify(resultValue)}`);
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
input: row.input,
|
|
350
|
+
output: row.output,
|
|
351
|
+
result: resultValue,
|
|
352
|
+
agentName: row.agent_name,
|
|
353
|
+
metricName: row.metric_name,
|
|
354
|
+
instructions: row.instructions,
|
|
355
|
+
testInfo: testInfoValue,
|
|
356
|
+
globalRunId: row.global_run_id,
|
|
357
|
+
runId: row.run_id,
|
|
358
|
+
createdAt: row.created_at
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
async getEvalsByAgentName(agentName, type) {
|
|
362
|
+
try {
|
|
363
|
+
const baseQuery = `SELECT * FROM ${chunkF5UYWPV4_cjs.TABLE_EVALS} WHERE agent_name = ?`;
|
|
364
|
+
const typeCondition = type === "test" ? " AND test_info IS NOT NULL AND test_info->>'testPath' IS NOT NULL" : type === "live" ? " AND (test_info IS NULL OR test_info->>'testPath' IS NULL)" : "";
|
|
365
|
+
const result = await this.client.execute({
|
|
366
|
+
sql: `${baseQuery}${typeCondition} ORDER BY created_at DESC`,
|
|
367
|
+
args: [agentName]
|
|
368
|
+
});
|
|
369
|
+
return result.rows?.map((row) => this.transformEvalRow(row)) ?? [];
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (error instanceof Error && error.message.includes("no such table")) {
|
|
372
|
+
return [];
|
|
373
|
+
}
|
|
374
|
+
this.logger.error("Failed to get evals for the specified agent: " + error?.message);
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
// TODO: add types
|
|
379
|
+
async getTraces({
|
|
380
|
+
name,
|
|
381
|
+
scope,
|
|
382
|
+
page,
|
|
383
|
+
perPage,
|
|
384
|
+
attributes
|
|
385
|
+
} = {
|
|
386
|
+
page: 0,
|
|
387
|
+
perPage: 100
|
|
388
|
+
}) {
|
|
389
|
+
const limit = perPage;
|
|
390
|
+
const offset = page * perPage;
|
|
391
|
+
const args = [];
|
|
392
|
+
const conditions = [];
|
|
393
|
+
if (name) {
|
|
394
|
+
conditions.push("name LIKE CONCAT(?, '%')");
|
|
395
|
+
}
|
|
396
|
+
if (scope) {
|
|
397
|
+
conditions.push("scope = ?");
|
|
398
|
+
}
|
|
399
|
+
if (attributes) {
|
|
400
|
+
Object.keys(attributes).forEach((key) => {
|
|
401
|
+
conditions.push(`attributes->>'$.${key}' = ?`);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
405
|
+
if (name) {
|
|
406
|
+
args.push(name);
|
|
407
|
+
}
|
|
408
|
+
if (scope) {
|
|
409
|
+
args.push(scope);
|
|
410
|
+
}
|
|
411
|
+
if (attributes) {
|
|
412
|
+
for (const [_key, value] of Object.entries(attributes)) {
|
|
413
|
+
args.push(value);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
args.push(limit, offset);
|
|
417
|
+
const result = await this.client.execute({
|
|
418
|
+
sql: `SELECT * FROM ${chunkF5UYWPV4_cjs.TABLE_TRACES} ${whereClause} ORDER BY "startTime" DESC LIMIT ? OFFSET ?`,
|
|
419
|
+
args
|
|
420
|
+
});
|
|
421
|
+
if (!result.rows) {
|
|
422
|
+
return [];
|
|
423
|
+
}
|
|
424
|
+
return result.rows.map((row) => ({
|
|
425
|
+
id: row.id,
|
|
426
|
+
parentSpanId: row.parentSpanId,
|
|
427
|
+
traceId: row.traceId,
|
|
428
|
+
name: row.name,
|
|
429
|
+
scope: row.scope,
|
|
430
|
+
kind: row.kind,
|
|
431
|
+
status: safelyParseJSON(row.status),
|
|
432
|
+
events: safelyParseJSON(row.events),
|
|
433
|
+
links: safelyParseJSON(row.links),
|
|
434
|
+
attributes: safelyParseJSON(row.attributes),
|
|
435
|
+
startTime: row.startTime,
|
|
436
|
+
endTime: row.endTime,
|
|
437
|
+
other: safelyParseJSON(row.other),
|
|
438
|
+
createdAt: row.createdAt
|
|
439
|
+
}));
|
|
440
|
+
}
|
|
441
|
+
};
|
|
5
442
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () { return chunkVA4P7QJT_cjs.LibSQLStore; }
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(exports, "LibSQLStore", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () { return chunkVA4P7QJT_cjs.LibSQLStore; }
|
|
14
|
-
});
|
|
443
|
+
exports.DefaultStorage = LibSQLStore;
|
|
444
|
+
exports.LibSQLStore = LibSQLStore;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as MastraStorage, g as TABLE_NAMES, h as StorageColumn, i as StorageThreadType, j as MessageType, k as StorageGetMessagesArg, E as EvalRow } from '../../base-
|
|
1
|
+
import { f as MastraStorage, g as TABLE_NAMES, h as StorageColumn, i as StorageThreadType, j as MessageType, k as StorageGetMessagesArg, E as EvalRow } from '../../base-zjGki2_Z.cjs';
|
|
2
2
|
import 'ai';
|
|
3
3
|
import '../../base-DboIg_Cd.cjs';
|
|
4
4
|
import '@opentelemetry/api';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as MastraStorage, g as TABLE_NAMES, h as StorageColumn, i as StorageThreadType, j as MessageType, k as StorageGetMessagesArg, E as EvalRow } from '../../base-
|
|
1
|
+
import { f as MastraStorage, g as TABLE_NAMES, h as StorageColumn, i as StorageThreadType, j as MessageType, k as StorageGetMessagesArg, E as EvalRow } from '../../base-DA1J3qra.js';
|
|
2
2
|
import 'ai';
|
|
3
3
|
import '../../base-BZViaFTt.js';
|
|
4
4
|
import '@opentelemetry/api';
|