@mastra/mssql 0.0.0-remove-unused-model-providers-api-20251030210744 → 0.0.0-safe-stringify-telemetry-20251205024938
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/CHANGELOG.md +102 -13
- package/README.md +1 -1
- package/dist/index.cjs +434 -200
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +434 -200
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/legacy-evals/index.d.ts +20 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +7 -4
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +37 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +4 -5
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +31 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +13 -6
package/dist/index.cjs
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
var error = require('@mastra/core/error');
|
|
4
4
|
var storage = require('@mastra/core/storage');
|
|
5
|
-
var
|
|
6
|
-
var agent = require('@mastra/core/agent');
|
|
5
|
+
var sql3 = require('mssql');
|
|
7
6
|
var utils = require('@mastra/core/utils');
|
|
7
|
+
var agent = require('@mastra/core/agent');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
9
|
var scores = require('@mastra/core/scores');
|
|
10
10
|
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var sql3__default = /*#__PURE__*/_interopDefault(sql3);
|
|
14
14
|
|
|
15
15
|
// src/storage/index.ts
|
|
16
16
|
function getSchemaName(schema) {
|
|
@@ -86,7 +86,153 @@ function transformFromSqlRow({
|
|
|
86
86
|
return result;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
// src/storage/domains/
|
|
89
|
+
// src/storage/domains/legacy-evals/index.ts
|
|
90
|
+
function transformEvalRow(row) {
|
|
91
|
+
let testInfoValue = null, resultValue = null;
|
|
92
|
+
if (row.test_info) {
|
|
93
|
+
try {
|
|
94
|
+
testInfoValue = typeof row.test_info === "string" ? JSON.parse(row.test_info) : row.test_info;
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (row.result) {
|
|
99
|
+
try {
|
|
100
|
+
resultValue = typeof row.result === "string" ? JSON.parse(row.result) : row.result;
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
agentName: row.agent_name,
|
|
106
|
+
input: row.input,
|
|
107
|
+
output: row.output,
|
|
108
|
+
result: resultValue,
|
|
109
|
+
metricName: row.metric_name,
|
|
110
|
+
instructions: row.instructions,
|
|
111
|
+
testInfo: testInfoValue,
|
|
112
|
+
globalRunId: row.global_run_id,
|
|
113
|
+
runId: row.run_id,
|
|
114
|
+
createdAt: row.created_at
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
var LegacyEvalsMSSQL = class extends storage.LegacyEvalsStorage {
|
|
118
|
+
pool;
|
|
119
|
+
schema;
|
|
120
|
+
constructor({ pool, schema }) {
|
|
121
|
+
super();
|
|
122
|
+
this.pool = pool;
|
|
123
|
+
this.schema = schema;
|
|
124
|
+
}
|
|
125
|
+
/** @deprecated use getEvals instead */
|
|
126
|
+
async getEvalsByAgentName(agentName, type) {
|
|
127
|
+
try {
|
|
128
|
+
let query = `SELECT * FROM ${getTableName({ indexName: storage.TABLE_EVALS, schemaName: getSchemaName(this.schema) })} WHERE agent_name = @p1`;
|
|
129
|
+
if (type === "test") {
|
|
130
|
+
query += " AND test_info IS NOT NULL AND JSON_VALUE(test_info, '$.testPath') IS NOT NULL";
|
|
131
|
+
} else if (type === "live") {
|
|
132
|
+
query += " AND (test_info IS NULL OR JSON_VALUE(test_info, '$.testPath') IS NULL)";
|
|
133
|
+
}
|
|
134
|
+
query += " ORDER BY created_at DESC";
|
|
135
|
+
const request = this.pool.request();
|
|
136
|
+
request.input("p1", agentName);
|
|
137
|
+
const result = await request.query(query);
|
|
138
|
+
const rows = result.recordset;
|
|
139
|
+
return typeof transformEvalRow === "function" ? rows?.map((row) => transformEvalRow(row)) ?? [] : rows ?? [];
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (error && error.number === 208 && error.message && error.message.includes("Invalid object name")) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
this.logger?.error?.("Failed to get evals for the specified agent:", error);
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async getEvals(options = {}) {
|
|
149
|
+
const { agentName, type, page = 0, perPage = 100, dateRange } = options;
|
|
150
|
+
const fromDate = dateRange?.start;
|
|
151
|
+
const toDate = dateRange?.end;
|
|
152
|
+
const where = [];
|
|
153
|
+
const params = {};
|
|
154
|
+
if (agentName) {
|
|
155
|
+
where.push("agent_name = @agentName");
|
|
156
|
+
params["agentName"] = agentName;
|
|
157
|
+
}
|
|
158
|
+
if (type === "test") {
|
|
159
|
+
where.push("test_info IS NOT NULL AND JSON_VALUE(test_info, '$.testPath') IS NOT NULL");
|
|
160
|
+
} else if (type === "live") {
|
|
161
|
+
where.push("(test_info IS NULL OR JSON_VALUE(test_info, '$.testPath') IS NULL)");
|
|
162
|
+
}
|
|
163
|
+
if (fromDate instanceof Date && !isNaN(fromDate.getTime())) {
|
|
164
|
+
where.push(`[created_at] >= @fromDate`);
|
|
165
|
+
params[`fromDate`] = fromDate.toISOString();
|
|
166
|
+
}
|
|
167
|
+
if (toDate instanceof Date && !isNaN(toDate.getTime())) {
|
|
168
|
+
where.push(`[created_at] <= @toDate`);
|
|
169
|
+
params[`toDate`] = toDate.toISOString();
|
|
170
|
+
}
|
|
171
|
+
const whereClause = where.length > 0 ? `WHERE ${where.join(" AND ")}` : "";
|
|
172
|
+
const tableName = getTableName({ indexName: storage.TABLE_EVALS, schemaName: getSchemaName(this.schema) });
|
|
173
|
+
const offset = page * perPage;
|
|
174
|
+
const countQuery = `SELECT COUNT(*) as total FROM ${tableName} ${whereClause}`;
|
|
175
|
+
const dataQuery = `SELECT * FROM ${tableName} ${whereClause} ORDER BY seq_id DESC OFFSET @offset ROWS FETCH NEXT @perPage ROWS ONLY`;
|
|
176
|
+
try {
|
|
177
|
+
const countReq = this.pool.request();
|
|
178
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
179
|
+
if (value instanceof Date) {
|
|
180
|
+
countReq.input(key, sql3__default.default.DateTime, value);
|
|
181
|
+
} else {
|
|
182
|
+
countReq.input(key, value);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const countResult = await countReq.query(countQuery);
|
|
186
|
+
const total = countResult.recordset[0]?.total || 0;
|
|
187
|
+
if (total === 0) {
|
|
188
|
+
return {
|
|
189
|
+
evals: [],
|
|
190
|
+
total: 0,
|
|
191
|
+
page,
|
|
192
|
+
perPage,
|
|
193
|
+
hasMore: false
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const req = this.pool.request();
|
|
197
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
198
|
+
if (value instanceof Date) {
|
|
199
|
+
req.input(key, sql3__default.default.DateTime, value);
|
|
200
|
+
} else {
|
|
201
|
+
req.input(key, value);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
req.input("offset", offset);
|
|
205
|
+
req.input("perPage", perPage);
|
|
206
|
+
const result = await req.query(dataQuery);
|
|
207
|
+
const rows = result.recordset;
|
|
208
|
+
return {
|
|
209
|
+
evals: rows?.map((row) => transformEvalRow(row)) ?? [],
|
|
210
|
+
total,
|
|
211
|
+
page,
|
|
212
|
+
perPage,
|
|
213
|
+
hasMore: offset + (rows?.length ?? 0) < total
|
|
214
|
+
};
|
|
215
|
+
} catch (error$1) {
|
|
216
|
+
const mastraError = new error.MastraError(
|
|
217
|
+
{
|
|
218
|
+
id: "MASTRA_STORAGE_MSSQL_STORE_GET_EVALS_FAILED",
|
|
219
|
+
domain: error.ErrorDomain.STORAGE,
|
|
220
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
221
|
+
details: {
|
|
222
|
+
agentName: agentName || "all",
|
|
223
|
+
type: type || "all",
|
|
224
|
+
page,
|
|
225
|
+
perPage
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
error$1
|
|
229
|
+
);
|
|
230
|
+
this.logger?.error?.(mastraError.toString());
|
|
231
|
+
this.logger?.trackException?.(mastraError);
|
|
232
|
+
throw mastraError;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
90
236
|
var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
91
237
|
pool;
|
|
92
238
|
schema;
|
|
@@ -118,7 +264,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
118
264
|
}
|
|
119
265
|
async getThreadById({ threadId }) {
|
|
120
266
|
try {
|
|
121
|
-
const
|
|
267
|
+
const sql7 = `SELECT
|
|
122
268
|
id,
|
|
123
269
|
[resourceId],
|
|
124
270
|
title,
|
|
@@ -129,7 +275,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
129
275
|
WHERE id = @threadId`;
|
|
130
276
|
const request = this.pool.request();
|
|
131
277
|
request.input("threadId", threadId);
|
|
132
|
-
const resultSet = await request.query(
|
|
278
|
+
const resultSet = await request.query(sql7);
|
|
133
279
|
const thread = resultSet.recordset[0] || null;
|
|
134
280
|
if (!thread) {
|
|
135
281
|
return null;
|
|
@@ -235,12 +381,12 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
235
381
|
req.input("title", thread.title);
|
|
236
382
|
const metadata = thread.metadata ? JSON.stringify(thread.metadata) : null;
|
|
237
383
|
if (metadata === null) {
|
|
238
|
-
req.input("metadata",
|
|
384
|
+
req.input("metadata", sql3__default.default.NVarChar, null);
|
|
239
385
|
} else {
|
|
240
386
|
req.input("metadata", metadata);
|
|
241
387
|
}
|
|
242
|
-
req.input("createdAt",
|
|
243
|
-
req.input("updatedAt",
|
|
388
|
+
req.input("createdAt", sql3__default.default.DateTime2, thread.createdAt);
|
|
389
|
+
req.input("updatedAt", sql3__default.default.DateTime2, thread.updatedAt);
|
|
244
390
|
await req.query(mergeSql);
|
|
245
391
|
return thread;
|
|
246
392
|
} catch (error$1) {
|
|
@@ -309,7 +455,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
309
455
|
};
|
|
310
456
|
try {
|
|
311
457
|
const table = getTableName({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName(this.schema) });
|
|
312
|
-
const
|
|
458
|
+
const sql7 = `UPDATE ${table}
|
|
313
459
|
SET title = @title,
|
|
314
460
|
metadata = @metadata,
|
|
315
461
|
[updatedAt] = @updatedAt
|
|
@@ -320,7 +466,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
320
466
|
req.input("title", title);
|
|
321
467
|
req.input("metadata", JSON.stringify(mergedMetadata));
|
|
322
468
|
req.input("updatedAt", /* @__PURE__ */ new Date());
|
|
323
|
-
const result = await req.query(
|
|
469
|
+
const result = await req.query(sql7);
|
|
324
470
|
let thread = result.recordset && result.recordset[0];
|
|
325
471
|
if (thread && "seq_id" in thread) {
|
|
326
472
|
const { seq_id, ...rest } = thread;
|
|
@@ -390,7 +536,8 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
390
536
|
}
|
|
391
537
|
async _getIncludedMessages({
|
|
392
538
|
threadId,
|
|
393
|
-
selectBy
|
|
539
|
+
selectBy,
|
|
540
|
+
orderByStatement
|
|
394
541
|
}) {
|
|
395
542
|
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
396
543
|
const include = selectBy?.include;
|
|
@@ -418,7 +565,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
418
565
|
m.[resourceId],
|
|
419
566
|
m.seq_id
|
|
420
567
|
FROM (
|
|
421
|
-
SELECT *, ROW_NUMBER() OVER (
|
|
568
|
+
SELECT *, ROW_NUMBER() OVER (${orderByStatement}) as row_num
|
|
422
569
|
FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })}
|
|
423
570
|
WHERE [thread_id] = ${pThreadId}
|
|
424
571
|
) AS m
|
|
@@ -426,17 +573,15 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
426
573
|
OR EXISTS (
|
|
427
574
|
SELECT 1
|
|
428
575
|
FROM (
|
|
429
|
-
SELECT *, ROW_NUMBER() OVER (
|
|
576
|
+
SELECT *, ROW_NUMBER() OVER (${orderByStatement}) as row_num
|
|
430
577
|
FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })}
|
|
431
578
|
WHERE [thread_id] = ${pThreadId}
|
|
432
579
|
) AS target
|
|
433
580
|
WHERE target.id = ${pId}
|
|
434
581
|
AND (
|
|
435
|
-
|
|
436
|
-
(m.row_num < target.row_num AND m.row_num >= target.row_num - ${pPrev})
|
|
582
|
+
(m.row_num <= target.row_num + ${pPrev} AND m.row_num > target.row_num)
|
|
437
583
|
OR
|
|
438
|
-
|
|
439
|
-
(m.row_num > target.row_num AND m.row_num <= target.row_num + ${pNext})
|
|
584
|
+
(m.row_num >= target.row_num - ${pNext} AND m.row_num < target.row_num)
|
|
440
585
|
)
|
|
441
586
|
)
|
|
442
587
|
`
|
|
@@ -475,7 +620,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
475
620
|
let rows = [];
|
|
476
621
|
const include = selectBy?.include || [];
|
|
477
622
|
if (include?.length) {
|
|
478
|
-
const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
|
|
623
|
+
const includeMessages = await this._getIncludedMessages({ threadId, selectBy, orderByStatement });
|
|
479
624
|
if (includeMessages) {
|
|
480
625
|
rows.push(...includeMessages);
|
|
481
626
|
}
|
|
@@ -520,7 +665,10 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
520
665
|
return [];
|
|
521
666
|
}
|
|
522
667
|
}
|
|
523
|
-
async
|
|
668
|
+
async getMessagesById({
|
|
669
|
+
messageIds,
|
|
670
|
+
format
|
|
671
|
+
}) {
|
|
524
672
|
if (messageIds.length === 0) return [];
|
|
525
673
|
const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
|
|
526
674
|
const orderByStatement = `ORDER BY [seq_id] DESC`;
|
|
@@ -538,8 +686,8 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
538
686
|
return timeDiff;
|
|
539
687
|
});
|
|
540
688
|
rows = rows.map(({ seq_id, ...rest }) => rest);
|
|
541
|
-
|
|
542
|
-
return
|
|
689
|
+
if (format === `v1`) return this._parseAndFormatMessages(rows, format);
|
|
690
|
+
return this._parseAndFormatMessages(rows, `v2`);
|
|
543
691
|
} catch (error$1) {
|
|
544
692
|
const mastraError = new error.MastraError(
|
|
545
693
|
{
|
|
@@ -557,135 +705,6 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
557
705
|
return [];
|
|
558
706
|
}
|
|
559
707
|
}
|
|
560
|
-
async listMessages(args) {
|
|
561
|
-
const { threadId, resourceId, include, filter, limit, offset = 0, orderBy } = args;
|
|
562
|
-
if (!threadId.trim()) {
|
|
563
|
-
throw new error.MastraError(
|
|
564
|
-
{
|
|
565
|
-
id: "STORAGE_MSSQL_LIST_MESSAGES_INVALID_THREAD_ID",
|
|
566
|
-
domain: error.ErrorDomain.STORAGE,
|
|
567
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
568
|
-
details: { threadId }
|
|
569
|
-
},
|
|
570
|
-
new Error("threadId must be a non-empty string")
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
try {
|
|
574
|
-
let perPage = 40;
|
|
575
|
-
if (limit !== void 0) {
|
|
576
|
-
if (limit === false) {
|
|
577
|
-
perPage = Number.MAX_SAFE_INTEGER;
|
|
578
|
-
} else if (limit === 0) {
|
|
579
|
-
perPage = 0;
|
|
580
|
-
} else if (typeof limit === "number" && limit > 0) {
|
|
581
|
-
perPage = limit;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
const page = perPage === 0 ? 0 : Math.floor(offset / perPage);
|
|
585
|
-
const sortField = orderBy?.field || "createdAt";
|
|
586
|
-
const sortDirection = orderBy?.direction || "DESC";
|
|
587
|
-
const orderByStatement = `ORDER BY [${sortField}] ${sortDirection}`;
|
|
588
|
-
const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
|
|
589
|
-
const tableName = getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
|
|
590
|
-
const conditions = ["[thread_id] = @threadId"];
|
|
591
|
-
const request = this.pool.request();
|
|
592
|
-
request.input("threadId", threadId);
|
|
593
|
-
if (resourceId) {
|
|
594
|
-
conditions.push("[resourceId] = @resourceId");
|
|
595
|
-
request.input("resourceId", resourceId);
|
|
596
|
-
}
|
|
597
|
-
if (filter?.dateRange?.start) {
|
|
598
|
-
conditions.push("[createdAt] >= @fromDate");
|
|
599
|
-
request.input("fromDate", filter.dateRange.start);
|
|
600
|
-
}
|
|
601
|
-
if (filter?.dateRange?.end) {
|
|
602
|
-
conditions.push("[createdAt] <= @toDate");
|
|
603
|
-
request.input("toDate", filter.dateRange.end);
|
|
604
|
-
}
|
|
605
|
-
const whereClause = `WHERE ${conditions.join(" AND ")}`;
|
|
606
|
-
const countQuery = `SELECT COUNT(*) as total FROM ${tableName} ${whereClause}`;
|
|
607
|
-
const countResult = await request.query(countQuery);
|
|
608
|
-
const total = parseInt(countResult.recordset[0]?.total, 10) || 0;
|
|
609
|
-
const dataQuery = `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
|
|
610
|
-
request.input("offset", offset);
|
|
611
|
-
if (perPage > 2147483647) {
|
|
612
|
-
request.input("limit", sql2__default.default.BigInt, perPage);
|
|
613
|
-
} else {
|
|
614
|
-
request.input("limit", perPage);
|
|
615
|
-
}
|
|
616
|
-
const rowsResult = await request.query(dataQuery);
|
|
617
|
-
const rows = rowsResult.recordset || [];
|
|
618
|
-
const messages = [...rows];
|
|
619
|
-
if (total === 0 && messages.length === 0) {
|
|
620
|
-
return {
|
|
621
|
-
messages: [],
|
|
622
|
-
total: 0,
|
|
623
|
-
page,
|
|
624
|
-
perPage,
|
|
625
|
-
hasMore: false
|
|
626
|
-
};
|
|
627
|
-
}
|
|
628
|
-
const messageIds = new Set(messages.map((m) => m.id));
|
|
629
|
-
if (include && include.length > 0) {
|
|
630
|
-
const selectBy = { include };
|
|
631
|
-
const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
|
|
632
|
-
if (includeMessages) {
|
|
633
|
-
for (const includeMsg of includeMessages) {
|
|
634
|
-
if (!messageIds.has(includeMsg.id)) {
|
|
635
|
-
messages.push(includeMsg);
|
|
636
|
-
messageIds.add(includeMsg.id);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
const parsed = this._parseAndFormatMessages(messages, "v2");
|
|
642
|
-
let finalMessages = parsed;
|
|
643
|
-
finalMessages = finalMessages.sort((a, b) => {
|
|
644
|
-
const aValue = sortField === "createdAt" ? new Date(a.createdAt).getTime() : a[sortField];
|
|
645
|
-
const bValue = sortField === "createdAt" ? new Date(b.createdAt).getTime() : b[sortField];
|
|
646
|
-
return sortDirection === "ASC" ? aValue - bValue : bValue - aValue;
|
|
647
|
-
});
|
|
648
|
-
const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
|
|
649
|
-
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
650
|
-
const hasMore = limit === false ? false : allThreadMessagesReturned ? false : offset + rows.length < total;
|
|
651
|
-
return {
|
|
652
|
-
messages: finalMessages,
|
|
653
|
-
total,
|
|
654
|
-
page,
|
|
655
|
-
perPage,
|
|
656
|
-
hasMore
|
|
657
|
-
};
|
|
658
|
-
} catch (error$1) {
|
|
659
|
-
const errorPerPage = limit === false ? Number.MAX_SAFE_INTEGER : limit === 0 ? 0 : limit || 40;
|
|
660
|
-
const mastraError = new error.MastraError(
|
|
661
|
-
{
|
|
662
|
-
id: "MASTRA_STORAGE_MSSQL_STORE_LIST_MESSAGES_FAILED",
|
|
663
|
-
domain: error.ErrorDomain.STORAGE,
|
|
664
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
665
|
-
details: {
|
|
666
|
-
threadId,
|
|
667
|
-
resourceId: resourceId ?? ""
|
|
668
|
-
}
|
|
669
|
-
},
|
|
670
|
-
error$1
|
|
671
|
-
);
|
|
672
|
-
this.logger?.error?.(mastraError.toString());
|
|
673
|
-
this.logger?.trackException?.(mastraError);
|
|
674
|
-
return {
|
|
675
|
-
messages: [],
|
|
676
|
-
total: 0,
|
|
677
|
-
page: errorPerPage === 0 ? 0 : Math.floor(offset / errorPerPage),
|
|
678
|
-
perPage: errorPerPage,
|
|
679
|
-
hasMore: false
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
async listThreadsByResourceId(args) {
|
|
684
|
-
const { resourceId, limit, offset, orderBy, sortDirection } = args;
|
|
685
|
-
const page = Math.floor(offset / limit);
|
|
686
|
-
const perPage = limit;
|
|
687
|
-
return this.getThreadsByResourceIdPaginated({ resourceId, page, perPage, orderBy, sortDirection });
|
|
688
|
-
}
|
|
689
708
|
async getMessagesPaginated(args) {
|
|
690
709
|
const { threadId, resourceId, format, selectBy } = args;
|
|
691
710
|
const { page = 0, perPage: perPageInput, dateRange } = selectBy?.pagination || {};
|
|
@@ -697,7 +716,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
697
716
|
const orderByStatement = `ORDER BY [seq_id] DESC`;
|
|
698
717
|
let messages = [];
|
|
699
718
|
if (selectBy?.include?.length) {
|
|
700
|
-
const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
|
|
719
|
+
const includeMessages = await this._getIncludedMessages({ threadId, selectBy, orderByStatement });
|
|
701
720
|
if (includeMessages) messages.push(...includeMessages);
|
|
702
721
|
}
|
|
703
722
|
const perPage = perPageInput !== void 0 ? perPageInput : storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
|
|
@@ -741,7 +760,8 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
741
760
|
const rows = rowsResult.recordset || [];
|
|
742
761
|
rows.sort((a, b) => a.seq_id - b.seq_id);
|
|
743
762
|
messages.push(...rows);
|
|
744
|
-
|
|
763
|
+
let parsed = this._parseAndFormatMessages(messages, format);
|
|
764
|
+
parsed = parsed.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
745
765
|
return {
|
|
746
766
|
messages: parsed,
|
|
747
767
|
total,
|
|
@@ -816,7 +836,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
816
836
|
"content",
|
|
817
837
|
typeof message.content === "string" ? message.content : JSON.stringify(message.content)
|
|
818
838
|
);
|
|
819
|
-
request.input("createdAt",
|
|
839
|
+
request.input("createdAt", sql3__default.default.DateTime2, message.createdAt);
|
|
820
840
|
request.input("role", message.role);
|
|
821
841
|
request.input("type", message.type || "v2");
|
|
822
842
|
request.input("resourceId", message.resourceId);
|
|
@@ -835,7 +855,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
835
855
|
await request.query(mergeSql);
|
|
836
856
|
}
|
|
837
857
|
const threadReq = transaction.request();
|
|
838
|
-
threadReq.input("updatedAt",
|
|
858
|
+
threadReq.input("updatedAt", sql3__default.default.DateTime2, /* @__PURE__ */ new Date());
|
|
839
859
|
threadReq.input("id", threadId);
|
|
840
860
|
await threadReq.query(`UPDATE ${tableThreads} SET [updatedAt] = @updatedAt WHERE id = @id`);
|
|
841
861
|
await transaction.commit();
|
|
@@ -1537,7 +1557,7 @@ var StoreOperationsMSSQL = class extends storage.StoreOperations {
|
|
|
1537
1557
|
const value = record[col];
|
|
1538
1558
|
const preparedValue = this.prepareValue(value, col, tableName);
|
|
1539
1559
|
if (preparedValue instanceof Date) {
|
|
1540
|
-
request.input(`param${i}`,
|
|
1560
|
+
request.input(`param${i}`, sql3__default.default.DateTime2, preparedValue);
|
|
1541
1561
|
} else if (preparedValue === null || preparedValue === void 0) {
|
|
1542
1562
|
request.input(`param${i}`, this.getMssqlType(tableName, col), null);
|
|
1543
1563
|
} else {
|
|
@@ -1752,7 +1772,7 @@ ${columns}
|
|
|
1752
1772
|
try {
|
|
1753
1773
|
const keyEntries = Object.entries(keys).map(([key, value]) => [utils.parseSqlIdentifier(key, "column name"), value]);
|
|
1754
1774
|
const conditions = keyEntries.map(([key], i) => `[${key}] = @param${i}`).join(" AND ");
|
|
1755
|
-
const
|
|
1775
|
+
const sql7 = `SELECT * FROM ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} WHERE ${conditions}`;
|
|
1756
1776
|
const request = this.pool.request();
|
|
1757
1777
|
keyEntries.forEach(([key, value], i) => {
|
|
1758
1778
|
const preparedValue = this.prepareValue(value, key, tableName);
|
|
@@ -1762,7 +1782,7 @@ ${columns}
|
|
|
1762
1782
|
request.input(`param${i}`, preparedValue);
|
|
1763
1783
|
}
|
|
1764
1784
|
});
|
|
1765
|
-
const resultSet = await request.query(
|
|
1785
|
+
const resultSet = await request.query(sql7);
|
|
1766
1786
|
const result = resultSet.recordset[0] || null;
|
|
1767
1787
|
if (!result) {
|
|
1768
1788
|
return null;
|
|
@@ -1847,6 +1867,20 @@ ${columns}
|
|
|
1847
1867
|
return value ? 1 : 0;
|
|
1848
1868
|
}
|
|
1849
1869
|
if (columnSchema?.type === "jsonb") {
|
|
1870
|
+
if (typeof value === "string") {
|
|
1871
|
+
const trimmed = value.trim();
|
|
1872
|
+
if (trimmed.length > 0) {
|
|
1873
|
+
try {
|
|
1874
|
+
JSON.parse(trimmed);
|
|
1875
|
+
return trimmed;
|
|
1876
|
+
} catch {
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
return JSON.stringify(value);
|
|
1880
|
+
}
|
|
1881
|
+
if (typeof value === "bigint") {
|
|
1882
|
+
return value.toString();
|
|
1883
|
+
}
|
|
1850
1884
|
return JSON.stringify(value);
|
|
1851
1885
|
}
|
|
1852
1886
|
if (typeof value === "object") {
|
|
@@ -1861,23 +1895,23 @@ ${columns}
|
|
|
1861
1895
|
const col = storage.TABLE_SCHEMAS[tableName]?.[columnName];
|
|
1862
1896
|
switch (col?.type) {
|
|
1863
1897
|
case "text":
|
|
1864
|
-
return
|
|
1898
|
+
return sql3__default.default.NVarChar;
|
|
1865
1899
|
case "timestamp":
|
|
1866
|
-
return
|
|
1900
|
+
return sql3__default.default.DateTime2;
|
|
1867
1901
|
case "uuid":
|
|
1868
|
-
return
|
|
1902
|
+
return sql3__default.default.UniqueIdentifier;
|
|
1869
1903
|
case "jsonb":
|
|
1870
|
-
return
|
|
1904
|
+
return sql3__default.default.NVarChar;
|
|
1871
1905
|
case "integer":
|
|
1872
|
-
return
|
|
1906
|
+
return sql3__default.default.Int;
|
|
1873
1907
|
case "bigint":
|
|
1874
|
-
return
|
|
1908
|
+
return sql3__default.default.BigInt;
|
|
1875
1909
|
case "float":
|
|
1876
|
-
return
|
|
1910
|
+
return sql3__default.default.Float;
|
|
1877
1911
|
case "boolean":
|
|
1878
|
-
return
|
|
1912
|
+
return sql3__default.default.Bit;
|
|
1879
1913
|
default:
|
|
1880
|
-
return
|
|
1914
|
+
return sql3__default.default.NVarChar;
|
|
1881
1915
|
}
|
|
1882
1916
|
}
|
|
1883
1917
|
/**
|
|
@@ -2321,6 +2355,11 @@ ${columns}
|
|
|
2321
2355
|
table: storage.TABLE_TRACES,
|
|
2322
2356
|
columns: ["name", "seq_id DESC"]
|
|
2323
2357
|
},
|
|
2358
|
+
{
|
|
2359
|
+
name: `${schemaPrefix}mastra_evals_agent_name_seqid_idx`,
|
|
2360
|
+
table: storage.TABLE_EVALS,
|
|
2361
|
+
columns: ["agent_name", "seq_id DESC"]
|
|
2362
|
+
},
|
|
2324
2363
|
{
|
|
2325
2364
|
name: `${schemaPrefix}mastra_scores_trace_id_span_id_seqid_idx`,
|
|
2326
2365
|
table: storage.TABLE_SCORERS,
|
|
@@ -2385,10 +2424,10 @@ function transformScoreRow(row) {
|
|
|
2385
2424
|
metadata: storage.safelyParseJSON(row.metadata),
|
|
2386
2425
|
output: storage.safelyParseJSON(row.output),
|
|
2387
2426
|
additionalContext: storage.safelyParseJSON(row.additionalContext),
|
|
2388
|
-
|
|
2427
|
+
runtimeContext: storage.safelyParseJSON(row.runtimeContext),
|
|
2389
2428
|
entity: storage.safelyParseJSON(row.entity),
|
|
2390
|
-
createdAt: row.createdAt,
|
|
2391
|
-
updatedAt: row.updatedAt
|
|
2429
|
+
createdAt: new Date(row.createdAt),
|
|
2430
|
+
updatedAt: new Date(row.updatedAt)
|
|
2392
2431
|
};
|
|
2393
2432
|
}
|
|
2394
2433
|
var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
@@ -2452,7 +2491,7 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2452
2491
|
input,
|
|
2453
2492
|
output,
|
|
2454
2493
|
additionalContext,
|
|
2455
|
-
|
|
2494
|
+
runtimeContext,
|
|
2456
2495
|
entity,
|
|
2457
2496
|
...rest
|
|
2458
2497
|
} = validatedScore;
|
|
@@ -2467,7 +2506,7 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2467
2506
|
analyzeStepResult: analyzeStepResult || null,
|
|
2468
2507
|
metadata: metadata || null,
|
|
2469
2508
|
additionalContext: additionalContext || null,
|
|
2470
|
-
|
|
2509
|
+
runtimeContext: runtimeContext || null,
|
|
2471
2510
|
entity: entity || null,
|
|
2472
2511
|
scorer: scorer || null,
|
|
2473
2512
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -2719,6 +2758,173 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2719
2758
|
}
|
|
2720
2759
|
}
|
|
2721
2760
|
};
|
|
2761
|
+
var TracesMSSQL = class extends storage.TracesStorage {
|
|
2762
|
+
pool;
|
|
2763
|
+
operations;
|
|
2764
|
+
schema;
|
|
2765
|
+
constructor({
|
|
2766
|
+
pool,
|
|
2767
|
+
operations,
|
|
2768
|
+
schema
|
|
2769
|
+
}) {
|
|
2770
|
+
super();
|
|
2771
|
+
this.pool = pool;
|
|
2772
|
+
this.operations = operations;
|
|
2773
|
+
this.schema = schema;
|
|
2774
|
+
}
|
|
2775
|
+
/** @deprecated use getTracesPaginated instead*/
|
|
2776
|
+
async getTraces(args) {
|
|
2777
|
+
if (args.fromDate || args.toDate) {
|
|
2778
|
+
args.dateRange = {
|
|
2779
|
+
start: args.fromDate,
|
|
2780
|
+
end: args.toDate
|
|
2781
|
+
};
|
|
2782
|
+
}
|
|
2783
|
+
const result = await this.getTracesPaginated(args);
|
|
2784
|
+
return result.traces;
|
|
2785
|
+
}
|
|
2786
|
+
async getTracesPaginated(args) {
|
|
2787
|
+
const { name, scope, page = 0, perPage: perPageInput, attributes, filters, dateRange } = args;
|
|
2788
|
+
const fromDate = dateRange?.start;
|
|
2789
|
+
const toDate = dateRange?.end;
|
|
2790
|
+
const perPage = perPageInput !== void 0 ? perPageInput : 100;
|
|
2791
|
+
const currentOffset = page * perPage;
|
|
2792
|
+
const paramMap = {};
|
|
2793
|
+
const conditions = [];
|
|
2794
|
+
let paramIndex = 1;
|
|
2795
|
+
if (name) {
|
|
2796
|
+
const paramName = `p${paramIndex++}`;
|
|
2797
|
+
conditions.push(`[name] LIKE @${paramName}`);
|
|
2798
|
+
paramMap[paramName] = `${name}%`;
|
|
2799
|
+
}
|
|
2800
|
+
if (scope) {
|
|
2801
|
+
const paramName = `p${paramIndex++}`;
|
|
2802
|
+
conditions.push(`[scope] = @${paramName}`);
|
|
2803
|
+
paramMap[paramName] = scope;
|
|
2804
|
+
}
|
|
2805
|
+
if (attributes) {
|
|
2806
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
2807
|
+
const parsedKey = utils.parseFieldKey(key);
|
|
2808
|
+
const paramName = `p${paramIndex++}`;
|
|
2809
|
+
conditions.push(`JSON_VALUE([attributes], '$.${parsedKey}') = @${paramName}`);
|
|
2810
|
+
paramMap[paramName] = value;
|
|
2811
|
+
});
|
|
2812
|
+
}
|
|
2813
|
+
if (filters) {
|
|
2814
|
+
Object.entries(filters).forEach(([key, value]) => {
|
|
2815
|
+
const parsedKey = utils.parseFieldKey(key);
|
|
2816
|
+
const paramName = `p${paramIndex++}`;
|
|
2817
|
+
conditions.push(`[${parsedKey}] = @${paramName}`);
|
|
2818
|
+
paramMap[paramName] = value;
|
|
2819
|
+
});
|
|
2820
|
+
}
|
|
2821
|
+
if (fromDate instanceof Date && !isNaN(fromDate.getTime())) {
|
|
2822
|
+
const paramName = `p${paramIndex++}`;
|
|
2823
|
+
conditions.push(`[createdAt] >= @${paramName}`);
|
|
2824
|
+
paramMap[paramName] = fromDate.toISOString();
|
|
2825
|
+
}
|
|
2826
|
+
if (toDate instanceof Date && !isNaN(toDate.getTime())) {
|
|
2827
|
+
const paramName = `p${paramIndex++}`;
|
|
2828
|
+
conditions.push(`[createdAt] <= @${paramName}`);
|
|
2829
|
+
paramMap[paramName] = toDate.toISOString();
|
|
2830
|
+
}
|
|
2831
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
2832
|
+
const countQuery = `SELECT COUNT(*) as total FROM ${getTableName({ indexName: storage.TABLE_TRACES, schemaName: getSchemaName(this.schema) })} ${whereClause}`;
|
|
2833
|
+
let total = 0;
|
|
2834
|
+
try {
|
|
2835
|
+
const countRequest = this.pool.request();
|
|
2836
|
+
Object.entries(paramMap).forEach(([key, value]) => {
|
|
2837
|
+
if (value instanceof Date) {
|
|
2838
|
+
countRequest.input(key, sql3__default.default.DateTime, value);
|
|
2839
|
+
} else {
|
|
2840
|
+
countRequest.input(key, value);
|
|
2841
|
+
}
|
|
2842
|
+
});
|
|
2843
|
+
const countResult = await countRequest.query(countQuery);
|
|
2844
|
+
total = parseInt(countResult.recordset[0].total, 10);
|
|
2845
|
+
} catch (error$1) {
|
|
2846
|
+
throw new error.MastraError(
|
|
2847
|
+
{
|
|
2848
|
+
id: "MASTRA_STORAGE_MSSQL_STORE_GET_TRACES_PAGINATED_FAILED_TO_RETRIEVE_TOTAL_COUNT",
|
|
2849
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2850
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
2851
|
+
details: {
|
|
2852
|
+
name: args.name ?? "",
|
|
2853
|
+
scope: args.scope ?? ""
|
|
2854
|
+
}
|
|
2855
|
+
},
|
|
2856
|
+
error$1
|
|
2857
|
+
);
|
|
2858
|
+
}
|
|
2859
|
+
if (total === 0) {
|
|
2860
|
+
return {
|
|
2861
|
+
traces: [],
|
|
2862
|
+
total: 0,
|
|
2863
|
+
page,
|
|
2864
|
+
perPage,
|
|
2865
|
+
hasMore: false
|
|
2866
|
+
};
|
|
2867
|
+
}
|
|
2868
|
+
const dataQuery = `SELECT * FROM ${getTableName({ indexName: storage.TABLE_TRACES, schemaName: getSchemaName(this.schema) })} ${whereClause} ORDER BY [seq_id] DESC OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
|
|
2869
|
+
const dataRequest = this.pool.request();
|
|
2870
|
+
Object.entries(paramMap).forEach(([key, value]) => {
|
|
2871
|
+
if (value instanceof Date) {
|
|
2872
|
+
dataRequest.input(key, sql3__default.default.DateTime, value);
|
|
2873
|
+
} else {
|
|
2874
|
+
dataRequest.input(key, value);
|
|
2875
|
+
}
|
|
2876
|
+
});
|
|
2877
|
+
dataRequest.input("offset", currentOffset);
|
|
2878
|
+
dataRequest.input("limit", perPage);
|
|
2879
|
+
try {
|
|
2880
|
+
const rowsResult = await dataRequest.query(dataQuery);
|
|
2881
|
+
const rows = rowsResult.recordset;
|
|
2882
|
+
const traces = rows.map((row) => ({
|
|
2883
|
+
id: row.id,
|
|
2884
|
+
parentSpanId: row.parentSpanId,
|
|
2885
|
+
traceId: row.traceId,
|
|
2886
|
+
name: row.name,
|
|
2887
|
+
scope: row.scope,
|
|
2888
|
+
kind: row.kind,
|
|
2889
|
+
status: JSON.parse(row.status),
|
|
2890
|
+
events: JSON.parse(row.events),
|
|
2891
|
+
links: JSON.parse(row.links),
|
|
2892
|
+
attributes: JSON.parse(row.attributes),
|
|
2893
|
+
startTime: row.startTime,
|
|
2894
|
+
endTime: row.endTime,
|
|
2895
|
+
other: row.other,
|
|
2896
|
+
createdAt: row.createdAt
|
|
2897
|
+
}));
|
|
2898
|
+
return {
|
|
2899
|
+
traces,
|
|
2900
|
+
total,
|
|
2901
|
+
page,
|
|
2902
|
+
perPage,
|
|
2903
|
+
hasMore: currentOffset + traces.length < total
|
|
2904
|
+
};
|
|
2905
|
+
} catch (error$1) {
|
|
2906
|
+
throw new error.MastraError(
|
|
2907
|
+
{
|
|
2908
|
+
id: "MASTRA_STORAGE_MSSQL_STORE_GET_TRACES_PAGINATED_FAILED_TO_RETRIEVE_TRACES",
|
|
2909
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2910
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
2911
|
+
details: {
|
|
2912
|
+
name: args.name ?? "",
|
|
2913
|
+
scope: args.scope ?? ""
|
|
2914
|
+
}
|
|
2915
|
+
},
|
|
2916
|
+
error$1
|
|
2917
|
+
);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
async batchTraceInsert({ records }) {
|
|
2921
|
+
this.logger.debug("Batch inserting traces", { count: records.length });
|
|
2922
|
+
await this.operations.batchInsert({
|
|
2923
|
+
tableName: storage.TABLE_TRACES,
|
|
2924
|
+
records
|
|
2925
|
+
});
|
|
2926
|
+
}
|
|
2927
|
+
};
|
|
2722
2928
|
var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
2723
2929
|
pool;
|
|
2724
2930
|
operations;
|
|
@@ -2756,13 +2962,13 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
2756
2962
|
runId,
|
|
2757
2963
|
stepId,
|
|
2758
2964
|
result,
|
|
2759
|
-
|
|
2965
|
+
runtimeContext
|
|
2760
2966
|
}) {
|
|
2761
2967
|
const table = getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName(this.schema) });
|
|
2762
2968
|
const transaction = this.pool.transaction();
|
|
2763
2969
|
try {
|
|
2764
2970
|
await transaction.begin();
|
|
2765
|
-
const selectRequest = new
|
|
2971
|
+
const selectRequest = new sql3__default.default.Request(transaction);
|
|
2766
2972
|
selectRequest.input("workflow_name", workflowName);
|
|
2767
2973
|
selectRequest.input("run_id", runId);
|
|
2768
2974
|
const existingSnapshotResult = await selectRequest.query(
|
|
@@ -2773,28 +2979,29 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
2773
2979
|
snapshot = {
|
|
2774
2980
|
context: {},
|
|
2775
2981
|
activePaths: [],
|
|
2982
|
+
activeStepsPath: {},
|
|
2776
2983
|
timestamp: Date.now(),
|
|
2777
2984
|
suspendedPaths: {},
|
|
2778
2985
|
resumeLabels: {},
|
|
2779
2986
|
serializedStepGraph: [],
|
|
2987
|
+
status: "pending",
|
|
2780
2988
|
value: {},
|
|
2781
2989
|
waitingPaths: {},
|
|
2782
|
-
status: "pending",
|
|
2783
2990
|
runId,
|
|
2784
|
-
|
|
2991
|
+
runtimeContext: {}
|
|
2785
2992
|
};
|
|
2786
2993
|
} else {
|
|
2787
2994
|
const existingSnapshot = existingSnapshotResult.recordset[0].snapshot;
|
|
2788
2995
|
snapshot = typeof existingSnapshot === "string" ? JSON.parse(existingSnapshot) : existingSnapshot;
|
|
2789
2996
|
}
|
|
2790
2997
|
snapshot.context[stepId] = result;
|
|
2791
|
-
snapshot.
|
|
2792
|
-
const upsertReq = new
|
|
2998
|
+
snapshot.runtimeContext = { ...snapshot.runtimeContext, ...runtimeContext };
|
|
2999
|
+
const upsertReq = new sql3__default.default.Request(transaction);
|
|
2793
3000
|
upsertReq.input("workflow_name", workflowName);
|
|
2794
3001
|
upsertReq.input("run_id", runId);
|
|
2795
3002
|
upsertReq.input("snapshot", JSON.stringify(snapshot));
|
|
2796
|
-
upsertReq.input("createdAt",
|
|
2797
|
-
upsertReq.input("updatedAt",
|
|
3003
|
+
upsertReq.input("createdAt", sql3__default.default.DateTime2, /* @__PURE__ */ new Date());
|
|
3004
|
+
upsertReq.input("updatedAt", sql3__default.default.DateTime2, /* @__PURE__ */ new Date());
|
|
2798
3005
|
await upsertReq.query(
|
|
2799
3006
|
`MERGE ${table} AS target
|
|
2800
3007
|
USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
|
|
@@ -2834,7 +3041,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
2834
3041
|
const transaction = this.pool.transaction();
|
|
2835
3042
|
try {
|
|
2836
3043
|
await transaction.begin();
|
|
2837
|
-
const selectRequest = new
|
|
3044
|
+
const selectRequest = new sql3__default.default.Request(transaction);
|
|
2838
3045
|
selectRequest.input("workflow_name", workflowName);
|
|
2839
3046
|
selectRequest.input("run_id", runId);
|
|
2840
3047
|
const existingSnapshotResult = await selectRequest.query(
|
|
@@ -2862,11 +3069,11 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
2862
3069
|
);
|
|
2863
3070
|
}
|
|
2864
3071
|
const updatedSnapshot = { ...snapshot, ...opts };
|
|
2865
|
-
const updateRequest = new
|
|
3072
|
+
const updateRequest = new sql3__default.default.Request(transaction);
|
|
2866
3073
|
updateRequest.input("snapshot", JSON.stringify(updatedSnapshot));
|
|
2867
3074
|
updateRequest.input("workflow_name", workflowName);
|
|
2868
3075
|
updateRequest.input("run_id", runId);
|
|
2869
|
-
updateRequest.input("updatedAt",
|
|
3076
|
+
updateRequest.input("updatedAt", sql3__default.default.DateTime2, /* @__PURE__ */ new Date());
|
|
2870
3077
|
await updateRequest.query(
|
|
2871
3078
|
`UPDATE ${table} SET snapshot = @snapshot, [updatedAt] = @updatedAt WHERE workflow_name = @workflow_name AND run_id = @run_id`
|
|
2872
3079
|
);
|
|
@@ -2905,8 +3112,8 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
2905
3112
|
request.input("run_id", runId);
|
|
2906
3113
|
request.input("resourceId", resourceId);
|
|
2907
3114
|
request.input("snapshot", JSON.stringify(snapshot));
|
|
2908
|
-
request.input("createdAt",
|
|
2909
|
-
request.input("updatedAt",
|
|
3115
|
+
request.input("createdAt", sql3__default.default.DateTime2, new Date(now));
|
|
3116
|
+
request.input("updatedAt", sql3__default.default.DateTime2, new Date(now));
|
|
2910
3117
|
const mergeSql = `MERGE INTO ${table} AS target
|
|
2911
3118
|
USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
|
|
2912
3119
|
ON target.workflow_name = src.workflow_name AND target.run_id = src.run_id
|
|
@@ -3003,13 +3210,14 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3003
3210
|
);
|
|
3004
3211
|
}
|
|
3005
3212
|
}
|
|
3006
|
-
async
|
|
3213
|
+
async getWorkflowRuns({
|
|
3007
3214
|
workflowName,
|
|
3008
3215
|
fromDate,
|
|
3009
3216
|
toDate,
|
|
3010
3217
|
limit,
|
|
3011
3218
|
offset,
|
|
3012
|
-
resourceId
|
|
3219
|
+
resourceId,
|
|
3220
|
+
status
|
|
3013
3221
|
} = {}) {
|
|
3014
3222
|
try {
|
|
3015
3223
|
const conditions = [];
|
|
@@ -3018,6 +3226,10 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3018
3226
|
conditions.push(`[workflow_name] = @workflowName`);
|
|
3019
3227
|
paramMap["workflowName"] = workflowName;
|
|
3020
3228
|
}
|
|
3229
|
+
if (status) {
|
|
3230
|
+
conditions.push(`JSON_VALUE([snapshot], '$.status') = @status`);
|
|
3231
|
+
paramMap["status"] = status;
|
|
3232
|
+
}
|
|
3021
3233
|
if (resourceId) {
|
|
3022
3234
|
const hasResourceId = await this.operations.hasColumn(storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId");
|
|
3023
3235
|
if (hasResourceId) {
|
|
@@ -3041,7 +3253,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3041
3253
|
const request = this.pool.request();
|
|
3042
3254
|
Object.entries(paramMap).forEach(([key, value]) => {
|
|
3043
3255
|
if (value instanceof Date) {
|
|
3044
|
-
request.input(key,
|
|
3256
|
+
request.input(key, sql3__default.default.DateTime, value);
|
|
3045
3257
|
} else {
|
|
3046
3258
|
request.input(key, value);
|
|
3047
3259
|
}
|
|
@@ -3098,7 +3310,7 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3098
3310
|
}
|
|
3099
3311
|
}
|
|
3100
3312
|
this.schema = config.schemaName || "dbo";
|
|
3101
|
-
this.pool = "connectionString" in config ? new
|
|
3313
|
+
this.pool = "connectionString" in config ? new sql3__default.default.ConnectionPool(config.connectionString) : new sql3__default.default.ConnectionPool({
|
|
3102
3314
|
server: config.server,
|
|
3103
3315
|
database: config.database,
|
|
3104
3316
|
user: config.user,
|
|
@@ -3106,15 +3318,19 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3106
3318
|
port: config.port,
|
|
3107
3319
|
options: config.options || { encrypt: true, trustServerCertificate: true }
|
|
3108
3320
|
});
|
|
3321
|
+
const legacyEvals = new LegacyEvalsMSSQL({ pool: this.pool, schema: this.schema });
|
|
3109
3322
|
const operations = new StoreOperationsMSSQL({ pool: this.pool, schemaName: this.schema });
|
|
3110
3323
|
const scores = new ScoresMSSQL({ pool: this.pool, operations, schema: this.schema });
|
|
3324
|
+
const traces = new TracesMSSQL({ pool: this.pool, operations, schema: this.schema });
|
|
3111
3325
|
const workflows = new WorkflowsMSSQL({ pool: this.pool, operations, schema: this.schema });
|
|
3112
3326
|
const memory = new MemoryMSSQL({ pool: this.pool, schema: this.schema, operations });
|
|
3113
3327
|
const observability = new ObservabilityMSSQL({ pool: this.pool, operations, schema: this.schema });
|
|
3114
3328
|
this.stores = {
|
|
3115
3329
|
operations,
|
|
3116
3330
|
scores,
|
|
3331
|
+
traces,
|
|
3117
3332
|
workflows,
|
|
3333
|
+
legacyEvals,
|
|
3118
3334
|
memory,
|
|
3119
3335
|
observability
|
|
3120
3336
|
};
|
|
@@ -3173,6 +3389,25 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3173
3389
|
indexManagement: true
|
|
3174
3390
|
};
|
|
3175
3391
|
}
|
|
3392
|
+
/** @deprecated use getEvals instead */
|
|
3393
|
+
async getEvalsByAgentName(agentName, type) {
|
|
3394
|
+
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
3395
|
+
}
|
|
3396
|
+
async getEvals(options = {}) {
|
|
3397
|
+
return this.stores.legacyEvals.getEvals(options);
|
|
3398
|
+
}
|
|
3399
|
+
/**
|
|
3400
|
+
* @deprecated use getTracesPaginated instead
|
|
3401
|
+
*/
|
|
3402
|
+
async getTraces(args) {
|
|
3403
|
+
return this.stores.traces.getTraces(args);
|
|
3404
|
+
}
|
|
3405
|
+
async getTracesPaginated(args) {
|
|
3406
|
+
return this.stores.traces.getTracesPaginated(args);
|
|
3407
|
+
}
|
|
3408
|
+
async batchTraceInsert({ records }) {
|
|
3409
|
+
return this.stores.traces.batchTraceInsert({ records });
|
|
3410
|
+
}
|
|
3176
3411
|
async createTable({
|
|
3177
3412
|
tableName,
|
|
3178
3413
|
schema
|
|
@@ -3232,6 +3467,12 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3232
3467
|
async getMessages(args) {
|
|
3233
3468
|
return this.stores.memory.getMessages(args);
|
|
3234
3469
|
}
|
|
3470
|
+
async getMessagesById({
|
|
3471
|
+
messageIds,
|
|
3472
|
+
format
|
|
3473
|
+
}) {
|
|
3474
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3475
|
+
}
|
|
3235
3476
|
async getMessagesPaginated(args) {
|
|
3236
3477
|
return this.stores.memory.getMessagesPaginated(args);
|
|
3237
3478
|
}
|
|
@@ -3267,9 +3508,9 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3267
3508
|
runId,
|
|
3268
3509
|
stepId,
|
|
3269
3510
|
result,
|
|
3270
|
-
|
|
3511
|
+
runtimeContext
|
|
3271
3512
|
}) {
|
|
3272
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
3513
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
3273
3514
|
}
|
|
3274
3515
|
async updateWorkflowState({
|
|
3275
3516
|
workflowName,
|
|
@@ -3292,15 +3533,8 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3292
3533
|
}) {
|
|
3293
3534
|
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
3294
3535
|
}
|
|
3295
|
-
async
|
|
3296
|
-
|
|
3297
|
-
fromDate,
|
|
3298
|
-
toDate,
|
|
3299
|
-
limit,
|
|
3300
|
-
offset,
|
|
3301
|
-
resourceId
|
|
3302
|
-
} = {}) {
|
|
3303
|
-
return this.stores.workflows.listWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId });
|
|
3536
|
+
async getWorkflowRuns(args = {}) {
|
|
3537
|
+
return this.stores.workflows.getWorkflowRuns(args);
|
|
3304
3538
|
}
|
|
3305
3539
|
async getWorkflowRunById({
|
|
3306
3540
|
runId,
|