Skip to content

Core Extension Points

The AIClient-2-API project is highly modular, allowing developers to integrate new models or custom functionalities through three key extension points:

1. Protocol Conversion (Converter Strategy)

This is the most common extension point when you need to support a new API protocol (e.g., DeepSeek or a platform-specific private protocol).

  • Core Path: src/converters/strategies/
  • Action: Inherit from BaseConverter and implement methods like toOpenAIRequest, toOpenAIResponse.
  • Registration: Register via ConverterFactory in src/converters/register-converters.js.

2. Provider Driver (Provider Core)

Use this when you need to change how you interact with the underlying service (e.g., changing from API Key to a complex OAuth flow, or using specific HTTP client settings).

  • Core Path: src/providers/
  • Interface: ApiServiceAdapter (located in src/providers/adapter.js).
  • Implementation: Create a new driver module (e.g., src/providers/new_provider/new_core.js).

3. Plugin System (Plugin Hooks)

The plugin system allows you to intercept and process request/response streams without modifying the core code.

  • Core Path: src/plugins/
  • Hook Points:
    • onContentGenerated: Callback after content generation.
    • onStreamChunk: Intercept stream chunks before they are sent to the client.
    • onUnaryResponse: Intercept unary responses before they are sent.

4. Key Constant Definitions

Before introducing any new provider or protocol, define them in src/utils/common.js:

  • MODEL_PROTOCOL_PREFIX: Protocol prefix (e.g., deepseek).
  • MODEL_PROVIDER: Provider type identifier.