@mastra/mssql 0.0.0-fix-backport-setserver-20251201151948 → 0.0.0-fix-request-context-as-query-key-20251209130646
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 +588 -53
- package/README.md +28 -20
- package/dist/index.cjs +470 -776
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +469 -775
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +14 -43
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +16 -16
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +6 -6
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +5 -11
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +58 -96
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +12 -14
- package/dist/storage/domains/legacy-evals/index.d.ts +0 -20
- package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
- package/dist/storage/domains/traces/index.d.ts +0 -37
- package/dist/storage/domains/traces/index.d.ts.map +0 -1
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 utils = require('@mastra/core/utils');
|
|
5
|
+
var sql2 = require('mssql');
|
|
7
6
|
var agent = require('@mastra/core/agent');
|
|
7
|
+
var utils = require('@mastra/core/utils');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
|
-
var
|
|
9
|
+
var evals = require('@mastra/core/evals');
|
|
10
10
|
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var sql2__default = /*#__PURE__*/_interopDefault(sql2);
|
|
14
14
|
|
|
15
15
|
// src/storage/index.ts
|
|
16
16
|
function getSchemaName(schema) {
|
|
@@ -32,24 +32,62 @@ function buildDateRangeFilter(dateRange, fieldName) {
|
|
|
32
32
|
}
|
|
33
33
|
return filters;
|
|
34
34
|
}
|
|
35
|
+
function isInOperator(value) {
|
|
36
|
+
return typeof value === "object" && value !== null && "$in" in value && Array.isArray(value.$in);
|
|
37
|
+
}
|
|
35
38
|
function prepareWhereClause(filters, _schema) {
|
|
36
39
|
const conditions = [];
|
|
37
40
|
const params = {};
|
|
38
41
|
let paramIndex = 1;
|
|
39
42
|
Object.entries(filters).forEach(([key, value]) => {
|
|
40
43
|
if (value === void 0) return;
|
|
41
|
-
const paramName = `p${paramIndex++}`;
|
|
42
44
|
if (key.endsWith("_gte")) {
|
|
45
|
+
const paramName = `p${paramIndex++}`;
|
|
43
46
|
const fieldName = key.slice(0, -4);
|
|
44
47
|
conditions.push(`[${utils.parseSqlIdentifier(fieldName, "field name")}] >= @${paramName}`);
|
|
45
48
|
params[paramName] = value instanceof Date ? value.toISOString() : value;
|
|
46
49
|
} else if (key.endsWith("_lte")) {
|
|
50
|
+
const paramName = `p${paramIndex++}`;
|
|
47
51
|
const fieldName = key.slice(0, -4);
|
|
48
52
|
conditions.push(`[${utils.parseSqlIdentifier(fieldName, "field name")}] <= @${paramName}`);
|
|
49
53
|
params[paramName] = value instanceof Date ? value.toISOString() : value;
|
|
50
54
|
} else if (value === null) {
|
|
51
55
|
conditions.push(`[${utils.parseSqlIdentifier(key, "field name")}] IS NULL`);
|
|
56
|
+
} else if (isInOperator(value)) {
|
|
57
|
+
const inValues = value.$in;
|
|
58
|
+
if (inValues.length === 0) {
|
|
59
|
+
conditions.push("1 = 0");
|
|
60
|
+
} else if (inValues.length === 1) {
|
|
61
|
+
const paramName = `p${paramIndex++}`;
|
|
62
|
+
conditions.push(`[${utils.parseSqlIdentifier(key, "field name")}] = @${paramName}`);
|
|
63
|
+
params[paramName] = inValues[0] instanceof Date ? inValues[0].toISOString() : inValues[0];
|
|
64
|
+
} else {
|
|
65
|
+
const inParamNames = [];
|
|
66
|
+
for (const item of inValues) {
|
|
67
|
+
const paramName = `p${paramIndex++}`;
|
|
68
|
+
inParamNames.push(`@${paramName}`);
|
|
69
|
+
params[paramName] = item instanceof Date ? item.toISOString() : item;
|
|
70
|
+
}
|
|
71
|
+
conditions.push(`[${utils.parseSqlIdentifier(key, "field name")}] IN (${inParamNames.join(", ")})`);
|
|
72
|
+
}
|
|
73
|
+
} else if (Array.isArray(value)) {
|
|
74
|
+
if (value.length === 0) {
|
|
75
|
+
conditions.push("1 = 0");
|
|
76
|
+
} else if (value.length === 1) {
|
|
77
|
+
const paramName = `p${paramIndex++}`;
|
|
78
|
+
conditions.push(`[${utils.parseSqlIdentifier(key, "field name")}] = @${paramName}`);
|
|
79
|
+
params[paramName] = value[0] instanceof Date ? value[0].toISOString() : value[0];
|
|
80
|
+
} else {
|
|
81
|
+
const inParamNames = [];
|
|
82
|
+
for (const item of value) {
|
|
83
|
+
const paramName = `p${paramIndex++}`;
|
|
84
|
+
inParamNames.push(`@${paramName}`);
|
|
85
|
+
params[paramName] = item instanceof Date ? item.toISOString() : item;
|
|
86
|
+
}
|
|
87
|
+
conditions.push(`[${utils.parseSqlIdentifier(key, "field name")}] IN (${inParamNames.join(", ")})`);
|
|
88
|
+
}
|
|
52
89
|
} else {
|
|
90
|
+
const paramName = `p${paramIndex++}`;
|
|
53
91
|
conditions.push(`[${utils.parseSqlIdentifier(key, "field name")}] = @${paramName}`);
|
|
54
92
|
params[paramName] = value instanceof Date ? value.toISOString() : value;
|
|
55
93
|
}
|
|
@@ -86,153 +124,7 @@ function transformFromSqlRow({
|
|
|
86
124
|
return result;
|
|
87
125
|
}
|
|
88
126
|
|
|
89
|
-
// src/storage/domains/
|
|
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
|
-
};
|
|
127
|
+
// src/storage/domains/memory/index.ts
|
|
236
128
|
var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
237
129
|
pool;
|
|
238
130
|
schema;
|
|
@@ -250,7 +142,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
250
142
|
});
|
|
251
143
|
const cleanMessages = messagesWithParsedContent.map(({ seq_id, ...rest }) => rest);
|
|
252
144
|
const list = new agent.MessageList().add(cleanMessages, "memory");
|
|
253
|
-
return format === "v2" ? list.get.all.
|
|
145
|
+
return format === "v2" ? list.get.all.db() : list.get.all.v1();
|
|
254
146
|
}
|
|
255
147
|
constructor({
|
|
256
148
|
pool,
|
|
@@ -264,7 +156,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
264
156
|
}
|
|
265
157
|
async getThreadById({ threadId }) {
|
|
266
158
|
try {
|
|
267
|
-
const
|
|
159
|
+
const sql5 = `SELECT
|
|
268
160
|
id,
|
|
269
161
|
[resourceId],
|
|
270
162
|
title,
|
|
@@ -275,7 +167,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
275
167
|
WHERE id = @threadId`;
|
|
276
168
|
const request = this.pool.request();
|
|
277
169
|
request.input("threadId", threadId);
|
|
278
|
-
const resultSet = await request.query(
|
|
170
|
+
const resultSet = await request.query(sql5);
|
|
279
171
|
const thread = resultSet.recordset[0] || null;
|
|
280
172
|
if (!thread) {
|
|
281
173
|
return null;
|
|
@@ -289,7 +181,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
289
181
|
} catch (error$1) {
|
|
290
182
|
throw new error.MastraError(
|
|
291
183
|
{
|
|
292
|
-
id: "
|
|
184
|
+
id: storage.createStorageErrorId("MSSQL", "GET_THREAD_BY_ID", "FAILED"),
|
|
293
185
|
domain: error.ErrorDomain.STORAGE,
|
|
294
186
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
295
187
|
details: {
|
|
@@ -300,11 +192,24 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
300
192
|
);
|
|
301
193
|
}
|
|
302
194
|
}
|
|
303
|
-
async
|
|
304
|
-
const { resourceId, page = 0, perPage: perPageInput, orderBy
|
|
195
|
+
async listThreadsByResourceId(args) {
|
|
196
|
+
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
197
|
+
if (page < 0) {
|
|
198
|
+
throw new error.MastraError({
|
|
199
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
200
|
+
domain: error.ErrorDomain.STORAGE,
|
|
201
|
+
category: error.ErrorCategory.USER,
|
|
202
|
+
text: "Page number must be non-negative",
|
|
203
|
+
details: {
|
|
204
|
+
resourceId,
|
|
205
|
+
page
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
210
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
211
|
+
const { field, direction } = this.parseOrderBy(orderBy);
|
|
305
212
|
try {
|
|
306
|
-
const perPage = perPageInput !== void 0 ? perPageInput : 100;
|
|
307
|
-
const currentOffset = page * perPage;
|
|
308
213
|
const baseQuery = `FROM ${getTableName({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName(this.schema) })} WHERE [resourceId] = @resourceId`;
|
|
309
214
|
const countQuery = `SELECT COUNT(*) as count ${baseQuery}`;
|
|
310
215
|
const countRequest = this.pool.request();
|
|
@@ -316,17 +221,22 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
316
221
|
threads: [],
|
|
317
222
|
total: 0,
|
|
318
223
|
page,
|
|
319
|
-
perPage,
|
|
224
|
+
perPage: perPageForResponse,
|
|
320
225
|
hasMore: false
|
|
321
226
|
};
|
|
322
227
|
}
|
|
323
|
-
const orderByField =
|
|
324
|
-
const dir = (
|
|
228
|
+
const orderByField = field === "createdAt" ? "[createdAt]" : "[updatedAt]";
|
|
229
|
+
const dir = (direction || "DESC").toUpperCase() === "ASC" ? "ASC" : "DESC";
|
|
230
|
+
const limitValue = perPageInput === false ? total : perPage;
|
|
325
231
|
const dataQuery = `SELECT id, [resourceId], title, metadata, [createdAt], [updatedAt] ${baseQuery} ORDER BY ${orderByField} ${dir} OFFSET @offset ROWS FETCH NEXT @perPage ROWS ONLY`;
|
|
326
232
|
const dataRequest = this.pool.request();
|
|
327
233
|
dataRequest.input("resourceId", resourceId);
|
|
328
|
-
dataRequest.input("
|
|
329
|
-
|
|
234
|
+
dataRequest.input("offset", offset);
|
|
235
|
+
if (limitValue > 2147483647) {
|
|
236
|
+
dataRequest.input("perPage", sql2__default.default.BigInt, limitValue);
|
|
237
|
+
} else {
|
|
238
|
+
dataRequest.input("perPage", limitValue);
|
|
239
|
+
}
|
|
330
240
|
const rowsResult = await dataRequest.query(dataQuery);
|
|
331
241
|
const rows = rowsResult.recordset || [];
|
|
332
242
|
const threads = rows.map((thread) => ({
|
|
@@ -339,13 +249,13 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
339
249
|
threads,
|
|
340
250
|
total,
|
|
341
251
|
page,
|
|
342
|
-
perPage,
|
|
343
|
-
hasMore:
|
|
252
|
+
perPage: perPageForResponse,
|
|
253
|
+
hasMore: perPageInput === false ? false : offset + perPage < total
|
|
344
254
|
};
|
|
345
255
|
} catch (error$1) {
|
|
346
256
|
const mastraError = new error.MastraError(
|
|
347
257
|
{
|
|
348
|
-
id: "
|
|
258
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
|
|
349
259
|
domain: error.ErrorDomain.STORAGE,
|
|
350
260
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
351
261
|
details: {
|
|
@@ -357,7 +267,13 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
357
267
|
);
|
|
358
268
|
this.logger?.error?.(mastraError.toString());
|
|
359
269
|
this.logger?.trackException?.(mastraError);
|
|
360
|
-
return {
|
|
270
|
+
return {
|
|
271
|
+
threads: [],
|
|
272
|
+
total: 0,
|
|
273
|
+
page,
|
|
274
|
+
perPage: perPageForResponse,
|
|
275
|
+
hasMore: false
|
|
276
|
+
};
|
|
361
277
|
}
|
|
362
278
|
}
|
|
363
279
|
async saveThread({ thread }) {
|
|
@@ -381,18 +297,18 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
381
297
|
req.input("title", thread.title);
|
|
382
298
|
const metadata = thread.metadata ? JSON.stringify(thread.metadata) : null;
|
|
383
299
|
if (metadata === null) {
|
|
384
|
-
req.input("metadata",
|
|
300
|
+
req.input("metadata", sql2__default.default.NVarChar, null);
|
|
385
301
|
} else {
|
|
386
302
|
req.input("metadata", metadata);
|
|
387
303
|
}
|
|
388
|
-
req.input("createdAt",
|
|
389
|
-
req.input("updatedAt",
|
|
304
|
+
req.input("createdAt", sql2__default.default.DateTime2, thread.createdAt);
|
|
305
|
+
req.input("updatedAt", sql2__default.default.DateTime2, thread.updatedAt);
|
|
390
306
|
await req.query(mergeSql);
|
|
391
307
|
return thread;
|
|
392
308
|
} catch (error$1) {
|
|
393
309
|
throw new error.MastraError(
|
|
394
310
|
{
|
|
395
|
-
id: "
|
|
311
|
+
id: storage.createStorageErrorId("MSSQL", "SAVE_THREAD", "FAILED"),
|
|
396
312
|
domain: error.ErrorDomain.STORAGE,
|
|
397
313
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
398
314
|
details: {
|
|
@@ -403,31 +319,6 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
403
319
|
);
|
|
404
320
|
}
|
|
405
321
|
}
|
|
406
|
-
/**
|
|
407
|
-
* @deprecated use getThreadsByResourceIdPaginated instead
|
|
408
|
-
*/
|
|
409
|
-
async getThreadsByResourceId(args) {
|
|
410
|
-
const { resourceId, orderBy = "createdAt", sortDirection = "DESC" } = args;
|
|
411
|
-
try {
|
|
412
|
-
const baseQuery = `FROM ${getTableName({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName(this.schema) })} WHERE [resourceId] = @resourceId`;
|
|
413
|
-
const orderByField = orderBy === "createdAt" ? "[createdAt]" : "[updatedAt]";
|
|
414
|
-
const dir = (sortDirection || "DESC").toUpperCase() === "ASC" ? "ASC" : "DESC";
|
|
415
|
-
const dataQuery = `SELECT id, [resourceId], title, metadata, [createdAt], [updatedAt] ${baseQuery} ORDER BY ${orderByField} ${dir}`;
|
|
416
|
-
const request = this.pool.request();
|
|
417
|
-
request.input("resourceId", resourceId);
|
|
418
|
-
const resultSet = await request.query(dataQuery);
|
|
419
|
-
const rows = resultSet.recordset || [];
|
|
420
|
-
return rows.map((thread) => ({
|
|
421
|
-
...thread,
|
|
422
|
-
metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata,
|
|
423
|
-
createdAt: thread.createdAt,
|
|
424
|
-
updatedAt: thread.updatedAt
|
|
425
|
-
}));
|
|
426
|
-
} catch (error) {
|
|
427
|
-
this.logger?.error?.(`Error getting threads for resource ${resourceId}:`, error);
|
|
428
|
-
return [];
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
322
|
/**
|
|
432
323
|
* Updates a thread's title and metadata, merging with existing metadata. Returns the updated thread.
|
|
433
324
|
*/
|
|
@@ -439,7 +330,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
439
330
|
const existingThread = await this.getThreadById({ threadId: id });
|
|
440
331
|
if (!existingThread) {
|
|
441
332
|
throw new error.MastraError({
|
|
442
|
-
id: "
|
|
333
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_THREAD", "NOT_FOUND"),
|
|
443
334
|
domain: error.ErrorDomain.STORAGE,
|
|
444
335
|
category: error.ErrorCategory.USER,
|
|
445
336
|
text: `Thread ${id} not found`,
|
|
@@ -455,7 +346,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
455
346
|
};
|
|
456
347
|
try {
|
|
457
348
|
const table = getTableName({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName(this.schema) });
|
|
458
|
-
const
|
|
349
|
+
const sql5 = `UPDATE ${table}
|
|
459
350
|
SET title = @title,
|
|
460
351
|
metadata = @metadata,
|
|
461
352
|
[updatedAt] = @updatedAt
|
|
@@ -466,7 +357,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
466
357
|
req.input("title", title);
|
|
467
358
|
req.input("metadata", JSON.stringify(mergedMetadata));
|
|
468
359
|
req.input("updatedAt", /* @__PURE__ */ new Date());
|
|
469
|
-
const result = await req.query(
|
|
360
|
+
const result = await req.query(sql5);
|
|
470
361
|
let thread = result.recordset && result.recordset[0];
|
|
471
362
|
if (thread && "seq_id" in thread) {
|
|
472
363
|
const { seq_id, ...rest } = thread;
|
|
@@ -474,7 +365,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
474
365
|
}
|
|
475
366
|
if (!thread) {
|
|
476
367
|
throw new error.MastraError({
|
|
477
|
-
id: "
|
|
368
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_THREAD", "NOT_FOUND"),
|
|
478
369
|
domain: error.ErrorDomain.STORAGE,
|
|
479
370
|
category: error.ErrorCategory.USER,
|
|
480
371
|
text: `Thread ${id} not found after update`,
|
|
@@ -493,7 +384,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
493
384
|
} catch (error$1) {
|
|
494
385
|
throw new error.MastraError(
|
|
495
386
|
{
|
|
496
|
-
id: "
|
|
387
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_THREAD", "FAILED"),
|
|
497
388
|
domain: error.ErrorDomain.STORAGE,
|
|
498
389
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
499
390
|
details: {
|
|
@@ -523,7 +414,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
523
414
|
});
|
|
524
415
|
throw new error.MastraError(
|
|
525
416
|
{
|
|
526
|
-
id: "
|
|
417
|
+
id: storage.createStorageErrorId("MSSQL", "DELETE_THREAD", "FAILED"),
|
|
527
418
|
domain: error.ErrorDomain.STORAGE,
|
|
528
419
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
529
420
|
details: {
|
|
@@ -534,25 +425,18 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
534
425
|
);
|
|
535
426
|
}
|
|
536
427
|
}
|
|
537
|
-
async _getIncludedMessages({
|
|
538
|
-
|
|
539
|
-
selectBy,
|
|
540
|
-
orderByStatement
|
|
541
|
-
}) {
|
|
542
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
543
|
-
const include = selectBy?.include;
|
|
544
|
-
if (!include) return null;
|
|
428
|
+
async _getIncludedMessages({ include }) {
|
|
429
|
+
if (!include || include.length === 0) return null;
|
|
545
430
|
const unionQueries = [];
|
|
546
431
|
const paramValues = [];
|
|
547
432
|
let paramIdx = 1;
|
|
548
433
|
const paramNames = [];
|
|
434
|
+
const tableName = getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
|
|
549
435
|
for (const inc of include) {
|
|
550
436
|
const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
|
|
551
|
-
const
|
|
552
|
-
const
|
|
553
|
-
const
|
|
554
|
-
const pPrev = `@p${paramIdx + 2}`;
|
|
555
|
-
const pNext = `@p${paramIdx + 3}`;
|
|
437
|
+
const pId = `@p${paramIdx}`;
|
|
438
|
+
const pPrev = `@p${paramIdx + 1}`;
|
|
439
|
+
const pNext = `@p${paramIdx + 2}`;
|
|
556
440
|
unionQueries.push(
|
|
557
441
|
`
|
|
558
442
|
SELECT
|
|
@@ -565,30 +449,32 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
565
449
|
m.[resourceId],
|
|
566
450
|
m.seq_id
|
|
567
451
|
FROM (
|
|
568
|
-
SELECT *, ROW_NUMBER() OVER (
|
|
569
|
-
FROM ${
|
|
570
|
-
WHERE [thread_id] = ${
|
|
452
|
+
SELECT *, ROW_NUMBER() OVER (ORDER BY [createdAt] ASC) as row_num
|
|
453
|
+
FROM ${tableName}
|
|
454
|
+
WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId})
|
|
571
455
|
) AS m
|
|
572
456
|
WHERE m.id = ${pId}
|
|
573
457
|
OR EXISTS (
|
|
574
458
|
SELECT 1
|
|
575
459
|
FROM (
|
|
576
|
-
SELECT *, ROW_NUMBER() OVER (
|
|
577
|
-
FROM ${
|
|
578
|
-
WHERE [thread_id] = ${
|
|
460
|
+
SELECT *, ROW_NUMBER() OVER (ORDER BY [createdAt] ASC) as row_num
|
|
461
|
+
FROM ${tableName}
|
|
462
|
+
WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId})
|
|
579
463
|
) AS target
|
|
580
464
|
WHERE target.id = ${pId}
|
|
581
465
|
AND (
|
|
582
|
-
|
|
466
|
+
-- Get previous messages (messages that come BEFORE the target)
|
|
467
|
+
(m.row_num < target.row_num AND m.row_num >= target.row_num - ${pPrev})
|
|
583
468
|
OR
|
|
584
|
-
|
|
469
|
+
-- Get next messages (messages that come AFTER the target)
|
|
470
|
+
(m.row_num > target.row_num AND m.row_num <= target.row_num + ${pNext})
|
|
585
471
|
)
|
|
586
472
|
)
|
|
587
473
|
`
|
|
588
474
|
);
|
|
589
|
-
paramValues.push(
|
|
590
|
-
paramNames.push(`p${paramIdx}`, `p${paramIdx + 1}`, `p${paramIdx + 2}
|
|
591
|
-
paramIdx +=
|
|
475
|
+
paramValues.push(id, withPreviousMessages, withNextMessages);
|
|
476
|
+
paramNames.push(`p${paramIdx}`, `p${paramIdx + 1}`, `p${paramIdx + 2}`);
|
|
477
|
+
paramIdx += 3;
|
|
592
478
|
}
|
|
593
479
|
const finalQuery = `
|
|
594
480
|
SELECT * FROM (
|
|
@@ -610,34 +496,16 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
610
496
|
});
|
|
611
497
|
return dedupedRows;
|
|
612
498
|
}
|
|
613
|
-
async
|
|
614
|
-
|
|
499
|
+
async listMessagesById({ messageIds }) {
|
|
500
|
+
if (messageIds.length === 0) return { messages: [] };
|
|
615
501
|
const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
|
|
616
502
|
const orderByStatement = `ORDER BY [seq_id] DESC`;
|
|
617
|
-
const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
|
|
618
503
|
try {
|
|
619
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
620
504
|
let rows = [];
|
|
621
|
-
|
|
622
|
-
if (include?.length) {
|
|
623
|
-
const includeMessages = await this._getIncludedMessages({ threadId, selectBy, orderByStatement });
|
|
624
|
-
if (includeMessages) {
|
|
625
|
-
rows.push(...includeMessages);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
const excludeIds = rows.map((m) => m.id).filter(Boolean);
|
|
629
|
-
let query = `${selectStatement} FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} WHERE [thread_id] = @threadId`;
|
|
505
|
+
let query = `${selectStatement} FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} WHERE [id] IN (${messageIds.map((_, i) => `@id${i}`).join(", ")})`;
|
|
630
506
|
const request = this.pool.request();
|
|
631
|
-
request.input(
|
|
632
|
-
|
|
633
|
-
const excludeParams = excludeIds.map((_, idx) => `@id${idx}`);
|
|
634
|
-
query += ` AND id NOT IN (${excludeParams.join(", ")})`;
|
|
635
|
-
excludeIds.forEach((id, idx) => {
|
|
636
|
-
request.input(`id${idx}`, id);
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
query += ` ${orderByStatement} OFFSET 0 ROWS FETCH NEXT @limit ROWS ONLY`;
|
|
640
|
-
request.input("limit", limit);
|
|
507
|
+
messageIds.forEach((id, i) => request.input(`id${i}`, id));
|
|
508
|
+
query += ` ${orderByStatement}`;
|
|
641
509
|
const result = await request.query(query);
|
|
642
510
|
const remainingRows = result.recordset || [];
|
|
643
511
|
rows.push(...remainingRows);
|
|
@@ -645,158 +513,177 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
645
513
|
const timeDiff = a.seq_id - b.seq_id;
|
|
646
514
|
return timeDiff;
|
|
647
515
|
});
|
|
648
|
-
|
|
649
|
-
|
|
516
|
+
const messagesWithParsedContent = rows.map((row) => {
|
|
517
|
+
if (typeof row.content === "string") {
|
|
518
|
+
try {
|
|
519
|
+
return { ...row, content: JSON.parse(row.content) };
|
|
520
|
+
} catch {
|
|
521
|
+
return row;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return row;
|
|
525
|
+
});
|
|
526
|
+
const cleanMessages = messagesWithParsedContent.map(({ seq_id, ...rest }) => rest);
|
|
527
|
+
const list = new agent.MessageList().add(cleanMessages, "memory");
|
|
528
|
+
return { messages: list.get.all.db() };
|
|
650
529
|
} catch (error$1) {
|
|
651
530
|
const mastraError = new error.MastraError(
|
|
652
531
|
{
|
|
653
|
-
id: "
|
|
532
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_MESSAGES_BY_ID", "FAILED"),
|
|
654
533
|
domain: error.ErrorDomain.STORAGE,
|
|
655
534
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
656
535
|
details: {
|
|
657
|
-
|
|
658
|
-
resourceId: resourceId ?? ""
|
|
536
|
+
messageIds: JSON.stringify(messageIds)
|
|
659
537
|
}
|
|
660
538
|
},
|
|
661
539
|
error$1
|
|
662
540
|
);
|
|
663
541
|
this.logger?.error?.(mastraError.toString());
|
|
664
542
|
this.logger?.trackException?.(mastraError);
|
|
665
|
-
return [];
|
|
543
|
+
return { messages: [] };
|
|
666
544
|
}
|
|
667
545
|
}
|
|
668
|
-
async
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
|
|
674
|
-
const orderByStatement = `ORDER BY [seq_id] DESC`;
|
|
675
|
-
try {
|
|
676
|
-
let rows = [];
|
|
677
|
-
let query = `${selectStatement} FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} WHERE [id] IN (${messageIds.map((_, i) => `@id${i}`).join(", ")})`;
|
|
678
|
-
const request = this.pool.request();
|
|
679
|
-
messageIds.forEach((id, i) => request.input(`id${i}`, id));
|
|
680
|
-
query += ` ${orderByStatement}`;
|
|
681
|
-
const result = await request.query(query);
|
|
682
|
-
const remainingRows = result.recordset || [];
|
|
683
|
-
rows.push(...remainingRows);
|
|
684
|
-
rows.sort((a, b) => {
|
|
685
|
-
const timeDiff = a.seq_id - b.seq_id;
|
|
686
|
-
return timeDiff;
|
|
687
|
-
});
|
|
688
|
-
rows = rows.map(({ seq_id, ...rest }) => rest);
|
|
689
|
-
if (format === `v1`) return this._parseAndFormatMessages(rows, format);
|
|
690
|
-
return this._parseAndFormatMessages(rows, `v2`);
|
|
691
|
-
} catch (error$1) {
|
|
692
|
-
const mastraError = new error.MastraError(
|
|
546
|
+
async listMessages(args) {
|
|
547
|
+
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
548
|
+
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
549
|
+
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
550
|
+
throw new error.MastraError(
|
|
693
551
|
{
|
|
694
|
-
id: "
|
|
552
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_MESSAGES", "INVALID_THREAD_ID"),
|
|
695
553
|
domain: error.ErrorDomain.STORAGE,
|
|
696
554
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
697
|
-
details: {
|
|
698
|
-
messageIds: JSON.stringify(messageIds)
|
|
699
|
-
}
|
|
555
|
+
details: { threadId: Array.isArray(threadId) ? threadId.join(",") : threadId }
|
|
700
556
|
},
|
|
701
|
-
|
|
557
|
+
new Error("threadId must be a non-empty string or array of non-empty strings")
|
|
702
558
|
);
|
|
703
|
-
this.logger?.error?.(mastraError.toString());
|
|
704
|
-
this.logger?.trackException?.(mastraError);
|
|
705
|
-
return [];
|
|
706
559
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
560
|
+
if (page < 0) {
|
|
561
|
+
throw new error.MastraError({
|
|
562
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_MESSAGES", "INVALID_PAGE"),
|
|
563
|
+
domain: error.ErrorDomain.STORAGE,
|
|
564
|
+
category: error.ErrorCategory.USER,
|
|
565
|
+
text: "Page number must be non-negative",
|
|
566
|
+
details: {
|
|
567
|
+
threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
|
|
568
|
+
page
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
const perPage = storage.normalizePerPage(perPageInput, 40);
|
|
573
|
+
const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
711
574
|
try {
|
|
712
|
-
|
|
713
|
-
const
|
|
714
|
-
const
|
|
715
|
-
const
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
request
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
request.input("fromDate", fromDate.toISOString());
|
|
730
|
-
}
|
|
731
|
-
if (toDate instanceof Date && !isNaN(toDate.getTime())) {
|
|
732
|
-
conditions.push("[createdAt] <= @toDate");
|
|
733
|
-
request.input("toDate", toDate.toISOString());
|
|
734
|
-
}
|
|
735
|
-
const whereClause = `WHERE ${conditions.join(" AND ")}`;
|
|
736
|
-
const countQuery = `SELECT COUNT(*) as total FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} ${whereClause}`;
|
|
737
|
-
const countResult = await request.query(countQuery);
|
|
575
|
+
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
576
|
+
const orderByStatement = `ORDER BY [${field}] ${direction}, [seq_id] ${direction}`;
|
|
577
|
+
const tableName = getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
|
|
578
|
+
const baseQuery = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId FROM ${tableName}`;
|
|
579
|
+
const filters = {
|
|
580
|
+
thread_id: threadIds.length === 1 ? threadIds[0] : { $in: threadIds },
|
|
581
|
+
...resourceId ? { resourceId } : {},
|
|
582
|
+
...buildDateRangeFilter(filter?.dateRange, "createdAt")
|
|
583
|
+
};
|
|
584
|
+
const { sql: actualWhereClause = "", params: whereParams } = prepareWhereClause(
|
|
585
|
+
filters);
|
|
586
|
+
const bindWhereParams = (req) => {
|
|
587
|
+
Object.entries(whereParams).forEach(([paramName, paramValue]) => req.input(paramName, paramValue));
|
|
588
|
+
};
|
|
589
|
+
const countRequest = this.pool.request();
|
|
590
|
+
bindWhereParams(countRequest);
|
|
591
|
+
const countResult = await countRequest.query(`SELECT COUNT(*) as total FROM ${tableName}${actualWhereClause}`);
|
|
738
592
|
const total = parseInt(countResult.recordset[0]?.total, 10) || 0;
|
|
739
|
-
|
|
740
|
-
const
|
|
593
|
+
const fetchBaseMessages = async () => {
|
|
594
|
+
const request = this.pool.request();
|
|
595
|
+
bindWhereParams(request);
|
|
596
|
+
if (perPageInput === false) {
|
|
597
|
+
const result2 = await request.query(`${baseQuery}${actualWhereClause} ${orderByStatement}`);
|
|
598
|
+
return result2.recordset || [];
|
|
599
|
+
}
|
|
600
|
+
request.input("offset", offset);
|
|
601
|
+
request.input("limit", perPage > 2147483647 ? sql2__default.default.BigInt : sql2__default.default.Int, perPage);
|
|
602
|
+
const result = await request.query(
|
|
603
|
+
`${baseQuery}${actualWhereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`
|
|
604
|
+
);
|
|
605
|
+
return result.recordset || [];
|
|
606
|
+
};
|
|
607
|
+
const baseRows = perPage === 0 ? [] : await fetchBaseMessages();
|
|
608
|
+
const messages = [...baseRows];
|
|
609
|
+
const seqById = /* @__PURE__ */ new Map();
|
|
610
|
+
messages.forEach((msg) => {
|
|
611
|
+
if (typeof msg.seq_id === "number") seqById.set(msg.id, msg.seq_id);
|
|
612
|
+
});
|
|
613
|
+
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
741
614
|
return {
|
|
742
|
-
messages:
|
|
743
|
-
total:
|
|
615
|
+
messages: [],
|
|
616
|
+
total: 0,
|
|
744
617
|
page,
|
|
745
|
-
perPage,
|
|
618
|
+
perPage: perPageForResponse,
|
|
746
619
|
hasMore: false
|
|
747
620
|
};
|
|
748
621
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
622
|
+
if (include?.length) {
|
|
623
|
+
const messageIds = new Set(messages.map((m) => m.id));
|
|
624
|
+
const includeMessages = await this._getIncludedMessages({ include });
|
|
625
|
+
includeMessages?.forEach((msg) => {
|
|
626
|
+
if (!messageIds.has(msg.id)) {
|
|
627
|
+
messages.push(msg);
|
|
628
|
+
messageIds.add(msg.id);
|
|
629
|
+
if (typeof msg.seq_id === "number") seqById.set(msg.id, msg.seq_id);
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
const parsed = this._parseAndFormatMessages(messages, "v2");
|
|
634
|
+
const mult = direction === "ASC" ? 1 : -1;
|
|
635
|
+
const finalMessages = parsed.sort((a, b) => {
|
|
636
|
+
const aVal = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
|
|
637
|
+
const bVal = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
|
|
638
|
+
if (aVal == null || bVal == null) {
|
|
639
|
+
return aVal == null && bVal == null ? a.id.localeCompare(b.id) : aVal == null ? 1 : -1;
|
|
640
|
+
}
|
|
641
|
+
const diff = (typeof aVal === "number" && typeof bVal === "number" ? aVal - bVal : String(aVal).localeCompare(String(bVal))) * mult;
|
|
642
|
+
if (diff !== 0) return diff;
|
|
643
|
+
const seqA = seqById.get(a.id);
|
|
644
|
+
const seqB = seqById.get(b.id);
|
|
645
|
+
return seqA != null && seqB != null ? (seqA - seqB) * mult : a.id.localeCompare(b.id);
|
|
646
|
+
});
|
|
647
|
+
const threadIdSet = new Set(threadIds);
|
|
648
|
+
const returnedThreadMessageCount = finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).length;
|
|
649
|
+
const hasMore = perPageInput !== false && returnedThreadMessageCount < total && offset + perPage < total;
|
|
765
650
|
return {
|
|
766
|
-
messages:
|
|
651
|
+
messages: finalMessages,
|
|
767
652
|
total,
|
|
768
653
|
page,
|
|
769
|
-
perPage,
|
|
770
|
-
hasMore
|
|
654
|
+
perPage: perPageForResponse,
|
|
655
|
+
hasMore
|
|
771
656
|
};
|
|
772
657
|
} catch (error$1) {
|
|
773
658
|
const mastraError = new error.MastraError(
|
|
774
659
|
{
|
|
775
|
-
id: "
|
|
660
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_MESSAGES", "FAILED"),
|
|
776
661
|
domain: error.ErrorDomain.STORAGE,
|
|
777
662
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
778
663
|
details: {
|
|
779
|
-
threadId,
|
|
780
|
-
resourceId: resourceId ?? ""
|
|
781
|
-
page
|
|
664
|
+
threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
|
|
665
|
+
resourceId: resourceId ?? ""
|
|
782
666
|
}
|
|
783
667
|
},
|
|
784
668
|
error$1
|
|
785
669
|
);
|
|
786
670
|
this.logger?.error?.(mastraError.toString());
|
|
787
671
|
this.logger?.trackException?.(mastraError);
|
|
788
|
-
return {
|
|
672
|
+
return {
|
|
673
|
+
messages: [],
|
|
674
|
+
total: 0,
|
|
675
|
+
page,
|
|
676
|
+
perPage: perPageForResponse,
|
|
677
|
+
hasMore: false
|
|
678
|
+
};
|
|
789
679
|
}
|
|
790
680
|
}
|
|
791
|
-
async saveMessages({
|
|
792
|
-
messages
|
|
793
|
-
format
|
|
794
|
-
}) {
|
|
795
|
-
if (messages.length === 0) return messages;
|
|
681
|
+
async saveMessages({ messages }) {
|
|
682
|
+
if (messages.length === 0) return { messages: [] };
|
|
796
683
|
const threadId = messages[0]?.threadId;
|
|
797
684
|
if (!threadId) {
|
|
798
685
|
throw new error.MastraError({
|
|
799
|
-
id: "
|
|
686
|
+
id: storage.createStorageErrorId("MSSQL", "SAVE_MESSAGES", "INVALID_THREAD_ID"),
|
|
800
687
|
domain: error.ErrorDomain.STORAGE,
|
|
801
688
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
802
689
|
text: `Thread ID is required`
|
|
@@ -805,7 +692,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
805
692
|
const thread = await this.getThreadById({ threadId });
|
|
806
693
|
if (!thread) {
|
|
807
694
|
throw new error.MastraError({
|
|
808
|
-
id: "
|
|
695
|
+
id: storage.createStorageErrorId("MSSQL", "SAVE_MESSAGES", "THREAD_NOT_FOUND"),
|
|
809
696
|
domain: error.ErrorDomain.STORAGE,
|
|
810
697
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
811
698
|
text: `Thread ${threadId} not found`,
|
|
@@ -836,7 +723,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
836
723
|
"content",
|
|
837
724
|
typeof message.content === "string" ? message.content : JSON.stringify(message.content)
|
|
838
725
|
);
|
|
839
|
-
request.input("createdAt",
|
|
726
|
+
request.input("createdAt", sql2__default.default.DateTime2, message.createdAt);
|
|
840
727
|
request.input("role", message.role);
|
|
841
728
|
request.input("type", message.type || "v2");
|
|
842
729
|
request.input("resourceId", message.resourceId);
|
|
@@ -855,7 +742,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
855
742
|
await request.query(mergeSql);
|
|
856
743
|
}
|
|
857
744
|
const threadReq = transaction.request();
|
|
858
|
-
threadReq.input("updatedAt",
|
|
745
|
+
threadReq.input("updatedAt", sql2__default.default.DateTime2, /* @__PURE__ */ new Date());
|
|
859
746
|
threadReq.input("id", threadId);
|
|
860
747
|
await threadReq.query(`UPDATE ${tableThreads} SET [updatedAt] = @updatedAt WHERE id = @id`);
|
|
861
748
|
await transaction.commit();
|
|
@@ -874,12 +761,11 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
874
761
|
return message;
|
|
875
762
|
});
|
|
876
763
|
const list = new agent.MessageList().add(messagesWithParsedContent, "memory");
|
|
877
|
-
|
|
878
|
-
return list.get.all.v1();
|
|
764
|
+
return { messages: list.get.all.db() };
|
|
879
765
|
} catch (error$1) {
|
|
880
766
|
throw new error.MastraError(
|
|
881
767
|
{
|
|
882
|
-
id: "
|
|
768
|
+
id: storage.createStorageErrorId("MSSQL", "SAVE_MESSAGES", "FAILED"),
|
|
883
769
|
domain: error.ErrorDomain.STORAGE,
|
|
884
770
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
885
771
|
details: { threadId }
|
|
@@ -970,7 +856,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
970
856
|
await transaction.rollback();
|
|
971
857
|
throw new error.MastraError(
|
|
972
858
|
{
|
|
973
|
-
id: "
|
|
859
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_MESSAGES", "FAILED"),
|
|
974
860
|
domain: error.ErrorDomain.STORAGE,
|
|
975
861
|
category: error.ErrorCategory.THIRD_PARTY
|
|
976
862
|
},
|
|
@@ -1032,7 +918,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
1032
918
|
} catch (error$1) {
|
|
1033
919
|
throw new error.MastraError(
|
|
1034
920
|
{
|
|
1035
|
-
id: "
|
|
921
|
+
id: storage.createStorageErrorId("MSSQL", "DELETE_MESSAGES", "FAILED"),
|
|
1036
922
|
domain: error.ErrorDomain.STORAGE,
|
|
1037
923
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1038
924
|
details: { messageIds: messageIds.join(", ") }
|
|
@@ -1060,7 +946,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
1060
946
|
} catch (error$1) {
|
|
1061
947
|
const mastraError = new error.MastraError(
|
|
1062
948
|
{
|
|
1063
|
-
id: "
|
|
949
|
+
id: storage.createStorageErrorId("MSSQL", "GET_RESOURCE_BY_ID", "FAILED"),
|
|
1064
950
|
domain: error.ErrorDomain.STORAGE,
|
|
1065
951
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1066
952
|
details: { resourceId }
|
|
@@ -1127,7 +1013,7 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
|
|
|
1127
1013
|
} catch (error$1) {
|
|
1128
1014
|
const mastraError = new error.MastraError(
|
|
1129
1015
|
{
|
|
1130
|
-
id: "
|
|
1016
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_RESOURCE", "FAILED"),
|
|
1131
1017
|
domain: error.ErrorDomain.STORAGE,
|
|
1132
1018
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1133
1019
|
details: { resourceId }
|
|
@@ -1154,13 +1040,13 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1154
1040
|
this.operations = operations;
|
|
1155
1041
|
this.schema = schema;
|
|
1156
1042
|
}
|
|
1157
|
-
get
|
|
1043
|
+
get tracingStrategy() {
|
|
1158
1044
|
return {
|
|
1159
1045
|
preferred: "batch-with-updates",
|
|
1160
1046
|
supported: ["batch-with-updates", "insert-only"]
|
|
1161
1047
|
};
|
|
1162
1048
|
}
|
|
1163
|
-
async
|
|
1049
|
+
async createSpan(span) {
|
|
1164
1050
|
try {
|
|
1165
1051
|
const startedAt = span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt;
|
|
1166
1052
|
const endedAt = span.endedAt instanceof Date ? span.endedAt.toISOString() : span.endedAt;
|
|
@@ -1170,11 +1056,11 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1170
1056
|
endedAt
|
|
1171
1057
|
// Note: createdAt/updatedAt will be set by default values
|
|
1172
1058
|
};
|
|
1173
|
-
return this.operations.insert({ tableName: storage.
|
|
1059
|
+
return this.operations.insert({ tableName: storage.TABLE_SPANS, record });
|
|
1174
1060
|
} catch (error$1) {
|
|
1175
1061
|
throw new error.MastraError(
|
|
1176
1062
|
{
|
|
1177
|
-
id: "
|
|
1063
|
+
id: storage.createStorageErrorId("MSSQL", "CREATE_SPAN", "FAILED"),
|
|
1178
1064
|
domain: error.ErrorDomain.STORAGE,
|
|
1179
1065
|
category: error.ErrorCategory.USER,
|
|
1180
1066
|
details: {
|
|
@@ -1188,10 +1074,10 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1188
1074
|
);
|
|
1189
1075
|
}
|
|
1190
1076
|
}
|
|
1191
|
-
async
|
|
1077
|
+
async getTrace(traceId) {
|
|
1192
1078
|
try {
|
|
1193
1079
|
const tableName = getTableName({
|
|
1194
|
-
indexName: storage.
|
|
1080
|
+
indexName: storage.TABLE_SPANS,
|
|
1195
1081
|
schemaName: getSchemaName(this.schema)
|
|
1196
1082
|
});
|
|
1197
1083
|
const request = this.pool.request();
|
|
@@ -1212,7 +1098,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1212
1098
|
traceId,
|
|
1213
1099
|
spans: result.recordset.map(
|
|
1214
1100
|
(span) => transformFromSqlRow({
|
|
1215
|
-
tableName: storage.
|
|
1101
|
+
tableName: storage.TABLE_SPANS,
|
|
1216
1102
|
sqlRow: span
|
|
1217
1103
|
})
|
|
1218
1104
|
)
|
|
@@ -1220,7 +1106,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1220
1106
|
} catch (error$1) {
|
|
1221
1107
|
throw new error.MastraError(
|
|
1222
1108
|
{
|
|
1223
|
-
id: "
|
|
1109
|
+
id: storage.createStorageErrorId("MSSQL", "GET_TRACE", "FAILED"),
|
|
1224
1110
|
domain: error.ErrorDomain.STORAGE,
|
|
1225
1111
|
category: error.ErrorCategory.USER,
|
|
1226
1112
|
details: {
|
|
@@ -1231,7 +1117,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1231
1117
|
);
|
|
1232
1118
|
}
|
|
1233
1119
|
}
|
|
1234
|
-
async
|
|
1120
|
+
async updateSpan({
|
|
1235
1121
|
spanId,
|
|
1236
1122
|
traceId,
|
|
1237
1123
|
updates
|
|
@@ -1245,14 +1131,14 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1245
1131
|
data.startedAt = data.startedAt.toISOString();
|
|
1246
1132
|
}
|
|
1247
1133
|
await this.operations.update({
|
|
1248
|
-
tableName: storage.
|
|
1134
|
+
tableName: storage.TABLE_SPANS,
|
|
1249
1135
|
keys: { spanId, traceId },
|
|
1250
1136
|
data
|
|
1251
1137
|
});
|
|
1252
1138
|
} catch (error$1) {
|
|
1253
1139
|
throw new error.MastraError(
|
|
1254
1140
|
{
|
|
1255
|
-
id: "
|
|
1141
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_SPAN", "FAILED"),
|
|
1256
1142
|
domain: error.ErrorDomain.STORAGE,
|
|
1257
1143
|
category: error.ErrorCategory.USER,
|
|
1258
1144
|
details: {
|
|
@@ -1264,7 +1150,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1264
1150
|
);
|
|
1265
1151
|
}
|
|
1266
1152
|
}
|
|
1267
|
-
async
|
|
1153
|
+
async getTracesPaginated({
|
|
1268
1154
|
filters,
|
|
1269
1155
|
pagination
|
|
1270
1156
|
}) {
|
|
@@ -1289,7 +1175,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1289
1175
|
name = `agent run: '${entityId}'`;
|
|
1290
1176
|
} else {
|
|
1291
1177
|
const error$1 = new error.MastraError({
|
|
1292
|
-
id: "
|
|
1178
|
+
id: storage.createStorageErrorId("MSSQL", "GET_TRACES_PAGINATED", "INVALID_ENTITY_TYPE"),
|
|
1293
1179
|
domain: error.ErrorDomain.STORAGE,
|
|
1294
1180
|
category: error.ErrorCategory.USER,
|
|
1295
1181
|
details: {
|
|
@@ -1308,7 +1194,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1308
1194
|
params[entityParam] = name;
|
|
1309
1195
|
}
|
|
1310
1196
|
const tableName = getTableName({
|
|
1311
|
-
indexName: storage.
|
|
1197
|
+
indexName: storage.TABLE_SPANS,
|
|
1312
1198
|
schemaName: getSchemaName(this.schema)
|
|
1313
1199
|
});
|
|
1314
1200
|
try {
|
|
@@ -1342,7 +1228,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1342
1228
|
);
|
|
1343
1229
|
const spans = dataResult.recordset.map(
|
|
1344
1230
|
(row) => transformFromSqlRow({
|
|
1345
|
-
tableName: storage.
|
|
1231
|
+
tableName: storage.TABLE_SPANS,
|
|
1346
1232
|
sqlRow: row
|
|
1347
1233
|
})
|
|
1348
1234
|
);
|
|
@@ -1358,7 +1244,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1358
1244
|
} catch (error$1) {
|
|
1359
1245
|
throw new error.MastraError(
|
|
1360
1246
|
{
|
|
1361
|
-
id: "
|
|
1247
|
+
id: storage.createStorageErrorId("MSSQL", "GET_TRACES_PAGINATED", "FAILED"),
|
|
1362
1248
|
domain: error.ErrorDomain.STORAGE,
|
|
1363
1249
|
category: error.ErrorCategory.USER
|
|
1364
1250
|
},
|
|
@@ -1366,13 +1252,13 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1366
1252
|
);
|
|
1367
1253
|
}
|
|
1368
1254
|
}
|
|
1369
|
-
async
|
|
1255
|
+
async batchCreateSpans(args) {
|
|
1370
1256
|
if (!args.records || args.records.length === 0) {
|
|
1371
1257
|
return;
|
|
1372
1258
|
}
|
|
1373
1259
|
try {
|
|
1374
1260
|
await this.operations.batchInsert({
|
|
1375
|
-
tableName: storage.
|
|
1261
|
+
tableName: storage.TABLE_SPANS,
|
|
1376
1262
|
records: args.records.map((span) => ({
|
|
1377
1263
|
...span,
|
|
1378
1264
|
startedAt: span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt,
|
|
@@ -1382,7 +1268,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1382
1268
|
} catch (error$1) {
|
|
1383
1269
|
throw new error.MastraError(
|
|
1384
1270
|
{
|
|
1385
|
-
id: "
|
|
1271
|
+
id: storage.createStorageErrorId("MSSQL", "BATCH_CREATE_SPANS", "FAILED"),
|
|
1386
1272
|
domain: error.ErrorDomain.STORAGE,
|
|
1387
1273
|
category: error.ErrorCategory.USER,
|
|
1388
1274
|
details: {
|
|
@@ -1393,7 +1279,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1393
1279
|
);
|
|
1394
1280
|
}
|
|
1395
1281
|
}
|
|
1396
|
-
async
|
|
1282
|
+
async batchUpdateSpans(args) {
|
|
1397
1283
|
if (!args.records || args.records.length === 0) {
|
|
1398
1284
|
return;
|
|
1399
1285
|
}
|
|
@@ -1412,13 +1298,13 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1412
1298
|
};
|
|
1413
1299
|
});
|
|
1414
1300
|
await this.operations.batchUpdate({
|
|
1415
|
-
tableName: storage.
|
|
1301
|
+
tableName: storage.TABLE_SPANS,
|
|
1416
1302
|
updates
|
|
1417
1303
|
});
|
|
1418
1304
|
} catch (error$1) {
|
|
1419
1305
|
throw new error.MastraError(
|
|
1420
1306
|
{
|
|
1421
|
-
id: "
|
|
1307
|
+
id: storage.createStorageErrorId("MSSQL", "BATCH_UPDATE_SPANS", "FAILED"),
|
|
1422
1308
|
domain: error.ErrorDomain.STORAGE,
|
|
1423
1309
|
category: error.ErrorCategory.USER,
|
|
1424
1310
|
details: {
|
|
@@ -1429,20 +1315,20 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
|
|
|
1429
1315
|
);
|
|
1430
1316
|
}
|
|
1431
1317
|
}
|
|
1432
|
-
async
|
|
1318
|
+
async batchDeleteTraces(args) {
|
|
1433
1319
|
if (!args.traceIds || args.traceIds.length === 0) {
|
|
1434
1320
|
return;
|
|
1435
1321
|
}
|
|
1436
1322
|
try {
|
|
1437
1323
|
const keys = args.traceIds.map((traceId) => ({ traceId }));
|
|
1438
1324
|
await this.operations.batchDelete({
|
|
1439
|
-
tableName: storage.
|
|
1325
|
+
tableName: storage.TABLE_SPANS,
|
|
1440
1326
|
keys
|
|
1441
1327
|
});
|
|
1442
1328
|
} catch (error$1) {
|
|
1443
1329
|
throw new error.MastraError(
|
|
1444
1330
|
{
|
|
1445
|
-
id: "
|
|
1331
|
+
id: storage.createStorageErrorId("MSSQL", "BATCH_DELETE_TRACES", "FAILED"),
|
|
1446
1332
|
domain: error.ErrorDomain.STORAGE,
|
|
1447
1333
|
category: error.ErrorCategory.USER,
|
|
1448
1334
|
details: {
|
|
@@ -1482,7 +1368,7 @@ var StoreOperationsMSSQL = class extends storage.StoreOperations {
|
|
|
1482
1368
|
return "BIT";
|
|
1483
1369
|
default:
|
|
1484
1370
|
throw new error.MastraError({
|
|
1485
|
-
id: "
|
|
1371
|
+
id: storage.createStorageErrorId("MSSQL", "TYPE", "NOT_SUPPORTED"),
|
|
1486
1372
|
domain: error.ErrorDomain.STORAGE,
|
|
1487
1373
|
category: error.ErrorCategory.THIRD_PARTY
|
|
1488
1374
|
});
|
|
@@ -1557,7 +1443,7 @@ var StoreOperationsMSSQL = class extends storage.StoreOperations {
|
|
|
1557
1443
|
const value = record[col];
|
|
1558
1444
|
const preparedValue = this.prepareValue(value, col, tableName);
|
|
1559
1445
|
if (preparedValue instanceof Date) {
|
|
1560
|
-
request.input(`param${i}`,
|
|
1446
|
+
request.input(`param${i}`, sql2__default.default.DateTime2, preparedValue);
|
|
1561
1447
|
} else if (preparedValue === null || preparedValue === void 0) {
|
|
1562
1448
|
request.input(`param${i}`, this.getMssqlType(tableName, col), null);
|
|
1563
1449
|
} else {
|
|
@@ -1568,7 +1454,7 @@ var StoreOperationsMSSQL = class extends storage.StoreOperations {
|
|
|
1568
1454
|
} catch (error$1) {
|
|
1569
1455
|
throw new error.MastraError(
|
|
1570
1456
|
{
|
|
1571
|
-
id: "
|
|
1457
|
+
id: storage.createStorageErrorId("MSSQL", "INSERT", "FAILED"),
|
|
1572
1458
|
domain: error.ErrorDomain.STORAGE,
|
|
1573
1459
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1574
1460
|
details: {
|
|
@@ -1594,7 +1480,7 @@ var StoreOperationsMSSQL = class extends storage.StoreOperations {
|
|
|
1594
1480
|
} catch (error$1) {
|
|
1595
1481
|
throw new error.MastraError(
|
|
1596
1482
|
{
|
|
1597
|
-
id: "
|
|
1483
|
+
id: storage.createStorageErrorId("MSSQL", "CLEAR_TABLE", "FAILED"),
|
|
1598
1484
|
domain: error.ErrorDomain.STORAGE,
|
|
1599
1485
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1600
1486
|
details: {
|
|
@@ -1697,7 +1583,7 @@ ${columns}
|
|
|
1697
1583
|
} catch (error$1) {
|
|
1698
1584
|
throw new error.MastraError(
|
|
1699
1585
|
{
|
|
1700
|
-
id: "
|
|
1586
|
+
id: storage.createStorageErrorId("MSSQL", "CREATE_TABLE", "FAILED"),
|
|
1701
1587
|
domain: error.ErrorDomain.STORAGE,
|
|
1702
1588
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1703
1589
|
details: {
|
|
@@ -1757,7 +1643,7 @@ ${columns}
|
|
|
1757
1643
|
} catch (error$1) {
|
|
1758
1644
|
throw new error.MastraError(
|
|
1759
1645
|
{
|
|
1760
|
-
id: "
|
|
1646
|
+
id: storage.createStorageErrorId("MSSQL", "ALTER_TABLE", "FAILED"),
|
|
1761
1647
|
domain: error.ErrorDomain.STORAGE,
|
|
1762
1648
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1763
1649
|
details: {
|
|
@@ -1772,7 +1658,7 @@ ${columns}
|
|
|
1772
1658
|
try {
|
|
1773
1659
|
const keyEntries = Object.entries(keys).map(([key, value]) => [utils.parseSqlIdentifier(key, "column name"), value]);
|
|
1774
1660
|
const conditions = keyEntries.map(([key], i) => `[${key}] = @param${i}`).join(" AND ");
|
|
1775
|
-
const
|
|
1661
|
+
const sql5 = `SELECT * FROM ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} WHERE ${conditions}`;
|
|
1776
1662
|
const request = this.pool.request();
|
|
1777
1663
|
keyEntries.forEach(([key, value], i) => {
|
|
1778
1664
|
const preparedValue = this.prepareValue(value, key, tableName);
|
|
@@ -1782,7 +1668,7 @@ ${columns}
|
|
|
1782
1668
|
request.input(`param${i}`, preparedValue);
|
|
1783
1669
|
}
|
|
1784
1670
|
});
|
|
1785
|
-
const resultSet = await request.query(
|
|
1671
|
+
const resultSet = await request.query(sql5);
|
|
1786
1672
|
const result = resultSet.recordset[0] || null;
|
|
1787
1673
|
if (!result) {
|
|
1788
1674
|
return null;
|
|
@@ -1798,7 +1684,7 @@ ${columns}
|
|
|
1798
1684
|
} catch (error$1) {
|
|
1799
1685
|
throw new error.MastraError(
|
|
1800
1686
|
{
|
|
1801
|
-
id: "
|
|
1687
|
+
id: storage.createStorageErrorId("MSSQL", "LOAD", "FAILED"),
|
|
1802
1688
|
domain: error.ErrorDomain.STORAGE,
|
|
1803
1689
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1804
1690
|
details: {
|
|
@@ -1821,7 +1707,7 @@ ${columns}
|
|
|
1821
1707
|
await transaction.rollback();
|
|
1822
1708
|
throw new error.MastraError(
|
|
1823
1709
|
{
|
|
1824
|
-
id: "
|
|
1710
|
+
id: storage.createStorageErrorId("MSSQL", "BATCH_INSERT", "FAILED"),
|
|
1825
1711
|
domain: error.ErrorDomain.STORAGE,
|
|
1826
1712
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1827
1713
|
details: {
|
|
@@ -1840,7 +1726,7 @@ ${columns}
|
|
|
1840
1726
|
} catch (error$1) {
|
|
1841
1727
|
throw new error.MastraError(
|
|
1842
1728
|
{
|
|
1843
|
-
id: "
|
|
1729
|
+
id: storage.createStorageErrorId("MSSQL", "DROP_TABLE", "FAILED"),
|
|
1844
1730
|
domain: error.ErrorDomain.STORAGE,
|
|
1845
1731
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1846
1732
|
details: {
|
|
@@ -1895,23 +1781,23 @@ ${columns}
|
|
|
1895
1781
|
const col = storage.TABLE_SCHEMAS[tableName]?.[columnName];
|
|
1896
1782
|
switch (col?.type) {
|
|
1897
1783
|
case "text":
|
|
1898
|
-
return
|
|
1784
|
+
return sql2__default.default.NVarChar;
|
|
1899
1785
|
case "timestamp":
|
|
1900
|
-
return
|
|
1786
|
+
return sql2__default.default.DateTime2;
|
|
1901
1787
|
case "uuid":
|
|
1902
|
-
return
|
|
1788
|
+
return sql2__default.default.UniqueIdentifier;
|
|
1903
1789
|
case "jsonb":
|
|
1904
|
-
return
|
|
1790
|
+
return sql2__default.default.NVarChar;
|
|
1905
1791
|
case "integer":
|
|
1906
|
-
return
|
|
1792
|
+
return sql2__default.default.Int;
|
|
1907
1793
|
case "bigint":
|
|
1908
|
-
return
|
|
1794
|
+
return sql2__default.default.BigInt;
|
|
1909
1795
|
case "float":
|
|
1910
|
-
return
|
|
1796
|
+
return sql2__default.default.Float;
|
|
1911
1797
|
case "boolean":
|
|
1912
|
-
return
|
|
1798
|
+
return sql2__default.default.Bit;
|
|
1913
1799
|
default:
|
|
1914
|
-
return
|
|
1800
|
+
return sql2__default.default.NVarChar;
|
|
1915
1801
|
}
|
|
1916
1802
|
}
|
|
1917
1803
|
/**
|
|
@@ -1926,7 +1812,7 @@ ${columns}
|
|
|
1926
1812
|
try {
|
|
1927
1813
|
if (!data || Object.keys(data).length === 0) {
|
|
1928
1814
|
throw new error.MastraError({
|
|
1929
|
-
id: "
|
|
1815
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE", "EMPTY_DATA"),
|
|
1930
1816
|
domain: error.ErrorDomain.STORAGE,
|
|
1931
1817
|
category: error.ErrorCategory.USER,
|
|
1932
1818
|
text: "Cannot update with empty data payload"
|
|
@@ -1934,7 +1820,7 @@ ${columns}
|
|
|
1934
1820
|
}
|
|
1935
1821
|
if (!keys || Object.keys(keys).length === 0) {
|
|
1936
1822
|
throw new error.MastraError({
|
|
1937
|
-
id: "
|
|
1823
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE", "EMPTY_KEYS"),
|
|
1938
1824
|
domain: error.ErrorDomain.STORAGE,
|
|
1939
1825
|
category: error.ErrorCategory.USER,
|
|
1940
1826
|
text: "Cannot update without keys to identify records"
|
|
@@ -1975,7 +1861,7 @@ ${columns}
|
|
|
1975
1861
|
} catch (error$1) {
|
|
1976
1862
|
throw new error.MastraError(
|
|
1977
1863
|
{
|
|
1978
|
-
id: "
|
|
1864
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE", "FAILED"),
|
|
1979
1865
|
domain: error.ErrorDomain.STORAGE,
|
|
1980
1866
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1981
1867
|
details: {
|
|
@@ -2004,7 +1890,7 @@ ${columns}
|
|
|
2004
1890
|
await transaction.rollback();
|
|
2005
1891
|
throw new error.MastraError(
|
|
2006
1892
|
{
|
|
2007
|
-
id: "
|
|
1893
|
+
id: storage.createStorageErrorId("MSSQL", "BATCH_UPDATE", "FAILED"),
|
|
2008
1894
|
domain: error.ErrorDomain.STORAGE,
|
|
2009
1895
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2010
1896
|
details: {
|
|
@@ -2053,7 +1939,7 @@ ${columns}
|
|
|
2053
1939
|
await transaction.rollback();
|
|
2054
1940
|
throw new error.MastraError(
|
|
2055
1941
|
{
|
|
2056
|
-
id: "
|
|
1942
|
+
id: storage.createStorageErrorId("MSSQL", "BATCH_DELETE", "FAILED"),
|
|
2057
1943
|
domain: error.ErrorDomain.STORAGE,
|
|
2058
1944
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2059
1945
|
details: {
|
|
@@ -2110,7 +1996,7 @@ ${columns}
|
|
|
2110
1996
|
} catch (error$1) {
|
|
2111
1997
|
throw new error.MastraError(
|
|
2112
1998
|
{
|
|
2113
|
-
id: "
|
|
1999
|
+
id: storage.createStorageErrorId("MSSQL", "INDEX_CREATE", "FAILED"),
|
|
2114
2000
|
domain: error.ErrorDomain.STORAGE,
|
|
2115
2001
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2116
2002
|
details: {
|
|
@@ -2146,7 +2032,7 @@ ${columns}
|
|
|
2146
2032
|
if (result.recordset.length > 1) {
|
|
2147
2033
|
const tables = result.recordset.map((r) => r.table_name).join(", ");
|
|
2148
2034
|
throw new error.MastraError({
|
|
2149
|
-
id: "
|
|
2035
|
+
id: storage.createStorageErrorId("MSSQL", "INDEX", "AMBIGUOUS"),
|
|
2150
2036
|
domain: error.ErrorDomain.STORAGE,
|
|
2151
2037
|
category: error.ErrorCategory.USER,
|
|
2152
2038
|
text: `Index "${indexNameSafe}" exists on multiple tables (${tables}) in schema "${schemaName}". Please drop indexes manually or ensure unique index names.`
|
|
@@ -2162,7 +2048,7 @@ ${columns}
|
|
|
2162
2048
|
} catch (error$1) {
|
|
2163
2049
|
throw new error.MastraError(
|
|
2164
2050
|
{
|
|
2165
|
-
id: "
|
|
2051
|
+
id: storage.createStorageErrorId("MSSQL", "INDEX_DROP", "FAILED"),
|
|
2166
2052
|
domain: error.ErrorDomain.STORAGE,
|
|
2167
2053
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2168
2054
|
details: {
|
|
@@ -2246,7 +2132,7 @@ ${columns}
|
|
|
2246
2132
|
} catch (error$1) {
|
|
2247
2133
|
throw new error.MastraError(
|
|
2248
2134
|
{
|
|
2249
|
-
id: "
|
|
2135
|
+
id: storage.createStorageErrorId("MSSQL", "INDEX_LIST", "FAILED"),
|
|
2250
2136
|
domain: error.ErrorDomain.STORAGE,
|
|
2251
2137
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2252
2138
|
details: tableName ? {
|
|
@@ -2319,7 +2205,7 @@ ${columns}
|
|
|
2319
2205
|
} catch (error$1) {
|
|
2320
2206
|
throw new error.MastraError(
|
|
2321
2207
|
{
|
|
2322
|
-
id: "
|
|
2208
|
+
id: storage.createStorageErrorId("MSSQL", "INDEX_DESCRIBE", "FAILED"),
|
|
2323
2209
|
domain: error.ErrorDomain.STORAGE,
|
|
2324
2210
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2325
2211
|
details: {
|
|
@@ -2355,35 +2241,30 @@ ${columns}
|
|
|
2355
2241
|
table: storage.TABLE_TRACES,
|
|
2356
2242
|
columns: ["name", "seq_id DESC"]
|
|
2357
2243
|
},
|
|
2358
|
-
{
|
|
2359
|
-
name: `${schemaPrefix}mastra_evals_agent_name_seqid_idx`,
|
|
2360
|
-
table: storage.TABLE_EVALS,
|
|
2361
|
-
columns: ["agent_name", "seq_id DESC"]
|
|
2362
|
-
},
|
|
2363
2244
|
{
|
|
2364
2245
|
name: `${schemaPrefix}mastra_scores_trace_id_span_id_seqid_idx`,
|
|
2365
2246
|
table: storage.TABLE_SCORERS,
|
|
2366
2247
|
columns: ["traceId", "spanId", "seq_id DESC"]
|
|
2367
2248
|
},
|
|
2368
|
-
//
|
|
2249
|
+
// Spans indexes for optimal trace querying
|
|
2369
2250
|
{
|
|
2370
2251
|
name: `${schemaPrefix}mastra_ai_spans_traceid_startedat_idx`,
|
|
2371
|
-
table: storage.
|
|
2252
|
+
table: storage.TABLE_SPANS,
|
|
2372
2253
|
columns: ["traceId", "startedAt DESC"]
|
|
2373
2254
|
},
|
|
2374
2255
|
{
|
|
2375
2256
|
name: `${schemaPrefix}mastra_ai_spans_parentspanid_startedat_idx`,
|
|
2376
|
-
table: storage.
|
|
2257
|
+
table: storage.TABLE_SPANS,
|
|
2377
2258
|
columns: ["parentSpanId", "startedAt DESC"]
|
|
2378
2259
|
},
|
|
2379
2260
|
{
|
|
2380
2261
|
name: `${schemaPrefix}mastra_ai_spans_name_idx`,
|
|
2381
|
-
table: storage.
|
|
2262
|
+
table: storage.TABLE_SPANS,
|
|
2382
2263
|
columns: ["name"]
|
|
2383
2264
|
},
|
|
2384
2265
|
{
|
|
2385
2266
|
name: `${schemaPrefix}mastra_ai_spans_spantype_startedat_idx`,
|
|
2386
|
-
table: storage.
|
|
2267
|
+
table: storage.TABLE_SPANS,
|
|
2387
2268
|
columns: ["spanType", "startedAt DESC"]
|
|
2388
2269
|
}
|
|
2389
2270
|
];
|
|
@@ -2405,7 +2286,7 @@ ${columns}
|
|
|
2405
2286
|
} catch (error$1) {
|
|
2406
2287
|
throw new error.MastraError(
|
|
2407
2288
|
{
|
|
2408
|
-
id: "
|
|
2289
|
+
id: storage.createStorageErrorId("MSSQL", "CREATE_PERFORMANCE_INDEXES", "FAILED"),
|
|
2409
2290
|
domain: error.ErrorDomain.STORAGE,
|
|
2410
2291
|
category: error.ErrorCategory.THIRD_PARTY
|
|
2411
2292
|
},
|
|
@@ -2415,20 +2296,9 @@ ${columns}
|
|
|
2415
2296
|
}
|
|
2416
2297
|
};
|
|
2417
2298
|
function transformScoreRow(row) {
|
|
2418
|
-
return {
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
scorer: storage.safelyParseJSON(row.scorer),
|
|
2422
|
-
preprocessStepResult: storage.safelyParseJSON(row.preprocessStepResult),
|
|
2423
|
-
analyzeStepResult: storage.safelyParseJSON(row.analyzeStepResult),
|
|
2424
|
-
metadata: storage.safelyParseJSON(row.metadata),
|
|
2425
|
-
output: storage.safelyParseJSON(row.output),
|
|
2426
|
-
additionalContext: storage.safelyParseJSON(row.additionalContext),
|
|
2427
|
-
runtimeContext: storage.safelyParseJSON(row.runtimeContext),
|
|
2428
|
-
entity: storage.safelyParseJSON(row.entity),
|
|
2429
|
-
createdAt: new Date(row.createdAt),
|
|
2430
|
-
updatedAt: new Date(row.updatedAt)
|
|
2431
|
-
};
|
|
2299
|
+
return storage.transformScoreRow(row, {
|
|
2300
|
+
convertTimestamps: true
|
|
2301
|
+
});
|
|
2432
2302
|
}
|
|
2433
2303
|
var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
2434
2304
|
pool;
|
|
@@ -2458,7 +2328,7 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2458
2328
|
} catch (error$1) {
|
|
2459
2329
|
throw new error.MastraError(
|
|
2460
2330
|
{
|
|
2461
|
-
id: "
|
|
2331
|
+
id: storage.createStorageErrorId("MSSQL", "GET_SCORE_BY_ID", "FAILED"),
|
|
2462
2332
|
domain: error.ErrorDomain.STORAGE,
|
|
2463
2333
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2464
2334
|
details: { id }
|
|
@@ -2470,19 +2340,27 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2470
2340
|
async saveScore(score) {
|
|
2471
2341
|
let validatedScore;
|
|
2472
2342
|
try {
|
|
2473
|
-
validatedScore =
|
|
2343
|
+
validatedScore = evals.saveScorePayloadSchema.parse(score);
|
|
2474
2344
|
} catch (error$1) {
|
|
2475
2345
|
throw new error.MastraError(
|
|
2476
2346
|
{
|
|
2477
|
-
id: "
|
|
2347
|
+
id: storage.createStorageErrorId("MSSQL", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
2478
2348
|
domain: error.ErrorDomain.STORAGE,
|
|
2479
|
-
category: error.ErrorCategory.
|
|
2349
|
+
category: error.ErrorCategory.USER,
|
|
2350
|
+
details: {
|
|
2351
|
+
scorer: score.scorer?.id ?? "unknown",
|
|
2352
|
+
entityId: score.entityId ?? "unknown",
|
|
2353
|
+
entityType: score.entityType ?? "unknown",
|
|
2354
|
+
traceId: score.traceId ?? "",
|
|
2355
|
+
spanId: score.spanId ?? ""
|
|
2356
|
+
}
|
|
2480
2357
|
},
|
|
2481
2358
|
error$1
|
|
2482
2359
|
);
|
|
2483
2360
|
}
|
|
2484
2361
|
try {
|
|
2485
2362
|
const scoreId = crypto.randomUUID();
|
|
2363
|
+
const now = /* @__PURE__ */ new Date();
|
|
2486
2364
|
const {
|
|
2487
2365
|
scorer,
|
|
2488
2366
|
preprocessStepResult,
|
|
@@ -2491,7 +2369,7 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2491
2369
|
input,
|
|
2492
2370
|
output,
|
|
2493
2371
|
additionalContext,
|
|
2494
|
-
|
|
2372
|
+
requestContext,
|
|
2495
2373
|
entity,
|
|
2496
2374
|
...rest
|
|
2497
2375
|
} = validatedScore;
|
|
@@ -2506,19 +2384,18 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2506
2384
|
analyzeStepResult: analyzeStepResult || null,
|
|
2507
2385
|
metadata: metadata || null,
|
|
2508
2386
|
additionalContext: additionalContext || null,
|
|
2509
|
-
|
|
2387
|
+
requestContext: requestContext || null,
|
|
2510
2388
|
entity: entity || null,
|
|
2511
2389
|
scorer: scorer || null,
|
|
2512
|
-
createdAt:
|
|
2513
|
-
updatedAt:
|
|
2390
|
+
createdAt: now.toISOString(),
|
|
2391
|
+
updatedAt: now.toISOString()
|
|
2514
2392
|
}
|
|
2515
2393
|
});
|
|
2516
|
-
|
|
2517
|
-
return { score: scoreFromDb };
|
|
2394
|
+
return { score: { ...validatedScore, id: scoreId, createdAt: now, updatedAt: now } };
|
|
2518
2395
|
} catch (error$1) {
|
|
2519
2396
|
throw new error.MastraError(
|
|
2520
2397
|
{
|
|
2521
|
-
id: "
|
|
2398
|
+
id: storage.createStorageErrorId("MSSQL", "SAVE_SCORE", "FAILED"),
|
|
2522
2399
|
domain: error.ErrorDomain.STORAGE,
|
|
2523
2400
|
category: error.ErrorCategory.THIRD_PARTY
|
|
2524
2401
|
},
|
|
@@ -2526,7 +2403,7 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2526
2403
|
);
|
|
2527
2404
|
}
|
|
2528
2405
|
}
|
|
2529
|
-
async
|
|
2406
|
+
async listScoresByScorerId({
|
|
2530
2407
|
scorerId,
|
|
2531
2408
|
pagination,
|
|
2532
2409
|
entityId,
|
|
@@ -2560,38 +2437,43 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2560
2437
|
});
|
|
2561
2438
|
const totalResult = await countRequest.query(`SELECT COUNT(*) as count FROM ${tableName} WHERE ${whereClause}`);
|
|
2562
2439
|
const total = totalResult.recordset[0]?.count || 0;
|
|
2440
|
+
const { page, perPage: perPageInput } = pagination;
|
|
2563
2441
|
if (total === 0) {
|
|
2564
2442
|
return {
|
|
2565
2443
|
pagination: {
|
|
2566
2444
|
total: 0,
|
|
2567
|
-
page
|
|
2568
|
-
perPage:
|
|
2445
|
+
page,
|
|
2446
|
+
perPage: perPageInput,
|
|
2569
2447
|
hasMore: false
|
|
2570
2448
|
},
|
|
2571
2449
|
scores: []
|
|
2572
2450
|
};
|
|
2573
2451
|
}
|
|
2452
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
2453
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2454
|
+
const limitValue = perPageInput === false ? total : perPage;
|
|
2455
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
2574
2456
|
const dataRequest = this.pool.request();
|
|
2575
2457
|
Object.entries(params).forEach(([key, value]) => {
|
|
2576
2458
|
dataRequest.input(key, value);
|
|
2577
2459
|
});
|
|
2578
|
-
dataRequest.input("perPage",
|
|
2579
|
-
dataRequest.input("offset",
|
|
2460
|
+
dataRequest.input("perPage", limitValue);
|
|
2461
|
+
dataRequest.input("offset", start);
|
|
2580
2462
|
const dataQuery = `SELECT * FROM ${tableName} WHERE ${whereClause} ORDER BY [createdAt] DESC OFFSET @offset ROWS FETCH NEXT @perPage ROWS ONLY`;
|
|
2581
2463
|
const result = await dataRequest.query(dataQuery);
|
|
2582
2464
|
return {
|
|
2583
2465
|
pagination: {
|
|
2584
2466
|
total: Number(total),
|
|
2585
|
-
page
|
|
2586
|
-
perPage:
|
|
2587
|
-
hasMore:
|
|
2467
|
+
page,
|
|
2468
|
+
perPage: perPageForResponse,
|
|
2469
|
+
hasMore: end < total
|
|
2588
2470
|
},
|
|
2589
2471
|
scores: result.recordset.map((row) => transformScoreRow(row))
|
|
2590
2472
|
};
|
|
2591
2473
|
} catch (error$1) {
|
|
2592
2474
|
throw new error.MastraError(
|
|
2593
2475
|
{
|
|
2594
|
-
id: "
|
|
2476
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_SCORES_BY_SCORER_ID", "FAILED"),
|
|
2595
2477
|
domain: error.ErrorDomain.STORAGE,
|
|
2596
2478
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2597
2479
|
details: { scorerId }
|
|
@@ -2600,7 +2482,7 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2600
2482
|
);
|
|
2601
2483
|
}
|
|
2602
2484
|
}
|
|
2603
|
-
async
|
|
2485
|
+
async listScoresByRunId({
|
|
2604
2486
|
runId,
|
|
2605
2487
|
pagination
|
|
2606
2488
|
}) {
|
|
@@ -2611,37 +2493,42 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2611
2493
|
`SELECT COUNT(*) as count FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName(this.schema) })} WHERE [runId] = @p1`
|
|
2612
2494
|
);
|
|
2613
2495
|
const total = totalResult.recordset[0]?.count || 0;
|
|
2496
|
+
const { page, perPage: perPageInput } = pagination;
|
|
2614
2497
|
if (total === 0) {
|
|
2615
2498
|
return {
|
|
2616
2499
|
pagination: {
|
|
2617
2500
|
total: 0,
|
|
2618
|
-
page
|
|
2619
|
-
perPage:
|
|
2501
|
+
page,
|
|
2502
|
+
perPage: perPageInput,
|
|
2620
2503
|
hasMore: false
|
|
2621
2504
|
},
|
|
2622
2505
|
scores: []
|
|
2623
2506
|
};
|
|
2624
2507
|
}
|
|
2508
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
2509
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2510
|
+
const limitValue = perPageInput === false ? total : perPage;
|
|
2511
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
2625
2512
|
const dataRequest = this.pool.request();
|
|
2626
2513
|
dataRequest.input("p1", runId);
|
|
2627
|
-
dataRequest.input("p2",
|
|
2628
|
-
dataRequest.input("p3",
|
|
2514
|
+
dataRequest.input("p2", limitValue);
|
|
2515
|
+
dataRequest.input("p3", start);
|
|
2629
2516
|
const result = await dataRequest.query(
|
|
2630
2517
|
`SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName(this.schema) })} WHERE [runId] = @p1 ORDER BY [createdAt] DESC OFFSET @p3 ROWS FETCH NEXT @p2 ROWS ONLY`
|
|
2631
2518
|
);
|
|
2632
2519
|
return {
|
|
2633
2520
|
pagination: {
|
|
2634
2521
|
total: Number(total),
|
|
2635
|
-
page
|
|
2636
|
-
perPage:
|
|
2637
|
-
hasMore:
|
|
2522
|
+
page,
|
|
2523
|
+
perPage: perPageForResponse,
|
|
2524
|
+
hasMore: end < total
|
|
2638
2525
|
},
|
|
2639
2526
|
scores: result.recordset.map((row) => transformScoreRow(row))
|
|
2640
2527
|
};
|
|
2641
2528
|
} catch (error$1) {
|
|
2642
2529
|
throw new error.MastraError(
|
|
2643
2530
|
{
|
|
2644
|
-
id: "
|
|
2531
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_SCORES_BY_RUN_ID", "FAILED"),
|
|
2645
2532
|
domain: error.ErrorDomain.STORAGE,
|
|
2646
2533
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2647
2534
|
details: { runId }
|
|
@@ -2650,7 +2537,7 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2650
2537
|
);
|
|
2651
2538
|
}
|
|
2652
2539
|
}
|
|
2653
|
-
async
|
|
2540
|
+
async listScoresByEntityId({
|
|
2654
2541
|
entityId,
|
|
2655
2542
|
entityType,
|
|
2656
2543
|
pagination
|
|
@@ -2663,38 +2550,43 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2663
2550
|
`SELECT COUNT(*) as count FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName(this.schema) })} WHERE [entityId] = @p1 AND [entityType] = @p2`
|
|
2664
2551
|
);
|
|
2665
2552
|
const total = totalResult.recordset[0]?.count || 0;
|
|
2553
|
+
const { page, perPage: perPageInput } = pagination;
|
|
2554
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
2555
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2666
2556
|
if (total === 0) {
|
|
2667
2557
|
return {
|
|
2668
2558
|
pagination: {
|
|
2669
2559
|
total: 0,
|
|
2670
|
-
page
|
|
2671
|
-
perPage:
|
|
2560
|
+
page,
|
|
2561
|
+
perPage: perPageForResponse,
|
|
2672
2562
|
hasMore: false
|
|
2673
2563
|
},
|
|
2674
2564
|
scores: []
|
|
2675
2565
|
};
|
|
2676
2566
|
}
|
|
2567
|
+
const limitValue = perPageInput === false ? total : perPage;
|
|
2568
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
2677
2569
|
const dataRequest = this.pool.request();
|
|
2678
2570
|
dataRequest.input("p1", entityId);
|
|
2679
2571
|
dataRequest.input("p2", entityType);
|
|
2680
|
-
dataRequest.input("p3",
|
|
2681
|
-
dataRequest.input("p4",
|
|
2572
|
+
dataRequest.input("p3", limitValue);
|
|
2573
|
+
dataRequest.input("p4", start);
|
|
2682
2574
|
const result = await dataRequest.query(
|
|
2683
2575
|
`SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName(this.schema) })} WHERE [entityId] = @p1 AND [entityType] = @p2 ORDER BY [createdAt] DESC OFFSET @p4 ROWS FETCH NEXT @p3 ROWS ONLY`
|
|
2684
2576
|
);
|
|
2685
2577
|
return {
|
|
2686
2578
|
pagination: {
|
|
2687
2579
|
total: Number(total),
|
|
2688
|
-
page
|
|
2689
|
-
perPage:
|
|
2690
|
-
hasMore:
|
|
2580
|
+
page,
|
|
2581
|
+
perPage: perPageForResponse,
|
|
2582
|
+
hasMore: end < total
|
|
2691
2583
|
},
|
|
2692
2584
|
scores: result.recordset.map((row) => transformScoreRow(row))
|
|
2693
2585
|
};
|
|
2694
2586
|
} catch (error$1) {
|
|
2695
2587
|
throw new error.MastraError(
|
|
2696
2588
|
{
|
|
2697
|
-
id: "
|
|
2589
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_SCORES_BY_ENTITY_ID", "FAILED"),
|
|
2698
2590
|
domain: error.ErrorDomain.STORAGE,
|
|
2699
2591
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2700
2592
|
details: { entityId, entityType }
|
|
@@ -2703,7 +2595,7 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2703
2595
|
);
|
|
2704
2596
|
}
|
|
2705
2597
|
}
|
|
2706
|
-
async
|
|
2598
|
+
async listScoresBySpan({
|
|
2707
2599
|
traceId,
|
|
2708
2600
|
spanId,
|
|
2709
2601
|
pagination
|
|
@@ -2716,39 +2608,43 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2716
2608
|
`SELECT COUNT(*) as count FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName(this.schema) })} WHERE [traceId] = @p1 AND [spanId] = @p2`
|
|
2717
2609
|
);
|
|
2718
2610
|
const total = totalResult.recordset[0]?.count || 0;
|
|
2611
|
+
const { page, perPage: perPageInput } = pagination;
|
|
2612
|
+
const perPage = storage.normalizePerPage(perPageInput, 100);
|
|
2613
|
+
const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
|
|
2719
2614
|
if (total === 0) {
|
|
2720
2615
|
return {
|
|
2721
2616
|
pagination: {
|
|
2722
2617
|
total: 0,
|
|
2723
|
-
page
|
|
2724
|
-
perPage:
|
|
2618
|
+
page,
|
|
2619
|
+
perPage: perPageForResponse,
|
|
2725
2620
|
hasMore: false
|
|
2726
2621
|
},
|
|
2727
2622
|
scores: []
|
|
2728
2623
|
};
|
|
2729
2624
|
}
|
|
2730
|
-
const
|
|
2625
|
+
const limitValue = perPageInput === false ? total : perPage;
|
|
2626
|
+
const end = perPageInput === false ? total : start + perPage;
|
|
2731
2627
|
const dataRequest = this.pool.request();
|
|
2732
2628
|
dataRequest.input("p1", traceId);
|
|
2733
2629
|
dataRequest.input("p2", spanId);
|
|
2734
|
-
dataRequest.input("p3",
|
|
2735
|
-
dataRequest.input("p4",
|
|
2630
|
+
dataRequest.input("p3", limitValue);
|
|
2631
|
+
dataRequest.input("p4", start);
|
|
2736
2632
|
const result = await dataRequest.query(
|
|
2737
2633
|
`SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName(this.schema) })} WHERE [traceId] = @p1 AND [spanId] = @p2 ORDER BY [createdAt] DESC OFFSET @p4 ROWS FETCH NEXT @p3 ROWS ONLY`
|
|
2738
2634
|
);
|
|
2739
2635
|
return {
|
|
2740
2636
|
pagination: {
|
|
2741
2637
|
total: Number(total),
|
|
2742
|
-
page
|
|
2743
|
-
perPage:
|
|
2744
|
-
hasMore:
|
|
2638
|
+
page,
|
|
2639
|
+
perPage: perPageForResponse,
|
|
2640
|
+
hasMore: end < total
|
|
2745
2641
|
},
|
|
2746
|
-
scores: result.recordset.
|
|
2642
|
+
scores: result.recordset.map((row) => transformScoreRow(row))
|
|
2747
2643
|
};
|
|
2748
2644
|
} catch (error$1) {
|
|
2749
2645
|
throw new error.MastraError(
|
|
2750
2646
|
{
|
|
2751
|
-
id: "
|
|
2647
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_SCORES_BY_SPAN", "FAILED"),
|
|
2752
2648
|
domain: error.ErrorDomain.STORAGE,
|
|
2753
2649
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2754
2650
|
details: { traceId, spanId }
|
|
@@ -2758,173 +2654,6 @@ var ScoresMSSQL = class extends storage.ScoresStorage {
|
|
|
2758
2654
|
}
|
|
2759
2655
|
}
|
|
2760
2656
|
};
|
|
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
|
-
};
|
|
2928
2657
|
var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
2929
2658
|
pool;
|
|
2930
2659
|
operations;
|
|
@@ -2962,13 +2691,13 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
2962
2691
|
runId,
|
|
2963
2692
|
stepId,
|
|
2964
2693
|
result,
|
|
2965
|
-
|
|
2694
|
+
requestContext
|
|
2966
2695
|
}) {
|
|
2967
2696
|
const table = getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName(this.schema) });
|
|
2968
2697
|
const transaction = this.pool.transaction();
|
|
2969
2698
|
try {
|
|
2970
2699
|
await transaction.begin();
|
|
2971
|
-
const selectRequest = new
|
|
2700
|
+
const selectRequest = new sql2__default.default.Request(transaction);
|
|
2972
2701
|
selectRequest.input("workflow_name", workflowName);
|
|
2973
2702
|
selectRequest.input("run_id", runId);
|
|
2974
2703
|
const existingSnapshotResult = await selectRequest.query(
|
|
@@ -2979,28 +2708,29 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
2979
2708
|
snapshot = {
|
|
2980
2709
|
context: {},
|
|
2981
2710
|
activePaths: [],
|
|
2711
|
+
activeStepsPath: {},
|
|
2982
2712
|
timestamp: Date.now(),
|
|
2983
2713
|
suspendedPaths: {},
|
|
2984
2714
|
resumeLabels: {},
|
|
2985
2715
|
serializedStepGraph: [],
|
|
2716
|
+
status: "pending",
|
|
2986
2717
|
value: {},
|
|
2987
2718
|
waitingPaths: {},
|
|
2988
|
-
status: "pending",
|
|
2989
2719
|
runId,
|
|
2990
|
-
|
|
2720
|
+
requestContext: {}
|
|
2991
2721
|
};
|
|
2992
2722
|
} else {
|
|
2993
2723
|
const existingSnapshot = existingSnapshotResult.recordset[0].snapshot;
|
|
2994
2724
|
snapshot = typeof existingSnapshot === "string" ? JSON.parse(existingSnapshot) : existingSnapshot;
|
|
2995
2725
|
}
|
|
2996
2726
|
snapshot.context[stepId] = result;
|
|
2997
|
-
snapshot.
|
|
2998
|
-
const upsertReq = new
|
|
2727
|
+
snapshot.requestContext = { ...snapshot.requestContext, ...requestContext };
|
|
2728
|
+
const upsertReq = new sql2__default.default.Request(transaction);
|
|
2999
2729
|
upsertReq.input("workflow_name", workflowName);
|
|
3000
2730
|
upsertReq.input("run_id", runId);
|
|
3001
2731
|
upsertReq.input("snapshot", JSON.stringify(snapshot));
|
|
3002
|
-
upsertReq.input("createdAt",
|
|
3003
|
-
upsertReq.input("updatedAt",
|
|
2732
|
+
upsertReq.input("createdAt", sql2__default.default.DateTime2, /* @__PURE__ */ new Date());
|
|
2733
|
+
upsertReq.input("updatedAt", sql2__default.default.DateTime2, /* @__PURE__ */ new Date());
|
|
3004
2734
|
await upsertReq.query(
|
|
3005
2735
|
`MERGE ${table} AS target
|
|
3006
2736
|
USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
|
|
@@ -3018,7 +2748,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3018
2748
|
}
|
|
3019
2749
|
throw new error.MastraError(
|
|
3020
2750
|
{
|
|
3021
|
-
id: "
|
|
2751
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_WORKFLOW_RESULTS", "FAILED"),
|
|
3022
2752
|
domain: error.ErrorDomain.STORAGE,
|
|
3023
2753
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3024
2754
|
details: {
|
|
@@ -3040,7 +2770,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3040
2770
|
const transaction = this.pool.transaction();
|
|
3041
2771
|
try {
|
|
3042
2772
|
await transaction.begin();
|
|
3043
|
-
const selectRequest = new
|
|
2773
|
+
const selectRequest = new sql2__default.default.Request(transaction);
|
|
3044
2774
|
selectRequest.input("workflow_name", workflowName);
|
|
3045
2775
|
selectRequest.input("run_id", runId);
|
|
3046
2776
|
const existingSnapshotResult = await selectRequest.query(
|
|
@@ -3056,7 +2786,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3056
2786
|
await transaction.rollback();
|
|
3057
2787
|
throw new error.MastraError(
|
|
3058
2788
|
{
|
|
3059
|
-
id: "
|
|
2789
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_WORKFLOW_STATE", "SNAPSHOT_NOT_FOUND"),
|
|
3060
2790
|
domain: error.ErrorDomain.STORAGE,
|
|
3061
2791
|
category: error.ErrorCategory.SYSTEM,
|
|
3062
2792
|
details: {
|
|
@@ -3068,11 +2798,11 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3068
2798
|
);
|
|
3069
2799
|
}
|
|
3070
2800
|
const updatedSnapshot = { ...snapshot, ...opts };
|
|
3071
|
-
const updateRequest = new
|
|
2801
|
+
const updateRequest = new sql2__default.default.Request(transaction);
|
|
3072
2802
|
updateRequest.input("snapshot", JSON.stringify(updatedSnapshot));
|
|
3073
2803
|
updateRequest.input("workflow_name", workflowName);
|
|
3074
2804
|
updateRequest.input("run_id", runId);
|
|
3075
|
-
updateRequest.input("updatedAt",
|
|
2805
|
+
updateRequest.input("updatedAt", sql2__default.default.DateTime2, /* @__PURE__ */ new Date());
|
|
3076
2806
|
await updateRequest.query(
|
|
3077
2807
|
`UPDATE ${table} SET snapshot = @snapshot, [updatedAt] = @updatedAt WHERE workflow_name = @workflow_name AND run_id = @run_id`
|
|
3078
2808
|
);
|
|
@@ -3083,9 +2813,10 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3083
2813
|
await transaction.rollback();
|
|
3084
2814
|
} catch {
|
|
3085
2815
|
}
|
|
2816
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
3086
2817
|
throw new error.MastraError(
|
|
3087
2818
|
{
|
|
3088
|
-
id: "
|
|
2819
|
+
id: storage.createStorageErrorId("MSSQL", "UPDATE_WORKFLOW_STATE", "FAILED"),
|
|
3089
2820
|
domain: error.ErrorDomain.STORAGE,
|
|
3090
2821
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3091
2822
|
details: {
|
|
@@ -3111,8 +2842,8 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3111
2842
|
request.input("run_id", runId);
|
|
3112
2843
|
request.input("resourceId", resourceId);
|
|
3113
2844
|
request.input("snapshot", JSON.stringify(snapshot));
|
|
3114
|
-
request.input("createdAt",
|
|
3115
|
-
request.input("updatedAt",
|
|
2845
|
+
request.input("createdAt", sql2__default.default.DateTime2, new Date(now));
|
|
2846
|
+
request.input("updatedAt", sql2__default.default.DateTime2, new Date(now));
|
|
3116
2847
|
const mergeSql = `MERGE INTO ${table} AS target
|
|
3117
2848
|
USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
|
|
3118
2849
|
ON target.workflow_name = src.workflow_name AND target.run_id = src.run_id
|
|
@@ -3126,7 +2857,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3126
2857
|
} catch (error$1) {
|
|
3127
2858
|
throw new error.MastraError(
|
|
3128
2859
|
{
|
|
3129
|
-
id: "
|
|
2860
|
+
id: storage.createStorageErrorId("MSSQL", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
3130
2861
|
domain: error.ErrorDomain.STORAGE,
|
|
3131
2862
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3132
2863
|
details: {
|
|
@@ -3157,7 +2888,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3157
2888
|
} catch (error$1) {
|
|
3158
2889
|
throw new error.MastraError(
|
|
3159
2890
|
{
|
|
3160
|
-
id: "
|
|
2891
|
+
id: storage.createStorageErrorId("MSSQL", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
3161
2892
|
domain: error.ErrorDomain.STORAGE,
|
|
3162
2893
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3163
2894
|
details: {
|
|
@@ -3197,7 +2928,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3197
2928
|
} catch (error$1) {
|
|
3198
2929
|
throw new error.MastraError(
|
|
3199
2930
|
{
|
|
3200
|
-
id: "
|
|
2931
|
+
id: storage.createStorageErrorId("MSSQL", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
3201
2932
|
domain: error.ErrorDomain.STORAGE,
|
|
3202
2933
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3203
2934
|
details: {
|
|
@@ -3209,13 +2940,14 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3209
2940
|
);
|
|
3210
2941
|
}
|
|
3211
2942
|
}
|
|
3212
|
-
async
|
|
2943
|
+
async listWorkflowRuns({
|
|
3213
2944
|
workflowName,
|
|
3214
2945
|
fromDate,
|
|
3215
2946
|
toDate,
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
resourceId
|
|
2947
|
+
page,
|
|
2948
|
+
perPage,
|
|
2949
|
+
resourceId,
|
|
2950
|
+
status
|
|
3219
2951
|
} = {}) {
|
|
3220
2952
|
try {
|
|
3221
2953
|
const conditions = [];
|
|
@@ -3224,6 +2956,10 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3224
2956
|
conditions.push(`[workflow_name] = @workflowName`);
|
|
3225
2957
|
paramMap["workflowName"] = workflowName;
|
|
3226
2958
|
}
|
|
2959
|
+
if (status) {
|
|
2960
|
+
conditions.push(`JSON_VALUE([snapshot], '$.status') = @status`);
|
|
2961
|
+
paramMap["status"] = status;
|
|
2962
|
+
}
|
|
3227
2963
|
if (resourceId) {
|
|
3228
2964
|
const hasResourceId = await this.operations.hasColumn(storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId");
|
|
3229
2965
|
if (hasResourceId) {
|
|
@@ -3247,20 +2983,23 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3247
2983
|
const request = this.pool.request();
|
|
3248
2984
|
Object.entries(paramMap).forEach(([key, value]) => {
|
|
3249
2985
|
if (value instanceof Date) {
|
|
3250
|
-
request.input(key,
|
|
2986
|
+
request.input(key, sql2__default.default.DateTime, value);
|
|
3251
2987
|
} else {
|
|
3252
2988
|
request.input(key, value);
|
|
3253
2989
|
}
|
|
3254
2990
|
});
|
|
3255
|
-
|
|
2991
|
+
const usePagination = typeof perPage === "number" && typeof page === "number";
|
|
2992
|
+
if (usePagination) {
|
|
3256
2993
|
const countQuery = `SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`;
|
|
3257
2994
|
const countResult = await request.query(countQuery);
|
|
3258
2995
|
total = Number(countResult.recordset[0]?.count || 0);
|
|
3259
2996
|
}
|
|
3260
2997
|
let query = `SELECT * FROM ${tableName} ${whereClause} ORDER BY [seq_id] DESC`;
|
|
3261
|
-
if (
|
|
3262
|
-
|
|
3263
|
-
|
|
2998
|
+
if (usePagination) {
|
|
2999
|
+
const normalizedPerPage = storage.normalizePerPage(perPage, Number.MAX_SAFE_INTEGER);
|
|
3000
|
+
const offset = page * normalizedPerPage;
|
|
3001
|
+
query += ` OFFSET @offset ROWS FETCH NEXT @perPage ROWS ONLY`;
|
|
3002
|
+
request.input("perPage", normalizedPerPage);
|
|
3264
3003
|
request.input("offset", offset);
|
|
3265
3004
|
}
|
|
3266
3005
|
const result = await request.query(query);
|
|
@@ -3269,7 +3008,7 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
|
|
|
3269
3008
|
} catch (error$1) {
|
|
3270
3009
|
throw new error.MastraError(
|
|
3271
3010
|
{
|
|
3272
|
-
id: "
|
|
3011
|
+
id: storage.createStorageErrorId("MSSQL", "LIST_WORKFLOW_RUNS", "FAILED"),
|
|
3273
3012
|
domain: error.ErrorDomain.STORAGE,
|
|
3274
3013
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3275
3014
|
details: {
|
|
@@ -3289,7 +3028,10 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3289
3028
|
isConnected = null;
|
|
3290
3029
|
stores;
|
|
3291
3030
|
constructor(config) {
|
|
3292
|
-
|
|
3031
|
+
if (!config.id || typeof config.id !== "string" || config.id.trim() === "") {
|
|
3032
|
+
throw new Error("MSSQLStore: id must be provided and cannot be empty.");
|
|
3033
|
+
}
|
|
3034
|
+
super({ id: config.id, name: "MSSQLStore", disableInit: config.disableInit });
|
|
3293
3035
|
try {
|
|
3294
3036
|
if ("connectionString" in config) {
|
|
3295
3037
|
if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
|
|
@@ -3304,7 +3046,7 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3304
3046
|
}
|
|
3305
3047
|
}
|
|
3306
3048
|
this.schema = config.schemaName || "dbo";
|
|
3307
|
-
this.pool = "connectionString" in config ? new
|
|
3049
|
+
this.pool = "connectionString" in config ? new sql2__default.default.ConnectionPool(config.connectionString) : new sql2__default.default.ConnectionPool({
|
|
3308
3050
|
server: config.server,
|
|
3309
3051
|
database: config.database,
|
|
3310
3052
|
user: config.user,
|
|
@@ -3312,26 +3054,22 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3312
3054
|
port: config.port,
|
|
3313
3055
|
options: config.options || { encrypt: true, trustServerCertificate: true }
|
|
3314
3056
|
});
|
|
3315
|
-
const legacyEvals = new LegacyEvalsMSSQL({ pool: this.pool, schema: this.schema });
|
|
3316
3057
|
const operations = new StoreOperationsMSSQL({ pool: this.pool, schemaName: this.schema });
|
|
3317
3058
|
const scores = new ScoresMSSQL({ pool: this.pool, operations, schema: this.schema });
|
|
3318
|
-
const traces = new TracesMSSQL({ pool: this.pool, operations, schema: this.schema });
|
|
3319
3059
|
const workflows = new WorkflowsMSSQL({ pool: this.pool, operations, schema: this.schema });
|
|
3320
3060
|
const memory = new MemoryMSSQL({ pool: this.pool, schema: this.schema, operations });
|
|
3321
3061
|
const observability = new ObservabilityMSSQL({ pool: this.pool, operations, schema: this.schema });
|
|
3322
3062
|
this.stores = {
|
|
3323
3063
|
operations,
|
|
3324
3064
|
scores,
|
|
3325
|
-
traces,
|
|
3326
3065
|
workflows,
|
|
3327
|
-
legacyEvals,
|
|
3328
3066
|
memory,
|
|
3329
3067
|
observability
|
|
3330
3068
|
};
|
|
3331
3069
|
} catch (e) {
|
|
3332
3070
|
throw new error.MastraError(
|
|
3333
3071
|
{
|
|
3334
|
-
id: "
|
|
3072
|
+
id: storage.createStorageErrorId("MSSQL", "INITIALIZATION", "FAILED"),
|
|
3335
3073
|
domain: error.ErrorDomain.STORAGE,
|
|
3336
3074
|
category: error.ErrorCategory.USER
|
|
3337
3075
|
},
|
|
@@ -3355,7 +3093,7 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3355
3093
|
this.isConnected = null;
|
|
3356
3094
|
throw new error.MastraError(
|
|
3357
3095
|
{
|
|
3358
|
-
id: "
|
|
3096
|
+
id: storage.createStorageErrorId("MSSQL", "INIT", "FAILED"),
|
|
3359
3097
|
domain: error.ErrorDomain.STORAGE,
|
|
3360
3098
|
category: error.ErrorCategory.THIRD_PARTY
|
|
3361
3099
|
},
|
|
@@ -3378,30 +3116,11 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3378
3116
|
hasColumn: true,
|
|
3379
3117
|
createTable: true,
|
|
3380
3118
|
deleteMessages: true,
|
|
3381
|
-
|
|
3382
|
-
|
|
3119
|
+
listScoresBySpan: true,
|
|
3120
|
+
observabilityInstance: true,
|
|
3383
3121
|
indexManagement: true
|
|
3384
3122
|
};
|
|
3385
3123
|
}
|
|
3386
|
-
/** @deprecated use getEvals instead */
|
|
3387
|
-
async getEvalsByAgentName(agentName, type) {
|
|
3388
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
3389
|
-
}
|
|
3390
|
-
async getEvals(options = {}) {
|
|
3391
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
3392
|
-
}
|
|
3393
|
-
/**
|
|
3394
|
-
* @deprecated use getTracesPaginated instead
|
|
3395
|
-
*/
|
|
3396
|
-
async getTraces(args) {
|
|
3397
|
-
return this.stores.traces.getTraces(args);
|
|
3398
|
-
}
|
|
3399
|
-
async getTracesPaginated(args) {
|
|
3400
|
-
return this.stores.traces.getTracesPaginated(args);
|
|
3401
|
-
}
|
|
3402
|
-
async batchTraceInsert({ records }) {
|
|
3403
|
-
return this.stores.traces.batchTraceInsert({ records });
|
|
3404
|
-
}
|
|
3405
3124
|
async createTable({
|
|
3406
3125
|
tableName,
|
|
3407
3126
|
schema
|
|
@@ -3436,15 +3155,6 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3436
3155
|
async getThreadById({ threadId }) {
|
|
3437
3156
|
return this.stores.memory.getThreadById({ threadId });
|
|
3438
3157
|
}
|
|
3439
|
-
/**
|
|
3440
|
-
* @deprecated use getThreadsByResourceIdPaginated instead
|
|
3441
|
-
*/
|
|
3442
|
-
async getThreadsByResourceId(args) {
|
|
3443
|
-
return this.stores.memory.getThreadsByResourceId(args);
|
|
3444
|
-
}
|
|
3445
|
-
async getThreadsByResourceIdPaginated(args) {
|
|
3446
|
-
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
3447
|
-
}
|
|
3448
3158
|
async saveThread({ thread }) {
|
|
3449
3159
|
return this.stores.memory.saveThread({ thread });
|
|
3450
3160
|
}
|
|
@@ -3458,17 +3168,8 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3458
3168
|
async deleteThread({ threadId }) {
|
|
3459
3169
|
return this.stores.memory.deleteThread({ threadId });
|
|
3460
3170
|
}
|
|
3461
|
-
async
|
|
3462
|
-
return this.stores.memory.
|
|
3463
|
-
}
|
|
3464
|
-
async getMessagesById({
|
|
3465
|
-
messageIds,
|
|
3466
|
-
format
|
|
3467
|
-
}) {
|
|
3468
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3469
|
-
}
|
|
3470
|
-
async getMessagesPaginated(args) {
|
|
3471
|
-
return this.stores.memory.getMessagesPaginated(args);
|
|
3171
|
+
async listMessagesById({ messageIds }) {
|
|
3172
|
+
return this.stores.memory.listMessagesById({ messageIds });
|
|
3472
3173
|
}
|
|
3473
3174
|
async saveMessages(args) {
|
|
3474
3175
|
return this.stores.memory.saveMessages(args);
|
|
@@ -3502,9 +3203,9 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3502
3203
|
runId,
|
|
3503
3204
|
stepId,
|
|
3504
3205
|
result,
|
|
3505
|
-
|
|
3206
|
+
requestContext
|
|
3506
3207
|
}) {
|
|
3507
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result,
|
|
3208
|
+
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, requestContext });
|
|
3508
3209
|
}
|
|
3509
3210
|
async updateWorkflowState({
|
|
3510
3211
|
workflowName,
|
|
@@ -3527,15 +3228,8 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3527
3228
|
}) {
|
|
3528
3229
|
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
3529
3230
|
}
|
|
3530
|
-
async
|
|
3531
|
-
|
|
3532
|
-
fromDate,
|
|
3533
|
-
toDate,
|
|
3534
|
-
limit,
|
|
3535
|
-
offset,
|
|
3536
|
-
resourceId
|
|
3537
|
-
} = {}) {
|
|
3538
|
-
return this.stores.workflows.getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId });
|
|
3231
|
+
async listWorkflowRuns(args = {}) {
|
|
3232
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
3539
3233
|
}
|
|
3540
3234
|
async getWorkflowRunById({
|
|
3541
3235
|
runId,
|
|
@@ -3562,12 +3256,12 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3562
3256
|
return this.stores.operations.dropIndex(indexName);
|
|
3563
3257
|
}
|
|
3564
3258
|
/**
|
|
3565
|
-
*
|
|
3259
|
+
* Tracing / Observability
|
|
3566
3260
|
*/
|
|
3567
3261
|
getObservabilityStore() {
|
|
3568
3262
|
if (!this.stores.observability) {
|
|
3569
3263
|
throw new error.MastraError({
|
|
3570
|
-
id: "
|
|
3264
|
+
id: storage.createStorageErrorId("MSSQL", "OBSERVABILITY", "NOT_INITIALIZED"),
|
|
3571
3265
|
domain: error.ErrorDomain.STORAGE,
|
|
3572
3266
|
category: error.ErrorCategory.SYSTEM,
|
|
3573
3267
|
text: "Observability storage is not initialized"
|
|
@@ -3575,30 +3269,30 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3575
3269
|
}
|
|
3576
3270
|
return this.stores.observability;
|
|
3577
3271
|
}
|
|
3578
|
-
async
|
|
3579
|
-
return this.getObservabilityStore().
|
|
3272
|
+
async createSpan(span) {
|
|
3273
|
+
return this.getObservabilityStore().createSpan(span);
|
|
3580
3274
|
}
|
|
3581
|
-
async
|
|
3275
|
+
async updateSpan({
|
|
3582
3276
|
spanId,
|
|
3583
3277
|
traceId,
|
|
3584
3278
|
updates
|
|
3585
3279
|
}) {
|
|
3586
|
-
return this.getObservabilityStore().
|
|
3280
|
+
return this.getObservabilityStore().updateSpan({ spanId, traceId, updates });
|
|
3587
3281
|
}
|
|
3588
|
-
async
|
|
3589
|
-
return this.getObservabilityStore().
|
|
3282
|
+
async getTrace(traceId) {
|
|
3283
|
+
return this.getObservabilityStore().getTrace(traceId);
|
|
3590
3284
|
}
|
|
3591
|
-
async
|
|
3592
|
-
return this.getObservabilityStore().
|
|
3285
|
+
async getTracesPaginated(args) {
|
|
3286
|
+
return this.getObservabilityStore().getTracesPaginated(args);
|
|
3593
3287
|
}
|
|
3594
|
-
async
|
|
3595
|
-
return this.getObservabilityStore().
|
|
3288
|
+
async batchCreateSpans(args) {
|
|
3289
|
+
return this.getObservabilityStore().batchCreateSpans(args);
|
|
3596
3290
|
}
|
|
3597
|
-
async
|
|
3598
|
-
return this.getObservabilityStore().
|
|
3291
|
+
async batchUpdateSpans(args) {
|
|
3292
|
+
return this.getObservabilityStore().batchUpdateSpans(args);
|
|
3599
3293
|
}
|
|
3600
|
-
async
|
|
3601
|
-
return this.getObservabilityStore().
|
|
3294
|
+
async batchDeleteTraces(args) {
|
|
3295
|
+
return this.getObservabilityStore().batchDeleteTraces(args);
|
|
3602
3296
|
}
|
|
3603
3297
|
/**
|
|
3604
3298
|
* Scorers
|
|
@@ -3606,14 +3300,14 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3606
3300
|
async getScoreById({ id: _id }) {
|
|
3607
3301
|
return this.stores.scores.getScoreById({ id: _id });
|
|
3608
3302
|
}
|
|
3609
|
-
async
|
|
3303
|
+
async listScoresByScorerId({
|
|
3610
3304
|
scorerId: _scorerId,
|
|
3611
3305
|
pagination: _pagination,
|
|
3612
3306
|
entityId: _entityId,
|
|
3613
3307
|
entityType: _entityType,
|
|
3614
3308
|
source: _source
|
|
3615
3309
|
}) {
|
|
3616
|
-
return this.stores.scores.
|
|
3310
|
+
return this.stores.scores.listScoresByScorerId({
|
|
3617
3311
|
scorerId: _scorerId,
|
|
3618
3312
|
pagination: _pagination,
|
|
3619
3313
|
entityId: _entityId,
|
|
@@ -3621,32 +3315,32 @@ var MSSQLStore = class extends storage.MastraStorage {
|
|
|
3621
3315
|
source: _source
|
|
3622
3316
|
});
|
|
3623
3317
|
}
|
|
3624
|
-
async saveScore(
|
|
3625
|
-
return this.stores.scores.saveScore(
|
|
3318
|
+
async saveScore(score) {
|
|
3319
|
+
return this.stores.scores.saveScore(score);
|
|
3626
3320
|
}
|
|
3627
|
-
async
|
|
3321
|
+
async listScoresByRunId({
|
|
3628
3322
|
runId: _runId,
|
|
3629
3323
|
pagination: _pagination
|
|
3630
3324
|
}) {
|
|
3631
|
-
return this.stores.scores.
|
|
3325
|
+
return this.stores.scores.listScoresByRunId({ runId: _runId, pagination: _pagination });
|
|
3632
3326
|
}
|
|
3633
|
-
async
|
|
3327
|
+
async listScoresByEntityId({
|
|
3634
3328
|
entityId: _entityId,
|
|
3635
3329
|
entityType: _entityType,
|
|
3636
3330
|
pagination: _pagination
|
|
3637
3331
|
}) {
|
|
3638
|
-
return this.stores.scores.
|
|
3332
|
+
return this.stores.scores.listScoresByEntityId({
|
|
3639
3333
|
entityId: _entityId,
|
|
3640
3334
|
entityType: _entityType,
|
|
3641
3335
|
pagination: _pagination
|
|
3642
3336
|
});
|
|
3643
3337
|
}
|
|
3644
|
-
async
|
|
3338
|
+
async listScoresBySpan({
|
|
3645
3339
|
traceId,
|
|
3646
3340
|
spanId,
|
|
3647
3341
|
pagination: _pagination
|
|
3648
3342
|
}) {
|
|
3649
|
-
return this.stores.scores.
|
|
3343
|
+
return this.stores.scores.listScoresBySpan({ traceId, spanId, pagination: _pagination });
|
|
3650
3344
|
}
|
|
3651
3345
|
};
|
|
3652
3346
|
|