From d3b9a965045ce19a64c285aeea62ceb3aa16fafe Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Tue, 25 Feb 2025 17:57:12 +0100 Subject: [PATCH] feat(react): support interrupt_before/after --- libs/sdk-js/src/react/stream.tsx | 7 ++++++- libs/sdk-js/src/schema.ts | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libs/sdk-js/src/react/stream.tsx b/libs/sdk-js/src/react/stream.tsx index a2cbf9e28..72c25bbe4 100644 --- a/libs/sdk-js/src/react/stream.tsx +++ b/libs/sdk-js/src/react/stream.tsx @@ -896,7 +896,12 @@ export function useStream< if (isLoading) return undefined; const interrupts = threadHead?.tasks?.at(-1)?.interrupts; - if (interrupts == null || interrupts.length === 0) return undefined; + if (interrupts == null || interrupts.length === 0) { + // check if there's a next task present + const next = threadHead?.next ?? []; + if (!next.length || error != null) return undefined; + return { when: "breakpoint" }; + } // Return only the current interrupt return interrupts.at(-1) as Interrupt | undefined; diff --git a/libs/sdk-js/src/schema.ts b/libs/sdk-js/src/schema.ts index 1a549dfc4..84596c82c 100644 --- a/libs/sdk-js/src/schema.ts +++ b/libs/sdk-js/src/schema.ts @@ -142,9 +142,9 @@ export interface AssistantGraph { * An interrupt thrown inside a thread. */ export interface Interrupt { - value: TValue; - when: "during"; - resumable: boolean; + value?: TValue; + when: "during" | (string & {}); + resumable?: boolean; ns?: string[]; }