fix: add missing trace info and cancellation events

This commit is contained in:
mingholy.lmh
2025-10-10 20:32:57 +08:00
parent 9fce177bd8
commit ff10b9fded
9 changed files with 206 additions and 3 deletions

View File

@@ -31,6 +31,9 @@ import {
ConversationFinishedEvent,
ApprovalMode,
parseAndFormatApiError,
logUserCancellation,
UserCancellationEvent,
UserCancellationType,
} from '@qwen-code/qwen-code-core';
import { type Part, type PartListUnion, FinishReason } from '@google/genai';
import type {
@@ -448,6 +451,17 @@ export const useGeminiStream = (
if (turnCancelledRef.current) {
return;
}
// Log user cancellation event
const prompt_id = config.getSessionId() + '########' + getPromptCount();
const cancellationEvent = new UserCancellationEvent(
UserCancellationType.REQUEST_CANCELLED,
{
prompt_id,
},
);
logUserCancellation(config, cancellationEvent);
if (pendingHistoryItemRef.current) {
if (pendingHistoryItemRef.current.type === 'tool_group') {
const updatedTools = pendingHistoryItemRef.current.tools.map(
@@ -475,7 +489,14 @@ export const useGeminiStream = (
setIsResponding(false);
setThought(null); // Reset thought when user cancels
},
[addItem, pendingHistoryItemRef, setPendingHistoryItem, setThought],
[
addItem,
pendingHistoryItemRef,
setPendingHistoryItem,
setThought,
config,
getPromptCount,
],
);
const handleErrorEvent = useCallback(