openmagic 0.33.7 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var OpenMagicToolbar=(()=>{var
|
|
2
|
+
"use strict";var OpenMagicToolbar=(()=>{var Pe=`
|
|
3
3
|
:host {
|
|
4
4
|
all: initial;
|
|
5
5
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
@@ -372,48 +372,48 @@
|
|
|
372
372
|
.om-msg:hover .om-copy-btn { opacity: 1; }
|
|
373
373
|
.om-copy-btn:hover { color: #ccc; background: rgba(0,0,0,0.5); }
|
|
374
374
|
.om-msg { position: relative; }
|
|
375
|
-
`;var
|
|
375
|
+
`;var j=null,O=new Map,ne=[],xe=[],Z=!1,_e=!1,ye=null,be=0;function ve(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function we(t,e){return _e=!0,new Promise((s,o)=>{let a=!1,l=setTimeout(()=>{a||(a=!0,o(new Error("Handshake timeout")),j?.close())},1e4);try{let r=window.location.hostname||"127.0.0.1",p=window.location.protocol==="https:"?"wss:":"ws:";j=new WebSocket(`${p}//${r}:${t}/__openmagic__/ws`),j.onopen=()=>{let c=ve();j.send(JSON.stringify({id:c,type:"handshake",payload:{token:e}})),O.set(c,m=>{if(m.type==="handshake.ok"){clearTimeout(l),Z=!0,be=0;for(let u of xe)j?.send(u);xe=[],a||(a=!0,s())}else m.type==="error"&&(clearTimeout(l),a||(a=!0,o(new Error(m.payload?.message||"Handshake failed"))))})},j.onmessage=c=>{try{let m=JSON.parse(c.data);m.id&&O.has(m.id)&&(O.get(m.id)(m),(m.type==="llm.done"||m.type==="llm.error"||!m.type.startsWith("llm."))&&O.delete(m.id));for(let u of ne)u(m)}catch{}},j.onclose=()=>{let c=Z;if(Z=!1,O.forEach((m,u)=>{m({type:"error",id:u,payload:{message:"Connection lost"}})}),O.clear(),!c&&!a){clearTimeout(l),a=!0,o(new Error("WebSocket closed before handshake"));return}if(c&&_e&&!ye){let m=Math.min(2e3*Math.pow(1.5,be),3e4);be++,ye=setTimeout(()=>{ye=null,we(t,e).then(()=>{for(let u of ne)u({type:"reconnected",payload:{}})}).catch(()=>{})},m)}},j.onerror=()=>{!Z&&!a&&(clearTimeout(l),a=!0,o(new Error("WebSocket connection failed")))}}catch(r){clearTimeout(l),a||(a=!0,o(r))}})}function Ne(t){let e=JSON.stringify(t);j&&j.readyState===WebSocket.OPEN&&Z?j.send(e):xe.push(e)}function C(t,e){return new Promise((s,o)=>{let a=ve(),l=setTimeout(()=>{O.delete(a),o(new Error("Request timeout"))},3e4);O.set(a,r=>{clearTimeout(l),r.type==="error"?o(new Error(r.payload?.message||"Unknown error")):s(r)}),Ne({id:a,type:t,payload:e})})}function Re(t,e,s){return new Promise((o,a)=>{let l=ve(),r=setTimeout(()=>{O.delete(l),a(new Error("Stream timeout"))},12e4);O.set(l,p=>{p.type==="llm.chunk"?s(p.payload?.delta||""):p.type==="llm.done"?(clearTimeout(r),O.delete(l),o(p.payload)):(p.type==="llm.error"||p.type==="error")&&(clearTimeout(r),O.delete(l),a(new Error(p.payload?.message||"Stream error")))}),Ne({id:l,type:t,payload:e})})}function Ae(t){return ne.push(t),()=>{ne=ne.filter(e=>e!==t)}}function ke(){return Z}var Oe=["display","position","width","height","margin","padding","color","background-color","background","font-size","font-weight","font-family","border","border-radius","box-shadow","flex-direction","justify-content","align-items","gap","grid-template-columns","grid-template-rows","overflow","opacity","z-index","text-align","line-height","letter-spacing"];function De(t){let e=window.getComputedStyle(t),s={};for(let i of Oe)s[i]=e.getPropertyValue(i);let o=t.getBoundingClientRect(),a={};if(t.parentElement&&t.parentElement!==document.body){let i=window.getComputedStyle(t.parentElement);for(let g of Oe)a[g]=i.getPropertyValue(g)}let l=[];if(t.parentElement){let i=Array.from(t.parentElement.children),g=i.indexOf(t),b=Math.max(0,g-3),d=Math.min(i.length,g+4);b>0&&l.push(`... ${b} elements before ...`);for(let f=b;f<d;f++){let h=i[f],M=h.tagName.toLowerCase(),w=(h.className||"").toString().slice(0,60);h===t?l.push(`[SELECTED] <${M} class="${w}">`):l.push(`<${M} class="${w}">`)}d<i.length&&l.push(`... ${i.length-d} elements after ...`)}let r=[],p=Array.from(t.children).slice(0,12);for(let i=0;i<p.length;i++){let g=p[i],b=g.getBoundingClientRect(),d=window.getComputedStyle(g),f=null;if(i<p.length-1){let h=p[i+1].getBoundingClientRect();f={vertical:Math.round(h.top-b.bottom),horizontal:Math.round(h.left-b.right)}}r.push({tag:g.tagName.toLowerCase(),className:(g.className||"").toString().slice(0,80),rect:{x:Math.round(b.x),y:Math.round(b.y),width:Math.round(b.width),height:Math.round(b.height)},gapToNext:f,margin:d.margin,padding:d.padding})}let c=lt(t),m=dt(t,c),u={};for(let i of Array.from(t.attributes))(i.name.startsWith("aria-")||i.name==="role"||i.name==="tabindex")&&(u[i.name]=i.value);let v=[];for(let i of Array.from(t.attributes))i.name.startsWith("on")&&v.push(i.name);let $=ct(t);return{tagName:t.tagName.toLowerCase(),id:t.id||"",className:t.className||"",textContent:(t.textContent||"").trim().slice(0,200),outerHTML:at(t),cssSelector:rt(t),xpath:it(t),computedStyles:s,ancestry:ot(t),componentHint:st(t),rect:{x:o.x,y:o.y,width:o.width,height:o.height},parentStyles:a,siblings:l,childrenLayout:r,matchedCssRules:c,resolvedClasses:m,viewport:{width:window.innerWidth,height:window.innerHeight},ariaAttributes:u,eventHandlers:v,reactProps:$}}function ot(t,e=5){let s=[],o=t.parentElement;for(;o&&o!==document.body&&s.length<e;){let a=o.tagName.toLowerCase(),l=(typeof o.className=="string"?o.className:"").split(/\s+/).filter(r=>r.length>1&&!r.startsWith("_")).slice(0,3).join(".");s.push(l?`${a}.${l}`:a),o=o.parentElement}return s}function st(t){let e=t;for(;e&&e!==document.body;){let s=e.getAttribute("data-component")||e.getAttribute("data-testid")||e.getAttribute("data-cy");if(s)return s;let o=Object.keys(e);for(let a of o)if(a.startsWith("__reactFiber")||a.startsWith("__reactInternalInstance"))try{let l=e[a],r=l?.type?.name||l?.type?.displayName||l?.return?.type?.name||l?.return?.type?.displayName;if(r&&r!=="div"&&r!=="span"&&r.length>1)return r}catch{}e=e.parentElement}return""}function at(t){let e=t.cloneNode(!0);e.querySelectorAll("script, style, svg").forEach(a=>a.remove());let o=e.outerHTML;if(o.length>2e3){let a=t.tagName.toLowerCase(),l=Array.from(t.attributes).map(p=>`${p.name}="${p.value}"`).join(" "),r=Array.from(t.children).slice(0,5).map(p=>`<${p.tagName.toLowerCase()} .../>`).join(`
|
|
376
376
|
`);o=`<${a} ${l}>
|
|
377
377
|
${r}
|
|
378
378
|
${t.children.length>5?`<!-- +${t.children.length-5} more children -->`:""}
|
|
379
|
-
</${a}>`}return o}function
|
|
379
|
+
</${a}>`}return o}function rt(t){if(t.id)return`#${CSS.escape(t.id)}`;let e=[],s=t;for(;s&&s!==document.body;){let o=s.tagName.toLowerCase();if(s.id){e.unshift(`#${CSS.escape(s.id)}`);break}if(s.className&&typeof s.className=="string"){let l=s.className.trim().split(/\s+/).filter(r=>!r.startsWith("__")&&r.length<30).slice(0,2).map(r=>CSS.escape(r));l.length>0&&(o+="."+l.join("."))}let a=s.parentElement;if(a){let l=Array.from(a.children).filter(r=>r.tagName===s.tagName);if(l.length>1){let r=l.indexOf(s)+1;o+=`:nth-of-type(${r})`}}e.unshift(o),s=s.parentElement}return e.join(" > ")}function it(t){let e=[],s=t;for(;s&&s!==document;){if(s.nodeType===Node.ELEMENT_NODE){let o=s,a=1,l=o.previousElementSibling;for(;l;)l.tagName===o.tagName&&a++,l=l.previousElementSibling;e.unshift(`${o.tagName.toLowerCase()}[${a}]`)}s=s.parentNode}return"/"+e.join("/")}function lt(t){let e=[];try{for(let s of Array.from(document.styleSheets))try{let o=s.cssRules||s.rules;if(!o)continue;for(let a of Array.from(o))if(a instanceof CSSStyleRule)try{if(t.matches(a.selectorText)){let l=a.cssText;l.length>10&&l.length<500&&e.push(l)}}catch{}}catch{}}catch{}return e.slice(0,15)}function ct(t){try{let e=Object.keys(t);for(let s of e)if(s.startsWith("__reactFiber")||s.startsWith("__reactInternalInstance")){let o=t[s];if(!o?.memoizedProps)continue;let a=o.memoizedProps,l={},r=0;for(let[p,c]of Object.entries(a)){if(r>=10)break;if(p==="children")continue;let m=typeof c;m==="string"||m==="number"||m==="boolean"||c===null?(l[p]=c,r++):m==="function"?(l[p]="[function]",r++):Array.isArray(c)&&(l[p]=`[Array(${c.length})]`,r++)}return Object.keys(l).length>0?l:null}}catch{}return null}function dt(t,e){let s=[],o=(t.className||"").toString().trim().split(/\s+/).filter(Boolean);for(let a of o){let l=CSS.escape(a);for(let r of e)if(r.includes(`.${l}`)&&r.length<200){s.push({className:a,css:r});break}if(s.length>=20)break}return s}var D=null;function Ie(t){D||(D=document.createElement("div"),D.style.cssText=`
|
|
380
380
|
position: fixed;
|
|
381
381
|
pointer-events: none;
|
|
382
382
|
z-index: 2147483646;
|
|
383
383
|
border: 2px solid #6c5ce7;
|
|
384
384
|
background: rgba(108, 92, 231, 0.1);
|
|
385
385
|
transition: all 0.1s ease;
|
|
386
|
-
`,
|
|
386
|
+
`,D.dataset.openmagic="highlight",document.body.appendChild(D)),D.style.left=`${t.x}px`,D.style.top=`${t.y}px`,D.style.width=`${t.width}px`,D.style.height=`${t.height}px`,D.style.display="block"}function qe(){D&&(D.style.display="none")}async function je(t){try{let e=t||document.body,s=await pt(e);if(s)return{data:s}}catch{}try{let e=await mt(t);if(e)return{data:e}}catch(e){return{data:null,error:`Screenshot failed: ${e.message||"unknown error"}. Try using the image attachment button instead.`}}return{data:null,error:"Screenshot capture not available on this page. Try pasting or dragging an image instead."}}async function pt(t){let e=t.getBoundingClientRect(),s=Math.min(e.width||window.innerWidth,1920),o=Math.min(e.height||window.innerHeight,1080),a=Fe(t,0,4);if(!a)return null;let l=`
|
|
387
387
|
<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${o}">
|
|
388
388
|
<foreignObject width="100%" height="100%">
|
|
389
389
|
<div xmlns="http://www.w3.org/1999/xhtml" style="width:${s}px;height:${o}px;overflow:hidden;">
|
|
390
390
|
${a.outerHTML}
|
|
391
391
|
</div>
|
|
392
392
|
</foreignObject>
|
|
393
|
-
</svg>`,r=new Blob([l],{type:"image/svg+xml;charset=utf-8"}),p=URL.createObjectURL(r);return new Promise(c=>{let m=new Image,u=document.createElement("canvas"),x=Math.min(window.devicePixelRatio||1,2);u.width=s*x,u.height=o*x,m.onload=()=>{URL.revokeObjectURL(p);let v=u.getContext("2d");if(!v){c(null);return}v.scale(x,x),v.drawImage(m,0,0);try{c(u.toDataURL("image/png",.8))}catch{c(null)}},m.onerror=()=>{URL.revokeObjectURL(p),c(null)},setTimeout(()=>{URL.revokeObjectURL(p),c(null)},5e3),m.src=p})}async function pt(t){let e=t||document.documentElement,s=e.getBoundingClientRect(),o=document.createElement("canvas");o.width=400,o.height=300;let a=o.getContext("2d");return a?(a.fillStyle="#1a1a2e",a.fillRect(0,0,400,300),a.fillStyle="#e0e0e0",a.font="14px system-ui",a.fillText(`Element: <${e.tagName.toLowerCase()}>`,20,30),a.fillStyle="#888",a.font="12px system-ui",a.fillText(`Size: ${Math.round(s.width)}x${Math.round(s.height)}`,20,55),a.fillText(`Classes: ${(e.className||"").toString().slice(0,40)}`,20,75),a.fillText(`Page: ${window.location.pathname}`,20,95),a.fillStyle="#6c5ce7",a.font="11px system-ui",a.fillText("(Full screenshot unavailable \u2014 context sent as metadata)",20,130),o.toDataURL("image/png")):null}function je(t,e,s){if(e>s)return null;try{let o=t.cloneNode(!1);if(o.tagName==="SCRIPT"||o.tagName==="STYLE"||o.tagName==="SVG"||o.tagName==="CANVAS"||o.tagName==="VIDEO"||o.tagName==="IFRAME")return null;let a=window.getComputedStyle(t),l=["display","position","width","height","margin","padding","color","background-color","background","font-size","font-weight","font-family","border","border-radius","flex-direction","justify-content","align-items","gap","grid-template-columns","text-align","overflow"],r="";for(let p of l){let c=a.getPropertyValue(p);c&&c!=="normal"&&c!=="none"&&c!=="auto"&&c!=="0px"&&(r+=`${p}:${c};`)}o.setAttribute("style",r);for(let p=0;p<t.children.length&&p<20;p++){let c=je(t.children[p],e+1,s);c&&o.appendChild(c)}return o}catch{return null}}var re=[];var Fe=!1;function Be(){if(Fe)return;Fe=!0;let t=window.fetch;window.fetch=async function(...o){let a=new Request(...o),l={method:a.method,url:a.url,timestamp:Date.now()};try{let r=await t.apply(this,o);return l.status=r.status,l.duration=Date.now()-l.timestamp,ke(l),r}catch(r){throw l.status=0,l.duration=Date.now()-l.timestamp,ke(l),r}};let e=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,a,...l){return this.__om_method=o,this.__om_url=a,this.__om_start=Date.now(),e.apply(this,[o,a,...l])},XMLHttpRequest.prototype.send=function(...o){return this.addEventListener("loadend",()=>{ke({method:this.__om_method||"GET",url:this.__om_url||"",status:this.status,duration:Date.now()-(this.__om_start||Date.now()),timestamp:this.__om_start||Date.now()})}),s.apply(this,o)}}function ke(t){t.url.includes("__openmagic__")||(re.push(t),re.length>50&&re.shift())}function le(){return[...re]}var ie=[],mt=100,ze=!1;function Ue(){if(ze)return;ze=!0;let t=["log","warn","error","info","debug"];for(let e of t){let s=console[e];console[e]=function(...o){ie.push({level:e,args:o.map(a=>{try{return typeof a=="object"?JSON.stringify(a).slice(0,500):String(a)}catch{return String(a)}}),timestamp:Date.now()}),ie.length>mt&&ie.shift(),s.apply(console,o)}}}function ce(){return[...ie]}function We(t,e){return{selectedElement:t?{tagName:t.tagName,id:t.id,className:t.className,textContent:t.textContent,outerHTML:t.outerHTML,cssSelector:t.cssSelector,computedStyles:t.computedStyles}:void 0,screenshot:e||void 0,networkLogs:le().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:ce().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var $={sparkle:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.582a.5.5 0 0 1 0 .962L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/></svg>',crosshair:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="22" y1="12" x2="18" y2="12"/><line x1="6" y1="12" x2="2" y2="12"/><line x1="12" y1="6" x2="12" y2="2"/><line x1="12" y1="22" x2="12" y2="18"/></svg>',camera:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg>',chat:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',settings:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>',send:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>',x:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',externalLink:'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',check:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>',copy:'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>',grip:'<svg width="7" height="14" viewBox="0 0 8 14" fill="currentColor"><circle cx="2" cy="2" r="1.2"/><circle cx="6" cy="2" r="1.2"/><circle cx="2" cy="7" r="1.2"/><circle cx="6" cy="7" r="1.2"/><circle cx="2" cy="12" r="1.2"/><circle cx="6" cy="12" r="1.2"/></svg>',network:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',activity:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>',bug:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m8 2 1.88 1.88M14.12 3.88 16 2M9 7.13v-1a3.003 3.003 0 1 1 6 0v1"/><path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6"/><path d="M12 20v-9"/><path d="M6.53 9C4.6 8.8 3 7.1 3 5"/><path d="M6 13H2"/><path d="M3 21c0-2.1 1.7-3.9 3.8-4"/><path d="M20.97 5c0 2.1-1.6 3.8-3.5 4"/><path d="M22 13h-4"/><path d="M17.2 17c2.1.1 3.8 1.9 3.8 4"/></svg>',paperclip:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>',image:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',trash:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',minus:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>'},U={openai:{name:"OpenAI",keyUrl:"https://platform.openai.com/api-keys",keyPlaceholder:"sk-...",models:[{id:"gpt-5.4",name:"GPT-5.4"},{id:"gpt-5.4-mini",name:"GPT-5.4 Mini"},{id:"gpt-5.2",name:"GPT-5.2 Thinking"},{id:"o3",name:"o3"},{id:"o4-mini",name:"o4-mini"},{id:"gpt-4.1",name:"GPT-4.1"},{id:"gpt-4.1-mini",name:"GPT-4.1 Mini"}]},anthropic:{name:"Anthropic",keyUrl:"https://console.anthropic.com/settings/keys",keyPlaceholder:"sk-ant-...",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6"},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6"},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5"}]},google:{name:"Google Gemini",keyUrl:"https://aistudio.google.com/apikey",keyPlaceholder:"AIza...",models:[{id:"gemini-3.1-pro-preview",name:"Gemini 3.1 Pro"},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash"},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash"}]},xai:{name:"xAI (Grok)",keyUrl:"https://console.x.ai/team/default/api-keys",keyPlaceholder:"xai-...",models:[{id:"grok-4.20-0309-reasoning",name:"Grok 4.20 Reasoning"},{id:"grok-4-1-fast-non-reasoning",name:"Grok 4.1 Fast"}]},deepseek:{name:"DeepSeek",keyUrl:"https://platform.deepseek.com/api_keys",keyPlaceholder:"sk-...",models:[{id:"deepseek-chat",name:"DeepSeek V3.2"},{id:"deepseek-reasoner",name:"DeepSeek R1"}]},mistral:{name:"Mistral",keyUrl:"https://console.mistral.ai/api-keys",keyPlaceholder:"...",models:[{id:"mistral-large-3-25-12",name:"Mistral Large 3"},{id:"codestral-2508",name:"Codestral"},{id:"devstral-2-25-12",name:"Devstral 2"}]},groq:{name:"Groq",keyUrl:"https://console.groq.com/keys",keyPlaceholder:"gsk_...",models:[{id:"meta-llama/llama-4-scout-17b-16e-instruct",name:"Llama 4 Scout"},{id:"llama-3.3-70b-versatile",name:"Llama 3.3 70B"}]},minimax:{name:"MiniMax",keyUrl:"https://platform.minimax.chat/user-center/basic-information/interface-key",keyPlaceholder:"MiniMax key...",models:[{id:"MiniMax-M2.7",name:"MiniMax M2.7"},{id:"MiniMax-M2.5",name:"MiniMax M2.5"}]},moonshot:{name:"Kimi (Moonshot)",keyUrl:"https://platform.moonshot.cn/console/api-keys",keyPlaceholder:"Moonshot key...",models:[{id:"kimi-k2.5",name:"Kimi K2.5"},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking"}]},qwen:{name:"Qwen (Alibaba)",keyUrl:"https://dashscope.console.aliyun.com/apiKey",keyPlaceholder:"DashScope key...",models:[{id:"qwen3.5-plus",name:"Qwen 3.5 Plus"},{id:"qwen-max",name:"Qwen Max"}]},zhipu:{name:"Zhipu AI (GLM)",keyUrl:"https://open.bigmodel.cn/usercenter/apikeys",keyPlaceholder:"Zhipu key...",models:[{id:"glm-5",name:"GLM-5"},{id:"glm-4.7",name:"GLM-4.7"}]},doubao:{name:"Doubao (ByteDance)",keyUrl:"https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey",keyPlaceholder:"Volcano key...",models:[{id:"doubao-seed-2-0-pro",name:"Doubao Seed 2.0 Pro"},{id:"doubao-seed-2-0-code",name:"Doubao Seed 2.0 Code"}]},ollama:{name:"Ollama (Local)",keyPlaceholder:"not required",local:!0,models:[]},openrouter:{name:"OpenRouter",keyUrl:"https://openrouter.ai/settings/keys",keyPlaceholder:"sk-or-...",models:[]}};function pe(t){let e=new TextEncoder().encode(t),s="";for(let o=0;o<e.length;o+=32768)s+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(s)}function Y(t){let e=atob(t),s=new Uint8Array(e.length);for(let o=0;o<e.length;o++)s[o]=e.charCodeAt(o);return new TextDecoder().decode(s)}var Le="0.33.7",n={connected:!1,panelOpen:!1,activePanel:"",selecting:!1,selectedElement:null,screenshot:null,messages:[],streaming:!1,streamContent:"",provider:"",model:"",hasApiKey:!1,configuredProviders:{},roots:[],updateAvailable:!1,latestVersion:"",saveStatus:"",networkCapture:!1,attachments:[],groundedFiles:[],minimized:!1},T,P,B,Ye,Te,q;function ut(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function ht(){try{let t=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");t.messages?.length&&(n.messages=t.messages),t.provider&&(n.provider=t.provider),t.model&&(n.model=t.model),t.panelOpen&&(n.panelOpen=t.panelOpen,n.activePanel=t.activePanel||"")}catch{}}function Ge(){if(document.querySelector("openmagic-toolbar"))return;ht();let t=document.createElement("openmagic-toolbar");t.dataset.openmagic="true",T=t.attachShadow({mode:"closed"});let e=document.createElement("style");e.textContent=He,T.appendChild(e);let s=document.createElement("div");T.appendChild(s),s.innerHTML=gt(),P=s.querySelector(".om-toolbar"),B=s.querySelector(".om-prompt-input"),Ye=s.querySelector(".om-prompt-context"),Te=s.querySelector(".om-panel"),q=s.querySelector(".om-panel-body"),document.body.appendChild(t),ft(s),Tt();try{let r=JSON.parse(localStorage.getItem("__om_pos__")||"");r?.left&&r?.top&&(P.style.left=r.left,P.style.top=r.top,P.style.right="auto",P.style.bottom="auto")}catch{}Be(),Ue(),Ht();let a=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,l=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);a&&ve(l,a).then(()=>(n.connected=!0,me(),L("config.get"))).then(r=>{let p=r.payload?.provider||"",c=r.payload?.model||"";n.provider=n.provider||p,n.model=n.model||c,n.configuredProviders=r.payload?.apiKeys||{},n.hasApiKey=n.configuredProviders[n.provider]||!1,n.roots=r.payload?.roots||[],n.panelOpen&&n.activePanel?W(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&W("settings"),ae()}).catch(()=>{n.connected=!1,me()})}function gt(){return`
|
|
393
|
+
</svg>`,r=new Blob([l],{type:"image/svg+xml;charset=utf-8"}),p=URL.createObjectURL(r);return new Promise(c=>{let m=new Image,u=document.createElement("canvas"),v=Math.min(window.devicePixelRatio||1,2);u.width=s*v,u.height=o*v,m.onload=()=>{URL.revokeObjectURL(p);let $=u.getContext("2d");if(!$){c(null);return}$.scale(v,v),$.drawImage(m,0,0);try{c(u.toDataURL("image/png",.8))}catch{c(null)}},m.onerror=()=>{URL.revokeObjectURL(p),c(null)},setTimeout(()=>{URL.revokeObjectURL(p),c(null)},5e3),m.src=p})}async function mt(t){let e=t||document.documentElement,s=e.getBoundingClientRect(),o=document.createElement("canvas");o.width=400,o.height=300;let a=o.getContext("2d");return a?(a.fillStyle="#1a1a2e",a.fillRect(0,0,400,300),a.fillStyle="#e0e0e0",a.font="14px system-ui",a.fillText(`Element: <${e.tagName.toLowerCase()}>`,20,30),a.fillStyle="#888",a.font="12px system-ui",a.fillText(`Size: ${Math.round(s.width)}x${Math.round(s.height)}`,20,55),a.fillText(`Classes: ${(e.className||"").toString().slice(0,40)}`,20,75),a.fillText(`Page: ${window.location.pathname}`,20,95),a.fillStyle="#6c5ce7",a.font="11px system-ui",a.fillText("(Full screenshot unavailable \u2014 context sent as metadata)",20,130),o.toDataURL("image/png")):null}function Fe(t,e,s){if(e>s)return null;try{let o=t.cloneNode(!1);if(o.tagName==="SCRIPT"||o.tagName==="STYLE"||o.tagName==="SVG"||o.tagName==="CANVAS"||o.tagName==="VIDEO"||o.tagName==="IFRAME")return null;let a=window.getComputedStyle(t),l=["display","position","width","height","margin","padding","color","background-color","background","font-size","font-weight","font-family","border","border-radius","flex-direction","justify-content","align-items","gap","grid-template-columns","text-align","overflow"],r="";for(let p of l){let c=a.getPropertyValue(p);c&&c!=="normal"&&c!=="none"&&c!=="auto"&&c!=="0px"&&(r+=`${p}:${c};`)}o.setAttribute("style",r);for(let p=0;p<t.children.length&&p<20;p++){let c=Fe(t.children[p],e+1,s);c&&o.appendChild(c)}return o}catch{return null}}var ie=[];var ze=!1;function Ue(){if(ze)return;ze=!0;let t=window.fetch;window.fetch=async function(...o){let a=new Request(...o),l={method:a.method,url:a.url,timestamp:Date.now()};try{let r=await t.apply(this,o);return l.status=r.status,l.duration=Date.now()-l.timestamp,$e(l),r}catch(r){throw l.status=0,l.duration=Date.now()-l.timestamp,$e(l),r}};let e=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,a,...l){return this.__om_method=o,this.__om_url=a,this.__om_start=Date.now(),e.apply(this,[o,a,...l])},XMLHttpRequest.prototype.send=function(...o){return this.addEventListener("loadend",()=>{$e({method:this.__om_method||"GET",url:this.__om_url||"",status:this.status,duration:Date.now()-(this.__om_start||Date.now()),timestamp:this.__om_start||Date.now()})}),s.apply(this,o)}}function $e(t){t.url.includes("__openmagic__")||(ie.push(t),ie.length>50&&ie.shift())}function ce(){return[...ie]}var le=[],ut=100,Be=!1;function We(){if(Be)return;Be=!0;let t=["log","warn","error","info","debug"];for(let e of t){let s=console[e];console[e]=function(...o){le.push({level:e,args:o.map(a=>{try{return typeof a=="object"?JSON.stringify(a).slice(0,500):String(a)}catch{return String(a)}}),timestamp:Date.now()}),le.length>ut&&le.shift(),s.apply(console,o)}}}function de(){return[...le]}function Ge(t,e){return{selectedElement:t?{tagName:t.tagName,id:t.id,className:t.className,textContent:t.textContent,outerHTML:t.outerHTML,cssSelector:t.cssSelector,computedStyles:t.computedStyles}:void 0,screenshot:e||void 0,networkLogs:ce().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:de().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var S={sparkle:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.582a.5.5 0 0 1 0 .962L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/></svg>',crosshair:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="22" y1="12" x2="18" y2="12"/><line x1="6" y1="12" x2="2" y2="12"/><line x1="12" y1="6" x2="12" y2="2"/><line x1="12" y1="22" x2="12" y2="18"/></svg>',camera:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg>',chat:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',settings:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>',send:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>',x:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',externalLink:'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',check:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>',copy:'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>',grip:'<svg width="7" height="14" viewBox="0 0 8 14" fill="currentColor"><circle cx="2" cy="2" r="1.2"/><circle cx="6" cy="2" r="1.2"/><circle cx="2" cy="7" r="1.2"/><circle cx="6" cy="7" r="1.2"/><circle cx="2" cy="12" r="1.2"/><circle cx="6" cy="12" r="1.2"/></svg>',network:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',activity:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>',bug:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m8 2 1.88 1.88M14.12 3.88 16 2M9 7.13v-1a3.003 3.003 0 1 1 6 0v1"/><path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6"/><path d="M12 20v-9"/><path d="M6.53 9C4.6 8.8 3 7.1 3 5"/><path d="M6 13H2"/><path d="M3 21c0-2.1 1.7-3.9 3.8-4"/><path d="M20.97 5c0 2.1-1.6 3.8-3.5 4"/><path d="M22 13h-4"/><path d="M17.2 17c2.1.1 3.8 1.9 3.8 4"/></svg>',paperclip:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>',image:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',trash:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',minus:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>'},W={openai:{name:"OpenAI",keyUrl:"https://platform.openai.com/api-keys",keyPlaceholder:"sk-...",models:[{id:"gpt-5.4",name:"GPT-5.4"},{id:"gpt-5.4-mini",name:"GPT-5.4 Mini"},{id:"gpt-5.2",name:"GPT-5.2 Thinking"},{id:"o3",name:"o3"},{id:"o4-mini",name:"o4-mini"},{id:"gpt-4.1",name:"GPT-4.1"},{id:"gpt-4.1-mini",name:"GPT-4.1 Mini"}]},anthropic:{name:"Anthropic",keyUrl:"https://console.anthropic.com/settings/keys",keyPlaceholder:"sk-ant-...",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6"},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6"},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5"}]},google:{name:"Google Gemini",keyUrl:"https://aistudio.google.com/apikey",keyPlaceholder:"AIza...",models:[{id:"gemini-3.1-pro-preview",name:"Gemini 3.1 Pro"},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash"},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash"}]},xai:{name:"xAI (Grok)",keyUrl:"https://console.x.ai/team/default/api-keys",keyPlaceholder:"xai-...",models:[{id:"grok-4.20-0309-reasoning",name:"Grok 4.20 Reasoning"},{id:"grok-4-1-fast-non-reasoning",name:"Grok 4.1 Fast"}]},deepseek:{name:"DeepSeek",keyUrl:"https://platform.deepseek.com/api_keys",keyPlaceholder:"sk-...",models:[{id:"deepseek-chat",name:"DeepSeek V3.2"},{id:"deepseek-reasoner",name:"DeepSeek R1"}]},mistral:{name:"Mistral",keyUrl:"https://console.mistral.ai/api-keys",keyPlaceholder:"...",models:[{id:"mistral-large-3-25-12",name:"Mistral Large 3"},{id:"codestral-2508",name:"Codestral"},{id:"devstral-2-25-12",name:"Devstral 2"}]},groq:{name:"Groq",keyUrl:"https://console.groq.com/keys",keyPlaceholder:"gsk_...",models:[{id:"meta-llama/llama-4-scout-17b-16e-instruct",name:"Llama 4 Scout"},{id:"llama-3.3-70b-versatile",name:"Llama 3.3 70B"}]},minimax:{name:"MiniMax",keyUrl:"https://platform.minimax.chat/user-center/basic-information/interface-key",keyPlaceholder:"MiniMax key...",models:[{id:"MiniMax-M2.7",name:"MiniMax M2.7"},{id:"MiniMax-M2.5",name:"MiniMax M2.5"}]},moonshot:{name:"Kimi (Moonshot)",keyUrl:"https://platform.moonshot.cn/console/api-keys",keyPlaceholder:"Moonshot key...",models:[{id:"kimi-k2.5",name:"Kimi K2.5"},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking"}]},qwen:{name:"Qwen (Alibaba)",keyUrl:"https://dashscope.console.aliyun.com/apiKey",keyPlaceholder:"DashScope key...",models:[{id:"qwen3.5-plus",name:"Qwen 3.5 Plus"},{id:"qwen-max",name:"Qwen Max"}]},zhipu:{name:"Zhipu AI (GLM)",keyUrl:"https://open.bigmodel.cn/usercenter/apikeys",keyPlaceholder:"Zhipu key...",models:[{id:"glm-5",name:"GLM-5"},{id:"glm-4.7",name:"GLM-4.7"}]},doubao:{name:"Doubao (ByteDance)",keyUrl:"https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey",keyPlaceholder:"Volcano key...",models:[{id:"doubao-seed-2-0-pro",name:"Doubao Seed 2.0 Pro"},{id:"doubao-seed-2-0-code",name:"Doubao Seed 2.0 Code"}]},ollama:{name:"Ollama (Local)",keyPlaceholder:"not required",local:!0,models:[]},openrouter:{name:"OpenRouter",keyUrl:"https://openrouter.ai/settings/keys",keyPlaceholder:"sk-or-...",models:[]}};function me(t){let e=new TextEncoder().encode(t),s="";for(let o=0;o<e.length;o+=32768)s+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(s)}function Q(t){let e=atob(t),s=new Uint8Array(e.length);for(let o=0;o<e.length;o++)s[o]=e.charCodeAt(o);return new TextDecoder().decode(s)}var Te="0.34.0",n={connected:!1,panelOpen:!1,activePanel:"",selecting:!1,selectedElement:null,screenshot:null,messages:[],streaming:!1,streamContent:"",provider:"",model:"",hasApiKey:!1,configuredProviders:{},roots:[],updateAvailable:!1,latestVersion:"",saveStatus:"",networkCapture:!1,attachments:[],groundedFiles:[],minimized:!1},P,N,U,Ze,Ce,F;function ht(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function gt(){try{let t=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");t.messages?.length&&(n.messages=t.messages),t.provider&&(n.provider=t.provider),t.model&&(n.model=t.model),t.panelOpen&&(n.panelOpen=t.panelOpen,n.activePanel=t.activePanel||"")}catch{}}function Ke(){if(document.querySelector("openmagic-toolbar"))return;gt();let t=document.createElement("openmagic-toolbar");t.dataset.openmagic="true",P=t.attachShadow({mode:"closed"});let e=document.createElement("style");e.textContent=Pe,P.appendChild(e);let s=document.createElement("div");P.appendChild(s),s.innerHTML=ft(),N=s.querySelector(".om-toolbar"),U=s.querySelector(".om-prompt-input"),Ze=s.querySelector(".om-prompt-context"),Ce=s.querySelector(".om-panel"),F=s.querySelector(".om-panel-body"),document.body.appendChild(t),yt(s),Ct();try{let r=JSON.parse(localStorage.getItem("__om_pos__")||"");r?.left&&r?.top&&(N.style.left=r.left,N.style.top=r.top,N.style.right="auto",N.style.bottom="auto")}catch{}Ue(),We(),Pt();let a=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,l=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);a&&we(l,a).then(()=>(n.connected=!0,ue(),C("config.get"))).then(r=>{let p=r.payload?.provider||"",c=r.payload?.model||"";n.provider=n.provider||p,n.model=n.model||c,n.configuredProviders=r.payload?.apiKeys||{},n.hasApiKey=n.configuredProviders[n.provider]||!1,n.roots=r.payload?.roots||[],n.panelOpen&&n.activePanel?G(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&G("settings"),re()}).catch(()=>{n.connected=!1,ue()})}function ft(){return`
|
|
394
394
|
<div class="om-toolbar">
|
|
395
395
|
<div class="om-toolbar-header">
|
|
396
|
-
<span class="om-grab">${
|
|
396
|
+
<span class="om-grab">${S.grip}</span>
|
|
397
397
|
<span class="om-pill-brand">
|
|
398
398
|
<span class="om-pill-text">\u2728OpenMagic\u{1FA84}</span>
|
|
399
399
|
</span>
|
|
400
400
|
<span class="om-pill-divider"></span>
|
|
401
|
-
<button class="om-pill-btn" data-action="select" title="Select element">${
|
|
402
|
-
<button class="om-pill-btn" data-action="screenshot" title="Screenshot">${
|
|
403
|
-
<button class="om-pill-btn" data-action="network" title="Network & Performance">${
|
|
401
|
+
<button class="om-pill-btn" data-action="select" title="Select element">${S.crosshair}</button>
|
|
402
|
+
<button class="om-pill-btn" data-action="screenshot" title="Screenshot">${S.camera}</button>
|
|
403
|
+
<button class="om-pill-btn" data-action="network" title="Network & Performance">${S.activity}</button>
|
|
404
404
|
<span class="om-pill-divider"></span>
|
|
405
|
-
<button class="om-pill-btn" data-action="chat" title="Chat">${
|
|
406
|
-
<button class="om-pill-btn" data-action="settings" title="Settings">${
|
|
407
|
-
<button class="om-pill-btn" data-action="minimize" title="Minimize">${
|
|
405
|
+
<button class="om-pill-btn" data-action="chat" title="Chat">${S.chat}</button>
|
|
406
|
+
<button class="om-pill-btn" data-action="settings" title="Settings">${S.settings}</button>
|
|
407
|
+
<button class="om-pill-btn" data-action="minimize" title="Minimize">${S.minus}</button>
|
|
408
408
|
<span class="om-status-dot disconnected"></span>
|
|
409
409
|
</div>
|
|
410
410
|
<div class="om-panel om-hidden">
|
|
411
411
|
<div class="om-panel-header">
|
|
412
412
|
<span class="om-panel-title"></span>
|
|
413
|
-
<span class="om-panel-version">v${
|
|
414
|
-
<button class="om-panel-bug" data-action="report-issue" title="Report a bug on GitHub">${
|
|
415
|
-
<button class="om-panel-clear" data-action="clear-chat" title="Clear chat">${
|
|
416
|
-
<button class="om-panel-close" data-action="close-panel">${
|
|
413
|
+
<span class="om-panel-version">v${Te}</span>
|
|
414
|
+
<button class="om-panel-bug" data-action="report-issue" title="Report a bug on GitHub">${S.bug}</button>
|
|
415
|
+
<button class="om-panel-clear" data-action="clear-chat" title="Clear chat">${S.trash}</button>
|
|
416
|
+
<button class="om-panel-close" data-action="close-panel">${S.x}</button>
|
|
417
417
|
</div>
|
|
418
418
|
<div class="om-panel-body"></div>
|
|
419
419
|
</div>
|
|
@@ -427,33 +427,33 @@
|
|
|
427
427
|
<div class="om-prompt-attachments"></div>
|
|
428
428
|
<div class="om-prompt-row">
|
|
429
429
|
<div class="om-prompt-context"></div>
|
|
430
|
-
<button class="om-prompt-attach" data-action="attach-image" title="Attach image">${
|
|
430
|
+
<button class="om-prompt-attach" data-action="attach-image" title="Attach image">${S.paperclip}</button>
|
|
431
431
|
<input class="om-prompt-input" type="text" placeholder="Describe what to change..." autocomplete="off" />
|
|
432
|
-
<button class="om-prompt-send" data-action="prompt-send">${
|
|
432
|
+
<button class="om-prompt-send" data-action="prompt-send">${S.send}</button>
|
|
433
433
|
<input type="file" class="om-file-input om-hidden" accept="image/*" multiple />
|
|
434
434
|
</div>
|
|
435
|
-
</div>`}function
|
|
435
|
+
</div>`}function yt(t){t.addEventListener("click",o=>{let a=o.target.closest("[data-action]");if(!a)return;o.preventDefault(),o.stopPropagation();let l=a.dataset.action;wt(l,a)}),t.addEventListener("change",o=>{let a=o.target,l=a.dataset.field;l&&(l==="provider"?(n.provider=a.value,n.model=W[n.provider]?.models[0]?.id||"",n.hasApiKey=n.configuredProviders[n.provider]||W[n.provider]?.local||!1,n.saveStatus="",R()):l==="model"&&(n.model=a.value))}),U.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),Me())});let e=t.querySelector(".om-file-input");e&&e.addEventListener("change",()=>{Ee(e.files),e.value=""});let s=t.querySelector(".om-prompt-row");s&&(s.addEventListener("dragover",o=>{o.preventDefault(),s.style.borderColor="rgba(108, 92, 231, 0.5)"}),s.addEventListener("dragleave",()=>{s.style.borderColor=""}),s.addEventListener("drop",o=>{o.preventDefault(),s.style.borderColor="";let a=o.dataTransfer;a?.files?.length&&Ee(a.files)}),U.addEventListener("paste",o=>{let a=o.clipboardData?.items;if(a){for(let l=0;l<a.length;l++)if(a[l].type.startsWith("image/")){let r=a[l].getAsFile();if(r){let p=new DataTransfer;p.items.add(r),Ee(p.files)}}}})),Ae(o=>{o.type==="reconnected"&&(n.connected=!0,ue())}),document.addEventListener("keydown",o=>{if((o.ctrlKey||o.metaKey)&&o.shiftKey&&(o.key==="O"||o.key==="o")){if(o.preventDefault(),n.minimized){n.minimized=!1,N.querySelectorAll(".om-pill-btn:not([data-action='minimize']), .om-pill-divider, .om-status-dot").forEach(r=>r.style.display="");let l=P.querySelector(".om-prompt-row");l&&l.classList.remove("om-hidden")}else n.panelOpen?he():G("chat");return}if(o.key==="Escape"){if(n.selecting)return;n.panelOpen&&(he(),o.preventDefault())}}),U.addEventListener("keydown",o=>{(o.ctrlKey||o.metaKey)&&o.key==="Enter"&&(o.preventDefault(),Me())})}function Qe(t){return n.roots.length>0?n.roots[0]+"/"+t:t}function bt(t,e){let s=e.split(`
|
|
436
436
|
`).map(r=>r.trim()).filter(r=>r.length>0);if(s.length===0)return null;let o=t.split(`
|
|
437
437
|
`),a=s[0],l=s[s.length-1];for(let r=0;r<o.length;r++){if(o[r].trim()!==a||r+s.length>o.length)continue;let p=!0;for(let c=0;c<s.length;c++)if(o[r+c].trim()!==s[c]){p=!1;break}if(p){let c=0;for(let u=0;u<r;u++)c+=o[u].length+1;let m=c;for(let u=r;u<r+s.length;u++)m+=o[u].length+1;return m>0&&m<=t.length&&t[m-1]===`
|
|
438
|
-
`&&m--,{start:c,end:m}}}return null}async function
|
|
438
|
+
`&&m--,{start:c,end:m}}}return null}async function Ve(t){let e=t.dataset.file,s=t.dataset.search,o=t.dataset.replace;if(!e||!s||!o)return;t.disabled=!0,t.innerHTML='<span class="om-spinner"></span>',t.style.opacity="0.5",t.style.pointerEvents="none";let a=t.closest(".om-diff-card");if(a){let c=a.querySelector(".om-diff-actions");c&&(c.innerHTML='<span class="om-spinner"></span> Applying...')}await new Promise(c=>requestAnimationFrame(c));let l,r;try{l=Q(s),r=Q(o)}catch{n.messages.push({role:"system",content:`Failed to decode diff data for ${e}`}),R();return}let p=Qe(e);try{if(!l&&r){if((await C("fs.write",{path:p,content:r}))?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${e}`});else{let b=a?.dataset.diffIdx;b!==void 0?n.messages[parseInt(b)]={role:"system",content:`Created ${e}`}:n.messages.push({role:"system",content:`Created ${e}`})}R(),ee();return}let c,m=p,u=[p];e!==p&&u.push(e);let v=e.split("/").pop()||e,$=n.roots[0]||"",i=$?`${$}/${v}`:v;i!==p&&i!==e&&u.push(i);for(let g of u){let d=(await C("fs.read",{path:g}).catch(()=>null))?.payload?.content;if(d!=null&&String(d).length>0){c=String(d),m=g;break}}if(!c)n.messages.push({role:"system",content:`Could not read ${e} \u2014 tried: ${u.join(", ")}`});else{let g=c.split(l).length-1;if(g===1){let b=await C("fs.write",{path:m,content:c.replace(l,r)});if(b?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${e} - ${b.payload?.error||"unknown"}`});else{let d=a?.dataset.diffIdx;d!==void 0?n.messages[parseInt(d)]={role:"system",content:`Applied change to ${e}. Reloading...`}:n.messages.push({role:"system",content:`Applied change to ${e}. Reloading...`})}}else if(g>1)n.messages.push({role:"system",content:`Found ${g} exact matches in ${e} \u2014 expected 1. Edit not applied.`});else{let b=bt(c,l);if(b){let d=c.slice(0,b.start)+r+c.slice(b.end),f=await C("fs.write",{path:m,content:d});if(f?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${e} - ${f.payload?.error||"unknown"}`});else{let h=a?.dataset.diffIdx;h!==void 0?n.messages[parseInt(h)]={role:"system",content:`Applied change to ${e} (fuzzy match). Reloading...`}:n.messages.push({role:"system",content:`Applied change to ${e} (fuzzy match). Reloading...`})}}else n.messages.push({role:"system",content:`No matching code found in ${e}. The file may have changed since the suggestion.`})}}}catch(c){n.messages.push({role:"system",content:`Failed to apply: ${e} \u2014 ${c.message}`})}R(),ee(),setTimeout(()=>{window.location.reload()},1500)}function Je(t){t.disabled=!0,t.style.opacity="0.5";let e=t.dataset.idx;if(e!==void 0){let s=parseInt(e);try{let o=JSON.parse(Q(n.messages[s]?.content.slice(8)||""));n.messages[s]={role:"system",content:`Rejected change to ${o.file||"file"}`}}catch{n.messages[s]={role:"system",content:"Change rejected"}}}R(),ee()}function xt(t){let e=P.querySelector(".om-apply-bar");if(e)if(t>0){e.classList.remove("om-hidden");let s=e.querySelector(".om-apply-bar-text");s&&(s.textContent=`${t} change${t>1?"s":""} ready`)}else e.classList.add("om-hidden")}function Xe(){let t=P.querySelector(".om-apply-bar");t&&t.classList.add("om-hidden")}async function vt(t){let e=t.dataset.file;if(!e)return;let s=Qe(e);try{(await C("fs.undo",{path:s}))?.payload?.ok?n.messages.push({role:"system",content:`Reverted change to ${e}`}):n.messages.push({role:"system",content:`No backup found for ${e}`})}catch{n.messages.push({role:"system",content:`Could not revert ${e} \u2014 backup may not exist`})}R()}function wt(t,e){switch(t){case"select":Lt();break;case"screenshot":Tt();break;case"chat":Se("chat");break;case"settings":Se("settings");break;case"close-panel":he();break;case"prompt-send":Me();break;case"save-settings":St();break;case"get-key":{let s=e.dataset.url;s&&window.open(s,"_blank","noopener");break}case"change-key":{let s=P.querySelector("[data-key-change]");s&&s.classList.remove("om-hidden"),e.style.display="none";break}case"network":Se("chat"),Et();break;case"attach-image":Mt();break;case"remove-attachment":{let s=parseInt(e.dataset.idx||"0",10);n.attachments.splice(s,1),He();break}case"apply-diff":Ve(e);break;case"reject-diff":Je(e);break;case"apply-all":{let s=P.querySelectorAll('[data-action="apply-diff"]');for(let o of Array.from(s))Ve(o);Xe();break}case"reject-all":{let s=P.querySelectorAll('[data-action="reject-diff"]');for(let o of Array.from(s))Je(o);Xe();break}case"undo-diff":vt(e);break;case"clear-chat":{n.messages=[];try{sessionStorage.removeItem("__om_state__")}catch{}R();break}case"copy-msg":{let s=parseInt(e.dataset.idx||"0",10);e.innerHTML='<span class="om-spinner"></span>',Ye(s).then(o=>{try{navigator.clipboard.writeText(o)}catch{}e.innerHTML=S.check,setTimeout(()=>{e.innerHTML=S.copy},1500)});break}case"report-issue":{e.innerHTML='<span class="om-spinner"></span>',Ye().then(s=>{try{navigator.clipboard.writeText(s)}catch{}e.innerHTML=S.bug,window.open("https://github.com/Kalmuraee/OpenMagic/issues/new?template=bug_report.yml","_blank","noopener"),n.messages.push({role:"system",content:"Debug info copied to clipboard. Paste it in the Debug Info field on GitHub."}),n.panelOpen&&R()});break}case"clear-element":n.selectedElement=null,ae();break;case"clear-screenshot":n.screenshot=null,ae();break;case"minimize":{n.minimized=!n.minimized;let s=P.querySelector(".om-panel"),o=P.querySelector(".om-prompt-row"),a=P.querySelector(".om-prompt-attachments"),l=N.querySelectorAll(".om-pill-btn:not([data-action='minimize']), .om-pill-divider, .om-status-dot");n.minimized?(s&&s.classList.add("om-hidden"),o&&o.classList.add("om-hidden"),a&&a.classList.add("om-hidden"),l.forEach(r=>r.style.display="none")):(o&&o.classList.remove("om-hidden"),a&&a.classList.remove("om-hidden"),l.forEach(r=>r.style.display=""),n.panelOpen&&n.activePanel&&s&&s.classList.remove("om-hidden"));break}}}function ue(){let t=P.querySelector(".om-status-dot");if(t){let e=n.updateAvailable?"outdated":n.connected?"connected":"disconnected";t.className=`om-status-dot ${e}`,t.setAttribute("title",n.updateAvailable?`v${n.latestVersion} available \u2014 run npx openmagic@latest`:n.connected?"Connected":"Disconnected")}}function re(){P.querySelectorAll(".om-pill-btn").forEach(t=>{let e=t.dataset.action;t.classList.toggle("active",e===n.activePanel||e==="select"&&n.selecting)})}function ae(){let t=[];n.selectedElement&&t.push(`<span class="om-prompt-chip">${n.selectedElement.tagName}${n.selectedElement.id?"#"+n.selectedElement.id:""} <button class="om-prompt-chip-x" data-action="clear-element">${S.x}</button></span>`),n.screenshot&&t.push(`<span class="om-prompt-chip">Screenshot <button class="om-prompt-chip-x" data-action="clear-screenshot">${S.x}</button></span>`),n.attachments.length&&t.push(`<span class="om-prompt-chip">${n.attachments.length} image${n.attachments.length>1?"s":""}</span>`),n.groundedFiles.length&&t.push(`<span class="om-prompt-chip">${n.groundedFiles.length} files grounded</span>`),Ze.innerHTML=t.join("")}function G(t){n.panelOpen=!0,n.activePanel=t,Ce.classList.remove("om-hidden");let e=P.querySelector(".om-panel-title");e&&(e.textContent=t==="settings"?"Settings":"Chat"),R(),re()}function he(){n.panelOpen=!1,n.activePanel="",Ce.classList.add("om-hidden"),re()}function Se(t){n.panelOpen&&n.activePanel===t?he():G(t)}function R(){n.activePanel==="settings"?F.innerHTML=kt():n.activePanel==="chat"&&(F.innerHTML=$t(),ee()),ht()}function kt(){let t=Object.entries(W).map(([i,g])=>{let d=n.configuredProviders[i]||g.local?" \u2713":"";return`<option value="${i}" ${n.provider===i?"selected":""}>${g.name}${d}</option>`}).join(""),e=W[n.provider],s=e?e.models.map(i=>`<option value="${i.id}" ${n.model===i.id?"selected":""}>${i.name}</option>`).join(""):'<option value="">Select provider first</option>',o=e?.local||!1,a=e?.keyUrl||"",l=e?.keyPlaceholder||"Enter API key...",r=n.configuredProviders[n.provider]||!1,p=n.updateAvailable?`<div class="om-update-banner">v${n.latestVersion} available <code class="om-update-cmd">npx openmagic@latest</code></div>`:"",c=r||o?`<div class="om-status om-status-success">${S.check} ${e?.name||"Provider"} connected</div>`:"",m=n.saveStatus==="saving"?'<span class="om-spinner"></span> Saving...':n.saveStatus==="saved"?`${S.check} Saved`:"Save",u=n.saveStatus==="saving"?"om-btn om-btn-saving":n.saveStatus==="saved"?"om-btn om-btn-saved":"om-btn",v=n.saveStatus==="saving"?"disabled":"",$="";return!o&&n.provider&&(r?$=`
|
|
439
439
|
<div class="om-field">
|
|
440
440
|
<label class="om-label">API Key</label>
|
|
441
441
|
<div class="om-key-configured">
|
|
442
|
-
${
|
|
442
|
+
${S.check} <span>Key configured</span>
|
|
443
443
|
<button class="om-btn-change-key" data-action="change-key">Change</button>
|
|
444
444
|
</div>
|
|
445
445
|
<div class="om-key-change-row om-hidden" data-key-change>
|
|
446
446
|
<div class="om-key-row">
|
|
447
447
|
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${l}" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
|
448
|
-
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${
|
|
448
|
+
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${S.externalLink} Get key</button>`:""}
|
|
449
449
|
</div>
|
|
450
450
|
</div>
|
|
451
|
-
</div
|
|
451
|
+
</div>`:$=`
|
|
452
452
|
<div class="om-field">
|
|
453
453
|
<label class="om-label">API Key</label>
|
|
454
454
|
<div class="om-key-row">
|
|
455
455
|
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${l}" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
|
456
|
-
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${
|
|
456
|
+
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${S.externalLink} Get key</button>`:""}
|
|
457
457
|
</div>
|
|
458
458
|
${a?`<div class="om-key-hint"><a data-action="get-key" data-url="${a}">Get your ${e?.name||""} API key here</a></div>`:""}
|
|
459
459
|
</div>`),`
|
|
@@ -467,31 +467,31 @@
|
|
|
467
467
|
<label class="om-label">Model</label>
|
|
468
468
|
<select class="om-select" data-field="model"><option value="">Select Model...</option>${s}</select>
|
|
469
469
|
</div>
|
|
470
|
-
${
|
|
471
|
-
<button class="${u}" data-action="save-settings" ${
|
|
470
|
+
${$}
|
|
471
|
+
<button class="${u}" data-action="save-settings" ${v}>${m}</button>
|
|
472
472
|
${c}
|
|
473
|
-
</div>`}function
|
|
474
|
-
<div class="om-diff-file">${
|
|
475
|
-
${r.search?`<div class="om-diff-removed">${
|
|
476
|
-
<div class="om-diff-added">${
|
|
473
|
+
</div>`}function $t(){if(!n.provider||!n.hasApiKey&&!W[n.provider]?.local)return'<div class="om-status om-status-error">Configure your provider in Settings first</div>';let t=n.messages.map((o,a)=>{if(o.content.startsWith("__DIFFGROUP__"))return"";if(o.content.startsWith("__DIFF__"))try{let r=JSON.parse(Q(o.content.slice(8))),p=r.type==="create"||!r.search&&r.replace,c=me(r.search||""),m=me(r.replace||"");return`<div class="om-diff-card" data-diff-idx="${a}">
|
|
474
|
+
<div class="om-diff-file">${z(p?"Create new file":"Edit")}: ${z(r.file)}</div>
|
|
475
|
+
${r.search?`<div class="om-diff-removed">${z(r.search.slice(0,200))}</div>`:""}
|
|
476
|
+
<div class="om-diff-added">${z((r.replace||"").slice(0,300))}</div>
|
|
477
477
|
<div class="om-diff-actions">
|
|
478
|
-
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${
|
|
478
|
+
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${z(r.file)}" data-search="${c}" data-replace="${m}">Apply</button>
|
|
479
479
|
<button class="om-btn-secondary om-btn-sm" data-action="reject-diff" data-idx="${a}">Reject</button>
|
|
480
480
|
</div>
|
|
481
|
-
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(o.content.startsWith("Applied change to ")){let r=o.content.replace("Applied change to ","").replace(/ \(fuzzy match.*?\)/g,"").replace(". Reloading...","");return`<div class="om-msg om-msg-system">${
|
|
482
|
-
// [FILE TRUNCATED \u2014 showing ${
|
|
483
|
-
// [FILE TRUNCATED \u2014 showing ${
|
|
484
|
-
// [TRUNCATED]`),h.push({path:
|
|
485
|
-
// [FILE TRUNCATED \u2014 showing ${
|
|
486
|
-
/* [TRUNCATED] */`),h.push({path:
|
|
487
|
-
All network requests (${m.length}):`);for(let u of m.slice(-30)){let
|
|
481
|
+
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(o.content.startsWith("Applied change to ")){let r=o.content.replace("Applied change to ","").replace(/ \(fuzzy match.*?\)/g,"").replace(". Reloading...","");return`<div class="om-msg om-msg-system">${z(o.content)} <button class="om-undo-btn" data-action="undo-diff" data-file="${z(r)}">Undo</button></div>`}let l=o.role==="user"||o.role==="assistant"?`<button class="om-copy-btn" data-action="copy-msg" data-idx="${a}" title="Copy">${S.copy}</button>`:"";return o.role==="assistant"?`<div class="om-msg om-msg-assistant">${Ht(o.content)}${l}</div>`:`<div class="om-msg om-msg-${o.role}">${z(o.content)}${l}</div>`}).join(""),e=n.streaming?'<div class="om-msg om-msg-assistant"><span class="om-spinner"></span> Generating response...</div>':"";return`<div class="om-chat-messages">${!n.messages.length&&!n.streaming?'<div class="om-chat-empty">Select an element or type below to start</div>':""}${t}${e}</div>`}function ee(){requestAnimationFrame(()=>{let t=F.querySelector(".om-chat-messages");t&&(t.scrollTop=t.scrollHeight)})}async function St(){let e=F.querySelector('[data-field="apiKey"]')?.value||"";if(!n.provider){n.saveStatus="error",pe(),setTimeout(()=>{n.saveStatus="",R()},2e3);return}if(!ke()){n.saveStatus="error",pe();let o=F.querySelector('[data-action="save-settings"]');o&&(o.innerHTML="Not connected - check terminal"),setTimeout(()=>{n.saveStatus="",R()},3e3);return}let s={provider:n.provider,model:n.model};e&&(s.apiKey=e),n.saveStatus="saving",pe();try{let o=await Promise.race([C("config.set",s),new Promise((a,l)=>setTimeout(()=>l(new Error("Save timed out")),8e3))]);e&&n.provider&&(n.configuredProviders[n.provider]=!0),n.hasApiKey=!!(e||n.configuredProviders[n.provider]),n.saveStatus="saved",pe(),setTimeout(()=>{n.saveStatus="",n.activePanel==="settings"&&G("chat")},1200)}catch(o){n.saveStatus="error";let a=F.querySelector('[data-action="save-settings"]'),l=(o?.message||"").includes("timeout")?"Connection timeout - is the CLI running?":(o?.message||"").includes("connected")?"Not connected to OpenMagic server":`Save failed: ${o?.message||"Unknown error"}`;a&&(a.innerHTML=l,a.className="om-btn",a.disabled=!1),setTimeout(()=>{n.saveStatus="",R()},4e3)}}function pe(){let t=F.querySelector('[data-action="save-settings"]');t&&(n.saveStatus==="saving"?(t.innerHTML='<span class="om-spinner"></span> Saving...',t.className="om-btn om-btn-saving",t.disabled=!0):n.saveStatus==="saved"?(t.innerHTML=`${S.check} Saved`,t.className="om-btn om-btn-saved",t.disabled=!1):n.saveStatus==="error"?(t.innerHTML="Save failed - try again",t.className="om-btn",t.disabled=!1):(t.innerHTML="Save",t.className="om-btn",t.disabled=!1))}async function Me(){let t=U.value.trim();if(!t||n.streaming)return;if(!n.provider||!n.hasApiKey&&!W[n.provider]?.local){G("settings");return}n.messages.push({role:"user",content:t}),n.streaming=!0,n.streamContent="",U.value="",G("chat");let e=Ge(n.selectedElement,n.screenshot);e.pageUrl=window.location.href,e.pageTitle=document.title,n.attachments.length>0&&(e.screenshot||(e.screenshot=n.attachments[0]),e.attachments=[...n.attachments]);let s=5,o=32e3,a=/\.(?:[cm]?[jt]sx?|svelte|vue|astro|html?|css|scss|less|php|py)$/i,l=F.querySelector(".om-msg-assistant:last-child");l&&(l.innerHTML='<span class="om-spinner"></span> Reading project files...');try{let m=await C("fs.list",{});m?.payload?.projectTree&&(e.projectTree=m.payload.projectTree);let v=(m?.payload?.files||[]).filter(y=>y.type==="file"&&a.test(y.path)),$=[t];if(n.selectedElement&&(n.selectedElement.id&&$.push(n.selectedElement.id),n.selectedElement.className&&$.push(n.selectedElement.className),n.selectedElement.textContent&&$.push(n.selectedElement.textContent.slice(0,100)),n.selectedElement.componentHint&&$.push(n.selectedElement.componentHint),n.selectedElement.ancestry))for(let y of n.selectedElement.ancestry)$.push(y);let i=$.filter(Boolean).join(" ").toLowerCase().split(/[^a-z0-9_-]+/).filter(y=>y.length>=2&&!["the","to","in","of","and","div","span","class","style"].includes(y)),b=window.location.pathname.split("/").filter(y=>y.length>1&&!/^\d+$/.test(y)),d="";if(n.selectedElement?.componentHint||b.length){let y=(n.selectedElement?.componentHint||"").toLowerCase(),x=new Map;for(let T of v){let k=T.path.split("/")[0];if(!k||k.includes("."))continue;let H=T.path.toLowerCase(),I=x.get(k)||0;y&&H.includes(y)&&(I+=10);for(let K of b)H.includes(K.toLowerCase())&&(I+=5);/(component|page|route|layout)/.test(H)&&(I+=1),x.set(k,I)}let E=0;for(let[T,k]of x)k>E&&(E=k,d=T)}let f=v.map(y=>{let x=0,E=y.path.toLowerCase(),T=E.replace(/\([^)]+\)\//g,"");if(d){let k=y.path.split("/")[0];k===d?x+=20:k!==d&&!y.path.includes("/")?x+=0:x-=15}for(let k of b)T.includes(k.toLowerCase())&&(x+=15);if(n.selectedElement?.componentHint){let k=n.selectedElement.componentHint.toLowerCase();E.includes(k)&&(x+=12)}for(let k of i)E.includes(k)&&(x+=5);return/(component|page|route|layout|template|view)/.test(E)&&(x+=3),/page\.[jt]sx?$|layout\.[jt]sx?$|\+page\.svelte$/.test(E)&&(x+=5),{...y,score:x}}).sort((y,x)=>x.score-y.score),h=[],M=new Set,w=0;for(let y of f.slice(0,s)){if(y.score<=0||w>=o)break;try{let x=n.roots[0]||"",E=x?`${x}/${y.path}`:y.path,T=await C("fs.read",{path:E}),k=String(T?.payload?.content||"");if(!k)continue;let H=Math.min(8e3,o-w),I=k.slice(0,H);k.length>H&&(I+=`
|
|
482
|
+
// [FILE TRUNCATED \u2014 showing ${H} of ${k.length} chars]`),h.push({path:y.path,content:I}),M.add(y.path),w+=I.length;let K=y.path.replace(/\.[^.]+$/,""),et=[".module.css",".module.scss",".css",".scss",".styles.ts"];for(let te of et){let L=K+te;if(M.has(L)||w>=o)continue;if(v.find(B=>B.path===L)){try{let B=await C("fs.read",{path:x?`${x}/${L}`:L}),_=String(B?.payload?.content||"");if(_){let J=Math.min(4e3,o-w),A=_.slice(0,J);_.length>J&&(A+=`
|
|
483
|
+
// [FILE TRUNCATED \u2014 showing ${J} of ${_.length} chars]`),h.push({path:L,content:A}),M.add(L),w+=A.length}}catch{}break}}if(h.length<=2&&w<o){let te=["layout.tsx","layout.jsx","layout.js","layout.ts"],L=y.path.replace(/\/[^/]+$/,""),q=0;for(;L&&q<4&&w<o;){let B=!1;for(let J of te){let A=`${L}/${J}`;if(M.has(A)){B=!0;break}try{let X=await C("fs.read",{path:x?`${x}/${A}`:A}).catch(()=>null),V=String(X?.payload?.content||"");if(V){let Y=Math.min(4e3,o-w),fe=V.slice(0,Y);V.length>Y&&(fe+=`
|
|
484
|
+
// [TRUNCATED]`),h.push({path:A,content:fe}),M.add(A),w+=fe.length,B=!0;break}}catch{}}let _=L.replace(/\/[^/]+$/,"");if(_===L||!_)break;L=_,q++}}let tt=k.matchAll(/(?:import|from)\s+['"]\.?\.\/([\w/.-]+)['"]/g);for(let te of tt){if(w>=o)break;let L=te[1],q=y.path.replace(/\/[^/]+$/,""),B=[`${q}/${L}`,`${q}/${L}.tsx`,`${q}/${L}.ts`,`${q}/${L}.jsx`,`${q}/${L}.js`,`${q}/${L}/index.tsx`,`${q}/${L}/index.ts`];for(let _ of B){if(M.has(_))break;if(v.find(A=>A.path===_)){try{let A=await C("fs.read",{path:x?`${x}/${_}`:_}),X=String(A?.payload?.content||"");if(X){let V=Math.min(8e3,o-w),Y=X.slice(0,V);X.length>V&&(Y+=`
|
|
485
|
+
// [FILE TRUNCATED \u2014 showing ${V} of ${X.length} chars]`),h.push({path:_,content:Y}),M.add(_),w+=Y.length}}catch{}break}}}}catch{}}if(w<o)try{let y=n.roots[0]||"",x=await C("fs.read",{path:y?`${y}/package.json`:"package.json"}),E=String(x?.payload?.content||"");if(E)try{let T=JSON.parse(E),k={...T.dependencies,...T.devDependencies},H=JSON.stringify(k,null,2);h.push({path:"package.json (dependencies)",content:H.slice(0,2e3)})}catch{h.push({path:"package.json",content:E.slice(0,2e3)})}}catch{}if(w<o){let y=n.roots[0]||"",x=["tailwind.config.ts","tailwind.config.js","tailwind.config.mjs","src/app/globals.css","src/styles/globals.css","styles/globals.css","app/globals.css","src/index.css","src/global.css"];for(let E of x)if(!(w>=o||M.has(E)))try{let T=y?`${y}/${E}`:E,k=await C("fs.read",{path:T}).catch(()=>null),H=String(k?.payload?.content||"");if(H){let I=Math.min(12e3,o-w),K=H.slice(0,I);H.length>I&&(K+=`
|
|
486
|
+
/* [TRUNCATED] */`),h.push({path:E,content:K}),M.add(E),w+=K.length}}catch{}}if(h.length){e.files=h;let y=h.map(x=>x.path.split("/").pop()).join(", ");l&&(l.innerHTML=`<span class="om-spinner"></span> Thinking... (${h.length} files: ${y})`)}n.groundedFiles=h.map(y=>y.path)}catch{}let r=4,p=0,c=new Set;try{for(;p<=r;){n.streamContent="";let m=await Re("llm.chat",{provider:n.provider,model:n.model,messages:n.messages.map(d=>({role:d.role,content:d.content})),context:e},d=>{n.streamContent+=d}),u=n.streamContent||m?.content||"",v=u;try{let d=JSON.parse(u);d.explanation&&(v=d.explanation)}catch{let d=u.match(/```(?:json)?\s*([\s\S]*?)```/);if(d)try{let f=JSON.parse(d[1]);f.explanation&&(v=f.explanation)}catch{}}let $=v.match(/NEED_FILE:\s*"?([^\s"}\]]+)"?/)||v.match(/(?:need|provide|show|read|see|contents?\s+of)\s+(?:the\s+)?(?:file\s+)?[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i)||v.match(/(?:source\s+(?:file|code)\s+(?:for|of|at))\s+[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i)||u.match(/NEED_FILE:\s*\\?"?([^\s"\\}\]]+)"?/);if($&&p<r&&!c.has($[1].trim())){let d=$[1].trim();c.add(d),p++;let f=F.querySelector(".om-msg-assistant:last-child");f&&(f.innerHTML=`<span class="om-spinner"></span> Reading ${d}...`);try{let h=n.roots[0]||"",M=h?`${h}/${d}`:d,w,y=[M];d!==M&&y.push(d);let x=d.split("/").pop()||d,E=h?`${h}/${x}`:x;E!==M&&E!==d&&y.push(E);for(let T of y){let k=await C("fs.read",{path:T}).catch(()=>null);if(k?.payload?.content){w=String(k.payload.content);break}}if(w){e.files||(e.files=[]);let T=e.files.findIndex(H=>H.path===d||H.path.endsWith("/"+d)||d.endsWith("/"+H.path)),k=w.slice(0,16e3);T>=0?e.files[T]={path:d,content:k}:e.files.push({path:d,content:k})}else{n.messages.push({role:"system",content:`Could not read ${d}`});break}}catch{n.messages.push({role:"system",content:`File not found: ${d}`});break}continue}let i=v.match(/SEARCH_FILES:\s*"([^"]+)"(?:\s+in\s+(\S+))?/)||u.match(/SEARCH_FILES:\s*\\?"([^"\\]+)\\?"(?:\s+in\s+(\S+))?/),g=e.searchResults?.some(d=>d.query===i?.[1]);if(i&&p<r&&!g){let d=i[1],f=i[2]||"";p++;let h=F.querySelector(".om-msg-assistant:last-child");h&&(h.innerHTML=`<span class="om-spinner"></span> Searching: "${d}"...`);try{let w=(await Promise.race([C("fs.grep",{pattern:d,path:f}),new Promise((y,x)=>setTimeout(()=>x(new Error("grep timeout")),5e3))]))?.payload?.results||[];w.length&&(e.searchResults||(e.searchResults=[]),e.searchResults.push({query:d,matches:w}))}catch{}continue}let b=v;if((/^NEED_FILE:\s/m.test(b)||/^SEARCH_FILES:\s/m.test(b))&&(b="I found the relevant files but couldn't determine the exact change needed. Try selecting a more specific element or describing the issue in more detail."),n.messages.push({role:"assistant",content:b}),m?.modifications?.length){let d=Math.random().toString(36).slice(2),f=m.modifications.filter(h=>h.type==="edit"&&h.file&&h.search&&h.replace||h.type==="create"&&h.file&&h.content);xt(f.length);for(let h of m.modifications)if(h.type==="edit"&&h.file&&h.search&&h.replace){let M=Math.random().toString(36).slice(2),w=JSON.stringify({id:M,file:h.file,search:h.search,replace:h.replace,groupId:d});n.messages.push({role:"system",content:`__DIFF__${me(w)}`})}else if(h.type==="create"&&h.file&&h.content){let M=Math.random().toString(36).slice(2),w=JSON.stringify({id:M,file:h.file,search:"",replace:h.content,type:"create",groupId:d});n.messages.push({role:"system",content:`__DIFF__${me(w)}`})}else h.type==="delete"&&h.file&&n.messages.push({role:"system",content:`LLM proposed deleting ${h.file} \u2014 skipped (use edit with search/replace instead)`})}break}}catch(m){n.messages.push({role:"system",content:`Error: ${m.message}`})}n.streaming=!1,n.streamContent="",n.attachments=[],He(),R(),ee()}function Et(){let t=window.performance,e=t.getEntriesByType("navigation")[0],s=t.getEntriesByType("paint"),o=t.getEntriesByType("resource").slice(-20),a=ce(),l=de(),r=[];r.push("--- Network & Performance Capture ---"),e&&(r.push(`Page load: ${Math.round(e.loadEventEnd-e.startTime)}ms`),r.push(`DOM ready: ${Math.round(e.domContentLoadedEventEnd-e.startTime)}ms`),r.push(`TTFB: ${Math.round(e.responseStart-e.startTime)}ms`));let p=s.find(c=>c.name==="first-contentful-paint");if(p&&r.push(`FCP: ${Math.round(p.startTime)}ms`),o.length){let c=o.filter(u=>u.initiatorType==="fetch"||u.initiatorType==="xmlhttprequest"),m=c.length>0?c:o;r.push(`
|
|
487
|
+
All network requests (${m.length}):`);for(let u of m.slice(-30)){let v=u.name.length>80?"..."+u.name.slice(-77):u.name,$=u.responseStatus||"";r.push(` ${Math.round(u.duration)}ms ${$?`[${$}]`:""} ${v}`)}}if(a.length){r.push(`
|
|
488
488
|
Fetch/XHR requests (${a.length}):`);for(let c of a.slice(-20))r.push(` ${c.method} ${c.url.slice(0,80)} \u2192 ${c.status||"pending"} (${c.duration||"?"}ms)`)}if(l.length){let c=l.filter(u=>u.level==="error"),m=l.filter(u=>u.level==="warn");c.length&&r.push(`
|
|
489
489
|
Console errors: ${c.length}`),m.length&&r.push(`Console warnings: ${m.length}`)}if(o.length>5){let c=[...o].sort((m,u)=>u.duration-m.duration).slice(0,5);r.push(`
|
|
490
490
|
Slowest resources:`);for(let m of c)r.push(` ${Math.round(m.duration)}ms \u2014 ${m.name.split("/").pop()?.slice(0,60)}`)}n.messages.push({role:"system",content:r.join(`
|
|
491
|
-
`)}),
|
|
491
|
+
`)}),R(),ee(),ae()}function Mt(){let t=P.querySelector(".om-file-input");t&&t.click()}function Ee(t){if(t)for(let e=0;e<t.length&&n.attachments.length<5;e++){let s=t[e];if(!s.type.startsWith("image/")||s.size>10*1024*1024)continue;let o=new FileReader;o.onload=()=>{typeof o.result=="string"&&(n.attachments.push(o.result),He())},o.readAsDataURL(s)}}function He(){let t=P.querySelector(".om-prompt-attachments");if(t){if(!n.attachments.length){t.innerHTML="",t.classList.add("om-hidden");return}t.classList.remove("om-hidden"),t.innerHTML=n.attachments.map((e,s)=>`<div class="om-attachment-thumb">
|
|
492
492
|
<img src="${e}" alt="attachment" />
|
|
493
|
-
<button class="om-attachment-remove" data-action="remove-attachment" data-idx="${s}">${
|
|
494
|
-
</div>`).join("")}}var
|
|
495
|
-
`),s=
|
|
496
|
-
`)}function
|
|
493
|
+
<button class="om-attachment-remove" data-action="remove-attachment" data-idx="${s}">${S.x}</button>
|
|
494
|
+
</div>`).join("")}}var oe=null,se=null;function Lt(){n.selecting?Le():ge()}function ge(){n.selecting=!0,document.body.style.cursor="crosshair",re(),se=e=>{let s=e.target;if(s.closest("openmagic-toolbar")||s.dataset?.openmagic)return;let o=s.getBoundingClientRect();Ie({x:o.x,y:o.y,width:o.width,height:o.height})},oe=e=>{e.preventDefault(),e.stopPropagation();let s=e.target;s.closest("openmagic-toolbar")||s.dataset?.openmagic||(n.selectedElement=De(s),Le(),ae(),U.focus())};let t=e=>{e.key==="Escape"&&Le()};document.addEventListener("mousemove",se,!0),document.addEventListener("click",oe,!0),document.addEventListener("keydown",t,!0),ge._escHandler=t}function Le(){n.selecting=!1,document.body.style.cursor="",qe(),se&&(document.removeEventListener("mousemove",se,!0),se=null),oe&&(document.removeEventListener("click",oe,!0),oe=null);let t=ge._escHandler;t&&(document.removeEventListener("keydown",t,!0),ge._escHandler=null),re()}async function Tt(){let t;try{let o=n.selectedElement?.cssSelector?.trim();o&&(t=document.querySelector(o)||void 0)}catch{}let e=await je(t||void 0);e.data&&e.data.length>5e3?(n.screenshot=e.data,ae(),U.focus()):(n.messages.push({role:"system",content:"Take a screenshot manually (Cmd+Shift+4 on Mac, Win+Shift+S on Windows), then paste it here (Ctrl+V) or drag it onto the prompt bar."}),G("chat"),R())}function Ct(){let t=!1,e=0,s=0,o=0,a=0;N.addEventListener("mousedown",l=>{let r=l.target;if(r.closest("[data-action]")||!r.closest(".om-grab")&&!r.closest(".om-pill-brand"))return;t=!0,e=l.clientX,s=l.clientY;let p=N.getBoundingClientRect();o=p.left,a=p.top,l.preventDefault()}),document.addEventListener("mousemove",l=>{t&&(N.style.left=o+l.clientX-e+"px",N.style.top=a+l.clientY-s+"px",N.style.right="auto",N.style.bottom="auto")}),document.addEventListener("mouseup",()=>{if(t){t=!1;try{localStorage.setItem("__om_pos__",JSON.stringify({left:N.style.left,top:N.style.top}))}catch{}}})}function z(t){let e=document.createElement("div");return e.textContent=t,e.innerHTML}function Ht(t){let e=t.replace(/\\n/g,`
|
|
495
|
+
`),s=z(e);return s=s.replace(/```(\w*)\n([\s\S]*?)```/g,'<pre class="om-code-block"><code>$2</code></pre>'),s=s.replace(/`([^`]+)`/g,'<code class="om-inline-code">$1</code>'),s=s.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),s=s.replace(/([^*]|^)\*([^*]+)\*([^*]|$)/g,"$1<em>$2</em>$3"),s=s.replace(/^- (.+)$/gm,"• $1"),s=s.replace(/\n/g,"<br>"),s}async function Ye(t){let e=[],s=null;try{ke()&&(s=(await Promise.race([C("debug.logs"),new Promise((g,b)=>setTimeout(()=>b(new Error("timeout")),3e3))]))?.payload||null)}catch{}e.push("## Environment"),e.push(""),e.push(`- **OpenMagic**: v${Te}${n.updateAvailable?` (v${n.latestVersion} available)`:""}`),e.push(`- **Browser**: ${navigator.userAgent}`),e.push(`- **Platform**: ${navigator.platform}`),e.push(`- **Viewport**: ${window.innerWidth}x${window.innerHeight} (devicePixelRatio: ${window.devicePixelRatio})`),e.push(`- **Page URL**: ${window.location.href}`),e.push(`- **Page Title**: ${document.title}`),s&&(e.push(`- **Node.js**: ${s.nodeVersion} (${s.platform}/${s.arch})`),e.push(`- **Server PID**: ${s.pid}`),e.push(`- **Server Uptime**: ${s.uptime}s`),e.push(`- **Server Memory**: ${s.memoryMB}MB RSS`),e.push(`- **Server CWD**: ${s.cwd}`)),e.push(""),e.push("## Configuration"),e.push(""),e.push(`- **WebSocket**: ${n.connected?"connected":"disconnected"}`),e.push(`- **Provider**: ${W[n.provider]?.name||n.provider||"not set"}`),e.push(`- **Model**: ${n.model||"not set"}`),e.push(`- **API Key Set**: ${n.hasApiKey?"yes":"no"}`);let o=Object.entries(n.configuredProviders).filter(([,i])=>i).map(([i])=>W[i]?.name||i);if(o.length&&e.push(`- **Configured Providers**: ${o.join(", ")}`),n.roots.length&&e.push(`- **Project Roots**: ${n.roots.join(", ")}`),n.selectedElement){let i=n.selectedElement;e.push(""),e.push("## Selected Element"),e.push(""),e.push(`- **Selector**: \`${i.cssSelector||""}\``),e.push(`- **Tag**: \`${i.tagName}\``),i.id&&e.push(`- **ID**: \`${i.id}\``),i.className&&e.push(`- **Class**: \`${i.className}\``),i.componentHint&&e.push(`- **Component**: \`${i.componentHint}\``),i.ancestry?.length&&e.push(`- **Ancestry**: ${i.ancestry.join(" > ")}`),i.textContent&&e.push(`- **Text**: ${i.textContent.slice(0,150)}`)}if(n.groundedFiles.length){e.push(""),e.push("## Files Sent to LLM"),e.push("");for(let i of n.groundedFiles)e.push(`- \`${i}\``)}let a=[];for(let i of n.messages)if(i.content.startsWith("__DIFF__"))try{let g=JSON.parse(Q(i.content.slice(8)));a.push({file:g.file,type:g.type||"edit"})}catch{}if(a.length){e.push(""),e.push("## Proposed Changes"),e.push("");for(let i of a)e.push(`- \`${i.file}\` (${i.type})`)}let l=n.messages.filter(i=>i.role==="system"&&(i.content.startsWith("Applied change to ")||i.content.startsWith("Rejected change to ")||i.content.startsWith("Reverted change to ")||i.content.startsWith("Created ")||i.content.startsWith("Change rejected")||i.content.startsWith("No matching code")||i.content.startsWith("Write failed")||i.content.startsWith("Could not read")));if(l.length){e.push(""),e.push("## Applied/Rejected Changes"),e.push("");for(let i of l)e.push(`- ${i.content.slice(0,200)}`)}let r=window.performance,p=r.getEntriesByType("navigation")[0],c=r.getEntriesByType("paint");if(p){e.push(""),e.push("## Page Performance"),e.push(""),e.push(`- **Page Load**: ${Math.round(p.loadEventEnd-p.startTime)}ms`),e.push(`- **DOM Ready**: ${Math.round(p.domContentLoadedEventEnd-p.startTime)}ms`),e.push(`- **TTFB**: ${Math.round(p.responseStart-p.startTime)}ms`);let i=c.find(g=>g.name==="first-contentful-paint");i&&e.push(`- **FCP**: ${Math.round(i.startTime)}ms`)}let m=de();if(m.length){let i=m.filter(d=>d.level==="error"),g=m.filter(d=>d.level==="warn"),b=m.filter(d=>d.level==="log"||d.level==="info"||d.level==="debug");if(e.push(""),e.push("## Browser Console"),e.push(""),e.push(`Total: ${m.length} entries (${i.length} errors, ${g.length} warnings, ${b.length} log/info/debug)`),i.length){e.push(""),e.push(`### Errors (${i.length})`),e.push("```");for(let d of i.slice(-15))e.push(`[${new Date(d.timestamp).toISOString()}] ${d.args.map(f=>String(f)).join(" ").slice(0,300)}`);e.push("```")}if(g.length){e.push(""),e.push(`### Warnings (${g.length})`),e.push("```");for(let d of g.slice(-10))e.push(`[${new Date(d.timestamp).toISOString()}] ${d.args.map(f=>String(f)).join(" ").slice(0,200)}`);e.push("```")}if(b.length){e.push(""),e.push("<details><summary>Log/Info/Debug ("+b.length+" entries)</summary>"),e.push(""),e.push("```");for(let d of b.slice(-30))e.push(`[${new Date(d.timestamp).toISOString()}] [${d.level}] ${d.args.map(f=>String(f)).join(" ").slice(0,200)}`);e.push("```"),e.push("</details>")}}let u=ce(),v=u.filter(i=>i.status&&i.status>=400),$=u.filter(i=>i.duration&&i.duration>2e3);if(v.length||$.length){if(e.push(""),e.push("## Network Issues"),e.push(""),v.length){e.push(`### Failed Requests (${v.length})`),e.push("```");for(let i of v.slice(-15))e.push(`${i.method} ${i.url.slice(0,120)} \u2192 ${i.status} (${i.duration||"?"}ms)`);e.push("```")}if($.length){e.push(`### Slow Requests >2s (${$.length})`),e.push("```");for(let i of $.slice(-10))e.push(`${i.method} ${i.url.slice(0,120)} \u2192 ${i.status} (${i.duration}ms)`);e.push("```")}}if(s?.logs?.length){let i=s.logs,g=i.filter(f=>f.level==="error"),b=i.filter(f=>f.level==="warn"),d=i.filter(f=>f.level==="log"||f.level==="info");if(e.push(""),e.push("## Server Logs (Terminal)"),e.push(""),e.push(`Total: ${i.length} entries (${g.length} errors, ${b.length} warnings, ${d.length} log/info)`),g.length){e.push(""),e.push(`### Server Errors (${g.length})`),e.push("```");for(let f of g.slice(-15))e.push(`[${new Date(f.ts).toISOString()}] ${f.msg.slice(0,300)}`);e.push("```")}if(b.length){e.push(""),e.push(`### Server Warnings (${b.length})`),e.push("```");for(let f of b.slice(-10))e.push(`[${new Date(f.ts).toISOString()}] ${f.msg.slice(0,200)}`);e.push("```")}e.push(""),e.push("<details><summary>All server logs ("+i.length+" entries)</summary>"),e.push(""),e.push("```");for(let f of i.slice(-50))e.push(`[${new Date(f.ts).toISOString()}] [${f.level}] ${f.msg.slice(0,200)}`);e.push("```"),e.push("</details>")}if(n.messages.length){e.push(""),e.push("## Chat History"),e.push(""),e.push("<details><summary>Full conversation ("+n.messages.length+" messages)</summary>"),e.push(""),e.push("```");for(let i of n.messages)if(!i.content.startsWith("__DIFFGROUP__")){if(i.content.startsWith("__DIFF__")){try{let g=JSON.parse(Q(i.content.slice(8)));e.push(`[diff] ${g.type||"edit"}: ${g.file}`),g.search&&e.push(` - search: ${g.search.slice(0,100)}...`),g.replace&&e.push(` + replace: ${g.replace.slice(0,100)}...`)}catch{e.push("[diff] (parse error)")}continue}e.push(`[${i.role}] ${i.content.slice(0,500)}`)}e.push("```"),e.push("</details>")}if(t!==void 0){let i=n.messages[t];i&&(e.push(""),e.push("## Copied Message"),e.push(""),e.push("```"),e.push(`[${i.role}] ${i.content.slice(0,2e3)}`),e.push("```"))}return e.join(`
|
|
496
|
+
`)}function Pt(){fetch("https://registry.npmjs.org/openmagic/latest",{headers:{Accept:"application/json"},signal:AbortSignal.timeout(5e3)}).then(t=>t.ok?t.json():null).then(t=>{if(!t||typeof t.version!="string"||!/^\d+\.\d+\.\d+/.test(t.version))return;let e=t.version.split(".").map(Number),s=Te.split(".").map(Number);for(let o=0;o<3;o++){if((e[o]||0)>(s[o]||0)){n.updateAvailable=!0,n.latestVersion=t.version,_t();return}if((e[o]||0)<(s[o]||0))return}}).catch(()=>{})}function _t(){ue()}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ke):Ke());})();
|
|
497
497
|
//# sourceMappingURL=index.global.js.map
|