Skip to content

BaseProviderClass

Abstract base provider that every CompositeVoice provider extends.

Defined in: src/providers/base/BaseProvider.ts:72

Abstract base provider that every CompositeVoice provider extends.

Remarks

BaseProvider defines the lifecycle shared by all provider categories:

  1. Construction — receives a ProviderType, a BaseProviderConfig, and an optional Logger.
  2. Initializationinitialize delegates to the subclass hook onInitialize and guards against double-init.
  3. Runtime — the provider is considered ready (isReady returns true) after initialization succeeds.
  4. Disposaldispose delegates to onDispose and resets the ready state.

Subclasses override the two abstract hooks (onInitialize and onDispose) plus optionally onConfigUpdate to react to runtime configuration changes.

Inheritance hierarchy:

BaseProvider
 +-- BaseSTTProvider
 |    +-- LiveSTTProvider   (WebSocket STT)
 |    +-- RestSTTProvider   (REST STT)
 +-- BaseLLMProvider        (all LLM providers)
 +-- BaseTTSProvider
      +-- LiveTTSProvider   (WebSocket TTS)
      +-- RestTTSProvider   (REST TTS)

Example

import { BaseProvider } from 'composite-voice';
import type { BaseProviderConfig, ProviderType } from 'composite-voice';

class MyCustomProvider extends BaseProvider {
  constructor(config: BaseProviderConfig) {
    super('rest', config);
  }

  protected async onInitialize(): Promise<void> {
    // Acquire resources, validate credentials, etc.
  }

  protected async onDispose(): Promise<void> {
    // Release resources, close connections, etc.
  }
}

See

Extended by

Implements

Constructors

Constructor

new BaseProviderClass(
   type, 
   config, 
   logger?): BaseProvider;

Defined in: src/providers/base/BaseProvider.ts:108

Create a new provider instance.

Parameters

ParameterTypeDescription
typeProviderTypeThe communication transport ('rest' or 'websocket').
configBaseProviderConfigProvider configuration options.
logger?LoggerOptional parent logger; a child logger scoped to this provider’s class name will be derived from it. When omitted a new Logger is created using the debug flag from config.

Returns

BaseProvider

Properties

PropertyModifierTypeDefault valueDescriptionDefined in
configprotectedBaseProviderConfigundefinedProvider-specific configuration.src/providers/base/BaseProvider.ts:91
initializedprotectedbooleanfalseTracks whether initialize has completed successfully.src/providers/base/BaseProvider.ts:97
loggerprotectedLoggerundefinedScoped logger instance for this provider.src/providers/base/BaseProvider.ts:94
rolesreadonlyreadonly ProviderRole[][]Pipeline roles this provider covers. Remarks Subclasses override this to declare which pipeline stages they handle. For example, BaseSTTProvider sets ['stt'], while NativeSTT overrides to ['input', 'stt'] because it manages its own microphone. See ProviderRole for the possible role valuessrc/providers/base/BaseProvider.ts:88
typereadonlyProviderTypeundefinedCommunication transport this provider uses ('rest' or 'websocket').src/providers/base/BaseProvider.ts:74

Methods

assertReady()

protected assertReady(): void;

Defined in: src/providers/base/BaseProvider.ts:255

Guard that throws if the provider has not been initialized.

Returns

void

Remarks

Call at the start of any method that requires the provider to be ready.

Throws

Error Thrown with a descriptive message when initialized is false.


dispose()

dispose(): Promise<void>;

Defined in: src/providers/base/BaseProvider.ts:154

Clean up resources and dispose of the provider.

Returns

Promise<void>

Remarks

Delegates to the subclass hook onDispose and resets the initialized flag. If the provider is not initialized, the call is a no-op.

Throws

Re-throws any error raised by onDispose.

Implementation of

BaseProvider.dispose


getConfig()

getConfig(): BaseProviderConfig;

Defined in: src/providers/base/BaseProvider.ts:187

Get a shallow copy of the current provider configuration.

Returns

BaseProviderConfig

A new object containing all current configuration values.


initialize()

initialize(): Promise<void>;

Defined in: src/providers/base/BaseProvider.ts:127

Initialize the provider, making it ready for use.

Returns

Promise<void>

Remarks

Calls the subclass hook onInitialize. If the provider has already been initialized the call is a no-op.

Throws

ProviderInitializationError Thrown when onInitialize rejects. The original error is wrapped with the provider class name for diagnostics.

Implementation of

BaseProvider.initialize


isReady()

isReady(): boolean;

Defined in: src/providers/base/BaseProvider.ts:178

Check whether the provider has been initialized and is ready.

Returns

boolean

true when initialize has completed successfully and dispose has not yet been called.

Implementation of

BaseProvider.isReady


onConfigUpdate()

protected onConfigUpdate(_config): void;

Defined in: src/providers/base/BaseProvider.ts:242

Hook called after updateConfig merges new values.

Parameters

ParameterTypeDescription
_configPartial<BaseProviderConfig>The partial configuration that was merged.

Returns

void

Remarks

The default implementation is a no-op. Override in subclasses to react to runtime configuration changes (e.g. reconnect with a new API key).


onDispose()

abstract protected onDispose(): Promise<void>;

Defined in: src/providers/base/BaseProvider.ts:229

Provider-specific disposal logic.

Returns

Promise<void>

Remarks

Subclasses must implement this method to release any resources acquired during onInitialize (e.g. close connections, free memory).


onInitialize()

abstract protected onInitialize(): Promise<void>;

Defined in: src/providers/base/BaseProvider.ts:217

Provider-specific initialization logic.

Returns

Promise<void>

Remarks

Subclasses must implement this method to perform any setup required before the provider can be used (e.g. validate credentials, open connections, load models).


updateConfig()

updateConfig(config): void;

Defined in: src/providers/base/BaseProvider.ts:201

Merge partial configuration updates into the current config.

Parameters

ParameterTypeDescription
configPartial<BaseProviderConfig>A partial configuration object whose keys will overwrite existing values.

Returns

void

Remarks

After merging, the subclass hook onConfigUpdate is called so providers can react to changed values at runtime.

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency