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