refactor(v2/providers): self-registration barrel + host container-config registry
Providers now mirror the channels pattern: each module calls registerProvider() at top level, and providers/index.ts is a barrel of side-effect imports. createProvider() becomes a thin registry lookup; the closed ProviderName union is gone (now a string alias, since the env var is a runtime string anyway). Also adds a host-side provider-container-registry so providers can declare their own mounts and env passthrough in src/providers/<name>.ts instead of the container-runner having to know about each one. The resolver runs once per spawn and threads provider + contribution through buildMounts and buildContainerArgs so side effects (mkdir, etc.) fire exactly once. Both barrels are append-only — adding a new provider is a new file + one import line per barrel, no edits to existing files. The built-in providers (claude, mock) don't need host-side config, so src/providers/ ships with an empty barrel; the container-side barrel imports both. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
33
container/agent-runner/src/providers/provider-registry.ts
Normal file
33
container/agent-runner/src/providers/provider-registry.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Provider self-registration registry.
|
||||
*
|
||||
* Mirrors `src/channels/channel-registry.ts` on the host. Each provider module
|
||||
* calls `registerProvider()` at top level; the barrel (`providers/index.ts`)
|
||||
* imports every provider module for its side effect so registrations fire
|
||||
* before `createProvider()` is called.
|
||||
*/
|
||||
import type { AgentProvider, ProviderOptions } from './types.js';
|
||||
|
||||
export type ProviderFactory = (options: ProviderOptions) => AgentProvider;
|
||||
|
||||
const registry = new Map<string, ProviderFactory>();
|
||||
|
||||
export function registerProvider(name: string, factory: ProviderFactory): void {
|
||||
if (registry.has(name)) {
|
||||
throw new Error(`Provider already registered: ${name}`);
|
||||
}
|
||||
registry.set(name, factory);
|
||||
}
|
||||
|
||||
export function getProviderFactory(name: string): ProviderFactory {
|
||||
const factory = registry.get(name);
|
||||
if (!factory) {
|
||||
const known = [...registry.keys()].join(', ') || '(none)';
|
||||
throw new Error(`Unknown provider: ${name}. Registered: ${known}`);
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
export function listProviderNames(): string[] {
|
||||
return [...registry.keys()];
|
||||
}
|
||||
Reference in New Issue
Block a user