import { useEditContext, useFieldsEditContext } from "../../client/editContext";
import { useAgentActiveStreaming } from "./useAgentActiveStreaming";
import { useAgentEditorContext } from "./useAgentEditorContext";
import { useAgentEditorContextPipeline } from "./useAgentEditorContextPipeline";
import { useAgentEffectiveModelName } from "./useAgentEffectiveModelName";
import { useAgentBrowserCapturePanel, } from "./useAgentBrowserCapturePanel";
import { useAgentInlineDialogPipeline } from "./useAgentInlineDialogPipeline";
import { useAgentRunDiagnostics } from "./useAgentRunDiagnostics";
import { useAgentRunRefs } from "./useAgentRunRefs";
import { useAgentRunMessagePipeline } from "./useAgentRunMessagePipeline";
import { useAgentLoadPipeline } from "./useAgentLoadPipeline";
import { useAgentPromptComposerSurface } from "./useAgentPromptComposerSurface";
import { useAgentTextareaDropHandlers } from "./useAgentTextareaDropHandlers";
import { useAgentPromptDraft } from "./useAgentPromptDraft";
import { useAgentSettingsPanel } from "./useAgentSettingsPanel";
import { useAgentStopGuardState } from "./useAgentStopGuardState";
import { useAgentRuntimeStatus } from "./useAgentRuntimeStatus";
import { useAgentStreamPipeline } from "./useAgentStreamPipeline";
import { useAgentSubmitLifecycle } from "./useAgentSubmitLifecycle";
import { useAgentInitialMetadataMerge } from "./useAgentInitialMetadataMerge";
import { useAgentMessageCompletionNotifier } from "./useAgentMessageCompletionNotifier";
import { useAgentTerminalScroll } from "./useAgentTerminalScroll";
import { useAgentTerminalElementRefs } from "./useAgentTerminalElementRefs";
import { useAgentTerminalNotices } from "./useAgentTerminalNotices";
import { useAgentTerminalBackgroundEvents } from "./useAgentTerminalBackgroundEvents";
import { useAgentTerminalControls } from "./useAgentTerminalControls";
import { useAgentTerminalUiState } from "./useAgentTerminalUiState";
import { useAgentTerminalViewState } from "./useAgentTerminalViewState";
import { useAgentTerminalViewProps } from "./useAgentTerminalViewProps";
import { useAgentToolApprovalSupersede } from "./useAgentToolApprovalSupersede";
import { useAgentToolUiEvents } from "./useAgentToolUiEvents";
import { useAgentVoiceInput } from "./useAgentVoiceInput";
import { useSuppressedQueuedPrompts } from "./useSuppressedQueuedPrompts";
import { deleteQueuedPromptSessionEntry } from "./useAgentSessionSync";
import { sanitizeAgentMetadata } from "./agentSessionMetadata";
import { useAgentSession } from "./useAgentSession";
import { useAgentSessionFacade } from "./useAgentSessionFacade";
import { useAgentSessionSocketSource } from "./useAgentSessionSocketSource";
import { normalizeSessionRunId as normalizeRunId } from "./agentSessionState";
export function useAgentTerminalController({ agentStub, initialMetadata, profiles, onReloadProfiles, isActive, isVisible, isFocused, compact = false, displayMode = "full", showSummaryInput = false, hideContext = false, hideBottomControls = false, showStatusBar, showAgentConfigControls, hideGreeting = false, defaultCollapseJson = false, simpleMode = false, className, initialPrompt, onAgentUpdate, onMessage, onInteractionSubmitted, onQuestionnaireOpenChange, questionnaireFooterActions, hideSummaryMessages = false, summaryPlaceholderActions, summaryPlaceholderMessage, hideSummaryWaitingPlaceholder = false, }) {
    // Derived from props. `isVisible` controls "is this terminal mounted and
    // streaming" (subscriptions, polling). `isFocused` controls "does this
    // terminal own keyboard focus and dialogs". Both fall back to legacy
    // `isActive` for the 8 callers that haven't been updated to the split props.
    const effectiveIsVisible = isVisible ?? isActive ?? true;
    const effectiveIsFocused = isFocused ?? isActive ?? true;
    const editContext = useEditContext();
    const { editContextRef, subscribeSessionSocketMessages } = useAgentSessionSocketSource(editContext);
    const fieldsContext = useFieldsEditContext();
    const agentSession = useAgentSession({ agentStub });
    const { state: sessionState, actions: sessionActions, commands: sessionCommands, bindCommands: bindSessionCommands, agent, agentStateRef, setAgent, messages, messagesRef, addOptimisticTranscriptMessage, removeOptimisticTranscriptMessage, isLoading, isConnecting, isSubmitting, isWaitingForResponse, isStopGuardActive, isAgentThinking, lastRunStatusReason, isExecuting, readOnly, error, setError, allPendingApprovals, hasPendingApprovals, setIsConnecting, setIsSubmitting, setIsWaitingForResponse, setIsStopGuardActive, setIsAgentThinking, setLastRunStatusReason, agentMetadata, agentMetadataRef, setAgentMetadata, operationHistory: sessionAgentOperations, queuedPrompts: sessionQueuedPrompts, costLimitExceeded: sessionCostLimitExceeded, contextWindowStatus: sessionContextWindowStatus, liveTotals: sessionLiveTotals, browserClaimMutationPending: sessionBrowserClaimMutationPending, setBrowserClaimMutationPending, replaceQueuedPrompts, } = useAgentSessionFacade({
        agentStub,
        agentSession,
    });
    const { prompt, setPrompt, promptHistory, setPromptHistory, currentHistoryIndex, setCurrentHistoryIndex, } = useAgentPromptDraft({
        agentId: agentStub.id,
        isDraftOwner: effectiveIsFocused,
    });
    useAgentMessageCompletionNotifier({
        agentId: agentStub.id,
        messages,
        onMessage,
    });
    const { recentToolUiEvents, appendToolUiEvent } = useAgentToolUiEvents();
    const { activeInlineDialog, activeInlineDialogRef, setActiveInlineDialog, cancelActiveInlineDialog, dialogTerminalInstanceIdRef, isQuestionnaireDialogOpen, schedulePendingDialogReplay, } = useAgentInlineDialogPipeline({
        inlineDialogState: {
            activeInlineDialog: sessionState.activeInlineDialog,
            setSessionActiveInlineDialog: sessionActions.setActiveInlineDialog,
            onQuestionnaireOpenChange,
        },
        summaryScroll: {
            displayMode,
            getMessagesContainer: () => messagesContainerRef.current,
        },
        questionnaireRecovery: {
            messagesRef,
            agentId: agent?.id || agentStub.id,
            sessionId: editContext?.sessionId,
            appendToolUiEvent,
            onInteractionSubmitted,
        },
        pendingRecovery: {
            agentId: agentStub.id,
            agentStatus: agent?.status,
            sessionId: editContext?.sessionId,
            appendToolUiEvent,
        },
    });
    const { isStoppingRef, clearStopGuard, armStopGuard } = useAgentStopGuardState({
        setIsStopGuardActive,
    });
    useAgentInitialMetadataMerge({
        initialMetadata,
        setAgentMetadata,
    });
    const hasActiveStreaming = useAgentActiveStreaming({ messagesRef });
    const currentAgentId = agent?.id || agentStub.id;
    const currentRunDiagnostics = useAgentRunDiagnostics({
        agentId: currentAgentId,
        webSocketMessages: editContext?.webSocketMessages,
    });
    const recentAgentRunEvents = currentRunDiagnostics.events;
    const { inputPlaceholder, setInputPlaceholder, activePlaceholderInput, setActivePlaceholderInput, allPlaceholdersFilled, setAllPlaceholdersFilled, showCompressionPopover, setShowCompressionPopover, showPredefined, setShowPredefined, contextPanelsActiveTab, setContextPanelsActiveTab, showCostAndAgent, setShowCostAndAgent, showAgentSettings, setShowAgentSettings, showSkillPicker, setShowSkillPicker, toolsSectionExpanded, setToolsSectionExpanded, allowancesSectionExpanded, setAllowancesSectionExpanded, subscribedTriggersSectionExpanded, setSubscribedTriggersSectionExpanded, } = useAgentTerminalUiState();
    const { addVisibleTestIdsToContext, buildEditorContextPayload, buildCurrentContext, } = useAgentEditorContext({
        editContext,
        fieldsContext,
    });
    const { activeProfile, setActiveProfile, activeTriggerSubscriptions, allowanceGroups, allowancesTotalCount, autoAssignedSkillSet, displayedAvailableTools, displayedAvailableToolsError, displayedAvailableToolsLoading, displayedOperationAllowancesError, displayedOperationAllowancesLoading, hasAnyAllowances, handleAddSkill, handleOpenProfileSettings, handleOpenSkillItem, handleRemoveSkill, handleSwitchToAutonomous, isLocalOnlyDraftAgent, manuallyAssignableSkillIdSet, mode, modeOptions, modelOptions, pendingSettingsRef, persistPendingSettingsIfNeeded, getPendingRequestSettings, profileOptions, profileFilteredSkills, selectedModelId, setMode, setSelectedModelId, selectedSkillIds, selectedSkills, selectableTemplateIdSet, setSkillActionError, skillActionError, skillRootIds, skillsError, skillsLoading, triggerSubscriptionsError, triggerSubscriptionsLoading, } = useAgentSettingsPanel({
        agent,
        agentStub,
        agentMetadata,
        profiles,
        editContext,
        showAgentSettings,
        onReloadProfiles,
        buildCurrentContext,
        sanitizeAgentMetadata,
        onAgentUpdate,
        readOnly,
        setAgent,
        setAgentMetadata,
    });
    const { supersedePendingApprovals } = useAgentToolApprovalSupersede({
        agentId: agent?.id || agentStub.id,
        pendingApprovals: allPendingApprovals,
        setError,
    });
    const sessionAgentMetadata = agentMetadata;
    const { isPendingBrowserCaptureWait, isClaimedByCurrentSession, setPendingBrowserCaptureWait, clearPendingBrowserCaptureWait, claimBrowser: handleClaimBrowser, releaseBrowser: handleReleaseBrowser, fixedBrowserClaimBanner, inlineBrowserClaimBanner, browserCaptureInlinePrompt, } = useAgentBrowserCapturePanel({
        agentId: agent?.id,
        agentStatus: agent?.status,
        sessionId: editContext?.sessionId,
        metadata: sessionAgentMetadata,
        terminalInstanceIdRef: dialogTerminalInstanceIdRef,
        setMetadata: setAgentMetadata,
        sanitizeMetadata: sanitizeAgentMetadata,
        setMutationPending: setBrowserClaimMutationPending,
        showErrorToast: editContext?.showErrorToast,
        mutationPending: sessionBrowserClaimMutationPending,
    });
    const effectiveModelName = useAgentEffectiveModelName({
        state: sessionState,
        activeProfile,
        selectedModelId,
    });
    const { messagesEndRef, textareaRef, documentListRef, placeholderInputRef, promptPlaceholderInputRef, shouldSubmitFilledPlaceholderInputRef, inlineDialogContainerRef, } = useAgentTerminalElementRefs();
    const { isVoiceDisabled, isListening, handleVoicePointerDown, handleVoicePointerUp, handleVoicePointerCancel, } = useAgentVoiceInput({
        inputPlaceholder,
        language: editContext?.currentItemDescriptor?.language,
        prompt,
        textareaRef,
        setInputPlaceholder,
        setPrompt,
    });
    const { isWaitingRef, seenMessageIdsRef, lastSeqRef, shouldCreateNewMessageRef: shouldCreateNewMessage, currentRunIdRef, lastSettledRunIdRef, lastResyncedMessageIdsRef, subscribedAgentIdRef, lastNonHeartbeatUpdateAtRef, lastStallReloadAtRef, noteMissingRunId, } = useAgentRunRefs({ isWaitingForResponse });
    const { registerSuppressedQueuedPrompt, clearSuppressedQueuedPrompt, shouldSuppressQueuedPrompt, } = useSuppressedQueuedPrompts();
    const { buildSubmitContext, handleRefreshContext, resolvedPageName, resolvedComponentName, resolvedFieldName, } = useAgentEditorContextPipeline({
        buildCurrentContext,
        addVisibleTestIdsToContext,
        submitContext: {
            agent,
            agentMetadata,
            activeProfile,
            profiles,
            editContext,
        },
        contextSync: {
            agent,
            agentMetadata,
            activeProfile,
            profiles,
            editContext,
            fieldsContext,
            sanitizeAgentMetadata,
            setAgentMetadata,
        },
        displayNames: {
            agentMetadata,
            editContext,
        },
    });
    const { messagesContainerRef, setShouldAutoScroll, shouldMaintainFocusRef, scrollToBottom, handleScroll, } = useAgentTerminalScroll({
        messages,
        textareaRef,
        activePlaceholderInput,
        effectiveIsFocused,
    });
    const { stripHeartbeatMessages, handleHeartbeatMessage, clearHeartbeatMessages, settleCompletedRun, createNewStreamMessage, handleContextUpdate, acceptRunSequenceFrame, handleContentChunk, handleToolCall, handleToolResult, } = useAgentRunMessagePipeline({
        streamMessageFactory: {
            agent,
            agentStubId: agentStub.id,
        },
        contextUpdate: {
            setAgentMetadata,
        },
        sequenceGuard: {
            lastSeqRef,
            actions: sessionActions,
            appendToolUiEvent,
        },
        heartbeat: {
            agent,
            agentStubId: agentStub.id,
            actions: sessionActions,
            messagesRef,
        },
        settle: {
            currentRunIdRef,
            lastSettledRunIdRef,
            messagesRef,
            clearStopGuard,
            setError,
            setAgent,
            isWaitingRef,
            shouldCreateNewMessageRef: shouldCreateNewMessage,
            sessionActions,
        },
        contentChunk: {
            agent,
            actions: sessionActions,
            messagesRef,
            isWaitingRef,
            shouldCreateNewMessageRef: shouldCreateNewMessage,
            setIsWaitingForResponse,
            setIsAgentThinking,
        },
        toolCall: {
            actions: sessionActions,
            messagesRef,
            appendToolUiEvent,
            setIsAgentThinking,
        },
        toolResult: {
            agent,
            actions: sessionActions,
            messagesRef,
            shouldCreateNewMessageRef: shouldCreateNewMessage,
            appendToolUiEvent,
        },
    });
    const { loadAgent, reconcileServerStateRef } = useAgentLoadPipeline({
        agent,
        agentStub,
        initialMetadata,
        profiles,
        currentItemDescriptor: editContext?.currentItemDescriptor,
        buildEditorContextPayload,
        messagesRef,
        sessionActions,
        setAgent,
        setAgentMetadata,
        setError,
        setPrompt,
        isStoppingRef,
        isWaitingRef,
        setIsWaitingForResponse,
        setIsConnecting,
        setIsAgentThinking,
        seenMessageIdsRef,
        sanitizeAgentMetadata,
        effectiveIsVisible,
        sessionCostLimitExceeded,
        sessionLiveTotalCost: sessionLiveTotals?.totalCost,
    });
    useAgentStreamPipeline({
        agent,
        agentStubId: agentStub.id,
        profiles,
        setAgent,
        setAgentMetadata,
        setActiveProfile,
        onAgentUpdate,
        sessionActions,
        messagesRef,
        seenMessageIdsRef,
        shouldSuppressQueuedPrompt,
        clearHeartbeatMessages,
        handleContentChunk,
        handleToolCall,
        handleToolResult,
        handleHeartbeatMessage,
        handleContextUpdate,
        appendToolUiEvent,
        isStoppingRef,
        currentRunIdRef,
        lastSettledRunIdRef,
        lastSeqRef,
        lastResyncedMessageIdsRef,
        lastNonHeartbeatUpdateAtRef,
        normalizeRunId,
        noteMissingRunId,
        acceptRunSequenceFrame,
        isWaitingRef,
        shouldCreateNewMessageRef: shouldCreateNewMessage,
        reconcileServerStateRef,
        clearStopGuard,
        clearPendingBrowserCaptureWait,
        setPendingBrowserCaptureWait,
        schedulePendingDialogReplay,
        settleCompletedRun,
        setError,
        setLastRunStatusReason,
        setIsConnecting,
        setIsWaitingForResponse,
        setIsAgentThinking,
        effectiveIsVisible,
        editContext,
        subscribedAgentIdRef,
        createNewStreamMessage,
    });
    useAgentTerminalBackgroundEvents({
        inlineDialogEvents: {
            agentId: agent?.id,
            agentStubId: agentStub.id,
            effectiveIsFocused,
            activeInlineDialog,
            activeInlineDialogRef,
            setActiveInlineDialog,
            dialogTerminalInstanceIdRef,
            editContextRef,
            textareaRef,
            scrollToBottom,
            onInteractionSubmitted,
        },
        toolApprovalResolved: {
            messagesRef,
            actions: sessionActions,
            isWaitingRef,
            setIsWaitingForResponse,
            setIsAgentThinking,
        },
        readyEvents: {
            agentId: agent?.id,
            agentStubId: agentStub.id,
            terminalInstanceIdRef: dialogTerminalInstanceIdRef,
        },
        queuedPromptReset: {
            agentId: agent?.id,
            isLocalOnlyDraftAgent,
            replaceQueuedPrompts,
        },
    });
    const { handleSubmit, handlePushQueuedPrompt, sendQuickMessage, handleStop } = useAgentSubmitLifecycle({
        submitResponse: {
            agentStub,
            isWaitingRef,
            onAgentUpdate,
            clearSuppressedQueuedPrompt,
            removeOptimisticTranscriptMessage,
            setAgent,
            setIsWaitingForResponse,
            setIsConnecting,
            setIsAgentThinking,
            setLastRunStatusReason,
        },
        submitHandlers: {
            readOnly,
            isSubmitting,
            editContext,
            agent,
            agentStub,
            prompt,
            activePlaceholderInput,
            allPlaceholdersFilled,
            placeholderInputRef,
            promptPlaceholderInputRef,
            shouldSubmitFilledPlaceholderInputRef,
            activeInlineDialogRef,
            isWaitingRef,
            lastNonHeartbeatUpdateAtRef,
            clearStopGuard,
            supersedePendingApprovals,
            hasPendingApprovals,
            registerSuppressedQueuedPrompt,
            clearSuppressedQueuedPrompt,
            cancelActiveInlineDialog,
            addOptimisticTranscriptMessage,
            removeOptimisticTranscriptMessage,
            getPendingRequestSettings,
            buildSubmitContext,
            persistPendingSettingsIfNeeded,
            onInteractionSubmitted,
            setError,
            setPrompt,
            setIsSubmitting,
            setIsWaitingForResponse,
            setIsAgentThinking,
            setShouldAutoScroll,
            setPromptHistory,
            setCurrentHistoryIndex,
        },
        pendingInitialPrompt: {
            initialPrompt,
            agentStubId: agentStub.id,
            agent,
            agentMetadata,
            initialMetadata,
            activeProfile,
            selectedModelId,
            effectiveIsFocused,
            isLoading,
            isSubmitting,
            readOnly,
            editContext,
        },
        initialPrompt: {
            initialPrompt,
            agentMetadata,
            isLoading,
            messageCount: messages.length,
            agentId: agentStub.id,
            editContext,
            activeProfile,
            profilesCount: profiles.length,
            setPrompt,
        },
        stop: {
            readOnly,
            agentId: agentStub.id,
            armStopGuard,
            setIsWaitingForResponse,
            isWaitingRef,
            setIsConnecting,
            setIsSubmitting,
            setAgent,
            shouldCreateNewMessage,
            setIsAgentThinking,
            messagesRef,
            sessionActions,
        },
        commandBindings: {
            bindCommands: bindSessionCommands,
            cancelActiveInlineDialog,
            handleClaimBrowser,
            handleReleaseBrowser,
            loadAgent,
        },
    });
    const { statusBarContent } = useAgentRuntimeStatus({
        statusBar: {
            agentSessionState: sessionState,
            agent,
            messages,
            currentAgentId,
            isSubmitting,
            isConnecting,
            isWaitingForResponse,
            isAgentThinking,
            isExecuting,
            lastRunStatusReason,
            hasActiveStreaming,
            subscribedAgentIdRef,
            lastSeqRef,
            recentAgentRunEvents,
            currentRunDiagnostics,
            recentToolUiEvents,
            editContext,
            effectiveModelName,
            subscribeSessionSocketMessages,
            sessionContextWindowStatus,
            sessionLiveTotals,
            showCompressionPopover,
            setShowCompressionPopover,
        },
        watchdog: {
            currentAgentId,
            sessionId: editContext?.sessionId,
            socketConnectionVersion: editContext?.socketConnectionVersion,
            effectiveIsVisible,
            isExecuting,
            isStopGuardActive,
            isAgentThinking,
            isSubmitting,
            isConnecting,
            isWaitingForResponse,
            hasActiveStreaming: hasActiveStreaming(),
            lastRunStatusReason,
            isStoppingRef,
            lastNonHeartbeatUpdateAtRef,
            lastStallReloadAtRef,
            lastSeqRef,
            currentRunIdRef,
            seenMessageIdsRef,
            appendToolUiEvent,
            loadAgent,
            normalizeRunId,
            settleCompletedRun,
        },
    });
    const handleDeleteQueuedPrompt = async (queuedPrompt) => {
        if (readOnly) {
            console.warn("[AgentTerminal] delete queued prompt blocked: read-only access");
            return;
        }
        const agentId = agent?.id || agentStub.id;
        if (!agentId || !queuedPrompt.id) {
            setError("Queued prompt not ready. Please try again.");
            return;
        }
        const previousQueuedPrompts = sessionQueuedPrompts;
        replaceQueuedPrompts(previousQueuedPrompts.filter((prompt) => prompt.id !== queuedPrompt.id));
        try {
            await deleteQueuedPromptSessionEntry({
                agentId,
                queuedPromptId: queuedPrompt.id,
            });
        }
        catch (err) {
            console.error("[AgentTerminal] Failed to delete queued prompt:", err);
            replaceQueuedPrompts(previousQueuedPrompts);
            setError(err instanceof Error
                ? err.message
                : "Failed to delete queued prompt. Please try again.");
        }
    };
    const { showInitialThinkingSplash, shouldShowThinkingDots, isLiveEditorContextMode, omitsEditorContext, parentAgentId, handleBackToParent, shouldShowLoadingContent, hasSpawnedAgents, hasTodoContent, hasHistoryContent, } = useAgentTerminalViewState({
        agent,
        agentStub,
        activeProfile,
        profiles,
        messages,
        error,
        hideGreeting,
        isSubmitting,
        isConnecting,
        activeInlineDialog,
        allPendingApprovalsCount: allPendingApprovals.length,
        isAgentThinking,
        isExecuting,
        isWaitingForResponse,
        sessionCostLimitExceeded,
        isLoading,
        sessionState,
    });
    const { loadingContent, readOnlyAccessNotice } = useAgentTerminalNotices({
        agent,
        readOnly,
        isLoading,
        shouldShowLoadingContent,
    });
    const { contextChrome, costLimitBanner, inlineDialogContent, handleModeSettingsChange, handleProfileSettingsChange, handleModelSettingsChange, } = useAgentTerminalControls({
        costLimit: {
            agentId: agent?.id,
            actions: sessionActions,
            isWaitingRef,
            setAgent,
            setError,
            setIsAgentThinking,
            setIsWaitingForResponse,
            setShouldAutoScroll,
        },
        settingsCommands: {
            activeProfile,
            agent,
            agentMetadata,
            isLocalOnlyDraftAgent,
            pendingSettingsRef,
            profiles,
            readOnly,
            setActiveProfile,
            setAgent,
            setAgentMetadata,
            setMode,
            setSelectedModelId,
        },
        chrome: {
            agent,
            agentMetadata,
            setAgentMetadata,
            setAgent,
            resolvedPageName,
            resolvedComponentName,
            resolvedFieldName,
            isLiveEditorContextMode,
            omitEditorContext: omitsEditorContext,
            onRefreshContext: handleRefreshContext,
            costLimitExceeded: sessionCostLimitExceeded,
            activeInlineDialog,
            setActiveInlineDialog,
            inlineDialogContainerRef,
            displayMode,
            questionnaireFooterActions,
            dialogRegistrations: editContext?.configuration?.editor?.agentDialogs,
            onInteractionSubmitted,
        },
    });
    const { handleSummaryQuickAction, handleMessageQuickAction, promptComposerProps, handleStopFromComposer, handleSubmitFromComposer, handleGreetingPromptClick, handleSelectPredefinedPrompt, handleSettingsOpenChange, handleOpenProfileSettingsFromSettings, } = useAgentPromptComposerSurface({
        handlers: {
            activePlaceholderInput,
            commands: sessionCommands,
            currentHistoryIndex,
            documentListRef,
            enableDocumentUpload: !!activeProfile?.enableDocumentUpload,
            hideBottomControls,
            isExecuting,
            placeholderInputRef,
            prompt,
            promptHistory,
            promptPlaceholderInputRef,
            shouldSubmitFilledPlaceholderInputRef,
            textareaRef,
            setActivePlaceholderInput,
            setAllPlaceholdersFilled,
            setCurrentHistoryIndex,
            setInputPlaceholder,
            setPrompt,
        },
        quickActions: {
            commands: sessionCommands,
            isExecuting,
            setActivePlaceholderInput,
            setInputPlaceholder,
            setPrompt,
        },
        composerProps: {
            activePlaceholderInput,
            prompt,
            hideBottomControls,
            effectiveIsFocused,
            readOnly,
            inputPlaceholder,
            isSubmitting,
            placeholderInputRef,
            promptPlaceholderInputRef,
            textareaRef,
            shouldMaintainFocusRef,
            setAllPlaceholdersFilled,
        },
        terminalActions: {
            commands: sessionCommands,
            prompt,
            setPrompt,
            setShowPredefined,
            setShowAgentSettings,
            setShowSkillPicker,
            textareaRef,
            handleOpenProfileSettings,
        },
    });
    const textareaDropHandlers = useAgentTextareaDropHandlers({
        agent,
        agentMetadata,
        setAgentMetadata,
        setAgent,
        documentListRef,
        documentsEnabled: !!(agent?.id && activeProfile?.enableDocumentUpload),
    });
    const sharedConversationProps = {
        fixedBrowserClaimBanner,
        agent,
        agentStub,
        error,
        lastRunStatusReason,
        messagesContainerRef,
        onScroll: handleScroll,
        showInitialThinkingSplash,
        activeProfile,
        inlineBrowserClaimBanner,
        isExecuting,
        operations: sessionAgentOperations,
        defaultCollapseJson,
        allPendingApprovals,
        onSwitchToAutonomous: handleSwitchToAutonomous,
        browserCaptureInlinePrompt,
        readOnly,
    };
    const composerCommandProps = {
        onStop: handleStopFromComposer,
        onSubmit: handleSubmitFromComposer,
    };
    const terminalViewProps = useAgentTerminalViewProps({
        loadingContent,
        displayMode,
        sharedConversationProps,
        composerCommandProps,
        summaryLayoutProps: {
            className,
            readOnlyAccessNotice,
            messages,
            hideSummaryMessages,
            inlineDialog: inlineDialogContent,
            onQuickAction: handleSummaryQuickAction,
            compact,
            hideSummaryWaitingPlaceholder,
            summaryPlaceholderActions,
            shouldShowThinkingDots,
            summaryPlaceholderMessage,
            messagesEndRef,
            showSummaryInput,
            activeInlineDialog,
            promptComposerProps,
            simpleMode,
        },
        fullUpperContentProps: {
            messages,
            hideGreeting,
            isLoading,
            onGreetingPromptClick: handleGreetingPromptClick,
            onQuickAction: handleMessageQuickAction,
            shouldShowThinkingDots,
            simpleMode,
            costLimitBanner,
            messagesEndRef,
            hideContext,
            isMobile: !!editContext?.isMobile,
            contextChrome,
            documentListRef,
            hasTodoContent,
            hasSpawnedAgents,
            hasHistoryContent,
            agentMetadata,
            contextPanelsActiveTab,
            setContextPanelsActiveTab,
            queuedPrompts: sessionQueuedPrompts,
            onPushQueuedPrompt: handlePushQueuedPrompt,
            onDeleteQueuedPrompt: handleDeleteQueuedPrompt,
            queuePushDisabled: readOnly || isSubmitting,
            queueDeleteDisabled: readOnly,
        },
        fullLayoutProps: {
            className,
            parentAgentId,
            simpleMode,
            onBackToParent: handleBackToParent,
            readOnlyAccessNotice,
            isQuestionnaireDialogOpen,
            compact,
            promptComposerProps,
            showStatusBar,
            hideBottomControls,
            isMobile: !!editContext?.isMobile,
            statusBarContent,
            dropHandlers: textareaDropHandlers,
        },
        fullPromptControlsProps: {
            prompt,
            hasActivePlaceholderInput: !!activePlaceholderInput,
            hideBottomControls,
            simpleMode,
            showAgentConfigControls,
            readOnly,
            mode,
            modeOptions,
            onModeChange: handleModeSettingsChange,
            settingsOpen: showAgentSettings,
            onSettingsOpenChange: handleSettingsOpenChange,
            agentId: agent?.id,
            isLocalOnlyDraftAgent,
            profiles,
            activeProfile,
            profileOptions,
            selectedModelId,
            modelOptions,
            onProfileChange: handleProfileSettingsChange,
            onModelChange: handleModelSettingsChange,
            onOpenProfileSettings: handleOpenProfileSettingsFromSettings,
            showSkillPicker,
            onShowSkillPickerChange: setShowSkillPicker,
            skillRootIds,
            selectedSkillIds,
            selectableTemplateIdSet,
            manuallyAssignableSkillIdSet,
            selectedSkills,
            autoAssignedSkillSet,
            skillsLoading,
            skillsError,
            skillActionError,
            profileFilteredSkills,
            onSkillActionErrorChange: setSkillActionError,
            onAddSkill: handleAddSkill,
            onOpenSkillItem: handleOpenSkillItem,
            onRemoveSkill: handleRemoveSkill,
            toolsSectionExpanded,
            onToolsSectionExpandedChange: setToolsSectionExpanded,
            tools: displayedAvailableTools,
            toolsLoading: displayedAvailableToolsLoading,
            toolsError: displayedAvailableToolsError,
            allowancesSectionExpanded,
            onAllowancesSectionExpandedChange: setAllowancesSectionExpanded,
            allowancesTotalCount,
            allowancesLoading: displayedOperationAllowancesLoading,
            allowancesError: displayedOperationAllowancesError,
            hasAnyAllowances,
            allowanceGroups,
            subscribedTriggersSectionExpanded,
            onSubscribedTriggersSectionExpandedChange: setSubscribedTriggersSectionExpanded,
            activeTriggerSubscriptions,
            triggerSubscriptionsLoading,
            triggerSubscriptionsError,
            predefinedPrompts: activeProfile?.prompts,
            predefinedOpen: showPredefined,
            onPredefinedOpenChange: setShowPredefined,
            onSelectPredefinedPrompt: handleSelectPredefinedPrompt,
            showMobileStatusPopover: !hideBottomControls && !simpleMode && !!editContext?.isMobile,
            mobileStatusOpen: showCostAndAgent,
            onMobileStatusOpenChange: setShowCostAndAgent,
            mobileStatusContent: statusBarContent,
            isVoiceDisabled,
            isListening,
            isExecuting,
            pendingApprovalCount: allPendingApprovals.length,
            allPlaceholdersFilled,
            onVoicePointerDown: handleVoicePointerDown,
            onVoicePointerUp: handleVoicePointerUp,
            onVoicePointerCancel: handleVoicePointerCancel,
            onStop: handleStopFromComposer,
            onSubmit: handleSubmitFromComposer,
        },
        inlineDialogContent,
        isLiveEditorContextMode,
    });
    return terminalViewProps;
}
//# sourceMappingURL=useAgentTerminalController.js.map