代码提交

This commit is contained in:
fengxiangdebaozi committed 2026-05-27 17:47:20 +08:00
1 parent deb9993a64
commit 24d4934c27
5 files changed
+263 -43

No files matched your search

@@ -91,6 +91,12 @@ export type Step2Snapshot = {
hasConsensus: boolean;
consensusPercentage: number;
budgetLimit: number;
/**
* 每个 seat thread 的 stub ai messages —— 加载草稿后点击历史 write_file 步骤,
* 沙箱要能复读 args.content。不存这部分 stub 的话,虚拟 URL 解析会拿不到内容。
* 老草稿可能没有这字段,反序列化时按空对象兜底。
*/
seatStubMessages: Record<string, StubAiMessage[]>;
};
/**
@@ -514,6 +520,39 @@ export function useStep2Orchestration(
],
);
/**
* 兜底:从 LangGraph messages-tuple 帧里扫描完整 tool_calls,把 args 持续灌进 stub。
* 与 `handleArtifactToolPhase` 相比:
* - 后者依赖 `onPhaseChange` 在 phase==="tool_calling" 时回调,首次出现 path 即触发自动打开;
* - 前者覆盖「phase 已切到 tool_result / streaming 后,后续帧又带回完整 tool_calls」的边界,
* 保证沙箱 MD 始终拿到 args.content 的最新版本(LangGraph 在收口阶段仍可能再发一次)。
* 不做自动打开 —— 那是 handleArtifactToolPhase 的职责;这里只做 args 同步。
*/
const handleUpstreamFrame = useCallback(
(frame: unknown, seatThreadId: string | undefined) => {
if (!seatThreadId) return;
if (!Array.isArray(frame) || frame.length === 0) return;
const chunk = frame[0];
if (!chunk || typeof chunk !== "object") return;
const obj = chunk as Record<string, unknown>;
const toolCalls = obj.tool_calls;
if (!Array.isArray(toolCalls) || toolCalls.length === 0) return;
for (const tc of toolCalls) {
if (!tc || typeof tc !== "object") continue;
const tcObj = tc as Record<string, unknown>;
const name = typeof tcObj.name === "string" ? tcObj.name : "";
if (name !== "write_file" && name !== "str_replace") continue;
const tcArgs = tcObj.args;
if (!tcArgs || typeof tcArgs !== "object") continue;
const argsObj = tcArgs as Record<string, unknown>;
const path = argsObj.path;
if (typeof path !== "string" || !path) continue;
upsertSeatToolCall(seatThreadId, name, argsObj);
}
},
[upsertSeatToolCall],
);
// ─── Dialogue / Speaker helpers ────────────────────────────────────
const appendDialogue = useCallback(
(card: {
@@ -890,6 +929,8 @@ export function useStep2Orchestration(
seatThreadId,
);
},
onUpstreamFrame: (frame) =>
handleUpstreamFrame(frame, seatThreadId),
});
if (orchestrationCancelRef.current) {
finalizeDialogue(
@@ -958,6 +999,7 @@ export function useStep2Orchestration(
clearAllStreamingSpeakers,
triggerToast,
handleArtifactToolPhase,
handleUpstreamFrame,
resolveSeatThreadId,
],
);
@@ -1236,6 +1278,9 @@ export function useStep2Orchestration(
setHasConsensus(snapshot.hasConsensus);
setConsensusPercentage(snapshot.consensusPercentage);
setBudgetLimit(snapshot.budgetLimit);
const restoredStubs = snapshot.seatStubMessages ?? {};
seatStubMessagesRef.current = restoredStubs;
setSeatStubMessages(restoredStubs);
// 调用方根据 furthestStep 决定是否置 init 闸门为已 init;这里默认置上,
// 调用方需要的话再 resetInitGate()。
step2InitRef.current = true;