fix(frontend): stabilize thread id when sending messages
This commit is contained in:
parent
f92444c722
commit
ce02c40b87
|
|
@ -200,9 +200,9 @@ export default function ChatPage() {
|
|||
return;
|
||||
}
|
||||
setHasSubmitted(true);
|
||||
void sendMessage(threadId, message);
|
||||
void sendMessage(safeThreadId, message);
|
||||
},
|
||||
[isSelectedSkillBootstrapping, sendMessage, threadId],
|
||||
[isSelectedSkillBootstrapping, safeThreadId, sendMessage],
|
||||
);
|
||||
const handleStop = useCallback(async () => {
|
||||
await thread.stop();
|
||||
|
|
|
|||
|
|
@ -69,6 +69,15 @@ function getStreamErrorMessage(error: unknown): string {
|
|||
return "Request failed.";
|
||||
}
|
||||
|
||||
function normalizeThreadId(
|
||||
value: string | null | undefined,
|
||||
): string | undefined {
|
||||
if (!value) return undefined;
|
||||
const normalized = value.trim();
|
||||
if (!normalized || normalized === "new") return undefined;
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function useThreadStreamLegacy({
|
||||
threadId,
|
||||
isNewThread,
|
||||
|
|
@ -155,12 +164,14 @@ export function useThreadStream({
|
|||
}, [onStart, onFinish, onToolEnd]);
|
||||
|
||||
useEffect(() => {
|
||||
const normalizedThreadId = threadId ?? null;
|
||||
const normalizedThreadId = normalizeThreadId(threadId) ?? null;
|
||||
if (!normalizedThreadId) {
|
||||
// Just reset for new thread creation when threadId becomes null/undefined
|
||||
startedRef.current = false;
|
||||
setOnStreamThreadId(normalizedThreadId);
|
||||
}
|
||||
setOnStreamThreadId((prev) =>
|
||||
prev === normalizedThreadId ? prev : normalizedThreadId,
|
||||
);
|
||||
threadIdRef.current = normalizedThreadId;
|
||||
}, [threadId]);
|
||||
|
||||
|
|
@ -288,7 +299,9 @@ export function useThreadStream({
|
|||
|
||||
const text = message.text.trim();
|
||||
const resolvedThreadId =
|
||||
threadId ?? threadIdRef.current ?? undefined;
|
||||
normalizeThreadId(threadId) ??
|
||||
normalizeThreadId(threadIdRef.current) ??
|
||||
undefined;
|
||||
if (resolvedThreadId === "new") {
|
||||
toast.error("Invalid thread id 'new'. Please refresh and retry.");
|
||||
sendInFlightRef.current = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue