@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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +59 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +4 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2510,6 +2510,65 @@ var MemoryMSSQL = class MemoryMSSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2510
2510
|
}, error);
|
|
2511
2511
|
}
|
|
2512
2512
|
}
|
|
2513
|
+
async updateThreadResourceId({ threadId, resourceId }) {
|
|
2514
|
+
const threadsTable = getTableName({
|
|
2515
|
+
indexName: _mastra_core_storage.TABLE_THREADS,
|
|
2516
|
+
schemaName: getSchemaName(this.schema)
|
|
2517
|
+
});
|
|
2518
|
+
const messagesTable = getTableName({
|
|
2519
|
+
indexName: _mastra_core_storage.TABLE_MESSAGES,
|
|
2520
|
+
schemaName: getSchemaName(this.schema)
|
|
2521
|
+
});
|
|
2522
|
+
const tx = this.pool.transaction();
|
|
2523
|
+
try {
|
|
2524
|
+
await tx.begin();
|
|
2525
|
+
const selectReq = tx.request();
|
|
2526
|
+
selectReq.input("threadId", threadId);
|
|
2527
|
+
const row = (await selectReq.query(`SELECT id, [resourceId], title, metadata, [createdAt], [updatedAt]
|
|
2528
|
+
FROM ${threadsTable} WITH (UPDLOCK, HOLDLOCK)
|
|
2529
|
+
WHERE id = @threadId`)).recordset[0];
|
|
2530
|
+
if (!row) throw new Error(`Thread "${threadId}" not found`);
|
|
2531
|
+
const normalized = {
|
|
2532
|
+
id: row.id,
|
|
2533
|
+
resourceId: row.resourceId,
|
|
2534
|
+
title: row.title,
|
|
2535
|
+
metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata,
|
|
2536
|
+
createdAt: row.createdAt,
|
|
2537
|
+
updatedAt: row.updatedAt
|
|
2538
|
+
};
|
|
2539
|
+
if (row.resourceId === resourceId) {
|
|
2540
|
+
await tx.commit();
|
|
2541
|
+
return normalized;
|
|
2542
|
+
}
|
|
2543
|
+
const now = /* @__PURE__ */ new Date();
|
|
2544
|
+
const updateThreadReq = tx.request();
|
|
2545
|
+
updateThreadReq.input("resourceId", resourceId);
|
|
2546
|
+
updateThreadReq.input("updatedAt", now);
|
|
2547
|
+
updateThreadReq.input("threadId", threadId);
|
|
2548
|
+
await updateThreadReq.query(`UPDATE ${threadsTable} SET [resourceId] = @resourceId, [updatedAt] = @updatedAt WHERE id = @threadId`);
|
|
2549
|
+
const updateMessagesReq = tx.request();
|
|
2550
|
+
updateMessagesReq.input("resourceId", resourceId);
|
|
2551
|
+
updateMessagesReq.input("threadId", threadId);
|
|
2552
|
+
await updateMessagesReq.query(`UPDATE ${messagesTable} SET [resourceId] = @resourceId WHERE [thread_id] = @threadId`);
|
|
2553
|
+
await tx.commit();
|
|
2554
|
+
return {
|
|
2555
|
+
...normalized,
|
|
2556
|
+
resourceId,
|
|
2557
|
+
updatedAt: now
|
|
2558
|
+
};
|
|
2559
|
+
} catch (error) {
|
|
2560
|
+
await tx.rollback().catch(() => {});
|
|
2561
|
+
throw new _mastra_core_error.MastraError({
|
|
2562
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("MSSQL", "UPDATE_THREAD_RESOURCE_ID", "FAILED"),
|
|
2563
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
2564
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
2565
|
+
details: {
|
|
2566
|
+
threadId,
|
|
2567
|
+
resourceId
|
|
2568
|
+
}
|
|
2569
|
+
}, error);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2513
2572
|
_sortMessages(messages, field, direction) {
|
|
2514
2573
|
const mult = direction === "ASC" ? 1 : -1;
|
|
2515
2574
|
return messages.sort((a, b) => {
|