# All files / src/agent/providers registry.ts

25% Statements 2/8
50% Branches 1/2
25% Functions 1/4
25% Lines 2/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51

    23x

    22x

     /**
     * Agent Provider Registry
     *
     * In-memory registry of agent provider configurations.
     * Pre-populated with built-in presets, extensible via registerProvider()
     * or loadProvidersFromFile() for custom/override configs.
     */

    import { readFileSync } from 'node:fs';
    import type { AgentProviderConfig } from './types.js';
    import { PROVIDER_PRESETS } from './presets.js';

    const providers = new Map<string, AgentProviderConfig>(
      Object.entries(PROVIDER_PRESETS),
    );

    /**
     * Get a provider configuration by name.
     * Returns null if the provider is not registered.
     */
    export function getProvider(name: string): AgentProviderConfig | null {
      return providers.get(name) ?? null;
    }

    /**
     * List all registered provider names.
     */
    export function listProviders(): string[] {
      return Array.from(providers.keys());
    }

    /**
     * Register or override a provider configuration.
     */
    export function registerProvider(config: AgentProviderConfig): void {
      providers.set(config.name, config);
    }

    /**
     * Load provider configurations from a JSON file and merge into the registry.
     * File should contain a JSON object mapping provider names to AgentProviderConfig objects.
     * Existing providers with matching names will be overridden.
     */
    export function loadProvidersFromFile(path: string): void {
      const raw = readFileSync(path, 'utf-8');
      const parsed = JSON.parse(raw) as Record<string, AgentProviderConfig>;
      for (const [name, config] of Object.entries(parsed)) {
        providers.set(name, { ...config, name });
      }
    }