/** SDK-owned platform module. This implementation is maintained in goodvibes-sdk. */
/**
 * Default resource contracts by component category.
 *
 * Components without an explicit contract inherit from their category default.
 * Active/interactive components get more generous budgets; monitoring components
 * 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 ComponentResourceContract for a component, merging category defaults
 * with any per-component overrides.
 *
 * @param componentId - The component's unique id.
 * @param category - The component's category (used to select the base contract).
 * @param overrides - Optional per-component overrides applied on top of the category contract.
 */
export function buildContract(componentId, category, overrides) {
    const base = CATEGORY_CONTRACTS[category] ?? CATEGORY_CONTRACTS['default'];
    return {
        componentId,
        ...base,
        ...overrides,
    };
}
/**
 * Create an initial (clean) ComponentHealthState for a component.
 */
export function createInitialComponentHealthState(componentId) {
    return {
        componentId,
        throttleStatus: 'normal',
        healthStatus: 'healthy',
        rendersInWindow: 0,
        renderP95Ms: 0,
        consecutiveViolations: 0,
        lastRenderAt: 0,
        nextAllowedAt: 0,
        totalSuppressed: 0,
        totalPermitted: 0,
    };
}
/**
 * @deprecated Use createInitialComponentHealthState.
 * Creates an initial PanelHealthState with a panelId field for legacy callers.
 */
export function createInitialPanelHealthState(panelId) {
    return {
        panelId,
        throttleStatus: 'normal',
        healthStatus: 'healthy',
        rendersInWindow: 0,
        renderP95Ms: 0,
        consecutiveViolations: 0,
        lastRenderAt: 0,
        nextAllowedAt: 0,
        totalSuppressed: 0,
        totalPermitted: 0,
    };
}
