import { normalizeApplyPatchToolCallsOnRequest } from '../../shared/tool-governor.js';
import { containsImageAttachment, stripHistoricalImageAttachments } from './chat-process-media.js';
import { maybeInjectPendingServerToolResultsAfterClientTools } from './chat-process-pending-tool-sync.js';
import { buildImageAttachmentMetadataWithNative } from '../../../router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.js';
export async function applyPostGovernedNormalization(options) {
    let request = {
        ...options.request,
        messages: stripHistoricalImageAttachments(options.request.messages)
    };
    request = normalizeApplyPatchToolCallsOnRequest(request);
    request = await maybeInjectPendingServerToolResultsAfterClientTools(request, options.metadata);
    if (containsImageAttachment(request.messages)) {
        request.metadata = buildImageAttachmentMetadataWithNative(request.metadata, options.originalEndpoint ?? '/v1/chat/completions');
    }
    return request;
}
