@mastra/mssql 0.0.0-fix-tool-call-history-3-20250806004225 → 0.0.0-interpolate-reporter-url-20250910180021

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
@@ -461,6 +461,7 @@ var MemoryMSSQL = class extends MemoryStorage {
461
461
  selectBy,
462
462
  orderByStatement
463
463
  }) {
464
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
464
465
  const include = selectBy?.include;
465
466
  if (!include) return null;
466
467
  const unionQueries = [];
@@ -532,11 +533,12 @@ var MemoryMSSQL = class extends MemoryStorage {
532
533
  return dedupedRows;
533
534
  }
534
535
  async getMessages(args) {
535
- const { threadId, format, selectBy } = args;
536
+ const { threadId, resourceId, format, selectBy } = args;
536
537
  const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
537
538
  const orderByStatement = `ORDER BY [seq_id] DESC`;
538
539
  const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
539
540
  try {
541
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
540
542
  let rows = [];
541
543
  const include = selectBy?.include || [];
542
544
  if (include?.length) {
@@ -574,7 +576,8 @@ var MemoryMSSQL = class extends MemoryStorage {
574
576
  domain: ErrorDomain.STORAGE,
575
577
  category: ErrorCategory.THIRD_PARTY,
576
578
  details: {
577
- threadId
579
+ threadId,
580
+ resourceId: resourceId ?? ""
578
581
  }
579
582
  },
580
583
  error
@@ -584,30 +587,65 @@ var MemoryMSSQL = class extends MemoryStorage {
584
587
  return [];
585
588
  }
586
589
  }
587
- async getMessagesPaginated(args) {
588
- const { threadId, selectBy } = args;
589
- const { page = 0, perPage: perPageInput } = selectBy?.pagination || {};
590
+ async getMessagesById({
591
+ messageIds,
592
+ format
593
+ }) {
594
+ if (messageIds.length === 0) return [];
595
+ const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
590
596
  const orderByStatement = `ORDER BY [seq_id] DESC`;
591
- if (selectBy?.include?.length) {
592
- await this._getIncludedMessages({ threadId, selectBy, orderByStatement });
597
+ try {
598
+ let rows = [];
599
+ let query = `${selectStatement} FROM ${getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} WHERE [id] IN (${messageIds.map((_, i) => `@id${i}`).join(", ")})`;
600
+ const request = this.pool.request();
601
+ messageIds.forEach((id, i) => request.input(`id${i}`, id));
602
+ query += ` ${orderByStatement}`;
603
+ const result = await request.query(query);
604
+ const remainingRows = result.recordset || [];
605
+ rows.push(...remainingRows);
606
+ rows.sort((a, b) => {
607
+ const timeDiff = a.seq_id - b.seq_id;
608
+ return timeDiff;
609
+ });
610
+ rows = rows.map(({ seq_id, ...rest }) => rest);
611
+ if (format === `v1`) return this._parseAndFormatMessages(rows, format);
612
+ return this._parseAndFormatMessages(rows, `v2`);
613
+ } catch (error) {
614
+ const mastraError = new MastraError(
615
+ {
616
+ id: "MASTRA_STORAGE_MSSQL_STORE_GET_MESSAGES_BY_ID_FAILED",
617
+ domain: ErrorDomain.STORAGE,
618
+ category: ErrorCategory.THIRD_PARTY,
619
+ details: {
620
+ messageIds: JSON.stringify(messageIds)
621
+ }
622
+ },
623
+ error
624
+ );
625
+ this.logger?.error?.(mastraError.toString());
626
+ this.logger?.trackException(mastraError);
627
+ return [];
593
628
  }
629
+ }
630
+ async getMessagesPaginated(args) {
631
+ const { threadId, resourceId, format, selectBy } = args;
632
+ const { page = 0, perPage: perPageInput, dateRange } = selectBy?.pagination || {};
594
633
  try {
595
- const { threadId: threadId2, format, selectBy: selectBy2 } = args;
596
- const { page: page2 = 0, perPage: perPageInput2, dateRange } = selectBy2?.pagination || {};
634
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
597
635
  const fromDate = dateRange?.start;
598
636
  const toDate = dateRange?.end;
599
637
  const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
600
- const orderByStatement2 = `ORDER BY [seq_id] DESC`;
601
- let messages2 = [];
602
- if (selectBy2?.include?.length) {
603
- const includeMessages = await this._getIncludedMessages({ threadId: threadId2, selectBy: selectBy2, orderByStatement: orderByStatement2 });
604
- if (includeMessages) messages2.push(...includeMessages);
638
+ const orderByStatement = `ORDER BY [seq_id] DESC`;
639
+ let messages = [];
640
+ if (selectBy?.include?.length) {
641
+ const includeMessages = await this._getIncludedMessages({ threadId, selectBy, orderByStatement });
642
+ if (includeMessages) messages.push(...includeMessages);
605
643
  }
606
- const perPage = perPageInput2 !== void 0 ? perPageInput2 : resolveMessageLimit({ last: selectBy2?.last, defaultLimit: 40 });
607
- const currentOffset = page2 * perPage;
644
+ const perPage = perPageInput !== void 0 ? perPageInput : resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
645
+ const currentOffset = page * perPage;
608
646
  const conditions = ["[thread_id] = @threadId"];
609
647
  const request = this.pool.request();
610
- request.input("threadId", threadId2);
648
+ request.input("threadId", threadId);
611
649
  if (fromDate instanceof Date && !isNaN(fromDate.getTime())) {
612
650
  conditions.push("[createdAt] >= @fromDate");
613
651
  request.input("fromDate", fromDate.toISOString());
@@ -620,35 +658,35 @@ var MemoryMSSQL = class extends MemoryStorage {
620
658
  const countQuery = `SELECT COUNT(*) as total FROM ${getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} ${whereClause}`;
621
659
  const countResult = await request.query(countQuery);
622
660
  const total = parseInt(countResult.recordset[0]?.total, 10) || 0;
623
- if (total === 0 && messages2.length > 0) {
624
- const parsedIncluded = this._parseAndFormatMessages(messages2, format);
661
+ if (total === 0 && messages.length > 0) {
662
+ const parsedIncluded = this._parseAndFormatMessages(messages, format);
625
663
  return {
626
664
  messages: parsedIncluded,
627
665
  total: parsedIncluded.length,
628
- page: page2,
666
+ page,
629
667
  perPage,
630
668
  hasMore: false
631
669
  };
632
670
  }
633
- const excludeIds = messages2.map((m) => m.id);
671
+ const excludeIds = messages.map((m) => m.id);
634
672
  if (excludeIds.length > 0) {
635
673
  const excludeParams = excludeIds.map((_, idx) => `@id${idx}`);
636
674
  conditions.push(`id NOT IN (${excludeParams.join(", ")})`);
637
675
  excludeIds.forEach((id, idx) => request.input(`id${idx}`, id));
638
676
  }
639
677
  const finalWhereClause = `WHERE ${conditions.join(" AND ")}`;
640
- const dataQuery = `${selectStatement} FROM ${getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} ${finalWhereClause} ${orderByStatement2} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
678
+ const dataQuery = `${selectStatement} FROM ${getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} ${finalWhereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
641
679
  request.input("offset", currentOffset);
642
680
  request.input("limit", perPage);
643
681
  const rowsResult = await request.query(dataQuery);
644
682
  const rows = rowsResult.recordset || [];
645
683
  rows.sort((a, b) => a.seq_id - b.seq_id);
646
- messages2.push(...rows);
647
- const parsed = this._parseAndFormatMessages(messages2, format);
684
+ messages.push(...rows);
685
+ const parsed = this._parseAndFormatMessages(messages, format);
648
686
  return {
649
687
  messages: parsed,
650
688
  total: total + excludeIds.length,
651
- page: page2,
689
+ page,
652
690
  perPage,
653
691
  hasMore: currentOffset + rows.length < total
654
692
  };
@@ -660,6 +698,7 @@ var MemoryMSSQL = class extends MemoryStorage {
660
698
  category: ErrorCategory.THIRD_PARTY,
661
699
  details: {
662
700
  threadId,
701
+ resourceId: resourceId ?? "",
663
702
  page
664
703
  }
665
704
  },
@@ -1832,6 +1871,22 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
1832
1871
  this.operations = operations;
1833
1872
  this.schema = schema;
1834
1873
  }
1874
+ updateWorkflowResults({
1875
+ // workflowName,
1876
+ // runId,
1877
+ // stepId,
1878
+ // result,
1879
+ // runtimeContext,
1880
+ }) {
1881
+ throw new Error("Method not implemented.");
1882
+ }
1883
+ updateWorkflowState({
1884
+ // workflowName,
1885
+ // runId,
1886
+ // opts,
1887
+ }) {
1888
+ throw new Error("Method not implemented.");
1889
+ }
1835
1890
  async persistWorkflowSnapshot({
1836
1891
  workflowName,
1837
1892
  runId,
@@ -2183,6 +2238,12 @@ var MSSQLStore = class extends MastraStorage {
2183
2238
  async getMessages(args) {
2184
2239
  return this.stores.memory.getMessages(args);
2185
2240
  }
2241
+ async getMessagesById({
2242
+ messageIds,
2243
+ format
2244
+ }) {
2245
+ return this.stores.memory.getMessagesById({ messageIds, format });
2246
+ }
2186
2247
  async getMessagesPaginated(args) {
2187
2248
  return this.stores.memory.getMessagesPaginated(args);
2188
2249
  }
@@ -2213,6 +2274,22 @@ var MSSQLStore = class extends MastraStorage {
2213
2274
  /**
2214
2275
  * Workflows
2215
2276
  */
2277
+ async updateWorkflowResults({
2278
+ workflowName,
2279
+ runId,
2280
+ stepId,
2281
+ result,
2282
+ runtimeContext
2283
+ }) {
2284
+ return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
2285
+ }
2286
+ async updateWorkflowState({
2287
+ workflowName,
2288
+ runId,
2289
+ opts
2290
+ }) {
2291
+ return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
2292
+ }
2216
2293
  async persistWorkflowSnapshot({
2217
2294
  workflowName,
2218
2295
  runId,