/**
 * Chat types — shared between session store, LLM client, and HTTP API.
 *
 * Block shape mirrors the Anthropic Messages API (text / tool_use /
 * tool_result) so the extension and Forge speak the same dialect.
 */

export type Role = 'user' | 'assistant';

export interface TextBlock {
  type: 'text';
  text: string;
}

export interface ToolUseBlock {
  type: 'tool_use';
  id: string;
  name: string;
  input: unknown;
}

export interface ToolResultBlock {
  type: 'tool_result';
  tool_use_id: string;
  content: string;
  is_error?: boolean;
}

export type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock;

export interface Message {
  id: string;
  session_id: string;
  role: Role;
  blocks: ContentBlock[];
  ts: number;
  error?: string;
}

export interface Session {
  id: string;
  title: string | null;
  created_at: number;
  updated_at: number;
  model: string | null;
  provider: string | null;
  system_prompt: string | null;
  /** Free-form metadata (e.g. linked workspace, project, etc.) */
  meta?: Record<string, unknown>;
}
