@mastra/mysql 0.6.0 → 0.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,59 @@
1
1
  # @mastra/mysql
2
2
 
3
+ ## 0.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
+
12
+ ## 0.7.0-alpha.0
13
+
14
+ ### Minor Changes
15
+
16
+ - Added experiment provenance and grouping support to the LibSQL, MongoDB, MySQL, PostgreSQL, and Spanner storage adapters. These fields remain available for later grouping and filtering. ([#20645](https://github.com/mastra-ai/mastra/pull/20645))
17
+
18
+ ```ts
19
+ import { PostgresStore } from '@mastra/pg';
20
+
21
+ const storage = new PostgresStore({
22
+ id: 'postgres-storage',
23
+ connectionString: process.env.DATABASE_URL!,
24
+ });
25
+
26
+ await dataset.startExperiment({
27
+ task,
28
+ scorers,
29
+ provenance: { source: 'github', sourceVersion: 'abc123' },
30
+ grouping: { experimentSetId: 'benchmark-1', variantId: 'candidate', trialIndex: 0 },
31
+ });
32
+ ```
33
+
34
+ - Memory list reads now surface database errors instead of silently returning empty results. ([#17910](https://github.com/mastra-ai/mastra/pull/17910))
35
+
36
+ Previously, the paginated memory reads (`listThreads`, `listMessages`, `listMessagesByResourceId`, and `listMessagesById`) caught backend failures, logged them, and returned an empty payload like `{ threads: [], total: 0, hasMore: false }`. A transient outage (locked table, dropped connection) was therefore indistinguishable from a genuinely empty result, so an agent reading conversation history during a brief failure would treat it as "no history" and could overwrite real state. These methods now re-throw the failure as a `MastraError`. Validation (USER) errors and genuinely empty results are unchanged.
37
+
38
+ **Behavior change**
39
+
40
+ Callers that previously received an empty result on a backend failure will now receive a thrown `MastraError`. If you call these read methods directly (rather than through an agent, which already surfaces errors), wrap them so a transient outage doesn't crash the caller:
41
+
42
+ ```ts
43
+ try {
44
+ const { threads } = await storage.listThreads({ resourceId });
45
+ // ...use threads
46
+ } catch (error) {
47
+ // a real backend failure. Decide whether to retry, surface, or degrade.
48
+ // An empty thread list no longer hides here; it only means "no threads".
49
+ }
50
+ ```
51
+
52
+ ### Patch Changes
53
+
54
+ - Updated dependencies [[`e7109ee`](https://github.com/mastra-ai/mastra/commit/e7109ee6f731bacc79c885906f3c7dca8d8f013a), [`772c0c8`](https://github.com/mastra-ai/mastra/commit/772c0c897cec383258de2e6178147f8014767c7b), [`578bf2e`](https://github.com/mastra-ai/mastra/commit/578bf2e6a88e9d5b8bf502204e15a95dfbb679ae), [`06b2d87`](https://github.com/mastra-ai/mastra/commit/06b2d87e63bcdd0ed59215c6789692b9b12de376), [`ac01d63`](https://github.com/mastra-ai/mastra/commit/ac01d6355974aec73fdb8781449ed12bac582094), [`a810a05`](https://github.com/mastra-ai/mastra/commit/a810a058f62ad407cfc1701e0be36ae91145d7cf), [`f8da216`](https://github.com/mastra-ai/mastra/commit/f8da21633e7eb0e31c9ce0fc30567870d19416d3), [`6104347`](https://github.com/mastra-ai/mastra/commit/61043473ba6bfd0a25156824e853e13165562e6c), [`45bfb88`](https://github.com/mastra-ai/mastra/commit/45bfb88fd52f1dd3be20e2a38905777c96499c90), [`e3b9307`](https://github.com/mastra-ai/mastra/commit/e3b9307098daefbfae2a52ae2ef51bc9fc701190), [`d6834c5`](https://github.com/mastra-ai/mastra/commit/d6834c5a7866b16734d23900163c2414ed70d791), [`c52d346`](https://github.com/mastra-ai/mastra/commit/c52d3462ec831a5d95926ecd3d3373f5928ad2e5), [`0023e79`](https://github.com/mastra-ai/mastra/commit/0023e7919431078280abd11c89d1edeae35fcc69), [`c2ad51e`](https://github.com/mastra-ai/mastra/commit/c2ad51e2467f901eecba8c9f4a45e22a50bd7c18), [`3dc97ea`](https://github.com/mastra-ai/mastra/commit/3dc97ea415fad353b48a13095fad1835933cc12a), [`3d01cd3`](https://github.com/mastra-ai/mastra/commit/3d01cd387321b6f9c5cac31d487c84bf51b19c78), [`7bf3086`](https://github.com/mastra-ai/mastra/commit/7bf308663f0115ca74ad20554ade740f06640859), [`a8dd139`](https://github.com/mastra-ai/mastra/commit/a8dd1391a9fe9a6632c25809ef236980afa9a020), [`e5786be`](https://github.com/mastra-ai/mastra/commit/e5786be02bb903073082bd9d6da880ebaacc343f), [`2093fbd`](https://github.com/mastra-ai/mastra/commit/2093fbd53bb744bae19ec89f6d73db9a66fbe8a7), [`e7a5da4`](https://github.com/mastra-ai/mastra/commit/e7a5da4ef8e4dd452d2f232961b4e682a85ffe43), [`7b4393d`](https://github.com/mastra-ai/mastra/commit/7b4393d557411fdcf07b0e30e5acaf7cc85154ae)]:
55
+ - @mastra/core@1.58.0-alpha.1
56
+
3
57
  ## 0.6.0
4
58
 
5
59
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -2838,15 +2838,28 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
2838
2838
  * Returns default index definitions for the experiments domain tables.
2839
2839
  */
2840
2840
  static getDefaultIndexDefs(_prefix = "") {
2841
- return [{
2842
- name: "idx_experiments_org_project",
2843
- table: _mastra_core_storage.TABLE_EXPERIMENTS,
2844
- columns: ["organizationId", "projectId"]
2845
- }, {
2846
- name: "idx_experiment_results_org_project",
2847
- table: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
2848
- columns: ["organizationId", "projectId"]
2849
- }];
2841
+ return [
2842
+ {
2843
+ name: "idx_experiments_grouping",
2844
+ table: _mastra_core_storage.TABLE_EXPERIMENTS,
2845
+ columns: [
2846
+ "experimentSetId",
2847
+ "comparisonId",
2848
+ "variantId",
2849
+ "trialIndex"
2850
+ ]
2851
+ },
2852
+ {
2853
+ name: "idx_experiments_org_project",
2854
+ table: _mastra_core_storage.TABLE_EXPERIMENTS,
2855
+ columns: ["organizationId", "projectId"]
2856
+ },
2857
+ {
2858
+ name: "idx_experiment_results_org_project",
2859
+ table: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
2860
+ columns: ["organizationId", "projectId"]
2861
+ }
2862
+ ];
2850
2863
  }
2851
2864
  /**
2852
2865
  * Exports DDL statements for all managed tables.
@@ -2902,7 +2915,13 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
2902
2915
  ifNotExists: [
2903
2916
  "agentVersion",
2904
2917
  "organizationId",
2905
- "projectId"
2918
+ "projectId",
2919
+ "provenance",
2920
+ "runnerAttestation",
2921
+ "experimentSetId",
2922
+ "comparisonId",
2923
+ "variantId",
2924
+ "trialIndex"
2906
2925
  ]
2907
2926
  });
2908
2927
  await this.operations.alterTable({
@@ -2934,6 +2953,12 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
2934
2953
  name: row.name ?? void 0,
2935
2954
  description: row.description ?? void 0,
2936
2955
  metadata: parseJSON$2(row.metadata),
2956
+ provenance: parseJSON$2(row.provenance) ?? null,
2957
+ runnerAttestation: parseJSON$2(row.runnerAttestation) ?? null,
2958
+ experimentSetId: row.experimentSetId ?? null,
2959
+ comparisonId: row.comparisonId ?? null,
2960
+ variantId: row.variantId ?? null,
2961
+ trialIndex: row.trialIndex ?? null,
2937
2962
  status: row.status,
2938
2963
  totalItems: row.totalItems,
2939
2964
  succeededCount: row.succeededCount,
@@ -2985,6 +3010,12 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
2985
3010
  name: input.name ?? null,
2986
3011
  description: input.description ?? null,
2987
3012
  metadata: input.metadata ? JSON.stringify(input.metadata) : null,
3013
+ provenance: input.provenance ? JSON.stringify(input.provenance) : null,
3014
+ runnerAttestation: input.runnerAttestation ? JSON.stringify(input.runnerAttestation) : null,
3015
+ experimentSetId: input.experimentSetId ?? null,
3016
+ comparisonId: input.comparisonId ?? null,
3017
+ variantId: input.variantId ?? null,
3018
+ trialIndex: input.trialIndex ?? null,
2988
3019
  status: "pending",
2989
3020
  totalItems: input.totalItems,
2990
3021
  succeededCount: 0,
@@ -3008,6 +3039,12 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
3008
3039
  name: input.name,
3009
3040
  description: input.description,
3010
3041
  metadata: input.metadata,
3042
+ provenance: input.provenance ?? null,
3043
+ runnerAttestation: input.runnerAttestation ?? null,
3044
+ experimentSetId: input.experimentSetId ?? null,
3045
+ comparisonId: input.comparisonId ?? null,
3046
+ variantId: input.variantId ?? null,
3047
+ trialIndex: input.trialIndex ?? null,
3011
3048
  status: "pending",
3012
3049
  totalItems: input.totalItems,
3013
3050
  succeededCount: 0,
@@ -3104,6 +3141,22 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
3104
3141
  conditions.push(`${quoteIdentifier("status", "column name")} = ?`);
3105
3142
  params.push(args.status);
3106
3143
  }
3144
+ if (args.experimentSetId !== void 0) {
3145
+ conditions.push(`${quoteIdentifier("experimentSetId", "column name")} = ?`);
3146
+ params.push(args.experimentSetId);
3147
+ }
3148
+ if (args.comparisonId !== void 0) {
3149
+ conditions.push(`${quoteIdentifier("comparisonId", "column name")} = ?`);
3150
+ params.push(args.comparisonId);
3151
+ }
3152
+ if (args.variantId !== void 0) {
3153
+ conditions.push(`${quoteIdentifier("variantId", "column name")} = ?`);
3154
+ params.push(args.variantId);
3155
+ }
3156
+ if (args.trialIndex !== void 0) {
3157
+ conditions.push(`${quoteIdentifier("trialIndex", "column name")} = ?`);
3158
+ params.push(args.trialIndex);
3159
+ }
3107
3160
  if (args.filters) {
3108
3161
  const { organizationId, projectId } = args.filters;
3109
3162
  if (organizationId !== void 0) {
@@ -4869,9 +4922,17 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
4869
4922
  if (row.type && row.type !== "v2") message.type = row.type;
4870
4923
  return message;
4871
4924
  }
4872
- async fetchMessagesForThread(threadId, limit) {
4873
- let sql = `SELECT id, thread_id, content, role, type, createdAt, resourceId FROM ${formatTableName(_mastra_core_storage.TABLE_MESSAGES)} WHERE ${quoteIdentifier("thread_id", "column name")} = ? ORDER BY ${quoteIdentifier("createdAt", "column name")} ASC`;
4874
- const params = [threadId];
4925
+ /**
4926
+ * Loads a thread's messages in chronological order.
4927
+ *
4928
+ * @param threadId - Thread to read.
4929
+ * @param limit - Optional cap on the number of rows.
4930
+ * @param resourceId - When set, returns only the rows owned by that resource.
4931
+ */
4932
+ async fetchMessagesForThread(threadId, limit, resourceId) {
4933
+ const resourceCondition = resourceId ? ` AND ${quoteIdentifier("resourceId", "column name")} = ?` : "";
4934
+ let sql = `SELECT id, thread_id, content, role, type, createdAt, resourceId FROM ${formatTableName(_mastra_core_storage.TABLE_MESSAGES)} WHERE ${quoteIdentifier("thread_id", "column name")} = ?${resourceCondition} ORDER BY ${quoteIdentifier("createdAt", "column name")} ASC`;
4935
+ const params = resourceId ? [threadId, resourceId] : [threadId];
4875
4936
  if (limit && limit > 0) {
4876
4937
  sql += ` LIMIT ?`;
4877
4938
  params.push(limit);
@@ -4882,15 +4943,20 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
4882
4943
  /**
4883
4944
  * Fetches included messages by ID, discovering their thread automatically.
4884
4945
  * This handles cross-thread includes where the include item doesn't specify a threadId.
4946
+ *
4947
+ * @param include - Message ids to pin, each with an optional before/after window.
4948
+ * @param resourceId - When set, restricts both the pinned messages and their context
4949
+ * to that resource so an id from another resource returns nothing.
4885
4950
  */
4886
- async _getIncludedMessages({ include }) {
4951
+ async _getIncludedMessages({ include, resourceId }) {
4887
4952
  if (!include || include.length === 0) return null;
4888
4953
  const tableName = formatTableName(_mastra_core_storage.TABLE_MESSAGES);
4889
4954
  const selectColumns = `id, thread_id, content, role, type, createdAt, resourceId`;
4955
+ const resourceCondition = resourceId ? ` AND m.${quoteIdentifier("resourceId", "column name")} = ?` : "";
4890
4956
  const targetIds = include.map((inc) => inc.id).filter(Boolean);
4891
4957
  if (targetIds.length === 0) return null;
4892
4958
  const idPlaceholders = targetIds.map(() => "?").join(", ");
4893
- const [targetRows] = await this.pool.execute(`SELECT id, thread_id, createdAt FROM ${tableName} WHERE id IN (${idPlaceholders})`, targetIds);
4959
+ const [targetRows] = await this.pool.execute(`SELECT id, thread_id, createdAt FROM ${tableName} WHERE id IN (${idPlaceholders})${resourceId ? ` AND ${quoteIdentifier("resourceId", "column name")} = ?` : ""}`, resourceId ? [...targetIds, resourceId] : targetIds);
4894
4960
  if (!targetRows || targetRows.length === 0) return null;
4895
4961
  const targetMap = new Map(targetRows.map((r) => [r.id, {
4896
4962
  threadId: r.thread_id,
@@ -4908,21 +4974,23 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
4908
4974
  SELECT ${selectColumns}
4909
4975
  FROM ${tableName} m
4910
4976
  WHERE m.thread_id = ?
4911
- AND m.createdAt <= ?
4977
+ AND m.createdAt <= ?${resourceCondition}
4912
4978
  ORDER BY m.createdAt DESC, m.id DESC
4913
4979
  LIMIT ${prevLimit}
4914
4980
  )`);
4915
4981
  params.push(target.threadId, target.createdAt);
4982
+ if (resourceId) params.push(resourceId);
4916
4983
  if (nextLimit > 0) {
4917
4984
  unionQueries.push(`(
4918
4985
  SELECT ${selectColumns}
4919
4986
  FROM ${tableName} m
4920
4987
  WHERE m.thread_id = ?
4921
- AND m.createdAt > ?
4988
+ AND m.createdAt > ?${resourceCondition}
4922
4989
  ORDER BY m.createdAt ASC, m.id ASC
4923
4990
  LIMIT ${nextLimit}
4924
4991
  )`);
4925
4992
  params.push(target.threadId, target.createdAt);
4993
+ if (resourceId) params.push(resourceId);
4926
4994
  }
4927
4995
  }
4928
4996
  if (unionQueries.length === 0) return null;
@@ -4930,7 +4998,17 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
4930
4998
  const [rows] = await this.pool.execute(finalQuery, params);
4931
4999
  return rows;
4932
5000
  }
4933
- async collectIncludeMessages({ threadId, include, messagesByThread }) {
5001
+ /**
5002
+ * Resolves include items against loaded threads, adding each pinned message and its
5003
+ * before/after window.
5004
+ *
5005
+ * @param threadId - Thread used when an include item names no thread of its own.
5006
+ * @param include - Message ids to pin, each with an optional before/after window.
5007
+ * @param messagesByThread - Cache of thread snapshots, reused and filled as threads load.
5008
+ * @param resourceId - When set, restricts both the pinned messages and their context
5009
+ * to that resource so an id from another resource returns nothing.
5010
+ */
5011
+ async collectIncludeMessages({ threadId, include, messagesByThread, resourceId }) {
4934
5012
  if (!include?.length) return [];
4935
5013
  const includeMessages = [];
4936
5014
  const seenIds = /* @__PURE__ */ new Set();
@@ -4938,18 +5016,18 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
4938
5016
  const resolvedThreadIds = /* @__PURE__ */ new Map();
4939
5017
  if (unresolvedIds.length > 0) {
4940
5018
  const placeholders = unresolvedIds.map(() => "?").join(", ");
4941
- const [rows] = await this.pool.execute(`SELECT id, thread_id FROM ${formatTableName(_mastra_core_storage.TABLE_MESSAGES)} WHERE id IN (${placeholders})`, unresolvedIds);
5019
+ const [rows] = await this.pool.execute(`SELECT id, thread_id FROM ${formatTableName(_mastra_core_storage.TABLE_MESSAGES)} WHERE id IN (${placeholders})${resourceId ? ` AND ${quoteIdentifier("resourceId", "column name")} = ?` : ""}`, resourceId ? [...unresolvedIds, resourceId] : unresolvedIds);
4942
5020
  for (const row of rows) resolvedThreadIds.set(row.id, row.thread_id);
4943
5021
  }
4944
5022
  for (const inc of include) {
4945
5023
  const targetThreadId = inc.threadId ?? resolvedThreadIds.get(inc.id) ?? threadId;
4946
5024
  let threadMessages = messagesByThread.get(targetThreadId);
4947
5025
  if (!threadMessages) {
4948
- threadMessages = (await this.fetchMessagesForThread(targetThreadId)).map((row) => this.mapMessage(row));
5026
+ threadMessages = (await this.fetchMessagesForThread(targetThreadId, void 0, resourceId)).map((row) => this.mapMessage(row));
4949
5027
  messagesByThread.set(targetThreadId, threadMessages);
4950
5028
  }
4951
5029
  if (!threadMessages.some((message) => message.id === inc.id) || (inc.withPreviousMessages ?? 0) > 0 || (inc.withNextMessages ?? 0) > 0 || threadMessages.length < (inc.withNextMessages ?? 0) + (inc.withPreviousMessages ?? 0) + 1) {
4952
- threadMessages = (await this.fetchMessagesForThread(targetThreadId)).map((row) => this.mapMessage(row));
5030
+ threadMessages = (await this.fetchMessagesForThread(targetThreadId, void 0, resourceId)).map((row) => this.mapMessage(row));
4953
5031
  messagesByThread.set(targetThreadId, threadMessages);
4954
5032
  }
4955
5033
  const targetIndex = threadMessages.findIndex((msg) => msg.id === inc.id);
@@ -5066,12 +5144,16 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
5066
5144
  hasMore: perPageInput === false ? false : offset + perPageNormalized < total
5067
5145
  };
5068
5146
  } catch (error) {
5069
- throw new _mastra_core_error.MastraError({
5070
- id: "MYSQL_MEMORY_LIST_THREADS_FAILED",
5147
+ if (error instanceof _mastra_core_error.MastraError && error.category === _mastra_core_error.ErrorCategory.USER) throw error;
5148
+ const mastraError = new _mastra_core_error.MastraError({
5149
+ id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "LIST_THREADS", "FAILED"),
5071
5150
  domain: _mastra_core_error.ErrorDomain.STORAGE,
5072
5151
  category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
5073
5152
  details: { filter: JSON.stringify(filter ?? {}) }
5074
5153
  }, error);
5154
+ this.logger?.error?.(mastraError.toString());
5155
+ this.logger?.trackException?.(mastraError);
5156
+ throw mastraError;
5075
5157
  }
5076
5158
  }
5077
5159
  async getThreadsByResourceId(args) {
@@ -5539,7 +5621,10 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
5539
5621
  hasMore: false
5540
5622
  };
5541
5623
  if (perPage === 0 && include && include.length > 0) {
5542
- const includeRows = await this._getIncludedMessages({ include });
5624
+ const includeRows = await this._getIncludedMessages({
5625
+ include,
5626
+ resourceId
5627
+ });
5543
5628
  if (!includeRows || includeRows.length === 0) return {
5544
5629
  messages: [],
5545
5630
  total: 0,
@@ -5577,7 +5662,8 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
5577
5662
  const includeMessages = await this.collectIncludeMessages({
5578
5663
  threadId: primaryThreadId,
5579
5664
  include,
5580
- messagesByThread
5665
+ messagesByThread,
5666
+ resourceId
5581
5667
  });
5582
5668
  const combinedMap = /* @__PURE__ */ new Map();
5583
5669
  for (const msg of paginatedMain) combinedMap.set(msg.id, msg);
@@ -5597,8 +5683,9 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
5597
5683
  hasMore: metadataFilter || !include?.length || mainThreadMessageCount < total ? baseHasMore : false
5598
5684
  };
5599
5685
  } catch (error) {
5686
+ if (error instanceof _mastra_core_error.MastraError && error.category === _mastra_core_error.ErrorCategory.USER) throw error;
5600
5687
  const mastraError = new _mastra_core_error.MastraError({
5601
- id: "MYSQL_MEMORY_GET_MESSAGES_PAGINATED_FAILED",
5688
+ id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "LIST_MESSAGES", "FAILED"),
5602
5689
  domain: _mastra_core_error.ErrorDomain.STORAGE,
5603
5690
  category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
5604
5691
  details: {
@@ -5609,13 +5696,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
5609
5696
  }, error);
5610
5697
  this.logger?.error?.(mastraError.toString());
5611
5698
  this.logger?.trackException?.(mastraError);
5612
- return {
5613
- messages: [],
5614
- total: 0,
5615
- page,
5616
- perPage,
5617
- hasMore: false
5618
- };
5699
+ throw mastraError;
5619
5700
  }
5620
5701
  }
5621
5702
  async listMessagesByResourceId(args) {
@@ -5670,7 +5751,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
5670
5751
  if (include && include.length > 0) {
5671
5752
  const validInclude = (await Promise.all(include.map(async (inc) => {
5672
5753
  if (inc.threadId) return inc;
5673
- const [msgRows] = await this.pool.execute(`SELECT thread_id FROM ${tableName} WHERE id = ? LIMIT 1`, [inc.id]);
5754
+ const [msgRows] = await this.pool.execute(`SELECT thread_id FROM ${tableName} WHERE id = ? AND ${quoteIdentifier("resourceId", "column name")} = ? LIMIT 1`, [inc.id, resourceId]);
5674
5755
  const threadId = msgRows?.[0]?.thread_id;
5675
5756
  return threadId ? {
5676
5757
  ...inc,
@@ -5682,7 +5763,8 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
5682
5763
  const includeMessages = await this.collectIncludeMessages({
5683
5764
  threadId: validInclude[0].threadId,
5684
5765
  include: validInclude,
5685
- messagesByThread
5766
+ messagesByThread,
5767
+ resourceId
5686
5768
  });
5687
5769
  for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
5688
5770
  messages.push(includeMsg);
@@ -5707,21 +5789,16 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
5707
5789
  hasMore
5708
5790
  };
5709
5791
  } catch (error) {
5792
+ if (error instanceof _mastra_core_error.MastraError && error.category === _mastra_core_error.ErrorCategory.USER) throw error;
5710
5793
  const mastraError = new _mastra_core_error.MastraError({
5711
- id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "LIST_MESSAGES", "FAILED"),
5794
+ id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "LIST_MESSAGES_BY_RESOURCE_ID", "FAILED"),
5712
5795
  domain: _mastra_core_error.ErrorDomain.STORAGE,
5713
5796
  category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
5714
5797
  details: { resourceId }
5715
5798
  }, error);
5716
5799
  this.logger?.error?.(mastraError.toString());
5717
5800
  this.logger?.trackException?.(mastraError);
5718
- return {
5719
- messages: [],
5720
- total: 0,
5721
- page,
5722
- perPage: perPageForResponse,
5723
- hasMore: false
5724
- };
5801
+ throw mastraError;
5725
5802
  }
5726
5803
  }
5727
5804
  async getResourceById({ resourceId }) {