fluxflow-cli 4.25.1 → 4.25.4

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.
@@ -0,0 +1,5 @@
1
+ import{screen as V}from"@nut-tree-fork/nut-js";import P from"screenshot-desktop";import Z from"sharp";import K from"fs-extra";import Q from"path";var M={TARGET_WIDTH:1280,TARGET_HEIGHT:720,COLS:40,ROWS:30},st=process.env.USE_UI_MODEL!=="false"&&!0,nt=process.env.RAW_MODEL_ONLY==="true"||!1,F=[];async function z(e,o=!1){try{let{data:b,info:T}=await Z(e).resize(M.TARGET_WIDTH,M.TARGET_HEIGHT,{fit:"fill"}).greyscale().raw().toBuffer({resolveWithObject:!0}),s=T.width,h=T.height,d=M.COLS,Y=M.ROWS,m=s/d,r=h/Y,H=[],x=1;for(let n=0;n<Y;n++)for(let c=0;c<d;c++){let u=Math.floor(c*m),p=Math.floor(n*r),w=Math.floor((c+1)*m),a=Math.floor((n+1)*r),t=Math.floor((a-p)/3),y=0,O=0,D=0,E=0,g=0,f=0;for(let W=p;W<a;W+=2)for(let S=u;S<w;S+=2){let q=b[W*s+S];W<p+t?(D+=q,E++):W>a-t?(g+=q,f++):(y+=q,O++)}let A=(D+y+g)/(E+O+f),X=0,v=0,G=0;for(let W=p;W<a;W+=2)for(let S=u;S<w;S+=2){let $=b[W*s+S]-A;W<p+t?v+=$*$:W>a-t?G+=$*$:X+=$*$}let N=Math.sqrt(X/(O||1)),I=Math.sqrt(v/(E||1)),R=Math.sqrt(G/(f||1)),_=Math.sqrt((v+X+G)/(E+O+f||1)),L=3;I>R+3?L=10:(R>I+3||N>12)&&(L=-8),_>18&&H.push({cellNum:x,cx:Math.floor(u+m/2),cy:Math.floor(p+r/2),cellW:m,cellH:r,startX:u,startY:p,yOffset:L,mean:A,stdDev:_}),x++}let i=Array.from({length:Y},()=>Array(d).fill(null));for(let n of H){let c=Math.floor((n.cellNum-1)/d),u=(n.cellNum-1)%d;i[c][u]=n}let C=Array.from({length:Y},()=>Array(d).fill(!1)),l=[];for(let n=0;n<Y;n++)for(let c=0;c<d;c++)if(i[n][c]&&!C[n][c]){let u=n,p=n,w=c,a=c,t=[[n,c]],y=[i[n][c]],O=Array.from({length:Y},()=>Array(d).fill(!1));for(O[n][c]=!0;t.length>0;){let[g,f]=t.shift();u=Math.min(u,g),p=Math.max(p,g),w=Math.min(w,f),a=Math.max(a,f);let A=[[g-1,f],[g+1,f],[g,f-1],[g,f+1],[g-1,f-1],[g-1,f+1],[g+1,f-1],[g+1,f+1]];for(let[X,v]of A)X>=0&&X<Y&&v>=0&&v<d&&i[X][v]&&!O[X][v]&&(O[X][v]=!0,t.push([X,v]),y.push(i[X][v]))}let D=p-u+1,E=a-w+1;if(D<=4&&E<=4){for(let I of y){let R=Math.floor((I.cellNum-1)/d),_=(I.cellNum-1)%d;C[R][_]=!0}let g=Math.floor(w*m),f=Math.floor(u*r),A=Math.floor((a+1)*m),X=Math.floor((p+1)*r),v=A-g,G=X-f,N=3;if(G>r){let I=y.filter(W=>W.startY<f+G/2),R=y.filter(W=>W.startY>=f+G/2),_=I.reduce((W,S)=>W+S.stdDev,0)/(I.length||1),L=R.reduce((W,S)=>W+S.stdDev,0)/(R.length||1);L>_+2?N=-Math.floor(G/4):_>L+2?N=Math.floor(G/4):N=-12}else N=(y.find(R=>R.yOffset!==3)||y[0]).yOffset;l.push({cellNum:y[0].cellNum,cx:Math.floor(g+v/2),cy:Math.floor(f+G/2),cellW:v,cellH:G,startX:g,startY:f,yOffset:N})}else{C[n][c]=!0;let g=i[n][c],f=n+1<Y?i[n+1][c]:null;if(f&&!C[n+1][c]){C[n+1][c]=!0;let A=Math.floor(c*m),X=Math.floor(n*r),v=Math.floor((c+1)*m),G=Math.floor((n+2)*r),N=v-A,I=G-X,R=Math.floor(r*.25),_=Math.floor(X+r-R),L=Math.floor(X+r+R),W=0,S=0;for(let B=_;B<L;B+=2)for(let k=A;k<v;k+=2)W+=b[B*s+k],S++;let q=W/(S||1),$=0;for(let B=_;B<L;B+=2)for(let k=A;k<v;k+=2){let J=b[B*s+k]-q;$+=J*J}let ot=Math.sqrt($/(S||1)),U;if(ot<14)U=Math.floor(X+r)+4;else{let B=g.stdDev||0,k=f.stdDev||0;B<k?U=Math.floor(X+r/2)+(g.yOffset!==3?g.yOffset:-4):U=Math.floor(X+r+r/2)+(f.yOffset!==3?f.yOffset:4)}U=Math.max(X+11,Math.min(X+I-2,U)),l.push({cellNum:g.cellNum,cx:Math.floor(A+N/2),cy:U,cellW:N,cellH:I,startX:A,startY:X,yOffset:0,isCustomY:!0})}else l.push(g)}}if(o){let n=[],c=l.filter(w=>w.isCustomY||w.cellH>r*1.5),u=l.filter(w=>!(w.isCustomY||w.cellH>r*1.5)),p=new Map;for(let w of c){let a=w.startY;p.has(a)||p.set(a,[]),p.get(a).push(w)}for(let[w,a]of p.entries()){a.sort((y,O)=>y.startX-O.startX);let t=[];for(let y=0;y<a.length;y++){let O=a[y];if(t.length===0)t.push(O);else{let D=t[t.length-1];if(Math.abs(D.startX+D.cellW-O.startX)<=3)t.push(O);else{if(t.length>=3){let E=t[0].startX,f=t[t.length-1].startX+t[t.length-1].cellW-E,A=t[0].cellH;n.push({cellNum:t[0].cellNum,cx:Math.floor(E+f/2),cy:t[0].cy,cellW:f,cellH:A,startX:E,startY:w,yOffset:0,isCustomY:!0})}else n.push(...t);t=[O]}}}if(t.length>=3){let y=t[0].startX,D=t[t.length-1].startX+t[t.length-1].cellW-y,E=t[0].cellH;n.push({cellNum:t[0].cellNum,cx:Math.floor(y+D/2),cy:t[0].cy,cellW:D,cellH:E,startX:y,startY:w,yOffset:0,isCustomY:!0})}else n.push(...t)}l.length=0,l.push(...n,...u)}return l.forEach((n,c)=>{n.badgeId=c+1}),F=l,l}catch(b){return console.error("UI Element Detection error:",b),[]}}function rt(e,o,b,T,s=[]){let h=e/b,d=o/T,Y="";for(let m of s){let{badgeId:r,cellNum:H,startX:x,startY:i,cellW:C,cellH:l,cx:n,cy:c}=m,u=r!==void 0?r:H;Y+=`
2
+ <rect x="${x+1}" y="${i+1}" width="${C-2}" height="${l-2}" fill="rgba(0, 255, 255, 0.015)" stroke="rgba(255, 255, 0, 0.3)" stroke-width="1.1" rx="2"/>
3
+ `;let p=s.some(t=>t!==m&&t.startY+t.cellH>=i-6&&t.startY<i&&Math.max(0,Math.min(x+C,t.startX+t.cellW)-Math.max(x,t.startX))>10),w=s.some(t=>t!==m&&t.startY<=i+l+6&&t.startY>i&&Math.max(0,Math.min(x+C,t.startX+t.cellW)-Math.max(x,t.startX))>10),a;if(m.isCustomY)a=c,!p&&a<i+11&&(a=Math.max(10,Math.min(a,i+4)));else{let t=m.yOffset!==void 0?m.yOffset:3;!p&&t<0&&(t=Math.min(t,-12));let y=c+t,O=!p&&(t<0||y<i+11)?Math.max(10,i+4):i+11,D=!w&&(t>0||y>i+l-2)?Math.min(o-2,i+l+6):i+l+3;a=Math.max(O,Math.min(D,y))}Y+=`
4
+ <text x="${n}" y="${a}" font-family="'Segoe UI', Roboto, sans-serif" font-size="14" font-weight="600" fill="#FFFF00" stroke="#000000" stroke-width="2" paint-order="stroke fill" stroke-linejoin="round" opacity="0.8" text-anchor="middle">${u}</text>
5
+ `}return`<svg width="${e}" height="${o}" xmlns="http://www.w3.org/2000/svg">${Y}</svg>`}var tt=1,j=e=>new Promise(o=>setTimeout(o,e));async function et(){try{let{loadSettings:e}=await import("./settings-KKYNW25D.js"),o=await e();return Number(o.display||0)}catch{return 0}}async function lt(){let e=await et();try{let o=await P.listDisplays();if(o&&o.length>0)return{format:"png",screen:(o[e]||o[0]).id}}catch{}return{format:"png"}}async function ct(){let e=0,o=await lt();for(;e<2;){let b=await P(o);await j(500);let T=await P(o);if(b.equals(T))return T;e++,e<2&&await j(3e3)}return await j(3e3),await P(o)}function at(e=[],o=[]){if(!e||e.length===0)return o||[];if(!o||o.length===0)return e;let b=[...e],T=typeof e.getModelConfidence=="function"?e.getModelConfidence.bind(e):null;for(let s of o){if(T&&T(s.startX,s.startY,s.cellW,s.cellH)<.01)continue;let h=s.startX,d=s.startX+s.cellW,Y=s.startY,m=s.startY+s.cellH;for(let u of e){let p=u.startX,w=u.startY,a=u.startX+u.cellW,t=u.startY+u.cellH;if(Math.max(0,Math.min(m,t)-Math.max(Y,w))>s.cellH*.4&&p<d&&a>h){let O=(p+a)/2,D=(h+d)/2;O<=D?h=Math.max(h,a):d=Math.min(d,p)}}let r=d-h;if(r<18)continue;let H=h,x=Y,i=d,C=m,l=Math.floor(h+r/2),n=s.cy,c=!1;for(let u of e){let p=u.startX,w=u.startY,a=u.startX+u.cellW,t=u.startY+u.cellH;if(l>=p&&l<=a&&n>=w&&n<=t){c=!0;break}let y=Math.max(H,p),O=Math.max(x,w),D=Math.min(i,a),E=Math.min(C,t),g=Math.max(0,D-y)*Math.max(0,E-O),f=(i-H)*(C-x);if(g/(f||1)>=.25){c=!0;break}}c||b.push({...s,startX:H,cellW:r,cx:l})}return b.sort((s,h)=>Math.abs(s.startY-h.startY)>18?s.startY-h.startY:s.startX-h.startX),b.forEach((s,h)=>{s.badgeId=h+1}),b}async function pt(){try{let e=await ct(),o=null;if(st){let m=(async()=>{try{let{detectUIBoxesONNX:r}=await import("./ui_detector_onnx-YGGFMOK5.js");return await r(e,M.TARGET_WIDTH,M.TARGET_HEIGHT)}catch{return null}})();if(nt)o=await m||[];else{let r=z(e,!0),[H,x]=await Promise.all([m,r]);o=H&&H.length>0?at(H,x):await z(e,!1)}}else o=await z(e,!1);F=o;let b=rt(M.TARGET_WIDTH,M.TARGET_HEIGHT,M.COLS,M.ROWS,o),T=await Z(e).resize(M.TARGET_WIDTH,M.TARGET_HEIGHT,{fit:"fill"}).composite([{input:Buffer.from(b),top:0,left:0}]).png({quality:100}).toBuffer();if(process.env.SHOW_DEBUG_GRID)try{let m=Q.resolve(process.cwd(),"screenshots");await K.ensureDir(m);let r=Q.join(m,`${tt}.png`);await K.writeFile(r,T),tt++}catch{}let s=T.toString("base64"),h=o.length,d=e,Y=T;return d=null,Y=null,{base64:s,mimeType:"image/png",width:M.TARGET_WIDTH,height:M.TARGET_HEIGHT,detectedCount:h}}catch(e){return console.error("Failed to capture gridded screenshot:",e),null}}function it(e){if(e==null)return null;let o=null;if(typeof e=="number")o=e;else if(typeof e=="string"){let H=e.trim();if(/^\d+$/.test(H))o=parseInt(H,10);else{let x=H.match(/^([A-Z])([0-9]{1,2})$/i);if(x){let i=x[1].toUpperCase().charCodeAt(0)-65,C=parseInt(x[2],10)-1;o=i*M.COLS+C+1}}}if(o===null||isNaN(o))return null;if(F&&F.length>0){let H=F.find(x=>x.badgeId===o)||F.find(x=>x.cellNum===o);if(H){let x=Math.floor((H.cellNum-1)%M.COLS),i=Math.floor((H.cellNum-1)/M.COLS);return{x:H.cx,y:H.cy,colIdx:x>=0?x:0,rowIdx:i>=0?i:0,cellNum:o}}}let b=M.COLS*M.ROWS;if(o<1||o>b)return null;let T=o-1,s=Math.floor(T/M.COLS),h=T%M.COLS,d=M.TARGET_WIDTH/M.COLS,Y=M.TARGET_HEIGHT/M.ROWS,m=Math.floor(h*d+d/2),r=Math.floor(s*Y+Y/2);return{x:m,y:r,colIdx:h,rowIdx:s,cellNum:o}}async function yt(e,o,b){let T=null;if(typeof e=="number"||typeof e=="string"?T=it(e):e&&typeof e.x=="number"&&typeof e.y=="number"&&(T=e),!T)return null;let s=o,h=b,d=0,Y=0,m=await et();try{let C=await P.listDisplays();if(C&&C.length>0){let l=C[m]||C[0];l.width&&l.height&&(s=l.width,h=l.height),l.left!==void 0&&(d=l.left),l.top!==void 0&&(Y=l.top)}}catch{}if(!s||!h)try{let C=await P({}),l=await Z(C).metadata();l&&l.width&&l.height?(s=l.width,h=l.height):(s=await V.width(),h=await V.height())}catch{(!s||!h)&&(s=await V.width(),h=await V.height())}let r=s/M.TARGET_WIDTH,H=h/M.TARGET_HEIGHT,x=Math.round(T.x*r)+d,i=Math.round(T.y*H)+Y;return{x,y:i,screenW:s,screenH:h,offsetX:d,offsetY:Y}}export{M as a,st as b,nt as c,et as d,pt as e,it as f,yt as g};
@@ -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};
@@ -1 +1 @@
1
- import{g as f}from"./chunk-A73HW6DI.js";import{mouse as c,keyboard as i,Button as u,Key as e,Point as l,clipboard as g}from"@nut-tree-fork/nut-js";c.config.autoDelayMs=50;i.config.autoDelayMs=50;async function w(){try{await i.releaseKey(e.LeftControl,e.RightControl,e.LeftAlt,e.RightAlt,e.LeftShift,e.RightShift,e.LeftSuper,e.RightSuper)}catch{}}async function h(n,t,s={}){let r=await f(t);if(!r&&(n==="move"||n==="click"||n==="drag"))return`ERROR: Invalid target location specified: ${JSON.stringify(t)}`;try{switch(n.toLowerCase()){case"move":return await c.setPosition(new l(r.x,r.y)),`Moved mouse to grid target ${typeof t=="string"?t:`(${r.x}, ${r.y})`}`;case"click":{await c.setPosition(new l(r.x,r.y));let a=s.button==="right"?u.RIGHT:s.button==="middle"?u.MIDDLE:u.LEFT;return s.clickType==="double"?await c.doubleClick(a):await c.click(a),`${s.clickType||"Single"} clicked ${s.button||"left"} button at ${typeof t=="string"?t:`(${r.x}, ${r.y})`}`}case"drag":{let a=await f(s.from||t),o=await f(s.to);return!a||!o?'ERROR: Drag requires valid "from" and "to" target coordinates/grid codes.':(await c.setPosition(new l(a.x,a.y)),await c.pressButton(u.LEFT),await c.setPosition(new l(o.x,o.y)),await c.releaseButton(u.LEFT),`Dragged mouse from (${a.x}, ${a.y}) to (${o.x}, ${o.y})`)}case"scroll":{let a=r||await f({x:640,y:360});a&&(await c.setPosition(new l(a.x,a.y)),await new Promise(d=>setTimeout(d,60)));let o=parseInt(s.amount,10);(isNaN(o)||o<=0)&&(o=5);let y=o>50?Math.min(20,Math.max(1,Math.round(o/100))):Math.min(20,o),R=s.direction==="up";for(let d=0;d<y;d++)R?await c.scrollUp(120):await c.scrollDown(120),await new Promise(L=>setTimeout(L,20));return`Scrolled ${s.direction||"down"} (${y} notches${r?` at target (${r.x}, ${r.y})`:" at screen center"})`}default:return`ERROR: Unsupported mouse action "${n}"`}}catch(a){return`ERROR: Mouse action failed: ${a.message}`}}var m={enter:e.Enter,return:e.Return,escape:e.Escape,esc:e.Escape,backspace:e.Backspace,tab:e.Tab,space:e.Space,up:e.Up,down:e.Down,left:e.Left,right:e.Right,ctrl:e.LeftControl,control:e.LeftControl,alt:e.LeftAlt,shift:e.LeftShift,cmd:e.LeftCmd,win:e.LeftWin,meta:e.LeftWin,super:e.LeftSuper,a:e.A,b:e.B,c:e.C,d:e.D,e:e.E,f:e.F,g:e.G,h:e.H,i:e.I,j:e.J,k:e.K,l:e.L,m:e.M,n:e.N,o:e.O,p:e.P,q:e.Q,r:e.R,s:e.S,t:e.T,u:e.U,v:e.V,w:e.W,x:e.X,y:e.Y,z:e.Z,0:e.Num0,1:e.Num1,2:e.Num2,3:e.Num3,4:e.Num4,5:e.Num5,6:e.Num6,7:e.Num7,8:e.Num8,9:e.Num9,f1:e.F1,f2:e.F2,f3:e.F3,f4:e.F4,f5:e.F5,f6:e.F6,f7:e.F7,f8:e.F8,f9:e.F9,f10:e.F10,f11:e.F11,f12:e.F12},p=n=>{if(!n)return;let t=String(n).toLowerCase().trim();if(m[t]!==void 0)return m[t];if(e[n]!==void 0)return e[n];if(e[t.toUpperCase()]!==void 0)return e[t.toUpperCase()]};async function E(n,t,s={}){try{switch(n.toLowerCase()){case"type":{if(typeof t!="string")return"ERROR: Type action requires a valid string input";await w(),await g.setContent(t);let a=process.platform==="darwin"?e.LeftSuper:e.LeftControl;return await i.pressKey(a,e.V),await i.releaseKey(a,e.V),await w(),s.autoPressEnter?(await new Promise(o=>setTimeout(o,50)),await i.type(e.Enter),`Typed text input ("${t.length>20?t.substring(0,20)+"...":t}") and pressed Enter`):`Typed text input ("${t.length>20?t.substring(0,20)+"...":t}")`}case"key_press":{let r=p(t);return r===void 0?`ERROR: Unknown key name "${t}"`:(await i.type(r),`Pressed key ${t}`)}case"key_combination":{if(!Array.isArray(t))return'ERROR: key_combination requires an array of keys (e.g. ["ctrl", "c"])';let r=t.map(a=>p(a)).filter(a=>a!==void 0);return r.length===0?"ERROR: Invalid key combination":(await i.pressKey(...r),await i.releaseKey(...r),`Executed key combination [${t.join(" + ")}]`)}case"clear_input":return await i.pressKey(e.LeftControl,e.A),await i.releaseKey(e.LeftControl,e.A),await i.type(e.Backspace),"Cleared active text input (Select All + Backspace)";case"browser_back":{let r=process.platform==="darwin";return r?(await i.pressKey(e.LeftSuper,e.Left),await i.releaseKey(e.LeftSuper,e.Left)):(await i.pressKey(e.LeftAlt,e.Left),await i.releaseKey(e.LeftAlt,e.Left)),await w(),`Browser back navigation (${r?"Cmd+Left":"Alt+Left"})`}default:return`ERROR: Unsupported keyboard action "${n}"`}}catch(r){return`ERROR: Keyboard action failed: ${r.message}`}}export{h as a,E as b};
1
+ import{g as f}from"./chunk-2AUIP6N5.js";import{mouse as c,keyboard as i,Button as u,Key as e,Point as l,clipboard as g}from"@nut-tree-fork/nut-js";c.config.autoDelayMs=50;i.config.autoDelayMs=50;async function w(){try{await i.releaseKey(e.LeftControl,e.RightControl,e.LeftAlt,e.RightAlt,e.LeftShift,e.RightShift,e.LeftSuper,e.RightSuper)}catch{}}async function h(n,t,s={}){let r=await f(t);if(!r&&(n==="move"||n==="click"||n==="drag"))return`ERROR: Invalid target location specified: ${JSON.stringify(t)}`;try{switch(n.toLowerCase()){case"move":return await c.setPosition(new l(r.x,r.y)),`Moved mouse to grid target ${typeof t=="string"?t:`(${r.x}, ${r.y})`}`;case"click":{await c.setPosition(new l(r.x,r.y));let a=s.button==="right"?u.RIGHT:s.button==="middle"?u.MIDDLE:u.LEFT;return s.clickType==="double"?await c.doubleClick(a):await c.click(a),`${s.clickType||"Single"} clicked ${s.button||"left"} button at ${typeof t=="string"?t:`(${r.x}, ${r.y})`}`}case"drag":{let a=await f(s.from||t),o=await f(s.to);return!a||!o?'ERROR: Drag requires valid "from" and "to" target coordinates/grid codes.':(await c.setPosition(new l(a.x,a.y)),await c.pressButton(u.LEFT),await c.setPosition(new l(o.x,o.y)),await c.releaseButton(u.LEFT),`Dragged mouse from (${a.x}, ${a.y}) to (${o.x}, ${o.y})`)}case"scroll":{let a=r||await f({x:640,y:360});a&&(await c.setPosition(new l(a.x,a.y)),await new Promise(d=>setTimeout(d,60)));let o=parseInt(s.amount,10);(isNaN(o)||o<=0)&&(o=5);let y=o>50?Math.min(20,Math.max(1,Math.round(o/100))):Math.min(20,o),R=s.direction==="up";for(let d=0;d<y;d++)R?await c.scrollUp(120):await c.scrollDown(120),await new Promise(L=>setTimeout(L,20));return`Scrolled ${s.direction||"down"} (${y} notches${r?` at target (${r.x}, ${r.y})`:" at screen center"})`}default:return`ERROR: Unsupported mouse action "${n}"`}}catch(a){return`ERROR: Mouse action failed: ${a.message}`}}var m={enter:e.Enter,return:e.Return,escape:e.Escape,esc:e.Escape,backspace:e.Backspace,tab:e.Tab,space:e.Space,up:e.Up,down:e.Down,left:e.Left,right:e.Right,ctrl:e.LeftControl,control:e.LeftControl,alt:e.LeftAlt,shift:e.LeftShift,cmd:e.LeftCmd,win:e.LeftWin,meta:e.LeftWin,super:e.LeftSuper,a:e.A,b:e.B,c:e.C,d:e.D,e:e.E,f:e.F,g:e.G,h:e.H,i:e.I,j:e.J,k:e.K,l:e.L,m:e.M,n:e.N,o:e.O,p:e.P,q:e.Q,r:e.R,s:e.S,t:e.T,u:e.U,v:e.V,w:e.W,x:e.X,y:e.Y,z:e.Z,0:e.Num0,1:e.Num1,2:e.Num2,3:e.Num3,4:e.Num4,5:e.Num5,6:e.Num6,7:e.Num7,8:e.Num8,9:e.Num9,f1:e.F1,f2:e.F2,f3:e.F3,f4:e.F4,f5:e.F5,f6:e.F6,f7:e.F7,f8:e.F8,f9:e.F9,f10:e.F10,f11:e.F11,f12:e.F12},p=n=>{if(!n)return;let t=String(n).toLowerCase().trim();if(m[t]!==void 0)return m[t];if(e[n]!==void 0)return e[n];if(e[t.toUpperCase()]!==void 0)return e[t.toUpperCase()]};async function E(n,t,s={}){try{switch(n.toLowerCase()){case"type":{if(typeof t!="string")return"ERROR: Type action requires a valid string input";await w(),await g.setContent(t);let a=process.platform==="darwin"?e.LeftSuper:e.LeftControl;return await i.pressKey(a,e.V),await i.releaseKey(a,e.V),await w(),s.autoPressEnter?(await new Promise(o=>setTimeout(o,50)),await i.type(e.Enter),`Typed text input ("${t.length>20?t.substring(0,20)+"...":t}") and pressed Enter`):`Typed text input ("${t.length>20?t.substring(0,20)+"...":t}")`}case"key_press":{let r=p(t);return r===void 0?`ERROR: Unknown key name "${t}"`:(await i.type(r),`Pressed key ${t}`)}case"key_combination":{if(!Array.isArray(t))return'ERROR: key_combination requires an array of keys (e.g. ["ctrl", "c"])';let r=t.map(a=>p(a)).filter(a=>a!==void 0);return r.length===0?"ERROR: Invalid key combination":(await i.pressKey(...r),await i.releaseKey(...r),`Executed key combination [${t.join(" + ")}]`)}case"clear_input":return await i.pressKey(e.LeftControl,e.A),await i.releaseKey(e.LeftControl,e.A),await i.type(e.Backspace),"Cleared active text input (Select All + Backspace)";case"browser_back":{let r=process.platform==="darwin";return r?(await i.pressKey(e.LeftSuper,e.Left),await i.releaseKey(e.LeftSuper,e.Left)):(await i.pressKey(e.LeftAlt,e.Left),await i.releaseKey(e.LeftAlt,e.Left)),await w(),`Browser back navigation (${r?"Cmd+Left":"Alt+Left"})`}default:return`ERROR: Unsupported keyboard action "${n}"`}}catch(r){return`ERROR: Keyboard action failed: ${r.message}`}}export{h as a,E as b};