fix(frontend): 修复 3qfx/xdfx 任务深链「新建对话」开场白发进上一个会话
根因竞态:从已有会话点「新建对话」时 isNewThread 立刻翻 true,但 useThreadStream 的 onStreamThreadId 慢一帧才归零;自动发送 effect 同帧 submit,而 SDK 的 SubmitOptions.threadId 仅在 hook 线程为空时生效,于是开场白发进了上一个对话 (表现为「一直在同一个聊天框里发消息」,首次正常、之后每次都串)。 - useThreadStream 追加返回当前绑定的流线程 id onStreamThreadId(向后兼容) - AgentChatPage 自动发送 effect 增加守卫 streamThreadId == null:等底层 stream 切到全新线程后再发,开场白即落到新建对话 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
29cc004b69
commit
e5ca717783
2 files changed
+12
-3
No files matched your search
@@ -785,7 +785,10 @@ export function useThreadStream({
|
|||||||
} as typeof thread)
|
} as typeof thread)
|
||||||
: thread;
|
: thread;
|
||||||
|
|
||||||
return [mergedThread, sendMessage, isUploading] as const;
|
// 第 4 个返回值 `onStreamThreadId` = 底层 useStream 当前实际绑定的线程 id(新建/未保存时为 null)。
|
||||||
|
// 调用方据此判断「流是否已切到全新线程」,避免在切换会话的那一帧把消息发进上一个会话
|
||||||
|
// (submit 的 threadId 选项仅在 hook 线程为 null/undefined 时才生效)。
|
||||||
|
return [mergedThread, sendMessage, isUploading, onStreamThreadId] as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useThreads(
|
export function useThreads(
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export default function AgentChatPage({
|
|||||||
}, [isNewThread, threadId, agent_id]);
|
}, [isNewThread, threadId, agent_id]);
|
||||||
|
|
||||||
const { showNotification } = useNotification();
|
const { showNotification } = useNotification();
|
||||||
const [thread, sendMessage] = useThreadStream({
|
const [thread, sendMessage, , streamThreadId] = useThreadStream({
|
||||||
threadId: isNewThread ? undefined : threadId,
|
threadId: isNewThread ? undefined : threadId,
|
||||||
assistantId: agent_id,
|
assistantId: agent_id,
|
||||||
context: { ...settings.context, agent_id },
|
context: { ...settings.context, agent_id },
|
||||||
@@ -229,13 +229,19 @@ export default function AgentChatPage({
|
|||||||
|
|
||||||
// 纯绑定任务深链(3qfx/xdfx,无闸门):进入新建对话即自动发出任务开场信息。
|
// 纯绑定任务深链(3qfx/xdfx,无闸门):进入新建对话即自动发出任务开场信息。
|
||||||
// 每次新建对话都带(与 rwfx 闸门「开始问答」发出等价);ref 防止同一会话内重复发出。
|
// 每次新建对话都带(与 rwfx 闸门「开始问答」发出等价);ref 防止同一会话内重复发出。
|
||||||
|
//
|
||||||
|
// 必须等 `streamThreadId == null`(底层 stream 已切到全新线程)才发:从已有会话点「新建对话」时,
|
||||||
|
// `isNewThread` 先翻 true,但 useThreadStream 的 onStreamThreadId 要慢一帧才重置为 null。
|
||||||
|
// 若在那一帧就 submit,hook 仍绑定上一个会话,submit 的 threadId 选项被忽略 → 开场信息发进
|
||||||
|
// 上一个对话(表现为「一直在同一个聊天框里发消息」)。等它归零再发即落到新建线程。
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!taskAutoSendText) return;
|
if (!taskAutoSendText) return;
|
||||||
if (!isNewThread) return;
|
if (!isNewThread) return;
|
||||||
|
if (streamThreadId != null) return;
|
||||||
if (taskAutoSentRef.current) return;
|
if (taskAutoSentRef.current) return;
|
||||||
taskAutoSentRef.current = true;
|
taskAutoSentRef.current = true;
|
||||||
handleSubmit({ text: taskAutoSendText, files: [] });
|
handleSubmit({ text: taskAutoSendText, files: [] });
|
||||||
}, [taskAutoSendText, isNewThread, handleSubmit]);
|
}, [taskAutoSendText, isNewThread, streamThreadId, handleSubmit]);
|
||||||
|
|
||||||
const handleClarificationSubmit = useCallback(
|
const handleClarificationSubmit = useCallback(
|
||||||
(answer: string) => {
|
(answer: string) => {
|
||||||
|
|||||||
Reference in new issue
Block a user