import { getVisiblePeerCommands } from "../../commands/index.js";
import { createRemoteInteractiveView } from "./remote-interactive-state.js";
export function createRemoteInteractiveController(runtime, capabilityOverrides = {}) {
    const capabilities = {
        supportsCompact: true,
        supportsReload: true,
        supportsModelSelection: true,
        supportsSessionTree: false,
        supportsSessionCreation: false,
        supportsSessionResume: false,
        supportsSessionFork: false,
        supportsSessionClone: false,
        ...capabilityOverrides,
    };
    return {
        getView: () => createRemoteInteractiveView(runtime.appState.getSnapshot(), runtime.uiState.getSnapshot(), {
            peerId: runtime.hello.peerId,
            cwd: runtime.hello.cwd ?? process.cwd(),
            visibleCommands: getVisiblePeerCommands(capabilities),
            helloAgentId: runtime.hello.agentId,
        }),
        actions: {
            queueWrite: (text, images, streamingBehavior) => {
                if (runtime.queueWrite) {
                    return runtime.queueWrite(text, images, streamingBehavior);
                }
                if (runtime.submitPrompt) {
                    return runtime.submitPrompt(text);
                }
                throw new Error("Queue write action is not available.");
            },
            queueFlush: () => {
                if (!runtime.queueFlush) {
                    throw new Error("Queue flush action is not available.");
                }
                return runtime.queueFlush();
            },
            submitPrompt: (text) => {
                if (runtime.queueWrite) {
                    return runtime.queueWrite(text);
                }
                if (runtime.submitPrompt) {
                    return runtime.submitPrompt(text);
                }
                throw new Error("Queue write action is not available.");
            },
            submitFollowUp: (text) => {
                if (runtime.queueWrite) {
                    return runtime.queueWrite(text);
                }
                if (runtime.followUp) {
                    return runtime.followUp(text);
                }
                if (runtime.submitPrompt) {
                    return runtime.submitPrompt(text);
                }
                throw new Error("Queue write action is not available.");
            },
            steer: (text) => {
                if (runtime.queueWrite) {
                    return runtime.queueWrite(text);
                }
                if (runtime.steer) {
                    return runtime.steer(text);
                }
                if (runtime.submitPrompt) {
                    return runtime.submitPrompt(text);
                }
                throw new Error("Queue write action is not available.");
            },
            abort: () => runtime.abort(),
            switchAgent: (agentId) => {
                if (!runtime.switchAgent) {
                    throw new Error("Agent switching action is not available.");
                }
                return runtime.switchAgent(agentId);
            },
            setModel: (modelResourceId) => runtime.setModel(modelResourceId),
            setThinkingLevel: (level) => runtime.setThinkingLevel(level),
            invokeCommand: (commandName, args) => runtime.invokeCommand(commandName, args),
            getSessionSources: () => runtime.getSessionSources(),
            pauseSource: (resourceId) => runtime.pauseSource(resourceId),
            restartSource: (resourceId) => runtime.restartSource(resourceId),
            removeSource: (resourceId) => runtime.removeSource(resourceId),
            getMcpServers: () => runtime.getMcpServers(),
            getSkills: () => runtime.getSkills?.() ?? Promise.resolve({ ok: true, skills: [], diagnostics: [] }),
            pauseMcpServer: (name) => runtime.pauseMcpServer(name),
            restartMcpServer: (name) => runtime.restartMcpServer(name),
            removeMcpServer: (name) => runtime.removeMcpServer(name),
            retryConnection: () => runtime.retryConnection?.(),
        },
        capabilities,
    };
}
//# sourceMappingURL=remote-interactive-controller.js.map