fix [name, options] syntax for transformers registered as instances#1390
Open
gigi206 wants to merge 1 commit into
Open
fix [name, options] syntax for transformers registered as instances#1390gigi206 wants to merge 1 commit into
gigi206 wants to merge 1 commit into
Conversation
When a config uses the array form `["TransformerName", { options }]`,
ccr resolved the name then called `new` unconditionally. Built-in
transformers without a `static TransformerName` (Anthropic, Gemini,
OpenAI, Deepseek, ...) are registered as already-built instances, so
the `new` threw `TypeError: o is not a constructor` and the provider
silently failed to load.
Detect whether the resolved transformer is a class (function) or an
instance. For instances, build a fresh one via `.constructor` so the
requested options take effect without mutating the shared instance.
Applied to both `use` and model-specific `use` entries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The configuration syntax
"use": [["TransformerName", { ...options }]]is documented for passing options to a transformer constructor, and the built-inAnthropicTransformerexposes aUseBeareroption through its constructor:However, attempting to use it from config:
{ "transformer": { "use": [["Anthropic", { "UseBearer": true }]] } }logs:
and the provider silently fails to load.
Root cause
In
ProviderService.initializeFromProvidersArray, the array form is handled by:But
getTransformerreturns either a class or an already-built instance, depending on how the transformer was registered:Built-in transformers without a
static TransformerName(Anthropic, Gemini, OpenAI, Deepseek, etc.) are registered as instances, sonew instance(options)throws.The string-only form already handled both cases with a
typeof === 'function'check; the array-with-options form did not.Fix
Check whether the resolved value is a class (function) or an instance:
.constructorso the requested options take effect without mutating the shared instance registered globally.Applied to both
transformer.useand model-specifictransformer[model].use.Use case
{ "transformer": { "use": [["Anthropic", { "UseBearer": true }]] } }Now correctly switches the Anthropic transformer to send
Authorization: Bearer ...instead ofx-api-key, useful for Anthropic-compatible endpoints whose auth scheme differs from Anthropic's official endpoint.