fluxflow-cli 4.46.1 → 4.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,44 +0,0 @@
1
- import{c as U}from"./chunk-26BQ45XP.js";import G from"os";import{structuredPatch as V}from"diff";var R=e=>typeof e!="string"?e:e.length>12?(e+"").replace("",""):e,D=(e,o)=>{if(!e)return"";let d=/\x1B\[[0-?]*[ -/]*[@-~]/g,p=e.split(`
2
- `),c=[];if(o<=5)return e;let i=t=>t<32||t>=127&&t<160||t>=768&&t<=879||t>=7616&&t<=7679||t>=8400&&t<=8447||t>=65056&&t<=65071?0:t>=4352&&t<=4447||t>=9001&&t<=9002||t>=11904&&t<=12350||t>=12352&&t<=42191||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65040&&t<=65049||t>=65072&&t<=65135||t>=65280&&t<=65376||t>=65504&&t<=65510||t>=127744&&t<=128591||t>=128640&&t<=128767||t>=131072&&t<=262141?2:1,m=t=>{let r=t.replace(d,""),s=0;for(let l=0;l<r.length;l++){let h=r.codePointAt(l);h>65535&&l++,s+=i(h)}return s},I=(t,r)=>{let s=0,l=t.length,h=!1;for(let g=0;g<t.length;g++){if(t[g]==="\x1B"&&t[g+1]==="["&&(h=!0),h){(t[g]==="m"||t[g]>="@"&&t[g]<="~"&&t[g]!=="[")&&(h=!1);continue}let $=t.codePointAt(g);$>65535&&g++;let S=i($);if(s+S>r){l=$>65535?g-1:g;break}if(s+=S,s>=r){l=g+1;break}}return{head:t.substring(0,l),tail:t.substring(l)}};return p.forEach(t=>{if(m(t)<=o){c.push(t);return}let s=t.split(/(\s+)/),l="",h=0,g=t.match(/^(\s*)/),$=g?g[1]:"";s.forEach(S=>{if(S.length===0)return;let a=S;for(;a.length>0;){let F=m(a);if(h+F<=o){l+=a,h+=F;break}l.trim().length>0&&(c.push(l.trimEnd()),l=$.substring(0,Math.min($.length,8)),h=m(l));let n=Math.max(1,o-h);if(m(a)>n){let{head:f,tail:u}=I(a,n);c.push((l+f).trimEnd()),l=$.substring(0,Math.min($.length,8)),h=m(l),a=u}else l+=a,h+=m(a),a=""}}),(l.trimEnd().length>0||l===$)&&c.push(l.trimEnd())}),R(c.join(`
3
- `))},oe=e=>{if(!e)return 0;let o=0,d=e.match(/[\u4e00-\u9fa5\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g);d&&(o+=d.length*.55);let p=e.replace(/[\u4e00-\u9fa5\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g," "),c=p.match(/[<>/\._@#$%^&*+=`~|\\:;!?'"()\[\]{}-]+/g);c&&(o+=c.length);let i=p.split(/[\s<>/\._@#$%^&*+=`~|\\:;!?'"()\[\]{}-]+/g).filter(Boolean);return o+=i.length,Math.max(.1,o)},le=e=>e?e.match(/[\u4e00-\u9fa5\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]|\s+|[<>/\._@#$%^&*+=`~|\\:;!?'"()\[\]{}-]+|[^\s<>/\._@#$%^&*+=`~|\\:;!?'"()\[\]{}\-\u4e00-\u9fa5\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]+/g)||[e]:[],ce=e=>{if(!e&&e!==0)return"0.0k";let o=typeof e=="string"?parseFloat(e):e;return o>=1e6?`${(o/1e6).toFixed(1)}m`:o>=1e3?`${(o/1e3).toFixed(1)}k`:o.toString()},ae=(e,o=40)=>{let d=U.replaceAll("\\\\","\\");if(e=e.replace(G.homedir(),"~").replace(d,"FluxFlow").replaceAll("\\","/"),!e||e.length<=o)return R(e);let p=Math.floor((o-3)/2);return R(e.substring(0,p)+"..."+e.substring(e.length-p).replaceAll("\\","/"))},fe=e=>{let o=[],d=new Set,p=e.allowMultiple===!0||String(e.allowMultiple).toLowerCase()==="true";Object.keys(e).forEach(t=>{let r=t.match(/^(searchContent|search_content|replaceContent|replace_content|newContent|new_content|content_to_replace|content_to_add|searchBlock|search_block|newBlock|new_block)_?(\d+)?$/i);if(r){let s=r[2]?parseInt(r[2],10):1;d.add(s)}});let c=Array.from(d).sort((t,r)=>t-r),i=["searchContent","search_content","replaceContent","replace_content","content_to_replace","searchBlock","search_block"],m=["newContent","new_content","content_to_add","newBlock","new_block"],I=(t,r,s)=>{let l,h;for(let g of r){let $=t===1?[`${g}1`,g,`${g}_1`]:[`${g}${t}`,`${g}_${t}`];for(let S of $)if(e[S]!==void 0){l=e[S];break}if(l!==void 0)break}for(let g of s){let $=t===1?[`${g}1`,g,`${g}_1`]:[`${g}${t}`,`${g}_${t}`];for(let S of $)if(e[S]!==void 0){h=e[S];break}if(h!==void 0)break}return{r:l,n:h}};for(let t of c){let{r,n:s}=I(t,i,m);if(r!==void 0&&s!==void 0)o.push({replace:r,new:s});else if(r!==void 0||s!==void 0)return{error:`Mismatched replacement pair for index ${t}. Both replacement and new content must be provided.`,allowMultiple:p}}return{patchPairs:o,allowMultiple:p}},Z=e=>{if(!e)return null;let o="",d=0,p=e.length;for(;d<p;){let c=e[d];if(c==="\\"){for(;d<p&&e[d]==="\\";)d++;o+="\\\\*"}else if(c===`
4
- `)o+="(?:\\r?\\n|\\\\*n|\\\\*r|\\s*)",d++;else if(c==="\r")o+="(?:\\r|\\\\*r)?",d++;else if(c===" ")o+="(?:\\t|\\\\*t|\\s*)",d++;else if(c==='"'||c==="'"||c==="`")o.endsWith("\\\\*")||(o+="\\\\*"),o+=c,d++;else if(/[.*+?^${}()|[\]]/.test(c))o+="\\"+c,d++;else if(/\s/.test(c)){for(;d<p&&/\s/.test(e[d])&&e[d]!==`
5
- `&&e[d]!=="\r"&&e[d]!==" ";)d++;o+="\\s*"}else o+=c,d++}if(!o)return null;try{return new RegExp(o,"g")}catch{return null}},ue=(e,o,d={})=>{let p=typeof d=="boolean"?d:!!(d&&d.allowMultiple),c=e.replace(/\r\n/g,`
6
- `).replace(/\r/g,`
7
- `),i=n=>n.replace(/^```[\w]*\n?/,"").replace(/```\s*$/,"").replace(/\r\n/g,`
8
- `).replace(/\r/g,`
9
- `),m=n=>n.match(/^\s*/)[0],I=n=>{let f=n.split(`
10
- `).filter(E=>E.trim()!=="");if(f.length===0)return"";let u=m(f[0]);for(let E of f){let w=m(E);w.length<u.length&&(u=w)}return u},t=(n,f,u="")=>{if(!n||f===void 0)return n;let w=/^\t/m.test(f)?" ":" ",C=b=>b.split(`
11
- `).find(y=>y.trim()!=="")??"",L=C(f).match(/^\s*/)[0].length,x=C(n).match(/^\s*/)[0].length,k=L-x,A=(u.match(/^\s*/)||[""])[0].length;return n.split(`
12
- `).map((b,y)=>{if(b.trim()===""&&y!==0)return"";let _=b.match(/^\s*/)[0].length,T=Math.max(0,_+k);return y===0&&(T=Math.max(0,T-A)),w.repeat(T)+b.trimStart()}).join(`
13
- `)},r=[];for(let n=0;n<o.length;n++){let f=o[n],u=(f.replace||"").trim(),E=i(f.new||"");if(u.startsWith("^LINE:")&&u.endsWith("$")){let A=u.slice(6,-1).trim().split(".."),M=parseInt(A[0]),b=A[1]!==void 0?parseInt(A[1]):M;if(!isNaN(M)&&!isNaN(b)){let y=c.split(`
14
- `);if(M<1||M>y.length||b<M||b>y.length){r.push({index:n,success:!1,error:`Block ${n+1}: Line range ^LINE:${M}..${b}$ out of bounds (file has ${y.length} lines).`});continue}let T=y.slice(M-1,b).join(`
15
- `),O=0;for(let P=0;P<M-1;P++)O+=y[P].length+1;r.push({index:n,success:!0,startPos:O,firstMatchContent:T,content_to_add:E});continue}}let w=i(f.replace||"");if(w===""&&E===""){r.push({index:n,success:!1,error:`Block ${n+1}: Empty replace and add content.`});continue}let C=w.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),L=null;if(w!==""&&c.includes(w))L=new RegExp(C,"g");else{let k=w.split(`
16
- `).map(A=>A.trim()).filter(A=>A.length>0).map(A=>A.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s*"));if(k.length>0){let A=k.join("\\s*");try{L=new RegExp(A,"g")}catch{L=new RegExp(C,"g")}}else L=new RegExp(C,"g")}let x=[...c.matchAll(L)];if(x.length===0&&w!==""){let k=Z(w);k&&(x=[...c.matchAll(k)])}if(x.length===0){r.push({index:n,success:!1,error:`Block ${n+1}: Could not find match.`});continue}if(x.length>1&&!p){r.push({index:n,success:!1,error:`Block ${n+1}: Found ${x.length} matches (must be unique or use allowMultiple: true if sure).`});continue}for(let k of x)r.push({index:n,success:!0,startPos:k.index,firstMatchContent:k[0],content_to_add:E})}let s=r.filter(n=>n.success).sort((n,f)=>n.startPos-f.startPos);for(let n=0;n<s.length-1;n++){let f=s[n],u=s[n+1];f.startPos+f.firstMatchContent.length>u.startPos&&(f.success=!1,f.error=`Block ${f.index+1}: Overlaps with another block.`,u.success=!1,u.error=`Block ${u.index+1}: Overlaps with another block.`)}let l=new Map,h=c,g=0,$=0,S=r.filter(n=>n.success).sort((n,f)=>n.startPos-f.startPos);for(let n of S){let f=n.startPos,u=c.substring(0,f).split(`
17
- `).length,E=f+g,w=u+$,C=h.lastIndexOf(`
18
- `,E)+1,L=h.substring(C,E),x=t(n.content_to_add,n.firstMatchContent,L),k=h.split(`
19
- `),A=[];for(let _=Math.max(0,w-4);_<w-1;_++)A.push({num:_+1,text:k[_]});let M=n.firstMatchContent.split(`
20
- `),b=[],y=w+M.length-1;for(let _=y;_<Math.min(k.length,y+3);_++)b.push({num:_+1,text:k[_]});l.set(n,{success:!0,index:n.index,oldContent:n.firstMatchContent,newContent:x,originalStartLine:u,finalStartLine:w,contextBefore:A,contextAfter:b}),h=h.substring(0,E)+x+h.substring(E+n.firstMatchContent.length),g+=x.length-n.firstMatchContent.length,$+=x.split(`
21
- `).length-n.firstMatchContent.split(`
22
- `).length}let a=[];for(let n=0;n<o.length;n++){let f=S.filter(u=>u.index===n);if(f.length>0)for(let u of f)l.has(u)&&a.push(l.get(u));else{let u=r.find(E=>E.index===n);a.push({success:!1,error:u?u.error:`Block ${n+1}: Unknown error.`})}}let F=a.filter(n=>!n.success&&n.error&&n.error.includes("Could not find match"));if(F.length===1)F[0].error+=" (Use Line Anchor or Run tool safely if search string fails)";else if(F.length>1){let n=F[F.length-1];n.error+=`
23
- (Tip: Use Line Anchor or Run tool safely if search string fails)`}return{content:h,results:a}},he=(e,o,d,p=8,c=!1)=>{if(e===o)return"";let i=(e||"").split(/\r?\n/),m=(o||"").split(/\r?\n/),I=Math.max(i.length,m.length,1),t=Math.max(4,String(I).length),r=g=>String(g).padStart(t," "),s=`[DIFF_START]
24
- `,l="\u2550".repeat(88),h=V("","",e||"",o||"","","",{context:3});if(!h||!h.hunks||h.hunks.length===0)return"";if(h.hunks.forEach((g,$)=>{$>0&&(s+=`[UI_CONTEXT] ${l}
25
- `);let S=g.oldStart,a=g.newStart;for(let F of g.lines){let n=F[0],f=F.slice(1);n===" "?(s+=`[UI_CONTEXT] ${r(a)} |${f}
26
- `,S++,a++):n==="-"?(s+=`-${r(S)} |${f}
27
- `,S++):n==="+"&&(s+=`+${r(a)} |${f}
28
- `,a++)}}),c){let g=`[DIFF_START]
29
- `,$=s.substring(g.length),S=`[UI_CONTEXT] ${l}
30
- `,F=$.split(S).map(n=>n.split(`
31
- `).filter(u=>u.trim()!=="").length>120?`[[VERIFIED]]
32
- ${n}
33
- [[/VERIFIED]]`:n);s=g+F.join(S)}return s+="[DIFF_END]",R(s)},K=e=>{if(!e)return null;let o=e.replace("[UI_CONTEXT]","").replace(/\r/g,""),d=o.startsWith("-"),p=o.startsWith("+"),c=d||p?o.substring(1):o,i=c.indexOf("|"),m=i!==-1?R(c.substring(0,i).trim()):"",I=R(i!==-1?c.substring(i+1):c);return{isR:d,isA:p,num:m,content:I}},Y=(e,o)=>{if(!e&&!o)return 1;if(!e||!o)return 0;let d=e.length,p=o.length,c=e,i=o;d<p&&(c=o,i=e);let m=c.length,I=i.length,t=new Int32Array(I+1),r=new Int32Array(I+1);for(let h=0;h<=I;h++)t[h]=h;for(let h=1;h<=m;h++){r[0]=h;let g=c[h-1];for(let $=1;$<=I;$++)g===i[$-1]?r[$]=t[$-1]:r[$]=Math.min(t[$],r[$-1],t[$-1])+1;t.set(r)}let s=t[I],l=Math.max(d,p);return l===0?1:1-s/l},H=e=>{let o=[],d=[];e.forEach((s,l)=>{s.parsed.isR?o.push({index:l,content:s.parsed.content}):s.parsed.isA&&d.push({index:l,content:s.parsed.content})});let p=o.length,c=d.length;if(p===0||c===0)return;let i=Array.from({length:p+1},()=>Array(c+1).fill(0)),m=Array.from({length:p+1},()=>Array(c+1).fill(""));for(let s=1;s<=p;s++)m[s][0]="up";for(let s=1;s<=c;s++)m[0][s]="left";let I=Array.from({length:p},()=>Array(c).fill(0));for(let s=0;s<p;s++)for(let l=0;l<c;l++)I[s][l]=Y(o[s].content.trim(),d[l].content.trim());for(let s=1;s<=p;s++)for(let l=1;l<=c;l++){let h=I[s-1][l-1],g=h>=.2?h:-10,$=i[s-1][l-1]+g,S=i[s-1][l],a=i[s][l-1];$>=S&&$>=a?(i[s][l]=$,m[s][l]="diag"):S>=a?(i[s][l]=S,m[s][l]="up"):(i[s][l]=a,m[s][l]="left")}let t=p,r=c;for(;t>0||r>0;)if(m[t][r]==="diag"){if(I[t-1][r-1]>=.2){let l=o[t-1].index,h=d[r-1].index;e[l].pairContent=e[h].parsed.content,e[h].pairContent=e[l].parsed.content}t--,r--}else m[t][r]==="up"?t--:r--},B=new Map,W=new Map,X=200,j=5,z=(e,o)=>{o.set(e.key,e),e.type==="chunk"&&e.blocks&&e.blocks.forEach(d=>z(d,o))},de=(e,o)=>{if(!e)return{completed:[],active:[]};let d=`${e.id}-${e.text?.length||0}-${o}-${e.isStreaming}-${e.workedDuration||0}`;if(!e.isStreaming&&B.has(d))return B.get(d);let p=R(ne(e.text||"",e.role)),c=`${e.id}-${o}`,i=new Map;if(e.isStreaming){let a=W.get(c);a&&p.startsWith(a.text)&&(i=a.blocksMap)}let m=(a,F,n,f={})=>{let u=i.get(a);if(u&&u.text===n&&u.type===F&&!!u.isActiveBlock==!!f.isActiveBlock&&!!u.isStreaming==!!f.isStreaming&&u.pairContent===f.pairContent)return u;let E=R(n),w={...f};return typeof w.pairContent=="string"&&(w.pairContent=R(w.pairContent)),Array.isArray(w.wrappedLines)&&(w.wrappedLines=w.wrappedLines.map(R)),{key:a,isStreamingMsg:!!e.isStreaming,workedDuration:e.workedDuration,type:F,text:E,msg:F==="full-message"?e:void 0,...w}};if(p.includes("- Content Preview:")){let a="",F=p.match(/File\s+\[(.*?)\]/i);F&&(a=F[1].split(".").pop().toLowerCase());let w=((p.split("- Content Preview:")[1]||"").split("[SYSTEM] Check the content preview for verification [/SYSTEM]")[0]?.trim()||"").split(`
34
- `).map(b=>b.replace(/\r$/,"")),C=String(w.length).length,L=[],x=null,k=[],A=()=>{if(!k.length)return;let b=k;k=[],L.push(b.length===1?b[0]:{key:`${b[0].key}-chunk`,type:"chunk",blocks:b})},M=o-(C+6);return w.forEach((b,y)=>{let _=y===w.length-1,T=D(b,M).split(`
35
- `),O=m(`${e.id||Date.now()}-write-line-${y}`,"write-line",b,{gutterWidth:C,lineNum:y+1,isFirstLine:y===0,isLastLine:_,extension:a,wrappedLines:T});_&&e.isStreaming?(A(),x=O):(k.push(O),k.length>=j&&A())}),A(),{completed:L,active:x?[x]:[]}}if(p.includes("[DIFF_START]")){let a=p.match(/\[DIFF_START\]([\s\S]*?)(?:\[DIFF_END\]|$)/),n=(a?a[1].trim():"").split(`
36
- `).map(x=>x.replace(/\r$/,"")),f=n.map(x=>({line:x,parsed:K(x),pairContent:null})),u=[];for(let x=0;x<f.length;x++){let k=f[x];k.parsed&&(k.parsed.isR||k.parsed.isA)?u.push(k):u.length>0&&(H(u),u=[])}u.length>0&&H(u);let E=[],w=null,C=[],L=()=>{if(!C.length)return;let x=C;C=[],E.push(x.length===1?x[0]:{key:`${x[0].key}-chunk`,type:"chunk",blocks:x})};return n.forEach((x,k)=>{let A=k===n.length-1,M=f[k].parsed,b=null;M&&(b=D(M.content,o-17).split(`
37
- `));let y=m(`${e.id||Date.now()}-diff-${k}`,"diff-line",x,{isFirstLine:k===0,isLastLine:A,pairContent:f[k].pairContent,wrappedLines:b});A&&e.isStreaming?(L(),w=y):(C.push(y),C.length>=j&&L())}),L(),{completed:E,active:w?[w]:[]}}if(e.role==="system"||e.isLogo||e.isHelpRecord||e.isTerminalRecord||e.isHomeWarning||e.isImageStats||e.isAskRecord||e.isAboutRecord||e.isUpdateNotification||e.role==="user"){if(!p&&!e.isLogo&&!e.isHelpRecord&&!e.isTerminalRecord&&!e.isHomeWarning&&!e.isImageStats&&!e.isAskRecord&&!e.isAboutRecord&&!e.isUpdateNotification){let a={completed:[],active:[]};return B.set(d,a),a}return{completed:[m(`${e.id||Date.now()}-full`,"full-message",p)],active:[]}}if(!p&&!e.isStreaming){let a={completed:[],active:[]};return B.set(d,a),a}let I=[],t=null,r=[],s=null,l=()=>{if(!r.length)return;let a=r;r=[],s=null,I.push(a.length===1?a[0]:{key:`${e.id||"x"}-chunk-${a[0].key}`,type:"chunk",blocks:a})},h=(a,F=!1)=>{if(s!==null&&s!==a.type&&l(),r.push(a),s=a.type,r.length>=j){if(e.isStreaming&&F)return;l()}},g=Math.max(20,(o||80)-6),$=Math.max(20,(o||80)-8);if(e.role==="think"){I.push(m(`${e.id}-header`,"think-header","",{duration:e.duration}));let a=p.split(`
38
- `),F=[];a.forEach(n=>{D(n,$).split(`
39
- `).forEach(u=>F.push(u))}),F.forEach((n,f)=>{let u=f===F.length-1;h(m(`${e.id}-${f}`,"think-line",n,{}),u)}),e.isStreaming||(l(),I.push({key:`${e.id}-footer-padding`,type:"think-footer-padding",text:""}))}else{let a=p.split(`
40
- `),F=!1,n=[],f=!1,u="",E=0,w=0,C=[];a.forEach(L=>{let x=L.trim();x.startsWith("```")?(f=!f,C.push(L)):f||x.startsWith("|")?C.push(L):D(L,g).split(`
41
- `).forEach(A=>C.push(A))}),f=!1,C.forEach((L,x)=>{let k=x===C.length-1,A=L.trim().startsWith("|"),M=L.trim().startsWith("```");if(f)M?(f=!1,h(m(`${e.id}-code-close-${w}`,"code-fence-close","",{}),k)):(E++,h(m(`${e.id}-code-line-${x}`,"code-line",L,{lineNum:E,lang:u}),k));else if(M)f=!0,w=x,E=0,u=L.trim().replace(/^```/,"").trim(),h(m(`${e.id}-code-open-${x}`,"code-fence-open",u,{}),k);else if(A){if(F||(F=!0,n=[]),n.push(L),n.length===2){let b=n[0],y=b.split("|");y[0]!==void 0&&y[0].trim()===""&&y.shift(),y.length>0&&y[y.length-1].trim()===""&&y.pop();let _=y.map(T=>T.trim());h(m(`${e.id}-table-hdr-${x}`,"table-header",b,{colHeaders:_,colCount:_.length}),k)}else if(n.length>2){let b=L.split("|");b[0]!==void 0&&b[0].trim()===""&&b.shift(),b.length>0&&b[b.length-1].trim()===""&&b.pop();let y=b.map(P=>P.trim()),_=n[0].split("|");_[0]!==void 0&&_[0].trim()===""&&_.shift(),_.length>0&&_[_.length-1].trim()===""&&_.pop();let T=_.map(P=>P.trim()),O=Math.max(1,T.length);h(m(`${e.id}-table-row-${x}`,"table-row",L,{cells:y,colHeaders:T,colCount:O,rowIndex:n.length-3}),k)}k&&!e.isStreaming&&(l(),h(m(`${e.id}-table-end-${x}`,"table-close","",{}),!0))}else F&&(h(m(`${e.id}-table-end-${x}`,"table-close","",{}),k),F=!1,n=[]),h(m(`${e.id}-${x}`,"agent-line",L,{}),k)}),!e.isStreaming&&e.workedDuration&&(l(),I.push(m(`${e.id}-worked-duration`,"worked-duration","")))}e.isStreaming&&r.length>0?t=r.length===1?r[0]:{key:`${e.id||"x"}-chunk-active-${r[0].key}`,type:"chunk",blocks:r}:l();let S={completed:I,active:t?[t]:[]};if(e.isStreaming){let a=new Map;if(I.forEach(F=>z(F,a)),t&&z(t,a),W.set(c,{text:p,blocksMap:a}),W.size>X){let F=W.keys().next().value;W.delete(F)}}else{if(B.set(d,S),B.size>X){let a=B.keys().next().value;B.delete(a)}W.delete(c)}return S},q={},J=/(\r?\n){2}(?=\[?(?:tool:(?:functions\.)?|tool\.functions|action:(?:functions\.)?|action:|action\.functions|\s*turn\s*:))/gi,N=(e,o)=>{let d=!1,p=!1,c=0;for(;c<o;){if(e.startsWith("```",c)){d=!d,c+=3;continue}if(d){c++;continue}if(e[c]===`
42
- `){p=!1,c++;continue}e[c]==="`"&&(c===0||e[c-1]!=="\\")&&(p=!p),c++}if(d)return!0;if(p){let i=e.indexOf(`
43
- `,o),m=i===-1?e.length:i;if(e.substring(o,m).includes("`"))return!0}return!1},Q=/\[SYSTEM\][\s\S]*?\[\/SYSTEM\]|\[ANSWER\][\s\S]*?(?:\[\/ANSWER\]|$)|\[(?:TOOL|ACTION) RESULTS?\]:?\s*|\[\s*turn\s*:\s*(continue|finish)\s*\]|\[\[END\]\]|\[\s*turn\s*:?.*?$|\n\s*turn\s*:?.*?$|\[\s*(?:turn|ANSWER|TOOL|ACTION).*?$|\n\nResponded on .*|\n\n\[Prompted on: .*\]|@\[TerminalName:.*?, ProcessId:.*?\]/gm,ee=/(\$?\\?\/?\\rightarrow\$?|\$\\rightarrow\$)|(\$?\\?\/?\\leftarrow\$?|\$\\leftarrow\$)|(\$?\\?\/?\\uparrow\$?|\$\\uparrow\$)|(\$?\\?\/?\\downarrow\$?|\$\\downarrow\$)|(\$?\\?\/?\\leftrightarrow\$?|\$\\leftrightarrow\$)/gi,te=/\b(write_file|update_file|read_folder|view_file|exec_command|web_search|web_scrape|search_keyword|write_pdf|write_docx|generate_image)\b/gi,v=!1,ne=(e,o="agent")=>{if(!e)return e;let d=o===!0||o==="think",p=o===!1||o==="agent",c=e.replace(/<\|channel>thought/gi,"<think_fluxflow>").replace(/<channel\|>/gi,"</think_fluxflow>");if(d)return c.replace(/^<think_fluxflow>/gi,"").replace(/<\/think_fluxflow>$/gi,"").replace(/^\r?\n+/,"").replace(/\r?\n+$/,"");let i=c;if(c.trimStart().startsWith("ERROR: [INTERNAL CRITICAL] "))return"";p&&(i=i.replace(/<\/?think_fluxflow>/gi,(t,r,s)=>N(s,r)?t:""),i=i.replace(J,(t,r,s,l)=>!v&&N(l,s)?t:""),i&&(i.includes("[tool:")||i.includes("[action:"))&&(i=i.replace(/<(\w+)(?:[^>]*)>\s*([\s\S]*?\[(?:tool|action):[^\]]*\][\s\S]*?)\s*<\/\1>/gi,(t,r,s)=>s&&(s.includes("[tool:")||s.includes("[action:"))?s.trim():t),v&&(i=i.replace(/```(?:tool|action|yaml|function|json)?\s*\n?([\s\S]*?)\n?\```/gi,(t,r)=>r.includes("[tool:")||r.includes("[action:")?r.trim():t))));let m="tool:",I="action:";if(p&&(i.toLowerCase().includes(m)||i.toLowerCase().includes(I)))for(;;){let t=i.toLowerCase(),r=t.indexOf(m),s=t.indexOf(I),l=m,h=r;if((r===-1||s!==-1&&s<r)&&(l=I,h=s),h===-1)break;if(!v&&N(i,h)){let u=-1,E=0;for(;;){let w=t.indexOf(m,E),C=t.indexOf(I,E),L=-1,x=m;if(w===-1&&C===-1)break;if(w===-1||C!==-1&&C<w?(L=C,x=I):L=w,!N(i,L)){u=L,l=x;break}E=L+x.length}if(u===-1)break;h=u}let g=h,$=!1,S=h-1;for(;S>=0&&/\s/.test(i[S]);)S--;S>=0&&i[S]==="["&&(g=S,$=!0);let a=0,F=!1,n=null,f=h;for(;f<i.length;){let u=i[f];if(!n&&(u==="'"||u==='"'||u==="`")?n=u:n&&u===n&&i[f-1]!=="\\"&&(n=null),n||(u==="("?(a++,F=!0):u===")"&&a--),F&&a===0&&!n){let E=f;if($){let w=f+1;for(;w<i.length&&/\s/.test(i[w]);)w++;w<i.length&&i[w]==="]"&&(E=w)}i=i.substring(0,g)+i.substring(E+1);break}if(f++,f===i.length){i=i.substring(0,g);break}}}return p&&(i=i.replace(/\[\s*(?:tool|action):[a-zA-Z0-9_.]*\s*\([\s\S]*?\)\s*\]/gi,(t,r,s)=>!v&&N(s,r)?t:""),i=i.replace(/\[\s*(?:tool|action):[a-zA-Z0-9_.]*[\s\S]*$/gi,(t,r,s)=>!v&&N(s,r)?t:""),i=i.replace(/^(?:\s*=\s*["'][^"'\n]*["']|\s*[a-zA-Z0-9_]+\s*=\s*(?:["'][^"'\n]*["']|\d+|true|false))(?:\s*,\s*[a-zA-Z0-9_]+\s*=\s*(?:["'][^"'\n]*["']|\d+|true|false))*\s*\)?\]\s*/gm,(t,r,s)=>!v&&N(s,r)?t:""),i=i.replace(/(?:\r?\n|^)\s*=\s*["'][^"'\n]*["'][\s\S]*?\s*\)?\]\s*/g,(t,r,s)=>!v&&N(s,r)?t:`
44
- `)),i=i.replace(Q,""),i=i.replace(ee,t=>{let r=t.toLowerCase();return r.includes("leftrightarrow")?"\u2194":r.includes("rightarrow")?"\u2192":r.includes("leftarrow")?"\u2190":r.includes("uparrow")?"\u2191":r.includes("downarrow")?"\u2193":t}),i=i.replace(te,t=>q[t.toLowerCase()]||t),i.trim()},pe=()=>{B.clear(),W.clear()};export{R as a,D as b,oe as c,le as d,ce as e,ae as f,fe as g,ue as h,he as i,K as j,H as k,de as l,ne as m,pe as n};