@mastra/mssql 1.7.5 → 1.8.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
@@ -2486,6 +2486,65 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
2486
2486
  }, error);
2487
2487
  }
2488
2488
  }
2489
+ async updateThreadResourceId({ threadId, resourceId }) {
2490
+ const threadsTable = getTableName({
2491
+ indexName: TABLE_THREADS,
2492
+ schemaName: getSchemaName(this.schema)
2493
+ });
2494
+ const messagesTable = getTableName({
2495
+ indexName: TABLE_MESSAGES,
2496
+ schemaName: getSchemaName(this.schema)
2497
+ });
2498
+ const tx = this.pool.transaction();
2499
+ try {
2500
+ await tx.begin();
2501
+ const selectReq = tx.request();
2502
+ selectReq.input("threadId", threadId);
2503
+ const row = (await selectReq.query(`SELECT id, [resourceId], title, metadata, [createdAt], [updatedAt]
2504
+ FROM ${threadsTable} WITH (UPDLOCK, HOLDLOCK)
2505
+ WHERE id = @threadId`)).recordset[0];
2506
+ if (!row) throw new Error(`Thread "${threadId}" not found`);
2507
+ const normalized = {
2508
+ id: row.id,
2509
+ resourceId: row.resourceId,
2510
+ title: row.title,
2511
+ metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
2512
+ createdAt: row.createdAt,
2513
+ updatedAt: row.updatedAt
2514
+ };
2515
+ if (row.resourceId === resourceId) {
2516
+ await tx.commit();
2517
+ return normalized;
2518
+ }
2519
+ const now = /* @__PURE__ */ new Date();
2520
+ const updateThreadReq = tx.request();
2521
+ updateThreadReq.input("resourceId", resourceId);
2522
+ updateThreadReq.input("updatedAt", now);
2523
+ updateThreadReq.input("threadId", threadId);
2524
+ await updateThreadReq.query(`UPDATE ${threadsTable} SET [resourceId] = @resourceId, [updatedAt] = @updatedAt WHERE id = @threadId`);
2525
+ const updateMessagesReq = tx.request();
2526
+ updateMessagesReq.input("resourceId", resourceId);
2527
+ updateMessagesReq.input("threadId", threadId);
2528
+ await updateMessagesReq.query(`UPDATE ${messagesTable} SET [resourceId] = @resourceId WHERE [thread_id] = @threadId`);
2529
+ await tx.commit();
2530
+ return {
2531
+ ...normalized,
2532
+ resourceId,
2533
+ updatedAt: now
2534
+ };
2535
+ } catch (error) {
2536
+ await tx.rollback().catch(() => {});
2537
+ throw new MastraError({
2538
+ id: createStorageErrorId("MSSQL", "UPDATE_THREAD_RESOURCE_ID", "FAILED"),
2539
+ domain: ErrorDomain.STORAGE,
2540
+ category: ErrorCategory.THIRD_PARTY,
2541
+ details: {
2542
+ threadId,
2543
+ resourceId
2544
+ }
2545
+ }, error);
2546
+ }
2547
+ }
2489
2548
  _sortMessages(messages, field, direction) {
2490
2549
  const mult = direction === "ASC" ? 1 : -1;
2491
2550
  return messages.sort((a, b) => {