/**
 * @fileoverview Pure, framework-agnostic helpers that shape each DevTools
 * inspector's runtime state into the flat key/value `AgentContext` object that
 * flows to the async chat agent and the realtime co-agent via
 * `NavigationService.SetAgentContext`.
 *
 * These functions are intentionally free of Angular / component dependencies so
 * they can be unit-tested in isolation. Each component supplies a plain snapshot
 * of its current state and the matching helper returns the context object.
 *
 * 🔒 SAFETY BOUNDARY (read carefully — per-inspector classification):
 *
 * - Event Monitor / Class Registry / Lazy Module Status / Layout Inspector are
 *   SAFE developer diagnostics: their context reports counts + the user's own
 *   filter/search/sort/selection state, plus BOUNDED lists of NON-secret names
 *   (event types, class names, module labels, layout sections). No secret-bearing
 *   VALUES are exposed.
 *
 * - App State Inspector and Settings Explorer are METADATA-ONLY: the context
 *   reports counts (state size, key/setting counts, search term) and — for
 *   Settings / App State — the bounded list of KEY NAMES (e.g. "mj.formBuilder.…",
 *   "search.showFilterPanel", "Email", "Roles"). Setting/state keys are
 *   identifiers, not secrets. The context NEVER includes the underlying state
 *   VALUES or setting VALUES, which may contain auth tokens, API URLs,
 *   credentials, or other secrets. The matching helpers below accept counts +
 *   key names, never raw values, by construction. No value-returning tools are
 *   registered on either surface.
 *
 * - GraphQL Console has NO helper here and is intentionally NOT wired (arbitrary
 *   query execution is an injection risk). See its component for the rationale.
 */
/**
 * Upper bound on how many names a DevTools surface publishes in a name-list
 * context field (event types, class names, module labels, setting keys, …).
 * Mirrors the Admin `AGENT_CONTEXT_NAME_LIST_CAP`. Kept LOCAL to DevTools so this
 * file has no cross-package coupling. When the underlying list is larger, the
 * surface publishes a companion total-count field so the agent still knows the
 * true size.
 */
export const DEV_TOOLS_NAME_LIST_CAP = 25;
/**
 * Cap an array of names to at most {@link DEV_TOOLS_NAME_LIST_CAP} entries.
 * Pure + deterministic so the published context shape stays unit-testable.
 * Never mutates the input. The caller owns de-duplication / ordering.
 */
export function boundDevToolsNames(names) {
    return names.slice(0, DEV_TOOLS_NAME_LIST_CAP);
}
/** Build the agent-visible context for the Event Monitor inspector. */
export function buildEventMonitorAgentContext(input) {
    const hasActiveFilters = input.TextFilter.length > 0 ||
        input.TypeFilter.length > 0 ||
        input.ComponentFilter.length > 0 ||
        input.CodeFilter.length > 0;
    const context = {
        EventCount: input.EventCount,
        BufferedCount: input.BufferedCount,
        FilteredCount: input.FilteredCount,
        EventsPerSecond: input.EventsPerSecond,
        Paused: input.Paused,
        TextFilter: input.TextFilter,
        TypeFilter: input.TypeFilter,
        ComponentFilter: input.ComponentFilter,
        CodeFilter: input.CodeFilter,
        HasActiveFilters: hasActiveFilters,
        SortField: input.SortField,
        SortDirection: input.SortDirection,
    };
    addBoundedNameField(context, 'KnownEventTypes', 'KnownEventTypeCount', input.KnownTypes);
    addBoundedNameField(context, 'KnownComponents', 'KnownComponentCount', input.KnownComponents);
    addBoundedNameField(context, 'KnownEventCodes', 'KnownEventCodeCount', input.KnownCodes);
    if (input.RecentEvents.length > 0) {
        context['RecentEvents'] = input.RecentEvents.slice(0, DEV_TOOLS_NAME_LIST_CAP);
    }
    return context;
}
/** Build the agent-visible context for the Class Registry inspector. */
export function buildClassRegistryAgentContext(input) {
    const context = {
        TotalClassCount: input.TotalClassCount,
        BaseClassCount: input.BaseClassCount,
        OverrideCount: input.OverrideCount,
        SearchTerm: input.SearchTerm,
        FilterByBase: input.FilterByBase,
        HasActiveSearch: input.SearchTerm.trim().length > 0,
        VisibleGroupCount: input.VisibleGroupCount,
    };
    addBoundedNameField(context, 'VisibleBaseClasses', 'VisibleBaseClassCount', input.VisibleBaseClassNames);
    return context;
}
/** Build the agent-visible context for the Lazy Module Status inspector. */
export function buildLazyModuleStatusAgentContext(input) {
    const pendingModules = Math.max(0, input.TotalModules - input.LoadedModules);
    const context = {
        Available: input.Available,
        TotalModules: input.TotalModules,
        LoadedModules: input.LoadedModules,
        PendingModules: pendingModules,
        Filter: input.Filter,
        SearchQuery: input.SearchQuery,
        HasActiveSearch: input.SearchQuery.trim().length > 0,
        VisibleModuleCount: input.VisibleModuleCount,
    };
    addBoundedNameField(context, 'VisibleModules', 'VisibleModulesTotal', input.VisibleModuleNames);
    return context;
}
/** Build the agent-visible context for the Layout Inspector. */
export function buildLayoutInspectorAgentContext(input) {
    return {
        SelectedElement: input.SelectedSection,
        SelectedSectionLabel: input.SelectedSectionLabel,
        ElementCount: input.SectionCount,
        AvailableSections: boundDevToolsNames(input.SectionIds),
        SnapshotSize: input.SnapshotSize,
    };
}
/**
 * Build the agent-visible context for the App State Inspector.
 * 🔒 METADATA-ONLY: emits StateSize + KeyCount + section label/ids + top-level
 * KEY NAMES. NEVER the state values themselves.
 */
export function buildAppStateInspectorAgentContext(input) {
    const context = {
        StateSize: input.StateSize,
        KeyCount: input.KeyCount,
        ActiveSection: input.ActiveSection,
        ActiveSectionLabel: input.ActiveSectionLabel,
        AvailableSections: boundDevToolsNames(input.SectionIds),
    };
    addBoundedNameField(context, 'TopLevelKeys', 'TopLevelKeyTotal', input.TopLevelKeys);
    return context;
}
/**
 * Build the agent-visible context for the Settings Explorer.
 * 🔒 METADATA-ONLY: emits counts + scope + the search term + setting KEY NAMES.
 * NEVER setting values.
 */
export function buildSettingsExplorerAgentContext(input) {
    const context = {
        SettingCount: input.SettingCount,
        UserSettingCount: input.UserSettingCount,
        InstanceSettingCount: input.InstanceSettingCount,
        Scope: input.Scope,
        SearchTerm: input.SearchTerm,
        HasActiveSearch: input.SearchTerm.trim().length > 0,
        FilteredCount: input.FilteredCount,
    };
    addBoundedNameField(context, 'SettingKeys', 'SettingKeyTotal', input.SettingKeys);
    return context;
}
// ============================================================================
// Shared internals
// ============================================================================
/**
 * Attach a bounded name list to the context under `listKey`, plus a companion
 * total-count under `countKey` ONLY when the list is truncated. Mutates the
 * passed context object (the builders own it locally). No-op for an empty list.
 */
function addBoundedNameField(context, listKey, countKey, names) {
    if (names.length === 0) {
        return;
    }
    context[listKey] = boundDevToolsNames(names);
    if (names.length > DEV_TOOLS_NAME_LIST_CAP) {
        context[countKey] = names.length;
    }
}
//# sourceMappingURL=dev-tools-agent-context.js.map