Router
Defined in: ai.matey.core/src/router.ts:60
Router manages multiple backend adapters with intelligent routing.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Router(
config):Router
Defined in: ai.matey.core/src/router.ts:83
Parameters
Section titled “Parameters”config
Section titled “config”Partial<RouterConfig> = {}
Returns
Section titled “Returns”Router
Properties
Section titled “Properties”config
Section titled “config”
readonlyconfig:RouterConfig
Defined in: ai.matey.core/src/router.ts:62
Router configuration.
Implementation of
Section titled “Implementation of”metadata
Section titled “metadata”
readonlymetadata:AdapterMetadata
Defined in: ai.matey.core/src/router.ts:61
Adapter metadata for identification and capabilities.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”checkHealth()
Section titled “checkHealth()”Call Signature
Section titled “Call Signature”checkHealth():
Promise<Record<string,boolean>>
Defined in: ai.matey.core/src/router.ts:790
Check health of all or specific backend.
Returns
Section titled “Returns”Promise<Record<string, boolean>>
Implementation of
Section titled “Implementation of”Call Signature
Section titled “Call Signature”checkHealth(
name):Promise<boolean>
Defined in: ai.matey.core/src/router.ts:791
Check health of specific backend.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”clearBackendTranslationMapping()
Section titled “clearBackendTranslationMapping()”clearBackendTranslationMapping(
backendName?):Router
Defined in: ai.matey.core/src/router.ts:420
Clear backend-specific model translation mappings.
Parameters
Section titled “Parameters”backendName?
Section titled “backendName?”string
Optional backend name to clear. If not provided, clears all.
Returns
Section titled “Returns”Router
This router for chaining
clearModelTranslationMapping()
Section titled “clearModelTranslationMapping()”clearModelTranslationMapping():
Router
Defined in: ai.matey.core/src/router.ts:409
Clear all model translation mappings.
Returns
Section titled “Returns”Router
This router for chaining
clone()
Section titled “clone()”clone(
config):Router
Defined in: ai.matey.core/src/router.ts:975
Clone router with new configuration.
Parameters
Section titled “Parameters”config
Section titled “config”Partial<RouterConfig>
Returns
Section titled “Returns”Router
Implementation of
Section titled “Implementation of”closeCircuitBreaker()
Section titled “closeCircuitBreaker()”closeCircuitBreaker(
name):void
Defined in: ai.matey.core/src/router.ts:860
Manually close circuit breaker for a backend.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”dispatchParallel()
Section titled “dispatchParallel()”dispatchParallel(
request,options,signal?):Promise<ParallelDispatchResult>
Defined in: ai.matey.core/src/router.ts:658
Dispatch request to multiple backends in parallel.
Parameters
Section titled “Parameters”request
Section titled “request”options
Section titled “options”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”Promise<ParallelDispatchResult>
Implementation of
Section titled “Implementation of”dispose()
Section titled “dispose()”dispose():
void
Defined in: ai.matey.core/src/router.ts:994
Clean up resources.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”execute()
Section titled “execute()”execute(
request,signal?):Promise<IRChatResponse>
Defined in: ai.matey.core/src/router.ts:553
Execute request with automatic backend selection and fallback.
Parameters
Section titled “Parameters”request
Section titled “request”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”Promise<IRChatResponse>
Implementation of
Section titled “Implementation of”executeStream()
Section titled “executeStream()”executeStream(
request,signal?):IRChatStream
Defined in: ai.matey.core/src/router.ts:608
Execute streaming request with automatic backend selection and fallback.
Parameters
Section titled “Parameters”request
Section titled “request”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”fromIR()
Section titled “fromIR()”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.
Parameters
Section titled “Parameters”_request
Section titled “_request”Returns
Section titled “Returns”unknown
Implementation of
Section titled “Implementation of”get(
name):BackendAdapter<unknown,unknown> |undefined
Defined in: ai.matey.core/src/router.ts:219
Get a registered backend adapter.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”BackendAdapter<unknown, unknown> | undefined
Implementation of
Section titled “Implementation of”getBackendInfo()
Section titled “getBackendInfo()”Call Signature
Section titled “Call Signature”getBackendInfo():
BackendInfo[]
Defined in: ai.matey.core/src/router.ts:240
Get information about all or specific backend.
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”Call Signature
Section titled “Call Signature”getBackendInfo(
name):BackendInfo|undefined
Defined in: ai.matey.core/src/router.ts:241
Get information about specific backend.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”BackendInfo | undefined
Implementation of
Section titled “Implementation of”getBackendStats()
Section titled “getBackendStats()”getBackendStats(
name):BackendStats|undefined
Defined in: ai.matey.core/src/router.ts:960
Get statistics for specific backend.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”BackendStats | undefined
Implementation of
Section titled “Implementation of”getBackendTranslationMapping()
Section titled “getBackendTranslationMapping()”getBackendTranslationMapping(
backendName):ModelMapping
Defined in: ai.matey.core/src/router.ts:391
Get backend-specific model translation mapping.
Parameters
Section titled “Parameters”backendName
Section titled “backendName”string
Returns
Section titled “Returns”getFallbackChain()
Section titled “getFallbackChain()”getFallbackChain(): readonly
string[]
Defined in: ai.matey.core/src/router.ts:284
Get current fallback chain.
Returns
Section titled “Returns”readonly string[]
Implementation of
Section titled “Implementation of”getModelMapping()
Section titled “getModelMapping()”getModelMapping():
ModelMapping
Defined in: ai.matey.core/src/router.ts:310
Get current model mapping.
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”getModelPatterns()
Section titled “getModelPatterns()”getModelPatterns(): readonly
ModelPatternMapping[]
Defined in: ai.matey.core/src/router.ts:456
Get current model patterns.
Returns
Section titled “Returns”readonly ModelPatternMapping[]
Implementation of
Section titled “Implementation of”getModelTranslationMapping()
Section titled “getModelTranslationMapping()”getModelTranslationMapping():
ModelMapping
Defined in: ai.matey.core/src/router.ts:341
Get current model translation mapping.
Returns
Section titled “Returns”getStats()
Section titled “getStats()”getStats():
RouterStats
Defined in: ai.matey.core/src/router.ts:917
Get router statistics.
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”has(
name):boolean
Defined in: ai.matey.core/src/router.ts:226
Check if backend is registered.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”isCircuitBreakerOpen()
Section titled “isCircuitBreakerOpen()”isCircuitBreakerOpen(
name):boolean
Defined in: ai.matey.core/src/router.ts:902
Check if circuit breaker is open for a backend.
Parameters
Section titled “Parameters”string
Backend name
Returns
Section titled “Returns”boolean
true if circuit breaker is open, false otherwise
listBackends()
Section titled “listBackends()”listBackends(): readonly
string[]
Defined in: ai.matey.core/src/router.ts:233
List all registered backend names.
Returns
Section titled “Returns”readonly string[]
Implementation of
Section titled “Implementation of”openCircuitBreaker()
Section titled “openCircuitBreaker()”openCircuitBreaker(
name,timeoutMs?):void
Defined in: ai.matey.core/src/router.ts:833
Manually open circuit breaker for a backend.
Parameters
Section titled “Parameters”string
timeoutMs?
Section titled “timeoutMs?”number
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”register()
Section titled “register()”register(
name,adapter):Router
Defined in: ai.matey.core/src/router.ts:154
Register a backend adapter.
Parameters
Section titled “Parameters”string
adapter
Section titled “adapter”Returns
Section titled “Returns”Router
Implementation of
Section titled “Implementation of”resetCircuitBreaker()
Section titled “resetCircuitBreaker()”resetCircuitBreaker(
name?):void
Defined in: ai.matey.core/src/router.ts:879
Reset circuit breaker statistics.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”resetStats()
Section titled “resetStats()”resetStats():
void
Defined in: ai.matey.core/src/router.ts:938
Reset router statistics.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”selectBackend()
Section titled “selectBackend()”selectBackend(
request,preferredBackend?):Promise<string>
Defined in: ai.matey.core/src/router.ts:467
Select backend for a request.
Parameters
Section titled “Parameters”request
Section titled “request”preferredBackend?
Section titled “preferredBackend?”string
Returns
Section titled “Returns”Promise<string>
Implementation of
Section titled “Implementation of”setBackendTranslationMapping()
Section titled “setBackendTranslationMapping()”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.
Parameters
Section titled “Parameters”backendName
Section titled “backendName”string
mapping
Section titled “mapping”Returns
Section titled “Returns”Router
Example
Section titled “Example”router.setBackendTranslationMapping('anthropic', { 'gpt-4': 'claude-3-5-sonnet-20241022', 'gpt-3.5-turbo': 'claude-3-5-haiku-20241022'});setFallbackChain()
Section titled “setFallbackChain()”setFallbackChain(
chain):Router
Defined in: ai.matey.core/src/router.ts:265
Set fallback chain for sequential failover.
Parameters
Section titled “Parameters”readonly string[]
Returns
Section titled “Returns”Router
Implementation of
Section titled “Implementation of”setModelMapping()
Section titled “setModelMapping()”setModelMapping(
mapping):Router
Defined in: ai.matey.core/src/router.ts:291
Set model to backend mapping.
Parameters
Section titled “Parameters”mapping
Section titled “mapping”Returns
Section titled “Returns”Router
Implementation of
Section titled “Implementation of”setModelPatterns()
Section titled “setModelPatterns()”setModelPatterns(
patterns):Router
Defined in: ai.matey.core/src/router.ts:437
Set model pattern mappings.
Parameters
Section titled “Parameters”patterns
Section titled “patterns”readonly ModelPatternMapping[]
Returns
Section titled “Returns”Router
Implementation of
Section titled “Implementation of”setModelTranslationMapping()
Section titled “setModelTranslationMapping()”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.
Parameters
Section titled “Parameters”mapping
Section titled “mapping”Returns
Section titled “Returns”Router
Example
Section titled “Example”router.setModelTranslationMapping({ 'gpt-4': 'claude-3-5-sonnet-20241022', 'gpt-3.5-turbo': 'claude-3-5-haiku-20241022'});toIR()
Section titled “toIR()”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.
Parameters
Section titled “Parameters”_response
Section titled “_response”unknown
_originalRequest
Section titled “_originalRequest”_latencyMs
Section titled “_latencyMs”number
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”unregister()
Section titled “unregister()”unregister(
name):Router
Defined in: ai.matey.core/src/router.ts:182
Unregister a backend adapter.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Router