import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo } from "react";
import { AgentTerminalStatusBar } from "./components/AgentTerminalStatusBar";
import { buildAgentTerminalRunDiagnosticsSnapshot, } from "../agentDiagnostics";
import { normalizeDialogAgentId } from "../agentMessageHelpers";
import { selectAgentCostLimit, selectMessageStatsFromMessages, selectTotalTokensFromMessages, } from "./agentSessionSelectors";
import { loadAgentRunDiagnostics, loadAgentSessionLastPayload, loadAgentSessionOperationAllowances, } from "./useAgentSessionSync";
export function useAgentStatusBarContent(input) {
    const { agentSessionState, agent, messages, currentAgentId, isSubmitting, isConnecting, isWaitingForResponse, isAgentThinking, isExecuting, lastRunStatusReason, hasActiveStreaming, subscribedAgentIdRef, lastSeqRef, recentAgentRunEvents, currentRunDiagnostics, recentToolUiEvents, editContext, effectiveModelName, subscribeSessionSocketMessages, sessionContextWindowStatus, sessionLiveTotals, showCompressionPopover, setShowCompressionPopover, } = input;
    const agentCostLimit = selectAgentCostLimit(agentSessionState);
    const totalTokens = useMemo(() => selectTotalTokensFromMessages(messages, Number(agent?.totalImageCost) || 0), [messages, agent?.totalImageCost]);
    const messageStats = useMemo(() => selectMessageStatsFromMessages(messages), [messages]);
    const runDiagnosticsSnapshot = useMemo(() => buildAgentTerminalRunDiagnosticsSnapshot({
        agentId: currentAgentId || "",
        isSubmitting,
        isConnecting,
        isWaitingForResponse,
        isAgentThinking,
        isExecuting,
        lastStatusReason: lastRunStatusReason,
        lastStatusMessage: agent?.statusMessage || null,
        hasActiveStreaming: hasActiveStreaming(),
        isSubscribed: normalizeDialogAgentId(subscribedAgentIdRef.current) ===
            normalizeDialogAgentId(currentAgentId),
        lastSeq: lastSeqRef.current,
        recentEvents: recentAgentRunEvents,
        currentRunReceivedSeqs: currentRunDiagnostics.receivedSeqs,
        currentRunMissingSeqs: currentRunDiagnostics.missingSeqs,
        currentRunTotalEventCount: currentRunDiagnostics.totalCount,
        assistantMessageCount: messageStats.assistantMessageCount,
        assistantGroupCount: messageStats.assistantGroupCount,
        assistantGroupsWithRenderableToolCalls: messageStats.assistantGroupsWithRenderableToolCalls,
        messagesWithToolCalls: messageStats.messagesWithToolCallsCount,
        totalToolCallCount: messageStats.totalToolCallCount,
        incompleteToolCallCount: messageStats.incompleteToolCallCount,
        recentToolUiEvents,
    }), [
        agent?.statusMessage,
        currentAgentId,
        currentRunDiagnostics,
        hasActiveStreaming,
        isAgentThinking,
        isConnecting,
        isExecuting,
        isSubmitting,
        isWaitingForResponse,
        lastRunStatusReason,
        messageStats,
        recentAgentRunEvents,
        recentToolUiEvents,
        subscribedAgentIdRef,
        lastSeqRef,
    ]);
    const statusBarTotalTokens = sessionLiveTotals
        ? {
            input: sessionLiveTotals.input,
            output: sessionLiveTotals.output,
            cached: sessionLiveTotals.cached,
            cacheWrite: sessionLiveTotals.cacheWrite ?? 0,
            inputCost: sessionLiveTotals.inputCost,
            outputCost: sessionLiveTotals.outputCost,
            cachedCost: sessionLiveTotals.cachedCost,
            cacheWriteCost: sessionLiveTotals.cacheWriteCost ?? 0,
            imageCost: sessionLiveTotals.imageCost ?? 0,
            totalCost: sessionLiveTotals.totalCost,
        }
        : totalTokens;
    return editContext ? (_jsx(AgentTerminalStatusBar, { agent: agent, contextWindowStatus: sessionContextWindowStatus, effectiveModelName: effectiveModelName, socketDiagnostics: editContext.socketDiagnostics, subscribeSocketMessages: subscribeSessionSocketMessages, runDiagnosticsSnapshot: runDiagnosticsSnapshot, liveTotals: sessionLiveTotals, totalTokens: statusBarTotalTokens, costLimit: agentCostLimit, messages: messages, showDebugButtons: editContext.userInfo.preferences?.showDebugButtons ?? false, showCompressionPopover: showCompressionPopover, setShowCompressionPopover: setShowCompressionPopover, loadRunDiagnostics: loadAgentRunDiagnostics, loadLastPayload: loadAgentSessionLastPayload, loadOperationAllowances: loadAgentSessionOperationAllowances })) : null;
}
//# sourceMappingURL=useAgentStatusBarContent.js.map