import type { TerminalHeaderProps } from "./terminal-header.js"; import type { GroupedResponseItem } from "./use-message-grouping.js"; import type { ResponseItem } from "openai/resources/responses/responses.mjs"; import TerminalChatResponseItem from "./terminal-chat-response-item.js"; import TerminalHeader from "./terminal-header.js"; import { Box, Static, Text } from "ink"; import React, { useMemo } from "react"; // A batch entry can either be a standalone response item or a grouped set of // items (e.g. auto‑approved tool‑call batches) that should be rendered // together. type BatchEntry = { item?: ResponseItem; group?: GroupedResponseItem }; type MessageHistoryProps = { batch: Array; groupCounts: Record; items: Array; userMsgCount: number; confirmationPrompt: React.ReactNode; loading: boolean; thinkingSeconds: number; headerProps: TerminalHeaderProps; fullStdout: boolean; }; const MessageHistory: React.FC = ({ batch, headerProps, loading, thinkingSeconds, fullStdout, }) => { // Flatten batch entries to response items. const messages = useMemo(() => batch.map(({ item }) => item!), [batch]); return ( {loading && ( {`thinking for ${thinkingSeconds}s`} )} {(item, index) => { if (item === "header") { return ; } // After the guard above, item is a ResponseItem const message = item as ResponseItem; // Suppress empty reasoning updates (i.e. items with an empty summary). const msg = message as unknown as { summary?: Array }; if (msg.summary?.length === 0) { return null; } return ( ); }} ); }; export default React.memo(MessageHistory);