/**
 * Assets Collector
 * Phase 3: Read from agent registry, count statuses
 */
import { getSystemState } from '../system-state.js';
/**
 * Collect asset registry data
 */
export async function collectAssets(appState) {
    try {
        let systemState;
        try {
            systemState = getSystemState(appState, false);
        }
        catch {
            systemState = null;
        }
        if (!systemState) {
            return {
                status: 'UNAVAILABLE',
                asOf: Date.now(),
                source: 'collector_assets',
                staleAfterMs: 2000,
                reasonCode: 'NO_SYSTEM_STATE',
                message: 'System state not available',
                action: 'system status',
            };
        }
        const assets = systemState.assetRegistrySummary;
        // Get last action from run history
        let lastAction = "NONE";
        if (appState.runHistory.length > 0) {
            const lastRun = appState.runHistory[appState.runHistory.length - 1];
            if (lastRun.status === 'RUNNING') {
                lastAction = `run:${lastRun.runId.substring(0, 8)}`;
            }
            else {
                lastAction = `start:${lastRun.agentName}`;
            }
        }
        const data = {
            total: assets.total,
            active: assets.active,
            idle: assets.idle,
            error: assets.error,
            highlight: assets.highlighted?.name || "UNKNOWN",
            lastAction,
        };
        // Phase 9: Assets are usually LIVE if collected successfully
        const now = Date.now();
        const status = 'LIVE';
        return {
            status,
            asOf: now,
            data,
            source: 'collector_assets',
            staleAfterMs: 2000,
        };
    }
    catch (error) {
        return {
            status: 'UNAVAILABLE',
            asOf: Date.now(),
            source: 'collector_assets',
            staleAfterMs: 2000,
            reasonCode: 'COLLECTION_ERROR',
            message: error.message || 'Unknown error',
            action: 'system status',
        };
    }
}
//# sourceMappingURL=collector_assets.js.map