ChromeAIBackendAdapter
Defined in: backend-browser/src/chrome-ai.ts:65
Backend adapter interface.
Backend adapters handle actual API calls to AI providers. They transform universal IR into provider-specific API requests and normalize responses back to IR.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ChromeAIBackendAdapter(
config?):ChromeAIBackendAdapter
Defined in: backend-browser/src/chrome-ai.ts:69
Parameters
Section titled “Parameters”config?
Section titled “config?”Partial<BackendAdapterConfig>
Returns
Section titled “Returns”ChromeAIBackendAdapter
Properties
Section titled “Properties”metadata
Section titled “metadata”
readonlymetadata:AdapterMetadata
Defined in: backend-browser/src/chrome-ai.ts:66
Adapter metadata for identification and capabilities.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”estimateCost()
Section titled “estimateCost()”estimateCost(
_request):Promise<number|null>
Defined in: backend-browser/src/chrome-ai.ts:371
Estimate the cost of a Chrome AI request.
Chrome AI is completely free as it runs locally on-device, so this always returns 0. No API keys or payment required.
Parameters
Section titled “Parameters”_request
Section titled “_request”IR chat request (unused)
Returns
Section titled “Returns”Promise<number | null>
Promise resolving to 0 (Chrome AI is free)
Example
Section titled “Example”const adapter = new ChromeAIBackendAdapter();const cost = await adapter.estimateCost(request);console.log(cost); // Always 0Implementation of
Section titled “Implementation of”execute()
Section titled “execute()”execute(
request,signal?):Promise<IRChatResponse>
Defined in: backend-browser/src/chrome-ai.ts:136
Execute a chat request using Chrome’s built-in AI.
This method processes an IR chat request through Chrome AI’s streaming API, collecting all chunks into a complete response. Chrome AI always streams internally, so this method consumes the stream and returns the final result. Requires Chrome 129+ with AI features enabled.
Parameters
Section titled “Parameters”request
Section titled “request”Universal IR chat request
signal?
Section titled “signal?”AbortSignal
Optional AbortSignal for cancellation
Returns
Section titled “Returns”Promise<IRChatResponse>
Promise resolving to IR chat response
Throws
Section titled “Throws”If Chrome AI is unavailable or request fails
Example
Section titled “Example”const adapter = new ChromeAIBackendAdapter();const response = await adapter.execute({ messages: [{ role: 'user', content: 'Hello!' }], parameters: { temperature: 0.7, topK: 40 }, metadata: { requestId: 'req_123', timestamp: Date.now(), provenance: {} }});console.log(response.message.content);Implementation of
Section titled “Implementation of”executeStream()
Section titled “executeStream()”executeStream(
request,signal?):IRChatStream
Defined in: backend-browser/src/chrome-ai.ts:211
Execute a streaming chat request using Chrome’s built-in AI.
This async generator method processes an IR chat request through Chrome AI’s streaming interface, yielding IR stream chunks as they arrive. It checks for Chrome AI availability, creates a session with the specified parameters, combines all messages into a single prompt, and streams the response. Supports abort signals for cancellation.
Parameters
Section titled “Parameters”request
Section titled “request”Universal IR chat request
signal?
Section titled “signal?”AbortSignal
Optional AbortSignal for cancellation
Returns
Section titled “Returns”Yields
Section titled “Yields”IR stream chunks including start, content, done, and error events
Throws
Section titled “Throws”Yields error chunk if Chrome AI unavailable or stream fails
Example
Section titled “Example”const adapter = new ChromeAIBackendAdapter();for await (const chunk of adapter.executeStream(request)) { if (chunk.type === 'content') { console.log('Delta:', chunk.delta); } else if (chunk.type === 'done') { console.log('Complete:', chunk.message.content); }}Implementation of
Section titled “Implementation of”fromIR()
Section titled “fromIR()”fromIR(
request):IRChatRequest
Defined in: backend-browser/src/chrome-ai.ts:97
Convert IR request to provider format (passthrough - uses IR internally).
Parameters
Section titled “Parameters”request
Section titled “request”Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”healthCheck()
Section titled “healthCheck()”healthCheck():
Promise<boolean>
Defined in: backend-browser/src/chrome-ai.ts:342
Check if Chrome AI is available and healthy.
This method verifies that Chrome AI is present in the browser environment and reports being available. Returns false if Chrome AI is not supported, not enabled, or if the device doesn’t support on-device AI.
Returns
Section titled “Returns”Promise<boolean>
Promise resolving to true if Chrome AI is available, false otherwise
Example
Section titled “Example”const adapter = new ChromeAIBackendAdapter();if (await adapter.healthCheck()) { console.log('Chrome AI is ready!');} else { console.log('Chrome AI not available - use a different backend');}Implementation of
Section titled “Implementation of”toIR()
Section titled “toIR()”toIR(
response,_originalRequest,_latencyMs):IRChatResponse
Defined in: backend-browser/src/chrome-ai.ts:104
Convert provider response to IR format (passthrough - uses IR internally).
Parameters
Section titled “Parameters”response
Section titled “response”_originalRequest
Section titled “_originalRequest”_latencyMs
Section titled “_latencyMs”number