@mastra/dynamodb 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/dist/index.js CHANGED
@@ -1745,7 +1745,10 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1745
1745
  hasMore: false
1746
1746
  };
1747
1747
  if (perPage === 0 && include && include.length > 0) {
1748
- const includeMessages = await this._getIncludedMessages({ include });
1748
+ const includeMessages = await this._getIncludedMessages({
1749
+ include,
1750
+ resourceId
1751
+ });
1749
1752
  const list = new MessageList().add(includeMessages, "memory");
1750
1753
  return {
1751
1754
  messages: this._sortMessages(list.get.all.db(), field, direction),
@@ -1834,7 +1837,10 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1834
1837
  const messageIds = new Set(paginatedMessages.map((m) => m.id));
1835
1838
  let includeMessages = [];
1836
1839
  if (include && include.length > 0) {
1837
- includeMessages = await this._getIncludedMessages({ include });
1840
+ includeMessages = await this._getIncludedMessages({
1841
+ include,
1842
+ resourceId
1843
+ });
1838
1844
  for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
1839
1845
  paginatedMessages.push(includeMsg);
1840
1846
  messageIds.add(includeMsg.id);
@@ -2009,7 +2015,14 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
2009
2015
  return direction === "ASC" ? aValue - bValue : bValue - aValue;
2010
2016
  });
2011
2017
  }
2012
- async _getIncludedMessages({ include }) {
2018
+ /**
2019
+ * Fetches the messages named by `include` together with their surrounding context.
2020
+ *
2021
+ * @param include - Message ids to pin, each with an optional before/after window.
2022
+ * @param resourceId - When set, restricts both the pinned messages and their context
2023
+ * to that resource so an id from another resource returns nothing.
2024
+ */
2025
+ async _getIncludedMessages({ include, resourceId }) {
2013
2026
  if (!include?.length) return [];
2014
2027
  const targetResults = await Promise.all(include.map((inc) => this.service.entities.message.get({
2015
2028
  entity: "message",
@@ -2022,7 +2035,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
2022
2035
  data: null
2023
2036
  }))));
2024
2037
  const targetMap = /* @__PURE__ */ new Map();
2025
- for (const { id, data } of targetResults) if (data) {
2038
+ for (const { id, data } of targetResults) if (data && (!resourceId || data.resourceId === resourceId)) {
2026
2039
  const createdAt = typeof data.createdAt === "string" ? data.createdAt : new Date(data.createdAt).toISOString();
2027
2040
  targetMap.set(id, {
2028
2041
  threadId: data.threadId,
@@ -2030,7 +2043,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
2030
2043
  });
2031
2044
  }
2032
2045
  if (targetMap.size === 0) return [];
2033
- const parseQueryMessages = (data) => data.map((item) => this.parseMessageData(item)).filter((msg) => "content" in msg && typeof msg.content === "object");
2046
+ const parseQueryMessages = (data) => data.map((item) => this.parseMessageData(item)).filter((msg) => "content" in msg && typeof msg.content === "object").filter((msg) => !resourceId || msg.resourceId === resourceId);
2034
2047
  const includeMessages = [];
2035
2048
  for (const includeItem of include) {
2036
2049
  const { id, withPreviousMessages = 0, withNextMessages = 0 } = includeItem;