/**
 * ThoughtSignature Validator
 *
 * 提供严格的 thoughtSignature 验证功能，用于 Claude/Gemini thinking 块的签名验证。
 * 参考 gcli2api 的实现，确保与上游 API 的兼容性。
 */
import { filterInvalidThinkingBlocksWithNative, hasValidThoughtSignatureWithNative, removeTrailingUnsignedThinkingBlocksWithNative, sanitizeThinkingBlockWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
function assertThoughtSignatureValidatorNativeAvailable() {
    if (typeof hasValidThoughtSignatureWithNative !== 'function' ||
        typeof sanitizeThinkingBlockWithNative !== 'function' ||
        typeof filterInvalidThinkingBlocksWithNative !== 'function' ||
        typeof removeTrailingUnsignedThinkingBlocksWithNative !== 'function') {
        throw new Error('[thought-signature-validator] native bindings unavailable');
    }
}
/**
 * 检查 thinking 块是否有有效的 thoughtSignature
 *
 * @param block - thinking 块对象
 * @param options - 验证选项
 * @returns 是否有效
 */
export function hasValidThoughtSignature(block, options) {
    assertThoughtSignatureValidatorNativeAvailable();
    return hasValidThoughtSignatureWithNative(block, options);
}
/**
 * 清理 thinking 块，移除额外字段，保留有效签名
 *
 * @param block - thinking 块对象
 * @returns 清理后的块
 */
export function sanitizeThinkingBlock(block) {
    assertThoughtSignatureValidatorNativeAvailable();
    return sanitizeThinkingBlockWithNative(block);
}
/**
 * 过滤消息中的无效 thinking 块
 *
 * @param messages - Anthropic messages 列表（会被修改）
 * @param options - 验证选项
 */
export function filterInvalidThinkingBlocks(messages, options) {
    assertThoughtSignatureValidatorNativeAvailable();
    const normalized = filterInvalidThinkingBlocksWithNative(messages, options);
    messages.splice(0, messages.length, ...normalized);
}
/**
 * 移除末尾未签名的 thinking 块
 *
 * @param blocks - content blocks 列表（会被修改）
 * @param options - 验证选项
 */
export function removeTrailingUnsignedThinkingBlocks(blocks, options) {
    assertThoughtSignatureValidatorNativeAvailable();
    const normalized = removeTrailingUnsignedThinkingBlocksWithNative(blocks, options);
    blocks.splice(0, blocks.length, ...normalized);
}
