@mastra/dsql 1.3.0-alpha.0 → 1.3.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/index.cjs +23 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -8
- 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 +3 -3
package/dist/index.js
CHANGED
|
@@ -2100,7 +2100,7 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
2100
2100
|
text: `Thread ${id} not found`,
|
|
2101
2101
|
details: {
|
|
2102
2102
|
threadId: id,
|
|
2103
|
-
title
|
|
2103
|
+
title: title ?? null
|
|
2104
2104
|
}
|
|
2105
2105
|
});
|
|
2106
2106
|
const mergedMetadata = {
|
|
@@ -2110,14 +2110,14 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
2110
2110
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2111
2111
|
const thread = await this.#db.client.one(`UPDATE ${threadTableName}
|
|
2112
2112
|
SET
|
|
2113
|
-
title = $1,
|
|
2113
|
+
title = COALESCE($1, title),
|
|
2114
2114
|
metadata = $2,
|
|
2115
2115
|
"updatedAt" = $3::timestamp,
|
|
2116
2116
|
"updatedAtZ" = $4::timestamptz
|
|
2117
2117
|
WHERE id = $5
|
|
2118
2118
|
RETURNING *
|
|
2119
2119
|
`, [
|
|
2120
|
-
title,
|
|
2120
|
+
title ?? null,
|
|
2121
2121
|
JSON.stringify(mergedMetadata),
|
|
2122
2122
|
now,
|
|
2123
2123
|
now,
|
|
@@ -2141,7 +2141,7 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
2141
2141
|
category: ErrorCategory.THIRD_PARTY,
|
|
2142
2142
|
details: {
|
|
2143
2143
|
threadId: id,
|
|
2144
|
-
title
|
|
2144
|
+
title: title ?? null
|
|
2145
2145
|
}
|
|
2146
2146
|
}, error);
|
|
2147
2147
|
});
|
|
@@ -2172,7 +2172,14 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
2172
2172
|
}, error);
|
|
2173
2173
|
});
|
|
2174
2174
|
}
|
|
2175
|
-
|
|
2175
|
+
/**
|
|
2176
|
+
* Fetches the messages named by `include` together with their surrounding context.
|
|
2177
|
+
*
|
|
2178
|
+
* @param include - Message ids to pin, each with an optional before/after window.
|
|
2179
|
+
* @param resourceId - When set, restricts both the pinned messages and their context
|
|
2180
|
+
* to that resource so an id from another resource returns nothing.
|
|
2181
|
+
*/
|
|
2182
|
+
async _getIncludedMessages({ include, resourceId }) {
|
|
2176
2183
|
if (!include || include.length === 0) return null;
|
|
2177
2184
|
const unionQueries = [];
|
|
2178
2185
|
const params = [];
|
|
@@ -2183,17 +2190,18 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
2183
2190
|
});
|
|
2184
2191
|
for (const inc of include) {
|
|
2185
2192
|
const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
|
|
2193
|
+
const resourceCondition = resourceId ? ` AND "resourceId" = $${paramIdx + 3}` : "";
|
|
2186
2194
|
unionQueries.push(`
|
|
2187
2195
|
SELECT * FROM (
|
|
2188
2196
|
WITH target_thread AS (
|
|
2189
|
-
SELECT thread_id FROM ${tableName} WHERE id = $${paramIdx}
|
|
2197
|
+
SELECT thread_id FROM ${tableName} WHERE id = $${paramIdx}${resourceCondition}
|
|
2190
2198
|
),
|
|
2191
2199
|
ordered_messages AS (
|
|
2192
2200
|
SELECT
|
|
2193
2201
|
*,
|
|
2194
2202
|
ROW_NUMBER() OVER (ORDER BY "createdAt" ASC) as row_num
|
|
2195
2203
|
FROM ${tableName}
|
|
2196
|
-
WHERE thread_id = (SELECT thread_id FROM target_thread)
|
|
2204
|
+
WHERE thread_id = (SELECT thread_id FROM target_thread)${resourceCondition}
|
|
2197
2205
|
)
|
|
2198
2206
|
SELECT
|
|
2199
2207
|
m.id,
|
|
@@ -2219,6 +2227,10 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
2219
2227
|
`);
|
|
2220
2228
|
params.push(id, withPreviousMessages, withNextMessages);
|
|
2221
2229
|
paramIdx += 3;
|
|
2230
|
+
if (resourceId) {
|
|
2231
|
+
params.push(resourceId);
|
|
2232
|
+
paramIdx += 1;
|
|
2233
|
+
}
|
|
2222
2234
|
}
|
|
2223
2235
|
const finalQuery = unionQueries.join(" UNION ALL ") + " ORDER BY \"createdAt\" ASC";
|
|
2224
2236
|
const includedRows = await this.#db.client.manyOrNone(finalQuery, params);
|
|
@@ -2344,7 +2356,10 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
2344
2356
|
};
|
|
2345
2357
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
2346
2358
|
if (include && include.length > 0) {
|
|
2347
|
-
const includeMessages = await this._getIncludedMessages({
|
|
2359
|
+
const includeMessages = await this._getIncludedMessages({
|
|
2360
|
+
include,
|
|
2361
|
+
resourceId
|
|
2362
|
+
});
|
|
2348
2363
|
if (includeMessages) {
|
|
2349
2364
|
for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
|
|
2350
2365
|
messages.push(includeMsg);
|