#Client Functions cannot be passed directly to Server Functions.

2 messages · Page 1 of 1 (latest)

timber widget
#

I am trying to use the AI SDK but i keep getting this error
Error: Client Functions cannot be passed directly to Server Functions. Only Functions passed from the Server can be passed back again.
and i am following the docs example:
server action example: https://github.com/vercel/ai/blob/main/examples/next-ai-rsc/app/stream-object/generate-itinerary.tsx

My Server Action:

export async function getTriageLevel(prompt: string) {
  "use server";

  const history = getMutableAIState();

  const stream = createStreamableValue();

  history.update([...history.get(), { role: "user", content: prompt }]);

  (async () => {
    const { partialObjectStream } = await streamObject({
      model: google("models/gemini-1.5-pro-latest"),
      system: SYSTEM_PROMPT,
      messages: history.get(),
      schema: triageResultSchema,
    });

    for await (const partialObject of partialObjectStream) {
      stream.update(partialObject);
    }

    stream.done();
  })();

  history.done([
    ...history.get(),
    {
      role: "assistant",
      content: { object: stream.value },
    },
  ]);

  return { object: stream.value };
}

My client component:

setMessages((prevMessages: UIState) => [
        ...prevMessages,
        { id: Date.now().toString(), role: "user", content: prompt },
      ]);

      const { object } = await getTriageLevel(prompt);

      for await (const partialObject of readStreamableValue(object)) {
        if (partialObject) {
          console.log(partialObject);

          setGeneration(partialObject);
        }
      }

      setMessages((prevMessages: UIState) => [
        ...prevMessages,
        {
          id: Date.now().toString(),
          role: "assistant",
          content: generation as PartialTriageResult,
        },
      ]);
GitHub

Build AI-powered applications with React, Svelte, Vue, and Solid - vercel/ai

fervent kayakBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)