|
|
|
@ -41,6 +41,7 @@ export function useAgentChat(options: UseAgentChatOptions) { |
|
|
|
); |
|
|
|
|
|
|
|
let abortController: AbortController | null = null; |
|
|
|
let staleApprovalToolCallIds: Set<string> = new Set(); |
|
|
|
|
|
|
|
function generateId(): string { |
|
|
|
return Date.now().toString(36) + Math.random().toString(36).slice(2); |
|
|
|
@ -282,8 +283,10 @@ export function useAgentChat(options: UseAgentChatOptions) { |
|
|
|
const hasPendingApproval = pendingApprovalParts && pendingApprovalParts.length > 0; |
|
|
|
if (hasPendingApproval && isApprovalContinue && hasText) { |
|
|
|
pendingApprovalParts!.forEach((p) => { |
|
|
|
p.state = "result"; |
|
|
|
p.result = "(此工具调用已被跳过——AI 已给出最终回复)"; |
|
|
|
if (staleApprovalToolCallIds.has(p.toolCallId ?? "")) { |
|
|
|
p.state = "result"; |
|
|
|
p.result = "(此工具调用已被跳过——AI 已给出最终回复)"; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
const hasReasoning = finalMsg.parts?.some((p) => p.type === "reasoning" && p.text); |
|
|
|
@ -317,6 +320,7 @@ export function useAgentChat(options: UseAgentChatOptions) { |
|
|
|
|
|
|
|
errorMessage.value = ""; |
|
|
|
isStopped.value = false; |
|
|
|
staleApprovalToolCallIds = new Set(); |
|
|
|
|
|
|
|
let userMsgIdx = -1; |
|
|
|
|
|
|
|
@ -469,6 +473,14 @@ export function useAgentChat(options: UseAgentChatOptions) { |
|
|
|
); |
|
|
|
if (hasOtherPendingApprovals) return; |
|
|
|
|
|
|
|
staleApprovalToolCallIds = new Set( |
|
|
|
messages.value.flatMap((m) => |
|
|
|
(m.parts ?? []) |
|
|
|
.filter((p) => p.state === "approval-requested" && !p.isAutomaticApproval) |
|
|
|
.map((p) => p.toolCallId ?? ""), |
|
|
|
), |
|
|
|
); |
|
|
|
|
|
|
|
isLoading.value = true; |
|
|
|
abortController = new AbortController(); |
|
|
|
|
|
|
|
|