Skip to content

Commit 1894f81

Browse files
lgrammelBrianHung
andauthoredJun 27, 2024··
feat (ai/ui): allow JSONValue as data in useChat handleSubmit (#2128)
Co-authored-by: Brian Hung <brianlhung@gmail.com>
1 parent 9b50003 commit 1894f81

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed
 

‎.changeset/swift-boats-shout.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@ai-sdk/ui-utils': patch
3+
'@ai-sdk/react': patch
4+
---
5+
6+
feat (ai/ui): allow JSONValue as data in useChat handleSubmit

‎content/docs/07-reference/ai-sdk-ui/01-use-chat.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Allows you to easily create a conversational user interface for your chatbot app
136136
},
137137
{
138138
name: 'experimental_prepareRequestBody',
139-
type: '(options: { messages: Message[]; requestData?: Record<string, string>; requestBody?: object }) => JSONValue',
139+
type: '(options: { messages: Message[]; requestData?: JSONValue; requestBody?: object }) => JSONValue',
140140
optional: true,
141141
description:
142142
'Experimental (React only). When a function is provided, it will be used to prepare the request body for the chat API. This can be useful for customizing the request body based on the messages and data in the chat.',
@@ -232,7 +232,7 @@ Allows you to easily create a conversational user interface for your chatbot app
232232
},
233233
{
234234
name: 'data',
235-
type: 'Record<string,string>',
235+
type: 'JSONValue',
236236
description: 'Additional data to be sent to the server.',
237237
},
238238
],

‎packages/react/src/use-chat.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const getStreamedResponse = async (
9191
experimental_prepareRequestBody:
9292
| ((options: {
9393
messages: Message[];
94-
requestData?: Record<string, string>;
94+
requestData?: JSONValue;
9595
requestBody?: object;
9696
}) => JSONValue)
9797
| undefined,
@@ -220,7 +220,7 @@ export function useChat({
220220
*/
221221
experimental_prepareRequestBody?: (options: {
222222
messages: Message[];
223-
requestData?: Record<string, string>;
223+
requestData?: JSONValue;
224224
requestBody?: object;
225225
}) => JSONValue;
226226

‎packages/ui-utils/src/types.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export type CreateMessage = Omit<Message, 'id'> & {
192192
export type ChatRequest = {
193193
messages: Message[];
194194
options?: RequestOptions;
195-
data?: Record<string, string>;
195+
data?: JSONValue;
196196

197197
/**
198198
* @deprecated
@@ -272,7 +272,7 @@ The options to be passed to the fetch call.
272272
/**
273273
Additional data to be sent to the server.
274274
*/
275-
data?: Record<string, string>;
275+
data?: JSONValue;
276276
};
277277

278278
export type UseChatOptions = {
@@ -468,6 +468,10 @@ or to provide a custom fetch implementation for e.g. testing.
468468
fetch?: FetchFunction;
469469
};
470470

471+
/**
472+
A JSON value can be a string, number, boolean, object, array, or null.
473+
JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
474+
*/
471475
export type JSONValue =
472476
| null
473477
| string

0 commit comments

Comments
 (0)
Please sign in to comment.