export function buildNativeReqOutboundCompatAdapterContext(adapterContext) {
    const row = (adapterContext ?? {});
    const readString = (key) => {
        const value = row[key];
        return typeof value === 'string' && value.trim().length ? value.trim() : undefined;
    };
    const readNumber = (key) => {
        const value = row[key];
        return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
    };
    const readRecord = (key) => {
        const value = row[key];
        if (!value || typeof value !== 'object' || Array.isArray(value)) {
            return undefined;
        }
        return value;
    };
    return {
        __rt: readRecord('__rt'),
        compatibilityProfile: readString('compatibilityProfile'),
        providerProtocol: readString('providerProtocol') ?? adapterContext?.providerProtocol,
        providerId: readString('providerId'),
        providerKey: readString('providerKey'),
        runtimeKey: readString('runtimeKey'),
        requestId: readString('requestId') ?? adapterContext?.requestId,
        clientRequestId: readString('clientRequestId'),
        groupRequestId: readString('groupRequestId'),
        sessionId: readString('sessionId'),
        conversationId: readString('conversationId'),
        entryEndpoint: readString('entryEndpoint') ?? adapterContext?.entryEndpoint,
        routeId: readString('routeId') ?? adapterContext?.routeId,
        capturedChatRequest: readRecord('capturedChatRequest'),
        deepseek: readRecord('deepseek'),
        claudeCode: readRecord('claudeCode'),
        estimatedInputTokens: readNumber('estimatedInputTokens'),
        modelId: readString('modelId'),
        clientModelId: readString('clientModelId'),
        originalModelId: readString('originalModelId')
    };
}
