A pair of bidirectional conversion functions for transforming data between two formats.
This type is used throughout the message system to enable conversion between
provider-specific message formats (like OpenAI, Anthropic, Google, etc.) and
standardized internal content block representations. The encode function
typically converts from a standard format to a provider-specific format, while
decode converts from a provider-specific format back to the standard format.
ConverterPair// Converter pair for OpenAI message blocks
const openAIConverter: ConverterPair<ContentBlock.Standard, OpenAIBlock> = {
encode: (standard) => ({ text: standard.text }),
decode: (openai) => ({ type: "text", text: openai.text })
};
// Usage
const standardBlock = { type: "text", text: "Hello" };
const openaiBlock = openAIConverter.encode(standardBlock);
const backToStandard = openAIConverter.decode(openaiBlock);