/**
* @license
* Copyright 2025 Vybestack LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type React from 'react';
import { useMemo } from 'react';
import { escapeAnsiCtrlCodes } from '../utils/textUtils.js';
import type { HistoryItem } from '../types.js';
import { UserMessage } from './messages/UserMessage.js';
import { UserShellMessage } from './messages/UserShellMessage.js';
import { AiMessage } from './messages/AiMessage.js';
import { InfoMessage } from './messages/InfoMessage.js';
import { ErrorMessage } from './messages/ErrorMessage.js';
import { OAuthUrlMessage } from './messages/OAuthUrlMessage.js';
import { ToolGroupMessage } from './messages/ToolGroupMessage.js';
import { AiMessageContent } from './messages/AiMessageContent.js';
import { CompressionMessage } from './messages/CompressionMessage.js';
import { WarningMessage } from './messages/WarningMessage.js';
import { ProfileChangeMessage } from './messages/ProfileChangeMessage.js';
import { Box, Text } from 'ink';
import { AboutBox } from './AboutBox.js';
import { StatsDisplay } from './StatsDisplay.js';
import { ModelStatsDisplay } from './ModelStatsDisplay.js';
import { ToolStatsDisplay } from './ToolStatsDisplay.js';
import { CacheStatsDisplay } from './CacheStatsDisplay.js';
import { LBStatsDisplay } from './LBStatsDisplay.js';
import { SessionSummaryDisplay } from './SessionSummaryDisplay.js';
import { Help } from './Help.js';
import type { SlashCommand } from '../commands/types.js';
import { ChatList } from './views/ChatList.js';
import { ExtensionsList } from './views/ExtensionsList.js';
import { HooksList } from './views/HooksList.js';
import { SkillsList } from './views/SkillsList.js';
import type { CliUiRuntime } from '../cliUiRuntime.js';
interface HistoryItemDisplayProps {
item: HistoryItem;
availableTerminalHeight?: number;
terminalWidth: number;
isPending: boolean;
config: CliUiRuntime;
isFocused?: boolean;
slashCommands?: readonly SlashCommand[]; // For help display
showTodoPanel?: boolean;
commands?: readonly SlashCommand[];
activeShellPtyId?: number | null;
embeddedShellFocused?: boolean;
availableTerminalHeightAi?: number;
}
function useSanitizedItem(item: HistoryItem) {
return useMemo(() => {
if (
item.type === 'info' ||
item.type === 'error' ||
item.type === 'warning' ||
item.type === 'oauth_url'
) {
return item;
}
return escapeAnsiCtrlCodes(item);
}, [item]);
}
function renderCoreMessages(
itemForDisplay: HistoryItem,
isPending: boolean,
availableTerminalHeight: number | undefined,
terminalWidth: number,
_availableTerminalHeightAi: number | undefined,
) {
switch (itemForDisplay.type) {
case 'user':
return ;
case 'user_shell':
return ;
case 'gemini':
return (
);
case 'gemini_content':
return (
);
case 'info':
return (
);
case 'warning':
return ;
case 'error':
return ;
case 'oauth_url':
return (
);
default:
return null;
}
}
function renderStatsMessages(itemForDisplay: HistoryItem) {
switch (itemForDisplay.type) {
case 'stats':
return (
);
case 'model_stats':
return ;
case 'tool_stats':
return ;
case 'cache_stats':
return ;
case 'lb_stats':
return ;
case 'quit':
return (
);
default:
return null;
}
}
function renderInfoViews(
itemForDisplay: HistoryItem,
slashCommands: readonly SlashCommand[],
) {
switch (itemForDisplay.type) {
case 'about':
return (
);
case 'help':
return ;
case 'compression':
return ;
case 'profile_change':
return ;
default:
return null;
}
}
function renderListViewMessages(itemForDisplay: HistoryItem) {
switch (itemForDisplay.type) {
case 'extensions_list':
return ;
case 'hooks_list':
return ;
case 'tools_list':
return (
Tools list view not yet implemented
);
case 'skills_list':
return (
);
case 'mcp_status':
return (
MCP status view not yet implemented
);
case 'chat_list':
return ;
default:
return null;
}
}
function renderToolGroupMessage(
itemForDisplay: HistoryItem,
availableTerminalHeight: number | undefined,
terminalWidth: number,
config: CliUiRuntime,
isFocused: boolean,
showTodoPanel: boolean,
_activeShellPtyId: number | null | undefined,
_embeddedShellFocused: boolean | undefined,
) {
if (itemForDisplay.type !== 'tool_group') return null;
return (
);
}
export const HistoryItemDisplay: React.FC = ({
item,
availableTerminalHeight,
terminalWidth,
isPending,
config,
isFocused = true,
slashCommands = [],
showTodoPanel = true,
activeShellPtyId: _activeShellPtyId,
embeddedShellFocused: _embeddedShellFocused,
availableTerminalHeightAi: _availableTerminalHeightAi,
}) => {
const itemForDisplay = useSanitizedItem(item);
return (
{renderCoreMessages(
itemForDisplay,
isPending,
availableTerminalHeight,
terminalWidth,
_availableTerminalHeightAi,
)}
{renderStatsMessages(itemForDisplay)}
{renderInfoViews(itemForDisplay, slashCommands)}
{renderListViewMessages(itemForDisplay)}
{renderToolGroupMessage(
itemForDisplay,
availableTerminalHeight,
terminalWidth,
config,
isFocused,
showTodoPanel,
_activeShellPtyId,
_embeddedShellFocused,
)}
);
};