@mastra/mssql 0.0.0-fix-9244-clickhouse-metadata-20251105010900 → 0.0.0-fix-ai-sdk-dependency-20251124104209
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 +396 -4
- package/README.md +21 -13
- package/dist/index.cjs +158 -186
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +159 -187
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -7
- 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/workflows/index.d.ts +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +16 -21
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +9 -7
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
2
|
-
import { MastraStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, TABLE_SCHEMAS, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_SCORERS,
|
|
2
|
+
import { MastraStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, TABLE_SCHEMAS, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_SCORERS, TABLE_SPANS, ScoresStorage, normalizePerPage, calculatePagination, WorkflowsStorage, MemoryStorage, TABLE_RESOURCES, ObservabilityStorage, safelyParseJSON } from '@mastra/core/storage';
|
|
3
3
|
import sql2 from 'mssql';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
5
|
import { parseSqlIdentifier } from '@mastra/core/utils';
|
|
@@ -150,6 +150,18 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
150
150
|
}
|
|
151
151
|
async listThreadsByResourceId(args) {
|
|
152
152
|
const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
|
|
153
|
+
if (page < 0) {
|
|
154
|
+
throw new MastraError({
|
|
155
|
+
id: "MASTRA_STORAGE_MSSQL_STORE_INVALID_PAGE",
|
|
156
|
+
domain: ErrorDomain.STORAGE,
|
|
157
|
+
category: ErrorCategory.USER,
|
|
158
|
+
text: "Page number must be non-negative",
|
|
159
|
+
details: {
|
|
160
|
+
resourceId,
|
|
161
|
+
page
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
153
165
|
const perPage = normalizePerPage(perPageInput, 100);
|
|
154
166
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
155
167
|
const { field, direction } = this.parseOrderBy(orderBy);
|
|
@@ -371,10 +383,9 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
371
383
|
}
|
|
372
384
|
async _getIncludedMessages({
|
|
373
385
|
threadId,
|
|
374
|
-
|
|
386
|
+
include
|
|
375
387
|
}) {
|
|
376
388
|
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
377
|
-
const include = selectBy?.include;
|
|
378
389
|
if (!include) return null;
|
|
379
390
|
const unionQueries = [];
|
|
380
391
|
const paramValues = [];
|
|
@@ -446,75 +457,6 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
446
457
|
});
|
|
447
458
|
return dedupedRows;
|
|
448
459
|
}
|
|
449
|
-
/**
|
|
450
|
-
* @deprecated use listMessages instead
|
|
451
|
-
*/
|
|
452
|
-
async getMessages(args) {
|
|
453
|
-
const { threadId, resourceId, selectBy } = args;
|
|
454
|
-
const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
|
|
455
|
-
const orderByStatement = `ORDER BY [seq_id] DESC`;
|
|
456
|
-
const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
|
|
457
|
-
try {
|
|
458
|
-
if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
|
|
459
|
-
let rows = [];
|
|
460
|
-
const include = selectBy?.include || [];
|
|
461
|
-
if (include?.length) {
|
|
462
|
-
const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
|
|
463
|
-
if (includeMessages) {
|
|
464
|
-
rows.push(...includeMessages);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
const excludeIds = rows.map((m) => m.id).filter(Boolean);
|
|
468
|
-
let query = `${selectStatement} FROM ${getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} WHERE [thread_id] = @threadId`;
|
|
469
|
-
const request = this.pool.request();
|
|
470
|
-
request.input("threadId", threadId);
|
|
471
|
-
if (excludeIds.length > 0) {
|
|
472
|
-
const excludeParams = excludeIds.map((_, idx) => `@id${idx}`);
|
|
473
|
-
query += ` AND id NOT IN (${excludeParams.join(", ")})`;
|
|
474
|
-
excludeIds.forEach((id, idx) => {
|
|
475
|
-
request.input(`id${idx}`, id);
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
query += ` ${orderByStatement} OFFSET 0 ROWS FETCH NEXT @limit ROWS ONLY`;
|
|
479
|
-
request.input("limit", limit);
|
|
480
|
-
const result = await request.query(query);
|
|
481
|
-
const remainingRows = result.recordset || [];
|
|
482
|
-
rows.push(...remainingRows);
|
|
483
|
-
rows.sort((a, b) => {
|
|
484
|
-
const timeDiff = a.seq_id - b.seq_id;
|
|
485
|
-
return timeDiff;
|
|
486
|
-
});
|
|
487
|
-
const messagesWithParsedContent = rows.map((row) => {
|
|
488
|
-
if (typeof row.content === "string") {
|
|
489
|
-
try {
|
|
490
|
-
return { ...row, content: JSON.parse(row.content) };
|
|
491
|
-
} catch {
|
|
492
|
-
return row;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
return row;
|
|
496
|
-
});
|
|
497
|
-
const cleanMessages = messagesWithParsedContent.map(({ seq_id, ...rest }) => rest);
|
|
498
|
-
const list = new MessageList().add(cleanMessages, "memory");
|
|
499
|
-
return { messages: list.get.all.db() };
|
|
500
|
-
} catch (error) {
|
|
501
|
-
const mastraError = new MastraError(
|
|
502
|
-
{
|
|
503
|
-
id: "MASTRA_STORAGE_MSSQL_STORE_GET_MESSAGES_FAILED",
|
|
504
|
-
domain: ErrorDomain.STORAGE,
|
|
505
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
506
|
-
details: {
|
|
507
|
-
threadId,
|
|
508
|
-
resourceId: resourceId ?? ""
|
|
509
|
-
}
|
|
510
|
-
},
|
|
511
|
-
error
|
|
512
|
-
);
|
|
513
|
-
this.logger?.error?.(mastraError.toString());
|
|
514
|
-
this.logger?.trackException?.(mastraError);
|
|
515
|
-
return { messages: [] };
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
460
|
async listMessagesById({ messageIds }) {
|
|
519
461
|
if (messageIds.length === 0) return { messages: [] };
|
|
520
462
|
const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
|
|
@@ -575,43 +517,59 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
575
517
|
new Error("threadId must be a non-empty string")
|
|
576
518
|
);
|
|
577
519
|
}
|
|
520
|
+
if (page < 0) {
|
|
521
|
+
throw new MastraError({
|
|
522
|
+
id: "MASTRA_STORAGE_MSSQL_STORE_INVALID_PAGE",
|
|
523
|
+
domain: ErrorDomain.STORAGE,
|
|
524
|
+
category: ErrorCategory.USER,
|
|
525
|
+
text: "Page number must be non-negative",
|
|
526
|
+
details: {
|
|
527
|
+
threadId,
|
|
528
|
+
page
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
578
532
|
const perPage = normalizePerPage(perPageInput, 40);
|
|
579
533
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
580
534
|
try {
|
|
581
|
-
const { field, direction } = this.parseOrderBy(orderBy);
|
|
582
|
-
const orderByStatement = `ORDER BY [${field}] ${direction}`;
|
|
583
|
-
const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
|
|
535
|
+
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
536
|
+
const orderByStatement = `ORDER BY [${field}] ${direction}, [seq_id] ${direction}`;
|
|
584
537
|
const tableName = getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
|
|
585
|
-
const
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
const whereClause = `WHERE ${conditions.join(" AND ")}`;
|
|
601
|
-
const countQuery = `SELECT COUNT(*) as total FROM ${tableName} ${whereClause}`;
|
|
602
|
-
const countResult = await request.query(countQuery);
|
|
538
|
+
const baseQuery = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId FROM ${tableName}`;
|
|
539
|
+
const filters = {
|
|
540
|
+
thread_id: threadId,
|
|
541
|
+
...resourceId ? { resourceId } : {},
|
|
542
|
+
...buildDateRangeFilter(filter?.dateRange, "createdAt")
|
|
543
|
+
};
|
|
544
|
+
const { sql: actualWhereClause = "", params: whereParams } = prepareWhereClause(
|
|
545
|
+
filters);
|
|
546
|
+
const bindWhereParams = (req) => {
|
|
547
|
+
Object.entries(whereParams).forEach(([paramName, paramValue]) => req.input(paramName, paramValue));
|
|
548
|
+
};
|
|
549
|
+
const countRequest = this.pool.request();
|
|
550
|
+
bindWhereParams(countRequest);
|
|
551
|
+
const countResult = await countRequest.query(`SELECT COUNT(*) as total FROM ${tableName}${actualWhereClause}`);
|
|
603
552
|
const total = parseInt(countResult.recordset[0]?.total, 10) || 0;
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
553
|
+
const fetchBaseMessages = async () => {
|
|
554
|
+
const request = this.pool.request();
|
|
555
|
+
bindWhereParams(request);
|
|
556
|
+
if (perPageInput === false) {
|
|
557
|
+
const result2 = await request.query(`${baseQuery}${actualWhereClause} ${orderByStatement}`);
|
|
558
|
+
return result2.recordset || [];
|
|
559
|
+
}
|
|
560
|
+
request.input("offset", offset);
|
|
561
|
+
request.input("limit", perPage > 2147483647 ? sql2.BigInt : sql2.Int, perPage);
|
|
562
|
+
const result = await request.query(
|
|
563
|
+
`${baseQuery}${actualWhereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`
|
|
564
|
+
);
|
|
565
|
+
return result.recordset || [];
|
|
566
|
+
};
|
|
567
|
+
const baseRows = perPage === 0 ? [] : await fetchBaseMessages();
|
|
568
|
+
const messages = [...baseRows];
|
|
569
|
+
const seqById = /* @__PURE__ */ new Map();
|
|
570
|
+
messages.forEach((msg) => {
|
|
571
|
+
if (typeof msg.seq_id === "number") seqById.set(msg.id, msg.seq_id);
|
|
572
|
+
});
|
|
615
573
|
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
616
574
|
return {
|
|
617
575
|
messages: [],
|
|
@@ -621,29 +579,33 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
621
579
|
hasMore: false
|
|
622
580
|
};
|
|
623
581
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
messageIds.add(includeMsg.id);
|
|
633
|
-
}
|
|
582
|
+
if (include?.length) {
|
|
583
|
+
const messageIds = new Set(messages.map((m) => m.id));
|
|
584
|
+
const includeMessages = await this._getIncludedMessages({ threadId, include });
|
|
585
|
+
includeMessages?.forEach((msg) => {
|
|
586
|
+
if (!messageIds.has(msg.id)) {
|
|
587
|
+
messages.push(msg);
|
|
588
|
+
messageIds.add(msg.id);
|
|
589
|
+
if (typeof msg.seq_id === "number") seqById.set(msg.id, msg.seq_id);
|
|
634
590
|
}
|
|
635
|
-
}
|
|
591
|
+
});
|
|
636
592
|
}
|
|
637
593
|
const parsed = this._parseAndFormatMessages(messages, "v2");
|
|
638
|
-
|
|
639
|
-
finalMessages =
|
|
640
|
-
const
|
|
641
|
-
const
|
|
642
|
-
|
|
594
|
+
const mult = direction === "ASC" ? 1 : -1;
|
|
595
|
+
const finalMessages = parsed.sort((a, b) => {
|
|
596
|
+
const aVal = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
|
|
597
|
+
const bVal = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
|
|
598
|
+
if (aVal == null || bVal == null) {
|
|
599
|
+
return aVal == null && bVal == null ? a.id.localeCompare(b.id) : aVal == null ? 1 : -1;
|
|
600
|
+
}
|
|
601
|
+
const diff = (typeof aVal === "number" && typeof bVal === "number" ? aVal - bVal : String(aVal).localeCompare(String(bVal))) * mult;
|
|
602
|
+
if (diff !== 0) return diff;
|
|
603
|
+
const seqA = seqById.get(a.id);
|
|
604
|
+
const seqB = seqById.get(b.id);
|
|
605
|
+
return seqA != null && seqB != null ? (seqA - seqB) * mult : a.id.localeCompare(b.id);
|
|
643
606
|
});
|
|
644
|
-
const
|
|
645
|
-
const
|
|
646
|
-
const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
607
|
+
const returnedThreadMessageCount = finalMessages.filter((m) => m.threadId === threadId).length;
|
|
608
|
+
const hasMore = perPageInput !== false && returnedThreadMessageCount < total && offset + perPage < total;
|
|
647
609
|
return {
|
|
648
610
|
messages: finalMessages,
|
|
649
611
|
total,
|
|
@@ -1037,13 +999,13 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1037
999
|
this.operations = operations;
|
|
1038
1000
|
this.schema = schema;
|
|
1039
1001
|
}
|
|
1040
|
-
get
|
|
1002
|
+
get tracingStrategy() {
|
|
1041
1003
|
return {
|
|
1042
1004
|
preferred: "batch-with-updates",
|
|
1043
1005
|
supported: ["batch-with-updates", "insert-only"]
|
|
1044
1006
|
};
|
|
1045
1007
|
}
|
|
1046
|
-
async
|
|
1008
|
+
async createSpan(span) {
|
|
1047
1009
|
try {
|
|
1048
1010
|
const startedAt = span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt;
|
|
1049
1011
|
const endedAt = span.endedAt instanceof Date ? span.endedAt.toISOString() : span.endedAt;
|
|
@@ -1053,11 +1015,11 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1053
1015
|
endedAt
|
|
1054
1016
|
// Note: createdAt/updatedAt will be set by default values
|
|
1055
1017
|
};
|
|
1056
|
-
return this.operations.insert({ tableName:
|
|
1018
|
+
return this.operations.insert({ tableName: TABLE_SPANS, record });
|
|
1057
1019
|
} catch (error) {
|
|
1058
1020
|
throw new MastraError(
|
|
1059
1021
|
{
|
|
1060
|
-
id: "
|
|
1022
|
+
id: "MSSQL_STORE_CREATE_SPAN_FAILED",
|
|
1061
1023
|
domain: ErrorDomain.STORAGE,
|
|
1062
1024
|
category: ErrorCategory.USER,
|
|
1063
1025
|
details: {
|
|
@@ -1071,10 +1033,10 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1071
1033
|
);
|
|
1072
1034
|
}
|
|
1073
1035
|
}
|
|
1074
|
-
async
|
|
1036
|
+
async getTrace(traceId) {
|
|
1075
1037
|
try {
|
|
1076
1038
|
const tableName = getTableName({
|
|
1077
|
-
indexName:
|
|
1039
|
+
indexName: TABLE_SPANS,
|
|
1078
1040
|
schemaName: getSchemaName(this.schema)
|
|
1079
1041
|
});
|
|
1080
1042
|
const request = this.pool.request();
|
|
@@ -1095,7 +1057,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1095
1057
|
traceId,
|
|
1096
1058
|
spans: result.recordset.map(
|
|
1097
1059
|
(span) => transformFromSqlRow({
|
|
1098
|
-
tableName:
|
|
1060
|
+
tableName: TABLE_SPANS,
|
|
1099
1061
|
sqlRow: span
|
|
1100
1062
|
})
|
|
1101
1063
|
)
|
|
@@ -1103,7 +1065,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1103
1065
|
} catch (error) {
|
|
1104
1066
|
throw new MastraError(
|
|
1105
1067
|
{
|
|
1106
|
-
id: "
|
|
1068
|
+
id: "MSSQL_STORE_GET_TRACE_FAILED",
|
|
1107
1069
|
domain: ErrorDomain.STORAGE,
|
|
1108
1070
|
category: ErrorCategory.USER,
|
|
1109
1071
|
details: {
|
|
@@ -1114,7 +1076,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1114
1076
|
);
|
|
1115
1077
|
}
|
|
1116
1078
|
}
|
|
1117
|
-
async
|
|
1079
|
+
async updateSpan({
|
|
1118
1080
|
spanId,
|
|
1119
1081
|
traceId,
|
|
1120
1082
|
updates
|
|
@@ -1128,14 +1090,14 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1128
1090
|
data.startedAt = data.startedAt.toISOString();
|
|
1129
1091
|
}
|
|
1130
1092
|
await this.operations.update({
|
|
1131
|
-
tableName:
|
|
1093
|
+
tableName: TABLE_SPANS,
|
|
1132
1094
|
keys: { spanId, traceId },
|
|
1133
1095
|
data
|
|
1134
1096
|
});
|
|
1135
1097
|
} catch (error) {
|
|
1136
1098
|
throw new MastraError(
|
|
1137
1099
|
{
|
|
1138
|
-
id: "
|
|
1100
|
+
id: "MSSQL_STORE_UPDATE_SPAN_FAILED",
|
|
1139
1101
|
domain: ErrorDomain.STORAGE,
|
|
1140
1102
|
category: ErrorCategory.USER,
|
|
1141
1103
|
details: {
|
|
@@ -1147,7 +1109,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1147
1109
|
);
|
|
1148
1110
|
}
|
|
1149
1111
|
}
|
|
1150
|
-
async
|
|
1112
|
+
async getTracesPaginated({
|
|
1151
1113
|
filters,
|
|
1152
1114
|
pagination
|
|
1153
1115
|
}) {
|
|
@@ -1172,7 +1134,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1172
1134
|
name = `agent run: '${entityId}'`;
|
|
1173
1135
|
} else {
|
|
1174
1136
|
const error = new MastraError({
|
|
1175
|
-
id: "
|
|
1137
|
+
id: "MSSQL_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1176
1138
|
domain: ErrorDomain.STORAGE,
|
|
1177
1139
|
category: ErrorCategory.USER,
|
|
1178
1140
|
details: {
|
|
@@ -1191,7 +1153,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1191
1153
|
params[entityParam] = name;
|
|
1192
1154
|
}
|
|
1193
1155
|
const tableName = getTableName({
|
|
1194
|
-
indexName:
|
|
1156
|
+
indexName: TABLE_SPANS,
|
|
1195
1157
|
schemaName: getSchemaName(this.schema)
|
|
1196
1158
|
});
|
|
1197
1159
|
try {
|
|
@@ -1225,7 +1187,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1225
1187
|
);
|
|
1226
1188
|
const spans = dataResult.recordset.map(
|
|
1227
1189
|
(row) => transformFromSqlRow({
|
|
1228
|
-
tableName:
|
|
1190
|
+
tableName: TABLE_SPANS,
|
|
1229
1191
|
sqlRow: row
|
|
1230
1192
|
})
|
|
1231
1193
|
);
|
|
@@ -1241,7 +1203,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1241
1203
|
} catch (error) {
|
|
1242
1204
|
throw new MastraError(
|
|
1243
1205
|
{
|
|
1244
|
-
id: "
|
|
1206
|
+
id: "MSSQL_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1245
1207
|
domain: ErrorDomain.STORAGE,
|
|
1246
1208
|
category: ErrorCategory.USER
|
|
1247
1209
|
},
|
|
@@ -1249,13 +1211,13 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1249
1211
|
);
|
|
1250
1212
|
}
|
|
1251
1213
|
}
|
|
1252
|
-
async
|
|
1214
|
+
async batchCreateSpans(args) {
|
|
1253
1215
|
if (!args.records || args.records.length === 0) {
|
|
1254
1216
|
return;
|
|
1255
1217
|
}
|
|
1256
1218
|
try {
|
|
1257
1219
|
await this.operations.batchInsert({
|
|
1258
|
-
tableName:
|
|
1220
|
+
tableName: TABLE_SPANS,
|
|
1259
1221
|
records: args.records.map((span) => ({
|
|
1260
1222
|
...span,
|
|
1261
1223
|
startedAt: span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt,
|
|
@@ -1265,7 +1227,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1265
1227
|
} catch (error) {
|
|
1266
1228
|
throw new MastraError(
|
|
1267
1229
|
{
|
|
1268
|
-
id: "
|
|
1230
|
+
id: "MSSQL_STORE_BATCH_CREATE_SPANS_FAILED",
|
|
1269
1231
|
domain: ErrorDomain.STORAGE,
|
|
1270
1232
|
category: ErrorCategory.USER,
|
|
1271
1233
|
details: {
|
|
@@ -1276,7 +1238,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1276
1238
|
);
|
|
1277
1239
|
}
|
|
1278
1240
|
}
|
|
1279
|
-
async
|
|
1241
|
+
async batchUpdateSpans(args) {
|
|
1280
1242
|
if (!args.records || args.records.length === 0) {
|
|
1281
1243
|
return;
|
|
1282
1244
|
}
|
|
@@ -1295,13 +1257,13 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1295
1257
|
};
|
|
1296
1258
|
});
|
|
1297
1259
|
await this.operations.batchUpdate({
|
|
1298
|
-
tableName:
|
|
1260
|
+
tableName: TABLE_SPANS,
|
|
1299
1261
|
updates
|
|
1300
1262
|
});
|
|
1301
1263
|
} catch (error) {
|
|
1302
1264
|
throw new MastraError(
|
|
1303
1265
|
{
|
|
1304
|
-
id: "
|
|
1266
|
+
id: "MSSQL_STORE_BATCH_UPDATE_SPANS_FAILED",
|
|
1305
1267
|
domain: ErrorDomain.STORAGE,
|
|
1306
1268
|
category: ErrorCategory.USER,
|
|
1307
1269
|
details: {
|
|
@@ -1312,20 +1274,20 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
|
|
|
1312
1274
|
);
|
|
1313
1275
|
}
|
|
1314
1276
|
}
|
|
1315
|
-
async
|
|
1277
|
+
async batchDeleteTraces(args) {
|
|
1316
1278
|
if (!args.traceIds || args.traceIds.length === 0) {
|
|
1317
1279
|
return;
|
|
1318
1280
|
}
|
|
1319
1281
|
try {
|
|
1320
1282
|
const keys = args.traceIds.map((traceId) => ({ traceId }));
|
|
1321
1283
|
await this.operations.batchDelete({
|
|
1322
|
-
tableName:
|
|
1284
|
+
tableName: TABLE_SPANS,
|
|
1323
1285
|
keys
|
|
1324
1286
|
});
|
|
1325
1287
|
} catch (error) {
|
|
1326
1288
|
throw new MastraError(
|
|
1327
1289
|
{
|
|
1328
|
-
id: "
|
|
1290
|
+
id: "MSSQL_STORE_BATCH_DELETE_TRACES_FAILED",
|
|
1329
1291
|
domain: ErrorDomain.STORAGE,
|
|
1330
1292
|
category: ErrorCategory.USER,
|
|
1331
1293
|
details: {
|
|
@@ -1750,6 +1712,20 @@ ${columns}
|
|
|
1750
1712
|
return value ? 1 : 0;
|
|
1751
1713
|
}
|
|
1752
1714
|
if (columnSchema?.type === "jsonb") {
|
|
1715
|
+
if (typeof value === "string") {
|
|
1716
|
+
const trimmed = value.trim();
|
|
1717
|
+
if (trimmed.length > 0) {
|
|
1718
|
+
try {
|
|
1719
|
+
JSON.parse(trimmed);
|
|
1720
|
+
return trimmed;
|
|
1721
|
+
} catch {
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
return JSON.stringify(value);
|
|
1725
|
+
}
|
|
1726
|
+
if (typeof value === "bigint") {
|
|
1727
|
+
return value.toString();
|
|
1728
|
+
}
|
|
1753
1729
|
return JSON.stringify(value);
|
|
1754
1730
|
}
|
|
1755
1731
|
if (typeof value === "object") {
|
|
@@ -2229,25 +2205,25 @@ ${columns}
|
|
|
2229
2205
|
table: TABLE_SCORERS,
|
|
2230
2206
|
columns: ["traceId", "spanId", "seq_id DESC"]
|
|
2231
2207
|
},
|
|
2232
|
-
//
|
|
2208
|
+
// Spans indexes for optimal trace querying
|
|
2233
2209
|
{
|
|
2234
2210
|
name: `${schemaPrefix}mastra_ai_spans_traceid_startedat_idx`,
|
|
2235
|
-
table:
|
|
2211
|
+
table: TABLE_SPANS,
|
|
2236
2212
|
columns: ["traceId", "startedAt DESC"]
|
|
2237
2213
|
},
|
|
2238
2214
|
{
|
|
2239
2215
|
name: `${schemaPrefix}mastra_ai_spans_parentspanid_startedat_idx`,
|
|
2240
|
-
table:
|
|
2216
|
+
table: TABLE_SPANS,
|
|
2241
2217
|
columns: ["parentSpanId", "startedAt DESC"]
|
|
2242
2218
|
},
|
|
2243
2219
|
{
|
|
2244
2220
|
name: `${schemaPrefix}mastra_ai_spans_name_idx`,
|
|
2245
|
-
table:
|
|
2221
|
+
table: TABLE_SPANS,
|
|
2246
2222
|
columns: ["name"]
|
|
2247
2223
|
},
|
|
2248
2224
|
{
|
|
2249
2225
|
name: `${schemaPrefix}mastra_ai_spans_spantype_startedat_idx`,
|
|
2250
|
-
table:
|
|
2226
|
+
table: TABLE_SPANS,
|
|
2251
2227
|
columns: ["spanType", "startedAt DESC"]
|
|
2252
2228
|
}
|
|
2253
2229
|
];
|
|
@@ -2695,13 +2671,14 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2695
2671
|
snapshot = {
|
|
2696
2672
|
context: {},
|
|
2697
2673
|
activePaths: [],
|
|
2674
|
+
activeStepsPath: {},
|
|
2698
2675
|
timestamp: Date.now(),
|
|
2699
2676
|
suspendedPaths: {},
|
|
2700
2677
|
resumeLabels: {},
|
|
2701
2678
|
serializedStepGraph: [],
|
|
2679
|
+
status: "pending",
|
|
2702
2680
|
value: {},
|
|
2703
2681
|
waitingPaths: {},
|
|
2704
|
-
status: "pending",
|
|
2705
2682
|
runId,
|
|
2706
2683
|
requestContext: {}
|
|
2707
2684
|
};
|
|
@@ -2931,7 +2908,8 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2931
2908
|
toDate,
|
|
2932
2909
|
page,
|
|
2933
2910
|
perPage,
|
|
2934
|
-
resourceId
|
|
2911
|
+
resourceId,
|
|
2912
|
+
status
|
|
2935
2913
|
} = {}) {
|
|
2936
2914
|
try {
|
|
2937
2915
|
const conditions = [];
|
|
@@ -2940,6 +2918,10 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2940
2918
|
conditions.push(`[workflow_name] = @workflowName`);
|
|
2941
2919
|
paramMap["workflowName"] = workflowName;
|
|
2942
2920
|
}
|
|
2921
|
+
if (status) {
|
|
2922
|
+
conditions.push(`JSON_VALUE([snapshot], '$.status') = @status`);
|
|
2923
|
+
paramMap["status"] = status;
|
|
2924
|
+
}
|
|
2943
2925
|
if (resourceId) {
|
|
2944
2926
|
const hasResourceId = await this.operations.hasColumn(TABLE_WORKFLOW_SNAPSHOT, "resourceId");
|
|
2945
2927
|
if (hasResourceId) {
|
|
@@ -3008,7 +2990,10 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3008
2990
|
isConnected = null;
|
|
3009
2991
|
stores;
|
|
3010
2992
|
constructor(config) {
|
|
3011
|
-
|
|
2993
|
+
if (!config.id || typeof config.id !== "string" || config.id.trim() === "") {
|
|
2994
|
+
throw new Error("MSSQLStore: id must be provided and cannot be empty.");
|
|
2995
|
+
}
|
|
2996
|
+
super({ id: config.id, name: "MSSQLStore" });
|
|
3012
2997
|
try {
|
|
3013
2998
|
if ("connectionString" in config) {
|
|
3014
2999
|
if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
|
|
@@ -3094,7 +3079,7 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3094
3079
|
createTable: true,
|
|
3095
3080
|
deleteMessages: true,
|
|
3096
3081
|
listScoresBySpan: true,
|
|
3097
|
-
|
|
3082
|
+
observabilityInstance: true,
|
|
3098
3083
|
indexManagement: true
|
|
3099
3084
|
};
|
|
3100
3085
|
}
|
|
@@ -3145,12 +3130,6 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3145
3130
|
async deleteThread({ threadId }) {
|
|
3146
3131
|
return this.stores.memory.deleteThread({ threadId });
|
|
3147
3132
|
}
|
|
3148
|
-
/**
|
|
3149
|
-
* @deprecated use listMessages instead
|
|
3150
|
-
*/
|
|
3151
|
-
async getMessages(args) {
|
|
3152
|
-
return this.stores.memory.getMessages(args);
|
|
3153
|
-
}
|
|
3154
3133
|
async listMessagesById({ messageIds }) {
|
|
3155
3134
|
return this.stores.memory.listMessagesById({ messageIds });
|
|
3156
3135
|
}
|
|
@@ -3211,15 +3190,8 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3211
3190
|
}) {
|
|
3212
3191
|
return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
|
|
3213
3192
|
}
|
|
3214
|
-
async listWorkflowRuns({
|
|
3215
|
-
|
|
3216
|
-
fromDate,
|
|
3217
|
-
toDate,
|
|
3218
|
-
perPage,
|
|
3219
|
-
page,
|
|
3220
|
-
resourceId
|
|
3221
|
-
} = {}) {
|
|
3222
|
-
return this.stores.workflows.listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId });
|
|
3193
|
+
async listWorkflowRuns(args = {}) {
|
|
3194
|
+
return this.stores.workflows.listWorkflowRuns(args);
|
|
3223
3195
|
}
|
|
3224
3196
|
async getWorkflowRunById({
|
|
3225
3197
|
runId,
|
|
@@ -3246,7 +3218,7 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3246
3218
|
return this.stores.operations.dropIndex(indexName);
|
|
3247
3219
|
}
|
|
3248
3220
|
/**
|
|
3249
|
-
*
|
|
3221
|
+
* Tracing / Observability
|
|
3250
3222
|
*/
|
|
3251
3223
|
getObservabilityStore() {
|
|
3252
3224
|
if (!this.stores.observability) {
|
|
@@ -3259,30 +3231,30 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3259
3231
|
}
|
|
3260
3232
|
return this.stores.observability;
|
|
3261
3233
|
}
|
|
3262
|
-
async
|
|
3263
|
-
return this.getObservabilityStore().
|
|
3234
|
+
async createSpan(span) {
|
|
3235
|
+
return this.getObservabilityStore().createSpan(span);
|
|
3264
3236
|
}
|
|
3265
|
-
async
|
|
3237
|
+
async updateSpan({
|
|
3266
3238
|
spanId,
|
|
3267
3239
|
traceId,
|
|
3268
3240
|
updates
|
|
3269
3241
|
}) {
|
|
3270
|
-
return this.getObservabilityStore().
|
|
3242
|
+
return this.getObservabilityStore().updateSpan({ spanId, traceId, updates });
|
|
3271
3243
|
}
|
|
3272
|
-
async
|
|
3273
|
-
return this.getObservabilityStore().
|
|
3244
|
+
async getTrace(traceId) {
|
|
3245
|
+
return this.getObservabilityStore().getTrace(traceId);
|
|
3274
3246
|
}
|
|
3275
|
-
async
|
|
3276
|
-
return this.getObservabilityStore().
|
|
3247
|
+
async getTracesPaginated(args) {
|
|
3248
|
+
return this.getObservabilityStore().getTracesPaginated(args);
|
|
3277
3249
|
}
|
|
3278
|
-
async
|
|
3279
|
-
return this.getObservabilityStore().
|
|
3250
|
+
async batchCreateSpans(args) {
|
|
3251
|
+
return this.getObservabilityStore().batchCreateSpans(args);
|
|
3280
3252
|
}
|
|
3281
|
-
async
|
|
3282
|
-
return this.getObservabilityStore().
|
|
3253
|
+
async batchUpdateSpans(args) {
|
|
3254
|
+
return this.getObservabilityStore().batchUpdateSpans(args);
|
|
3283
3255
|
}
|
|
3284
|
-
async
|
|
3285
|
-
return this.getObservabilityStore().
|
|
3256
|
+
async batchDeleteTraces(args) {
|
|
3257
|
+
return this.getObservabilityStore().batchDeleteTraces(args);
|
|
3286
3258
|
}
|
|
3287
3259
|
/**
|
|
3288
3260
|
* Scorers
|