/**
 * Cost Limit Middleware
 *
 * Replaces inline `isSessionCostLimitReached()` checks in the agent executor.
 *
 * @module agent/middleware
 */
export class CostLimitMiddleware {
    name = 'cost-limit';
    priority = 20;
    recordSessionCost;
    isSessionCostLimitReached;
    constructor(deps) {
        this.recordSessionCost = deps.recordSessionCost;
        this.isSessionCostLimitReached = deps.isSessionCostLimitReached;
    }
    afterTurn(context) {
        this.recordSessionCost(context.inputTokens, context.outputTokens);
        if (this.isSessionCostLimitReached()) {
            return {
                action: 'stop',
                message: `Session cost limit reached ($${context.sessionCost.toFixed(2)} / $${context.sessionCostLimit.toFixed(2)}). Please start a new session.`,
            };
        }
        // Warn at 80% of cost limit
        const warnThreshold = context.sessionCostLimit * 0.8;
        if (context.sessionCost >= warnThreshold) {
            return {
                action: 'warn',
                message: `Session cost approaching limit ($${context.sessionCost.toFixed(2)} / $${context.sessionCostLimit.toFixed(2)}).`,
            };
        }
        return { action: 'continue' };
    }
}
//# sourceMappingURL=cost-limit.js.map