@mastra/dsql 1.3.5-alpha.0 → 1.4.0-alpha.0

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
@@ -2185,6 +2185,57 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
2185
2185
  }, error);
2186
2186
  });
2187
2187
  }
2188
+ async updateThreadResourceId({ threadId, resourceId }) {
2189
+ const threadTableName = getTableName({
2190
+ indexName: TABLE_THREADS,
2191
+ schemaName: getSchemaName(this.#schema)
2192
+ });
2193
+ const messagesTableName = getTableName({
2194
+ indexName: TABLE_MESSAGES,
2195
+ schemaName: getSchemaName(this.#schema)
2196
+ });
2197
+ const { result } = await withRetry(async () => {
2198
+ return await this.#db.client.tx(async (t) => {
2199
+ const thread = await t.oneOrNone(`SELECT * FROM ${threadTableName} WHERE id = $1`, [threadId]);
2200
+ if (!thread) throw new Error(`Thread "${threadId}" not found`);
2201
+ const normalized = {
2202
+ id: thread.id,
2203
+ resourceId: thread.resourceId,
2204
+ title: thread.title,
2205
+ metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata,
2206
+ createdAt: thread.createdAtZ || thread.createdAt,
2207
+ updatedAt: thread.updatedAtZ || thread.updatedAt
2208
+ };
2209
+ if (thread.resourceId === resourceId) return normalized;
2210
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2211
+ await t.none(`UPDATE ${threadTableName} SET "resourceId" = $1, "updatedAt" = $2::timestamp, "updatedAtZ" = $3::timestamptz WHERE id = $4`, [
2212
+ resourceId,
2213
+ now,
2214
+ now,
2215
+ threadId
2216
+ ]);
2217
+ await t.none(`UPDATE ${messagesTableName} SET "resourceId" = $1 WHERE thread_id = $2`, [resourceId, threadId]);
2218
+ return {
2219
+ ...normalized,
2220
+ resourceId,
2221
+ updatedAt: new Date(now)
2222
+ };
2223
+ });
2224
+ }, { onRetry: (error, attempt, delay) => {
2225
+ this.logger?.warn?.(`updateThreadResourceId retry ${attempt} for ${threadId} after ${delay}ms: ${error.message}`);
2226
+ } }).catch((error) => {
2227
+ throw new MastraError({
2228
+ id: createStorageErrorId("DSQL", "UPDATE_THREAD_RESOURCE_ID", "FAILED"),
2229
+ domain: ErrorDomain.STORAGE,
2230
+ category: ErrorCategory.THIRD_PARTY,
2231
+ details: {
2232
+ threadId,
2233
+ resourceId
2234
+ }
2235
+ }, error);
2236
+ });
2237
+ return result;
2238
+ }
2188
2239
  /**
2189
2240
  * Fetches the messages named by `include` together with their surrounding context.
2190
2241
  *