export function applyAutoThinking(payload, config) {
    if (!config) {
        return payload;
    }
    const record = payload;
    const modelId = typeof record.model === 'string' ? record.model.toLowerCase().trim() : '';
    if (!modelId) {
        return payload;
    }
    const prefixes = config.modelPrefixes ?? [];
    const exclude = config.excludePrefixes ?? [];
    const matches = prefixes.length === 0
        ? true
        : prefixes.some(prefix => modelId.startsWith(prefix.toLowerCase()));
    const excluded = exclude.some(prefix => modelId.startsWith(prefix.toLowerCase()));
    if (!matches || excluded) {
        return payload;
    }
    const thinkingNode = record.thinking;
    if (thinkingNode && typeof thinkingNode === 'object') {
        return payload;
    }
    record.thinking = { type: 'enabled' };
    return payload;
}
