export function checkLimitsDetailed(config, state) {
    if (state.aborted) {
        return { type: 'hard_stop', reason: 'cancelled' };
    }
    if (Date.now() - state.startTime > config.timeoutMs) {
        return { type: 'hard_stop', reason: 'timeout' };
    }
    if (config.tokenBudget > 0 && state.totalTokens >= config.tokenBudget) {
        return { type: 'hard_stop', reason: 'token_budget' };
    }
    if (config.costLimitUsd && config.costLimitUsd > 0 && state.totalCost >= config.costLimitUsd) {
        return { type: 'hard_stop', reason: 'cost_limit' };
    }
    if (state.currentIteration >= config.maxIterations) {
        return { type: 'hard_stop', reason: 'max_iterations' };
    }
    if (config.tokenBudget > 0) {
        const usageRatio = state.totalTokens / config.tokenBudget;
        if (usageRatio >= config.budgetWarningThreshold) {
            return { type: 'warning', reason: 'token_budget' };
        }
    }
    if (config.costLimitUsd && config.costLimitUsd > 0) {
        const costRatio = state.totalCost / config.costLimitUsd;
        if (costRatio >= config.budgetWarningThreshold) {
            return { type: 'warning', reason: 'cost_limit' };
        }
    }
    const timeElapsed = Date.now() - state.startTime;
    const timeRatio = timeElapsed / config.timeoutMs;
    if (timeRatio >= config.budgetWarningThreshold) {
        return { type: 'warning', reason: 'timeout' };
    }
    return { type: 'ok' };
}
export function buildLimitConfig(tokenBudget, timeoutMs, costLimitUsd, maxIterations, budgetWarningThreshold) {
    return {
        tokenBudget,
        timeoutMs,
        costLimitUsd,
        maxIterations: maxIterations ?? 200,
        budgetWarningThreshold: budgetWarningThreshold ?? 0.9,
    };
}
//# sourceMappingURL=LimitChecker.js.map