fix(threads): 允许 sendMessage 接受 undefined threadId
This commit is contained in:
parent
ffd10063a9
commit
8cb49f68b5
|
|
@ -271,7 +271,7 @@ export function useThreadStream({
|
|||
|
||||
const sendMessage = useCallback(
|
||||
async (
|
||||
threadId: string,
|
||||
threadId: string | undefined,
|
||||
message: PromptInputMessage,
|
||||
extraContext?: Record<string, unknown>,
|
||||
) => {
|
||||
|
|
@ -281,6 +281,8 @@ export function useThreadStream({
|
|||
sendInFlightRef.current = true;
|
||||
|
||||
const text = message.text.trim();
|
||||
const resolvedThreadId =
|
||||
threadId ?? threadIdRef.current ?? undefined;
|
||||
|
||||
// Capture current count before showing optimistic messages
|
||||
prevMsgCountRef.current = thread.messages.length;
|
||||
|
|
@ -315,7 +317,9 @@ export function useThreadStream({
|
|||
}
|
||||
setOptimisticMessages(newOptimistic);
|
||||
|
||||
_handleOnStart(threadId);
|
||||
if (resolvedThreadId) {
|
||||
_handleOnStart(resolvedThreadId);
|
||||
}
|
||||
|
||||
let uploadedFileInfo: UploadedFileInfo[] = [];
|
||||
|
||||
|
|
@ -359,12 +363,12 @@ export function useThreadStream({
|
|||
);
|
||||
}
|
||||
|
||||
if (!threadId) {
|
||||
if (!resolvedThreadId) {
|
||||
throw new Error("Thread is not ready for file upload.");
|
||||
}
|
||||
|
||||
if (files.length > 0) {
|
||||
const uploadResponse = await uploadFiles(threadId, files);
|
||||
const uploadResponse = await uploadFiles(resolvedThreadId, files);
|
||||
uploadedFileInfo = uploadResponse.files;
|
||||
|
||||
// Update optimistic human message with uploaded status + paths
|
||||
|
|
@ -431,7 +435,7 @@ export function useThreadStream({
|
|||
],
|
||||
},
|
||||
{
|
||||
threadId: threadId,
|
||||
threadId: resolvedThreadId,
|
||||
streamSubgraphs: true,
|
||||
streamResumable: true,
|
||||
config: {
|
||||
|
|
@ -452,7 +456,7 @@ export function useThreadStream({
|
|||
: context.mode === "thinking"
|
||||
? "low"
|
||||
: undefined),
|
||||
thread_id: threadId,
|
||||
thread_id: resolvedThreadId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue