/** SDK-owned platform module. This implementation is maintained in goodvibes-sdk. */
/**
 * Default resource contracts by panel category.
 *
 * Panels without an explicit contract inherit from their category default.
 * Active/interactive panels get more generous budgets; monitoring panels
 * are throttled aggressively to prevent render storms.
 */
export const CATEGORY_CONTRACTS = {
    development: {
        maxUpdatesPerSecond: 10,
        maxRenderMs: 20,
        throttleIntervalMs: 100,
        degradeAfterViolations: 5,
        degradedIntervalMs: 500,
    },
    agent: {
        maxUpdatesPerSecond: 5,
        maxRenderMs: 30,
        throttleIntervalMs: 200,
        degradeAfterViolations: 5,
        degradedIntervalMs: 1000,
    },
    monitoring: {
        maxUpdatesPerSecond: 2,
        maxRenderMs: 50,
        throttleIntervalMs: 500,
        degradeAfterViolations: 3,
        degradedIntervalMs: 2000,
    },
    session: {
        maxUpdatesPerSecond: 4,
        maxRenderMs: 25,
        throttleIntervalMs: 250,
        degradeAfterViolations: 5,
        degradedIntervalMs: 1000,
    },
    ai: {
        maxUpdatesPerSecond: 8,
        maxRenderMs: 20,
        throttleIntervalMs: 125,
        degradeAfterViolations: 5,
        degradedIntervalMs: 500,
    },
    /** Fallback for unrecognised categories. */
    default: {
        maxUpdatesPerSecond: 5,
        maxRenderMs: 30,
        throttleIntervalMs: 200,
        degradeAfterViolations: 5,
        degradedIntervalMs: 1000,
    },
};
/**
 * Build a PanelResourceContract for a panel, merging category defaults
 * with any per-panel overrides.
 *
 * @param panelId - The panel's unique id.
 * @param category - The panel's category (used to select the base contract).
 * @param overrides - Optional per-panel overrides applied on top of the category contract.
 */
export function buildContract(panelId, category, overrides) {
    const base = CATEGORY_CONTRACTS[category] ?? CATEGORY_CONTRACTS['default'];
    return {
        panelId,
        ...base,
        ...overrides,
    };
}
/**
 * Create an initial (clean) PanelHealthState for a panel.
 */
export function createInitialPanelHealthState(panelId) {
    return {
        panelId,
        throttleStatus: 'normal',
        healthStatus: 'healthy',
        rendersInWindow: 0,
        renderP95Ms: 0,
        consecutiveViolations: 0,
        lastRenderAt: 0,
        nextAllowedAt: 0,
        totalSuppressed: 0,
        totalPermitted: 0,
    };
}
