mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-01 01:07:04 +02:00
test(ai-workflow-builder): Use checkpointer.getTuple in checkpoint- (#31081)
Co-authored-by: n8n-cat-bot[bot] <n8n-cat-bot[bot]@users.noreply.github.com>
This commit is contained in:
parent
eaa641f77d
commit
5d7b5e6bd2
|
|
@ -11,7 +11,6 @@
|
|||
*/
|
||||
import { AIMessage, HumanMessage } from '@langchain/core/messages';
|
||||
import type { BaseMessage } from '@langchain/core/messages';
|
||||
import type { CheckpointTuple } from '@langchain/langgraph';
|
||||
import {
|
||||
Annotation,
|
||||
Command,
|
||||
|
|
@ -42,30 +41,11 @@ async function getCheckpointMessages(
|
|||
checkpointer: MemorySaver,
|
||||
threadId: string,
|
||||
): Promise<BaseMessage[]> {
|
||||
let latestTuple: CheckpointTuple | undefined;
|
||||
for await (const tuple of checkpointer.list({ configurable: { thread_id: threadId } })) {
|
||||
if (!latestTuple || isLaterCheckpoint(tuple, latestTuple)) latestTuple = tuple;
|
||||
}
|
||||
|
||||
const messages = latestTuple?.checkpoint?.channel_values?.messages;
|
||||
const tuple = await checkpointer.getTuple({ configurable: { thread_id: threadId } });
|
||||
const messages = tuple?.checkpoint?.channel_values?.messages;
|
||||
return Array.isArray(messages) ? (messages as BaseMessage[]) : [];
|
||||
}
|
||||
|
||||
function isLaterCheckpoint(candidate: CheckpointTuple, current: CheckpointTuple): boolean {
|
||||
const candidateStep = getCheckpointStep(candidate);
|
||||
const currentStep = getCheckpointStep(current);
|
||||
|
||||
if (candidateStep !== currentStep) return candidateStep > currentStep;
|
||||
|
||||
return candidate.checkpoint.ts > current.checkpoint.ts;
|
||||
}
|
||||
|
||||
function getCheckpointStep(tuple: CheckpointTuple): number {
|
||||
const step = tuple.metadata?.step;
|
||||
|
||||
return typeof step === 'number' ? step : Number.NEGATIVE_INFINITY;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Tests
|
||||
// ============================================================================
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user