@mastra/cloudflare-d1 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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # @mastra/cloudflare-d1
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
@@ -3,7 +3,7 @@ name: mastra-cloudflare-d1
3
3
  description: Documentation for @mastra/cloudflare-d1. Use when working with @mastra/cloudflare-d1 APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/cloudflare-d1"
6
- version: "1.3.0-alpha.0"
6
+ version: "1.3.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0-alpha.0",
2
+ "version": "1.3.0-alpha.2",
3
3
  "package": "@mastra/cloudflare-d1",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -1284,7 +1284,7 @@ var MemoryStorageD1 = class extends _mastra_core_storage.MemoryStorage {
1284
1284
  "updatedAt"
1285
1285
  ];
1286
1286
  const values = [
1287
- title,
1287
+ title ?? thread.title,
1288
1288
  JSON.stringify(mergedMetadata),
1289
1289
  updatedAt.toISOString()
1290
1290
  ];
@@ -1295,7 +1295,7 @@ var MemoryStorageD1 = class extends _mastra_core_storage.MemoryStorage {
1295
1295
  });
1296
1296
  return {
1297
1297
  ...thread,
1298
- title,
1298
+ title: title ?? thread.title,
1299
1299
  metadata: {
1300
1300
  ...typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata,
1301
1301
  ...metadata
@@ -1390,15 +1390,23 @@ var MemoryStorageD1 = class extends _mastra_core_storage.MemoryStorage {
1390
1390
  return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
1391
1391
  });
1392
1392
  }
1393
- async _getIncludedMessages(include) {
1393
+ /**
1394
+ * Fetches the messages named by `include` together with their surrounding context.
1395
+ *
1396
+ * @param include - Message ids to pin, each with an optional before/after window.
1397
+ * @param resourceId - When set, restricts both the pinned messages and their context
1398
+ * to that resource so an id from another resource returns nothing.
1399
+ */
1400
+ async _getIncludedMessages(include, resourceId) {
1394
1401
  if (!include || include.length === 0) return null;
1395
1402
  const tableName = this.#db.getTableName(_mastra_core_storage.TABLE_MESSAGES);
1403
+ const resourceCondition = resourceId ? ` AND resourceId = ?` : "";
1396
1404
  const targetIds = include.map((inc) => inc.id).filter(Boolean);
1397
1405
  if (targetIds.length === 0) return null;
1398
1406
  const idPlaceholders = targetIds.map(() => "?").join(", ");
1399
1407
  const targetResult = await this.#db.executeQuery({
1400
- sql: `SELECT id, thread_id, createdAt FROM ${tableName} WHERE id IN (${idPlaceholders})`,
1401
- params: targetIds
1408
+ sql: `SELECT id, thread_id, createdAt FROM ${tableName} WHERE id IN (${idPlaceholders})${resourceCondition}`,
1409
+ params: resourceId ? [...targetIds, resourceId] : targetIds
1402
1410
  });
1403
1411
  if (!Array.isArray(targetResult) || targetResult.length === 0) return null;
1404
1412
  const targetMap = new Map(targetResult.map((r) => [r.id, {
@@ -1430,21 +1438,25 @@ var MemoryStorageD1 = class extends _mastra_core_storage.MemoryStorage {
1430
1438
  SELECT id, content, role, type, createdAt, thread_id AS threadId, resourceId
1431
1439
  FROM ${tableName}
1432
1440
  WHERE thread_id = ?
1433
- AND createdAt <= ?
1441
+ AND createdAt <= ?${resourceCondition}
1434
1442
  ORDER BY createdAt DESC, id DESC
1435
1443
  LIMIT ?
1436
1444
  )`);
1437
- unionParams.push(target.threadId, target.createdAt, withPreviousMessages + 1);
1445
+ unionParams.push(target.threadId, target.createdAt);
1446
+ if (resourceId) unionParams.push(resourceId);
1447
+ unionParams.push(withPreviousMessages + 1);
1438
1448
  if (withNextMessages > 0) {
1439
1449
  unionQueries.push(`SELECT * FROM (
1440
1450
  SELECT id, content, role, type, createdAt, thread_id AS threadId, resourceId
1441
1451
  FROM ${tableName}
1442
1452
  WHERE thread_id = ?
1443
- AND createdAt > ?
1453
+ AND createdAt > ?${resourceCondition}
1444
1454
  ORDER BY createdAt ASC, id ASC
1445
1455
  LIMIT ?
1446
1456
  )`);
1447
- unionParams.push(target.threadId, target.createdAt, withNextMessages);
1457
+ unionParams.push(target.threadId, target.createdAt);
1458
+ if (resourceId) unionParams.push(resourceId);
1459
+ unionParams.push(withNextMessages);
1448
1460
  }
1449
1461
  }
1450
1462
  await flushBatch();
@@ -1563,7 +1575,7 @@ var MemoryStorageD1 = class extends _mastra_core_storage.MemoryStorage {
1563
1575
  hasMore: false
1564
1576
  };
1565
1577
  if (perPage === 0 && include && include.length > 0) {
1566
- const includeResult = await this._getIncludedMessages(include);
1578
+ const includeResult = await this._getIncludedMessages(include, resourceId);
1567
1579
  if (!Array.isArray(includeResult) || includeResult.length === 0) return {
1568
1580
  messages: [],
1569
1581
  total: 0,
@@ -1634,7 +1646,7 @@ var MemoryStorageD1 = class extends _mastra_core_storage.MemoryStorage {
1634
1646
  const messageIds = new Set(paginatedMessages.map((m) => m.id));
1635
1647
  let includeMessages = [];
1636
1648
  if (include && include.length > 0) {
1637
- const includeResult = await this._getIncludedMessages(include);
1649
+ const includeResult = await this._getIncludedMessages(include, resourceId);
1638
1650
  if (Array.isArray(includeResult)) {
1639
1651
  includeMessages = includeResult;
1640
1652
  for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {