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:
parent
d1907636fe
commit
fb811c7cf4
|
|
@ -61,7 +61,7 @@ export interface FileAttachment {
|
||||||
|
|
||||||
/** 兼容旧版 StreamChunk 格式 */
|
/** 兼容旧版 StreamChunk 格式 */
|
||||||
export interface 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';
|
| 'agent_start' | 'agent_progress' | 'agent_complete' | 'coordinator_thinking';
|
||||||
content?: string;
|
content?: string;
|
||||||
toolName?: string;
|
toolName?: string;
|
||||||
|
|
@ -511,7 +511,7 @@ export class CoordinatorAgentService implements OnModuleInit {
|
||||||
|
|
||||||
case 'usage':
|
case 'usage':
|
||||||
return {
|
return {
|
||||||
type: 'end',
|
type: 'usage',
|
||||||
inputTokens: event.usage.inputTokens,
|
inputTokens: event.usage.inputTokens,
|
||||||
outputTokens: event.usage.outputTokens,
|
outputTokens: event.usage.outputTokens,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue