Skip to content

Commit 82d9c8d

Browse files
lgrammelAntzyMo
andauthored
feat (ai/ui): make event in useAssistant submitMessage optional (#2089)
Co-authored-by: AntzyMo <mozbano@163.com>
1 parent 3e6561b commit 82d9c8d

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

.changeset/chilled-rivers-beg.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@ai-sdk/svelte': patch
3+
'ai': patch
4+
---
5+
6+
feat (ai/ui): make event in useAssistant submitMessage optional

.changeset/thirty-poets-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/vue': patch
3+
---
4+
5+
fix (@ai-sdk/vue): make event in handleSubmit optional

content/docs/07-reference/ai-sdk-ui/20-use-assistant.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ This works in conjunction with [`AssistantResponse`](./assistant-response) in th
118118
},
119119
{
120120
name: 'submitMessage',
121-
type: '(event?: React.FormEvent<HTMLFormElement>) => void',
121+
type: '(event?: { preventDefault?: () => void }) => void',
122122
description:
123123
'Form submission handler that automatically resets the input field and appends a user message.',
124124
},

packages/core/svelte/use-assistant.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Abort the current request immediately, keep the generated tokens if any.
5353
* Form submission handler that automatically resets the input field and appends a user message.
5454
*/
5555
submitMessage: (
56-
e: any,
56+
event?: { preventDefault?: () => void },
5757
requestOptions?: { data?: Record<string, string> },
5858
) => Promise<void>;
5959

@@ -230,10 +230,10 @@ export function useAssistant({
230230

231231
// Function to handle form submission
232232
async function submitMessage(
233-
e: any,
233+
event?: { preventDefault?: () => void },
234234
requestOptions?: { data?: Record<string, string> },
235235
) {
236-
e.preventDefault();
236+
event?.preventDefault?.();
237237
const inputValue = get(input);
238238
if (!inputValue) return;
239239

packages/svelte/src/use-assistant.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Abort the current request immediately, keep the generated tokens if any.
5353
* Form submission handler that automatically resets the input field and appends a user message.
5454
*/
5555
submitMessage: (
56-
e: any,
56+
event?: { preventDefault?: () => void },
5757
requestOptions?: { data?: Record<string, string> },
5858
) => Promise<void>;
5959

@@ -227,10 +227,10 @@ export function useAssistant({
227227

228228
// Function to handle form submission
229229
async function submitMessage(
230-
e: any,
230+
event?: { preventDefault?: () => void },
231231
requestOptions?: { data?: Record<string, string> },
232232
) {
233-
e.preventDefault();
233+
event?.preventDefault?.();
234234
const inputValue = get(input);
235235
if (!inputValue) return;
236236

packages/vue/src/use-chat.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export type UseChatHelpers = {
5151
/** The current value of the input */
5252
input: Ref<string>;
5353
/** Form submission handler to automatically reset input and append a user message */
54-
handleSubmit: (e: any, chatRequestOptions?: ChatRequestOptions) => void;
54+
handleSubmit: (
55+
event?: { preventDefault?: () => void },
56+
chatRequestOptions?: ChatRequestOptions,
57+
) => void;
5558
/** Whether the API request is in progress */
5659
isLoading: Ref<boolean | undefined>;
5760

0 commit comments

Comments
 (0)