@mastra/mssql 0.0.0-fix-9244-clickhouse-metadata-20251104223105 → 0.0.0-fix-thread-list-20251105222841

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.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, TABLE_AI_SPANS, ScoresStorage, normalizePerPage, calculatePagination, WorkflowsStorage, MemoryStorage, resolveMessageLimit, TABLE_RESOURCES, ObservabilityStorage, safelyParseJSON } from '@mastra/core/storage';
2
+ import { MastraStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, TABLE_SCHEMAS, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_SCORERS, TABLE_AI_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';
@@ -371,10 +371,9 @@ var MemoryMSSQL = class extends MemoryStorage {
371
371
  }
372
372
  async _getIncludedMessages({
373
373
  threadId,
374
- selectBy
374
+ include
375
375
  }) {
376
376
  if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
377
- const include = selectBy?.include;
378
377
  if (!include) return null;
379
378
  const unionQueries = [];
380
379
  const paramValues = [];
@@ -446,75 +445,6 @@ var MemoryMSSQL = class extends MemoryStorage {
446
445
  });
447
446
  return dedupedRows;
448
447
  }
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
448
  async listMessagesById({ messageIds }) {
519
449
  if (messageIds.length === 0) return { messages: [] };
520
450
  const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
@@ -578,7 +508,7 @@ var MemoryMSSQL = class extends MemoryStorage {
578
508
  const perPage = normalizePerPage(perPageInput, 40);
579
509
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
580
510
  try {
581
- const { field, direction } = this.parseOrderBy(orderBy);
511
+ const { field, direction } = this.parseOrderBy(orderBy, "ASC");
582
512
  const orderByStatement = `ORDER BY [${field}] ${direction}`;
583
513
  const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
584
514
  const tableName = getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
@@ -623,8 +553,7 @@ var MemoryMSSQL = class extends MemoryStorage {
623
553
  }
624
554
  const messageIds = new Set(messages.map((m) => m.id));
625
555
  if (include && include.length > 0) {
626
- const selectBy = { include };
627
- const includeMessages = await this._getIncludedMessages({ threadId, selectBy });
556
+ const includeMessages = await this._getIncludedMessages({ threadId, include });
628
557
  if (includeMessages) {
629
558
  for (const includeMsg of includeMessages) {
630
559
  if (!messageIds.has(includeMsg.id)) {
@@ -1037,13 +966,13 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
1037
966
  this.operations = operations;
1038
967
  this.schema = schema;
1039
968
  }
1040
- get aiTracingStrategy() {
969
+ get tracingStrategy() {
1041
970
  return {
1042
971
  preferred: "batch-with-updates",
1043
972
  supported: ["batch-with-updates", "insert-only"]
1044
973
  };
1045
974
  }
1046
- async createAISpan(span) {
975
+ async createSpan(span) {
1047
976
  try {
1048
977
  const startedAt = span.startedAt instanceof Date ? span.startedAt.toISOString() : span.startedAt;
1049
978
  const endedAt = span.endedAt instanceof Date ? span.endedAt.toISOString() : span.endedAt;
@@ -1114,7 +1043,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
1114
1043
  );
1115
1044
  }
1116
1045
  }
1117
- async updateAISpan({
1046
+ async updateSpan({
1118
1047
  spanId,
1119
1048
  traceId,
1120
1049
  updates
@@ -1249,7 +1178,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
1249
1178
  );
1250
1179
  }
1251
1180
  }
1252
- async batchCreateAISpans(args) {
1181
+ async batchCreateSpans(args) {
1253
1182
  if (!args.records || args.records.length === 0) {
1254
1183
  return;
1255
1184
  }
@@ -1276,7 +1205,7 @@ var ObservabilityMSSQL = class extends ObservabilityStorage {
1276
1205
  );
1277
1206
  }
1278
1207
  }
1279
- async batchUpdateAISpans(args) {
1208
+ async batchUpdateSpans(args) {
1280
1209
  if (!args.records || args.records.length === 0) {
1281
1210
  return;
1282
1211
  }
@@ -2229,7 +2158,7 @@ ${columns}
2229
2158
  table: TABLE_SCORERS,
2230
2159
  columns: ["traceId", "spanId", "seq_id DESC"]
2231
2160
  },
2232
- // AI Spans indexes for optimal trace querying
2161
+ // Spans indexes for optimal trace querying
2233
2162
  {
2234
2163
  name: `${schemaPrefix}mastra_ai_spans_traceid_startedat_idx`,
2235
2164
  table: TABLE_AI_SPANS,
@@ -3094,7 +3023,7 @@ var MSSQLStore = class extends MastraStorage {
3094
3023
  createTable: true,
3095
3024
  deleteMessages: true,
3096
3025
  listScoresBySpan: true,
3097
- aiTracing: true,
3026
+ observabilityInstance: true,
3098
3027
  indexManagement: true
3099
3028
  };
3100
3029
  }
@@ -3145,12 +3074,6 @@ var MSSQLStore = class extends MastraStorage {
3145
3074
  async deleteThread({ threadId }) {
3146
3075
  return this.stores.memory.deleteThread({ threadId });
3147
3076
  }
3148
- /**
3149
- * @deprecated use listMessages instead
3150
- */
3151
- async getMessages(args) {
3152
- return this.stores.memory.getMessages(args);
3153
- }
3154
3077
  async listMessagesById({ messageIds }) {
3155
3078
  return this.stores.memory.listMessagesById({ messageIds });
3156
3079
  }
@@ -3246,7 +3169,7 @@ var MSSQLStore = class extends MastraStorage {
3246
3169
  return this.stores.operations.dropIndex(indexName);
3247
3170
  }
3248
3171
  /**
3249
- * AI Tracing / Observability
3172
+ * Tracing / Observability
3250
3173
  */
3251
3174
  getObservabilityStore() {
3252
3175
  if (!this.stores.observability) {
@@ -3259,15 +3182,15 @@ var MSSQLStore = class extends MastraStorage {
3259
3182
  }
3260
3183
  return this.stores.observability;
3261
3184
  }
3262
- async createAISpan(span) {
3263
- return this.getObservabilityStore().createAISpan(span);
3185
+ async createSpan(span) {
3186
+ return this.getObservabilityStore().createSpan(span);
3264
3187
  }
3265
- async updateAISpan({
3188
+ async updateSpan({
3266
3189
  spanId,
3267
3190
  traceId,
3268
3191
  updates
3269
3192
  }) {
3270
- return this.getObservabilityStore().updateAISpan({ spanId, traceId, updates });
3193
+ return this.getObservabilityStore().updateSpan({ spanId, traceId, updates });
3271
3194
  }
3272
3195
  async getAITrace(traceId) {
3273
3196
  return this.getObservabilityStore().getAITrace(traceId);
@@ -3275,11 +3198,11 @@ var MSSQLStore = class extends MastraStorage {
3275
3198
  async getAITracesPaginated(args) {
3276
3199
  return this.getObservabilityStore().getAITracesPaginated(args);
3277
3200
  }
3278
- async batchCreateAISpans(args) {
3279
- return this.getObservabilityStore().batchCreateAISpans(args);
3201
+ async batchCreateSpans(args) {
3202
+ return this.getObservabilityStore().batchCreateSpans(args);
3280
3203
  }
3281
- async batchUpdateAISpans(args) {
3282
- return this.getObservabilityStore().batchUpdateAISpans(args);
3204
+ async batchUpdateSpans(args) {
3205
+ return this.getObservabilityStore().batchUpdateSpans(args);
3283
3206
  }
3284
3207
  async batchDeleteAITraces(args) {
3285
3208
  return this.getObservabilityStore().batchDeleteAITraces(args);