Skip to content

Commit

Permalink
fix(checkpoint): add support for options.filter in MemorySaver.list
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincburns committed Oct 14, 2024
1 parent d3c8204 commit 5a8ddd5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion libs/checkpoint/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class MemorySaver extends BaseCheckpointSaver {
options?: CheckpointListOptions
): AsyncGenerator<CheckpointTuple> {
// 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);
Expand Down Expand Up @@ -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<string, unknown>)[key] === value
)
) {
continue;
}

// Limit search results
if (limit !== undefined) {
if (limit <= 0) break;
Expand Down

0 comments on commit 5a8ddd5

Please sign in to comment.