/**
 * LLM adapter types — ported from the extension.
 */

import type { ContentBlock, Message } from '../types';

export interface LlmTool {
  name: string;
  description: string;
  input_schema: {
    type: 'object';
    properties: Record<string, unknown>;
    required?: string[];
  };
}

export interface LlmCallbacks {
  onTextDelta: (delta: string) => void;
  onToolUse: (block: { id: string; name: string; input: unknown }) => void;
}

export type StopReason = 'end_turn' | 'tool_use' | 'max_tokens' | 'refusal' | 'error' | 'other';

export interface LlmTurnUsage {
  inputTokens?: number;
  outputTokens?: number;
  cacheReadTokens?: number;
  cacheCreationTokens?: number;
  totalTokens?: number;
}

export interface LlmTurnResult {
  stopReason: StopReason;
  content: ContentBlock[];
  /** Token usage from the provider, if reported. May be partially-filled
   *  or absent for proxies that don't expose it. */
  usage?: LlmTurnUsage;
}

export interface LlmRequest {
  provider: 'anthropic' | 'openai';
  apiKey: string;
  baseUrl: string;
  model: string;
  system: string;
  history: Message[];
  tools: LlmTool[];
  maxTokens: number;
}

export interface LlmAdapter {
  stream(req: LlmRequest, cb: LlmCallbacks): Promise<LlmTurnResult>;
}
