@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @mastra/dsql
|
|
2
2
|
|
|
3
|
+
## 1.3.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed generated thread titles being clobbered during a turn ([#21041](https://github.com/mastra-ai/mastra/pull/21041))
|
|
8
|
+
|
|
9
|
+
`updateThread` required both `title` and `metadata`, so callers that only needed to
|
|
10
|
+
change metadata (message persistence, working memory, observational memory, channel
|
|
11
|
+
subscriptions) had to read the thread and pass its title back. When title generation
|
|
12
|
+
finished between that read and the write, the freshly generated title was overwritten
|
|
13
|
+
with the stale one.
|
|
14
|
+
|
|
15
|
+
`title` and `metadata` are now independently optional: omitting one leaves that column
|
|
16
|
+
untouched. Callers that only change metadata no longer send a title, and message
|
|
17
|
+
persistence no longer rewrites a thread row it just read.
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`1c75e32`](https://github.com/mastra-ai/mastra/commit/1c75e32f7fc0b9fb6f548b4407feaec8a1440212), [`c47165c`](https://github.com/mastra-ai/mastra/commit/c47165c983c87594c6952f1fd2fa51a90205034c), [`e08e789`](https://github.com/mastra-ai/mastra/commit/e08e789c1bf4cd2fe46363f7a4728536ceccc9bd), [`35cc901`](https://github.com/mastra-ai/mastra/commit/35cc90102cf834a84827acaf9eee0b6d6d1e2a3b), [`a8b4cf0`](https://github.com/mastra-ai/mastra/commit/a8b4cf02823cffebc4751a53337dfacf097c1ae1), [`f33264f`](https://github.com/mastra-ai/mastra/commit/f33264f517ae603279afd5c4251e2b40f6dd3618), [`689f2c4`](https://github.com/mastra-ai/mastra/commit/689f2c4b6c0835fe455702b01d21daa8abcd9331), [`eeae63e`](https://github.com/mastra-ai/mastra/commit/eeae63e7fbe8e1f237adc69bca6e2ac13c5ca907), [`4c186a0`](https://github.com/mastra-ai/mastra/commit/4c186a017275f45e6ed4c09de0f89550e2d09e8c), [`b0fa077`](https://github.com/mastra-ai/mastra/commit/b0fa077bcbc9b08551846fe372a0d3d15b71ed72)]:
|
|
20
|
+
- @mastra/core@1.58.0-alpha.8
|
|
21
|
+
|
|
22
|
+
## 1.3.0-alpha.1
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Fixed resource-scoped message includes across storage adapters so included context cannot cross resource boundaries. ([#20984](https://github.com/mastra-ai/mastra/pull/20984))
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [[`6445eba`](https://github.com/mastra-ai/mastra/commit/6445eba6020abac681aba1cc9289f446cb400cbe), [`df31eb0`](https://github.com/mastra-ai/mastra/commit/df31eb0c7087d782a0d9346e467f9a4af4b0eef6), [`fcd0667`](https://github.com/mastra-ai/mastra/commit/fcd0667a4e378be35c9a1b1eb19cce78fbfd7282), [`bab06b1`](https://github.com/mastra-ai/mastra/commit/bab06b18923873a584bdfc71a6b4ec7fb4727fb7)]:
|
|
29
|
+
- @mastra/core@1.58.0-alpha.5
|
|
30
|
+
|
|
3
31
|
## 1.3.0-alpha.0
|
|
4
32
|
|
|
5
33
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -2101,7 +2101,7 @@ var MemoryDSQL = class MemoryDSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2101
2101
|
text: `Thread ${id} not found`,
|
|
2102
2102
|
details: {
|
|
2103
2103
|
threadId: id,
|
|
2104
|
-
title
|
|
2104
|
+
title: title ?? null
|
|
2105
2105
|
}
|
|
2106
2106
|
});
|
|
2107
2107
|
const mergedMetadata = {
|
|
@@ -2111,14 +2111,14 @@ var MemoryDSQL = class MemoryDSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2111
2111
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2112
2112
|
const thread = await this.#db.client.one(`UPDATE ${threadTableName}
|
|
2113
2113
|
SET
|
|
2114
|
-
title = $1,
|
|
2114
|
+
title = COALESCE($1, title),
|
|
2115
2115
|
metadata = $2,
|
|
2116
2116
|
"updatedAt" = $3::timestamp,
|
|
2117
2117
|
"updatedAtZ" = $4::timestamptz
|
|
2118
2118
|
WHERE id = $5
|
|
2119
2119
|
RETURNING *
|
|
2120
2120
|
`, [
|
|
2121
|
-
title,
|
|
2121
|
+
title ?? null,
|
|
2122
2122
|
JSON.stringify(mergedMetadata),
|
|
2123
2123
|
now,
|
|
2124
2124
|
now,
|
|
@@ -2142,7 +2142,7 @@ var MemoryDSQL = class MemoryDSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2142
2142
|
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
2143
2143
|
details: {
|
|
2144
2144
|
threadId: id,
|
|
2145
|
-
title
|
|
2145
|
+
title: title ?? null
|
|
2146
2146
|
}
|
|
2147
2147
|
}, error);
|
|
2148
2148
|
});
|
|
@@ -2173,7 +2173,14 @@ var MemoryDSQL = class MemoryDSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2173
2173
|
}, error);
|
|
2174
2174
|
});
|
|
2175
2175
|
}
|
|
2176
|
-
|
|
2176
|
+
/**
|
|
2177
|
+
* Fetches the messages named by `include` together with their surrounding context.
|
|
2178
|
+
*
|
|
2179
|
+
* @param include - Message ids to pin, each with an optional before/after window.
|
|
2180
|
+
* @param resourceId - When set, restricts both the pinned messages and their context
|
|
2181
|
+
* to that resource so an id from another resource returns nothing.
|
|
2182
|
+
*/
|
|
2183
|
+
async _getIncludedMessages({ include, resourceId }) {
|
|
2177
2184
|
if (!include || include.length === 0) return null;
|
|
2178
2185
|
const unionQueries = [];
|
|
2179
2186
|
const params = [];
|
|
@@ -2184,17 +2191,18 @@ var MemoryDSQL = class MemoryDSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2184
2191
|
});
|
|
2185
2192
|
for (const inc of include) {
|
|
2186
2193
|
const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
|
|
2194
|
+
const resourceCondition = resourceId ? ` AND "resourceId" = $${paramIdx + 3}` : "";
|
|
2187
2195
|
unionQueries.push(`
|
|
2188
2196
|
SELECT * FROM (
|
|
2189
2197
|
WITH target_thread AS (
|
|
2190
|
-
SELECT thread_id FROM ${tableName} WHERE id = $${paramIdx}
|
|
2198
|
+
SELECT thread_id FROM ${tableName} WHERE id = $${paramIdx}${resourceCondition}
|
|
2191
2199
|
),
|
|
2192
2200
|
ordered_messages AS (
|
|
2193
2201
|
SELECT
|
|
2194
2202
|
*,
|
|
2195
2203
|
ROW_NUMBER() OVER (ORDER BY "createdAt" ASC) as row_num
|
|
2196
2204
|
FROM ${tableName}
|
|
2197
|
-
WHERE thread_id = (SELECT thread_id FROM target_thread)
|
|
2205
|
+
WHERE thread_id = (SELECT thread_id FROM target_thread)${resourceCondition}
|
|
2198
2206
|
)
|
|
2199
2207
|
SELECT
|
|
2200
2208
|
m.id,
|
|
@@ -2220,6 +2228,10 @@ var MemoryDSQL = class MemoryDSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2220
2228
|
`);
|
|
2221
2229
|
params.push(id, withPreviousMessages, withNextMessages);
|
|
2222
2230
|
paramIdx += 3;
|
|
2231
|
+
if (resourceId) {
|
|
2232
|
+
params.push(resourceId);
|
|
2233
|
+
paramIdx += 1;
|
|
2234
|
+
}
|
|
2223
2235
|
}
|
|
2224
2236
|
const finalQuery = unionQueries.join(" UNION ALL ") + " ORDER BY \"createdAt\" ASC";
|
|
2225
2237
|
const includedRows = await this.#db.client.manyOrNone(finalQuery, params);
|
|
@@ -2345,7 +2357,10 @@ var MemoryDSQL = class MemoryDSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2345
2357
|
};
|
|
2346
2358
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
2347
2359
|
if (include && include.length > 0) {
|
|
2348
|
-
const includeMessages = await this._getIncludedMessages({
|
|
2360
|
+
const includeMessages = await this._getIncludedMessages({
|
|
2361
|
+
include,
|
|
2362
|
+
resourceId
|
|
2363
|
+
});
|
|
2349
2364
|
if (includeMessages) {
|
|
2350
2365
|
for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
|
|
2351
2366
|
messages.push(includeMsg);
|