"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveDroidReasoningRuntime = exports.DroidReasoningFlagError = void 0;
const thinking_arg_parser_1 = require("../cliproxy/executor/thinking-arg-parser");
const thinking_override_resolver_1 = require("../cliproxy/executor/thinking-override-resolver");
class DroidReasoningFlagError extends Error {
    constructor(message, flag) {
        super(message);
        this.flag = flag;
        this.name = 'DroidReasoningFlagError';
    }
}
exports.DroidReasoningFlagError = DroidReasoningFlagError;
function stripReasoningFlags(args) {
    return args.filter((arg, idx) => {
        if (arg === '--thinking' || arg === '--effort')
            return false;
        if (arg.startsWith('--thinking='))
            return false;
        if (arg.startsWith('--effort='))
            return false;
        if (args[idx - 1] === '--thinking' || args[idx - 1] === '--effort')
            return false;
        return true;
    });
}
function resolveDroidReasoningRuntime(args, envThinkingValue) {
    const parseResult = (0, thinking_arg_parser_1.parseThinkingOverride)(args);
    if (parseResult.error) {
        throw new DroidReasoningFlagError(`${parseResult.error.flag} requires a value`, parseResult.error.flag);
    }
    const { thinkingOverride, thinkingSource } = (0, thinking_override_resolver_1.resolveRuntimeThinkingOverride)(parseResult.value, envThinkingValue);
    return {
        argsWithoutReasoningFlags: stripReasoningFlags(args),
        reasoningOverride: thinkingOverride,
        sourceFlag: thinkingSource === 'flag' ? parseResult.sourceFlag : undefined,
        sourceDisplay: parseResult.sourceDisplay,
        duplicateDisplays: parseResult.duplicateDisplays,
    };
}
exports.resolveDroidReasoningRuntime = resolveDroidReasoningRuntime;
//# sourceMappingURL=droid-reasoning-runtime.js.map