/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import type React from 'react'; import { useMemo } from 'react'; import { escapeAnsiCtrlCodes, sanitizeSensitiveText, } from '../utils/textUtils.js'; import type { HistoryItem } from '../types.js'; import { UserMessage, UserShellMessage, AssistantMessage, AssistantMessageContent, ThinkMessage, ThinkMessageContent, } from './messages/ConversationMessages.js'; import { ToolGroupMessage } from './messages/ToolGroupMessage.js'; import { CompressionMessage } from './messages/CompressionMessage.js'; import { SummaryMessage } from './messages/SummaryMessage.js'; import { InfoMessage, WarningMessage, ErrorMessage, RetryCountdownMessage, SuccessMessage, } from './messages/StatusMessages.js'; import { Box, Text } from 'ink'; import { theme } from '../semantic-colors.js'; import { MarkdownDisplay } from '../utils/MarkdownDisplay.js'; import { AboutBox } from './AboutBox.js'; import { StatsDisplay } from './StatsDisplay.js'; import { ModelStatsDisplay } from './ModelStatsDisplay.js'; import { ToolStatsDisplay } from './ToolStatsDisplay.js'; import { SessionSummaryDisplay } from './SessionSummaryDisplay.js'; import { Help } from './Help.js'; import type { SlashCommand } from '../commands/types.js'; import { ExtensionsList } from './views/ExtensionsList.js'; import { getMCPServerStatus } from '@qwen-code/qwen-code-core'; import { SkillsList } from './views/SkillsList.js'; import { ToolsList } from './views/ToolsList.js'; import { McpStatus } from './views/McpStatus.js'; import { ContextUsage } from './views/ContextUsage.js'; import { DoctorReport } from './views/DoctorReport.js'; import { ArenaAgentCard, ArenaSessionCard } from './arena/ArenaCards.js'; import { InsightProgressMessage } from './messages/InsightProgressMessage.js'; import { BtwMessage } from './messages/BtwMessage.js'; import { MemorySavedMessage } from './messages/MemorySavedMessage.js'; import { useCompactMode } from '../contexts/CompactModeContext.js'; interface HistoryItemDisplayProps { item: HistoryItem; availableTerminalHeight?: number; terminalWidth: number; mainAreaWidth?: number; isPending: boolean; isFocused?: boolean; commands?: readonly SlashCommand[]; activeShellPtyId?: number | null; embeddedShellFocused?: boolean; availableTerminalHeightGemini?: number; } const HistoryItemDisplayComponent: React.FC = ({ item, availableTerminalHeight, terminalWidth, mainAreaWidth, isPending, commands, isFocused = true, activeShellPtyId, embeddedShellFocused, availableTerminalHeightGemini, }) => { const marginTop = item.type === 'gemini_content' || item.type === 'gemini_thought_content' ? 0 : 1; const { compactMode } = useCompactMode(); const itemForDisplay = useMemo(() => escapeAnsiCtrlCodes(item), [item]); const contentWidth = terminalWidth - 4; const boxWidth = mainAreaWidth || contentWidth; return ( {/* Render standard message types */} {itemForDisplay.type === 'user' && ( )} {itemForDisplay.type === 'notification' && ( )} {itemForDisplay.type === 'user_shell' && ( )} {itemForDisplay.type === 'gemini' && ( )} {itemForDisplay.type === 'gemini_content' && ( )} {!compactMode && itemForDisplay.type === 'gemini_thought' && ( )} {!compactMode && itemForDisplay.type === 'gemini_thought_content' && ( )} {itemForDisplay.type === 'info' && ( )} {itemForDisplay.type === 'success' && ( )} {itemForDisplay.type === 'warning' && ( )} {itemForDisplay.type === 'error' && ( )} {itemForDisplay.type === 'retry_countdown' && ( )} {itemForDisplay.type === 'about' && ( )} {itemForDisplay.type === 'help' && commands && ( )} {itemForDisplay.type === 'stats' && ( )} {itemForDisplay.type === 'model_stats' && ( )} {itemForDisplay.type === 'tool_stats' && ( )} {itemForDisplay.type === 'quit' && ( )} {itemForDisplay.type === 'tool_group' && ( )} {itemForDisplay.type === 'compression' && ( )} {itemForDisplay.type === 'summary' && ( )} {itemForDisplay.type === 'extensions_list' && } {itemForDisplay.type === 'tools_list' && ( )} {itemForDisplay.type === 'skills_list' && ( )} {itemForDisplay.type === 'mcp_status' && ( )} {itemForDisplay.type === 'context_usage' && ( )} {itemForDisplay.type === 'doctor' && ( )} {itemForDisplay.type === 'arena_agent_complete' && ( )} {itemForDisplay.type === 'arena_session_complete' && ( )} {itemForDisplay.type === 'insight_progress' && ( )} {itemForDisplay.type === 'btw' && itemForDisplay.btw && ( )} {itemForDisplay.type === 'user_prompt_submit_blocked' && ( {`✕ UserPromptSubmit operation blocked by hook:\n${itemForDisplay.reason}\n\nOriginal prompt: ${sanitizeSensitiveText(itemForDisplay.originalPrompt)}`} )} {itemForDisplay.type === 'stop_hook_loop' && ( )} {itemForDisplay.type === 'stop_hook_system_message' && ( ⎿ Stop says: )} {itemForDisplay.type === 'memory_saved' && ( )} ); }; // Export alias for backward compatibility export { HistoryItemDisplayComponent as HistoryItemDisplay };