/**
 * Narrow, shell-facing surfaces over `AgentSession`. These contracts decouple
 * shell components from the full session class so they can be reused with
 * non-local session backings (RPC, embedded) without depending on internals.
 */
import { switchMode as runSwitchMode } from '../app/modes/switch-mode.js';
function isObjectWithMethod(value, key) {
    return (typeof value === 'object' &&
        value !== null &&
        typeof value[key] === 'function');
}
function assertShellSessionServices(session) {
    if (!isObjectWithMethod(session.settingsManager, 'getGlobalSettings') ||
        !isObjectWithMethod(session.settingsManager, 'setSkillPaths') ||
        !isObjectWithMethod(session.settingsManager, 'setProjectSkillPaths') ||
        !isObjectWithMethod(session.settingsManager, 'setDefaultModelAndProvider')) {
        throw new Error('Interactive shell requires a shell-backed settings manager.');
    }
    if (!isObjectWithMethod(session.sessionManager, 'getSessionName') ||
        !isObjectWithMethod(session.sessionManager, 'appendSessionInfo') ||
        !isObjectWithMethod(session.sessionManager, 'getTree')) {
        throw new Error('Interactive shell requires a shell-backed session store.');
    }
    if (!isObjectWithMethod(session.modelRegistry, 'getAvailable') ||
        !isObjectWithMethod(session.modelRegistry, 'getAll') ||
        !isObjectWithMethod(session.modelRegistry, 'find')) {
        throw new Error('Interactive shell requires a shell-backed model registry.');
    }
    if (!isObjectWithMethod(session.resourceLoader, 'getSkills') ||
        !isObjectWithMethod(session.resourceLoader, 'getPathMetadata')) {
        throw new Error('Interactive shell requires a shell-backed resource loader.');
    }
}
function assertPrintSessionStore(session) {
    const { sessionManager } = session;
    if (!isObjectWithMethod(sessionManager, 'getHeader') ||
        !isObjectWithMethod(sessionManager, 'getSessionId') ||
        !isObjectWithMethod(sessionManager, 'appendSessionInfo') ||
        !isObjectWithMethod(sessionManager, 'buildSessionContext')) {
        throw new Error('Print mode requires a session store that supports extension setup.');
    }
}
function bindSessionMethod(session, method) {
    return method.bind(session);
}
function createInteractiveSessionSurface(session) {
    assertShellSessionServices(session);
    return {
        get agent() {
            return session.agent;
        },
        get approvalState() {
            return session.approvalState;
        },
        get collabClient() {
            return session.collabClient;
        },
        set collabClient(client) {
            session.collabClient = client;
        },
        get extensionRunner() {
            return session.extensionRunner;
        },
        get lastPrePromptDetails() {
            return session.lastPrePromptDetails;
        },
        get messages() {
            return session.messages;
        },
        get model() {
            return session.model;
        },
        get modelRegistry() {
            return session.modelRegistry;
        },
        get promptTemplates() {
            return session.promptTemplates;
        },
        get resourceLoader() {
            return session.resourceLoader;
        },
        get retryAttempt() {
            return session.retryAttempt;
        },
        get sessionManager() {
            return session.sessionManager;
        },
        get settingsManager() {
            return session.settingsManager;
        },
        get sheetPool() {
            return session.sheetPool;
        },
        set sheetPool(pool) {
            session.sheetPool = pool;
        },
        get state() {
            return session.state;
        },
        get isFastModeAllowed() {
            return session.isFastModeAllowed;
        },
        get isFastModeEnabled() {
            return session.isFastModeEnabled;
        },
        get isFastModeAvailable() {
            return session.isFastModeAvailable;
        },
        get fastModeDisabledReason() {
            return session.fastModeDisabledReason;
        },
        get thinkingLevel() {
            return session.thinkingLevel;
        },
        get tools() {
            return session.tools;
        },
        abortCompaction: bindSessionMethod(session, session.abortCompaction),
        abortRetry: bindSessionMethod(session, session.abortRetry),
        bindExtensions: bindSessionMethod(session, session.bindExtensions),
        clearQueue: bindSessionMethod(session, session.clearQueue),
        compact: bindSessionMethod(session, session.compact),
        consumePendingRefresh: bindSessionMethod(session, session.consumePendingRefresh),
        cycleModel: bindSessionMethod(session, session.cycleModel),
        cycleThinkingLevel: bindSessionMethod(session, session.cycleThinkingLevel),
        followUp: bindSessionMethod(session, session.followUp),
        fork: bindSessionMethod(session, session.fork),
        getAvailableThinkingLevels: bindSessionMethod(session, session.getAvailableThinkingLevels),
        getContextUsage: bindSessionMethod(session, session.getContextUsage),
        getFollowUpMessages: bindSessionMethod(session, session.getFollowUpMessages),
        getSessionStats: bindSessionMethod(session, session.getSessionStats),
        getSteeringMessages: bindSessionMethod(session, session.getSteeringMessages),
        getToolNames: bindSessionMethod(session, session.getToolNames),
        getToolSummaryDiagnostics: bindSessionMethod(session, session.getToolSummaryDiagnostics),
        get isCompacting() {
            return session.isCompacting;
        },
        get isRetrying() {
            return session.isRetrying;
        },
        get isStreaming() {
            return session.isStreaming;
        },
        navigateTree: bindSessionMethod(session, session.navigateTree),
        newSession: bindSessionMethod(session, session.newSession),
        preparePendingRefresh: bindSessionMethod(session, session.preparePendingRefresh),
        prompt: bindSessionMethod(session, session.prompt),
        reload: bindSessionMethod(session, session.reload),
        replaceToolsByName: bindSessionMethod(session, session.replaceToolsByName),
        setFastModeEnabled: bindSessionMethod(session, session.setFastModeEnabled),
        setModel: bindSessionMethod(session, session.setModel),
        setThinkingLevel: bindSessionMethod(session, session.setThinkingLevel),
        startAutonomous: bindSessionMethod(session, session.startAutonomous),
        steer: bindSessionMethod(session, session.steer),
        subscribe: bindSessionMethod(session, session.subscribe),
        switchMode: (modeName, options) => runSwitchMode(session, modeName, options),
        switchSession: bindSessionMethod(session, session.switchSession),
        toggleFastMode: bindSessionMethod(session, session.toggleFastMode)
    };
}
/** Wrap an `AgentSession` in the narrow surface the interactive shell consumes. */
export function createInteractiveSessionClient(session) {
    return createInteractiveSessionSurface(session);
}
/** Wrap an `AgentSession` in the narrow surface print mode requires. */
export function createPrintModeSessionClient(session) {
    assertPrintSessionStore(session);
    return {
        get agent() {
            return session.agent;
        },
        bindExtensions: bindSessionMethod(session, session.bindExtensions),
        consumePendingRefresh: bindSessionMethod(session, session.consumePendingRefresh),
        fork: bindSessionMethod(session, session.fork),
        get isRetrying() {
            return session.isRetrying;
        },
        navigateTree: bindSessionMethod(session, session.navigateTree),
        newSession: bindSessionMethod(session, session.newSession),
        preparePendingRefresh: bindSessionMethod(session, session.preparePendingRefresh),
        prompt: bindSessionMethod(session, session.prompt),
        reload: bindSessionMethod(session, session.reload),
        get sessionManager() {
            return session.sessionManager;
        },
        subscribe: bindSessionMethod(session, session.subscribe),
        switchSession: bindSessionMethod(session, session.switchSession)
    };
}
//# sourceMappingURL=session-client.js.map