@ai-sdk/react
Advanced tools
Comparing version 0.0.25 to 0.0.26
# @ai-sdk/react | ||
## 0.0.26 | ||
### Patch Changes | ||
- f63829fe: feat (ai/ui): add allowEmptySubmit flag to handleSubmit | ||
- 4b2c09d9: feat (ai/ui): add mutator function support to useChat / setMessages | ||
- Updated dependencies [f63829fe] | ||
- @ai-sdk/ui-utils@0.0.17 | ||
## 0.0.25 | ||
@@ -4,0 +13,0 @@ |
@@ -95,3 +95,3 @@ import { Message, CreateMessage, AssistantStatus, UseAssistantOptions, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, DeepPartial, FetchFunction } from '@ai-sdk/ui-utils'; | ||
*/ | ||
setMessages: (messages: Message[]) => void; | ||
setMessages: (messages: Message[] | ((messages: Message[]) => Message[])) => void; | ||
/** The current value of the input */ | ||
@@ -98,0 +98,0 @@ input: string; |
@@ -514,2 +514,5 @@ "use strict"; | ||
(messages2) => { | ||
if (typeof messages2 === "function") { | ||
messages2 = messages2(messagesRef.current); | ||
} | ||
mutate(messages2, false); | ||
@@ -524,2 +527,5 @@ messagesRef.current = messages2; | ||
var _a, _b, _c, _d, _e; | ||
(_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event); | ||
if (!input && !options.allowEmptySubmit) | ||
return; | ||
if (metadata) { | ||
@@ -531,3 +537,2 @@ extraMetadataRef.current = { | ||
} | ||
(_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event); | ||
const attachmentsForRequest = []; | ||
@@ -571,10 +576,11 @@ const attachmentsFromOptions = options.experimental_attachments; | ||
}; | ||
const messages2 = !input && options.allowEmptySubmit ? messagesRef.current : messagesRef.current.concat({ | ||
id: generateId2(), | ||
createdAt: /* @__PURE__ */ new Date(), | ||
role: "user", | ||
content: input, | ||
experimental_attachments: attachmentsForRequest.length > 0 ? attachmentsForRequest : void 0 | ||
}); | ||
const chatRequest = { | ||
messages: input ? messagesRef.current.concat({ | ||
id: generateId2(), | ||
createdAt: /* @__PURE__ */ new Date(), | ||
role: "user", | ||
content: input, | ||
experimental_attachments: attachmentsForRequest.length > 0 ? attachmentsForRequest : void 0 | ||
}) : messagesRef.current, | ||
messages: messages2, | ||
options: requestOptions, | ||
@@ -581,0 +587,0 @@ headers: requestOptions.headers, |
{ | ||
"name": "@ai-sdk/react", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"license": "Apache-2.0", | ||
@@ -19,3 +19,3 @@ "sideEffects": false, | ||
"@ai-sdk/provider-utils": "1.0.2", | ||
"@ai-sdk/ui-utils": "0.0.16", | ||
"@ai-sdk/ui-utils": "0.0.17", | ||
"swr": "2.2.5" | ||
@@ -22,0 +22,0 @@ }, |
@@ -54,3 +54,5 @@ import type { | ||
*/ | ||
setMessages: (messages: Message[]) => void; | ||
setMessages: ( | ||
messages: Message[] | ((messages: Message[]) => Message[]), | ||
) => void; | ||
/** The current value of the input */ | ||
@@ -511,3 +513,7 @@ input: string; | ||
const setMessages = useCallback( | ||
(messages: Message[]) => { | ||
(messages: Message[] | ((messages: Message[]) => Message[])) => { | ||
if (typeof messages === 'function') { | ||
messages = messages(messagesRef.current); | ||
} | ||
mutate(messages, false); | ||
@@ -528,2 +534,6 @@ messagesRef.current = messages; | ||
) => { | ||
event?.preventDefault?.(); | ||
if (!input && !options.allowEmptySubmit) return; | ||
if (metadata) { | ||
@@ -536,4 +546,2 @@ extraMetadataRef.current = { | ||
event?.preventDefault?.(); | ||
const attachmentsForRequest: Attachment[] = []; | ||
@@ -582,5 +590,6 @@ const attachmentsFromOptions = options.experimental_attachments; | ||
const chatRequest: ChatRequest = { | ||
messages: input | ||
? messagesRef.current.concat({ | ||
const messages = | ||
!input && options.allowEmptySubmit | ||
? messagesRef.current | ||
: messagesRef.current.concat({ | ||
id: generateId(), | ||
@@ -594,4 +603,6 @@ createdAt: new Date(), | ||
: undefined, | ||
}) | ||
: messagesRef.current, | ||
}); | ||
const chatRequest: ChatRequest = { | ||
messages, | ||
options: requestOptions, | ||
@@ -598,0 +609,0 @@ headers: requestOptions.headers, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
282372
4900
6
+ Added@ai-sdk/ui-utils@0.0.17(transitive)
- Removed@ai-sdk/ui-utils@0.0.16(transitive)
Updated@ai-sdk/ui-utils@0.0.17