@mastra/mssql 0.0.0-vnext-20251104230439 → 0.0.0-vnext-20251119160359

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -156,6 +156,18 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
156
156
  }
157
157
  async listThreadsByResourceId(args) {
158
158
  const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
159
+ if (page < 0) {
160
+ throw new error.MastraError({
161
+ id: "MASTRA_STORAGE_MSSQL_STORE_INVALID_PAGE",
162
+ domain: error.ErrorDomain.STORAGE,
163
+ category: error.ErrorCategory.USER,
164
+ text: "Page number must be non-negative",
165
+ details: {
166
+ resourceId,
167
+ page
168
+ }
169
+ });
170
+ }
159
171
  const perPage = storage.normalizePerPage(perPageInput, 100);
160
172
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
161
173
  const { field, direction } = this.parseOrderBy(orderBy);
@@ -377,10 +389,9 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
377
389
  }
378
390
  async _getIncludedMessages({
379
391
  threadId,
380
- selectBy
392
+ include
381
393
  }) {
382
394
  if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
383
- const include = selectBy?.include;
384
395
  if (!include) return null;
385
396
  const unionQueries = [];
386
397
  const paramValues = [];
@@ -452,75 +463,6 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
452
463
  });
453
464
  return dedupedRows;
454
465
  }
455
- /**
456
- * @deprecated use listMessages instead
457
- */
458
- async getMessages(args) {
459
- const { threadId, resourceId, selectBy } = args;
460
- const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
461
- const orderByStatement = `ORDER BY [seq_id] DESC`;
462
- const limit = storage.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
463
- try {
464
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
465
- let rows = [];
466
- const include = selectBy?.include || [];
467
- if (include?.length) {
468
- const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
469
- if (includeMessages) {
470
- rows.push(...includeMessages);
471
- }
472
- }
473
- const excludeIds = rows.map((m) => m.id).filter(Boolean);
474
- let query = `${selectStatement} FROM ${getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} WHERE [thread_id] = @threadId`;
475
- const request = this.pool.request();
476
- request.input("threadId", threadId);
477
- if (excludeIds.length > 0) {
478
- const excludeParams = excludeIds.map((_, idx) => `@id${idx}`);
479
- query += ` AND id NOT IN (${excludeParams.join(", ")})`;
480
- excludeIds.forEach((id, idx) => {
481
- request.input(`id${idx}`, id);
482
- });
483
- }
484
- query += ` ${orderByStatement} OFFSET 0 ROWS FETCH NEXT @limit ROWS ONLY`;
485
- request.input("limit", limit);
486
- const result = await request.query(query);
487
- const remainingRows = result.recordset || [];
488
- rows.push(...remainingRows);
489
- rows.sort((a, b) => {
490
- const timeDiff = a.seq_id - b.seq_id;
491
- return timeDiff;
492
- });
493
- const messagesWithParsedContent = rows.map((row) => {
494
- if (typeof row.content === "string") {
495
- try {
496
- return { ...row, content: JSON.parse(row.content) };
497
- } catch {
498
- return row;
499
- }
500
- }
501
- return row;
502
- });
503
- const cleanMessages = messagesWithParsedContent.map(({ seq_id, ...rest }) => rest);
504
- const list = new agent.MessageList().add(cleanMessages, "memory");
505
- return { messages: list.get.all.db() };
506
- } catch (error$1) {
507
- const mastraError = new error.MastraError(
508
- {
509
- id: "MASTRA_STORAGE_MSSQL_STORE_GET_MESSAGES_FAILED",
510
- domain: error.ErrorDomain.STORAGE,
511
- category: error.ErrorCategory.THIRD_PARTY,
512
- details: {
513
- threadId,
514
- resourceId: resourceId ?? ""
515
- }
516
- },
517
- error$1
518
- );
519
- this.logger?.error?.(mastraError.toString());
520
- this.logger?.trackException?.(mastraError);
521
- return { messages: [] };
522
- }
523
- }
524
466
  async listMessagesById({ messageIds }) {
525
467
  if (messageIds.length === 0) return { messages: [] };
526
468
  const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
@@ -581,43 +523,59 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
581
523
  new Error("threadId must be a non-empty string")
582
524
  );
583
525
  }
526
+ if (page < 0) {
527
+ throw new error.MastraError({
528
+ id: "MASTRA_STORAGE_MSSQL_STORE_INVALID_PAGE",
529
+ domain: error.ErrorDomain.STORAGE,
530
+ category: error.ErrorCategory.USER,
531
+ text: "Page number must be non-negative",
532
+ details: {
533
+ threadId,
534
+ page
535
+ }
536
+ });
537
+ }
584
538
  const perPage = storage.normalizePerPage(perPageInput, 40);
585
539
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
586
540
  try {
587
- const { field, direction } = this.parseOrderBy(orderBy);
588
- const orderByStatement = `ORDER BY [${field}] ${direction}`;
589
- const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
541
+ const { field, direction } = this.parseOrderBy(orderBy, "ASC");
542
+ const orderByStatement = `ORDER BY [${field}] ${direction}, [seq_id] ${direction}`;
590
543
  const tableName = getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
591
- const conditions = ["[thread_id] = @threadId"];
592
- const request = this.pool.request();
593
- request.input("threadId", threadId);
594
- if (resourceId) {
595
- conditions.push("[resourceId] = @resourceId");
596
- request.input("resourceId", resourceId);
597
- }
598
- if (filter?.dateRange?.start) {
599
- conditions.push("[createdAt] >= @fromDate");
600
- request.input("fromDate", filter.dateRange.start);
601
- }
602
- if (filter?.dateRange?.end) {
603
- conditions.push("[createdAt] <= @toDate");
604
- request.input("toDate", filter.dateRange.end);
605
- }
606
- const whereClause = `WHERE ${conditions.join(" AND ")}`;
607
- const countQuery = `SELECT COUNT(*) as total FROM ${tableName} ${whereClause}`;
608
- const countResult = await request.query(countQuery);
544
+ const baseQuery = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId FROM ${tableName}`;
545
+ const filters = {
546
+ thread_id: threadId,
547
+ ...resourceId ? { resourceId } : {},
548
+ ...buildDateRangeFilter(filter?.dateRange, "createdAt")
549
+ };
550
+ const { sql: actualWhereClause = "", params: whereParams } = prepareWhereClause(
551
+ filters);
552
+ const bindWhereParams = (req) => {
553
+ Object.entries(whereParams).forEach(([paramName, paramValue]) => req.input(paramName, paramValue));
554
+ };
555
+ const countRequest = this.pool.request();
556
+ bindWhereParams(countRequest);
557
+ const countResult = await countRequest.query(`SELECT COUNT(*) as total FROM ${tableName}${actualWhereClause}`);
609
558
  const total = parseInt(countResult.recordset[0]?.total, 10) || 0;
610
- const limitValue = perPageInput === false ? total : perPage;
611
- const dataQuery = `${selectStatement} FROM ${tableName} ${whereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
612
- request.input("offset", offset);
613
- if (limitValue > 2147483647) {
614
- request.input("limit", sql2__default.default.BigInt, limitValue);
615
- } else {
616
- request.input("limit", limitValue);
617
- }
618
- const rowsResult = await request.query(dataQuery);
619
- const rows = rowsResult.recordset || [];
620
- const messages = [...rows];
559
+ const fetchBaseMessages = async () => {
560
+ const request = this.pool.request();
561
+ bindWhereParams(request);
562
+ if (perPageInput === false) {
563
+ const result2 = await request.query(`${baseQuery}${actualWhereClause} ${orderByStatement}`);
564
+ return result2.recordset || [];
565
+ }
566
+ request.input("offset", offset);
567
+ request.input("limit", perPage > 2147483647 ? sql2__default.default.BigInt : sql2__default.default.Int, perPage);
568
+ const result = await request.query(
569
+ `${baseQuery}${actualWhereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`
570
+ );
571
+ return result.recordset || [];
572
+ };
573
+ const baseRows = perPage === 0 ? [] : await fetchBaseMessages();
574
+ const messages = [...baseRows];
575
+ const seqById = /* @__PURE__ */ new Map();
576
+ messages.forEach((msg) => {
577
+ if (typeof msg.seq_id === "number") seqById.set(msg.id, msg.seq_id);
578
+ });
621
579
  if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
622
580
  return {
623
581
  messages: [],
@@ -627,29 +585,33 @@ var MemoryMSSQL = class extends storage.MemoryStorage {
627
585
  hasMore: false
628
586
  };
629
587
  }
630
- const messageIds = new Set(messages.map((m) => m.id));
631
- if (include && include.length > 0) {
632
- const selectBy = { include };
633
- const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
634
- if (includeMessages) {
635
- for (const includeMsg of includeMessages) {
636
- if (!messageIds.has(includeMsg.id)) {
637
- messages.push(includeMsg);
638
- messageIds.add(includeMsg.id);
639
- }
588
+ if (include?.length) {
589
+ const messageIds = new Set(messages.map((m) => m.id));
590
+ const includeMessages = await this._getIncludedMessages({ threadId, include });
591
+ includeMessages?.forEach((msg) => {
592
+ if (!messageIds.has(msg.id)) {
593
+ messages.push(msg);
594
+ messageIds.add(msg.id);
595
+ if (typeof msg.seq_id === "number") seqById.set(msg.id, msg.seq_id);
640
596
  }
641
- }
597
+ });
642
598
  }
643
599
  const parsed = this._parseAndFormatMessages(messages, "v2");
644
- let finalMessages = parsed;
645
- finalMessages = finalMessages.sort((a, b) => {
646
- const aValue = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
647
- const bValue = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
648
- return direction === "ASC" ? aValue - bValue : bValue - aValue;
600
+ const mult = direction === "ASC" ? 1 : -1;
601
+ const finalMessages = parsed.sort((a, b) => {
602
+ const aVal = field === "createdAt" ? new Date(a.createdAt).getTime() : a[field];
603
+ const bVal = field === "createdAt" ? new Date(b.createdAt).getTime() : b[field];
604
+ if (aVal == null || bVal == null) {
605
+ return aVal == null && bVal == null ? a.id.localeCompare(b.id) : aVal == null ? 1 : -1;
606
+ }
607
+ const diff = (typeof aVal === "number" && typeof bVal === "number" ? aVal - bVal : String(aVal).localeCompare(String(bVal))) * mult;
608
+ if (diff !== 0) return diff;
609
+ const seqA = seqById.get(a.id);
610
+ const seqB = seqById.get(b.id);
611
+ return seqA != null && seqB != null ? (seqA - seqB) * mult : a.id.localeCompare(b.id);
649
612
  });
650
- const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
651
- const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
652
- const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
613
+ const returnedThreadMessageCount = finalMessages.filter((m) => m.threadId === threadId).length;
614
+ const hasMore = perPageInput !== false && returnedThreadMessageCount < total && offset + perPage < total;
653
615
  return {
654
616
  messages: finalMessages,
655
617
  total,
@@ -1043,13 +1005,13 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1043
1005
  this.operations = operations;
1044
1006
  this.schema = schema;
1045
1007
  }
1046
- get aiTracingStrategy() {
1008
+ get tracingStrategy() {
1047
1009
  return {
1048
1010
  preferred: "batch-with-updates",
1049
1011
  supported: ["batch-with-updates", "insert-only"]
1050
1012
  };
1051
1013
  }
1052
- async createAISpan(span) {
1014
+ async createSpan(span) {
1053
1015
  try {
1054
1016
  const startedAt = span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt;
1055
1017
  const endedAt = span.endedAt instanceof Date ? span.endedAt.toISOString() : span.endedAt;
@@ -1059,11 +1021,11 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1059
1021
  endedAt
1060
1022
  // Note: createdAt/updatedAt will be set by default values
1061
1023
  };
1062
- return this.operations.insert({ tableName: storage.TABLE_AI_SPANS, record });
1024
+ return this.operations.insert({ tableName: storage.TABLE_SPANS, record });
1063
1025
  } catch (error$1) {
1064
1026
  throw new error.MastraError(
1065
1027
  {
1066
- id: "MSSQL_STORE_CREATE_AI_SPAN_FAILED",
1028
+ id: "MSSQL_STORE_CREATE_SPAN_FAILED",
1067
1029
  domain: error.ErrorDomain.STORAGE,
1068
1030
  category: error.ErrorCategory.USER,
1069
1031
  details: {
@@ -1077,10 +1039,10 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1077
1039
  );
1078
1040
  }
1079
1041
  }
1080
- async getAITrace(traceId) {
1042
+ async getTrace(traceId) {
1081
1043
  try {
1082
1044
  const tableName = getTableName({
1083
- indexName: storage.TABLE_AI_SPANS,
1045
+ indexName: storage.TABLE_SPANS,
1084
1046
  schemaName: getSchemaName(this.schema)
1085
1047
  });
1086
1048
  const request = this.pool.request();
@@ -1101,7 +1063,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1101
1063
  traceId,
1102
1064
  spans: result.recordset.map(
1103
1065
  (span) => transformFromSqlRow({
1104
- tableName: storage.TABLE_AI_SPANS,
1066
+ tableName: storage.TABLE_SPANS,
1105
1067
  sqlRow: span
1106
1068
  })
1107
1069
  )
@@ -1109,7 +1071,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1109
1071
  } catch (error$1) {
1110
1072
  throw new error.MastraError(
1111
1073
  {
1112
- id: "MSSQL_STORE_GET_AI_TRACE_FAILED",
1074
+ id: "MSSQL_STORE_GET_TRACE_FAILED",
1113
1075
  domain: error.ErrorDomain.STORAGE,
1114
1076
  category: error.ErrorCategory.USER,
1115
1077
  details: {
@@ -1120,7 +1082,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1120
1082
  );
1121
1083
  }
1122
1084
  }
1123
- async updateAISpan({
1085
+ async updateSpan({
1124
1086
  spanId,
1125
1087
  traceId,
1126
1088
  updates
@@ -1134,14 +1096,14 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1134
1096
  data.startedAt = data.startedAt.toISOString();
1135
1097
  }
1136
1098
  await this.operations.update({
1137
- tableName: storage.TABLE_AI_SPANS,
1099
+ tableName: storage.TABLE_SPANS,
1138
1100
  keys: { spanId, traceId },
1139
1101
  data
1140
1102
  });
1141
1103
  } catch (error$1) {
1142
1104
  throw new error.MastraError(
1143
1105
  {
1144
- id: "MSSQL_STORE_UPDATE_AI_SPAN_FAILED",
1106
+ id: "MSSQL_STORE_UPDATE_SPAN_FAILED",
1145
1107
  domain: error.ErrorDomain.STORAGE,
1146
1108
  category: error.ErrorCategory.USER,
1147
1109
  details: {
@@ -1153,7 +1115,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1153
1115
  );
1154
1116
  }
1155
1117
  }
1156
- async getAITracesPaginated({
1118
+ async getTracesPaginated({
1157
1119
  filters,
1158
1120
  pagination
1159
1121
  }) {
@@ -1178,7 +1140,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1178
1140
  name = `agent run: '${entityId}'`;
1179
1141
  } else {
1180
1142
  const error$1 = new error.MastraError({
1181
- id: "MSSQL_STORE_GET_AI_TRACES_PAGINATED_FAILED",
1143
+ id: "MSSQL_STORE_GET_TRACES_PAGINATED_FAILED",
1182
1144
  domain: error.ErrorDomain.STORAGE,
1183
1145
  category: error.ErrorCategory.USER,
1184
1146
  details: {
@@ -1197,7 +1159,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1197
1159
  params[entityParam] = name;
1198
1160
  }
1199
1161
  const tableName = getTableName({
1200
- indexName: storage.TABLE_AI_SPANS,
1162
+ indexName: storage.TABLE_SPANS,
1201
1163
  schemaName: getSchemaName(this.schema)
1202
1164
  });
1203
1165
  try {
@@ -1231,7 +1193,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1231
1193
  );
1232
1194
  const spans = dataResult.recordset.map(
1233
1195
  (row) => transformFromSqlRow({
1234
- tableName: storage.TABLE_AI_SPANS,
1196
+ tableName: storage.TABLE_SPANS,
1235
1197
  sqlRow: row
1236
1198
  })
1237
1199
  );
@@ -1247,7 +1209,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1247
1209
  } catch (error$1) {
1248
1210
  throw new error.MastraError(
1249
1211
  {
1250
- id: "MSSQL_STORE_GET_AI_TRACES_PAGINATED_FAILED",
1212
+ id: "MSSQL_STORE_GET_TRACES_PAGINATED_FAILED",
1251
1213
  domain: error.ErrorDomain.STORAGE,
1252
1214
  category: error.ErrorCategory.USER
1253
1215
  },
@@ -1255,13 +1217,13 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1255
1217
  );
1256
1218
  }
1257
1219
  }
1258
- async batchCreateAISpans(args) {
1220
+ async batchCreateSpans(args) {
1259
1221
  if (!args.records || args.records.length === 0) {
1260
1222
  return;
1261
1223
  }
1262
1224
  try {
1263
1225
  await this.operations.batchInsert({
1264
- tableName: storage.TABLE_AI_SPANS,
1226
+ tableName: storage.TABLE_SPANS,
1265
1227
  records: args.records.map((span) => ({
1266
1228
  ...span,
1267
1229
  startedAt: span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt,
@@ -1271,7 +1233,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1271
1233
  } catch (error$1) {
1272
1234
  throw new error.MastraError(
1273
1235
  {
1274
- id: "MSSQL_STORE_BATCH_CREATE_AI_SPANS_FAILED",
1236
+ id: "MSSQL_STORE_BATCH_CREATE_SPANS_FAILED",
1275
1237
  domain: error.ErrorDomain.STORAGE,
1276
1238
  category: error.ErrorCategory.USER,
1277
1239
  details: {
@@ -1282,7 +1244,7 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1282
1244
  );
1283
1245
  }
1284
1246
  }
1285
- async batchUpdateAISpans(args) {
1247
+ async batchUpdateSpans(args) {
1286
1248
  if (!args.records || args.records.length === 0) {
1287
1249
  return;
1288
1250
  }
@@ -1301,13 +1263,13 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1301
1263
  };
1302
1264
  });
1303
1265
  await this.operations.batchUpdate({
1304
- tableName: storage.TABLE_AI_SPANS,
1266
+ tableName: storage.TABLE_SPANS,
1305
1267
  updates
1306
1268
  });
1307
1269
  } catch (error$1) {
1308
1270
  throw new error.MastraError(
1309
1271
  {
1310
- id: "MSSQL_STORE_BATCH_UPDATE_AI_SPANS_FAILED",
1272
+ id: "MSSQL_STORE_BATCH_UPDATE_SPANS_FAILED",
1311
1273
  domain: error.ErrorDomain.STORAGE,
1312
1274
  category: error.ErrorCategory.USER,
1313
1275
  details: {
@@ -1318,20 +1280,20 @@ var ObservabilityMSSQL = class extends storage.ObservabilityStorage {
1318
1280
  );
1319
1281
  }
1320
1282
  }
1321
- async batchDeleteAITraces(args) {
1283
+ async batchDeleteTraces(args) {
1322
1284
  if (!args.traceIds || args.traceIds.length === 0) {
1323
1285
  return;
1324
1286
  }
1325
1287
  try {
1326
1288
  const keys = args.traceIds.map((traceId) => ({ traceId }));
1327
1289
  await this.operations.batchDelete({
1328
- tableName: storage.TABLE_AI_SPANS,
1290
+ tableName: storage.TABLE_SPANS,
1329
1291
  keys
1330
1292
  });
1331
1293
  } catch (error$1) {
1332
1294
  throw new error.MastraError(
1333
1295
  {
1334
- id: "MSSQL_STORE_BATCH_DELETE_AI_TRACES_FAILED",
1296
+ id: "MSSQL_STORE_BATCH_DELETE_TRACES_FAILED",
1335
1297
  domain: error.ErrorDomain.STORAGE,
1336
1298
  category: error.ErrorCategory.USER,
1337
1299
  details: {
@@ -1756,6 +1718,20 @@ ${columns}
1756
1718
  return value ? 1 : 0;
1757
1719
  }
1758
1720
  if (columnSchema?.type === "jsonb") {
1721
+ if (typeof value === "string") {
1722
+ const trimmed = value.trim();
1723
+ if (trimmed.length > 0) {
1724
+ try {
1725
+ JSON.parse(trimmed);
1726
+ return trimmed;
1727
+ } catch {
1728
+ }
1729
+ }
1730
+ return JSON.stringify(value);
1731
+ }
1732
+ if (typeof value === "bigint") {
1733
+ return value.toString();
1734
+ }
1759
1735
  return JSON.stringify(value);
1760
1736
  }
1761
1737
  if (typeof value === "object") {
@@ -2235,25 +2211,25 @@ ${columns}
2235
2211
  table: storage.TABLE_SCORERS,
2236
2212
  columns: ["traceId", "spanId", "seq_id DESC"]
2237
2213
  },
2238
- // AI Spans indexes for optimal trace querying
2214
+ // Spans indexes for optimal trace querying
2239
2215
  {
2240
2216
  name: `${schemaPrefix}mastra_ai_spans_traceid_startedat_idx`,
2241
- table: storage.TABLE_AI_SPANS,
2217
+ table: storage.TABLE_SPANS,
2242
2218
  columns: ["traceId", "startedAt DESC"]
2243
2219
  },
2244
2220
  {
2245
2221
  name: `${schemaPrefix}mastra_ai_spans_parentspanid_startedat_idx`,
2246
- table: storage.TABLE_AI_SPANS,
2222
+ table: storage.TABLE_SPANS,
2247
2223
  columns: ["parentSpanId", "startedAt DESC"]
2248
2224
  },
2249
2225
  {
2250
2226
  name: `${schemaPrefix}mastra_ai_spans_name_idx`,
2251
- table: storage.TABLE_AI_SPANS,
2227
+ table: storage.TABLE_SPANS,
2252
2228
  columns: ["name"]
2253
2229
  },
2254
2230
  {
2255
2231
  name: `${schemaPrefix}mastra_ai_spans_spantype_startedat_idx`,
2256
- table: storage.TABLE_AI_SPANS,
2232
+ table: storage.TABLE_SPANS,
2257
2233
  columns: ["spanType", "startedAt DESC"]
2258
2234
  }
2259
2235
  ];
@@ -2701,13 +2677,14 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
2701
2677
  snapshot = {
2702
2678
  context: {},
2703
2679
  activePaths: [],
2680
+ activeStepsPath: {},
2704
2681
  timestamp: Date.now(),
2705
2682
  suspendedPaths: {},
2706
2683
  resumeLabels: {},
2707
2684
  serializedStepGraph: [],
2685
+ status: "pending",
2708
2686
  value: {},
2709
2687
  waitingPaths: {},
2710
- status: "pending",
2711
2688
  runId,
2712
2689
  requestContext: {}
2713
2690
  };
@@ -2937,7 +2914,8 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
2937
2914
  toDate,
2938
2915
  page,
2939
2916
  perPage,
2940
- resourceId
2917
+ resourceId,
2918
+ status
2941
2919
  } = {}) {
2942
2920
  try {
2943
2921
  const conditions = [];
@@ -2946,6 +2924,10 @@ var WorkflowsMSSQL = class extends storage.WorkflowsStorage {
2946
2924
  conditions.push(`[workflow_name] = @workflowName`);
2947
2925
  paramMap["workflowName"] = workflowName;
2948
2926
  }
2927
+ if (status) {
2928
+ conditions.push(`JSON_VALUE([snapshot], '$.status') = @status`);
2929
+ paramMap["status"] = status;
2930
+ }
2949
2931
  if (resourceId) {
2950
2932
  const hasResourceId = await this.operations.hasColumn(storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId");
2951
2933
  if (hasResourceId) {
@@ -3014,7 +2996,10 @@ var MSSQLStore = class extends storage.MastraStorage {
3014
2996
  isConnected = null;
3015
2997
  stores;
3016
2998
  constructor(config) {
3017
- super({ name: "MSSQLStore" });
2999
+ if (!config.id || typeof config.id !== "string" || config.id.trim() === "") {
3000
+ throw new Error("MSSQLStore: id must be provided and cannot be empty.");
3001
+ }
3002
+ super({ id: config.id, name: "MSSQLStore" });
3018
3003
  try {
3019
3004
  if ("connectionString" in config) {
3020
3005
  if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
@@ -3100,7 +3085,7 @@ var MSSQLStore = class extends storage.MastraStorage {
3100
3085
  createTable: true,
3101
3086
  deleteMessages: true,
3102
3087
  listScoresBySpan: true,
3103
- aiTracing: true,
3088
+ observabilityInstance: true,
3104
3089
  indexManagement: true
3105
3090
  };
3106
3091
  }
@@ -3151,12 +3136,6 @@ var MSSQLStore = class extends storage.MastraStorage {
3151
3136
  async deleteThread({ threadId }) {
3152
3137
  return this.stores.memory.deleteThread({ threadId });
3153
3138
  }
3154
- /**
3155
- * @deprecated use listMessages instead
3156
- */
3157
- async getMessages(args) {
3158
- return this.stores.memory.getMessages(args);
3159
- }
3160
3139
  async listMessagesById({ messageIds }) {
3161
3140
  return this.stores.memory.listMessagesById({ messageIds });
3162
3141
  }
@@ -3217,15 +3196,8 @@ var MSSQLStore = class extends storage.MastraStorage {
3217
3196
  }) {
3218
3197
  return this.stores.workflows.loadWorkflowSnapshot({ workflowName, runId });
3219
3198
  }
3220
- async listWorkflowRuns({
3221
- workflowName,
3222
- fromDate,
3223
- toDate,
3224
- perPage,
3225
- page,
3226
- resourceId
3227
- } = {}) {
3228
- return this.stores.workflows.listWorkflowRuns({ workflowName, fromDate, toDate, perPage, page, resourceId });
3199
+ async listWorkflowRuns(args = {}) {
3200
+ return this.stores.workflows.listWorkflowRuns(args);
3229
3201
  }
3230
3202
  async getWorkflowRunById({
3231
3203
  runId,
@@ -3252,7 +3224,7 @@ var MSSQLStore = class extends storage.MastraStorage {
3252
3224
  return this.stores.operations.dropIndex(indexName);
3253
3225
  }
3254
3226
  /**
3255
- * AI Tracing / Observability
3227
+ * Tracing / Observability
3256
3228
  */
3257
3229
  getObservabilityStore() {
3258
3230
  if (!this.stores.observability) {
@@ -3265,30 +3237,30 @@ var MSSQLStore = class extends storage.MastraStorage {
3265
3237
  }
3266
3238
  return this.stores.observability;
3267
3239
  }
3268
- async createAISpan(span) {
3269
- return this.getObservabilityStore().createAISpan(span);
3240
+ async createSpan(span) {
3241
+ return this.getObservabilityStore().createSpan(span);
3270
3242
  }
3271
- async updateAISpan({
3243
+ async updateSpan({
3272
3244
  spanId,
3273
3245
  traceId,
3274
3246
  updates
3275
3247
  }) {
3276
- return this.getObservabilityStore().updateAISpan({ spanId, traceId, updates });
3248
+ return this.getObservabilityStore().updateSpan({ spanId, traceId, updates });
3277
3249
  }
3278
- async getAITrace(traceId) {
3279
- return this.getObservabilityStore().getAITrace(traceId);
3250
+ async getTrace(traceId) {
3251
+ return this.getObservabilityStore().getTrace(traceId);
3280
3252
  }
3281
- async getAITracesPaginated(args) {
3282
- return this.getObservabilityStore().getAITracesPaginated(args);
3253
+ async getTracesPaginated(args) {
3254
+ return this.getObservabilityStore().getTracesPaginated(args);
3283
3255
  }
3284
- async batchCreateAISpans(args) {
3285
- return this.getObservabilityStore().batchCreateAISpans(args);
3256
+ async batchCreateSpans(args) {
3257
+ return this.getObservabilityStore().batchCreateSpans(args);
3286
3258
  }
3287
- async batchUpdateAISpans(args) {
3288
- return this.getObservabilityStore().batchUpdateAISpans(args);
3259
+ async batchUpdateSpans(args) {
3260
+ return this.getObservabilityStore().batchUpdateSpans(args);
3289
3261
  }
3290
- async batchDeleteAITraces(args) {
3291
- return this.getObservabilityStore().batchDeleteAITraces(args);
3262
+ async batchDeleteTraces(args) {
3263
+ return this.getObservabilityStore().batchDeleteTraces(args);
3292
3264
  }
3293
3265
  /**
3294
3266
  * Scorers