openmagic 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -208
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +71 -47
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
display: flex; align-items: center; justify-content: center;
|
|
80
80
|
}
|
|
81
81
|
.om-pill-btn:hover { background: rgba(108, 92, 231, 0.15); color: #a29bfe; }
|
|
82
|
+
.om-pill-btn:focus-visible { outline: 2px solid #6c5ce7; outline-offset: 2px; }
|
|
82
83
|
.om-pill-btn.active { background: rgba(108, 92, 231, 0.25); color: #c4b5fd; }
|
|
83
84
|
|
|
84
85
|
.om-status-dot {
|
|
@@ -127,7 +128,7 @@
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
.om-prompt-context {
|
|
130
|
-
display: flex; gap: 3px; flex-
|
|
131
|
+
display: flex; gap: 3px; flex-wrap: wrap; max-width: 200px; overflow: hidden;
|
|
131
132
|
}
|
|
132
133
|
.om-prompt-chip {
|
|
133
134
|
display: flex; align-items: center; gap: 3px;
|
|
@@ -337,83 +338,106 @@
|
|
|
337
338
|
display: flex; align-items: center; margin-right: 4px;
|
|
338
339
|
}
|
|
339
340
|
.om-panel-clear:hover { color: #e94560; background: rgba(233,69,96,0.08); }
|
|
340
|
-
|
|
341
|
-
|
|
341
|
+
|
|
342
|
+
/* \u2500\u2500 Code Blocks (Markdown) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
343
|
+
.om-code-block {
|
|
344
|
+
background: rgba(0,0,0,0.2); border-radius: 6px; padding: 8px 10px;
|
|
345
|
+
margin: 6px 0; overflow-x: auto; font-family: 'SF Mono', Consolas, monospace;
|
|
346
|
+
font-size: 11px; line-height: 1.5; white-space: pre-wrap;
|
|
347
|
+
}
|
|
348
|
+
.om-inline-code {
|
|
349
|
+
background: rgba(108,92,231,0.1); padding: 1px 4px; border-radius: 3px;
|
|
350
|
+
font-family: 'SF Mono', Consolas, monospace; font-size: 12px;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/* \u2500\u2500 Copy Button \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
354
|
+
.om-copy-btn {
|
|
355
|
+
position: absolute; top: 4px; right: 4px;
|
|
356
|
+
background: rgba(0,0,0,0.3); border: none; color: #888;
|
|
357
|
+
cursor: pointer; padding: 3px; border-radius: 4px;
|
|
358
|
+
opacity: 0; transition: opacity 0.15s;
|
|
359
|
+
display: flex; align-items: center;
|
|
360
|
+
}
|
|
361
|
+
.om-msg:hover .om-copy-btn { opacity: 1; }
|
|
362
|
+
.om-copy-btn:hover { color: #ccc; background: rgba(0,0,0,0.5); }
|
|
363
|
+
.om-msg { position: relative; }
|
|
364
|
+
`;var C=null,$=new Map,G=[],de=[],I=!1,Le=!1,le=null,ce=0;function pe(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function me(e,t){return Le=!0,new Promise((s,o)=>{let a=!1,r=setTimeout(()=>{a||(a=!0,o(new Error("Handshake timeout")),C?.close())},1e4);try{let i=window.location.hostname||"127.0.0.1",c=window.location.protocol==="https:"?"wss:":"ws:";C=new WebSocket(`${c}//${i}:${e}/__openmagic__/ws`),C.onopen=()=>{let l=pe();C.send(JSON.stringify({id:l,type:"handshake",payload:{token:t}})),$.set(l,d=>{if(d.type==="handshake.ok"){clearTimeout(r),I=!0,ce=0;for(let p of de)C?.send(p);de=[],a||(a=!0,s())}else d.type==="error"&&(clearTimeout(r),a||(a=!0,o(new Error(d.payload?.message||"Handshake failed"))))})},C.onmessage=l=>{try{let d=JSON.parse(l.data);d.id&&$.has(d.id)&&($.get(d.id)(d),(d.type==="llm.done"||d.type==="llm.error"||!d.type.startsWith("llm."))&&$.delete(d.id));for(let p of G)p(d)}catch{}},C.onclose=()=>{let l=I;if(I=!1,$.forEach((d,p)=>{d({type:"error",id:p,payload:{message:"Connection lost"}})}),$.clear(),!l&&!a){clearTimeout(r),a=!0,o(new Error("WebSocket closed before handshake"));return}if(l&&Le&&!le){let d=Math.min(2e3*Math.pow(1.5,ce),3e4);ce++,le=setTimeout(()=>{le=null,me(e,t).then(()=>{for(let p of G)p({type:"reconnected",payload:{}})}).catch(()=>{})},d)}},C.onerror=()=>{!I&&!a&&(clearTimeout(r),a=!0,o(new Error("WebSocket connection failed")))}}catch(i){clearTimeout(r),a||(a=!0,o(i))}})}function Me(e){let t=JSON.stringify(e);C&&C.readyState===WebSocket.OPEN&&I?C.send(t):de.push(t)}function k(e,t){return new Promise((s,o)=>{let a=pe(),r=setTimeout(()=>{$.delete(a),o(new Error("Request timeout"))},3e4);$.set(a,i=>{clearTimeout(r),i.type==="error"?o(new Error(i.payload?.message||"Unknown error")):s(i)}),Me({id:a,type:e,payload:t})})}function Te(e,t,s){return new Promise((o,a)=>{let r=pe(),i=setTimeout(()=>{$.delete(r),a(new Error("Stream timeout"))},12e4);$.set(r,c=>{c.type==="llm.chunk"?s(c.payload?.delta||""):c.type==="llm.done"?(clearTimeout(i),$.delete(r),o(c.payload)):(c.type==="llm.error"||c.type==="error")&&(clearTimeout(i),$.delete(r),a(new Error(c.payload?.message||"Stream error")))}),Me({id:r,type:e,payload:t})})}function Ce(e){return G.push(e),()=>{G=G.filter(t=>t!==e)}}function He(){return I}var Pe=["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 _e(e){let t=window.getComputedStyle(e),s={};for(let p of Pe)s[p]=t.getPropertyValue(p);let o=e.getBoundingClientRect(),a={};if(e.parentElement&&e.parentElement!==document.body){let p=window.getComputedStyle(e.parentElement);for(let m of Pe)a[m]=p.getPropertyValue(m)}let r=[];if(e.parentElement){let p=Array.from(e.parentElement.children),m=p.indexOf(e),h=Math.max(0,m-3),f=Math.min(p.length,m+4);h>0&&r.push(`... ${h} elements before ...`);for(let E=h;E<f;E++){let R=p[E],b=R.tagName.toLowerCase(),A=(R.className||"").toString().slice(0,60);R===e?r.push(`[SELECTED] <${b} class="${A}">`):r.push(`<${b} class="${A}">`)}f<p.length&&r.push(`... ${p.length-f} elements after ...`)}let i=ot(e),c={};for(let p of Array.from(e.attributes))(p.name.startsWith("aria-")||p.name==="role"||p.name==="tabindex")&&(c[p.name]=p.value);let l=[];for(let p of Array.from(e.attributes))p.name.startsWith("on")&&l.push(p.name);let d=st(e);return{tagName:e.tagName.toLowerCase(),id:e.id||"",className:e.className||"",textContent:(e.textContent||"").trim().slice(0,200),outerHTML:et(e),cssSelector:tt(e),xpath:nt(e),computedStyles:s,ancestry:Ze(e),componentHint:Qe(e),rect:{x:o.x,y:o.y,width:o.width,height:o.height},parentStyles:a,siblings:r,matchedCssRules:i,viewport:{width:window.innerWidth,height:window.innerHeight},ariaAttributes:c,eventHandlers:l,reactProps:d}}function Ze(e,t=5){let s=[],o=e.parentElement;for(;o&&o!==document.body&&s.length<t;){let a=o.tagName.toLowerCase(),r=(typeof o.className=="string"?o.className:"").split(/\s+/).filter(i=>i.length>1&&!i.startsWith("_")).slice(0,3).join(".");s.push(r?`${a}.${r}`:a),o=o.parentElement}return s}function Qe(e){let t=e;for(;t&&t!==document.body;){let s=t.getAttribute("data-component")||t.getAttribute("data-testid")||t.getAttribute("data-cy");if(s)return s;let o=Object.keys(t);for(let a of o)if(a.startsWith("__reactFiber")||a.startsWith("__reactInternalInstance"))try{let r=t[a],i=r?.type?.name||r?.type?.displayName||r?.return?.type?.name||r?.return?.type?.displayName;if(i&&i!=="div"&&i!=="span"&&i.length>1)return i}catch{}t=t.parentElement}return""}function et(e){let t=e.cloneNode(!0);t.querySelectorAll("script, style, svg").forEach(a=>a.remove());let o=t.outerHTML;if(o.length>2e3){let a=e.tagName.toLowerCase(),r=Array.from(e.attributes).map(c=>`${c.name}="${c.value}"`).join(" "),i=Array.from(e.children).slice(0,5).map(c=>`<${c.tagName.toLowerCase()} .../>`).join(`
|
|
365
|
+
`);o=`<${a} ${r}>
|
|
342
366
|
${i}
|
|
343
367
|
${e.children.length>5?`<!-- +${e.children.length-5} more children -->`:""}
|
|
344
|
-
</${
|
|
368
|
+
</${a}>`}return o}function tt(e){if(e.id)return`#${CSS.escape(e.id)}`;let t=[],s=e;for(;s&&s!==document.body;){let o=s.tagName.toLowerCase();if(s.id){t.unshift(`#${CSS.escape(s.id)}`);break}if(s.className&&typeof s.className=="string"){let r=s.className.trim().split(/\s+/).filter(i=>!i.startsWith("__")&&i.length<30).slice(0,2).map(i=>CSS.escape(i));r.length>0&&(o+="."+r.join("."))}let a=s.parentElement;if(a){let r=Array.from(a.children).filter(i=>i.tagName===s.tagName);if(r.length>1){let i=r.indexOf(s)+1;o+=`:nth-of-type(${i})`}}t.unshift(o),s=s.parentElement}return t.join(" > ")}function nt(e){let t=[],s=e;for(;s&&s!==document;){if(s.nodeType===Node.ELEMENT_NODE){let o=s,a=1,r=o.previousElementSibling;for(;r;)r.tagName===o.tagName&&a++,r=r.previousElementSibling;t.unshift(`${o.tagName.toLowerCase()}[${a}]`)}s=s.parentNode}return"/"+t.join("/")}function ot(e){let t=[];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(e.matches(a.selectorText)){let r=a.cssText;r.length>10&&r.length<500&&t.push(r)}}catch{}}catch{}}catch{}return t.slice(0,15)}function st(e){try{let t=Object.keys(e);for(let s of t)if(s.startsWith("__reactFiber")||s.startsWith("__reactInternalInstance")){let o=e[s];if(!o?.memoizedProps)continue;let a=o.memoizedProps,r={},i=0;for(let[c,l]of Object.entries(a)){if(i>=10)break;if(c==="children")continue;let d=typeof l;d==="string"||d==="number"||d==="boolean"||l===null?(r[c]=l,i++):d==="function"?(r[c]="[function]",i++):Array.isArray(l)&&(r[c]=`[Array(${l.length})]`,i++)}return Object.keys(r).length>0?r:null}}catch{}return null}var L=null;function Ne(e){L||(L=document.createElement("div"),L.style.cssText=`
|
|
345
369
|
position: fixed;
|
|
346
370
|
pointer-events: none;
|
|
347
371
|
z-index: 2147483646;
|
|
348
372
|
border: 2px solid #6c5ce7;
|
|
349
373
|
background: rgba(108, 92, 231, 0.1);
|
|
350
374
|
transition: all 0.1s ease;
|
|
351
|
-
`,L.dataset.openmagic="highlight",document.body.appendChild(L)),L.style.left=`${e.x}px`,L.style.top=`${e.y}px`,L.style.width=`${e.width}px`,L.style.height=`${e.height}px`,L.style.display="block"}function Re(){L&&(L.style.display="none")}async function Ae(e){try{return e?await rt(e):await at()}catch(
|
|
352
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="${
|
|
375
|
+
`,L.dataset.openmagic="highlight",document.body.appendChild(L)),L.style.left=`${e.x}px`,L.style.top=`${e.y}px`,L.style.width=`${e.width}px`,L.style.height=`${e.height}px`,L.style.display="block"}function Re(){L&&(L.style.display="none")}async function Ae(e){try{return e?await rt(e):await at()}catch(t){return console.warn("[OpenMagic] Screenshot capture failed:",t),null}}async function at(){let e=document.createElement("canvas"),t=window.devicePixelRatio||1;e.width=window.innerWidth*t,e.height=window.innerHeight*t;let s=e.getContext("2d");s.scale(t,t);try{let o=await Oe(document.body),a=await De(o,window.innerWidth,window.innerHeight);return s.drawImage(a,0,0),e.toDataURL("image/png")}catch{return null}}async function rt(e){let t=e.getBoundingClientRect(),s=document.createElement("canvas"),o=window.devicePixelRatio||1;s.width=t.width*o,s.height=t.height*o;let a=s.getContext("2d");a.scale(o,o);try{let r=await Oe(e),i=await De(r,t.width,t.height);return a.drawImage(i,0,0),s.toDataURL("image/png")}catch{return null}}function Oe(e){return new Promise(t=>{let s=e.cloneNode(!0);ze(e,s);let o=e.getBoundingClientRect(),a=o.width,r=o.height,i=`
|
|
376
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${a}" height="${r}">
|
|
353
377
|
<foreignObject width="100%" height="100%">
|
|
354
|
-
<div xmlns="http://www.w3.org/1999/xhtml" style="width:${
|
|
378
|
+
<div xmlns="http://www.w3.org/1999/xhtml" style="width:${a}px;height:${r}px;overflow:hidden;">
|
|
355
379
|
${s.outerHTML}
|
|
356
380
|
</div>
|
|
357
381
|
</foreignObject>
|
|
358
|
-
</svg>`;n(i)})}function ze(e,n){let s=window.getComputedStyle(e),o="";for(let i=0;i<s.length;i++){let c=s[i];o+=`${c}:${s.getPropertyValue(c)};`}n.style.cssText=o;let r=e.children,a=n.children;for(let i=0;i<r.length&&i<a.length;i++)ze(r[i],a[i])}function De(e,n,s){return new Promise((o,r)=>{let a=new Image,i=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),c=URL.createObjectURL(i);a.onload=()=>{URL.revokeObjectURL(c),o(a)},a.onerror=()=>{URL.revokeObjectURL(c),r(new Error("Failed to load SVG image"))},a.width=n,a.height=s,a.src=c})}var Q=[];var qe=!1;function Be(){if(qe)return;qe=!0;let e=window.fetch;window.fetch=async function(...o){let r=new Request(...o),a={method:r.method,url:r.url,timestamp:Date.now()};try{let i=await e.apply(this,o);return a.status=i.status,a.duration=Date.now()-a.timestamp,ue(a),i}catch(i){throw a.status=0,a.duration=Date.now()-a.timestamp,ue(a),i}};let n=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,r,...a){return this.__om_method=o,this.__om_url=r,this.__om_start=Date.now(),n.apply(this,[o,r,...a])},XMLHttpRequest.prototype.send=function(...o){return this.addEventListener("loadend",()=>{ue({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 ue(e){e.url.includes("__openmagic__")||(Q.push(e),Q.length>50&&Q.shift())}function ge(){return[...Q]}var ee=[],it=100,Ie=!1;function je(){if(Ie)return;Ie=!0;let e=["log","warn","error","info","debug"];for(let n of e){let s=console[n];console[n]=function(...o){ee.push({level:n,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>it&&ee.shift(),s.apply(console,o)}}}function he(){return[...ee]}function Fe(e,n){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:n||void 0,networkLogs:ge().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:he().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var h={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>',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>'},j={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 be(e){let n=new TextEncoder().encode(e),s="";for(let o=0;o<n.length;o+=32768)s+=String.fromCharCode(...n.subarray(o,o+32768));return btoa(s)}function xe(e){let n=atob(e),s=new Uint8Array(n.length);for(let o=0;o<n.length;o++)s[o]=n.charCodeAt(o);return new TextDecoder().decode(s)}var Ke="0.23.0",t={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},k,b,z,Ge,Ee,_;function lt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:t.messages,provider:t.provider,model:t.model,panelOpen:t.panelOpen,activePanel:t.activePanel}))}catch{}}function ct(){try{let e=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");e.messages?.length&&(t.messages=e.messages),e.provider&&(t.provider=e.provider),e.model&&(t.model=e.model),e.panelOpen&&(t.panelOpen=e.panelOpen,t.activePanel=e.activePanel||"")}catch{}}function Ue(){if(document.querySelector("openmagic-toolbar"))return;ct();let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",k=e.attachShadow({mode:"closed"});let n=document.createElement("style");n.textContent=$e,k.appendChild(n);let s=document.createElement("div");k.appendChild(s),s.innerHTML=dt(),b=s.querySelector(".om-toolbar"),z=s.querySelector(".om-prompt-input"),Ge=s.querySelector(".om-prompt-context"),Ee=s.querySelector(".om-panel"),_=s.querySelector(".om-panel-body"),document.body.appendChild(e),pt(s),St();try{let i=JSON.parse(localStorage.getItem("__om_pos__")||"");i?.left&&i?.top&&(b.style.left=i.left,b.style.top=i.top,b.style.right="auto",b.style.bottom="auto")}catch{}Be(),je(),$t();let r=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,a=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);r&&me(a,r).then(()=>(t.connected=!0,ve(),w("config.get"))).then(i=>{let c=i.payload?.provider||"",l=i.payload?.model||"";t.provider=t.provider||c,t.model=t.model||l,t.configuredProviders=i.payload?.apiKeys||{},t.hasApiKey=t.configuredProviders[t.provider]||!1,t.roots=i.payload?.roots||[],t.panelOpen&&t.activePanel?D(t.activePanel):(!t.provider||!t.hasApiKey&&!Object.values(t.configuredProviders).some(Boolean))&&D("settings"),J()}).catch(()=>{t.connected=!1,ve()})}function dt(){return`
|
|
382
|
+
</svg>`;t(i)})}function ze(e,t){let s=window.getComputedStyle(e),o="";for(let i=0;i<s.length;i++){let c=s[i];o+=`${c}:${s.getPropertyValue(c)};`}t.style.cssText=o;let a=e.children,r=t.children;for(let i=0;i<a.length&&i<r.length;i++)ze(a[i],r[i])}function De(e,t,s){return new Promise((o,a)=>{let r=new Image,i=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),c=URL.createObjectURL(i);r.onload=()=>{URL.revokeObjectURL(c),o(r)},r.onerror=()=>{URL.revokeObjectURL(c),a(new Error("Failed to load SVG image"))},r.width=t,r.height=s,r.src=c})}var Q=[];var qe=!1;function Ie(){if(qe)return;qe=!0;let e=window.fetch;window.fetch=async function(...o){let a=new Request(...o),r={method:a.method,url:a.url,timestamp:Date.now()};try{let i=await e.apply(this,o);return r.status=i.status,r.duration=Date.now()-r.timestamp,ue(r),i}catch(i){throw r.status=0,r.duration=Date.now()-r.timestamp,ue(r),i}};let t=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,a,...r){return this.__om_method=o,this.__om_url=a,this.__om_start=Date.now(),t.apply(this,[o,a,...r])},XMLHttpRequest.prototype.send=function(...o){return this.addEventListener("loadend",()=>{ue({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 ue(e){e.url.includes("__openmagic__")||(Q.push(e),Q.length>50&&Q.shift())}function ge(){return[...Q]}var ee=[],it=100,Be=!1;function je(){if(Be)return;Be=!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(a=>{try{return typeof a=="object"?JSON.stringify(a).slice(0,500):String(a)}catch{return String(a)}}),timestamp:Date.now()}),ee.length>it&&ee.shift(),s.apply(console,o)}}}function he(){return[...ee]}function Fe(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:ge().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:he().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var g={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>',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>'},j={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 be(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 xe(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 Ke="0.25.0",n={connected:!1,panelOpen:!1,activePanel:"",selecting:!1,selectedElement:null,screenshot:null,messages:[],streaming:!1,streamContent:"",provider:"",model:"",hasApiKey:!1,configuredProviders:{},roots:[],updateAvailable:!1,latestVersion:"",saveStatus:"",networkCapture:!1,attachments:[],groundedFiles:[],minimized:!1},v,x,z,Ge,Ee,N;function lt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function ct(){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 Ue(){if(document.querySelector("openmagic-toolbar"))return;ct();let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",v=e.attachShadow({mode:"closed"});let t=document.createElement("style");t.textContent=$e,v.appendChild(t);let s=document.createElement("div");v.appendChild(s),s.innerHTML=dt(),x=s.querySelector(".om-toolbar"),z=s.querySelector(".om-prompt-input"),Ge=s.querySelector(".om-prompt-context"),Ee=s.querySelector(".om-panel"),N=s.querySelector(".om-panel-body"),document.body.appendChild(e),pt(s),St();try{let i=JSON.parse(localStorage.getItem("__om_pos__")||"");i?.left&&i?.top&&(x.style.left=i.left,x.style.top=i.top,x.style.right="auto",x.style.bottom="auto")}catch{}Ie(),je(),Lt();let a=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,r=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);a&&me(r,a).then(()=>(n.connected=!0,ve(),k("config.get"))).then(i=>{let c=i.payload?.provider||"",l=i.payload?.model||"";n.provider=n.provider||c,n.model=n.model||l,n.configuredProviders=i.payload?.apiKeys||{},n.hasApiKey=n.configuredProviders[n.provider]||!1,n.roots=i.payload?.roots||[],n.panelOpen&&n.activePanel?D(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&D("settings"),J()}).catch(()=>{n.connected=!1,ve()})}function dt(){return`
|
|
359
383
|
<div class="om-toolbar">
|
|
360
384
|
<div class="om-toolbar-header">
|
|
361
|
-
<span class="om-grab">${
|
|
385
|
+
<span class="om-grab">${g.grip}</span>
|
|
362
386
|
<span class="om-pill-brand">
|
|
363
|
-
<span class="om-pill-icon">${
|
|
387
|
+
<span class="om-pill-icon">${g.sparkle}</span>
|
|
364
388
|
<span class="om-pill-text">OpenMagic</span>
|
|
365
389
|
</span>
|
|
366
390
|
<span class="om-pill-divider"></span>
|
|
367
|
-
<button class="om-pill-btn" data-action="select" title="Select element">${
|
|
368
|
-
<button class="om-pill-btn" data-action="screenshot" title="Screenshot">${
|
|
369
|
-
<button class="om-pill-btn" data-action="network" title="Network & Performance">${
|
|
391
|
+
<button class="om-pill-btn" data-action="select" title="Select element">${g.crosshair}</button>
|
|
392
|
+
<button class="om-pill-btn" data-action="screenshot" title="Screenshot">${g.camera}</button>
|
|
393
|
+
<button class="om-pill-btn" data-action="network" title="Network & Performance">${g.activity}</button>
|
|
370
394
|
<span class="om-pill-divider"></span>
|
|
371
|
-
<button class="om-pill-btn" data-action="chat" title="Chat">${
|
|
372
|
-
<button class="om-pill-btn" data-action="settings" title="Settings">${
|
|
373
|
-
<button class="om-pill-btn" data-action="minimize" title="Minimize">${
|
|
395
|
+
<button class="om-pill-btn" data-action="chat" title="Chat">${g.chat}</button>
|
|
396
|
+
<button class="om-pill-btn" data-action="settings" title="Settings">${g.settings}</button>
|
|
397
|
+
<button class="om-pill-btn" data-action="minimize" title="Minimize">${g.minus}</button>
|
|
374
398
|
<span class="om-status-dot disconnected"></span>
|
|
375
399
|
</div>
|
|
376
400
|
<div class="om-panel om-hidden">
|
|
377
401
|
<div class="om-panel-header">
|
|
378
402
|
<span class="om-panel-title"></span>
|
|
379
403
|
<span class="om-panel-version">v${Ke}</span>
|
|
380
|
-
<button class="om-panel-clear" data-action="clear-chat" title="Clear chat">${
|
|
381
|
-
<button class="om-panel-close" data-action="close-panel">${
|
|
404
|
+
<button class="om-panel-clear" data-action="clear-chat" title="Clear chat">${g.trash}</button>
|
|
405
|
+
<button class="om-panel-close" data-action="close-panel">${g.x}</button>
|
|
382
406
|
</div>
|
|
383
407
|
<div class="om-panel-body"></div>
|
|
384
408
|
</div>
|
|
385
409
|
<div class="om-prompt-attachments"></div>
|
|
386
410
|
<div class="om-prompt-row">
|
|
387
411
|
<div class="om-prompt-context"></div>
|
|
388
|
-
<button class="om-prompt-attach" data-action="attach-image" title="Attach image">${
|
|
412
|
+
<button class="om-prompt-attach" data-action="attach-image" title="Attach image">${g.paperclip}</button>
|
|
389
413
|
<input class="om-prompt-input" type="text" placeholder="Describe what to change..." autocomplete="off" />
|
|
390
|
-
<button class="om-prompt-send" data-action="prompt-send">${
|
|
414
|
+
<button class="om-prompt-send" data-action="prompt-send">${g.send}</button>
|
|
391
415
|
<input type="file" class="om-file-input om-hidden" accept="image/*" multiple />
|
|
392
416
|
</div>
|
|
393
|
-
</div>`}function pt(e){e.addEventListener("click",o=>{let
|
|
417
|
+
</div>`}function pt(e){e.addEventListener("click",o=>{let a=o.target.closest("[data-action]");if(!a)return;o.preventDefault(),o.stopPropagation();let r=a.dataset.action;ft(r,a)}),e.addEventListener("change",o=>{let a=o.target,r=a.dataset.field;r&&(r==="provider"?(n.provider=a.value,n.model=j[n.provider]?.models[0]?.id||"",n.hasApiKey=n.configuredProviders[n.provider]||j[n.provider]?.local||!1,n.saveStatus="",S()):r==="model"&&(n.model=a.value))}),z.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),we())});let t=e.querySelector(".om-file-input");t&&t.addEventListener("change",()=>{ye(t.files),t.value=""});let s=e.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&&ye(a.files)}),z.addEventListener("paste",o=>{let a=o.clipboardData?.items;if(a){for(let r=0;r<a.length;r++)if(a[r].type.startsWith("image/")){let i=a[r].getAsFile();if(i){let c=new DataTransfer;c.items.add(i),ye(c.files)}}}})),Ce(o=>{o.type==="reconnected"&&(n.connected=!0,ve())}),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,x.querySelectorAll(".om-pill-btn:not([data-action='minimize']), .om-pill-divider, .om-status-dot").forEach(i=>i.style.display="");let r=v.querySelector(".om-prompt-row");r&&r.classList.remove("om-hidden")}else n.panelOpen?ne():D("chat");return}if(o.key==="Escape"){if(n.selecting)return;n.panelOpen&&(ne(),o.preventDefault())}}),z.addEventListener("keydown",o=>{(o.ctrlKey||o.metaKey)&&o.key==="Enter"&&(o.preventDefault(),we())})}function We(e){return n.roots.length>0?n.roots[0]+"/"+e:e}function mt(e,t){let s=t.split(`
|
|
394
418
|
`).map(i=>i.trim()).filter(i=>i.length>0);if(s.length===0)return null;let o=e.split(`
|
|
395
|
-
`),
|
|
396
|
-
`&&d--,{start:l,end:d}}}return null}async function ut(e){let
|
|
419
|
+
`),a=s[0],r=s[s.length-1];for(let i=0;i<o.length;i++){if(o[i].trim()!==a||i+s.length>o.length)continue;let c=!0;for(let l=0;l<s.length;l++)if(o[i+l].trim()!==s[l]){c=!1;break}if(c){let l=0;for(let p=0;p<i;p++)l+=o[p].length+1;let d=l;for(let p=i;p<i+s.length;p++)d+=o[p].length+1;return d>0&&d<=e.length&&e[d-1]===`
|
|
420
|
+
`&&d--,{start:l,end:d}}}return null}async function ut(e){let t=e.dataset.file,s=e.dataset.search,o=e.dataset.replace;if(!t||!s||!o)return;let a,r;try{a=xe(s),r=xe(o)}catch{n.messages.push({role:"system",content:`Failed to decode diff data for ${t}`}),S();return}let i=e.closest(".om-diff-card"),c=We(t);if(i){let l=i.querySelector(".om-diff-actions");l&&(l.innerHTML='<span class="om-spinner"></span> Applying...')}try{let d=(await k("fs.read",{path:c}))?.payload?.content;if(!d)n.messages.push({role:"system",content:`Could not read ${t} \u2014 file may not exist at ${c}`});else{let p=d.split(a).length-1;if(p===1){let m=await k("fs.write",{path:c,content:d.replace(a,r)});if(m?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${t} - ${m.payload?.error||"unknown"}`});else{let h=i?.dataset.diffIdx;h!==void 0?n.messages[parseInt(h)]={role:"system",content:`Applied change to ${t}`}:n.messages.push({role:"system",content:`Applied change to ${t}`})}}else if(p>1)n.messages.push({role:"system",content:`Found ${p} exact matches in ${t} \u2014 expected 1. Edit not applied.`});else{let m=mt(d,a);if(m){let h=d.slice(0,m.start)+r+d.slice(m.end),f=await k("fs.write",{path:c,content:h});if(f?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${t} - ${f.payload?.error||"unknown"}`});else{let E=i?.dataset.diffIdx;E!==void 0?n.messages[parseInt(E)]={role:"system",content:`Applied change to ${t} (fuzzy match \u2014 whitespace adjusted)`}:n.messages.push({role:"system",content:`Applied change to ${t} (fuzzy match)`})}}else n.messages.push({role:"system",content:`No matching code found in ${t}. The file may have changed since the suggestion.`})}}}catch(l){n.messages.push({role:"system",content:`Failed to apply: ${t} \u2014 ${l.message}`})}S(),F()}function gt(e){let t=e.dataset.idx;if(t!==void 0){let s=parseInt(t),a=n.messages[s]?.content.split("__")?.[3]||"file";n.messages[s]={role:"system",content:`Rejected change to ${a}`}}S(),F()}async function ht(e){let t=e.dataset.file;if(!t)return;let s=We(t),o=s+".openmagic-backup";try{let r=(await k("fs.read",{path:o}))?.payload?.content;r?(await k("fs.write",{path:s,content:r}),n.messages.push({role:"system",content:`Reverted change to ${t}`})):n.messages.push({role:"system",content:`No backup found for ${t}`})}catch{n.messages.push({role:"system",content:`Could not revert ${t} \u2014 backup may not exist`})}S()}function ft(e,t){switch(e){case"select":kt();break;case"screenshot":Et();break;case"chat":fe("chat");break;case"settings":fe("settings");break;case"close-panel":ne();break;case"prompt-send":we();break;case"save-settings":xt();break;case"get-key":{let s=t.dataset.url;s&&window.open(s,"_blank","noopener");break}case"change-key":{let s=v.querySelector("[data-key-change]");s&&s.classList.remove("om-hidden"),t.style.display="none";break}case"network":fe("chat"),vt();break;case"attach-image":wt();break;case"remove-attachment":{let s=parseInt(t.dataset.idx||"0",10);n.attachments.splice(s,1),Se();break}case"apply-diff":ut(t);break;case"reject-diff":gt(t);break;case"undo-diff":ht(t);break;case"clear-chat":{n.messages=[];try{sessionStorage.removeItem("__om_state__")}catch{}S();break}case"copy-msg":{let s=parseInt(t.dataset.idx||"0",10),o=n.messages[s];if(o){try{navigator.clipboard.writeText(o.content)}catch{}t.innerHTML=g.check,setTimeout(()=>{t.innerHTML=g.copy},1500)}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=v.querySelector(".om-panel"),o=v.querySelector(".om-prompt-row"),a=v.querySelector(".om-prompt-attachments"),r=x.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"),r.forEach(i=>i.style.display="none")):(o&&o.classList.remove("om-hidden"),a&&a.classList.remove("om-hidden"),r.forEach(i=>i.style.display=""),n.panelOpen&&n.activePanel&&s&&s.classList.remove("om-hidden"));break}}}function ve(){let e=v.querySelector(".om-status-dot");e&&(e.className=`om-status-dot ${n.connected?"connected":"disconnected"}`)}function J(){v.querySelectorAll(".om-pill-btn").forEach(e=>{let t=e.dataset.action;e.classList.toggle("active",t===n.activePanel||t==="select"&&n.selecting)})}function X(){let e=[];n.selectedElement&&e.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">${g.x}</button></span>`),n.screenshot&&e.push(`<span class="om-prompt-chip">Screenshot <button class="om-prompt-chip-x" data-action="clear-screenshot">${g.x}</button></span>`),n.attachments.length&&e.push(`<span class="om-prompt-chip">${n.attachments.length} image${n.attachments.length>1?"s":""}</span>`),n.groundedFiles.length&&e.push(`<span class="om-prompt-chip">${n.groundedFiles.length} files grounded</span>`),Ge.innerHTML=e.join("")}function D(e){n.panelOpen=!0,n.activePanel=e,Ee.classList.remove("om-hidden");let t=v.querySelector(".om-panel-title");t&&(t.textContent=e==="settings"?"Settings":"Chat"),S(),J()}function ne(){n.panelOpen=!1,n.activePanel="",Ee.classList.add("om-hidden"),J()}function fe(e){n.panelOpen&&n.activePanel===e?ne():D(e)}function S(){n.activePanel==="settings"?N.innerHTML=yt():n.activePanel==="chat"&&(N.innerHTML=bt(),F()),lt()}function yt(){let e=Object.entries(j).map(([f,E])=>{let b=n.configuredProviders[f]||E.local?" \u2713":"";return`<option value="${f}" ${n.provider===f?"selected":""}>${E.name}${b}</option>`}).join(""),t=j[n.provider],s=t?t.models.map(f=>`<option value="${f.id}" ${n.model===f.id?"selected":""}>${f.name}</option>`).join(""):'<option value="">Select provider first</option>',o=t?.local||!1,a=t?.keyUrl||"",r=t?.keyPlaceholder||"Enter API key...",i=n.configuredProviders[n.provider]||!1,c=n.updateAvailable?`<div class="om-update-banner">v${n.latestVersion} available <code class="om-update-cmd">npx openmagic@latest</code></div>`:"",l=i||o?`<div class="om-status om-status-success">${g.check} ${t?.name||"Provider"} connected</div>`:"",d=n.saveStatus==="saving"?'<span class="om-spinner"></span> Saving...':n.saveStatus==="saved"?`${g.check} Saved`:"Save",p=n.saveStatus==="saving"?"om-btn om-btn-saving":n.saveStatus==="saved"?"om-btn om-btn-saved":"om-btn",m=n.saveStatus==="saving"?"disabled":"",h="";return!o&&n.provider&&(i?h=`
|
|
397
421
|
<div class="om-field">
|
|
398
422
|
<label class="om-label">API Key</label>
|
|
399
423
|
<div class="om-key-configured">
|
|
400
|
-
${
|
|
424
|
+
${g.check} <span>Key configured</span>
|
|
401
425
|
<button class="om-btn-change-key" data-action="change-key">Change</button>
|
|
402
426
|
</div>
|
|
403
427
|
<div class="om-key-change-row om-hidden" data-key-change>
|
|
404
428
|
<div class="om-key-row">
|
|
405
|
-
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${
|
|
406
|
-
${
|
|
429
|
+
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${r}" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
|
430
|
+
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${g.externalLink} Get key</button>`:""}
|
|
407
431
|
</div>
|
|
408
432
|
</div>
|
|
409
|
-
</div>`:
|
|
433
|
+
</div>`:h=`
|
|
410
434
|
<div class="om-field">
|
|
411
435
|
<label class="om-label">API Key</label>
|
|
412
436
|
<div class="om-key-row">
|
|
413
|
-
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${
|
|
414
|
-
${
|
|
437
|
+
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${r}" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
|
438
|
+
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${g.externalLink} Get key</button>`:""}
|
|
415
439
|
</div>
|
|
416
|
-
${
|
|
440
|
+
${a?`<div class="om-key-hint"><a data-action="get-key" data-url="${a}">Get your ${t?.name||""} API key here</a></div>`:""}
|
|
417
441
|
</div>`),`
|
|
418
442
|
${c}
|
|
419
443
|
<div class="om-settings">
|
|
@@ -425,26 +449,26 @@
|
|
|
425
449
|
<label class="om-label">Model</label>
|
|
426
450
|
<select class="om-select" data-field="model"><option value="">Select Model...</option>${s}</select>
|
|
427
451
|
</div>
|
|
428
|
-
${
|
|
452
|
+
${h}
|
|
429
453
|
<button class="${p}" data-action="save-settings" ${m}>${d}</button>
|
|
430
454
|
${l}
|
|
431
|
-
</div>`}function bt(){if(!
|
|
432
|
-
<div class="om-diff-file">${
|
|
433
|
-
<div class="om-diff-removed">${
|
|
434
|
-
<div class="om-diff-added">${
|
|
455
|
+
</div>`}function bt(){if(!n.provider||!n.hasApiKey&&!j[n.provider]?.local)return'<div class="om-status om-status-error">Configure your provider in Settings first</div>';let e=n.messages.map((o,a)=>{if(o.content.startsWith("__DIFF__"))try{let i=JSON.parse(xe(o.content.slice(8))),c=be(i.search),l=be(i.replace);return`<div class="om-diff-card" data-diff-idx="${a}">
|
|
456
|
+
<div class="om-diff-file">${_(i.file)}</div>
|
|
457
|
+
<div class="om-diff-removed">${_(i.search.slice(0,200))}</div>
|
|
458
|
+
<div class="om-diff-added">${_(i.replace.slice(0,200))}</div>
|
|
435
459
|
<div class="om-diff-actions">
|
|
436
|
-
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${
|
|
437
|
-
<button class="om-btn-secondary om-btn-sm" data-action="reject-diff" data-idx="${
|
|
460
|
+
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${_(i.file)}" data-search="${c}" data-replace="${l}">Apply</button>
|
|
461
|
+
<button class="om-btn-secondary om-btn-sm" data-action="reject-diff" data-idx="${a}">Reject</button>
|
|
438
462
|
</div>
|
|
439
|
-
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(o.content.startsWith("Applied change to ")){let
|
|
440
|
-
// [FILE TRUNCATED \u2014 showing ${U} of ${q.length} chars]`),
|
|
441
|
-
// [FILE TRUNCATED \u2014 showing ${Y} of ${T.length} chars]`),
|
|
442
|
-
// [FILE TRUNCATED \u2014 showing ${re} of ${Z.length} chars]`),
|
|
443
|
-
Recent requests (${
|
|
463
|
+
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(o.content.startsWith("Applied change to ")){let i=o.content.replace("Applied change to ","").replace(" (fuzzy match \u2014 whitespace adjusted)","").replace(" (fuzzy match)","");return`<div class="om-msg om-msg-system">${_(o.content)} <button class="om-undo-btn" data-action="undo-diff" data-file="${_(i)}">Undo</button></div>`}let r=o.role==="user"||o.role==="assistant"?`<button class="om-copy-btn" data-action="copy-msg" data-idx="${a}" title="Copy">${g.copy}</button>`:"";return o.role==="assistant"?`<div class="om-msg om-msg-assistant">${$t(o.content)}${r}</div>`:`<div class="om-msg om-msg-${o.role}">${_(o.content)}${r}</div>`}).join(""),t=n.streaming?`<div class="om-msg om-msg-assistant"><span class="om-spinner"></span>${_(n.streamContent)}</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>':""}${e}${t}</div>`}function F(){requestAnimationFrame(()=>{let e=N.querySelector(".om-chat-messages");e&&(e.scrollTop=e.scrollHeight)})}async function xt(){let t=N.querySelector('[data-field="apiKey"]')?.value||"";if(!n.provider){n.saveStatus="error",te(),setTimeout(()=>{n.saveStatus="",S()},2e3);return}if(!He()){n.saveStatus="error",te();let o=N.querySelector('[data-action="save-settings"]');o&&(o.innerHTML="Not connected - check terminal"),setTimeout(()=>{n.saveStatus="",S()},3e3);return}let s={provider:n.provider,model:n.model};t&&(s.apiKey=t),n.saveStatus="saving",te();try{let o=await Promise.race([k("config.set",s),new Promise((a,r)=>setTimeout(()=>r(new Error("Save timed out")),8e3))]);t&&n.provider&&(n.configuredProviders[n.provider]=!0),n.hasApiKey=!!(t||n.configuredProviders[n.provider]),n.saveStatus="saved",te(),setTimeout(()=>{n.saveStatus="",n.activePanel==="settings"&&D("chat")},1200)}catch(o){n.saveStatus="error";let a=N.querySelector('[data-action="save-settings"]'),r=(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=r,a.className="om-btn",a.disabled=!1),setTimeout(()=>{n.saveStatus="",S()},4e3)}}function te(){let e=N.querySelector('[data-action="save-settings"]');e&&(n.saveStatus==="saving"?(e.innerHTML='<span class="om-spinner"></span> Saving...',e.className="om-btn om-btn-saving",e.disabled=!0):n.saveStatus==="saved"?(e.innerHTML=`${g.check} Saved`,e.className="om-btn om-btn-saved",e.disabled=!1):n.saveStatus==="error"?(e.innerHTML="Save failed - try again",e.className="om-btn",e.disabled=!1):(e.innerHTML="Save",e.className="om-btn",e.disabled=!1))}async function we(){let e=z.value.trim();if(!e||n.streaming)return;if(!n.provider||!n.hasApiKey&&!j[n.provider]?.local){D("settings");return}n.messages.push({role:"user",content:e}),n.streaming=!0,n.streamContent="",z.value="",D("chat");let t=Fe(n.selectedElement,n.screenshot);t.pageUrl=window.location.href,t.pageTitle=document.title,n.attachments.length>0&&(t.screenshot||(t.screenshot=n.attachments[0]),t.attachments=[...n.attachments]);let s=5,o=32e3,a=/\.(?:[cm]?[jt]sx?|svelte|vue|astro|html?|css|scss|less|php|py)$/i,r=N.querySelector(".om-msg-assistant:last-child");r&&(r.innerHTML='<span class="om-spinner"></span> Reading project files...');try{let l=await k("fs.list",{});l?.payload?.projectTree&&(t.projectTree=l.payload.projectTree);let p=(l?.payload?.files||[]).filter(u=>u.type==="file"&&a.test(u.path)),m=[e];if(n.selectedElement&&(n.selectedElement.id&&m.push(n.selectedElement.id),n.selectedElement.className&&m.push(n.selectedElement.className),n.selectedElement.textContent&&m.push(n.selectedElement.textContent.slice(0,100)),n.selectedElement.componentHint&&m.push(n.selectedElement.componentHint),n.selectedElement.ancestry))for(let u of n.selectedElement.ancestry)m.push(u);let h=m.filter(Boolean).join(" ").toLowerCase().split(/[^a-z0-9_-]+/).filter(u=>u.length>=2&&!["the","to","in","of","and","div","span","class","style"].includes(u)),E=window.location.pathname.split("/").filter(u=>u.length>1&&!/^\d+$/.test(u)),R=p.map(u=>{let y=0,M=u.path.toLowerCase();for(let P of E)M.includes(P.toLowerCase())&&(y+=15);if(n.selectedElement?.componentHint){let P=n.selectedElement.componentHint.toLowerCase();M.includes(P)&&(y+=12)}for(let P of h)M.includes(P)&&(y+=5);return/(component|page|route|layout|template|view)/.test(M)&&(y+=3),/page\.[jt]sx?$|layout\.[jt]sx?$|\+page\.svelte$/.test(M)&&(y+=5),{...u,score:y}}).sort((u,y)=>y.score-u.score),b=[],A=new Set,H=0;for(let u of R.slice(0,s)){if(u.score<=0||H>=o)break;try{let y=n.roots[0]||"",M=y?`${y}/${u.path}`:u.path,P=await k("fs.read",{path:M}),q=String(P?.payload?.content||"");if(!q)continue;let U=Math.min(8e3,o-H),se=q.slice(0,U);q.length>U&&(se+=`
|
|
464
|
+
// [FILE TRUNCATED \u2014 showing ${U} of ${q.length} chars]`),b.push({path:u.path,content:se}),A.add(u.path),H+=se.length;let Ve=u.path.replace(/\.[^.]+$/,""),Xe=[".module.css",".module.scss",".css",".scss",".styles.ts"];for(let ae of Xe){let w=Ve+ae;if(A.has(w)||H>=o)continue;if(p.find(K=>K.path===w)){try{let K=await k("fs.read",{path:y?`${y}/${w}`:w}),T=String(K?.payload?.content||"");if(T){let Y=Math.min(4e3,o-H),B=T.slice(0,Y);T.length>Y&&(B+=`
|
|
465
|
+
// [FILE TRUNCATED \u2014 showing ${Y} of ${T.length} chars]`),b.push({path:w,content:B}),A.add(w),H+=B.length}}catch{}break}}let Je=q.matchAll(/(?:import|from)\s+['"]\.?\.\/([\w/.-]+)['"]/g);for(let ae of Je){if(H>=o)break;let w=ae[1],O=u.path.replace(/\/[^/]+$/,""),K=[`${O}/${w}`,`${O}/${w}.tsx`,`${O}/${w}.ts`,`${O}/${w}.jsx`,`${O}/${w}.js`,`${O}/${w}/index.tsx`,`${O}/${w}/index.ts`];for(let T of K){if(A.has(T))break;if(p.find(B=>B.path===T)){try{let B=await k("fs.read",{path:y?`${y}/${T}`:T}),Z=String(B?.payload?.content||"");if(Z){let re=Math.min(8e3,o-H),ie=Z.slice(0,re);Z.length>re&&(ie+=`
|
|
466
|
+
// [FILE TRUNCATED \u2014 showing ${re} of ${Z.length} chars]`),b.push({path:T,content:ie}),A.add(T),H+=ie.length}}catch{}break}}}}catch{}}if(H<o)try{let u=n.roots[0]||"",y=await k("fs.read",{path:u?`${u}/package.json`:"package.json"}),M=String(y?.payload?.content||"");if(M)try{let P=JSON.parse(M),q={...P.dependencies,...P.devDependencies},U=JSON.stringify(q,null,2);b.push({path:"package.json (dependencies)",content:U.slice(0,2e3)})}catch{b.push({path:"package.json",content:M.slice(0,2e3)})}}catch{}if(b.length){t.files=b;let u=b.map(y=>y.path.split("/").pop()).join(", ");r&&(r.innerHTML=`<span class="om-spinner"></span> Thinking... (${b.length} files: ${u})`)}n.groundedFiles=b.map(u=>u.path)}catch{}let i=4,c=0;try{for(;c<=i;){n.streamContent="";let l=await Te("llm.chat",{provider:n.provider,model:n.model,messages:n.messages.map(m=>({role:m.role,content:m.content})),context:t},m=>{n.streamContent+=m;let h=N.querySelector(".om-msg-assistant:last-child");h&&(h.innerHTML=`<span class="om-spinner"></span>${_(n.streamContent)}`,F())}),d=n.streamContent||l?.content||"",p=d.match(/NEED_FILE:\s*"?([^\s"}\]]+)"?/)||d.match(/(?:need|provide|show|read|see|contents?\s+of)\s+(?:the\s+)?(?:file\s+)?[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i)||d.match(/(?:source\s+(?:file|code)\s+(?:for|of|at))\s+[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i);if(p&&!l?.modifications?.length&&c<i){let m=p[1].trim();c++,n.messages.push({role:"system",content:`Reading ${m}...`}),S();try{let h=n.roots[0]||"",f=h?`${h}/${m}`:m,E=await k("fs.read",{path:f}),R=String(E?.payload?.content||"");if(R)t.files||(t.files=[]),t.files.push({path:m,content:R.slice(0,8e3)}),n.messages.push({role:"assistant",content:d}),n.messages.push({role:"user",content:`Here is ${m}. Now please make the edit.`});else{n.messages.push({role:"system",content:`Could not read ${m}`});break}}catch{n.messages.push({role:"system",content:`File not found: ${m}`});break}continue}if(n.messages.push({role:"assistant",content:d}),l?.modifications?.length){for(let m of l.modifications)if(m.type==="edit"&&m.file&&m.search&&m.replace){let h=Math.random().toString(36).slice(2),f=JSON.stringify({id:h,file:m.file,search:m.search,replace:m.replace});n.messages.push({role:"system",content:`__DIFF__${be(f)}`})}}break}}catch(l){n.messages.push({role:"system",content:`Error: ${l.message}`})}n.streaming=!1,n.streamContent="",n.attachments=[],Se(),S(),F()}function vt(){let e=window.performance,t=e.getEntriesByType("navigation")[0],s=e.getEntriesByType("paint"),o=e.getEntriesByType("resource").slice(-20),a=ge(),r=he(),i=[];i.push("--- Network & Performance Capture ---"),t&&(i.push(`Page load: ${Math.round(t.loadEventEnd-t.startTime)}ms`),i.push(`DOM ready: ${Math.round(t.domContentLoadedEventEnd-t.startTime)}ms`),i.push(`TTFB: ${Math.round(t.responseStart-t.startTime)}ms`));let c=s.find(l=>l.name==="first-contentful-paint");if(c&&i.push(`FCP: ${Math.round(c.startTime)}ms`),a.length){i.push(`
|
|
467
|
+
Recent requests (${a.length}):`);for(let l of a.slice(-15))i.push(` ${l.method} ${l.url.slice(0,80)} \u2192 ${l.status||"pending"} (${l.duration||"?"}ms)`)}if(r.length){let l=r.filter(p=>p.level==="error"),d=r.filter(p=>p.level==="warn");l.length&&i.push(`
|
|
444
468
|
Console errors: ${l.length}`),d.length&&i.push(`Console warnings: ${d.length}`)}if(o.length){let l=[...o].sort((d,p)=>p.duration-d.duration).slice(0,5);i.push(`
|
|
445
|
-
Slowest resources:`);for(let d of l)i.push(` ${Math.round(d.duration)}ms \u2014 ${d.name.split("/").pop()?.slice(0,50)}`)}
|
|
446
|
-
`)}),S(),F(),X()}function wt(){let e=
|
|
447
|
-
<img src="${
|
|
448
|
-
<button class="om-attachment-remove" data-action="remove-attachment" data-idx="${s}">${
|
|
449
|
-
</div>`).join("")}}var W=null,V=null;function kt(){
|
|
469
|
+
Slowest resources:`);for(let d of l)i.push(` ${Math.round(d.duration)}ms \u2014 ${d.name.split("/").pop()?.slice(0,50)}`)}n.messages.push({role:"system",content:i.join(`
|
|
470
|
+
`)}),S(),F(),X()}function wt(){let e=v.querySelector(".om-file-input");e&&e.click()}function ye(e){if(e)for(let t=0;t<e.length&&n.attachments.length<5;t++){let s=e[t];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),Se())},o.readAsDataURL(s)}}function Se(){let e=v.querySelector(".om-prompt-attachments");if(e){if(!n.attachments.length){e.innerHTML="",e.classList.add("om-hidden");return}e.classList.remove("om-hidden"),e.innerHTML=n.attachments.map((t,s)=>`<div class="om-attachment-thumb">
|
|
471
|
+
<img src="${t}" alt="attachment" />
|
|
472
|
+
<button class="om-attachment-remove" data-action="remove-attachment" data-idx="${s}">${g.x}</button>
|
|
473
|
+
</div>`).join("")}}var W=null,V=null;function kt(){n.selecting?ke():oe()}function oe(){n.selecting=!0,document.body.style.cursor="crosshair",J(),V=t=>{let s=t.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})},W=t=>{t.preventDefault(),t.stopPropagation();let s=t.target;s.closest("openmagic-toolbar")||s.dataset?.openmagic||(n.selectedElement=_e(s),ke(),X(),z.focus())};let e=t=>{t.key==="Escape"&&ke()};document.addEventListener("mousemove",V,!0),document.addEventListener("click",W,!0),document.addEventListener("keydown",e,!0),oe._escHandler=e}function ke(){n.selecting=!1,document.body.style.cursor="",Re(),V&&(document.removeEventListener("mousemove",V,!0),V=null),W&&(document.removeEventListener("click",W,!0),W=null);let e=oe._escHandler;e&&(document.removeEventListener("keydown",e,!0),oe._escHandler=null),J()}async function Et(){let e;try{let s=n.selectedElement?.cssSelector?.trim();s&&(e=document.querySelector(s)||void 0)}catch{}let t=await Ae(e||void 0);t&&(n.screenshot=t,X(),z.focus())}function St(){let e=!1,t=0,s=0,o=0,a=0;x.addEventListener("mousedown",r=>{let i=r.target;if(i.closest("[data-action]")||!i.closest(".om-grab")&&!i.closest(".om-pill-brand"))return;e=!0,t=r.clientX,s=r.clientY;let c=x.getBoundingClientRect();o=c.left,a=c.top,r.preventDefault()}),document.addEventListener("mousemove",r=>{e&&(x.style.left=o+r.clientX-t+"px",x.style.top=a+r.clientY-s+"px",x.style.right="auto",x.style.bottom="auto")}),document.addEventListener("mouseup",()=>{if(e){e=!1;try{localStorage.setItem("__om_pos__",JSON.stringify({left:x.style.left,top:x.style.top}))}catch{}}})}function _(e){let t=document.createElement("div");return t.textContent=e,t.innerHTML}function $t(e){let t=_(e);return t=t.replace(/```(\w*)\n([\s\S]*?)```/g,'<pre class="om-code-block"><code>$2</code></pre>'),t=t.replace(/`([^`]+)`/g,'<code class="om-inline-code">$1</code>'),t=t.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),t=t.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g,"<em>$1</em>"),t=t.replace(/\n/g,"<br>"),t}function Lt(){fetch("https://registry.npmjs.org/openmagic/latest",{headers:{Accept:"application/json"},signal:AbortSignal.timeout(5e3)}).then(e=>e.ok?e.json():null).then(e=>{if(!e?.version)return;let t=e.version.split(".").map(Number),s=Ke.split(".").map(Number);for(let o=0;o<3;o++){if((t[o]||0)>(s[o]||0)){n.updateAvailable=!0,n.latestVersion=e.version,Mt();return}if((t[o]||0)<(s[o]||0))return}}).catch(()=>{})}function Mt(){if(v.querySelector(".om-update-dot"))return;let t=document.createElement("span");t.className="om-update-dot",t.title=`v${n.latestVersion} available`,t.addEventListener("click",()=>D("settings"));let s=v.querySelector(".om-toolbar-header");s&&s.appendChild(t)}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ue):Ue());})();
|
|
450
474
|
//# sourceMappingURL=index.global.js.map
|