@mastra/mssql 1.7.0-alpha.0 → 1.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 +9 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +20 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +7 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -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);
|