@mastra/mssql 0.0.0-vector-query-tool-provider-options-20250828222356 → 0.0.0-vector-extension-schema-20250922130418

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
@@ -625,29 +628,24 @@ var MemoryMSSQL = class extends MemoryStorage {
625
628
  }
626
629
  }
627
630
  async getMessagesPaginated(args) {
628
- const { threadId, selectBy } = args;
629
- const { page = 0, perPage: perPageInput } = selectBy?.pagination || {};
630
- const orderByStatement = `ORDER BY [seq_id] DESC`;
631
- if (selectBy?.include?.length) {
632
- await this._getIncludedMessages({ threadId, selectBy, orderByStatement });
633
- }
631
+ const { threadId, resourceId, format, selectBy } = args;
632
+ const { page = 0, perPage: perPageInput, dateRange } = selectBy?.pagination || {};
634
633
  try {
635
- const { threadId: threadId2, format, selectBy: selectBy2 } = args;
636
- const { page: page2 = 0, perPage: perPageInput2, dateRange } = selectBy2?.pagination || {};
634
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
637
635
  const fromDate = dateRange?.start;
638
636
  const toDate = dateRange?.end;
639
637
  const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
640
- const orderByStatement2 = `ORDER BY [seq_id] DESC`;
641
- let messages2 = [];
642
- if (selectBy2?.include?.length) {
643
- const includeMessages = await this._getIncludedMessages({ threadId: threadId2, selectBy: selectBy2, orderByStatement: orderByStatement2 });
644
- 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);
645
643
  }
646
- const perPage = perPageInput2 !== void 0 ? perPageInput2 : resolveMessageLimit({ last: selectBy2?.last, defaultLimit: 40 });
647
- const currentOffset = page2 * perPage;
644
+ const perPage = perPageInput !== void 0 ? perPageInput : resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
645
+ const currentOffset = page * perPage;
648
646
  const conditions = ["[thread_id] = @threadId"];
649
647
  const request = this.pool.request();
650
- request.input("threadId", threadId2);
648
+ request.input("threadId", threadId);
651
649
  if (fromDate instanceof Date && !isNaN(fromDate.getTime())) {
652
650
  conditions.push("[createdAt] >= @fromDate");
653
651
  request.input("fromDate", fromDate.toISOString());
@@ -660,35 +658,35 @@ var MemoryMSSQL = class extends MemoryStorage {
660
658
  const countQuery = `SELECT COUNT(*) as total FROM ${getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} ${whereClause}`;
661
659
  const countResult = await request.query(countQuery);
662
660
  const total = parseInt(countResult.recordset[0]?.total, 10) || 0;
663
- if (total === 0 && messages2.length > 0) {
664
- const parsedIncluded = this._parseAndFormatMessages(messages2, format);
661
+ if (total === 0 && messages.length > 0) {
662
+ const parsedIncluded = this._parseAndFormatMessages(messages, format);
665
663
  return {
666
664
  messages: parsedIncluded,
667
665
  total: parsedIncluded.length,
668
- page: page2,
666
+ page,
669
667
  perPage,
670
668
  hasMore: false
671
669
  };
672
670
  }
673
- const excludeIds = messages2.map((m) => m.id);
671
+ const excludeIds = messages.map((m) => m.id);
674
672
  if (excludeIds.length > 0) {
675
673
  const excludeParams = excludeIds.map((_, idx) => `@id${idx}`);
676
674
  conditions.push(`id NOT IN (${excludeParams.join(", ")})`);
677
675
  excludeIds.forEach((id, idx) => request.input(`id${idx}`, id));
678
676
  }
679
677
  const finalWhereClause = `WHERE ${conditions.join(" AND ")}`;
680
- 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`;
681
679
  request.input("offset", currentOffset);
682
680
  request.input("limit", perPage);
683
681
  const rowsResult = await request.query(dataQuery);
684
682
  const rows = rowsResult.recordset || [];
685
683
  rows.sort((a, b) => a.seq_id - b.seq_id);
686
- messages2.push(...rows);
687
- const parsed = this._parseAndFormatMessages(messages2, format);
684
+ messages.push(...rows);
685
+ const parsed = this._parseAndFormatMessages(messages, format);
688
686
  return {
689
687
  messages: parsed,
690
688
  total: total + excludeIds.length,
691
- page: page2,
689
+ page,
692
690
  perPage,
693
691
  hasMore: currentOffset + rows.length < total
694
692
  };
@@ -700,6 +698,7 @@ var MemoryMSSQL = class extends MemoryStorage {
700
698
  category: ErrorCategory.THIRD_PARTY,
701
699
  details: {
702
700
  threadId,
701
+ resourceId: resourceId ?? "",
703
702
  page
704
703
  }
705
704
  },
@@ -1891,6 +1890,7 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
1891
1890
  async persistWorkflowSnapshot({
1892
1891
  workflowName,
1893
1892
  runId,
1893
+ resourceId,
1894
1894
  snapshot
1895
1895
  }) {
1896
1896
  const table = getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName(this.schema) });
@@ -1899,6 +1899,7 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
1899
1899
  const request = this.pool.request();
1900
1900
  request.input("workflow_name", workflowName);
1901
1901
  request.input("run_id", runId);
1902
+ request.input("resourceId", resourceId);
1902
1903
  request.input("snapshot", JSON.stringify(snapshot));
1903
1904
  request.input("createdAt", sql2.DateTime2, new Date(now));
1904
1905
  request.input("updatedAt", sql2.DateTime2, new Date(now));
@@ -1906,10 +1907,11 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
1906
1907
  USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
1907
1908
  ON target.workflow_name = src.workflow_name AND target.run_id = src.run_id
1908
1909
  WHEN MATCHED THEN UPDATE SET
1910
+ resourceId = @resourceId,
1909
1911
  snapshot = @snapshot,
1910
1912
  [updatedAt] = @updatedAt
1911
- WHEN NOT MATCHED THEN INSERT (workflow_name, run_id, snapshot, [createdAt], [updatedAt])
1912
- VALUES (@workflow_name, @run_id, @snapshot, @createdAt, @updatedAt);`;
1913
+ WHEN NOT MATCHED THEN INSERT (workflow_name, run_id, resourceId, snapshot, [createdAt], [updatedAt])
1914
+ VALUES (@workflow_name, @run_id, @resourceId, @snapshot, @createdAt, @updatedAt);`;
1913
1915
  await request.query(mergeSql);
1914
1916
  } catch (error) {
1915
1917
  throw new MastraError(
@@ -2294,9 +2296,10 @@ var MSSQLStore = class extends MastraStorage {
2294
2296
  async persistWorkflowSnapshot({
2295
2297
  workflowName,
2296
2298
  runId,
2299
+ resourceId,
2297
2300
  snapshot
2298
2301
  }) {
2299
- return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
2302
+ return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
2300
2303
  }
2301
2304
  async loadWorkflowSnapshot({
2302
2305
  workflowName,