@mastra/mssql 1.7.0-alpha.0 → 1.7.0-alpha.2
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 +28 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +24 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +9 -2
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2392,7 +2392,7 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2392
2392
|
text: `Thread ${id} not found`,
|
|
2393
2393
|
details: {
|
|
2394
2394
|
threadId: id,
|
|
2395
|
-
title
|
|
2395
|
+
title: title ?? null
|
|
2396
2396
|
}
|
|
2397
2397
|
});
|
|
2398
2398
|
const mergedMetadata = {
|
|
@@ -2411,7 +2411,7 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2411
2411
|
WHERE id = @id`;
|
|
2412
2412
|
const req = this.pool.request();
|
|
2413
2413
|
req.input("id", id);
|
|
2414
|
-
req.input("title", title);
|
|
2414
|
+
req.input("title", title ?? existingThread.title);
|
|
2415
2415
|
req.input("metadata", JSON.stringify(mergedMetadata));
|
|
2416
2416
|
req.input("updatedAt", /* @__PURE__ */ new Date());
|
|
2417
2417
|
const result = await req.query(sql);
|
|
@@ -2427,7 +2427,7 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2427
2427
|
text: `Thread ${id} not found after update`,
|
|
2428
2428
|
details: {
|
|
2429
2429
|
threadId: id,
|
|
2430
|
-
title
|
|
2430
|
+
title: title ?? null
|
|
2431
2431
|
}
|
|
2432
2432
|
});
|
|
2433
2433
|
return {
|
|
@@ -2443,7 +2443,7 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2443
2443
|
category: ErrorCategory.THIRD_PARTY,
|
|
2444
2444
|
details: {
|
|
2445
2445
|
threadId: id,
|
|
2446
|
-
title
|
|
2446
|
+
title: title ?? null
|
|
2447
2447
|
}
|
|
2448
2448
|
}, error);
|
|
2449
2449
|
}
|
|
@@ -2487,7 +2487,14 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2487
2487
|
return diff !== 0 ? diff : a.id.localeCompare(b.id);
|
|
2488
2488
|
});
|
|
2489
2489
|
}
|
|
2490
|
-
|
|
2490
|
+
/**
|
|
2491
|
+
* Fetches the messages named by `include` together with their surrounding context.
|
|
2492
|
+
*
|
|
2493
|
+
* @param include - Message ids to pin, each with an optional before/after window.
|
|
2494
|
+
* @param resourceId - When set, restricts both the pinned messages and their context
|
|
2495
|
+
* to that resource so an id from another resource returns nothing.
|
|
2496
|
+
*/
|
|
2497
|
+
async _getIncludedMessages({ include, resourceId }) {
|
|
2491
2498
|
if (!include || include.length === 0) return null;
|
|
2492
2499
|
const unionQueries = [];
|
|
2493
2500
|
const paramValues = [];
|
|
@@ -2497,6 +2504,7 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2497
2504
|
indexName: TABLE_MESSAGES,
|
|
2498
2505
|
schemaName: getSchemaName(this.schema)
|
|
2499
2506
|
});
|
|
2507
|
+
const resourceCondition = resourceId ? ` AND [resourceId] = @presource` : "";
|
|
2500
2508
|
for (const inc of include) {
|
|
2501
2509
|
const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
|
|
2502
2510
|
const pId = `@p${paramIdx}`;
|
|
@@ -2515,7 +2523,7 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2515
2523
|
FROM (
|
|
2516
2524
|
SELECT *, ROW_NUMBER() OVER (ORDER BY [createdAt] ASC) as row_num
|
|
2517
2525
|
FROM ${tableName}
|
|
2518
|
-
WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId})
|
|
2526
|
+
WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId}${resourceCondition})${resourceCondition}
|
|
2519
2527
|
) AS m
|
|
2520
2528
|
WHERE m.id = ${pId}
|
|
2521
2529
|
OR EXISTS (
|
|
@@ -2523,7 +2531,7 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2523
2531
|
FROM (
|
|
2524
2532
|
SELECT *, ROW_NUMBER() OVER (ORDER BY [createdAt] ASC) as row_num
|
|
2525
2533
|
FROM ${tableName}
|
|
2526
|
-
WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId})
|
|
2534
|
+
WHERE [thread_id] = (SELECT thread_id FROM ${tableName} WHERE id = ${pId}${resourceCondition})${resourceCondition}
|
|
2527
2535
|
) AS target
|
|
2528
2536
|
WHERE target.id = ${pId}
|
|
2529
2537
|
AND (
|
|
@@ -2547,6 +2555,7 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2547
2555
|
`;
|
|
2548
2556
|
const req = this.pool.request();
|
|
2549
2557
|
for (let i = 0; i < paramValues.length; ++i) req.input(paramNames[i], paramValues[i]);
|
|
2558
|
+
if (resourceId) req.input("presource", resourceId);
|
|
2550
2559
|
const includedRows = (await req.query(finalQuery)).recordset || [];
|
|
2551
2560
|
const seen = /* @__PURE__ */ new Set();
|
|
2552
2561
|
return includedRows.filter((row) => {
|
|
@@ -2646,7 +2655,10 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2646
2655
|
hasMore: false
|
|
2647
2656
|
};
|
|
2648
2657
|
if (perPage === 0 && include && include.length > 0) {
|
|
2649
|
-
const includeMessages = await this._getIncludedMessages({
|
|
2658
|
+
const includeMessages = await this._getIncludedMessages({
|
|
2659
|
+
include,
|
|
2660
|
+
resourceId
|
|
2661
|
+
});
|
|
2650
2662
|
const messages = this._parseAndFormatMessages(includeMessages ?? [], "v2");
|
|
2651
2663
|
return {
|
|
2652
2664
|
messages: this._sortMessages(messages, field, direction),
|
|
@@ -2683,7 +2695,10 @@ var MemoryMSSQL = class MemoryMSSQL extends MemoryStorage {
|
|
|
2683
2695
|
};
|
|
2684
2696
|
if (include?.length) {
|
|
2685
2697
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
2686
|
-
(await this._getIncludedMessages({
|
|
2698
|
+
(await this._getIncludedMessages({
|
|
2699
|
+
include,
|
|
2700
|
+
resourceId
|
|
2701
|
+
}))?.forEach((msg) => {
|
|
2687
2702
|
if (!messageIds.has(msg.id)) {
|
|
2688
2703
|
messages.push(msg);
|
|
2689
2704
|
messageIds.add(msg.id);
|