@mastra/cloudflare-d1 0.12.6-alpha.0 → 0.12.7-alpha.0

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.cjs CHANGED
@@ -926,6 +926,47 @@ var MemoryStorageD1 = class extends storage.MemoryStorage {
926
926
  throw mastraError;
927
927
  }
928
928
  }
929
+ async getMessagesById({
930
+ messageIds,
931
+ format
932
+ }) {
933
+ if (messageIds.length === 0) return [];
934
+ const fullTableName = this.operations.getTableName(storage.TABLE_MESSAGES);
935
+ const messages = [];
936
+ try {
937
+ const query = createSqlBuilder().select(["id", "content", "role", "type", "createdAt", "thread_id AS threadId", "resourceId"]).from(fullTableName).where(`id in (${messageIds.map(() => "?").join(",")})`, ...messageIds);
938
+ query.orderBy("createdAt", "DESC");
939
+ const { sql, params } = query.build();
940
+ const result = await this.operations.executeQuery({ sql, params });
941
+ if (Array.isArray(result)) messages.push(...result);
942
+ const processedMessages = messages.map((message) => {
943
+ const processedMsg = {};
944
+ for (const [key, value] of Object.entries(message)) {
945
+ if (key === `type` && value === `v2`) continue;
946
+ processedMsg[key] = deserializeValue(value);
947
+ }
948
+ return processedMsg;
949
+ });
950
+ this.logger.debug(`Retrieved ${messages.length} messages`);
951
+ const list = new agent.MessageList().add(processedMessages, "memory");
952
+ if (format === `v1`) return list.get.all.v1();
953
+ return list.get.all.v2();
954
+ } catch (error$1) {
955
+ const mastraError = new error.MastraError(
956
+ {
957
+ id: "CLOUDFLARE_D1_STORAGE_GET_MESSAGES_BY_ID_ERROR",
958
+ domain: error.ErrorDomain.STORAGE,
959
+ category: error.ErrorCategory.THIRD_PARTY,
960
+ text: `Failed to retrieve messages by ID: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
961
+ details: { messageIds: JSON.stringify(messageIds) }
962
+ },
963
+ error$1
964
+ );
965
+ this.logger?.error(mastraError.toString());
966
+ this.logger?.trackException(mastraError);
967
+ throw mastraError;
968
+ }
969
+ }
929
970
  async getMessagesPaginated({
930
971
  threadId,
931
972
  selectBy,
@@ -2247,6 +2288,12 @@ var D1Store = class extends storage.MastraStorage {
2247
2288
  }) {
2248
2289
  return this.stores.memory.getMessages({ threadId, selectBy, format });
2249
2290
  }
2291
+ async getMessagesById({
2292
+ messageIds,
2293
+ format
2294
+ }) {
2295
+ return this.stores.memory.getMessagesById({ messageIds, format });
2296
+ }
2250
2297
  async getMessagesPaginated({
2251
2298
  threadId,
2252
2299
  selectBy,