import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { AiResponseMessage } from "./AiResponseMessage";
import { HeartbeatMessage } from "./HeartbeatMessage";
import { UserMessage } from "./UserMessage";
import { getOperationsForMessageGroup, groupConsecutiveMessages, } from "../../agentMessageGrouping";
import { convertAgentMessagesToAiFormat } from "../../agentMessageConversion";
export function AgentTerminalMessageGroups({ messages, operations, isExecuting, defaultCollapseJson, profile, agentId, allPendingApprovals, onSwitchToAutonomous, browserCaptureInlinePrompt, readOnly, onQuickAction, }) {
    const groups = groupConsecutiveMessages(messages);
    return (_jsx(_Fragment, { children: groups.map((group, groupIndex) => {
            const isLastGroup = groupIndex === groups.length - 1;
            if (group.type === "user" && group.messages[0]) {
                const userKey = group.messages[0].id;
                if (!userKey) {
                    console.warn("[AgentTerminal] user message group missing id", {
                        groupIndex,
                    });
                }
                return (_jsx(UserMessage, { message: group.messages[0] }, userKey ?? `user-${groupIndex}`));
            }
            if (group.type === "heartbeat" && group.messages[0]) {
                return (_jsx(HeartbeatMessage, { message: group.messages[0] }, group.messages[0].id));
            }
            const filteredMessages = group.messages.filter((message) => {
                const content = message.content || "";
                return (!content.startsWith("\u26a0\ufe0f") ||
                    !content.includes("Cost limit"));
            });
            if (filteredMessages.length === 0) {
                return null;
            }
            const convertedMessages = convertAgentMessagesToAiFormat(filteredMessages);
            const operationsForGroup = getOperationsForMessageGroup(convertedMessages, operations);
            const assistantKey = filteredMessages[0]?.id;
            if (!assistantKey) {
                console.warn("[AgentTerminal] assistant message group missing id", {
                    groupIndex,
                });
            }
            return (_jsx(AiResponseMessage, { messages: convertedMessages, finished: !isLastGroup || !isExecuting, editOperations: operationsForGroup, defaultCollapseJson: defaultCollapseJson, profileSvgIcon: profile?.svgIcon, agentId: agentId, agentName: profile?.agentName || profile?.displayTitle || profile?.name, allPendingApprovals: allPendingApprovals, onSwitchToAutonomous: onSwitchToAutonomous, browserCaptureInlinePrompt: browserCaptureInlinePrompt, readOnly: readOnly, onQuickAction: (action) => onQuickAction(action) }, assistantKey ?? `assistant-${groupIndex}`));
        }) }));
}
//# sourceMappingURL=AgentTerminalMessageGroups.js.map