import { AgentExecuteCodeMode } from '../contracts/agent-execute-code.js';
import { DEFAULT_THINKING_LEVEL } from '../core/defaults.js';
import { createShortcutXLAgentSettingsStore } from './bootstrap.js';
import { createDefaultHostTools, createSessionToolInfoState } from './host-tools/index.js';
import { SWITCH_MODE } from './host-tools/tool-names.js';
function toAgentExecuteCodeMode(mode) {
    switch (mode) {
        case AgentExecuteCodeMode.Action:
        case AgentExecuteCodeMode.Ask:
        case AgentExecuteCodeMode.Plan:
        case AgentExecuteCodeMode.Manage:
        case AgentExecuteCodeMode.Shorty:
        case AgentExecuteCodeMode.Review:
            return mode;
        default:
            return AgentExecuteCodeMode.Action;
    }
}
function createStreamBackedCompactionComplete(streamFn) {
    return async (model, context, options) => {
        const stream = await streamFn(model, context, options);
        return stream.result();
    };
}
function filterBenchmarkConfiguration(configuration) {
    return {
        ...configuration,
        toolNames: (configuration.toolNames ?? []).filter((toolName) => toolName !== SWITCH_MODE)
    };
}
export function buildHostEmbeddedAgentOptions(input) {
    const sessionToolInfoState = createSessionToolInfoState();
    const initialConfiguration = input.isBenchmark
        ? filterBenchmarkConfiguration(input.initialConfiguration)
        : input.initialConfiguration;
    const getSkipTools = (perTurnSkipTools) => {
        const skipTools = [...(perTurnSkipTools ?? []), ...(input.isBenchmark ? [SWITCH_MODE] : [])];
        return skipTools.length > 0 ? skipTools : undefined;
    };
    const options = {
        createHostTools: (pendingHostToolRequests, context) => {
            const agentMode = toAgentExecuteCodeMode(context.getAgentMode());
            return createDefaultHostTools({
                pendingHostToolRequests,
                sessionPolicy: input.sessionPolicy,
                agentMode,
                executeCodeSurface: input.executeCodeSurface,
                streamFn: input.streamFn,
                resolveModel: (modelId) => input.modelRegistry.find('shortcut', modelId),
                getCurrentModel: context.getCurrentModel,
                getApiKey: (provider) => input.modelRegistry.getApiKeyForProvider(provider),
                getSpeed: context.getSpeed,
                preferCurrentModelForSubagents: input.preferCurrentModelForSubagents,
                disabledToolNames: input.disabledToolNames,
                emitChildAgentEvent: input.emitChildAgentEvent,
                promptPlatform: input.promptPlatform,
                sessionToolInfoState,
                applyRuntimeHandoff: context.applyRuntimeHandoff,
                scheduleRefresh: context.scheduleRefresh,
                skipTools: getSkipTools(context.getSkipTools())
            });
        },
        initialConfiguration,
        model: input.model,
        modelRegistry: input.modelRegistry,
        sessionStore: input.sessionStore,
        settingsStore: createShortcutXLAgentSettingsStore(),
        streamFn: input.streamFn,
        compactionCompleteFn: createStreamBackedCompactionComplete(input.streamFn),
        thinkingLevel: DEFAULT_THINKING_LEVEL,
        ...(input.creditGate ? { creditGate: input.creditGate } : {}),
        ...(input.extraTools ? { tools: [...input.extraTools] } : {})
    };
    return { options, sessionToolInfoState };
}
//# sourceMappingURL=host-runtime-options.js.map