@ai-sdk/react
Advanced tools
Comparing version 0.0.17 to 0.0.18
# @ai-sdk/react | ||
## 0.0.18 | ||
### Patch Changes | ||
- 70d18003: add setThreadId helper to switch between threads for useAssistant | ||
## 0.0.17 | ||
@@ -4,0 +10,0 @@ |
@@ -19,2 +19,6 @@ import { Message, CreateMessage, AssistantStatus, UseAssistantOptions, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, DeepPartial, FetchFunction } from '@ai-sdk/ui-utils'; | ||
/** | ||
* Set the current thread ID. Specifying a thread ID will switch to that thread, if it exists. If set to 'undefined', a new thread will be created. For both cases, `threadId` will be updated with the new value and `messages` will be cleared. | ||
*/ | ||
setThreadId: (threadId: string | undefined) => void; | ||
/** | ||
* The current value of the input field. | ||
@@ -21,0 +25,0 @@ */ |
@@ -57,3 +57,5 @@ "use strict"; | ||
const [input, setInput] = (0, import_react.useState)(""); | ||
const [threadId, setThreadId] = (0, import_react.useState)(void 0); | ||
const [currentThreadId, setCurrentThreadId] = (0, import_react.useState)( | ||
void 0 | ||
); | ||
const [status, setStatus] = (0, import_react.useState)("awaiting_message"); | ||
@@ -97,3 +99,3 @@ const [error, setError] = (0, import_react.useState)(void 0); | ||
// always use user-provided threadId when available: | ||
threadId: (_a = threadIdParam != null ? threadIdParam : threadId) != null ? _a : null, | ||
threadId: (_a = threadIdParam != null ? threadIdParam : currentThreadId) != null ? _a : null, | ||
message: message.content, | ||
@@ -157,3 +159,3 @@ // optional request data: | ||
case "assistant_control_data": { | ||
setThreadId(value.threadId); | ||
setCurrentThreadId(value.threadId); | ||
setMessages((messages2) => { | ||
@@ -194,2 +196,6 @@ const lastMessage = messages2[messages2.length - 1]; | ||
}; | ||
const setThreadId = (threadId) => { | ||
setCurrentThreadId(threadId); | ||
setMessages([]); | ||
}; | ||
return { | ||
@@ -199,3 +205,4 @@ append, | ||
setMessages, | ||
threadId, | ||
threadId: currentThreadId, | ||
setThreadId, | ||
input, | ||
@@ -202,0 +209,0 @@ setInput, |
{ | ||
"name": "@ai-sdk/react", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -32,2 +32,7 @@ import { isAbortError } from '@ai-sdk/provider-utils'; | ||
/** | ||
* Set the current thread ID. Specifying a thread ID will switch to that thread, if it exists. If set to 'undefined', a new thread will be created. For both cases, `threadId` will be updated with the new value and `messages` will be cleared. | ||
*/ | ||
setThreadId: (threadId: string | undefined) => void; | ||
/** | ||
* The current value of the input field. | ||
@@ -101,3 +106,5 @@ */ | ||
const [input, setInput] = useState(''); | ||
const [threadId, setThreadId] = useState<string | undefined>(undefined); | ||
const [currentThreadId, setCurrentThreadId] = useState<string | undefined>( | ||
undefined, | ||
); | ||
const [status, setStatus] = useState<AssistantStatus>('awaiting_message'); | ||
@@ -156,3 +163,3 @@ const [error, setError] = useState<undefined | Error>(undefined); | ||
// always use user-provided threadId when available: | ||
threadId: threadIdParam ?? threadId ?? null, | ||
threadId: threadIdParam ?? currentThreadId ?? null, | ||
message: message.content, | ||
@@ -222,3 +229,3 @@ | ||
case 'assistant_control_data': { | ||
setThreadId(value.threadId); | ||
setCurrentThreadId(value.threadId); | ||
@@ -274,2 +281,7 @@ // set id of last message: | ||
const setThreadId = (threadId: string | undefined) => { | ||
setCurrentThreadId(threadId); | ||
setMessages([]); | ||
}; | ||
return { | ||
@@ -279,3 +291,4 @@ append, | ||
setMessages, | ||
threadId, | ||
threadId: currentThreadId, | ||
setThreadId, | ||
input, | ||
@@ -282,0 +295,0 @@ setInput, |
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
247728
4121