import type {
  AgentRuntime,
  AgentRuntimeSessions,
  AgentSession,
  ManualCompactionResult,
  RuntimeConfig,
  SessionModeId,
  ToolApprovalMode,
} from '#cli/compat/runtime'
import type { McpServerConfig } from '#cli/compat/mcp'

export type CliSessionModeId = Extract<SessionModeId, 'agent' | 'plan'>

export type CliAgentBridge = Readonly<{
  runtime?: AgentRuntime
  sessions?: AgentRuntimeSessions
  openSession?: (sessionId: string) => Promise<AgentSession | null>
  ensureSession?: (opts?: {
    sessionId?: string
    cwd?: string
    modeId?: CliSessionModeId
    runtimeConfig?: RuntimeConfig
    toolApprovalMode?: ToolApprovalMode
    mcpServers?: McpServerConfig[]
    metadata?: Record<string, unknown>
  }) => Promise<AgentSession>
  steerSession?: (sessionId: string, input: string) => Promise<boolean>
  setMode?: (modeId: CliSessionModeId) => void
  getMode?: () => CliSessionModeId
  triggerManualCompression?: (
    sessionId?: string,
  ) => Promise<ManualCompactionResult>
  invalidateSession?: (sessionId: string) => void
  receiveMessage?: (
    messages: readonly unknown[],
    metadata?: Record<string, unknown>,
  ) => AsyncIterable<unknown>
}>
