"use strict";function e(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function r(r){try{return JSON.parse(r)}catch(a){var n=r.replace(/`/g,"\\`");return n=(n=(n=function(e){return e.replace(/,\s*([}\]])/g,"$1")}(n=n.replace(/"([^"\\]*(\\.[^"\\]*)*)"/g,function(e){return e.replace(/\n/g,"\\n")}))).replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/g,function(r){return e(r)})).replace(/<explaination[\s\S]*?<\/explaination>/g,function(r){return e(r)}),JSON.parse(n)}}Object.defineProperty(exports,"__esModule",{value:!0});exports.buildAiReasoning=function(e){if(!e)return null;var r={id:null==e?void 0:e.id,reason:null==e?void 0:e.reason,gap:null==e?void 0:e.gap,score:(null==e?void 0:e.relevance_score)||(null==e?void 0:e.score)};return!(r.id||r.reason||r.gap||null!=r.score&&""!==r.score)?null:r},exports.extractReasoningFromText=function(e){if(null==e)return{text:"",aiReasoning:null,segments:[]};var r="";r="string"==typeof e?e:Array.isArray(e)?e.map(function(e){return"string"==typeof e?e:JSON.stringify(e)}).join(", "):"object"==typeof e?JSON.stringify(e):String(e);for(var n,a=/<ai_reasoning>([\s\S]*?)<\/ai_reasoning>/gi,t=null,o=[],s=0,i=function(){n.index>s&&o.push({type:"text",content:r.substring(s,n.index)});var e=n[1];e=e.replace(/`/g,"\\`").replace(/\*\*/g,"\\*\\*").replace(/__/g,"\\_\\_").replace(/#/g,"\\#").replace(/\r/g,"").replace(/\n/g,"\\n");var i=function(r){var n=e.match(new RegExp("<".concat(r,">([\\s\\S]*?)<\\/").concat(r,">"),"i"));return n?n[1].replace(/\\n/g,"\n").trim():""},c={id:i("id"),reason:i("reason"),gap:i("gap"),score:i("relevance_score")||i("score")};t||(t=c),o.push({type:"reasoning",reasoning:c}),s=a.lastIndex};null!==(n=a.exec(r));)i();s<r.length&&o.push({type:"text",content:r.substring(s)});var c=r.replace(/<ai_reasoning>[\s\S]*?<\/ai_reasoning>/gi,"").trim();return 0===o.length&&c&&o.push({type:"text",content:c}),{text:c,aiReasoning:t,segments:o}},exports.parseJsonBlocks=function(e){for(var n,a=/<!--\s*```json\s+property="([^"]+)"\s*([\s\S]*?)```\s*-->/gi,t=[];null!==(n=a.exec(e));){var o=n[0],s=n[1],i=n[2].trim();try{var c=r(i);t.push({property:s,data:c,rawMatch:o})}catch(e){var l="".concat(s,"::").concat(i.slice(0,40));console.warn('Failed to parse JSON for property="'.concat(s,'" warnId="').concat(l,'":'),e),console.warn("👉 Raw JSON string:",i),console.warn("👉 Error:"),console.warn(e),t.push({property:s,data:null,rawMatch:o})}}return t},exports.safeParse=r,exports.sanitizeBlock=e;
//# sourceMappingURL=message-rendering-utils.js.map
