diff --git a/packages/react-ai-sdk/src/rsc/VercelRSCRuntime.tsx b/packages/react-ai-sdk/src/rsc/VercelRSCRuntime.tsx index 2aae5e891..711d3062b 100644 --- a/packages/react-ai-sdk/src/rsc/VercelRSCRuntime.tsx +++ b/packages/react-ai-sdk/src/rsc/VercelRSCRuntime.tsx @@ -36,14 +36,8 @@ export class VercelRSCRuntime< return () => {}; } - public switchToThread(threadId: string | null) { - if (threadId) { - throw new Error( - "VercelRSCRuntime does not yet support switching threads", - ); - } - - this.thread = new VercelRSCThreadRuntime(this.thread.adapter); + public switchToThread() { + throw new Error("VercelRSCRuntime does not support switching threads"); } } diff --git a/packages/react-ai-sdk/src/ui/VercelAIRuntime.tsx b/packages/react-ai-sdk/src/ui/VercelAIRuntime.tsx index b0bb18ba7..3185d0575 100644 --- a/packages/react-ai-sdk/src/ui/VercelAIRuntime.tsx +++ b/packages/react-ai-sdk/src/ui/VercelAIRuntime.tsx @@ -1,6 +1,10 @@ -import type { ReactThreadRuntime, Unsubscribe } from "@assistant-ui/react"; -import type { AppendMessage, ThreadMessage } from "@assistant-ui/react"; -import { INTERNAL } from "@assistant-ui/react"; +import { + type ReactThreadRuntime, + type Unsubscribe, + type AppendMessage, + type ThreadMessage, + INTERNAL, +} from "@assistant-ui/react"; import type { Message } from "ai"; import { type StoreApi, type UseBoundStore, create } from "zustand"; import { getVercelAIMessage } from "./getVercelAIMessage"; @@ -39,6 +43,12 @@ export class VercelAIRuntime extends BaseAssistantRuntime throw new Error("VercelAIRuntime does not yet support switching threads"); } + // clear the vercel state (otherwise, it will be captured by the MessageRepository) + this.thread.vercel.messages = []; + this.thread.vercel.input = ""; + this.thread.vercel.setMessages([]); + this.thread.vercel.setInput(""); + this.thread = new VercelAIThreadRuntime(this.thread.vercel); } }