const DEFAULT_DOUBLE_ESCAPE_WINDOW_MS = 500;
/** Wire editor and UI actions for the interactive shell, including double-escape handling. */
export function registerInteractiveActions(options) {
    const { editor, ui, handlers } = options;
    const now = options.now ?? (() => Date.now());
    const doubleEscapeWindowMs = options.doubleEscapeWindowMs ?? DEFAULT_DOUBLE_ESCAPE_WINDOW_MS;
    let lastEscapeTime = 0;
    editor.onEscape = () => {
        if (handlers.isLoading()) {
            handlers.restoreQueuedMessagesToEditor({ abort: true });
            return;
        }
        if (editor.getText().trim()) {
            return;
        }
        const currentTime = now();
        if (currentTime - lastEscapeTime < doubleEscapeWindowMs) {
            handlers.showTreeSelector();
            lastEscapeTime = 0;
            return;
        }
        lastEscapeTime = currentTime;
    };
    editor.onAction('clear', () => handlers.handleCtrlC());
    editor.onCtrlD = () => handlers.handleCtrlD();
    editor.onAction('suspend', () => handlers.handleCtrlZ());
    editor.onAction('cycleThinkingLevel', () => handlers.cycleThinkingLevel());
    editor.onAction('toggleFastMode', () => handlers.toggleFastMode());
    editor.onAction('toggleAutoApprove', () => handlers.toggleAutoApprove());
    editor.onAction('toggleRuntimePermissionBypass', () => handlers.toggleRuntimePermissionBypass());
    editor.onAction('cycleModelForward', () => handlers.cycleModel('forward'));
    editor.onAction('cycleModelBackward', () => handlers.cycleModel('backward'));
    editor.onAction('selectModel', () => handlers.showModelSelector());
    editor.onAction('expandTools', () => handlers.toggleToolOutputExpansion());
    editor.onAction('toggleThinking', () => handlers.toggleThinkingBlockVisibility());
    editor.onAction('externalEditor', () => handlers.openExternalEditor());
    editor.onAction('followUp', () => handlers.handleFollowUp());
    editor.onAction('dequeue', () => handlers.handleDequeue());
    editor.onAction('newSession', () => handlers.handleClearCommand());
    editor.onAction('tree', () => handlers.showTreeSelector());
    editor.onAction('resume', () => handlers.showSessionSelector());
    editor.onAction('cycleMode', () => handlers.cycleMode());
    editor.onFilePaste = (filePath) => handlers.attachFile(filePath);
    editor.onPasteImage = () => {
        handlers.handleClipboardImagePaste();
    };
    ui.onDebug = () => {
        handlers.runDebugCommand();
    };
}
//# sourceMappingURL=interactive-actions.js.map