Open dennis-adamczyk opened 3 months ago
If I remember correctly, the type of AI
cannot be inferred correctly with the implicit return type of the action. For me, it helped to set an explicit return type, see https://github.com/unstubbable/ai-rsc-test/commit/ef44eb0.
That's correct. Because there is a cycling dependency in the definition of the AIProvider, the type can not be inferred. This is fixable when explicitly type the return type of the action (like here).
However, there is still a type error in the submitUserMessage
function, because aiState.get()
is not compatible with the messages property of the render
function: see this line. The error is the following:
Type '{ role: "function" | "user" | "assistant" | "system"; content: string; id?: string | undefined; name?: string | undefined; }' is not assignable to type 'ChatCompletionMessageParam'.
Type '{ role: "function" | "user" | "assistant" | "system"; content: string; id?: string | undefined; name?: string | undefined; }' is not assignable to type 'ChatCompletionFunctionMessageParam'.
Types of property 'name' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'. ts(2322)
After inspecting the types I still do not have a clue why the name property should not be compatible. I guess, I need some help here.
Define a proper union type to fix this: https://github.com/unstubbable/ai-rsc-test/blob/ef44eb040b8afaee86a6b7c3665f19983748998d/app/action.tsx#L15
@unstubbable @dennis-adamczyk I have a question slightly related to this but how do you specify a maxDuration
for the async render functions within the tool calls? e.g. render: async function* ({ flightNumber }) ...
I noticed that upgrading to the pro plan increases the function time limit from 10s to 15s, but how can I specify these on the fly here (or define a global default)? Since the functions are being invoked from an actions.tsx
file as opposed to the standard app/api/**/*
pattern, I'm getting errors when trying to define these globally in a vercel.json
file. Any help would be appreciated here, and I'm happy to open up a new issue for this.
@parthematics actions inherit runtime configurations from the page/layout they're called from (this is because they're ultimately in the same bundle on the server). See https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
@parthematics actions inherit runtime configurations from the page/layout they're called from (this is because they're ultimately in the same bundle on the server). See https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
Ah, gotcha. I'll try that and see if that resolves it! Thanks :)
Description
I tried to experiment with Generative UI. Therefore, I followed the steps described on https://sdk.vercel.ai/docs/concepts/ai-rsc#setup. After copying and pasting the code in step 2 I get a few type errors. The const
AI
has the type ofany
when hovering over it in VSCode. Also, theui
const which is the result of callingrender
throws an error, saying it is typed as any. But when hovering over the functions themselves, I see that they have a correct return type. You can check out the code at https://github.com/dennis-adamczyk/generative-ui-example but I really did just follow the steps in the documentation.Code example
Additional context
I'm running node v20.9.0 and TypeScript v5.3.2 on Windows 11 (WSL).