feat: add Tess runtime provider registry (#722)
This commit was merged in pull request #722.
This commit is contained in:
40
packages/agent/src/runtime-provider-registry.ts
Normal file
40
packages/agent/src/runtime-provider-registry.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { AgentRuntimeProvider } from '@mosaicstack/types';
|
||||
|
||||
/**
|
||||
* Registry for runtime providers. Registration is explicit and replacement is
|
||||
* forbidden so a provider identity cannot be silently hijacked at runtime.
|
||||
*/
|
||||
export class AgentRuntimeProviderRegistry {
|
||||
private readonly providers = new Map<string, AgentRuntimeProvider>();
|
||||
|
||||
register(provider: AgentRuntimeProvider): void {
|
||||
const providerId = provider.id.trim();
|
||||
if (providerId.length === 0) {
|
||||
throw new Error('Runtime provider ID is required');
|
||||
}
|
||||
if (this.providers.has(providerId)) {
|
||||
throw new Error(`Runtime provider is already registered: ${providerId}`);
|
||||
}
|
||||
this.providers.set(providerId, provider);
|
||||
}
|
||||
|
||||
get(providerId: string): AgentRuntimeProvider | undefined {
|
||||
return this.providers.get(providerId);
|
||||
}
|
||||
|
||||
require(providerId: string): AgentRuntimeProvider {
|
||||
const normalizedProviderId = providerId.trim();
|
||||
if (normalizedProviderId.length === 0) {
|
||||
throw new Error('Runtime provider ID is required');
|
||||
}
|
||||
const provider = this.providers.get(normalizedProviderId);
|
||||
if (!provider) {
|
||||
throw new Error(`Runtime provider is not registered: ${normalizedProviderId}`);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
list(): AgentRuntimeProvider[] {
|
||||
return Array.from(this.providers.values());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user