nexus-agents - v2.80.0
    Preparing search index...

    Class AdapterFactory

    Factory for creating and managing model adapters.

    Implements the registry pattern to allow dynamic registration of adapter creators for different model providers. This enables a plugin-style architecture where new providers can be added without modifying core code.

    const factory = new AdapterFactory();

    // Register a provider
    factory.register('anthropic', (config) => new ClaudeAdapter(config));

    // Create an adapter
    const result = factory.create({
    providerId: 'anthropic',
    modelId: 'claude-sonnet-4'
    });

    if (result.ok) {
    const adapter = result.value;
    // Use adapter...
    }
    Index

    Constructors

    Accessors

    Methods

    • Creates an adapter instance for the specified configuration.

      Validates the configuration against the schema, looks up the provider in the registry, and invokes the creator function to produce an adapter.

      Parameters

      • config: {
            providerId: string;
            modelId: string;
            apiKey?: string;
            baseUrl?: string;
            timeout?: number;
            maxRetries?: number;
        }

        Adapter configuration specifying provider and settings

        • providerId: string

          Provider identifier (e.g., 'anthropic', 'openai')

        • modelId: string

          Model identifier (e.g., 'claude-sonnet-4', 'gpt-4o')

        • OptionalapiKey?: string

          API key for authentication (optional, may come from environment)

        • OptionalbaseUrl?: string

          Base URL for the API (optional, uses provider default)

        • Optionaltimeout?: number

          Request timeout in milliseconds

        • OptionalmaxRetries?: number

          Maximum number of retries for failed requests

      Returns Result<IModelAdapter, ConfigError>

      Result containing the adapter or a ConfigError

      const result = factory.create({
      providerId: 'anthropic',
      modelId: 'claude-sonnet-4',
      timeout: 30000,
      maxRetries: 3
      });

      if (result.ok) {
      const response = await result.value.complete(request);
      } else {
      console.error('Failed to create adapter:', result.error.message);
      }