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.
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +81 -95
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
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
|
-
/*
|
|
578
|
-
.om-
|
|
578
|
+
/* API Key row with connect button */
|
|
579
|
+
.om-key-row {
|
|
579
580
|
display: flex;
|
|
580
|
-
gap:
|
|
581
|
-
|
|
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-
|
|
585
|
+
.om-key-input {
|
|
588
586
|
flex: 1;
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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-
|
|
601
|
-
|
|
602
|
-
|
|
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-
|
|
626
|
-
|
|
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-
|
|
630
|
-
|
|
620
|
+
.om-key-hint a {
|
|
621
|
+
color: #a29bfe;
|
|
622
|
+
cursor: pointer;
|
|
623
|
+
text-decoration: none;
|
|
631
624
|
}
|
|
632
625
|
|
|
633
|
-
.om-
|
|
634
|
-
|
|
635
|
-
|
|
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-
|
|
642
|
-
|
|
631
|
+
.om-status svg {
|
|
632
|
+
vertical-align: -2px;
|
|
633
|
+
margin-right: 4px;
|
|
643
634
|
}
|
|
644
|
-
`;var
|
|
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
|
|
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
|
|
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
|
-
${
|
|
650
|
+
${n.outerHTML}
|
|
660
651
|
</div>
|
|
661
652
|
</foreignObject>
|
|
662
|
-
</svg>`;
|
|
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 ${
|
|
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 ${
|
|
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 ${
|
|
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
|
-
`,!
|
|
684
|
-
<span>\u{1F680} v${
|
|
685
|
-
<span class="om-update-current">current: v${
|
|
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>`:"",
|
|
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${
|
|
682
|
+
<span class="om-panel-version">v${$}</span>
|
|
692
683
|
<button class="om-panel-close" data-action="close">×</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
|
-
${
|
|
700
|
+
${n}
|
|
710
701
|
</select>
|
|
711
702
|
</div>
|
|
712
703
|
|
|
713
704
|
<div class="om-field ${r?"om-hidden":""}">
|
|
714
|
-
<label class="om-label">
|
|
715
|
-
|
|
716
|
-
<
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
${
|
|
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 →</a>`:""}</div>`:""}
|
|
735
716
|
</div>
|
|
736
717
|
|
|
737
|
-
<button class="om-btn" data-action="save-settings">
|
|
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
|
-
${
|
|
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
|
|
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">×</button>
|
|
@@ -749,26 +736,25 @@
|
|
|
749
736
|
Configure your LLM provider in Settings first
|
|
750
737
|
</div>
|
|
751
738
|
</div>
|
|
752
|
-
`;let e=
|
|
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">×</button></span>`),o.screenshot&&n.push('<span class="om-context-chip">\u{1F4F8} Screenshot <button class="om-context-chip-remove" data-action="clear-screenshot">×</button></span>'),`
|
|
753
740
|
<div class="om-panel-header">
|
|
754
|
-
<span class="om-panel-title">Chat \u2014 ${
|
|
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">×</button>
|
|
756
743
|
</div>
|
|
757
744
|
<div class="om-panel-body">
|
|
758
|
-
${
|
|
759
|
-
${
|
|
745
|
+
${n.length>0?`<div class="om-context-bar">${n.join("")}</div>`:""}
|
|
746
|
+
${o.selectedElement?`<div class="om-element-info"><${o.selectedElement.tagName}${o.selectedElement.id?' id="'+o.selectedElement.id+'"':""}${o.selectedElement.className?' class="'+o.selectedElement.className.toString().slice(0,60)+'"':""}></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
|
-
${
|
|
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" ${
|
|
767
|
-
<button class="om-chat-send" data-action="send" ${
|
|
768
|
-
${
|
|
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
|
|
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
|