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