openmagic 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- "use strict";var OpenMagicToolbar=(()=>{var $=`
1
+ #!/usr/bin/env node
2
+ "use strict";var OpenMagicToolbar=(()=>{var N=`
2
3
  :host {
3
4
  all: initial;
4
5
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
@@ -574,92 +575,82 @@
574
575
  flex-shrink: 0;
575
576
  }
576
577
 
577
- /* Auth tabs */
578
- .om-auth-tabs {
578
+ /* API Key row with connect button */
579
+ .om-key-row {
579
580
  display: flex;
580
- gap: 0;
581
- margin-bottom: 8px;
582
- border: 1px solid rgba(255, 255, 255, 0.1);
583
- border-radius: 8px;
584
- overflow: hidden;
581
+ gap: 8px;
582
+ align-items: stretch;
585
583
  }
586
584
 
587
- .om-auth-tab {
585
+ .om-key-input {
588
586
  flex: 1;
589
- background: transparent;
590
- border: none;
591
- color: #888;
587
+ min-width: 0;
588
+ }
589
+
590
+ .om-btn-connect {
591
+ display: flex;
592
+ align-items: center;
593
+ gap: 5px;
592
594
  padding: 8px 12px;
595
+ background: rgba(108, 92, 231, 0.12);
596
+ border: 1px solid rgba(108, 92, 231, 0.25);
597
+ border-radius: 8px;
598
+ color: #a29bfe;
593
599
  font-size: 12px;
594
600
  font-weight: 600;
595
601
  font-family: inherit;
596
602
  cursor: pointer;
603
+ white-space: nowrap;
597
604
  transition: all 0.15s;
598
605
  }
599
606
 
600
- .om-auth-tab:hover {
601
- color: #ccc;
602
- background: rgba(255, 255, 255, 0.03);
603
- }
604
-
605
- .om-auth-tab.active {
606
- background: rgba(108, 92, 231, 0.15);
607
- color: #a29bfe;
608
- }
609
-
610
- .om-auth-hint {
611
- background: rgba(255, 255, 255, 0.02);
612
- border: 1px solid rgba(255, 255, 255, 0.05);
613
- border-radius: 8px;
614
- padding: 10px 12px;
615
- margin-top: 8px;
616
- font-size: 12px;
617
- color: #888;
618
- line-height: 1.6;
619
- }
620
-
621
- .om-auth-hint p {
622
- margin-bottom: 6px;
607
+ .om-btn-connect:hover {
608
+ background: rgba(108, 92, 231, 0.2);
609
+ border-color: rgba(108, 92, 231, 0.4);
610
+ color: #c4b5fd;
623
611
  }
624
612
 
625
- .om-auth-hint ol {
626
- padding-left: 18px;
613
+ .om-key-hint {
614
+ font-size: 11px;
615
+ color: #666;
616
+ margin-top: 6px;
617
+ line-height: 1.5;
627
618
  }
628
619
 
629
- .om-auth-hint li {
630
- margin-bottom: 3px;
620
+ .om-key-hint a {
621
+ color: #a29bfe;
622
+ cursor: pointer;
623
+ text-decoration: none;
631
624
  }
632
625
 
633
- .om-auth-hint code {
634
- background: rgba(108, 92, 231, 0.1);
635
- padding: 1px 5px;
636
- border-radius: 3px;
637
- font-size: 11px;
638
- color: #a29bfe;
626
+ .om-key-hint a:hover {
627
+ text-decoration: underline;
628
+ color: #c4b5fd;
639
629
  }
640
630
 
641
- .om-auth-hint strong {
642
- color: #ccc;
631
+ .om-status svg {
632
+ vertical-align: -2px;
633
+ margin-right: 4px;
643
634
  }
644
- `;var u=null,p=new Map,Q=[],M=[],E=!1,k=null;function L(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function S(e,o){return new Promise((t,i)=>{try{u=new WebSocket(`ws://127.0.0.1:${e}/__openmagic__/ws`),u.onopen=()=>{let r=L();C({id:r,type:"handshake",payload:{token:o}}),p.set(r,a=>{if(a.type==="handshake.ok"){E=!0;for(let s of M)u?.send(s);M=[],t()}else a.type==="error"&&i(new Error(a.payload?.message||"Handshake failed"))})},u.onmessage=r=>{try{let a=JSON.parse(r.data);a.id&&p.has(a.id)&&(p.get(a.id)(a),(a.type==="llm.done"||a.type==="llm.error"||!a.type.startsWith("llm."))&&p.delete(a.id));for(let s of Q)s(a)}catch{}},u.onclose=()=>{E=!1,k||(k=setTimeout(()=>{k=null,S(e,o).catch(()=>{})},2e3))},u.onerror=()=>{}}catch(r){i(r)}})}function C(e){let o=JSON.stringify(e);u&&E?u.send(o):M.push(o)}function g(e,o){return new Promise((t,i)=>{let r=L(),a=setTimeout(()=>{p.delete(r),i(new Error("Request timeout"))},3e4);p.set(r,s=>{clearTimeout(a),s.type==="error"?i(new Error(s.payload?.message||"Unknown error")):t(s)}),C({id:r,type:e,payload:o})})}function N(e,o,t){return new Promise((i,r)=>{let a=L(),s=setTimeout(()=>{p.delete(a),r(new Error("Stream timeout"))},12e4);p.set(a,l=>{l.type==="llm.chunk"?t(l.payload?.delta||""):l.type==="llm.done"?(clearTimeout(s),p.delete(a),i(l.payload)):(l.type==="llm.error"||l.type==="error")&&(clearTimeout(s),p.delete(a),r(new Error(l.payload?.message||"Stream error")))}),C({id:a,type:e,payload:o})})}var Z=["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 O(e){let o=window.getComputedStyle(e),t={};for(let r of Z)t[r]=o.getPropertyValue(r);let i=e.getBoundingClientRect();return{tagName:e.tagName.toLowerCase(),id:e.id||"",className:e.className||"",textContent:(e.textContent||"").trim().slice(0,200),outerHTML:ee(e),cssSelector:te(e),xpath:oe(e),computedStyles:t,rect:{x:i.x,y:i.y,width:i.width,height:i.height}}}function ee(e){let o=e.cloneNode(!0);o.querySelectorAll("script, style, svg").forEach(r=>r.remove());let i=o.outerHTML;if(i.length>2e3){let r=e.tagName.toLowerCase(),a=Array.from(e.attributes).map(l=>`${l.name}="${l.value}"`).join(" "),s=Array.from(e.children).slice(0,5).map(l=>`<${l.tagName.toLowerCase()} .../>`).join(`
635
+ `;var g=null,p=new Map,Z=[],M=[],E=!1,k=null;function L(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function S(e,t){return new Promise((n,i)=>{try{g=new WebSocket(`ws://127.0.0.1:${e}/__openmagic__/ws`),g.onopen=()=>{let r=L();C({id:r,type:"handshake",payload:{token:t}}),p.set(r,a=>{if(a.type==="handshake.ok"){E=!0;for(let s of M)g?.send(s);M=[],n()}else a.type==="error"&&i(new Error(a.payload?.message||"Handshake failed"))})},g.onmessage=r=>{try{let a=JSON.parse(r.data);a.id&&p.has(a.id)&&(p.get(a.id)(a),(a.type==="llm.done"||a.type==="llm.error"||!a.type.startsWith("llm."))&&p.delete(a.id));for(let s of Z)s(a)}catch{}},g.onclose=()=>{E=!1,k||(k=setTimeout(()=>{k=null,S(e,t).catch(()=>{})},2e3))},g.onerror=()=>{}}catch(r){i(r)}})}function C(e){let t=JSON.stringify(e);g&&E?g.send(t):M.push(t)}function h(e,t){return new Promise((n,i)=>{let r=L(),a=setTimeout(()=>{p.delete(r),i(new Error("Request timeout"))},3e4);p.set(r,s=>{clearTimeout(a),s.type==="error"?i(new Error(s.payload?.message||"Unknown error")):n(s)}),C({id:r,type:e,payload:t})})}function O(e,t,n){return new Promise((i,r)=>{let a=L(),s=setTimeout(()=>{p.delete(a),r(new Error("Stream timeout"))},12e4);p.set(a,l=>{l.type==="llm.chunk"?n(l.payload?.delta||""):l.type==="llm.done"?(clearTimeout(s),p.delete(a),i(l.payload)):(l.type==="llm.error"||l.type==="error")&&(clearTimeout(s),p.delete(a),r(new Error(l.payload?.message||"Stream error")))}),C({id:a,type:e,payload:t})})}var te=["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){let t=window.getComputedStyle(e),n={};for(let r of te)n[r]=t.getPropertyValue(r);let i=e.getBoundingClientRect();return{tagName:e.tagName.toLowerCase(),id:e.id||"",className:e.className||"",textContent:(e.textContent||"").trim().slice(0,200),outerHTML:ne(e),cssSelector:oe(e),xpath:ae(e),computedStyles:n,rect:{x:i.x,y:i.y,width:i.width,height:i.height}}}function ne(e){let t=e.cloneNode(!0);t.querySelectorAll("script, style, svg").forEach(r=>r.remove());let i=t.outerHTML;if(i.length>2e3){let r=e.tagName.toLowerCase(),a=Array.from(e.attributes).map(l=>`${l.name}="${l.value}"`).join(" "),s=Array.from(e.children).slice(0,5).map(l=>`<${l.tagName.toLowerCase()} .../>`).join(`
645
636
  `);i=`<${r} ${a}>
646
637
  ${s}
647
638
  ${e.children.length>5?`<!-- +${e.children.length-5} more children -->`:""}
648
- </${r}>`}return i}function te(e){if(e.id)return`#${e.id}`;let o=[],t=e;for(;t&&t!==document.body;){let i=t.tagName.toLowerCase();if(t.id){o.unshift(`#${t.id}`);break}if(t.className&&typeof t.className=="string"){let a=t.className.trim().split(/\s+/).filter(s=>!s.startsWith("__")&&s.length<30).slice(0,2);a.length>0&&(i+="."+a.join("."))}let r=t.parentElement;if(r){let a=Array.from(r.children).filter(s=>s.tagName===t.tagName);if(a.length>1){let s=a.indexOf(t)+1;i+=`:nth-child(${s})`}}o.unshift(i),t=t.parentElement}return o.join(" > ")}function oe(e){let o=[],t=e;for(;t&&t!==document;){if(t.nodeType===Node.ELEMENT_NODE){let i=t,r=1,a=i.previousElementSibling;for(;a;)a.tagName===i.tagName&&r++,a=a.previousElementSibling;o.unshift(`${i.tagName.toLowerCase()}[${r}]`)}t=t.parentNode}return"/"+o.join("/")}var d=null;function A(e){d||(d=document.createElement("div"),d.style.cssText=`
639
+ </${r}>`}return i}function oe(e){if(e.id)return`#${e.id}`;let t=[],n=e;for(;n&&n!==document.body;){let i=n.tagName.toLowerCase();if(n.id){t.unshift(`#${n.id}`);break}if(n.className&&typeof n.className=="string"){let a=n.className.trim().split(/\s+/).filter(s=>!s.startsWith("__")&&s.length<30).slice(0,2);a.length>0&&(i+="."+a.join("."))}let r=n.parentElement;if(r){let a=Array.from(r.children).filter(s=>s.tagName===n.tagName);if(a.length>1){let s=a.indexOf(n)+1;i+=`:nth-child(${s})`}}t.unshift(i),n=n.parentElement}return t.join(" > ")}function ae(e){let t=[],n=e;for(;n&&n!==document;){if(n.nodeType===Node.ELEMENT_NODE){let i=n,r=1,a=i.previousElementSibling;for(;a;)a.tagName===i.tagName&&r++,a=a.previousElementSibling;t.unshift(`${i.tagName.toLowerCase()}[${r}]`)}n=n.parentNode}return"/"+t.join("/")}var d=null;function A(e){d||(d=document.createElement("div"),d.style.cssText=`
649
640
  position: fixed;
650
641
  pointer-events: none;
651
642
  z-index: 2147483646;
652
643
  border: 2px solid #6c5ce7;
653
644
  background: rgba(108, 92, 231, 0.1);
654
645
  transition: all 0.1s ease;
655
- `,d.dataset.openmagic="highlight",document.body.appendChild(d)),d.style.left=`${e.x}px`,d.style.top=`${e.y}px`,d.style.width=`${e.width}px`,d.style.height=`${e.height}px`,d.style.display="block"}function _(){d&&(d.style.display="none")}async function R(e){try{return e?await ae(e):await ne()}catch(o){return console.warn("[OpenMagic] Screenshot capture failed:",o),null}}async function ne(){let e=document.createElement("canvas"),o=window.devicePixelRatio||1;e.width=window.innerWidth*o,e.height=window.innerHeight*o;let t=e.getContext("2d");t.scale(o,o);try{let i=await q(document.body),r=await D(i,window.innerWidth,window.innerHeight);return t.drawImage(r,0,0),e.toDataURL("image/png")}catch{return null}}async function ae(e){let o=e.getBoundingClientRect(),t=document.createElement("canvas"),i=window.devicePixelRatio||1;t.width=o.width*i,t.height=o.height*i;let r=t.getContext("2d");r.scale(i,i);try{let a=await q(e),s=await D(a,o.width,o.height);return r.drawImage(s,0,0),t.toDataURL("image/png")}catch{return null}}function q(e){return new Promise(o=>{let t=e.cloneNode(!0);z(e,t);let i=e.getBoundingClientRect(),r=i.width,a=i.height,s=`
646
+ `,d.dataset.openmagic="highlight",document.body.appendChild(d)),d.style.left=`${e.x}px`,d.style.top=`${e.y}px`,d.style.width=`${e.width}px`,d.style.height=`${e.height}px`,d.style.display="block"}function R(){d&&(d.style.display="none")}async function q(e){try{return e?await re(e):await ie()}catch(t){return console.warn("[OpenMagic] Screenshot capture failed:",t),null}}async function ie(){let e=document.createElement("canvas"),t=window.devicePixelRatio||1;e.width=window.innerWidth*t,e.height=window.innerHeight*t;let n=e.getContext("2d");n.scale(t,t);try{let i=await z(document.body),r=await G(i,window.innerWidth,window.innerHeight);return n.drawImage(r,0,0),e.toDataURL("image/png")}catch{return null}}async function re(e){let t=e.getBoundingClientRect(),n=document.createElement("canvas"),i=window.devicePixelRatio||1;n.width=t.width*i,n.height=t.height*i;let r=n.getContext("2d");r.scale(i,i);try{let a=await z(e),s=await G(a,t.width,t.height);return r.drawImage(s,0,0),n.toDataURL("image/png")}catch{return null}}function z(e){return new Promise(t=>{let n=e.cloneNode(!0);D(e,n);let i=e.getBoundingClientRect(),r=i.width,a=i.height,s=`
656
647
  <svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${a}">
657
648
  <foreignObject width="100%" height="100%">
658
649
  <div xmlns="http://www.w3.org/1999/xhtml" style="width:${r}px;height:${a}px;overflow:hidden;">
659
- ${t.outerHTML}
650
+ ${n.outerHTML}
660
651
  </div>
661
652
  </foreignObject>
662
- </svg>`;o(s)})}function z(e,o){let t=window.getComputedStyle(e),i="";for(let s=0;s<t.length;s++){let l=t[s];i+=`${l}:${t.getPropertyValue(l)};`}o.style.cssText=i;let r=e.children,a=o.children;for(let s=0;s<r.length&&s<a.length;s++)z(r[s],a[s])}function D(e,o,t){return new Promise((i,r)=>{let a=new Image,s=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),l=URL.createObjectURL(s);a.onload=()=>{URL.revokeObjectURL(l),i(a)},a.onerror=()=>{URL.revokeObjectURL(l),r(new Error("Failed to load SVG image"))},a.width=o,a.height=t,a.src=l})}var x=[];var G=!1;function I(){if(G)return;G=!0;let e=window.fetch;window.fetch=async function(...i){let r=new Request(...i),a={method:r.method,url:r.url,timestamp:Date.now()};try{let s=await e.apply(this,i);return a.status=s.status,a.duration=Date.now()-a.timestamp,T(a),s}catch(s){throw a.status=0,a.duration=Date.now()-a.timestamp,T(a),s}};let o=XMLHttpRequest.prototype.open,t=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(i,r,...a){return this.__om_method=i,this.__om_url=r,this.__om_start=Date.now(),o.apply(this,[i,r,...a])},XMLHttpRequest.prototype.send=function(...i){return this.addEventListener("loadend",()=>{T({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()})}),t.apply(this,i)}}function T(e){e.url.includes("__openmagic__")||(x.push(e),x.length>50&&x.shift())}function ie(){return[...x]}var v=[],re=100,j=!1;function K(){if(j)return;j=!0;let e=["log","warn","error","info","debug"];for(let o of e){let t=console[o];console[o]=function(...i){v.push({level:o,args:i.map(r=>{try{return typeof r=="object"?JSON.stringify(r).slice(0,500):String(r)}catch{return String(r)}}),timestamp:Date.now()}),v.length>re&&v.shift(),t.apply(console,i)}}}function se(){return[...v]}function B(e,o){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:o||void 0,networkLogs:ie().map(t=>({method:t.method,url:t.url,status:t.status,duration:t.duration,timestamp:t.timestamp})),consoleLogs:se().map(t=>({level:t.level,args:t.args,timestamp:t.timestamp}))}}var w={openai:{name:"OpenAI",models:[{id:"gpt-5.4",name:"GPT-5.4"},{id:"gpt-5.4-pro",name:"GPT-5.4 Pro"},{id:"gpt-5.4-mini",name:"GPT-5.4 Mini"},{id:"gpt-5.4-nano",name:"GPT-5.4 Nano"},{id:"gpt-5.2",name:"GPT-5.2 Thinking"},{id:"gpt-5.2-pro",name:"GPT-5.2 Pro"},{id:"o3",name:"o3 (Reasoning)"},{id:"o4-mini",name:"o4-mini (Reasoning)"},{id:"gpt-4.1",name:"GPT-4.1"},{id:"gpt-4.1-mini",name:"GPT-4.1 Mini"},{id:"codex-mini-latest",name:"Codex Mini"}],keyPlaceholder:"sk-..."},anthropic:{name:"Anthropic",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"},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5"},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5"},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4"},{id:"claude-opus-4-20250514",name:"Claude Opus 4"}],keyPlaceholder:"sk-ant-..."},google:{name:"Google Gemini",models:[{id:"gemini-3.1-pro-preview",name:"Gemini 3.1 Pro"},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash"},{id:"gemini-3.1-flash-lite-preview",name:"Gemini 3.1 Flash Lite"},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash"},{id:"gemini-2.5-flash-lite",name:"Gemini 2.5 Flash Lite"}],keyPlaceholder:"AIza..."},xai:{name:"xAI (Grok)",models:[{id:"grok-4.20-0309-reasoning",name:"Grok 4.20 Reasoning"},{id:"grok-4.20-0309-non-reasoning",name:"Grok 4.20"},{id:"grok-4-1-fast-reasoning",name:"Grok 4.1 Fast Reasoning"},{id:"grok-4-1-fast-non-reasoning",name:"Grok 4.1 Fast"}],keyPlaceholder:"xai-..."},deepseek:{name:"DeepSeek",models:[{id:"deepseek-chat",name:"DeepSeek V3.2"},{id:"deepseek-reasoner",name:"DeepSeek R1"}],keyPlaceholder:"sk-..."},mistral:{name:"Mistral",models:[{id:"mistral-large-3-25-12",name:"Mistral Large 3"},{id:"mistral-small-4-0-26-03",name:"Mistral Small 4"},{id:"codestral-2508",name:"Codestral"},{id:"devstral-2-25-12",name:"Devstral 2"},{id:"magistral-medium-1-2-25-09",name:"Magistral Medium"}],keyPlaceholder:"..."},groq:{name:"Groq",models:[{id:"meta-llama/llama-4-scout-17b-16e-instruct",name:"Llama 4 Scout 17B"},{id:"llama-3.3-70b-versatile",name:"Llama 3.3 70B"},{id:"llama-3.1-8b-instant",name:"Llama 3.1 8B Instant"},{id:"qwen/qwen3-32b",name:"Qwen 3 32B"}],keyPlaceholder:"gsk_..."},minimax:{name:"MiniMax",models:[{id:"MiniMax-M2.7",name:"MiniMax M2.7"},{id:"MiniMax-M2.7-highspeed",name:"M2.7 Highspeed"},{id:"MiniMax-M2.5",name:"MiniMax M2.5"}],keyPlaceholder:"MiniMax key..."},moonshot:{name:"Kimi (Moonshot)",models:[{id:"kimi-k2.5",name:"Kimi K2.5"},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking"}],keyPlaceholder:"Moonshot key..."},qwen:{name:"Qwen (Alibaba)",models:[{id:"qwen3.5-plus",name:"Qwen 3.5 Plus"},{id:"qwen-max",name:"Qwen Max"},{id:"qwen-turbo",name:"Qwen Turbo"}],keyPlaceholder:"DashScope key..."},zhipu:{name:"Zhipu AI (GLM)",models:[{id:"glm-5",name:"GLM-5"},{id:"glm-4.7",name:"GLM-4.7"},{id:"glm-4.6",name:"GLM-4.6"}],keyPlaceholder:"Zhipu key..."},doubao:{name:"Doubao (ByteDance)",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"}],keyPlaceholder:"Volcano key..."},ollama:{name:"Ollama (Local)",models:[],keyPlaceholder:"not required",local:!0},openrouter:{name:"OpenRouter",models:[],keyPlaceholder:"sk-or-..."}},P="0.6.0",n={connected:!1,panelOpen:!1,activePanel:null,selecting:!1,selectedElement:null,screenshot:null,messages:[],streaming:!1,streamContent:"",provider:"",model:"",hasApiKey:!1,roots:[],updateAvailable:!1,latestVersion:""},y,h;function F(){if(document.querySelector("openmagic-toolbar"))return;let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",y=e.attachShadow({mode:"closed"});let o=document.createElement("style");o.textContent=$,y.appendChild(o),h=document.createElement("div"),y.appendChild(h),document.body.appendChild(e),I(),K(),he();let t=window.__OPENMAGIC_CONFIG__;t&&S(t.wsPort,t.token).then(()=>{n.connected=!0,g("config.get").then(i=>{n.provider=i.payload?.provider||"",n.model=i.payload?.model||"",n.hasApiKey=i.payload?.hasApiKey||!1,n.roots=i.payload?.roots||[],(!n.provider||!n.hasApiKey)&&(n.panelOpen=!0,n.activePanel="settings"),c()})}).catch(i=>{console.error("[OpenMagic] Connection failed:",i),n.connected=!1,c()}),c()}function c(){if(h.innerHTML="",n.panelOpen&&n.activePanel){let o=document.createElement("div");o.className="om-panel",n.activePanel==="settings"?o.innerHTML=le():n.activePanel==="chat"&&(o.innerHTML=ce()),h.appendChild(o),de(o)}let e=document.createElement("div");if(e.className="om-pill",e.innerHTML=`
653
+ </svg>`;t(s)})}function D(e,t){let n=window.getComputedStyle(e),i="";for(let s=0;s<n.length;s++){let l=n[s];i+=`${l}:${n.getPropertyValue(l)};`}t.style.cssText=i;let r=e.children,a=t.children;for(let s=0;s<r.length&&s<a.length;s++)D(r[s],a[s])}function G(e,t,n){return new Promise((i,r)=>{let a=new Image,s=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),l=URL.createObjectURL(s);a.onload=()=>{URL.revokeObjectURL(l),i(a)},a.onerror=()=>{URL.revokeObjectURL(l),r(new Error("Failed to load SVG image"))},a.width=t,a.height=n,a.src=l})}var y=[];var j=!1;function K(){if(j)return;j=!0;let e=window.fetch;window.fetch=async function(...i){let r=new Request(...i),a={method:r.method,url:r.url,timestamp:Date.now()};try{let s=await e.apply(this,i);return a.status=s.status,a.duration=Date.now()-a.timestamp,T(a),s}catch(s){throw a.status=0,a.duration=Date.now()-a.timestamp,T(a),s}};let t=XMLHttpRequest.prototype.open,n=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(i,r,...a){return this.__om_method=i,this.__om_url=r,this.__om_start=Date.now(),t.apply(this,[i,r,...a])},XMLHttpRequest.prototype.send=function(...i){return this.addEventListener("loadend",()=>{T({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()})}),n.apply(this,i)}}function T(e){e.url.includes("__openmagic__")||(y.push(e),y.length>50&&y.shift())}function se(){return[...y]}var v=[],le=100,I=!1;function B(){if(I)return;I=!0;let e=["log","warn","error","info","debug"];for(let t of e){let n=console[t];console[t]=function(...i){v.push({level:t,args:i.map(r=>{try{return typeof r=="object"?JSON.stringify(r).slice(0,500):String(r)}catch{return String(r)}}),timestamp:Date.now()}),v.length>le&&v.shift(),n.apply(console,i)}}}function ce(){return[...v]}function F(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:se().map(n=>({method:n.method,url:n.url,status:n.status,duration:n.duration,timestamp:n.timestamp})),consoleLogs:ce().map(n=>({level:n.level,args:n.args,timestamp:n.timestamp}))}}var P={openai:{name:"OpenAI",models:[{id:"gpt-5.4",name:"GPT-5.4"},{id:"gpt-5.4-pro",name:"GPT-5.4 Pro"},{id:"gpt-5.4-mini",name:"GPT-5.4 Mini"},{id:"gpt-5.4-nano",name:"GPT-5.4 Nano"},{id:"gpt-5.2",name:"GPT-5.2 Thinking"},{id:"gpt-5.2-pro",name:"GPT-5.2 Pro"},{id:"o3",name:"o3 (Reasoning)"},{id:"o4-mini",name:"o4-mini (Reasoning)"},{id:"gpt-4.1",name:"GPT-4.1"},{id:"gpt-4.1-mini",name:"GPT-4.1 Mini"},{id:"codex-mini-latest",name:"Codex Mini"}],keyPlaceholder:"sk-..."},anthropic:{name:"Anthropic",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"},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5"},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5"},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4"},{id:"claude-opus-4-20250514",name:"Claude Opus 4"}],keyPlaceholder:"sk-ant-..."},google:{name:"Google Gemini",models:[{id:"gemini-3.1-pro-preview",name:"Gemini 3.1 Pro"},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash"},{id:"gemini-3.1-flash-lite-preview",name:"Gemini 3.1 Flash Lite"},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash"},{id:"gemini-2.5-flash-lite",name:"Gemini 2.5 Flash Lite"}],keyPlaceholder:"AIza..."},xai:{name:"xAI (Grok)",models:[{id:"grok-4.20-0309-reasoning",name:"Grok 4.20 Reasoning"},{id:"grok-4.20-0309-non-reasoning",name:"Grok 4.20"},{id:"grok-4-1-fast-reasoning",name:"Grok 4.1 Fast Reasoning"},{id:"grok-4-1-fast-non-reasoning",name:"Grok 4.1 Fast"}],keyPlaceholder:"xai-..."},deepseek:{name:"DeepSeek",models:[{id:"deepseek-chat",name:"DeepSeek V3.2"},{id:"deepseek-reasoner",name:"DeepSeek R1"}],keyPlaceholder:"sk-..."},mistral:{name:"Mistral",models:[{id:"mistral-large-3-25-12",name:"Mistral Large 3"},{id:"mistral-small-4-0-26-03",name:"Mistral Small 4"},{id:"codestral-2508",name:"Codestral"},{id:"devstral-2-25-12",name:"Devstral 2"},{id:"magistral-medium-1-2-25-09",name:"Magistral Medium"}],keyPlaceholder:"..."},groq:{name:"Groq",models:[{id:"meta-llama/llama-4-scout-17b-16e-instruct",name:"Llama 4 Scout 17B"},{id:"llama-3.3-70b-versatile",name:"Llama 3.3 70B"},{id:"llama-3.1-8b-instant",name:"Llama 3.1 8B Instant"},{id:"qwen/qwen3-32b",name:"Qwen 3 32B"}],keyPlaceholder:"gsk_..."},minimax:{name:"MiniMax",models:[{id:"MiniMax-M2.7",name:"MiniMax M2.7"},{id:"MiniMax-M2.7-highspeed",name:"M2.7 Highspeed"},{id:"MiniMax-M2.5",name:"MiniMax M2.5"}],keyPlaceholder:"MiniMax key..."},moonshot:{name:"Kimi (Moonshot)",models:[{id:"kimi-k2.5",name:"Kimi K2.5"},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking"}],keyPlaceholder:"Moonshot key..."},qwen:{name:"Qwen (Alibaba)",models:[{id:"qwen3.5-plus",name:"Qwen 3.5 Plus"},{id:"qwen-max",name:"Qwen Max"},{id:"qwen-turbo",name:"Qwen Turbo"}],keyPlaceholder:"DashScope key..."},zhipu:{name:"Zhipu AI (GLM)",models:[{id:"glm-5",name:"GLM-5"},{id:"glm-4.7",name:"GLM-4.7"},{id:"glm-4.6",name:"GLM-4.6"}],keyPlaceholder:"Zhipu key..."},doubao:{name:"Doubao (ByteDance)",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"}],keyPlaceholder:"Volcano key..."},ollama:{name:"Ollama (Local)",models:[],keyPlaceholder:"not required",local:!0},openrouter:{name:"OpenRouter",models:[],keyPlaceholder:"sk-or-..."}},$="0.7.0",o={connected:!1,panelOpen:!1,activePanel:null,selecting:!1,selectedElement:null,screenshot:null,messages:[],streaming:!1,streamContent:"",provider:"",model:"",hasApiKey:!1,roots:[],updateAvailable:!1,latestVersion:""},w,f;function V(){if(document.querySelector("openmagic-toolbar"))return;let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",w=e.attachShadow({mode:"closed"});let t=document.createElement("style");t.textContent=N,w.appendChild(t),f=document.createElement("div"),w.appendChild(f),document.body.appendChild(e),K(),B(),be();let n=window.__OPENMAGIC_CONFIG__;n&&S(n.wsPort,n.token).then(()=>{o.connected=!0,h("config.get").then(i=>{o.provider=i.payload?.provider||"",o.model=i.payload?.model||"",o.hasApiKey=i.payload?.hasApiKey||!1,o.roots=i.payload?.roots||[],(!o.provider||!o.hasApiKey)&&(o.panelOpen=!0,o.activePanel="settings"),c()})}).catch(i=>{console.error("[OpenMagic] Connection failed:",i),o.connected=!1,c()}),c()}function c(){if(f.innerHTML="",o.panelOpen&&o.activePanel){let t=document.createElement("div");t.className="om-panel",o.activePanel==="settings"?t.innerHTML=de():o.activePanel==="chat"&&(t.innerHTML=pe()),f.appendChild(t),me(t)}let e=document.createElement("div");if(e.className="om-pill",e.innerHTML=`
663
654
  <span class="om-grab" title="Drag to move">
664
655
  <svg width="8" 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>
665
656
  </span>
@@ -668,27 +659,27 @@
668
659
  <span class="om-pill-text">OpenMagic</span>
669
660
  </span>
670
661
  <span class="om-pill-divider"></span>
671
- <button class="om-pill-btn ${n.selecting?"active":""}" data-action="select" title="Select Element">
662
+ <button class="om-pill-btn ${o.selecting?"active":""}" data-action="select" title="Select Element">
672
663
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 7h10v10"/><path d="M7 17 17 7"/></svg>
673
664
  </button>
674
665
  <button class="om-pill-btn" data-action="screenshot" title="Screenshot">
675
666
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
676
667
  </button>
677
- <button class="om-pill-btn ${n.activePanel==="chat"?"active":""}" data-action="chat" title="Chat with AI">
668
+ <button class="om-pill-btn ${o.activePanel==="chat"?"active":""}" data-action="chat" title="Chat with AI">
678
669
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
679
670
  </button>
680
- <button class="om-pill-btn ${n.activePanel==="settings"?"active":""}" data-action="settings" title="Settings">
671
+ <button class="om-pill-btn ${o.activePanel==="settings"?"active":""}" data-action="settings" title="Settings">
681
672
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/></svg>
682
673
  </button>
683
- `,!n.connected){let o=document.createElement("span");o.style.cssText="width:8px;height:8px;border-radius:50%;background:#e94560;margin-left:4px;",e.appendChild(o)}if(n.updateAvailable){let o=document.createElement("span");o.className="om-update-dot",o.title=`Update available: v${n.latestVersion}`,o.addEventListener("click",t=>{t.stopPropagation(),n.panelOpen=!0,n.activePanel="settings",c()}),e.appendChild(o)}h.appendChild(e),ge(e),e.querySelectorAll(".om-pill-btn").forEach(o=>{o.addEventListener("click",t=>{t.stopPropagation();let i=o.dataset.action;i==="select"?pe():i==="screenshot"?ue():i==="chat"?X("chat"):i==="settings"&&X("settings")})})}function le(){let e=Object.entries(w).map(([l,m])=>`<option value="${l}" ${n.provider===l?"selected":""}>${m.name}</option>`).join(""),o=w[n.provider],t=o?o.models.map(l=>`<option value="${l.id}" ${n.model===l.id?"selected":""}>${l.name}</option>`).join(""):'<option value="">Select a provider first</option>',i=o?.keyPlaceholder||"Enter API key...",r=o?.local||!1,a=n.updateAvailable?`<div class="om-update-banner">
684
- <span>\u{1F680} v${n.latestVersion} available</span>
685
- <span class="om-update-current">current: v${P}</span>
674
+ `,!o.connected){let t=document.createElement("span");t.style.cssText="width:8px;height:8px;border-radius:50%;background:#e94560;margin-left:4px;",e.appendChild(t)}if(o.updateAvailable){let t=document.createElement("span");t.className="om-update-dot",t.title=`Update available: v${o.latestVersion}`,t.addEventListener("click",n=>{n.stopPropagation(),o.panelOpen=!0,o.activePanel="settings",c()}),e.appendChild(t)}f.appendChild(e),fe(e),e.querySelectorAll(".om-pill-btn").forEach(t=>{t.addEventListener("click",n=>{n.stopPropagation();let i=t.dataset.action;i==="select"?ge():i==="screenshot"?he():i==="chat"?Y("chat"):i==="settings"&&Y("settings")})})}function de(){let e=Object.entries(P).map(([u,J])=>`<option value="${u}" ${o.provider===u?"selected":""}>${J.name}</option>`).join(""),t=P[o.provider],n=t?t.models.map(u=>`<option value="${u.id}" ${o.model===u.id?"selected":""}>${u.name}</option>`).join(""):'<option value="">Select a provider first</option>',i=t?.keyPlaceholder||"Enter API key...",r=t?.local||!1,a=o.updateAvailable?`<div class="om-update-banner">
675
+ <span>\u{1F680} v${o.latestVersion} available</span>
676
+ <span class="om-update-current">current: v${$}</span>
686
677
  <code class="om-update-cmd">npx openmagic@latest</code>
687
- </div>`:"",s=n.provider==="openai"||n.provider==="anthropic";return`
678
+ </div>`:"",l={openai:"https://platform.openai.com/api-keys",anthropic:"https://console.anthropic.com/settings/keys",google:"https://aistudio.google.com/apikey",xai:"https://console.x.ai/team/default/api-keys",deepseek:"https://platform.deepseek.com/api_keys",mistral:"https://console.mistral.ai/api-keys",groq:"https://console.groq.com/keys",minimax:"https://platform.minimax.chat/user-center/basic-information/interface-key",moonshot:"https://platform.moonshot.cn/console/api-keys",qwen:"https://dashscope.console.aliyun.com/apiKey",zhipu:"https://open.bigmodel.cn/usercenter/apikeys",doubao:"https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey",openrouter:"https://openrouter.ai/settings/keys"}[o.provider]||"",m=t?.name||"provider";return`
688
679
  <div class="om-panel-header">
689
680
  <svg class="om-header-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/></svg>
690
681
  <span class="om-panel-title">Settings</span>
691
- <span class="om-panel-version">v${P}</span>
682
+ <span class="om-panel-version">v${$}</span>
692
683
  <button class="om-panel-close" data-action="close">&times;</button>
693
684
  </div>
694
685
  <div class="om-panel-body">
@@ -706,40 +697,36 @@
706
697
  <label class="om-label">Model</label>
707
698
  <select class="om-select" data-field="model">
708
699
  <option value="">Select Model...</option>
709
- ${t}
700
+ ${n}
710
701
  </select>
711
702
  </div>
712
703
 
713
704
  <div class="om-field ${r?"om-hidden":""}">
714
- <label class="om-label">Authentication</label>
715
- ${s?`
716
- <div class="om-auth-tabs">
717
- <button class="om-auth-tab active" data-auth="apikey">API Key</button>
718
- <button class="om-auth-tab" data-auth="session">Session Token</button>
719
- </div>
720
- `:""}
721
- <input type="password" class="om-input" data-field="apiKey"
722
- placeholder="${i}"
723
- value="" />
724
- ${s?`
725
- <div class="om-auth-hint om-hidden" data-hint="session">
726
- <p>To use your existing account session:</p>
727
- <ol>
728
- <li>Go to <strong>${n.provider==="openai"?"platform.openai.com":"console.anthropic.com"}</strong></li>
729
- <li>Open DevTools \u2192 Application \u2192 Cookies</li>
730
- <li>Copy the <code>sessionKey</code> value</li>
731
- <li>Paste it above</li>
732
- </ol>
733
- </div>
734
- `:""}
705
+ <label class="om-label">API Key</label>
706
+ <div class="om-key-row">
707
+ <input type="password" class="om-input om-key-input" data-field="apiKey"
708
+ placeholder="${i}"
709
+ value="" />
710
+ ${l?`<button class="om-btn-connect" data-action="get-key" data-url="${l}" title="Get API key from ${m}">
711
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
712
+ Get key
713
+ </button>`:""}
714
+ </div>
715
+ ${o.provider&&!r?`<div class="om-key-hint">Paste your ${m} API key above.${l?` <a data-action="get-key" data-url="${l}">Get one here &rarr;</a>`:""}</div>`:""}
735
716
  </div>
736
717
 
737
- <button class="om-btn" data-action="save-settings">Save Configuration</button>
718
+ <button class="om-btn" data-action="save-settings">
719
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
720
+ Save
721
+ </button>
738
722
 
739
- ${n.hasApiKey?'<div class="om-status om-status-success">Authenticated</div>':""}
723
+ ${o.hasApiKey?`<div class="om-status om-status-success">
724
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
725
+ Connected
726
+ </div>`:""}
740
727
  </div>
741
728
  </div>
742
- `}function ce(){if(!n.hasApiKey||!n.provider)return`
729
+ `}function pe(){if(!o.hasApiKey||!o.provider)return`
743
730
  <div class="om-panel-header">
744
731
  <span class="om-panel-title">Chat</span>
745
732
  <button class="om-panel-close" data-action="close">&times;</button>
@@ -749,26 +736,25 @@
749
736
  Configure your LLM provider in Settings first
750
737
  </div>
751
738
  </div>
752
- `;let e=n.messages.map(i=>`<div class="om-msg om-msg-${i.role}">${H(i.content)}</div>`).join(""),o=n.streaming?`<div class="om-msg om-msg-assistant"><div class="om-loading"><div class="om-spinner"></div> Thinking...</div>${H(n.streamContent)}</div>`:"",t=[];return n.selectedElement&&t.push(`<span class="om-context-chip">\u{1F3AF} ${n.selectedElement.tagName}${n.selectedElement.id?"#"+n.selectedElement.id:""} <button class="om-context-chip-remove" data-action="clear-element">&times;</button></span>`),n.screenshot&&t.push('<span class="om-context-chip">\u{1F4F8} Screenshot <button class="om-context-chip-remove" data-action="clear-screenshot">&times;</button></span>'),`
739
+ `;let e=o.messages.map(i=>`<div class="om-msg om-msg-${i.role}">${H(i.content)}</div>`).join(""),t=o.streaming?`<div class="om-msg om-msg-assistant"><div class="om-loading"><div class="om-spinner"></div> Thinking...</div>${H(o.streamContent)}</div>`:"",n=[];return o.selectedElement&&n.push(`<span class="om-context-chip">\u{1F3AF} ${o.selectedElement.tagName}${o.selectedElement.id?"#"+o.selectedElement.id:""} <button class="om-context-chip-remove" data-action="clear-element">&times;</button></span>`),o.screenshot&&n.push('<span class="om-context-chip">\u{1F4F8} Screenshot <button class="om-context-chip-remove" data-action="clear-screenshot">&times;</button></span>'),`
753
740
  <div class="om-panel-header">
754
- <span class="om-panel-title">Chat \u2014 ${w[n.provider]?.name||n.provider} / ${n.model}</span>
741
+ <span class="om-panel-title">Chat \u2014 ${P[o.provider]?.name||o.provider} / ${o.model}</span>
755
742
  <button class="om-panel-close" data-action="close">&times;</button>
756
743
  </div>
757
744
  <div class="om-panel-body">
758
- ${t.length>0?`<div class="om-context-bar">${t.join("")}</div>`:""}
759
- ${n.selectedElement?`<div class="om-element-info">&lt;${n.selectedElement.tagName}${n.selectedElement.id?' id="'+n.selectedElement.id+'"':""}${n.selectedElement.className?' class="'+n.selectedElement.className.toString().slice(0,60)+'"':""}&gt;</div>`:""}
745
+ ${n.length>0?`<div class="om-context-bar">${n.join("")}</div>`:""}
746
+ ${o.selectedElement?`<div class="om-element-info">&lt;${o.selectedElement.tagName}${o.selectedElement.id?' id="'+o.selectedElement.id+'"':""}${o.selectedElement.className?' class="'+o.selectedElement.className.toString().slice(0,60)+'"':""}&gt;</div>`:""}
760
747
  <div class="om-chat-messages">
761
748
  ${e||'<div style="color:#555;text-align:center;padding:40px 0;font-size:13px;">Select an element or describe what you want to change</div>'}
762
- ${o}
749
+ ${t}
763
750
  </div>
764
751
  <div class="om-chat-input-wrap">
765
752
  <textarea class="om-chat-input" placeholder="Describe the change you want..."
766
- rows="1" ${n.streaming?"disabled":""}></textarea>
767
- <button class="om-chat-send" data-action="send" ${n.streaming?"disabled":""}>
768
- ${n.streaming?"...":"Send"}
753
+ rows="1" ${o.streaming?"disabled":""}></textarea>
754
+ <button class="om-chat-send" data-action="send" ${o.streaming?"disabled":""}>
755
+ ${o.streaming?"...":"Send"}
769
756
  </button>
770
757
  </div>
771
758
  </div>
772
- `}function de(e){e.querySelector('[data-action="close"]')?.addEventListener("click",()=>{n.panelOpen=!1,n.activePanel=null,c()}),e.querySelector('[data-field="provider"]')?.addEventListener("change",t=>{n.provider=t.target.value,n.model="",c()}),e.querySelector('[data-field="model"]')?.addEventListener("change",t=>{n.model=t.target.value}),e.querySelectorAll(".om-auth-tab").forEach(t=>{t.addEventListener("click",()=>{e.querySelectorAll(".om-auth-tab").forEach(s=>s.classList.remove("active")),t.classList.add("active");let i=t.dataset.auth,r=e.querySelector('[data-hint="session"]'),a=e.querySelector('[data-field="apiKey"]');if(i==="session")r?.classList.remove("om-hidden"),a&&(a.placeholder="Paste session token...");else{r?.classList.add("om-hidden");let s=w[n.provider];a&&(a.placeholder=s?.keyPlaceholder||"Enter API key...")}})}),e.querySelector('[data-action="save-settings"]')?.addEventListener("click",()=>{let i=e.querySelector('[data-field="apiKey"]')?.value||"",r={provider:n.provider,model:n.model};i&&(r.apiKey=i),g("config.set",r).then(()=>{n.hasApiKey=!0,c()}).catch(a=>{console.error("[OpenMagic] Failed to save config:",a)})}),e.querySelector('[data-action="send"]')?.addEventListener("click",()=>{V(e)});let o=e.querySelector(".om-chat-input");o?.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),V(e))}),o?.addEventListener("input",()=>{o.style.height="auto",o.style.height=Math.min(o.scrollHeight,120)+"px"}),e.querySelector('[data-action="clear-element"]')?.addEventListener("click",()=>{n.selectedElement=null,c()}),e.querySelector('[data-action="clear-screenshot"]')?.addEventListener("click",()=>{n.screenshot=null,c()})}async function V(e){let o=e.querySelector(".om-chat-input");if(!o)return;let t=o.value.trim();if(!t||n.streaming)return;n.messages.push({role:"user",content:t}),n.streaming=!0,n.streamContent="",c();let i=B(n.selectedElement,n.screenshot);try{let r=await N("llm.chat",{provider:n.provider,model:n.model,messages:n.messages.map(a=>({role:a.role,content:a.content})),context:i},a=>{n.streamContent+=a;let l=y.querySelector(".om-chat-messages")?.querySelector(".om-msg-assistant:last-child");l&&(l.innerHTML=H(n.streamContent))});if(n.messages.push({role:"assistant",content:n.streamContent||r?.content||""}),r?.modifications&&r.modifications.length>0){for(let a of r.modifications)if(a.type==="edit"&&a.file&&a.search&&a.replace)try{let l=(await g("fs.read",{path:U(a.file)})).payload?.content;if(l&&l.includes(a.search)){let m=l.replace(a.search,a.replace);await g("fs.write",{path:U(a.file),content:m}),n.messages.push({role:"system",content:`Applied change to ${a.file}`})}}catch(s){n.messages.push({role:"system",content:`Failed to apply change to ${a.file}: ${s.message}`})}}}catch(r){n.messages.push({role:"system",content:`Error: ${r.message}`})}n.streaming=!1,n.streamContent="",c()}function U(e){return n.roots.length>0?n.roots[0]+"/"+e:e}var f=null,b=null;function pe(){n.selecting?W():me()}function me(){n.selecting=!0,document.body.style.cursor="crosshair",b=e=>{let o=e.target;if(Y(o))return;let t=o.getBoundingClientRect();A({x:t.x,y:t.y,width:t.width,height:t.height})},f=e=>{e.preventDefault(),e.stopPropagation();let o=e.target;Y(o)||(n.selectedElement=O(o),W(),n.activePanel!=="chat"&&(n.panelOpen=!0,n.activePanel="chat"),c())},document.addEventListener("mousemove",b,!0),document.addEventListener("click",f,!0),c()}function W(){n.selecting=!1,document.body.style.cursor="",_(),b&&(document.removeEventListener("mousemove",b,!0),b=null),f&&(document.removeEventListener("click",f,!0),f=null),c()}async function ue(){let e=await R();e&&(n.screenshot=e,n.panelOpen=!0,n.activePanel="chat",c())}function X(e){n.panelOpen&&n.activePanel===e?(n.panelOpen=!1,n.activePanel=null):(n.panelOpen=!0,n.activePanel=e),c()}function ge(e){let o=!1,t=0,i=0,r=0,a=0;e.addEventListener("mousedown",s=>{let l=s.target;if(l.closest(".om-pill-btn")||!l.closest(".om-grab")&&!l.closest(".om-pill-brand"))return;o=!0,t=s.clientX,i=s.clientY;let m=e.getBoundingClientRect();r=m.left,a=m.top,s.preventDefault()}),document.addEventListener("mousemove",s=>{if(!o)return;let l=s.clientX-t,m=s.clientY-i;e.style.position="fixed",e.style.left=r+l+"px",e.style.top=a+m+"px",e.style.right="auto",e.style.bottom="auto"}),document.addEventListener("mouseup",()=>{o=!1})}function Y(e){return!!e.closest("openmagic-toolbar")||!!e.dataset?.openmagic}function H(e){let o=document.createElement("div");return o.textContent=e,o.innerHTML}function he(){fetch("https://registry.npmjs.org/openmagic/latest",{headers:{Accept:"application/json"},signal:AbortSignal.timeout(5e3)}).then(e=>{if(e.ok)return e.json()}).then(e=>{if(!e?.version)return;let o=e.version;fe(o,P)&&(n.updateAvailable=!0,n.latestVersion=o,c())}).catch(()=>{})}function fe(e,o){let t=e.split(".").map(Number),i=o.split(".").map(Number);for(let r=0;r<3;r++){if((t[r]||0)>(i[r]||0))return!0;if((t[r]||0)<(i[r]||0))return!1}return!1}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",F):F());})();
773
- aded",F):F());})();
759
+ `}function me(e){e.querySelector('[data-action="close"]')?.addEventListener("click",()=>{o.panelOpen=!1,o.activePanel=null,c()}),e.querySelector('[data-field="provider"]')?.addEventListener("change",n=>{o.provider=n.target.value,o.model="",c()}),e.querySelector('[data-field="model"]')?.addEventListener("change",n=>{o.model=n.target.value}),e.querySelectorAll('[data-action="get-key"]').forEach(n=>{n.addEventListener("click",i=>{i.preventDefault();let r=n.dataset.url;r&&window.open(r,"_blank","noopener")})}),e.querySelector('[data-action="save-settings"]')?.addEventListener("click",()=>{let i=e.querySelector('[data-field="apiKey"]')?.value||"",r={provider:o.provider,model:o.model};i&&(r.apiKey=i),h("config.set",r).then(()=>{o.hasApiKey=!0,c()}).catch(a=>{console.error("[OpenMagic] Failed to save config:",a)})}),e.querySelector('[data-action="send"]')?.addEventListener("click",()=>{U(e)});let t=e.querySelector(".om-chat-input");t?.addEventListener("keydown",n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),U(e))}),t?.addEventListener("input",()=>{t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px"}),e.querySelector('[data-action="clear-element"]')?.addEventListener("click",()=>{o.selectedElement=null,c()}),e.querySelector('[data-action="clear-screenshot"]')?.addEventListener("click",()=>{o.screenshot=null,c()})}async function U(e){let t=e.querySelector(".om-chat-input");if(!t)return;let n=t.value.trim();if(!n||o.streaming)return;o.messages.push({role:"user",content:n}),o.streaming=!0,o.streamContent="",c();let i=F(o.selectedElement,o.screenshot);try{let r=await O("llm.chat",{provider:o.provider,model:o.model,messages:o.messages.map(a=>({role:a.role,content:a.content})),context:i},a=>{o.streamContent+=a;let l=w.querySelector(".om-chat-messages")?.querySelector(".om-msg-assistant:last-child");l&&(l.innerHTML=H(o.streamContent))});if(o.messages.push({role:"assistant",content:o.streamContent||r?.content||""}),r?.modifications&&r.modifications.length>0){for(let a of r.modifications)if(a.type==="edit"&&a.file&&a.search&&a.replace)try{let l=(await h("fs.read",{path:X(a.file)})).payload?.content;if(l&&l.includes(a.search)){let m=l.replace(a.search,a.replace);await h("fs.write",{path:X(a.file),content:m}),o.messages.push({role:"system",content:`Applied change to ${a.file}`})}}catch(s){o.messages.push({role:"system",content:`Failed to apply change to ${a.file}: ${s.message}`})}}}catch(r){o.messages.push({role:"system",content:`Error: ${r.message}`})}o.streaming=!1,o.streamContent="",c()}function X(e){return o.roots.length>0?o.roots[0]+"/"+e:e}var b=null,x=null;function ge(){o.selecting?Q():ue()}function ue(){o.selecting=!0,document.body.style.cursor="crosshair",x=e=>{let t=e.target;if(W(t))return;let n=t.getBoundingClientRect();A({x:n.x,y:n.y,width:n.width,height:n.height})},b=e=>{e.preventDefault(),e.stopPropagation();let t=e.target;W(t)||(o.selectedElement=_(t),Q(),o.activePanel!=="chat"&&(o.panelOpen=!0,o.activePanel="chat"),c())},document.addEventListener("mousemove",x,!0),document.addEventListener("click",b,!0),c()}function Q(){o.selecting=!1,document.body.style.cursor="",R(),x&&(document.removeEventListener("mousemove",x,!0),x=null),b&&(document.removeEventListener("click",b,!0),b=null),c()}async function he(){let e=await q();e&&(o.screenshot=e,o.panelOpen=!0,o.activePanel="chat",c())}function Y(e){o.panelOpen&&o.activePanel===e?(o.panelOpen=!1,o.activePanel=null):(o.panelOpen=!0,o.activePanel=e),c()}function fe(e){let t=!1,n=0,i=0,r=0,a=0;e.addEventListener("mousedown",s=>{let l=s.target;if(l.closest(".om-pill-btn")||!l.closest(".om-grab")&&!l.closest(".om-pill-brand"))return;t=!0,n=s.clientX,i=s.clientY;let m=e.getBoundingClientRect();r=m.left,a=m.top,s.preventDefault()}),document.addEventListener("mousemove",s=>{if(!t)return;let l=s.clientX-n,m=s.clientY-i;e.style.position="fixed",e.style.left=r+l+"px",e.style.top=a+m+"px",e.style.right="auto",e.style.bottom="auto"}),document.addEventListener("mouseup",()=>{t=!1})}function W(e){return!!e.closest("openmagic-toolbar")||!!e.dataset?.openmagic}function H(e){let t=document.createElement("div");return t.textContent=e,t.innerHTML}function be(){fetch("https://registry.npmjs.org/openmagic/latest",{headers:{Accept:"application/json"},signal:AbortSignal.timeout(5e3)}).then(e=>{if(e.ok)return e.json()}).then(e=>{if(!e?.version)return;let t=e.version;xe(t,$)&&(o.updateAvailable=!0,o.latestVersion=t,c())}).catch(()=>{})}function xe(e,t){let n=e.split(".").map(Number),i=t.split(".").map(Number);for(let r=0;r<3;r++){if((n[r]||0)>(i[r]||0))return!0;if((n[r]||0)<(i[r]||0))return!1}return!1}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",V):V());})();
774
760
  //# sourceMappingURL=index.global.js.map