import { buildBridgeHistoryWithNative, coerceBridgeRoleWithNative, convertBridgeInputToChatMessagesWithNative, ensureMessagesArrayWithNative, serializeToolArgumentsWithNative, serializeToolOutputWithNative } from '../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
function assertBridgeMessageUtilsNativeAvailable() {
    if (typeof buildBridgeHistoryWithNative !== 'function' ||
        typeof convertBridgeInputToChatMessagesWithNative !== 'function' ||
        typeof coerceBridgeRoleWithNative !== 'function' ||
        typeof serializeToolArgumentsWithNative !== 'function' ||
        typeof serializeToolOutputWithNative !== 'function' ||
        typeof ensureMessagesArrayWithNative !== 'function') {
        throw new Error('[bridge-message-utils] native bindings unavailable');
    }
}
export function coerceBridgeRole(role) {
    assertBridgeMessageUtilsNativeAvailable();
    return coerceBridgeRoleWithNative(role);
}
export function serializeToolArguments(argsStringOrObj, _functionName, _tools) {
    assertBridgeMessageUtilsNativeAvailable();
    return serializeToolArgumentsWithNative({ args: argsStringOrObj });
}
export function serializeToolOutput(entry) {
    assertBridgeMessageUtilsNativeAvailable();
    return serializeToolOutputWithNative({ output: entry?.output });
}
export function convertMessagesToBridgeInput(options) {
    assertBridgeMessageUtilsNativeAvailable();
    const { messages, tools } = options;
    const native = buildBridgeHistoryWithNative({ messages, tools });
    return native;
}
export function convertBridgeInputToChatMessages(options) {
    assertBridgeMessageUtilsNativeAvailable();
    const { input, tools, normalizeFunctionName, toolResultFallbackText } = options;
    const output = convertBridgeInputToChatMessagesWithNative({
        input: Array.isArray(input) ? input : [],
        tools,
        toolResultFallbackText,
        normalizeFunctionName: typeof normalizeFunctionName === 'string' ? normalizeFunctionName : undefined
    });
    return output.messages;
}
export function ensureMessagesArray(state) {
    assertBridgeMessageUtilsNativeAvailable();
    const output = ensureMessagesArrayWithNative({ state });
    return output.messages;
}
