openmagic 0.35.1 → 0.36.1
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.
- package/dist/cli.js +255 -5
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +5 -5
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
|
@@ -372,25 +372,25 @@
|
|
|
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 j=null,
|
|
375
|
+
`;var j=null,I=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,i=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}})),I.set(c,m=>{if(m.type==="handshake.ok"){clearTimeout(i),Z=!0,be=0;for(let u of xe)j?.send(u);xe=[],a||(a=!0,s())}else m.type==="error"&&(clearTimeout(i),a||(a=!0,o(new Error(m.payload?.message||"Handshake failed"))))})},j.onmessage=c=>{try{let m=JSON.parse(c.data);m.id&&I.has(m.id)&&(I.get(m.id)(m),(m.type==="llm.done"||m.type==="llm.error"||!m.type.startsWith("llm."))&&I.delete(m.id));for(let u of ne)u(m)}catch{}},j.onclose=()=>{let c=Z;if(Z=!1,I.forEach((m,u)=>{m({type:"error",id:u,payload:{message:"Connection lost"}})}),I.clear(),!c&&!a){clearTimeout(i),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(i),a=!0,o(new Error("WebSocket connection failed")))}}catch(r){clearTimeout(i),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(),i=setTimeout(()=>{I.delete(a),o(new Error("Request timeout"))},3e4);I.set(a,r=>{clearTimeout(i),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 i=ve(),r=setTimeout(()=>{I.delete(i),a(new Error("Stream timeout"))},12e4);I.set(i,p=>{p.type==="llm.chunk"?s(p.payload?.delta||""):p.type==="llm.done"?(clearTimeout(r),I.delete(i),o(p.payload)):(p.type==="llm.error"||p.type==="error")&&(clearTimeout(r),I.delete(i),a(new Error(p.payload?.message||"Stream error")))}),Ne({id:i,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 Ie(t){let e=window.getComputedStyle(t),s={};for(let l of Oe)s[l]=e.getPropertyValue(l);let o=t.getBoundingClientRect(),a={};if(t.parentElement&&t.parentElement!==document.body){let l=window.getComputedStyle(t.parentElement);for(let h of Oe)a[h]=l.getPropertyValue(h)}let i=[];if(t.parentElement){let l=Array.from(t.parentElement.children),h=l.indexOf(t),b=Math.max(0,h-3),f=Math.min(l.length,h+4);b>0&&i.push(`... ${b} elements before ...`);for(let d=b;d<f;d++){let v=l[d],y=v.tagName.toLowerCase(),S=(v.className||"").toString().slice(0,60);v===t?i.push(`[SELECTED] <${y} class="${S}">`):i.push(`<${y} class="${S}">`)}f<l.length&&i.push(`... ${l.length-f} elements after ...`)}let r=[],p=Array.from(t.children).slice(0,12);for(let l=0;l<p.length;l++){let h=p[l],b=h.getBoundingClientRect(),f=window.getComputedStyle(h),d=null;if(l<p.length-1){let v=p[l+1].getBoundingClientRect();d={vertical:Math.round(v.top-b.bottom),horizontal:Math.round(v.left-b.right)}}r.push({tag:h.tagName.toLowerCase(),className:(h.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:d,margin:f.margin,padding:f.padding})}let c=lt(t),m=dt(t,c),u={};for(let l of Array.from(t.attributes))(l.name.startsWith("aria-")||l.name==="role"||l.name==="tabindex")&&(u[l.name]=l.value);let w=[];for(let l of Array.from(t.attributes))l.name.startsWith("on")&&w.push(l.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:i,childrenLayout:r,matchedCssRules:c,resolvedClasses:m,viewport:{width:window.innerWidth,height:window.innerHeight},ariaAttributes:u,eventHandlers:w,reactProps:$}}function ot(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 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 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 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(),i=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} ${i}>
|
|
377
377
|
${r}
|
|
378
378
|
${t.children.length>5?`<!-- +${t.children.length-5} more children -->`:""}
|
|
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 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 it(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 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 i=a.cssText;i.length>10&&i.length<500&&e.push(i)}}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,i={},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?(i[p]=c,r++):m==="function"?(i[p]="[function]",r++):Array.isArray(c)&&(i[p]=`[Array(${c.length})]`,r++)}return Object.keys(i).length>0?i: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 i=CSS.escape(a);for(let r of e)if(r.includes(`.${i}`)&&r.length<200){s.push({className:a,css:r});break}if(s.length>=20)break}return s}var
|
|
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 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 it(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 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 i=a.cssText;i.length>10&&i.length<500&&e.push(i)}}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,i={},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?(i[p]=c,r++):m==="function"?(i[p]="[function]",r++):Array.isArray(c)&&(i[p]=`[Array(${c.length})]`,r++)}return Object.keys(i).length>0?i: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 i=CSS.escape(a);for(let r of e)if(r.includes(`.${i}`)&&r.length<200){s.push({className:a,css:r});break}if(s.length>=20)break}return s}var D=null;function De(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 i=`
|
|
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([i],{type:"image/svg+xml;charset=utf-8"}),p=URL.createObjectURL(r);return new Promise(c=>{let m=new Image,u=document.createElement("canvas"),w=Math.min(window.devicePixelRatio||1,2);u.width=s*w,u.height=o*w,m.onload=()=>{URL.revokeObjectURL(p);let $=u.getContext("2d");if(!$){c(null);return}$.scale(w,w),$.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),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 p of i){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),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,$e(i),r}catch(r){throw i.status=0,i.duration=Date.now()-i.timestamp,$e(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",()=>{$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 M={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.35.1",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,R,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(),R=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&&(R.style.left=r.left,R.style.top=r.top,R.style.right="auto",R.style.bottom="auto")}catch{}Ue(),We(),Pt();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&&we(i,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`
|
|
393
|
+
</svg>`,r=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),p=URL.createObjectURL(r);return new Promise(c=>{let m=new Image,u=document.createElement("canvas"),w=Math.min(window.devicePixelRatio||1,2);u.width=s*w,u.height=o*w,m.onload=()=>{URL.revokeObjectURL(p);let $=u.getContext("2d");if(!$){c(null);return}$.scale(w,w),$.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),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 p of i){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),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,$e(i),r}catch(r){throw i.status=0,i.duration=Date.now()-i.timestamp,$e(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",()=>{$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 M={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={"claude-code":{name:"Claude Code (CLI)",keyPlaceholder:"not required",local:!0,models:[{id:"claude-code",name:"Claude Code"}]},"codex-cli":{name:"Codex CLI",keyPlaceholder:"not required",local:!0,models:[{id:"codex-cli",name:"Codex CLI"}]},"gemini-cli":{name:"Gemini CLI",keyPlaceholder:"not required",local:!0,models:[{id:"gemini-cli",name:"Gemini CLI"}]},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.36.1",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,R,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(),R=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&&(R.style.left=r.left,R.style.top=r.top,R.style.right="auto",R.style.bottom="auto")}catch{}Ue(),We(),Pt();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&&we(i,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
396
|
<span class="om-grab">${M.grip}</span>
|
|
@@ -491,7 +491,7 @@ Slowest resources:`);for(let m of c)r.push(` ${Math.round(m.duration)}ms \u2014
|
|
|
491
491
|
`)}),A(),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
493
|
<button class="om-attachment-remove" data-action="remove-attachment" data-idx="${s}">${M.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();
|
|
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();De({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=Ie(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"),A())}function Ct(){let t=!1,e=0,s=0,o=0,a=0;R.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 p=R.getBoundingClientRect();o=p.left,a=p.top,i.preventDefault()}),document.addEventListener("mousemove",i=>{t&&(R.style.left=o+i.clientX-e+"px",R.style.top=a+i.clientY-s+"px",R.style.right="auto",R.style.bottom="auto")}),document.addEventListener("mouseup",()=>{if(t){t=!1;try{localStorage.setItem("__om_pos__",JSON.stringify({left:R.style.left,top:R.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
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((h,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(([,l])=>l).map(([l])=>W[l]?.name||l);if(o.length&&e.push(`- **Configured Providers**: ${o.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 a=[];for(let l of n.messages)if(l.content.startsWith("__DIFF__"))try{let h=JSON.parse(Q(l.content.slice(8)));a.push({file:h.file,type:h.type||"edit"})}catch{}if(a.length){e.push(""),e.push("## Proposed Changes"),e.push("");for(let l of a)e.push(`- \`${l.file}\` (${l.type})`)}let i=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(i.length){e.push(""),e.push("## Applied/Rejected Changes"),e.push("");for(let l of i)e.push(`- ${l.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 l=c.find(h=>h.name==="first-contentful-paint");l&&e.push(`- **FCP**: ${Math.round(l.startTime)}ms`)}let m=de();if(m.length){let l=m.filter(f=>f.level==="error"),h=m.filter(f=>f.level==="warn"),b=m.filter(f=>f.level==="log"||f.level==="info"||f.level==="debug");if(e.push(""),e.push("## Browser Console"),e.push(""),e.push(`Total: ${m.length} entries (${l.length} errors, ${h.length} warnings, ${b.length} log/info/debug)`),l.length){e.push(""),e.push(`### Errors (${l.length})`),e.push("```");for(let f of l.slice(-15))e.push(`[${new Date(f.timestamp).toISOString()}] ${f.args.map(d=>String(d)).join(" ").slice(0,300)}`);e.push("```")}if(h.length){e.push(""),e.push(`### Warnings (${h.length})`),e.push("```");for(let f of h.slice(-10))e.push(`[${new Date(f.timestamp).toISOString()}] ${f.args.map(d=>String(d)).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 f of b.slice(-30))e.push(`[${new Date(f.timestamp).toISOString()}] [${f.level}] ${f.args.map(d=>String(d)).join(" ").slice(0,200)}`);e.push("```"),e.push("</details>")}}let u=ce(),w=u.filter(l=>l.status&&l.status>=400),$=u.filter(l=>l.duration&&l.duration>2e3);if(w.length||$.length){if(e.push(""),e.push("## Network Issues"),e.push(""),w.length){e.push(`### Failed Requests (${w.length})`),e.push("```");for(let l of w.slice(-15))e.push(`${l.method} ${l.url.slice(0,120)} \u2192 ${l.status} (${l.duration||"?"}ms)`);e.push("```")}if($.length){e.push(`### Slow Requests >2s (${$.length})`),e.push("```");for(let l of $.slice(-10))e.push(`${l.method} ${l.url.slice(0,120)} \u2192 ${l.status} (${l.duration}ms)`);e.push("```")}}if(s?.logs?.length){let l=s.logs,h=l.filter(d=>d.level==="error"),b=l.filter(d=>d.level==="warn"),f=l.filter(d=>d.level==="log"||d.level==="info");if(e.push(""),e.push("## Server Logs (Terminal)"),e.push(""),e.push(`Total: ${l.length} entries (${h.length} errors, ${b.length} warnings, ${f.length} log/info)`),h.length){e.push(""),e.push(`### Server Errors (${h.length})`),e.push("```");for(let d of h.slice(-15))e.push(`[${new Date(d.ts).toISOString()}] ${d.msg.slice(0,300)}`);e.push("```")}if(b.length){e.push(""),e.push(`### Server Warnings (${b.length})`),e.push("```");for(let d of b.slice(-10))e.push(`[${new Date(d.ts).toISOString()}] ${d.msg.slice(0,200)}`);e.push("```")}e.push(""),e.push("<details><summary>All server logs ("+l.length+" entries)</summary>"),e.push(""),e.push("```");for(let d of l.slice(-50))e.push(`[${new Date(d.ts).toISOString()}] [${d.level}] ${d.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 l of n.messages)if(!l.content.startsWith("__DIFFGROUP__")){if(l.content.startsWith("__DIFF__")){try{let h=JSON.parse(Q(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(`
|
|
496
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
|