AnthropicFrontendAdapter
Defined in: adapters/anthropic.ts:287
Frontend adapter for Anthropic Messages API.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AnthropicFrontendAdapter():
AnthropicFrontendAdapter
Returns
Section titled “Returns”AnthropicFrontendAdapter
Properties
Section titled “Properties”metadata
Section titled “metadata”
readonlymetadata:AdapterMetadata
Defined in: adapters/anthropic.ts:292
Adapter metadata for identification and capabilities.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”fromIR()
Section titled “fromIR()”fromIR(
response):Promise<AnthropicResponse>
Defined in: adapters/anthropic.ts:402
Convert Universal IR response back to Anthropic Messages API format.
This method transforms the standardized IR response into the format expected by Anthropic’s Messages API. It handles message conversion, stop reason mapping, and usage statistics formatting specific to Anthropic’s response structure.
Parameters
Section titled “Parameters”response
Section titled “response”Universal IR chat response
Returns
Section titled “Returns”Promise<AnthropicResponse>
Promise resolving to Anthropic Messages API response
Throws
Section titled “Throws”If conversion fails
Example
Section titled “Example”const adapter = new AnthropicFrontendAdapter();const anthropicResponse = await adapter.fromIR(irResponse);console.log(anthropicResponse.content[0].text);Implementation of
Section titled “Implementation of”fromIRStream()
Section titled “fromIRStream()”fromIRStream(
stream,options?):AsyncGenerator<AnthropicStreamEvent,void,undefined>
Defined in: adapters/anthropic.ts:461
Convert Universal IR stream to Anthropic Server-Sent Events (SSE) format.
This async generator method transforms a stream of IR chunks into Anthropic-formatted streaming events. It handles stream mode conversion, tracks message metadata, and emits properly formatted SSE events compatible with Anthropic’s streaming API including message_start, content_block_delta, and message_stop events.
Parameters
Section titled “Parameters”stream
Section titled “stream”Universal IR chat stream
options?
Section titled “options?”Optional stream conversion options (stream mode, etc.)
Returns
Section titled “Returns”AsyncGenerator<AnthropicStreamEvent, void, undefined>
Yields
Section titled “Yields”Anthropic-formatted streaming events
Throws
Section titled “Throws”If stream conversion fails
Example
Section titled “Example”const adapter = new AnthropicFrontendAdapter();for await (const event of adapter.fromIRStream(irStream)) { if (event.type === 'content_block_delta') { console.log(event.delta.text); }}Implementation of
Section titled “Implementation of”toIR()
Section titled “toIR()”toIR(
request):Promise<IRChatRequest>
Defined in: adapters/anthropic.ts:332
Convert Anthropic Messages API request to Universal IR format.
This method transforms an Anthropic-formatted request into the standardized Intermediate Representation (IR) format. It handles Anthropic’s unique system message format (separate from messages array) by converting it to IR’s in-messages format, and maps Anthropic-specific parameters like top_k.
Parameters
Section titled “Parameters”request
Section titled “request”Anthropic Messages API request
Returns
Section titled “Returns”Promise<IRChatRequest>
Promise resolving to IR chat request
Throws
Section titled “Throws”If conversion fails
Example
Section titled “Example”const adapter = new AnthropicFrontendAdapter();const irRequest = await adapter.toIR({ model: 'claude-3-5-sonnet-20241022', max_tokens: 1024, messages: [{ role: 'user', content: 'Hello!' }], system: 'You are a helpful assistant'});