export type AiSseEventName =
  | 'message.created'
  | 'reasoning.delta'
  | 'content.delta'
  | 'model.retrying'
  | 'tool.started'
  | 'tool.completed'
  | 'tool.failed'
  | 'ui.form'
  | 'ui.review'
  | 'ui.chart'
  | 'attachment.processed'
  | 'message.completed'
  | 'message.cancelled'
  | 'error'
  | 'done';

export type AiSseEmitter = (event: AiSseEventName, data: Record<string, unknown>) => void;

export interface ModelToolCall {
  id: string;
  name: string;
  arguments: string;
}

export type ModelContentPart =
  | { type: 'text'; text: string }
  | { type: 'image_url'; image_url: { url: string } };

export type ModelMessage =
  | { role: 'system'; content: string }
  | { role: 'user'; content: string | ModelContentPart[] }
  | {
      role: 'assistant';
      content: string | null;
      tool_calls?: Array<{
        id: string;
        type: 'function';
        function: { name: string; arguments: string };
      }>;
    }
  | { role: 'tool'; tool_call_id: string; content: string };

export type ModelStreamEvent =
  | { type: 'reasoning'; delta: string }
  | { type: 'content'; delta: string }
  | {
      type: 'retrying';
      attempt: number;
      maxRetries: number;
      delayMs: number;
      reason: string;
    }
  | { type: 'complete'; toolCalls: ModelToolCall[] };
