import { mapOpenaiChatFromChatWithNative, mapOpenaiChatToChatWithNative } from '../../../../router/virtual-router/engine-selection/native-hub-pipeline-semantic-mappers.js';
export function maybeAugmentApplyPatchErrorContent(content, toolName) {
    if (!content)
        return content;
    const lower = content.toLowerCase();
    const isApplyPatch = (typeof toolName === 'string' && toolName.trim() === 'apply_patch') ||
        lower.includes('apply_patch verification failed') ||
        lower.includes('failed to apply patch');
    if (!isApplyPatch) {
        return content;
    }
    if (content.includes('[apply_patch hint]') || content.includes('[RouteCodex hint] apply_patch')) {
        return content;
    }
    const sandboxSignal = lower.includes('sandbox(signal(9))') || (lower.includes('sandbox') && lower.includes('signal(9)'));
    if (sandboxSignal) {
        return content +
            '\n\n[RouteCodex hint] apply_patch \u88ab sandbox \u7ec8\u6b62 (Signal 9)\u3002\u5e38\u89c1\u539f\u56e0\u662f\u8865\u4e01\u6d89\u53ca workspace \u4e4b\u5916\u7684\u8def\u5f84\u3002\u8bf7\u6539\u7528\u5f53\u524d workspace \u5185\u8def\u5f84\uff0c\u6216\u5c06\u76ee\u6807\u4ed3\u52a0\u5165 workspaces/workdir \u540e\u518d\u8c03\u7528 apply_patch\u3002';
    }
    const missingPath = lower.includes('failed to read file to update') ||
        lower.includes('no such file or directory');
    if (missingPath) {
        return content +
            '\n\n[RouteCodex hint] apply_patch \u8bfb\u53d6\u76ee\u6807\u6587\u4ef6\u5931\u8d25\uff1a\u8def\u5f84\u4e0d\u5b58\u5728\u6216\u4e0d\u5728\u5f53\u524d workspace\u3002\u8bf7\u786e\u8ba4\u8def\u5f84\u5728\u5f53\u524d workspace \u5185\u4e14\u6587\u4ef6\u771f\u5b9e\u5b58\u5728\uff1b\u8def\u5f84\u5fc5\u987b\u4e3a workspace \u76f8\u5bf9\u8def\u5f84\uff08\u5982 src/...\uff09\uff0c\u4e0d\u8981\u4ee5 / \u6216\u76d8\u7b26\u5f00\u5934\u3002\u5fc5\u8981\u65f6\u5207\u6362 workspace/workdir\u3002';
    }
    return content +
        '\n\n[apply_patch hint] \u5728\u4f7f\u7528 apply_patch \u4e4b\u524d\uff0c\u8bf7\u5148\u8bfb\u53d6\u76ee\u6807\u6587\u4ef6\u7684\u6700\u65b0\u5185\u5bb9\uff0c\u5e76\u57fa\u4e8e\u8be5\u5185\u5bb9\u751f\u6210\u8865\u4e01\uff1b\u540c\u65f6\u786e\u4fdd\u8865\u4e01\u683c\u5f0f\u7b26\u5408\u5de5\u5177\u89c4\u8303\uff08\u7edf\u4e00\u8865\u4e01\u683c\u5f0f\u6216\u7ed3\u6784\u5316\u53c2\u6570\uff09\uff0c\u907f\u514d\u4e0a\u4e0b\u6587\u4e0d\u5339\u914d\u6216\u8bed\u6cd5\u9519\u8bef\u3002';
}
export class ChatSemanticMapper {
    async toChat(format, ctx) {
        return mapOpenaiChatToChatWithNative((format.payload ?? {}), ctx);
    }
    async fromChat(chat, ctx) {
        return mapOpenaiChatFromChatWithNative(chat, ctx);
    }
}
