/**
 * SSE stream events — the canonical wire shape consumed by the reducer.
 *
 * Backend-specific shapes (e.g. pydantic-AI's `text_delta`) get normalized
 * into this union by `mapPydanticAIEvent` and friends.
 */

import type { ChatSource } from './attachment';

export type ChatStreamEvent =
  | { type: 'message_start'; messageId: string; sessionId: string }
  | { type: 'resume_start' }
  | { type: 'chunk'; delta: string }
  | { type: 'tool_activity'; tool: string; status: string }
  | {
      type: 'tool_call_start';
      toolId: string;
      name: string;
      input: unknown;
      sourceHostname?: string;
    }
  | { type: 'tool_call_delta'; toolId: string; delta: string }
  | {
      type: 'tool_call_end';
      toolId: string;
      output: unknown;
      status: 'success' | 'error';
    }
  | {
      type: 'message_end';
      tokensIn?: number;
      tokensOut?: number;
      sources?: ChatSource[];
    }
  | { type: 'error'; code: string; message: string };
