fluxflow-cli 4.25.0 → 4.25.2

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