import { buildAnthropicRequestFromOpenAIChat } from '../shared/anthropic-message-utils.js';
import { buildAnthropicFromOpenAIChatWithNative, buildOpenAIChatFromAnthropicWithNative } from '../../router/virtual-router/engine-selection/native-compat-action-semantics.js';
export function buildOpenAIChatFromAnthropic(payload, options) {
    const result = buildOpenAIChatFromAnthropicWithNative((payload ?? {}), options);
    return (result.request ?? {});
}
export function buildAnthropicFromOpenAIChat(payload, options) {
    return buildAnthropicFromOpenAIChatWithNative((payload ?? {}), options);
}
export { buildAnthropicRequestFromOpenAIChat };
export class AnthropicOpenAIConversionCodec {
    _dependencies;
    id = 'anthropic-openai';
    initialized = false;
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    constructor(_dependencies) {
        this._dependencies = _dependencies;
    }
    async initialize() {
        this.initialized = true;
    }
    async convertRequest(payload, _profile, context) {
        if (!this.initialized)
            await this.initialize();
        const native = buildOpenAIChatFromAnthropicWithNative(payload ?? {}, {
            includeToolCallIds: true
        });
        const request = native.request && typeof native.request === 'object'
            ? { ...native.request }
            : {};
        const aliasMap = native.anthropicToolNameMap && typeof native.anthropicToolNameMap === 'object'
            ? native.anthropicToolNameMap
            : undefined;
        if (aliasMap && Object.keys(aliasMap).length > 0) {
            context.metadata = context.metadata ?? {};
            context.metadata.anthropicToolNameMap = aliasMap;
        }
        return request;
    }
    async convertResponse(payload, _profile, context) {
        if (!this.initialized)
            await this.initialize();
        const aliasMap = context.metadata && typeof context.metadata === 'object'
            ? context.metadata.anthropicToolNameMap
            : undefined;
        return buildAnthropicFromOpenAIChatWithNative((payload ?? {}), {
            toolNameMap: aliasMap,
            requestId: context.requestId,
            entryEndpoint: context.entryEndpoint ?? context.endpoint
        });
    }
}
