Skip to content

prefer static TransformerName for custom transformer name resolution#1391

Open
gigi206 wants to merge 1 commit into
musistudio:mainfrom
gigi206:fix/custom-transformer-name-from-static
Open

prefer static TransformerName for custom transformer name resolution#1391
gigi206 wants to merge 1 commit into
musistudio:mainfrom
gigi206:fix/custom-transformer-name-from-static

Conversation

@gigi206
Copy link
Copy Markdown

@gigi206 gigi206 commented May 11, 2026

Problem

When a transformer is registered from a file via transformers: [{ path }], ccr uses instance.name as the registry key. The built-in convention in registerDefaultTransformersInternal is to prefer static TransformerName when present, and only fall back to instance.name.

This inconsistency bites users who mirror the built-in pattern in their custom transformer:

class OpenCodeOpenAIBearerTransformer {
  static TransformerName = "opencode-openai-bearer"; // for config refs
  name = "OpenCodeOpenAIBearer";                     // runtime identity
  endPoint = "/v1/chat/completions";
  // ...
}
module.exports = OpenCodeOpenAIBearerTransformer;

Config:

{
  "transformers": [
    { "path": "/path/to/opencode-openai-bearer.js" }
  ],
  "Providers": [{
    "name": "opencode-openai",
    "transformer": { "use": ["opencode-openai-bearer"] }
  }]
}

Result: the transformer is registered as OpenCodeOpenAIBearer (instance.name), but the config references opencode-openai-bearer (TransformerName). getTransformer("opencode-openai-bearer") returns undefined, the array entry is filtered out, and the provider has an empty transformer list, silently, with no log to point at the cause.

Fix

Use the same name resolution order in registerTransformerFromConfig as in the built-in path: prefer static TransformerName, fall back to instance.name. The error message is also clarified to mention both.

Empirically verified by reproducing the bug locally with a transformer whose name and TransformerName differ. Before the patch, the registry logs register transformer: OpenCodeOpenAIBearer and the provider's use array is silently empty. After the patch, it logs register transformer: opencode-openai-bearer and the provider correctly resolves the transformer.

Compatibility note

A custom transformer that defined static TransformerName = "X" and name = "Y" (different values), and that was referenced as "Y" in user configs, would now be registered as "X" instead. This is intentional realignment with the documented built-in pattern, but worth mentioning in case downstream users have come to rely on the previous behaviour.

registerDefaultTransformersInternal already resolves a built-in
transformer's name from `static TransformerName` first, with
`instance.name` as a fallback. registerTransformerFromConfig only used
`instance.name`, so a custom transformer that follows the same pattern
(kebab-case `TransformerName` for config references, descriptive
`name` for runtime identity) silently registered under the wrong name
and could not be referenced from `transformer.use`.

Use the same resolution order in both code paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant