ai
ai copied to clipboard
SvelteKit "handleSubmit" omits data
Description
I cannot get "data" to get passed along to the server when using sveltekit. I am trying this:
I set the "useChat" up on my +page.svelte
const { input, handleSubmit, messages } = useChat();
My submit handler:
function submitHandler(event: any) {
event.preventDefault();
handleSubmit(event, {
data: {
test: 'data'
}
});
}
And my server:
export const POST = (async ({ request }) => {
try {
const jsonData = await request.json();
console.dir(jsonData); // "data" object is missing from here. i only have "messages"
Based on this React example I also tried:
<form
on:submit={(e) => {
handleSubmit(e, {
data: {
test: 'data'
}
});
}}
>
but "data" is still not available in +server.ts
endpoint
Code example
No response
Additional context
No response
I also have this problem.
Same problem for me, looks like in the append function, 'data' is not destructured from the ChatRequestOptions and passed through.
message: Message | CreateMessage,
{
options,
functions,
function_call,
tools,
tool_choice,
}: ChatRequestOptions = {},
) => {
if (!message.id) {
message.id = generateId();
}
const chatRequest: ChatRequest = {
messages: get(messages).concat(message as Message),
options,
...(functions !== undefined && { functions }),
...(function_call !== undefined && { function_call }),
...(tools !== undefined && { tools }),
...(tool_choice !== undefined && { tool_choice }),
};
return triggerRequest(chatRequest);
};
https://github.com/vercel/ai/pull/1748
I am still having this issue as well. Any fix ?
Sometimes I see handleSubmit being called twice. The first time, data is received by the server while the second time, it comes through as empty / undefined