ChromeAIFrontendAdapter
Defined in: adapters/chrome-ai.ts:63
Frontend adapter interface.
Frontend adapters represent how developers want to interact with AI APIs. They normalize provider-specific request formats into universal IR and denormalize IR responses back to provider-specific formats.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ChromeAIFrontendAdapter():
ChromeAIFrontendAdapter
Returns
Section titled “Returns”ChromeAIFrontendAdapter
Properties
Section titled “Properties”metadata
Section titled “metadata”
readonlymetadata:AdapterMetadata
Defined in: adapters/chrome-ai.ts:64
Adapter metadata for identification and capabilities.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”fromIR()
Section titled “fromIR()”fromIR(
response):Promise<ChromeAIResponse>
Defined in: adapters/chrome-ai.ts:130
Convert Universal IR response back to Chrome AI format.
This method transforms the standardized IR response into the format
expected by Chrome AI’s interface. It extracts the text content from
the IR message and returns it in Chrome AI’s simple { text } format.
Parameters
Section titled “Parameters”response
Section titled “response”Universal IR chat response
Returns
Section titled “Returns”Promise<ChromeAIResponse>
Promise resolving to Chrome AI response
Example
Section titled “Example”const adapter = new ChromeAIFrontendAdapter();const chromeResponse = await adapter.fromIR(irResponse);console.log(chromeResponse.text);Implementation of
Section titled “Implementation of”fromIRStream()
Section titled “fromIRStream()”fromIRStream(
stream,options?):AsyncGenerator<string>
Defined in: adapters/chrome-ai.ts:156
Convert Universal IR stream to Chrome AI streaming format.
This async generator method transforms a stream of IR chunks into Chrome AI’s simple text streaming format. It yields raw text strings (no JSON wrapping, no SSE format) and supports stream mode conversion through options (delta, full, or text-only modes).
Parameters
Section titled “Parameters”stream
Section titled “stream”AsyncGenerator<IRStreamChunk>
Universal IR chat stream
options?
Section titled “options?”Optional stream conversion options (stream mode, etc.)
Returns
Section titled “Returns”AsyncGenerator<string>
Yields
Section titled “Yields”Raw text strings
Example
Section titled “Example”const adapter = new ChromeAIFrontendAdapter();for await (const textChunk of adapter.fromIRStream(irStream)) { console.log(textChunk); // Raw text like "Hello" or " world"}Implementation of
Section titled “Implementation of”toIR()
Section titled “toIR()”toIR(
request):Promise<IRChatRequest>
Defined in: adapters/chrome-ai.ts:98
Convert Chrome AI request to Universal IR format.
This method transforms a Chrome AI-formatted request into the standardized Intermediate Representation (IR) format. Chrome AI uses a simple prompt-based format, so this converts the single prompt string into a user message within the IR message array structure.
Parameters
Section titled “Parameters”request
Section titled “request”Chrome AI request with prompt and optional parameters
Returns
Section titled “Returns”Promise<IRChatRequest>
Promise resolving to IR chat request
Example
Section titled “Example”const adapter = new ChromeAIFrontendAdapter();const irRequest = await adapter.toIR({ prompt: 'What is the capital of France?', temperature: 0.7, topK: 40});