feat: support resuming ongoing streams (#974)

This commit is contained in:
Jeremy 2025-05-01 12:36:52 -07:00 committed by GitHub
parent 45978c27a2
commit a3221fbcdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 1005 additions and 47 deletions

View file

@ -25,6 +25,7 @@ export function Chat({
selectedVisibilityType,
isReadonly,
session,
autoResume,
}: {
id: string;
initialMessages: Array<UIMessage>;
@ -32,6 +33,7 @@ export function Chat({
selectedVisibilityType: VisibilityType;
isReadonly: boolean;
session: Session;
autoResume: boolean;
}) {
const { mutate } = useSWRConfig();
@ -45,6 +47,7 @@ export function Chat({
status,
stop,
reload,
experimental_resume,
} = useChat({
id,
initialMessages,
@ -67,6 +70,15 @@ export function Chat({
},
});
useEffect(() => {
if (autoResume) {
experimental_resume();
}
// note: this hook has no dependencies since it only needs to run once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const searchParams = useSearchParams();
const query = searchParams.get('query');