GenericFrontendAdapter
Defined in: adapters/generic.ts:102
Passthrough frontend adapter for IR format.
This adapter accepts IR requests directly and returns IR responses without any conversion. It’s useful for:
- Direct IR access: Work with the universal format without provider wrappers
- Testing: Test bridges and backends without conversion overhead
- Custom integrations: Build tools that operate at the IR level
- Format normalization: Use when your application already produces IR
Example
Section titled “Example”// Basic usageconst frontend = new GenericFrontendAdapter();
// With custom configurationconst frontend = new GenericFrontendAdapter({ name: 'my-app-frontend', trackProvenance: true, maxContextTokens: 128000,});Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new GenericFrontendAdapter(
config):GenericFrontendAdapter
Defined in: adapters/generic.ts:110
Parameters
Section titled “Parameters”config
Section titled “config”Returns
Section titled “Returns”GenericFrontendAdapter
Properties
Section titled “Properties”metadata
Section titled “metadata”
readonlymetadata:AdapterMetadata
Defined in: adapters/generic.ts:107
Adapter metadata for identification and capabilities.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”fromIR()
Section titled “fromIR()”fromIR(
response):Promise<IRChatResponse>
Defined in: adapters/generic.ts:194
Pass through Universal IR response without conversion.
This method accepts an IR response and returns it directly without any transformation. Since this is a passthrough adapter, the response remains in IR format, allowing applications to work directly with the universal format.
Parameters
Section titled “Parameters”response
Section titled “response”Universal IR chat response
Returns
Section titled “Returns”Promise<IRChatResponse>
Promise resolving to the same IR response
Example
Section titled “Example”const adapter = new GenericFrontendAdapter();const irResponse = await adapter.fromIR(irResponse);// Returns the exact same response unchangedconsole.log(irResponse.message.content);Implementation of
Section titled “Implementation of”fromIRStream()
Section titled “fromIRStream()”fromIRStream(
stream,_options?):AsyncGenerator<IRStreamChunk,void,undefined>
Defined in: adapters/generic.ts:220
Pass through Universal IR stream chunks without conversion.
This async generator method accepts an IR stream and yields each chunk directly without any transformation. Unlike other frontend adapters that convert to provider-specific formats (SSE, JSON, etc.), this maintains the raw IR chunk structure for direct consumption.
Parameters
Section titled “Parameters”stream
Section titled “stream”Universal IR chat stream
_options?
Section titled “_options?”Optional stream conversion options (currently unused)
Returns
Section titled “Returns”AsyncGenerator<IRStreamChunk, void, undefined>
Yields
Section titled “Yields”IR stream chunks unchanged
Example
Section titled “Example”const adapter = new GenericFrontendAdapter();for await (const chunk of adapter.fromIRStream(irStream)) { if (chunk.type === 'content') { console.log(chunk.delta); // Access IR structure directly }}Implementation of
Section titled “Implementation of”toIR()
Section titled “toIR()”toIR(
request):Promise<IRChatRequest>
Defined in: adapters/generic.ts:157
Pass through Universal IR request without conversion.
This method accepts an IR request and returns it directly, as this is a passthrough adapter. When provenance tracking is enabled (default), it adds the frontend adapter name to the provenance metadata for tracking purposes, but otherwise performs no transformations.
Parameters
Section titled “Parameters”request
Section titled “request”Universal IR chat request
Returns
Section titled “Returns”Promise<IRChatRequest>
Promise resolving to the same IR request (with optional provenance)
Example
Section titled “Example”const adapter = new GenericFrontendAdapter();const irRequest = await adapter.toIR({ messages: [{ role: 'user', content: 'Hello!' }], parameters: { model: 'gpt-4', temperature: 0.7 }, metadata: { requestId: 'req_123', timestamp: Date.now(), provenance: {} }});// Returns the same request with provenance.frontend = 'generic-frontend'Implementation of
Section titled “Implementation of”validate()
Section titled “validate()”validate(
request):Promise<void>
Defined in: adapters/generic.ts:234
Validate IR request structure.
Only performs validation if validateRequests is enabled in config.
Parameters
Section titled “Parameters”request
Section titled “request”Returns
Section titled “Returns”Promise<void>