Skip to content

Router

Defined in: ai.matey.core/src/router.ts:60

Router manages multiple backend adapters with intelligent routing.

new Router(config): Router

Defined in: ai.matey.core/src/router.ts:83

Partial<RouterConfig> = {}

Router

readonly config: RouterConfig

Defined in: ai.matey.core/src/router.ts:62

Router configuration.

Router.config


readonly metadata: AdapterMetadata

Defined in: ai.matey.core/src/router.ts:61

Adapter metadata for identification and capabilities.

Router.metadata

checkHealth(): Promise<Record<string, boolean>>

Defined in: ai.matey.core/src/router.ts:790

Check health of all or specific backend.

Promise<Record<string, boolean>>

Router.checkHealth

checkHealth(name): Promise<boolean>

Defined in: ai.matey.core/src/router.ts:791

Check health of specific backend.

string

Promise<boolean>

Router.checkHealth


clearBackendTranslationMapping(backendName?): Router

Defined in: ai.matey.core/src/router.ts:420

Clear backend-specific model translation mappings.

string

Optional backend name to clear. If not provided, clears all.

Router

This router for chaining


clearModelTranslationMapping(): Router

Defined in: ai.matey.core/src/router.ts:409

Clear all model translation mappings.

Router

This router for chaining


clone(config): Router

Defined in: ai.matey.core/src/router.ts:975

Clone router with new configuration.

Partial<RouterConfig>

Router

Router.clone


closeCircuitBreaker(name): void

Defined in: ai.matey.core/src/router.ts:860

Manually close circuit breaker for a backend.

string

void

Router.closeCircuitBreaker


dispatchParallel(request, options, signal?): Promise<ParallelDispatchResult>

Defined in: ai.matey.core/src/router.ts:658

Dispatch request to multiple backends in parallel.

IRChatRequest

ParallelDispatchOptions = {}

AbortSignal

Promise<ParallelDispatchResult>

Router.dispatchParallel


dispose(): void

Defined in: ai.matey.core/src/router.ts:994

Clean up resources.

void

Router.dispose


execute(request, signal?): Promise<IRChatResponse>

Defined in: ai.matey.core/src/router.ts:553

Execute request with automatic backend selection and fallback.

IRChatRequest

AbortSignal

Promise<IRChatResponse>

Router.execute


executeStream(request, signal?): IRChatStream

Defined in: ai.matey.core/src/router.ts:608

Execute streaming request with automatic backend selection and fallback.

IRChatRequest

AbortSignal

IRChatStream

Router.executeStream


fromIR(_request): unknown

Defined in: ai.matey.core/src/router.ts:135

Convert IR request to provider format. Not applicable for Router - use the specific backend adapter instead.

IRChatRequest

unknown

Router.fromIR


get(name): BackendAdapter<unknown, unknown> | undefined

Defined in: ai.matey.core/src/router.ts:219

Get a registered backend adapter.

string

BackendAdapter<unknown, unknown> | undefined

Router.get


getBackendInfo(): BackendInfo[]

Defined in: ai.matey.core/src/router.ts:240

Get information about all or specific backend.

BackendInfo[]

Router.getBackendInfo

getBackendInfo(name): BackendInfo | undefined

Defined in: ai.matey.core/src/router.ts:241

Get information about specific backend.

string

BackendInfo | undefined

Router.getBackendInfo


getBackendStats(name): BackendStats | undefined

Defined in: ai.matey.core/src/router.ts:960

Get statistics for specific backend.

string

BackendStats | undefined

Router.getBackendStats


getBackendTranslationMapping(backendName): ModelMapping

Defined in: ai.matey.core/src/router.ts:391

Get backend-specific model translation mapping.

string

ModelMapping


getFallbackChain(): readonly string[]

Defined in: ai.matey.core/src/router.ts:284

Get current fallback chain.

readonly string[]

Router.getFallbackChain


getModelMapping(): ModelMapping

Defined in: ai.matey.core/src/router.ts:310

Get current model mapping.

ModelMapping

Router.getModelMapping


getModelPatterns(): readonly ModelPatternMapping[]

Defined in: ai.matey.core/src/router.ts:456

Get current model patterns.

readonly ModelPatternMapping[]

Router.getModelPatterns


getModelTranslationMapping(): ModelMapping

Defined in: ai.matey.core/src/router.ts:341

Get current model translation mapping.

ModelMapping


getStats(): RouterStats

Defined in: ai.matey.core/src/router.ts:917

Get router statistics.

RouterStats

Router.getStats


has(name): boolean

Defined in: ai.matey.core/src/router.ts:226

Check if backend is registered.

string

boolean

Router.has


isCircuitBreakerOpen(name): boolean

Defined in: ai.matey.core/src/router.ts:902

Check if circuit breaker is open for a backend.

string

Backend name

boolean

true if circuit breaker is open, false otherwise


listBackends(): readonly string[]

Defined in: ai.matey.core/src/router.ts:233

List all registered backend names.

readonly string[]

Router.listBackends


openCircuitBreaker(name, timeoutMs?): void

Defined in: ai.matey.core/src/router.ts:833

Manually open circuit breaker for a backend.

string

number

void

Router.openCircuitBreaker


register(name, adapter): Router

Defined in: ai.matey.core/src/router.ts:154

Register a backend adapter.

string

BackendAdapter

Router

Router.register


resetCircuitBreaker(name?): void

Defined in: ai.matey.core/src/router.ts:879

Reset circuit breaker statistics.

string

void

Router.resetCircuitBreaker


resetStats(): void

Defined in: ai.matey.core/src/router.ts:938

Reset router statistics.

void

Router.resetStats


selectBackend(request, preferredBackend?): Promise<string>

Defined in: ai.matey.core/src/router.ts:467

Select backend for a request.

IRChatRequest

string

Promise<string>

Router.selectBackend


setBackendTranslationMapping(backendName, mapping): Router

Defined in: ai.matey.core/src/router.ts:361

Set backend-specific model translation mapping. This takes priority over global model translation mapping.

string

ModelMapping

Router

router.setBackendTranslationMapping('anthropic', {
'gpt-4': 'claude-3-5-sonnet-20241022',
'gpt-3.5-turbo': 'claude-3-5-haiku-20241022'
});

setFallbackChain(chain): Router

Defined in: ai.matey.core/src/router.ts:265

Set fallback chain for sequential failover.

readonly string[]

Router

Router.setFallbackChain


setModelMapping(mapping): Router

Defined in: ai.matey.core/src/router.ts:291

Set model to backend mapping.

ModelMapping

Router

Router.setModelMapping


setModelPatterns(patterns): Router

Defined in: ai.matey.core/src/router.ts:437

Set model pattern mappings.

readonly ModelPatternMapping[]

Router

Router.setModelPatterns


setModelTranslationMapping(mapping): Router

Defined in: ai.matey.core/src/router.ts:330

Set model name translation mapping (for fallback scenarios). Maps source model names to target model names.

ModelMapping

Router

router.setModelTranslationMapping({
'gpt-4': 'claude-3-5-sonnet-20241022',
'gpt-3.5-turbo': 'claude-3-5-haiku-20241022'
});

toIR(_response, _originalRequest, _latencyMs): IRChatResponse

Defined in: ai.matey.core/src/router.ts:143

Convert provider response to IR format. Not applicable for Router - use the specific backend adapter instead.

unknown

IRChatRequest

number

IRChatResponse

Router.toIR


unregister(name): Router

Defined in: ai.matey.core/src/router.ts:182

Unregister a backend adapter.

string

Router

Router.unregister