openmagic 0.31.2 → 0.31.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.
|
@@ -81,20 +81,18 @@
|
|
|
81
81
|
.om-pill-btn:hover { background: rgba(108, 92, 231, 0.15); color: #a29bfe; }
|
|
82
82
|
.om-pill-btn:focus-visible { outline: 2px solid #6c5ce7; outline-offset: 2px; }
|
|
83
83
|
.om-pill-btn.active { background: rgba(108, 92, 231, 0.25); color: #c4b5fd; }
|
|
84
|
-
.om-
|
|
85
|
-
|
|
84
|
+
.om-panel-bug {
|
|
85
|
+
background: none; border: none; color: #666; cursor: pointer; padding: 2px 4px;
|
|
86
|
+
border-radius: 4px; line-height: 1; display: flex; align-items: center;
|
|
87
|
+
}
|
|
88
|
+
.om-panel-bug:hover { color: #e94560; background: rgba(233, 69, 96, 0.1); }
|
|
86
89
|
|
|
87
90
|
.om-status-dot {
|
|
88
91
|
width: 7px; height: 7px; border-radius: 50%; margin-left: auto; flex-shrink: 0;
|
|
89
92
|
}
|
|
90
93
|
.om-status-dot.connected { background: #00b894; }
|
|
91
94
|
.om-status-dot.disconnected { background: #e94560; }
|
|
92
|
-
|
|
93
|
-
.om-update-dot {
|
|
94
|
-
width: 7px; height: 7px; border-radius: 50%; background: #fdcb6e;
|
|
95
|
-
margin-left: 4px; cursor: pointer; flex-shrink: 0;
|
|
96
|
-
animation: om-pulse 2s ease infinite;
|
|
97
|
-
}
|
|
95
|
+
.om-status-dot.outdated { background: #fdcb6e; animation: om-pulse 2s ease infinite; }
|
|
98
96
|
@keyframes om-pulse {
|
|
99
97
|
0%, 100% { box-shadow: 0 0 0 0 rgba(253,203,110,0.4); }
|
|
100
98
|
50% { box-shadow: 0 0 0 5px rgba(253,203,110,0); }
|
|
@@ -374,29 +372,28 @@
|
|
|
374
372
|
.om-msg:hover .om-copy-btn { opacity: 1; }
|
|
375
373
|
.om-copy-btn:hover { color: #ccc; background: rgba(0,0,0,0.5); }
|
|
376
374
|
.om-msg { position: relative; }
|
|
377
|
-
`;var _=null,C=new Map,
|
|
378
|
-
`);o=`<${
|
|
379
|
-
${
|
|
380
|
-
${
|
|
381
|
-
</${
|
|
375
|
+
`;var _=null,C=new Map,G=[],ge=[],B=!1,Le=!1,ue=null,he=0;function fe(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function ye(t,e){return Le=!0,new Promise((s,o)=>{let a=!1,i=setTimeout(()=>{a||(a=!0,o(new Error("Handshake timeout")),_?.close())},1e4);try{let r=window.location.hostname||"127.0.0.1",m=window.location.protocol==="https:"?"wss:":"ws:";_=new WebSocket(`${m}//${r}:${t}/__openmagic__/ws`),_.onopen=()=>{let c=fe();_.send(JSON.stringify({id:c,type:"handshake",payload:{token:e}})),C.set(c,p=>{if(p.type==="handshake.ok"){clearTimeout(i),B=!0,he=0;for(let d of ge)_?.send(d);ge=[],a||(a=!0,s())}else p.type==="error"&&(clearTimeout(i),a||(a=!0,o(new Error(p.payload?.message||"Handshake failed"))))})},_.onmessage=c=>{try{let p=JSON.parse(c.data);p.id&&C.has(p.id)&&(C.get(p.id)(p),(p.type==="llm.done"||p.type==="llm.error"||!p.type.startsWith("llm."))&&C.delete(p.id));for(let d of G)d(p)}catch{}},_.onclose=()=>{let c=B;if(B=!1,C.forEach((p,d)=>{p({type:"error",id:d,payload:{message:"Connection lost"}})}),C.clear(),!c&&!a){clearTimeout(i),a=!0,o(new Error("WebSocket closed before handshake"));return}if(c&&Le&&!ue){let p=Math.min(2e3*Math.pow(1.5,he),3e4);he++,ue=setTimeout(()=>{ue=null,ye(t,e).then(()=>{for(let d of G)d({type:"reconnected",payload:{}})}).catch(()=>{})},p)}},_.onerror=()=>{!B&&!a&&(clearTimeout(i),a=!0,o(new Error("WebSocket connection failed")))}}catch(r){clearTimeout(i),a||(a=!0,o(r))}})}function Te(t){let e=JSON.stringify(t);_&&_.readyState===WebSocket.OPEN&&B?_.send(e):ge.push(e)}function S(t,e){return new Promise((s,o)=>{let a=fe(),i=setTimeout(()=>{C.delete(a),o(new Error("Request timeout"))},3e4);C.set(a,r=>{clearTimeout(i),r.type==="error"?o(new Error(r.payload?.message||"Unknown error")):s(r)}),Te({id:a,type:t,payload:e})})}function Ce(t,e,s){return new Promise((o,a)=>{let i=fe(),r=setTimeout(()=>{C.delete(i),a(new Error("Stream timeout"))},12e4);C.set(i,m=>{m.type==="llm.chunk"?s(m.payload?.delta||""):m.type==="llm.done"?(clearTimeout(r),C.delete(i),o(m.payload)):(m.type==="llm.error"||m.type==="error")&&(clearTimeout(r),C.delete(i),a(new Error(m.payload?.message||"Stream error")))}),Te({id:i,type:t,payload:e})})}function He(t){return G.push(t),()=>{G=G.filter(e=>e!==t)}}function Pe(){return B}var _e=["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 Re(t){let e=window.getComputedStyle(t),s={};for(let d of _e)s[d]=e.getPropertyValue(d);let o=t.getBoundingClientRect(),a={};if(t.parentElement&&t.parentElement!==document.body){let d=window.getComputedStyle(t.parentElement);for(let y of _e)a[y]=d.getPropertyValue(y)}let i=[];if(t.parentElement){let d=Array.from(t.parentElement.children),y=d.indexOf(t),u=Math.max(0,y-3),b=Math.min(d.length,y+4);u>0&&i.push(`... ${u} elements before ...`);for(let l=u;l<b;l++){let h=d[l],f=h.tagName.toLowerCase(),$=(h.className||"").toString().slice(0,60);h===t?i.push(`[SELECTED] <${f} class="${$}">`):i.push(`<${f} class="${$}">`)}b<d.length&&i.push(`... ${d.length-b} elements after ...`)}let r=at(t),m={};for(let d of Array.from(t.attributes))(d.name.startsWith("aria-")||d.name==="role"||d.name==="tabindex")&&(m[d.name]=d.value);let c=[];for(let d of Array.from(t.attributes))d.name.startsWith("on")&&c.push(d.name);let p=rt(t);return{tagName:t.tagName.toLowerCase(),id:t.id||"",className:t.className||"",textContent:(t.textContent||"").trim().slice(0,200),outerHTML:nt(t),cssSelector:ot(t),xpath:st(t),computedStyles:s,ancestry:et(t),componentHint:tt(t),rect:{x:o.x,y:o.y,width:o.width,height:o.height},parentStyles:a,siblings:i,matchedCssRules:r,viewport:{width:window.innerWidth,height:window.innerHeight},ariaAttributes:m,eventHandlers:c,reactProps:p}}function et(t,e=5){let s=[],o=t.parentElement;for(;o&&o!==document.body&&s.length<e;){let a=o.tagName.toLowerCase(),i=(typeof o.className=="string"?o.className:"").split(/\s+/).filter(r=>r.length>1&&!r.startsWith("_")).slice(0,3).join(".");s.push(i?`${a}.${i}`:a),o=o.parentElement}return s}function tt(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 i=e[a],r=i?.type?.name||i?.type?.displayName||i?.return?.type?.name||i?.return?.type?.displayName;if(r&&r!=="div"&&r!=="span"&&r.length>1)return r}catch{}e=e.parentElement}return""}function nt(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(),i=Array.from(t.attributes).map(m=>`${m.name}="${m.value}"`).join(" "),r=Array.from(t.children).slice(0,5).map(m=>`<${m.tagName.toLowerCase()} .../>`).join(`
|
|
376
|
+
`);o=`<${a} ${i}>
|
|
377
|
+
${r}
|
|
378
|
+
${t.children.length>5?`<!-- +${t.children.length-5} more children -->`:""}
|
|
379
|
+
</${a}>`}return o}function ot(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 i=s.className.trim().split(/\s+/).filter(r=>!r.startsWith("__")&&r.length<30).slice(0,2).map(r=>CSS.escape(r));i.length>0&&(o+="."+i.join("."))}let a=s.parentElement;if(a){let i=Array.from(a.children).filter(r=>r.tagName===s.tagName);if(i.length>1){let r=i.indexOf(s)+1;o+=`:nth-of-type(${r})`}}e.unshift(o),s=s.parentElement}return e.join(" > ")}function st(t){let e=[],s=t;for(;s&&s!==document;){if(s.nodeType===Node.ELEMENT_NODE){let o=s,a=1,i=o.previousElementSibling;for(;i;)i.tagName===o.tagName&&a++,i=i.previousElementSibling;e.unshift(`${o.tagName.toLowerCase()}[${a}]`)}s=s.parentNode}return"/"+e.join("/")}function at(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 i=a.cssText;i.length>10&&i.length<500&&e.push(i)}}catch{}}catch{}}catch{}return e.slice(0,15)}function rt(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,i={},r=0;for(let[m,c]of Object.entries(a)){if(r>=10)break;if(m==="children")continue;let p=typeof c;p==="string"||p==="number"||p==="boolean"||c===null?(i[m]=c,r++):p==="function"?(i[m]="[function]",r++):Array.isArray(c)&&(i[m]=`[Array(${c.length})]`,r++)}return Object.keys(i).length>0?i:null}}catch{}return null}var H=null;function Ne(t){H||(H=document.createElement("div"),H.style.cssText=`
|
|
382
380
|
position: fixed;
|
|
383
381
|
pointer-events: none;
|
|
384
382
|
z-index: 2147483646;
|
|
385
383
|
border: 2px solid #6c5ce7;
|
|
386
384
|
background: rgba(108, 92, 231, 0.1);
|
|
387
385
|
transition: all 0.1s ease;
|
|
388
|
-
`,H.dataset.openmagic="highlight",document.body.appendChild(H)),H.style.left=`${
|
|
386
|
+
`,H.dataset.openmagic="highlight",document.body.appendChild(H)),H.style.left=`${t.x}px`,H.style.top=`${t.y}px`,H.style.width=`${t.width}px`,H.style.height=`${t.height}px`,H.style.display="block"}function Ae(){H&&(H.style.display="none")}async function Oe(t){try{let e=t||document.body,s=await it(e);if(s)return{data:s}}catch{}try{let e=await lt(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 it(t){let e=t.getBoundingClientRect(),s=Math.min(e.width||window.innerWidth,1920),o=Math.min(e.height||window.innerHeight,1080),a=qe(t,0,4);if(!a)return null;let i=`
|
|
389
387
|
<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${o}">
|
|
390
388
|
<foreignObject width="100%" height="100%">
|
|
391
389
|
<div xmlns="http://www.w3.org/1999/xhtml" style="width:${s}px;height:${o}px;overflow:hidden;">
|
|
392
|
-
${
|
|
390
|
+
${a.outerHTML}
|
|
393
391
|
</div>
|
|
394
392
|
</foreignObject>
|
|
395
|
-
</svg>`,a=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),c=URL.createObjectURL(a);return new Promise(l=>{let p=new Image,d=document.createElement("canvas"),f=Math.min(window.devicePixelRatio||1,2);d.width=s*f,d.height=o*f,p.onload=()=>{URL.revokeObjectURL(c);let m=d.getContext("2d");if(!m){l(null);return}m.scale(f,f),m.drawImage(p,0,0);try{l(d.toDataURL("image/png",.8))}catch{l(null)}},p.onerror=()=>{URL.revokeObjectURL(c),l(null)},setTimeout(()=>{URL.revokeObjectURL(c),l(null)},5e3),p.src=c})}async function lt(e){let t=e||document.documentElement,s=t.getBoundingClientRect(),o=document.createElement("canvas");o.width=400,o.height=300;let r=o.getContext("2d");return r?(r.fillStyle="#1a1a2e",r.fillRect(0,0,400,300),r.fillStyle="#e0e0e0",r.font="14px system-ui",r.fillText(`Element: <${t.tagName.toLowerCase()}>`,20,30),r.fillStyle="#888",r.font="12px system-ui",r.fillText(`Size: ${Math.round(s.width)}x${Math.round(s.height)}`,20,55),r.fillText(`Classes: ${(t.className||"").toString().slice(0,40)}`,20,75),r.fillText(`Page: ${window.location.pathname}`,20,95),r.fillStyle="#6c5ce7",r.font="11px system-ui",r.fillText("(Full screenshot unavailable \u2014 context sent as metadata)",20,130),o.toDataURL("image/png")):null}function qe(e,t,s){if(t>s)return null;try{let o=e.cloneNode(!1);if(o.tagName==="SCRIPT"||o.tagName==="STYLE"||o.tagName==="SVG"||o.tagName==="CANVAS"||o.tagName==="VIDEO"||o.tagName==="IFRAME")return null;let r=window.getComputedStyle(e),i=["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"],a="";for(let c of i){let l=r.getPropertyValue(c);l&&l!=="normal"&&l!=="none"&&l!=="auto"&&l!=="0px"&&(a+=`${c}:${l};`)}o.setAttribute("style",a);for(let c=0;c<e.children.length&&c<20;c++){let l=qe(e.children[c],t+1,s);l&&o.appendChild(l)}return o}catch{return null}}var Q=[];var ze=!1;function Ie(){if(ze)return;ze=!0;let e=window.fetch;window.fetch=async function(...o){let r=new Request(...o),i={method:r.method,url:r.url,timestamp:Date.now()};try{let a=await e.apply(this,o);return i.status=a.status,i.duration=Date.now()-i.timestamp,ye(i),a}catch(a){throw i.status=0,i.duration=Date.now()-i.timestamp,ye(i),a}};let t=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,r,...i){return this.__om_method=o,this.__om_url=r,this.__om_start=Date.now(),t.apply(this,[o,r,...i])},XMLHttpRequest.prototype.send=function(...o){return this.addEventListener("loadend",()=>{ye({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 ye(e){e.url.includes("__openmagic__")||(Q.push(e),Q.length>50&&Q.shift())}function te(){return[...Q]}var ee=[],ct=100,De=!1;function Be(){if(De)return;De=!0;let e=["log","warn","error","info","debug"];for(let t of e){let s=console[t];console[t]=function(...o){ee.push({level:t,args:o.map(r=>{try{return typeof r=="object"?JSON.stringify(r).slice(0,500):String(r)}catch{return String(r)}}),timestamp:Date.now()}),ee.length>ct&&ee.shift(),s.apply(console,o)}}}function ne(){return[...ee]}function je(e,t){return{selectedElement:e?{tagName:e.tagName,id:e.id,className:e.className,textContent:e.textContent,outerHTML:e.outerHTML,cssSelector:e.cssSelector,computedStyles:e.computedStyles}:void 0,screenshot:t||void 0,networkLogs:te().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:ne().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var x={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>'},B={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 se(e){let t=new TextEncoder().encode(e),s="";for(let o=0;o<t.length;o+=32768)s+=String.fromCharCode(...t.subarray(o,o+32768));return btoa(s)}function ae(e){let t=atob(e),s=new Uint8Array(t.length);for(let o=0;o<t.length;o++)s[o]=t.charCodeAt(o);return new TextDecoder().decode(s)}var Se="0.31.2",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},w,E,z,Ve,$e,R;function dt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function pt(){try{let e=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");e.messages?.length&&(n.messages=e.messages),e.provider&&(n.provider=e.provider),e.model&&(n.model=e.model),e.panelOpen&&(n.panelOpen=e.panelOpen,n.activePanel=e.activePanel||"")}catch{}}function Fe(){if(document.querySelector("openmagic-toolbar"))return;pt();let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",w=e.attachShadow({mode:"closed"});let t=document.createElement("style");t.textContent=Me,w.appendChild(t);let s=document.createElement("div");w.appendChild(s),s.innerHTML=mt(),E=s.querySelector(".om-toolbar"),z=s.querySelector(".om-prompt-input"),Ve=s.querySelector(".om-prompt-context"),$e=s.querySelector(".om-panel"),R=s.querySelector(".om-panel-body"),document.body.appendChild(e),ut(s),Et();try{let a=JSON.parse(localStorage.getItem("__om_pos__")||"");a?.left&&a?.top&&(E.style.left=a.left,E.style.top=a.top,E.style.right="auto",E.style.bottom="auto")}catch{}Ie(),Be(),Lt();let r=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,i=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);r&&fe(i,r).then(()=>(n.connected=!0,ve(),$("config.get"))).then(a=>{let c=a.payload?.provider||"",l=a.payload?.model||"";n.provider=n.provider||c,n.model=n.model||l,n.configuredProviders=a.payload?.apiKeys||{},n.hasApiKey=n.configuredProviders[n.provider]||!1,n.roots=a.payload?.roots||[],n.panelOpen&&n.activePanel?O(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&O("settings"),J()}).catch(()=>{n.connected=!1,ve()})}function mt(){return`
|
|
393
|
+
</svg>`,r=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),m=URL.createObjectURL(r);return new Promise(c=>{let p=new Image,d=document.createElement("canvas"),y=Math.min(window.devicePixelRatio||1,2);d.width=s*y,d.height=o*y,p.onload=()=>{URL.revokeObjectURL(m);let u=d.getContext("2d");if(!u){c(null);return}u.scale(y,y),u.drawImage(p,0,0);try{c(d.toDataURL("image/png",.8))}catch{c(null)}},p.onerror=()=>{URL.revokeObjectURL(m),c(null)},setTimeout(()=>{URL.revokeObjectURL(m),c(null)},5e3),p.src=m})}async function lt(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 qe(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),i=["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 m of i){let c=a.getPropertyValue(m);c&&c!=="normal"&&c!=="none"&&c!=="auto"&&c!=="0px"&&(r+=`${m}:${c};`)}o.setAttribute("style",r);for(let m=0;m<t.children.length&&m<20;m++){let c=qe(t.children[m],e+1,s);c&&o.appendChild(c)}return o}catch{return null}}var ee=[];var De=!1;function je(){if(De)return;De=!0;let t=window.fetch;window.fetch=async function(...o){let a=new Request(...o),i={method:a.method,url:a.url,timestamp:Date.now()};try{let r=await t.apply(this,o);return i.status=r.status,i.duration=Date.now()-i.timestamp,be(i),r}catch(r){throw i.status=0,i.duration=Date.now()-i.timestamp,be(i),r}};let e=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,a,...i){return this.__om_method=o,this.__om_url=a,this.__om_start=Date.now(),e.apply(this,[o,a,...i])},XMLHttpRequest.prototype.send=function(...o){return this.addEventListener("loadend",()=>{be({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 be(t){t.url.includes("__openmagic__")||(ee.push(t),ee.length>50&&ee.shift())}function ne(){return[...ee]}var te=[],ct=100,Ie=!1;function ze(){if(Ie)return;Ie=!0;let t=["log","warn","error","info","debug"];for(let e of t){let s=console[e];console[e]=function(...o){te.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()}),te.length>ct&&te.shift(),s.apply(console,o)}}}function oe(){return[...te]}function Be(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:ne().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:oe().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var x={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>'},D={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 ae(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 F(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 $e="0.31.4",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},w,E,q,Ve,Se,N;function dt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function pt(){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 Fe(){if(document.querySelector("openmagic-toolbar"))return;pt();let t=document.createElement("openmagic-toolbar");t.dataset.openmagic="true",w=t.attachShadow({mode:"closed"});let e=document.createElement("style");e.textContent=Me,w.appendChild(e);let s=document.createElement("div");w.appendChild(s),s.innerHTML=mt(),E=s.querySelector(".om-toolbar"),q=s.querySelector(".om-prompt-input"),Ve=s.querySelector(".om-prompt-context"),Se=s.querySelector(".om-panel"),N=s.querySelector(".om-panel-body"),document.body.appendChild(t),ut(s),Et();try{let r=JSON.parse(localStorage.getItem("__om_pos__")||"");r?.left&&r?.top&&(E.style.left=r.left,E.style.top=r.top,E.style.right="auto",E.style.bottom="auto")}catch{}je(),ze(),Lt();let a=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,i=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);a&&ye(i,a).then(()=>(n.connected=!0,re(),S("config.get"))).then(r=>{let m=r.payload?.provider||"",c=r.payload?.model||"";n.provider=n.provider||m,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?I(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&I("settings"),Y()}).catch(()=>{n.connected=!1,re()})}function mt(){return`
|
|
396
394
|
<div class="om-toolbar">
|
|
397
395
|
<div class="om-toolbar-header">
|
|
398
396
|
<span class="om-grab">${x.grip}</span>
|
|
399
|
-
<button class="om-pill-btn om-pill-btn-bug" data-action="report-issue" title="Report a bug on GitHub">${x.bug}</button>
|
|
400
397
|
<span class="om-pill-brand">
|
|
401
398
|
<span class="om-pill-text">\u2728OpenMagic\u{1FA84}</span>
|
|
402
399
|
</span>
|
|
@@ -413,7 +410,8 @@
|
|
|
413
410
|
<div class="om-panel om-hidden">
|
|
414
411
|
<div class="om-panel-header">
|
|
415
412
|
<span class="om-panel-title"></span>
|
|
416
|
-
<span class="om-panel-version">v${
|
|
413
|
+
<span class="om-panel-version">v${$e}</span>
|
|
414
|
+
<button class="om-panel-bug" data-action="report-issue" title="Report a bug on GitHub">${x.bug}</button>
|
|
417
415
|
<button class="om-panel-clear" data-action="clear-chat" title="Clear chat">${x.trash}</button>
|
|
418
416
|
<button class="om-panel-close" data-action="close-panel">${x.x}</button>
|
|
419
417
|
</div>
|
|
@@ -434,10 +432,10 @@
|
|
|
434
432
|
<button class="om-prompt-send" data-action="prompt-send">${x.send}</button>
|
|
435
433
|
<input type="file" class="om-file-input om-hidden" accept="image/*" multiple />
|
|
436
434
|
</div>
|
|
437
|
-
</div>`}function ut(
|
|
438
|
-
`).map(
|
|
439
|
-
`),
|
|
440
|
-
`&&p--,{start:
|
|
435
|
+
</div>`}function ut(t){t.addEventListener("click",o=>{let a=o.target.closest("[data-action]");if(!a)return;o.preventDefault(),o.stopPropagation();let i=a.dataset.action;yt(i,a)}),t.addEventListener("change",o=>{let a=o.target,i=a.dataset.field;i&&(i==="provider"?(n.provider=a.value,n.model=D[n.provider]?.models[0]?.id||"",n.hasApiKey=n.configuredProviders[n.provider]||D[n.provider]?.local||!1,n.saveStatus="",M()):i==="model"&&(n.model=a.value))}),q.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),we())});let e=t.querySelector(".om-file-input");e&&e.addEventListener("change",()=>{ve(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&&ve(a.files)}),q.addEventListener("paste",o=>{let a=o.clipboardData?.items;if(a){for(let i=0;i<a.length;i++)if(a[i].type.startsWith("image/")){let r=a[i].getAsFile();if(r){let m=new DataTransfer;m.items.add(r),ve(m.files)}}}})),He(o=>{o.type==="reconnected"&&(n.connected=!0,re())}),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,E.querySelectorAll(".om-pill-btn:not([data-action='minimize']), .om-pill-divider, .om-status-dot").forEach(r=>r.style.display="");let i=w.querySelector(".om-prompt-row");i&&i.classList.remove("om-hidden")}else n.panelOpen?ie():I("chat");return}if(o.key==="Escape"){if(n.selecting)return;n.panelOpen&&(ie(),o.preventDefault())}}),q.addEventListener("keydown",o=>{(o.ctrlKey||o.metaKey)&&o.key==="Enter"&&(o.preventDefault(),we())})}function Je(t){return n.roots.length>0?n.roots[0]+"/"+t:t}function ht(t,e){let s=e.split(`
|
|
436
|
+
`).map(r=>r.trim()).filter(r=>r.length>0);if(s.length===0)return null;let o=t.split(`
|
|
437
|
+
`),a=s[0],i=s[s.length-1];for(let r=0;r<o.length;r++){if(o[r].trim()!==a||r+s.length>o.length)continue;let m=!0;for(let c=0;c<s.length;c++)if(o[r+c].trim()!==s[c]){m=!1;break}if(m){let c=0;for(let d=0;d<r;d++)c+=o[d].length+1;let p=c;for(let d=r;d<r+s.length;d++)p+=o[d].length+1;return p>0&&p<=t.length&&t[p-1]===`
|
|
438
|
+
`&&p--,{start:c,end:p}}}return null}async function Ue(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 i,r;try{i=F(s),r=F(o)}catch{n.messages.push({role:"system",content:`Failed to decode diff data for ${e}`}),M();return}let m=Je(e);try{if(!i&&r){if((await S("fs.write",{path:m,content:r}))?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${e}`});else{let h=a?.dataset.diffIdx;h!==void 0?n.messages[parseInt(h)]={role:"system",content:`Created ${e}`}:n.messages.push({role:"system",content:`Created ${e}`})}M(),U();return}let c,p=m,d=[m];e!==m&&d.push(e);let y=e.split("/").pop()||e,u=n.roots[0]||"",b=u?`${u}/${y}`:y;b!==m&&b!==e&&d.push(b);for(let l of d){let f=(await S("fs.read",{path:l}).catch(()=>null))?.payload?.content;if(f!=null&&String(f).length>0){c=String(f),p=l;break}}if(!c)n.messages.push({role:"system",content:`Could not read ${e} \u2014 tried: ${d.join(", ")}`});else{let l=c.split(i).length-1;if(l===1){let h=await S("fs.write",{path:p,content:c.replace(i,r)});if(h?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${e} - ${h.payload?.error||"unknown"}`});else{let f=a?.dataset.diffIdx;f!==void 0?n.messages[parseInt(f)]={role:"system",content:`Applied change to ${e}. Reloading...`}:n.messages.push({role:"system",content:`Applied change to ${e}. Reloading...`})}}else if(l>1)n.messages.push({role:"system",content:`Found ${l} exact matches in ${e} \u2014 expected 1. Edit not applied.`});else{let h=ht(c,i);if(h){let f=c.slice(0,h.start)+r+c.slice(h.end),$=await S("fs.write",{path:p,content:f});if($?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${e} - ${$.payload?.error||"unknown"}`});else{let k=a?.dataset.diffIdx;k!==void 0?n.messages[parseInt(k)]={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}`})}M(),U(),setTimeout(()=>{window.location.reload()},1500)}function We(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(F(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"}}}M(),U()}function gt(t){let e=w.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 Ke(){let t=w.querySelector(".om-apply-bar");t&&t.classList.add("om-hidden")}async function ft(t){let e=t.dataset.file;if(!e)return;let s=Je(e),o=s+".openmagic-backup";try{let i=(await S("fs.read",{path:o}))?.payload?.content;i?(await S("fs.write",{path:s,content:i}),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`})}M()}function yt(t,e){switch(t){case"select":$t();break;case"screenshot":St();break;case"chat":xe("chat");break;case"settings":xe("settings");break;case"close-panel":ie();break;case"prompt-send":we();break;case"save-settings":vt();break;case"get-key":{let s=e.dataset.url;s&&window.open(s,"_blank","noopener");break}case"change-key":{let s=w.querySelector("[data-key-change]");s&&s.classList.remove("om-hidden"),e.style.display="none";break}case"network":xe("chat"),wt();break;case"attach-image":kt();break;case"remove-attachment":{let s=parseInt(e.dataset.idx||"0",10);n.attachments.splice(s,1),Ee();break}case"apply-diff":Ue(e);break;case"reject-diff":We(e);break;case"apply-all":{let s=w.querySelectorAll('[data-action="apply-diff"]');for(let o of Array.from(s))Ue(o);Ke();break}case"reject-all":{let s=w.querySelectorAll('[data-action="reject-diff"]');for(let o of Array.from(s))We(o);Ke();break}case"undo-diff":ft(e);break;case"clear-chat":{n.messages=[];try{sessionStorage.removeItem("__om_state__")}catch{}M();break}case"copy-msg":{let s=parseInt(e.dataset.idx||"0",10),o=Ge(s);try{navigator.clipboard.writeText(o)}catch{}e.innerHTML=x.check,setTimeout(()=>{e.innerHTML=x.copy},1500);break}case"report-issue":{let s=Ge();try{navigator.clipboard.writeText(s)}catch{}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&&M();break}case"clear-element":n.selectedElement=null,X();break;case"clear-screenshot":n.screenshot=null,X();break;case"minimize":{n.minimized=!n.minimized;let s=w.querySelector(".om-panel"),o=w.querySelector(".om-prompt-row"),a=w.querySelector(".om-prompt-attachments"),i=E.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"),i.forEach(r=>r.style.display="none")):(o&&o.classList.remove("om-hidden"),a&&a.classList.remove("om-hidden"),i.forEach(r=>r.style.display=""),n.panelOpen&&n.activePanel&&s&&s.classList.remove("om-hidden"));break}}}function re(){let t=w.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 Y(){w.querySelectorAll(".om-pill-btn").forEach(t=>{let e=t.dataset.action;t.classList.toggle("active",e===n.activePanel||e==="select"&&n.selecting)})}function X(){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">${x.x}</button></span>`),n.screenshot&&t.push(`<span class="om-prompt-chip">Screenshot <button class="om-prompt-chip-x" data-action="clear-screenshot">${x.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>`),Ve.innerHTML=t.join("")}function I(t){n.panelOpen=!0,n.activePanel=t,Se.classList.remove("om-hidden");let e=w.querySelector(".om-panel-title");e&&(e.textContent=t==="settings"?"Settings":"Chat"),M(),Y()}function ie(){n.panelOpen=!1,n.activePanel="",Se.classList.add("om-hidden"),Y()}function xe(t){n.panelOpen&&n.activePanel===t?ie():I(t)}function M(){n.activePanel==="settings"?N.innerHTML=bt():n.activePanel==="chat"&&(N.innerHTML=xt(),U()),dt()}function bt(){let t=Object.entries(D).map(([b,l])=>{let f=n.configuredProviders[b]||l.local?" \u2713":"";return`<option value="${b}" ${n.provider===b?"selected":""}>${l.name}${f}</option>`}).join(""),e=D[n.provider],s=e?e.models.map(b=>`<option value="${b.id}" ${n.model===b.id?"selected":""}>${b.name}</option>`).join(""):'<option value="">Select provider first</option>',o=e?.local||!1,a=e?.keyUrl||"",i=e?.keyPlaceholder||"Enter API key...",r=n.configuredProviders[n.provider]||!1,m=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">${x.check} ${e?.name||"Provider"} connected</div>`:"",p=n.saveStatus==="saving"?'<span class="om-spinner"></span> Saving...':n.saveStatus==="saved"?`${x.check} Saved`:"Save",d=n.saveStatus==="saving"?"om-btn om-btn-saving":n.saveStatus==="saved"?"om-btn om-btn-saved":"om-btn",y=n.saveStatus==="saving"?"disabled":"",u="";return!o&&n.provider&&(r?u=`
|
|
441
439
|
<div class="om-field">
|
|
442
440
|
<label class="om-label">API Key</label>
|
|
443
441
|
<div class="om-key-configured">
|
|
@@ -447,51 +445,51 @@
|
|
|
447
445
|
<div class="om-key-change-row om-hidden" data-key-change>
|
|
448
446
|
<div class="om-key-row">
|
|
449
447
|
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${i}" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
|
450
|
-
${
|
|
448
|
+
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${x.externalLink} Get key</button>`:""}
|
|
451
449
|
</div>
|
|
452
450
|
</div>
|
|
453
|
-
</div>`:
|
|
451
|
+
</div>`:u=`
|
|
454
452
|
<div class="om-field">
|
|
455
453
|
<label class="om-label">API Key</label>
|
|
456
454
|
<div class="om-key-row">
|
|
457
455
|
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${i}" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
|
458
|
-
${
|
|
456
|
+
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${x.externalLink} Get key</button>`:""}
|
|
459
457
|
</div>
|
|
460
|
-
${
|
|
458
|
+
${a?`<div class="om-key-hint"><a data-action="get-key" data-url="${a}">Get your ${e?.name||""} API key here</a></div>`:""}
|
|
461
459
|
</div>`),`
|
|
462
|
-
${
|
|
460
|
+
${m}
|
|
463
461
|
<div class="om-settings">
|
|
464
462
|
<div class="om-field">
|
|
465
463
|
<label class="om-label">Provider</label>
|
|
466
|
-
<select class="om-select" data-field="provider"><option value="">Select Provider...</option>${
|
|
464
|
+
<select class="om-select" data-field="provider"><option value="">Select Provider...</option>${t}</select>
|
|
467
465
|
</div>
|
|
468
466
|
<div class="om-field">
|
|
469
467
|
<label class="om-label">Model</label>
|
|
470
468
|
<select class="om-select" data-field="model"><option value="">Select Model...</option>${s}</select>
|
|
471
469
|
</div>
|
|
472
|
-
${
|
|
473
|
-
<button class="${d}" data-action="save-settings" ${
|
|
474
|
-
${
|
|
475
|
-
</div>`}function xt(){if(!n.provider||!n.hasApiKey&&!
|
|
476
|
-
<div class="om-diff-file">${A(
|
|
477
|
-
${
|
|
478
|
-
<div class="om-diff-added">${A((
|
|
470
|
+
${u}
|
|
471
|
+
<button class="${d}" data-action="save-settings" ${y}>${p}</button>
|
|
472
|
+
${c}
|
|
473
|
+
</div>`}function xt(){if(!n.provider||!n.hasApiKey&&!D[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(F(o.content.slice(8))),m=r.type==="create"||!r.search&&r.replace,c=ae(r.search||""),p=ae(r.replace||"");return`<div class="om-diff-card" data-diff-idx="${a}">
|
|
474
|
+
<div class="om-diff-file">${A(m?"Create new file":"Edit")}: ${A(r.file)}</div>
|
|
475
|
+
${r.search?`<div class="om-diff-removed">${A(r.search.slice(0,200))}</div>`:""}
|
|
476
|
+
<div class="om-diff-added">${A((r.replace||"").slice(0,300))}</div>
|
|
479
477
|
<div class="om-diff-actions">
|
|
480
|
-
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${A(
|
|
481
|
-
<button class="om-btn-secondary om-btn-sm" data-action="reject-diff" data-idx="${
|
|
478
|
+
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${A(r.file)}" data-search="${c}" data-replace="${p}">Apply</button>
|
|
479
|
+
<button class="om-btn-secondary om-btn-sm" data-action="reject-diff" data-idx="${a}">Reject</button>
|
|
482
480
|
</div>
|
|
483
|
-
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(o.content.startsWith("Applied change to ")){let
|
|
484
|
-
// [FILE TRUNCATED \u2014 showing ${
|
|
485
|
-
// [FILE TRUNCATED \u2014 showing ${
|
|
486
|
-
// [FILE TRUNCATED \u2014 showing ${
|
|
487
|
-
All network requests (${p.length}):`);for(let d of p.slice(-30)){let
|
|
488
|
-
Fetch/XHR requests (${
|
|
489
|
-
Console errors: ${
|
|
490
|
-
Slowest resources:`);for(let p of
|
|
491
|
-
`)}),M(),
|
|
492
|
-
<img src="${
|
|
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">${A(o.content)} <button class="om-undo-btn" data-action="undo-diff" data-file="${A(r)}">Undo</button></div>`}let i=o.role==="user"||o.role==="assistant"?`<button class="om-copy-btn" data-action="copy-msg" data-idx="${a}" title="Copy">${x.copy}</button>`:"";return o.role==="assistant"?`<div class="om-msg om-msg-assistant">${Mt(o.content)}${i}</div>`:`<div class="om-msg om-msg-${o.role}">${A(o.content)}${i}</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 U(){requestAnimationFrame(()=>{let t=N.querySelector(".om-chat-messages");t&&(t.scrollTop=t.scrollHeight)})}async function vt(){let e=N.querySelector('[data-field="apiKey"]')?.value||"";if(!n.provider){n.saveStatus="error",se(),setTimeout(()=>{n.saveStatus="",M()},2e3);return}if(!Pe()){n.saveStatus="error",se();let o=N.querySelector('[data-action="save-settings"]');o&&(o.innerHTML="Not connected - check terminal"),setTimeout(()=>{n.saveStatus="",M()},3e3);return}let s={provider:n.provider,model:n.model};e&&(s.apiKey=e),n.saveStatus="saving",se();try{let o=await Promise.race([S("config.set",s),new Promise((a,i)=>setTimeout(()=>i(new Error("Save timed out")),8e3))]);e&&n.provider&&(n.configuredProviders[n.provider]=!0),n.hasApiKey=!!(e||n.configuredProviders[n.provider]),n.saveStatus="saved",se(),setTimeout(()=>{n.saveStatus="",n.activePanel==="settings"&&I("chat")},1200)}catch(o){n.saveStatus="error";let a=N.querySelector('[data-action="save-settings"]'),i=(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=i,a.className="om-btn",a.disabled=!1),setTimeout(()=>{n.saveStatus="",M()},4e3)}}function se(){let t=N.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=`${x.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 we(){let t=q.value.trim();if(!t||n.streaming)return;if(!n.provider||!n.hasApiKey&&!D[n.provider]?.local){I("settings");return}n.messages.push({role:"user",content:t}),n.streaming=!0,n.streamContent="",q.value="",I("chat");let e=Be(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,i=N.querySelector(".om-msg-assistant:last-child");i&&(i.innerHTML='<span class="om-spinner"></span> Reading project files...');try{let c=await S("fs.list",{});c?.payload?.projectTree&&(e.projectTree=c.payload.projectTree);let d=(c?.payload?.files||[]).filter(g=>g.type==="file"&&a.test(g.path)),y=[t];if(n.selectedElement&&(n.selectedElement.id&&y.push(n.selectedElement.id),n.selectedElement.className&&y.push(n.selectedElement.className),n.selectedElement.textContent&&y.push(n.selectedElement.textContent.slice(0,100)),n.selectedElement.componentHint&&y.push(n.selectedElement.componentHint),n.selectedElement.ancestry))for(let g of n.selectedElement.ancestry)y.push(g);let u=y.filter(Boolean).join(" ").toLowerCase().split(/[^a-z0-9_-]+/).filter(g=>g.length>=2&&!["the","to","in","of","and","div","span","class","style"].includes(g)),l=window.location.pathname.split("/").filter(g=>g.length>1&&!/^\d+$/.test(g)),h=d.map(g=>{let v=0,L=g.path.toLowerCase();for(let R of l)L.includes(R.toLowerCase())&&(v+=15);if(n.selectedElement?.componentHint){let R=n.selectedElement.componentHint.toLowerCase();L.includes(R)&&(v+=12)}for(let R of u)L.includes(R)&&(v+=5);return/(component|page|route|layout|template|view)/.test(L)&&(v+=3),/page\.[jt]sx?$|layout\.[jt]sx?$|\+page\.svelte$/.test(L)&&(v+=5),{...g,score:v}}).sort((g,v)=>v.score-g.score),f=[],$=new Set,k=0;for(let g of h.slice(0,s)){if(g.score<=0||k>=o)break;try{let v=n.roots[0]||"",L=v?`${v}/${g.path}`:g.path,R=await S("fs.read",{path:L}),j=String(R?.payload?.content||"");if(!j)continue;let W=Math.min(8e3,o-k),ce=j.slice(0,W);j.length>W&&(ce+=`
|
|
482
|
+
// [FILE TRUNCATED \u2014 showing ${W} of ${j.length} chars]`),f.push({path:g.path,content:ce}),$.add(g.path),k+=ce.length;let Xe=g.path.replace(/\.[^.]+$/,""),Ye=[".module.css",".module.scss",".css",".scss",".styles.ts"];for(let de of Ye){let T=Xe+de;if($.has(T)||k>=o)continue;if(d.find(K=>K.path===T)){try{let K=await S("fs.read",{path:v?`${v}/${T}`:T}),P=String(K?.payload?.content||"");if(P){let Z=Math.min(4e3,o-k),z=P.slice(0,Z);P.length>Z&&(z+=`
|
|
483
|
+
// [FILE TRUNCATED \u2014 showing ${Z} of ${P.length} chars]`),f.push({path:T,content:z}),$.add(T),k+=z.length}}catch{}break}}let Ze=j.matchAll(/(?:import|from)\s+['"]\.?\.\/([\w/.-]+)['"]/g);for(let de of Ze){if(k>=o)break;let T=de[1],O=g.path.replace(/\/[^/]+$/,""),K=[`${O}/${T}`,`${O}/${T}.tsx`,`${O}/${T}.ts`,`${O}/${T}.jsx`,`${O}/${T}.js`,`${O}/${T}/index.tsx`,`${O}/${T}/index.ts`];for(let P of K){if($.has(P))break;if(d.find(z=>z.path===P)){try{let z=await S("fs.read",{path:v?`${v}/${P}`:P}),Q=String(z?.payload?.content||"");if(Q){let pe=Math.min(8e3,o-k),me=Q.slice(0,pe);Q.length>pe&&(me+=`
|
|
484
|
+
// [FILE TRUNCATED \u2014 showing ${pe} of ${Q.length} chars]`),f.push({path:P,content:me}),$.add(P),k+=me.length}}catch{}break}}}}catch{}}if(k<o)try{let g=n.roots[0]||"",v=await S("fs.read",{path:g?`${g}/package.json`:"package.json"}),L=String(v?.payload?.content||"");if(L)try{let R=JSON.parse(L),j={...R.dependencies,...R.devDependencies},W=JSON.stringify(j,null,2);f.push({path:"package.json (dependencies)",content:W.slice(0,2e3)})}catch{f.push({path:"package.json",content:L.slice(0,2e3)})}}catch{}if(f.length){e.files=f;let g=f.map(v=>v.path.split("/").pop()).join(", ");i&&(i.innerHTML=`<span class="om-spinner"></span> Thinking... (${f.length} files: ${g})`)}n.groundedFiles=f.map(g=>g.path)}catch{}let r=4,m=0;try{for(;m<=r;){n.streamContent="";let c=await Ce("llm.chat",{provider:n.provider,model:n.model,messages:n.messages.map(u=>({role:u.role,content:u.content})),context:e},u=>{n.streamContent+=u}),p=n.streamContent||c?.content||"",d=p.match(/NEED_FILE:\s*"?([^\s"}\]]+)"?/)||p.match(/(?:need|provide|show|read|see|contents?\s+of)\s+(?:the\s+)?(?:file\s+)?[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i)||p.match(/(?:source\s+(?:file|code)\s+(?:for|of|at))\s+[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i);if(d&&!c?.modifications?.length&&m<r){let u=d[1].trim();m++;let b=N.querySelector(".om-msg-assistant:last-child");b&&(b.innerHTML=`<span class="om-spinner"></span> Reading ${u}...`);try{let l=n.roots[0]||"",h=l?`${l}/${u}`:u,f,$=[h];u!==h&&$.push(u);let k=u.split("/").pop()||u,g=l?`${l}/${k}`:k;g!==h&&g!==u&&$.push(g);for(let v of $){let L=await S("fs.read",{path:v}).catch(()=>null);if(L?.payload?.content){f=String(L.payload.content);break}}if(f)e.files||(e.files=[]),e.files.push({path:u,content:f.slice(0,8e3)});else{n.messages.push({role:"system",content:`Could not read ${u}`});break}}catch{n.messages.push({role:"system",content:`File not found: ${u}`});break}continue}let y=p;try{let u=JSON.parse(p);u.explanation&&(y=u.explanation)}catch{let u=p.match(/```(?:json)?\s*([\s\S]*?)```/);if(u)try{let b=JSON.parse(u[1]);b.explanation&&(y=b.explanation)}catch{}}if(n.messages.push({role:"assistant",content:y}),c?.modifications?.length){let u=Math.random().toString(36).slice(2),b=c.modifications.filter(l=>l.type==="edit"&&l.file&&l.search&&l.replace||l.type==="create"&&l.file&&l.content);gt(b.length);for(let l of c.modifications)if(l.type==="edit"&&l.file&&l.search&&l.replace){let h=Math.random().toString(36).slice(2),f=JSON.stringify({id:h,file:l.file,search:l.search,replace:l.replace,groupId:u});n.messages.push({role:"system",content:`__DIFF__${ae(f)}`})}else if(l.type==="create"&&l.file&&l.content){let h=Math.random().toString(36).slice(2),f=JSON.stringify({id:h,file:l.file,search:"",replace:l.content,type:"create",groupId:u});n.messages.push({role:"system",content:`__DIFF__${ae(f)}`})}else l.type==="delete"&&l.file&&n.messages.push({role:"system",content:`LLM proposed deleting ${l.file} \u2014 skipped (use edit with search/replace instead)`})}break}}catch(c){n.messages.push({role:"system",content:`Error: ${c.message}`})}n.streaming=!1,n.streamContent="",n.attachments=[],Ee(),M(),U()}function wt(){let t=window.performance,e=t.getEntriesByType("navigation")[0],s=t.getEntriesByType("paint"),o=t.getEntriesByType("resource").slice(-20),a=ne(),i=oe(),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 m=s.find(c=>c.name==="first-contentful-paint");if(m&&r.push(`FCP: ${Math.round(m.startTime)}ms`),o.length){let c=o.filter(d=>d.initiatorType==="fetch"||d.initiatorType==="xmlhttprequest"),p=c.length>0?c:o;r.push(`
|
|
485
|
+
All network requests (${p.length}):`);for(let d of p.slice(-30)){let y=d.name.length>80?"..."+d.name.slice(-77):d.name,u=d.responseStatus||"";r.push(` ${Math.round(d.duration)}ms ${u?`[${u}]`:""} ${y}`)}}if(a.length){r.push(`
|
|
486
|
+
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(i.length){let c=i.filter(d=>d.level==="error"),p=i.filter(d=>d.level==="warn");c.length&&r.push(`
|
|
487
|
+
Console errors: ${c.length}`),p.length&&r.push(`Console warnings: ${p.length}`)}if(o.length>5){let c=[...o].sort((p,d)=>d.duration-p.duration).slice(0,5);r.push(`
|
|
488
|
+
Slowest resources:`);for(let p of c)r.push(` ${Math.round(p.duration)}ms \u2014 ${p.name.split("/").pop()?.slice(0,60)}`)}n.messages.push({role:"system",content:r.join(`
|
|
489
|
+
`)}),M(),U(),X()}function kt(){let t=w.querySelector(".om-file-input");t&&t.click()}function ve(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),Ee())},o.readAsDataURL(s)}}function Ee(){let t=w.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">
|
|
490
|
+
<img src="${e}" alt="attachment" />
|
|
493
491
|
<button class="om-attachment-remove" data-action="remove-attachment" data-idx="${s}">${x.x}</button>
|
|
494
|
-
</div>`).join("")}}var
|
|
495
|
-
`),s=A(
|
|
496
|
-
`)}function Lt(){fetch("https://registry.npmjs.org/openmagic/latest",{headers:{Accept:"application/json"},signal:AbortSignal.timeout(5e3)}).then(
|
|
492
|
+
</div>`).join("")}}var V=null,J=null;function $t(){n.selecting?ke():le()}function le(){n.selecting=!0,document.body.style.cursor="crosshair",Y(),J=e=>{let s=e.target;if(s.closest("openmagic-toolbar")||s.dataset?.openmagic)return;let o=s.getBoundingClientRect();Ne({x:o.x,y:o.y,width:o.width,height:o.height})},V=e=>{e.preventDefault(),e.stopPropagation();let s=e.target;s.closest("openmagic-toolbar")||s.dataset?.openmagic||(n.selectedElement=Re(s),ke(),X(),q.focus())};let t=e=>{e.key==="Escape"&&ke()};document.addEventListener("mousemove",J,!0),document.addEventListener("click",V,!0),document.addEventListener("keydown",t,!0),le._escHandler=t}function ke(){n.selecting=!1,document.body.style.cursor="",Ae(),J&&(document.removeEventListener("mousemove",J,!0),J=null),V&&(document.removeEventListener("click",V,!0),V=null);let t=le._escHandler;t&&(document.removeEventListener("keydown",t,!0),le._escHandler=null),Y()}async function St(){let t;try{let o=n.selectedElement?.cssSelector?.trim();o&&(t=document.querySelector(o)||void 0)}catch{}let e=await Oe(t||void 0);e.data&&e.data.length>5e3?(n.screenshot=e.data,X(),q.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."}),I("chat"),M())}function Et(){let t=!1,e=0,s=0,o=0,a=0;E.addEventListener("mousedown",i=>{let r=i.target;if(r.closest("[data-action]")||!r.closest(".om-grab")&&!r.closest(".om-pill-brand"))return;t=!0,e=i.clientX,s=i.clientY;let m=E.getBoundingClientRect();o=m.left,a=m.top,i.preventDefault()}),document.addEventListener("mousemove",i=>{t&&(E.style.left=o+i.clientX-e+"px",E.style.top=a+i.clientY-s+"px",E.style.right="auto",E.style.bottom="auto")}),document.addEventListener("mouseup",()=>{if(t){t=!1;try{localStorage.setItem("__om_pos__",JSON.stringify({left:E.style.left,top:E.style.top}))}catch{}}})}function A(t){let e=document.createElement("div");return e.textContent=t,e.innerHTML}function Mt(t){let e=t.replace(/\\n/g,`
|
|
493
|
+
`),s=A(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}function Ge(t){let e=[];e.push("## Environment"),e.push(""),e.push(`- **OpenMagic**: v${$e}${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}`),e.push(""),e.push("## Configuration"),e.push(""),e.push(`- **WebSocket**: ${n.connected?"connected":"disconnected"}`),e.push(`- **Provider**: ${D[n.provider]?.name||n.provider||"not set"}`),e.push(`- **Model**: ${n.model||"not set"}`),e.push(`- **API Key Set**: ${n.hasApiKey?"yes":"no"}`);let s=Object.entries(n.configuredProviders).filter(([,l])=>l).map(([l])=>D[l]?.name||l);if(s.length&&e.push(`- **Configured Providers**: ${s.join(", ")}`),n.roots.length&&e.push(`- **Project Roots**: ${n.roots.join(", ")}`),n.selectedElement){let l=n.selectedElement;e.push(""),e.push("## Selected Element"),e.push(""),e.push(`- **Selector**: \`${l.cssSelector||""}\``),e.push(`- **Tag**: \`${l.tagName}\``),l.id&&e.push(`- **ID**: \`${l.id}\``),l.className&&e.push(`- **Class**: \`${l.className}\``),l.componentHint&&e.push(`- **Component**: \`${l.componentHint}\``),l.ancestry?.length&&e.push(`- **Ancestry**: ${l.ancestry.join(" > ")}`),l.textContent&&e.push(`- **Text**: ${l.textContent.slice(0,150)}`)}if(n.groundedFiles.length){e.push(""),e.push("## Files Sent to LLM"),e.push("");for(let l of n.groundedFiles)e.push(`- \`${l}\``)}let o=[];for(let l of n.messages)if(l.content.startsWith("__DIFF__"))try{let h=JSON.parse(F(l.content.slice(8)));o.push({file:h.file,type:h.type||"edit"})}catch{}if(o.length){e.push(""),e.push("## Proposed Changes"),e.push("");for(let l of o)e.push(`- \`${l.file}\` (${l.type})`)}let a=n.messages.filter(l=>l.role==="system"&&(l.content.startsWith("Applied change to ")||l.content.startsWith("Rejected change to ")||l.content.startsWith("Reverted change to ")||l.content.startsWith("Created ")||l.content.startsWith("Change rejected")||l.content.startsWith("No matching code")||l.content.startsWith("Write failed")||l.content.startsWith("Could not read")));if(a.length){e.push(""),e.push("## Applied/Rejected Changes"),e.push("");for(let l of a)e.push(`- ${l.content.slice(0,200)}`)}let i=window.performance,r=i.getEntriesByType("navigation")[0],m=i.getEntriesByType("paint");if(r){e.push(""),e.push("## Page Performance"),e.push(""),e.push(`- **Page Load**: ${Math.round(r.loadEventEnd-r.startTime)}ms`),e.push(`- **DOM Ready**: ${Math.round(r.domContentLoadedEventEnd-r.startTime)}ms`),e.push(`- **TTFB**: ${Math.round(r.responseStart-r.startTime)}ms`);let l=m.find(h=>h.name==="first-contentful-paint");l&&e.push(`- **FCP**: ${Math.round(l.startTime)}ms`)}let c=oe(),p=c.filter(l=>l.level==="error"),d=c.filter(l=>l.level==="warn");if(p.length||d.length){if(e.push(""),e.push("## Console Issues"),e.push(""),p.length){e.push(`### Errors (${p.length})`),e.push("```");for(let l of p.slice(-15))e.push(l.args.map(h=>String(h)).join(" ").slice(0,300));e.push("```")}if(d.length){e.push(`### Warnings (${d.length})`),e.push("```");for(let l of d.slice(-10))e.push(l.args.map(h=>String(h)).join(" ").slice(0,200));e.push("```")}}let y=ne(),u=y.filter(l=>l.status&&l.status>=400),b=y.filter(l=>l.duration&&l.duration>2e3);if(u.length||b.length){if(e.push(""),e.push("## Network Issues"),e.push(""),u.length){e.push(`### Failed Requests (${u.length})`),e.push("```");for(let l of u.slice(-15))e.push(`${l.method} ${l.url.slice(0,120)} \u2192 ${l.status} (${l.duration||"?"}ms)`);e.push("```")}if(b.length){e.push(`### Slow Requests >2s (${b.length})`),e.push("```");for(let l of b.slice(-10))e.push(`${l.method} ${l.url.slice(0,120)} \u2192 ${l.status} (${l.duration}ms)`);e.push("```")}}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 l of n.messages)if(!l.content.startsWith("__DIFFGROUP__")){if(l.content.startsWith("__DIFF__")){try{let h=JSON.parse(F(l.content.slice(8)));e.push(`[diff] ${h.type||"edit"}: ${h.file}`),h.search&&e.push(` - search: ${h.search.slice(0,100)}...`),h.replace&&e.push(` + replace: ${h.replace.slice(0,100)}...`)}catch{e.push("[diff] (parse error)")}continue}e.push(`[${l.role}] ${l.content.slice(0,500)}`)}e.push("```"),e.push("</details>")}if(t!==void 0){let l=n.messages[t];l&&(e.push(""),e.push("## Copied Message"),e.push(""),e.push("```"),e.push(`[${l.role}] ${l.content.slice(0,2e3)}`),e.push("```"))}return e.join(`
|
|
494
|
+
`)}function Lt(){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?.version)return;let e=t.version.split(".").map(Number),s=$e.split(".").map(Number);for(let o=0;o<3;o++){if((e[o]||0)>(s[o]||0)){n.updateAvailable=!0,n.latestVersion=t.version,Tt();return}if((e[o]||0)<(s[o]||0))return}}).catch(()=>{})}function Tt(){re()}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Fe):Fe());})();
|
|
497
495
|
//# sourceMappingURL=index.global.js.map
|