Skip to content

Commit

Permalink
feat (ai/ui): make event in useAssistant submitMessage optional (#2089)
Browse files Browse the repository at this point in the history
Co-authored-by: AntzyMo <[email protected]>
  • Loading branch information
lgrammel and AntzyMo committed Jun 25, 2024
1 parent 3e6561b commit 82d9c8d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-rivers-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ai-sdk/svelte': patch
'ai': patch
---

feat (ai/ui): make event in useAssistant submitMessage optional
5 changes: 5 additions & 0 deletions .changeset/thirty-poets-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/vue': patch
---

fix (@ai-sdk/vue): make event in handleSubmit optional
2 changes: 1 addition & 1 deletion content/docs/07-reference/ai-sdk-ui/20-use-assistant.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ This works in conjunction with [`AssistantResponse`](./assistant-response) in th
},
{
name: 'submitMessage',
type: '(event?: React.FormEvent<HTMLFormElement>) => void',
type: '(event?: { preventDefault?: () => void }) => void',
description:
'Form submission handler that automatically resets the input field and appends a user message.',
},
Expand Down
6 changes: 3 additions & 3 deletions packages/core/svelte/use-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Abort the current request immediately, keep the generated tokens if any.
* Form submission handler that automatically resets the input field and appends a user message.
*/
submitMessage: (
e: any,
event?: { preventDefault?: () => void },
requestOptions?: { data?: Record<string, string> },
) => Promise<void>;

Expand Down Expand Up @@ -230,10 +230,10 @@ export function useAssistant({

// Function to handle form submission
async function submitMessage(
e: any,
event?: { preventDefault?: () => void },
requestOptions?: { data?: Record<string, string> },
) {
e.preventDefault();
event?.preventDefault?.();
const inputValue = get(input);
if (!inputValue) return;

Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/use-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Abort the current request immediately, keep the generated tokens if any.
* Form submission handler that automatically resets the input field and appends a user message.
*/
submitMessage: (
e: any,
event?: { preventDefault?: () => void },
requestOptions?: { data?: Record<string, string> },
) => Promise<void>;

Expand Down Expand Up @@ -227,10 +227,10 @@ export function useAssistant({

// Function to handle form submission
async function submitMessage(
e: any,
event?: { preventDefault?: () => void },
requestOptions?: { data?: Record<string, string> },
) {
e.preventDefault();
event?.preventDefault?.();
const inputValue = get(input);
if (!inputValue) return;

Expand Down
5 changes: 4 additions & 1 deletion packages/vue/src/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export type UseChatHelpers = {
/** The current value of the input */
input: Ref<string>;
/** Form submission handler to automatically reset input and append a user message */
handleSubmit: (e: any, chatRequestOptions?: ChatRequestOptions) => void;
handleSubmit: (
event?: { preventDefault?: () => void },
chatRequestOptions?: ChatRequestOptions,
) => void;
/** Whether the API request is in progress */
isLoading: Ref<boolean | undefined>;

Expand Down

0 comments on commit 82d9c8d

Please sign in to comment.