Skip to content

Commit e3e625a

Browse files
committed
📦 NEW: onCancel function
1 parent 2e72330 commit e3e625a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/langbase/src/react/use-pipe.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Message, Role, RunResponse } from '@/langbase/langbase';
2-
import { getRunner, Runner } from '@/lib/helpers';
1+
import {Message, Role, RunResponse} from '@/langbase/langbase';
2+
import {getRunner, Runner} from '@/lib/helpers';
33
import React, {useCallback, useMemo, useRef, useState} from 'react';
44
import {z} from 'zod';
55

@@ -16,6 +16,7 @@ interface UsePipeOptions {
1616
onFinish?: (messages: Message[], threadId: string) => void;
1717
onConnect?: () => void;
1818
onError?: (error: Error) => void;
19+
onCancel?: (messages: Message[]) => void;
1920
threadId?: string;
2021
initialMessages?: Message[];
2122
stream?: boolean;
@@ -33,6 +34,7 @@ export function usePipe({
3334
threadId: initialThreadId,
3435
initialMessages = [],
3536
stream = true,
37+
onCancel,
3638
}: UsePipeOptions = {}) {
3739
const [messages, setMessages] = useState<Message[]>(initialMessages);
3840
const [input, setInput] = useState('');
@@ -256,6 +258,7 @@ export function usePipe({
256258

257259
const stop = useCallback(() => {
258260
abortControllerRef.current?.abort();
261+
onCancel?.(messagesRef.current);
259262
setIsLoading(false);
260263
}, []);
261264

0 commit comments

Comments
 (0)