Bridge
Defined in: ai.matey.core/src/bridge.ts:48
Bridge connects frontend and backend adapters.
Type Parameters
Section titled “Type Parameters”TFrontend
Section titled “TFrontend”TFrontend extends FrontendAdapter = FrontendAdapter
Frontend adapter type
Implements
Section titled “Implements”Bridge<TFrontend>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Bridge<
TFrontend>(frontend,backend,config):Bridge<TFrontend>
Defined in: ai.matey.core/src/bridge.ts:76
Create a new Bridge instance.
Parameters
Section titled “Parameters”frontend
Section titled “frontend”TFrontend
Frontend adapter
backend
Section titled “backend”Backend adapter
config
Section titled “config”Partial<BridgeConfig> = {}
Bridge configuration
Returns
Section titled “Returns”Bridge<TFrontend>
Properties
Section titled “Properties”backend
Section titled “backend”
readonlybackend:BackendAdapter
Defined in: ai.matey.core/src/bridge.ts:52
Backend adapter or router.
Implementation of
Section titled “Implementation of”config
Section titled “config”
readonlyconfig:BridgeConfig
Defined in: ai.matey.core/src/bridge.ts:53
Bridge configuration.
Implementation of
Section titled “Implementation of”frontend
Section titled “frontend”
readonlyfrontend:TFrontend
Defined in: ai.matey.core/src/bridge.ts:51
Frontend adapter for this bridge.
Implementation of
Section titled “Implementation of”generateObject()
Section titled “generateObject()”generateObject: <
T>(options) =>Promise<GenerateObjectResult<T>>
Defined in: ai.matey.core/src/bridge.ts:673
Generate a structured object matching a Zod schema using an LLM.
This method uses tool calling to extract structured data from the LLM response, validates it against the provided schema, and returns the typed object.
Type Parameters
Section titled “Type Parameters”T = any
Parameters
Section titled “Parameters”options
Section titled “options”Configuration for object generation
Returns
Section titled “Returns”Promise<GenerateObjectResult<T>>
Promise resolving to the generated and validated object
Example
Section titled “Example”const UserSchema = z.object({ name: z.string(), age: z.number(), email: z.string().email(),});
const result = await bridge.generateObject({ schema: UserSchema, prompt: 'Generate a user profile for Alice, age 30', model: 'gpt-4',});
console.log(result.object); // { name: 'Alice', age: 30, email: '...' }streamObject()
Section titled “streamObject()”streamObject: <
T>(options) =>AsyncGenerator<Partial<T>,T>
Defined in: ai.matey.core/src/bridge.ts:705
Stream a structured object matching a Zod schema using an LLM.
This method uses streaming tool calling to incrementally build up a structured object, yielding partial results as they become available.
Type Parameters
Section titled “Type Parameters”T = any
Parameters
Section titled “Parameters”options
Section titled “options”Configuration for streaming object generation
Returns
Section titled “Returns”AsyncGenerator<Partial<T>, T>
Async generator yielding partial objects and returning the final validated object
Example
Section titled “Example”const ArticleSchema = z.object({ title: z.string(), content: z.string(), tags: z.array(z.string()),});
const stream = bridge.streamObject({ schema: ArticleSchema, prompt: 'Write a blog post about TypeScript', onPartial: (partial) => { console.log('Partial:', partial); },});
for await (const partial of stream) { console.log('Progress:', partial);}Methods
Section titled “Methods”chat()
Section titled “chat()”chat(
request,options?):Promise<InferFrontendResponse<TFrontend>>
Defined in: ai.matey.core/src/bridge.ts:98
Execute a non-streaming chat completion request.
Parameters
Section titled “Parameters”request
Section titled “request”InferFrontendRequest<TFrontend>
options?
Section titled “options?”Returns
Section titled “Returns”Promise<InferFrontendResponse<TFrontend>>
Implementation of
Section titled “Implementation of”chatStream()
Section titled “chatStream()”chatStream(
request,options?):AsyncGenerator<InferFrontendStreamChunk<TFrontend>,void,undefined>
Defined in: ai.matey.core/src/bridge.ts:216
Execute a streaming chat completion request.
Parameters
Section titled “Parameters”request
Section titled “request”InferFrontendRequest<TFrontend>
options?
Section titled “options?”Returns
Section titled “Returns”AsyncGenerator<InferFrontendStreamChunk<TFrontend>, void, undefined>
Implementation of
Section titled “Implementation of”checkHealth()
Section titled “checkHealth()”checkHealth():
Promise<boolean>
Defined in: ai.matey.core/src/bridge.ts:550
Check health of the backend.
Returns
Section titled “Returns”Promise<boolean>
true if backend is healthy, false otherwise
clearMiddleware()
Section titled “clearMiddleware()”clearMiddleware():
Bridge<TFrontend>
Defined in: ai.matey.core/src/bridge.ts:413
Clear all middleware from the stack.
Returns
Section titled “Returns”Bridge<TFrontend>
Implementation of
Section titled “Implementation of”clone()
Section titled “clone()”clone(
config):Bridge<TFrontend>
Defined in: ai.matey.core/src/bridge.ts:569
Clone bridge with new configuration.
Parameters
Section titled “Parameters”config
Section titled “config”Partial<BridgeConfig>
Returns
Section titled “Returns”Bridge<TFrontend>
Implementation of
Section titled “Implementation of”dispose()
Section titled “dispose()”dispose():
void
Defined in: ai.matey.core/src/bridge.ts:579
Clean up resources.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”getConfig()
Section titled “getConfig()”getConfig():
Readonly<BridgeConfig>
Defined in: ai.matey.core/src/bridge.ts:562
Get a copy of the bridge configuration.
Returns
Section titled “Returns”Readonly<BridgeConfig>
Readonly copy of the bridge configuration
getMiddleware()
Section titled “getMiddleware()”getMiddleware(): readonly
Middleware[]
Defined in: ai.matey.core/src/bridge.ts:421
Get all middleware in the stack.
Returns
Section titled “Returns”readonly Middleware[]
Implementation of
Section titled “Implementation of”getRouter()
Section titled “getRouter()”getRouter():
null
Defined in: ai.matey.core/src/bridge.ts:541
Get router instance (returns null for basic Bridge).
Returns
Section titled “Returns”null
Implementation of
Section titled “Implementation of”getStats()
Section titled “getStats()”getStats():
BridgeStats
Defined in: ai.matey.core/src/bridge.ts:488
Get runtime statistics for this bridge.
Returns
Section titled “Returns”Bridge statistics including request counts, latencies, and error breakdown
Implementation of
Section titled “Implementation of”hasModel()
Section titled “hasModel()”hasModel(
modelId):Promise<boolean>
Defined in: ai.matey.core/src/bridge.ts:347
Check if a specific model is available from the backend.
Parameters
Section titled “Parameters”modelId
Section titled “modelId”string
Model identifier to check
Returns
Section titled “Returns”Promise<boolean>
true if model is available, false otherwise
listModels()
Section titled “listModels()”listModels(
options?):Promise<ListModelsResult|null>
Defined in: ai.matey.core/src/bridge.ts:333
List available models from the backend.
This delegates directly to the backend adapter’s listModels() method. Useful for discovering available models before making requests.
Parameters
Section titled “Parameters”options?
Section titled “options?”Options for listing models (filtering, cache control)
Returns
Section titled “Returns”Promise<ListModelsResult | null>
List of available models, or null if backend doesn’t support listing
off(
event,listener):Bridge<TFrontend>
Defined in: ai.matey.core/src/bridge.ts:453
Remove an event listener.
Parameters
Section titled “Parameters”Event type
BridgeEventType | "*"
listener
Section titled “listener”Callback function to remove
Returns
Section titled “Returns”Bridge<TFrontend>
Implementation of
Section titled “Implementation of”on(
event,listener):Bridge<TFrontend>
Defined in: ai.matey.core/src/bridge.ts:438
Register an event listener.
Note: Event emission is not yet implemented. Listeners are stored for future use when event emission is added.
Parameters
Section titled “Parameters”Event type to listen for, or ‘*’ for all events
BridgeEventType | "*"
listener
Section titled “listener”Callback function
Returns
Section titled “Returns”Bridge<TFrontend>
Implementation of
Section titled “Implementation of”once()
Section titled “once()”once(
event,listener):Bridge<TFrontend>
Defined in: ai.matey.core/src/bridge.ts:471
Register a one-time event listener.
Note: Event emission is not yet implemented. Listeners are stored for future use when event emission is added.
Parameters
Section titled “Parameters”Event type to listen for
listener
Section titled “listener”Callback function
Returns
Section titled “Returns”Bridge<TFrontend>
Implementation of
Section titled “Implementation of”removeMiddleware()
Section titled “removeMiddleware()”removeMiddleware(
middleware):Bridge<TFrontend>
Defined in: ai.matey.core/src/bridge.ts:405
Remove middleware from the stack.
Parameters
Section titled “Parameters”middleware
Section titled “middleware”Middleware to remove
Returns
Section titled “Returns”Bridge<TFrontend>
This bridge for chaining
Implementation of
Section titled “Implementation of”resetStats()
Section titled “resetStats()”resetStats():
void
Defined in: ai.matey.core/src/bridge.ts:524
Reset all statistics to zero.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”use(
middleware):Bridge<TFrontend>
Defined in: ai.matey.core/src/bridge.ts:394
Add middleware to the bridge’s middleware stack.
Parameters
Section titled “Parameters”middleware
Section titled “middleware”Returns
Section titled “Returns”Bridge<TFrontend>
Implementation of
Section titled “Implementation of”validateModel()
Section titled “validateModel()”validateModel(
modelId):Promise<void>
Defined in: ai.matey.core/src/bridge.ts:365
Validate that a model is available (optional safety check).
Note: This is an optional validation - the system doesn’t automatically validate models since cross-provider translation is supported.
Parameters
Section titled “Parameters”modelId
Section titled “modelId”string
Model identifier to validate
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”If model is not available