assistant-ui icon indicating copy to clipboard operation
assistant-ui copied to clipboard

Trigger response on initial messages

Open jorgemasta opened this issue 7 months ago • 0 comments

I want to start a thread with an initial user message received by the search params.

  const searchParams = useSearchParams();
  const message = searchParams.get("message");
  const runtime = useChatRuntime({
    api: "/api/chat",
    initialMessages: [
      {
        role: "user",
        content: [{ type: "text", text: message || "" }],
      },
    ],
  });

It adds the message correctly to the thread but I haven't found any programmatic way to force an assistant response, I need to add a new message manually.

Using append instead of initialMessages doesn't do the trick since it responds with an empty response (the api call is cancelled for some reason)

jorgemasta avatar May 29 '25 11:05 jorgemasta