import { buildFeatureRegistry } from '../../engines/feature-registry.js';
import { serializeSelectionAudit } from '../serializers/run-serializer.js';
import { collectDashboardBaseState } from './summary-selector.js';
export function serializeSpecialistsCatalog(specialists) {
    return specialists.map((specialist) => ({
        specialistId: specialist.specialistId,
        name: specialist.name,
        division: specialist.division,
        description: specialist.description,
        authority: specialist.authority,
        domains: specialist.domains,
        tools: specialist.tools,
        mission: specialist.mission,
        workflow: specialist.workflow,
        deliverables: specialist.deliverables,
        communicationStyle: specialist.communicationStyle,
        successMetrics: specialist.successMetrics,
        recommendedSkills: specialist.recommendedSkills,
        recommendedWorkflows: specialist.recommendedWorkflows,
        sourcePath: specialist.sourcePath,
    }));
}
export async function buildAssetsSurface(ctx, url) {
    const state = collectDashboardBaseState(ctx, url);
    const runtimeId = state.runtime?.getRuntimeId?.() ?? 'default';
    const patterns = ctx.getOrchestrator?.()?.listPatterns?.() ?? [];
    return {
        repoIdentity: state.snapshot?.repoIdentity ?? ctx.getSelectedRepoIdentity(url),
        usage: state.usage,
        selectionAudit: serializeSelectionAudit(state.usage),
        featureRegistry: await ctx.getCachedValue('feature-registry', 30_000, () => Promise.resolve(buildFeatureRegistry(ctx.repoRoot))),
        patternPacks: patterns.filter((pattern) => Array.isArray(pattern.tags) && pattern.tags.includes('pattern-pack')),
        skills: state.runtime?.listSkills?.() ?? [],
        specialists: await ctx.getCachedValue(`catalog:specialists:${runtimeId}`, 15_000, () => Promise.resolve(serializeSpecialistsCatalog(state.runtime?.listSpecialists?.() ?? []))),
        crews: state.runtime?.listCrews?.() ?? [],
        workflows: state.runtime?.listWorkflows?.() ?? [],
        hooks: state.runtime?.listHooks?.() ?? [],
        automations: state.runtime?.listAutomations?.() ?? [],
        backends: state.runtime?.getBackendCatalog?.() ?? {},
    };
}
