import { buildNativeReqOutboundCompatAdapterContext } from '../../hub/pipeline/compat/native-adapter-context.js';
import { applyAnthropicClaudeCodeUserIdWithNative } from '../../../router/virtual-router/engine-selection/native-compat-action-semantics.js';
const PROFILE = 'chat:claude-code';
const DEFAULT_PROVIDER_PROTOCOL = 'anthropic-messages';
const DEFAULT_ENTRY_ENDPOINT = '/v1/messages';
function buildClaudeCodeCompatContext(adapterContext) {
    const nativeContext = buildNativeReqOutboundCompatAdapterContext(adapterContext);
    return {
        ...nativeContext,
        compatibilityProfile: PROFILE,
        providerProtocol: nativeContext.providerProtocol ??
            adapterContext?.providerProtocol ??
            DEFAULT_PROVIDER_PROTOCOL,
        entryEndpoint: nativeContext.entryEndpoint ??
            adapterContext?.entryEndpoint ??
            DEFAULT_ENTRY_ENDPOINT,
    };
}
export function applyAnthropicClaudeCodeUserIdCompat(root, adapterContext) {
    if (!root || typeof root !== 'object' || Array.isArray(root)) {
        return;
    }
    const normalized = applyAnthropicClaudeCodeUserIdWithNative(root, buildClaudeCodeCompatContext(adapterContext));
    for (const key of Object.keys(root)) {
        if (!(key in normalized)) {
            delete root[key];
        }
    }
    Object.assign(root, normalized);
}
