fix(agents): prevent usage events from emitting stream_end to frontend

The mapEventToStreamChunk was mapping both 'usage' (per-turn) and 'end'
(final) events to type 'end', causing the gateway to emit multiple
stream_end events. This made the frontend create a separate message
bubble (with its own bot avatar) for each agent loop turn.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-06 08:58:11 -08:00
parent d1907636fe
commit fb811c7cf4
1 changed files with 2 additions and 2 deletions

View File

@ -61,7 +61,7 @@ export interface FileAttachment {
/** 兼容旧版 StreamChunk 格式 */
export interface StreamChunk {
type: 'text' | 'tool_use' | 'tool_result' | 'end' | 'stage_change' | 'state_update' | 'error'
type: 'text' | 'tool_use' | 'tool_result' | 'end' | 'usage' | 'stage_change' | 'state_update' | 'error'
| 'agent_start' | 'agent_progress' | 'agent_complete' | 'coordinator_thinking';
content?: string;
toolName?: string;
@ -511,7 +511,7 @@ export class CoordinatorAgentService implements OnModuleInit {
case 'usage':
return {
type: 'end',
type: 'usage',
inputTokens: event.usage.inputTokens,
outputTokens: event.usage.outputTokens,
};