@mastra/mssql 1.7.0-alpha.0 → 1.7.0-alpha.1

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/mssql
2
2
 
3
+ ## 1.7.0-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed resource-scoped message includes across storage adapters so included context cannot cross resource boundaries. ([#20984](https://github.com/mastra-ai/mastra/pull/20984))
8
+
9
+ - Updated dependencies [[`6445eba`](https://github.com/mastra-ai/mastra/commit/6445eba6020abac681aba1cc9289f446cb400cbe), [`df31eb0`](https://github.com/mastra-ai/mastra/commit/df31eb0c7087d782a0d9346e467f9a4af4b0eef6), [`fcd0667`](https://github.com/mastra-ai/mastra/commit/fcd0667a4e378be35c9a1b1eb19cce78fbfd7282), [`bab06b1`](https://github.com/mastra-ai/mastra/commit/bab06b18923873a584bdfc71a6b4ec7fb4727fb7)]:
10
+ - @mastra/core@1.58.0-alpha.5
11
+
3
12
  ## 1.7.0-alpha.0
4
13
 
5
14
  ### Minor Changes
@@ -3,7 +3,7 @@ name: mastra-mssql
3
3
  description: Documentation for @mastra/mssql. Use when working with @mastra/mssql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mssql"
6
- version: "1.7.0-alpha.0"
6
+ version: "1.7.0-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.0-alpha.0",
2
+ "version": "1.7.0-alpha.1",
3
3
  "package": "@mastra/mssql",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -2511,7 +2511,14 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
2511
2511
  return diff !== 0 ? diff : a.id.localeCompare(b.id);
2512
2512
  });
2513
2513
  }
2514
- async _getIncludedMessages({ include }) {
2514
+ /**
2515
+ * Fetches the messages named by `include` together with their surrounding context.
2516
+ *
2517
+ * @param include - Message ids to pin, each with an optional before/after window.
2518
+ * @param resourceId - When set, restricts both the pinned messages and their context
2519
+ * to that resource so an id from another resource returns nothing.
2520
+ */
2521
+ async _getIncludedMessages({ include, resourceId }) {
2515
2522
  if (!include || include.length === 0) return null;
2516
2523
  const unionQueries = [];
2517
2524
  const paramValues = [];
@@ -2521,6 +2528,7 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
2521
2528
  indexName: _mastra_core_storage.TABLE_MESSAGES,
2522
2529
  schemaName: getSchemaName(this.schema)
2523
2530
  });
2531
+ const resourceCondition = resourceId ? ` AND [resourceId] = @presource` : "";
2524
2532
  for (const inc of include) {
2525
2533
  const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
2526
2534
  const pId = `@p${paramIdx}`;
@@ -2539,7 +2547,7 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
2539
2547
  FROM (
2540
2548
  SELECT *, ROW_NUMBER() OVER (ORDER BY [createdAt] ASC) as row_num
2541
2549
  FROM ${tableName}
2542
- WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId})
2550
+ WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId}${resourceCondition})${resourceCondition}
2543
2551
  ) AS m
2544
2552
  WHERE m.id = ${pId}
2545
2553
  OR EXISTS (
@@ -2547,7 +2555,7 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
2547
2555
  FROM (
2548
2556
  SELECT *, ROW_NUMBER() OVER (ORDER BY [createdAt] ASC) as row_num
2549
2557
  FROM ${tableName}
2550
- WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId})
2558
+ WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId}${resourceCondition})${resourceCondition}
2551
2559
  ) AS target
2552
2560
  WHERE target.id = ${pId}
2553
2561
  AND (
@@ -2571,6 +2579,7 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
2571
2579
  `;
2572
2580
  const req = this.pool.request();
2573
2581
  for (let i = 0; i < paramValues.length; ++i) req.input(paramNames[i], paramValues[i]);
2582
+ if (resourceId) req.input("presource", resourceId);
2574
2583
  const includedRows = (await req.query(finalQuery)).recordset || [];
2575
2584
  const seen = /* @__PURE__ */ new Set();
2576
2585
  return includedRows.filter((row) => {
@@ -2670,7 +2679,10 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
2670
2679
  hasMore: false
2671
2680
  };
2672
2681
  if (perPage === 0 && include && include.length > 0) {
2673
- const includeMessages = await this._getIncludedMessages({ include });
2682
+ const includeMessages = await this._getIncludedMessages({
2683
+ include,
2684
+ resourceId
2685
+ });
2674
2686
  const messages = this._parseAndFormatMessages(includeMessages ?? [], "v2");
2675
2687
  return {
2676
2688
  messages: this._sortMessages(messages, field, direction),
@@ -2707,7 +2719,10 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
2707
2719
  };
2708
2720
  if (include?.length) {
2709
2721
  const messageIds = new Set(messages.map((m) => m.id));
2710
- (await this._getIncludedMessages({ include }))?.forEach((msg) => {
2722
+ (await this._getIncludedMessages({
2723
+ include,
2724
+ resourceId
2725
+ }))?.forEach((msg) => {
2711
2726
  if (!messageIds.has(msg.id)) {
2712
2727
  messages.push(msg);
2713
2728
  messageIds.add(msg.id);