From 5a8ddd52e7fe58e0ee4e2fe3a2624175ddd2cef7 Mon Sep 17 00:00:00 2001 From: Ben Burns <803016+benjamincburns@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:44:29 +1300 Subject: [PATCH] fix(checkpoint): add support for options.filter in MemorySaver.list --- libs/checkpoint/src/memory.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/checkpoint/src/memory.ts b/libs/checkpoint/src/memory.ts index ad8e45d9..72f04807 100644 --- a/libs/checkpoint/src/memory.ts +++ b/libs/checkpoint/src/memory.ts @@ -171,7 +171,7 @@ export class MemorySaver extends BaseCheckpointSaver { options?: CheckpointListOptions ): AsyncGenerator { // eslint-disable-next-line prefer-const - let { before, limit } = options ?? {}; + let { before, limit, filter } = options ?? {}; const threadIds = config.configurable?.thread_id ? [config.configurable?.thread_id] : Object.keys(this.storage); @@ -209,6 +209,16 @@ export class MemorySaver extends BaseCheckpointSaver { metadataStr )) as CheckpointMetadata; + if ( + filter && + !Object.entries(filter).every( + ([key, value]) => + (metadata as unknown as Record)[key] === value + ) + ) { + continue; + } + // Limit search results if (limit !== undefined) { if (limit <= 0) break;