// Messages sent from server to web client
export type ServerMessage =
  | { type: 'assistant_message'; sessionId: string; text: string; done: boolean }
  | { type: 'tool_call'; sessionId: string; requestId: string; toolName: string; input: Record<string, unknown>; description?: string }
  | { type: 'tool_result'; sessionId: string; requestId: string; output: string }
  | { type: 'session_state'; sessionId: string; state: SessionState }
  | { type: 'sessions_update'; sessions: SessionInfo[] }
  | { type: 'error'; message: string }

/** Messages sent from web client to server */
export type ClientMessage =
  | { type: 'user_message'; sessionId: string; text: string }
  | { type: 'tool_decision'; sessionId: string; requestId: string; decision: 'allow' | 'deny' }
  | { type: 'cancel'; sessionId: string }
  | { type: 'list_sessions' }
  | { type: 'start_session'; cwd: string }

export type SessionState = 'idle' | 'thinking' | 'streaming' | 'awaiting_approval' | 'error'

export interface SessionInfo {
  id: string
  cwd: string
  branch?: string
  state: SessionState
  lastActivity: number
  pendingApprovals: number
}

export interface RCServerConfig {
  port: number
  host: string
  token: string
}
