openmagic 0.5.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 +97 -4
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +156 -45
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var OpenMagicToolbar=(()=>{var
|
|
2
|
+
"use strict";var OpenMagicToolbar=(()=>{var N=`
|
|
3
3
|
:host {
|
|
4
4
|
all: initial;
|
|
5
5
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
@@ -22,51 +22,79 @@
|
|
|
22
22
|
z-index: 2147483647;
|
|
23
23
|
display: flex;
|
|
24
24
|
align-items: center;
|
|
25
|
-
gap:
|
|
26
|
-
padding:
|
|
27
|
-
background: linear-gradient(135deg, #
|
|
28
|
-
border: 1px solid rgba(108, 92, 231, 0.
|
|
29
|
-
border-radius:
|
|
30
|
-
cursor: grab;
|
|
25
|
+
gap: 2px;
|
|
26
|
+
padding: 6px 12px 6px 6px;
|
|
27
|
+
background: linear-gradient(135deg, #13132b 0%, #1a1a3e 100%);
|
|
28
|
+
border: 1px solid rgba(108, 92, 231, 0.25);
|
|
29
|
+
border-radius: 12px;
|
|
31
30
|
user-select: none;
|
|
32
|
-
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.
|
|
33
|
-
transition: box-shadow 0.2s, transform 0.
|
|
31
|
+
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(108, 92, 231, 0.08);
|
|
32
|
+
transition: box-shadow 0.2s, transform 0.15s;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
.om-pill:hover {
|
|
37
|
-
box-shadow: 0 6px 32px rgba(108, 92, 231, 0.
|
|
36
|
+
box-shadow: 0 6px 32px rgba(108, 92, 231, 0.25), 0 0 0 1px rgba(108, 92, 231, 0.3);
|
|
38
37
|
transform: translateY(-1px);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
/* Six-dot grab handle */
|
|
41
|
+
.om-grab {
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
width: 20px;
|
|
46
|
+
height: 28px;
|
|
47
|
+
color: #444;
|
|
48
|
+
cursor: grab;
|
|
49
|
+
border-radius: 6px;
|
|
50
|
+
transition: color 0.15s, background 0.15s;
|
|
51
|
+
flex-shrink: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.om-grab:hover {
|
|
55
|
+
color: #888;
|
|
56
|
+
background: rgba(255, 255, 255, 0.05);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.om-grab:active {
|
|
42
60
|
cursor: grabbing;
|
|
61
|
+
color: #a29bfe;
|
|
43
62
|
}
|
|
44
63
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
64
|
+
/* Brand */
|
|
65
|
+
.om-pill-brand {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
gap: 6px;
|
|
69
|
+
padding: 0 6px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.om-pill-icon {
|
|
73
|
+
color: #a29bfe;
|
|
74
|
+
flex-shrink: 0;
|
|
48
75
|
}
|
|
49
76
|
|
|
50
77
|
.om-pill-text {
|
|
51
78
|
font-size: 12px;
|
|
52
|
-
font-weight:
|
|
53
|
-
color: #
|
|
54
|
-
letter-spacing: 0.
|
|
79
|
+
font-weight: 700;
|
|
80
|
+
color: #c4b5fd;
|
|
81
|
+
letter-spacing: 0.3px;
|
|
82
|
+
white-space: nowrap;
|
|
55
83
|
}
|
|
56
84
|
|
|
57
85
|
.om-pill-btn {
|
|
58
86
|
background: none;
|
|
59
87
|
border: none;
|
|
60
|
-
color: #
|
|
88
|
+
color: #888;
|
|
61
89
|
cursor: pointer;
|
|
62
|
-
padding:
|
|
63
|
-
border-radius:
|
|
64
|
-
font-size: 16px;
|
|
90
|
+
padding: 6px;
|
|
91
|
+
border-radius: 8px;
|
|
65
92
|
line-height: 1;
|
|
66
|
-
transition: background 0.15s;
|
|
93
|
+
transition: background 0.15s, color 0.15s;
|
|
67
94
|
display: flex;
|
|
68
95
|
align-items: center;
|
|
69
96
|
justify-content: center;
|
|
97
|
+
position: relative;
|
|
70
98
|
}
|
|
71
99
|
|
|
72
100
|
.om-pill-btn:hover {
|
|
@@ -540,48 +568,118 @@
|
|
|
540
568
|
margin-left: auto;
|
|
541
569
|
margin-right: 8px;
|
|
542
570
|
}
|
|
543
|
-
|
|
571
|
+
|
|
572
|
+
.om-header-icon {
|
|
573
|
+
color: #a29bfe;
|
|
574
|
+
margin-right: 6px;
|
|
575
|
+
flex-shrink: 0;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/* API Key row with connect button */
|
|
579
|
+
.om-key-row {
|
|
580
|
+
display: flex;
|
|
581
|
+
gap: 8px;
|
|
582
|
+
align-items: stretch;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
.om-key-input {
|
|
586
|
+
flex: 1;
|
|
587
|
+
min-width: 0;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
.om-btn-connect {
|
|
591
|
+
display: flex;
|
|
592
|
+
align-items: center;
|
|
593
|
+
gap: 5px;
|
|
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;
|
|
599
|
+
font-size: 12px;
|
|
600
|
+
font-weight: 600;
|
|
601
|
+
font-family: inherit;
|
|
602
|
+
cursor: pointer;
|
|
603
|
+
white-space: nowrap;
|
|
604
|
+
transition: all 0.15s;
|
|
605
|
+
}
|
|
606
|
+
|
|
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;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
.om-key-hint {
|
|
614
|
+
font-size: 11px;
|
|
615
|
+
color: #666;
|
|
616
|
+
margin-top: 6px;
|
|
617
|
+
line-height: 1.5;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
.om-key-hint a {
|
|
621
|
+
color: #a29bfe;
|
|
622
|
+
cursor: pointer;
|
|
623
|
+
text-decoration: none;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
.om-key-hint a:hover {
|
|
627
|
+
text-decoration: underline;
|
|
628
|
+
color: #c4b5fd;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
.om-status svg {
|
|
632
|
+
vertical-align: -2px;
|
|
633
|
+
margin-right: 4px;
|
|
634
|
+
}
|
|
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(`
|
|
544
636
|
`);i=`<${r} ${a}>
|
|
545
637
|
${s}
|
|
546
638
|
${e.children.length>5?`<!-- +${e.children.length-5} more children -->`:""}
|
|
547
|
-
</${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=`
|
|
548
640
|
position: fixed;
|
|
549
641
|
pointer-events: none;
|
|
550
642
|
z-index: 2147483646;
|
|
551
643
|
border: 2px solid #6c5ce7;
|
|
552
644
|
background: rgba(108, 92, 231, 0.1);
|
|
553
645
|
transition: all 0.1s ease;
|
|
554
|
-
`,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
|
|
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=`
|
|
555
647
|
<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${a}">
|
|
556
648
|
<foreignObject width="100%" height="100%">
|
|
557
649
|
<div xmlns="http://www.w3.org/1999/xhtml" style="width:${r}px;height:${a}px;overflow:hidden;">
|
|
558
650
|
${n.outerHTML}
|
|
559
651
|
</div>
|
|
560
652
|
</foreignObject>
|
|
561
|
-
</svg>`;t(s)})}function
|
|
562
|
-
<span class="om-
|
|
563
|
-
|
|
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=`
|
|
654
|
+
<span class="om-grab" title="Drag to move">
|
|
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>
|
|
656
|
+
</span>
|
|
657
|
+
<span class="om-pill-brand">
|
|
658
|
+
<svg class="om-pill-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
|
|
659
|
+
<span class="om-pill-text">OpenMagic</span>
|
|
660
|
+
</span>
|
|
564
661
|
<span class="om-pill-divider"></span>
|
|
565
662
|
<button class="om-pill-btn ${o.selecting?"active":""}" data-action="select" title="Select Element">
|
|
566
|
-
|
|
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>
|
|
567
664
|
</button>
|
|
568
665
|
<button class="om-pill-btn" data-action="screenshot" title="Screenshot">
|
|
569
|
-
|
|
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>
|
|
570
667
|
</button>
|
|
571
|
-
<button class="om-pill-btn ${o.activePanel==="chat"?"active":""}" data-action="chat" title="Chat">
|
|
572
|
-
|
|
668
|
+
<button class="om-pill-btn ${o.activePanel==="chat"?"active":""}" data-action="chat" title="Chat with AI">
|
|
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>
|
|
573
670
|
</button>
|
|
574
671
|
<button class="om-pill-btn ${o.activePanel==="settings"?"active":""}" data-action="settings" title="Settings">
|
|
575
|
-
|
|
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>
|
|
576
673
|
</button>
|
|
577
|
-
`,!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)}
|
|
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">
|
|
578
675
|
<span>\u{1F680} v${o.latestVersion} available</span>
|
|
579
|
-
<span class="om-update-current">current: v${
|
|
676
|
+
<span class="om-update-current">current: v${$}</span>
|
|
580
677
|
<code class="om-update-cmd">npx openmagic@latest</code>
|
|
581
|
-
</div>`:"";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`
|
|
582
679
|
<div class="om-panel-header">
|
|
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>
|
|
583
681
|
<span class="om-panel-title">Settings</span>
|
|
584
|
-
<span class="om-panel-version">v${
|
|
682
|
+
<span class="om-panel-version">v${$}</span>
|
|
585
683
|
<button class="om-panel-close" data-action="close">×</button>
|
|
586
684
|
</div>
|
|
587
685
|
<div class="om-panel-body">
|
|
@@ -605,17 +703,30 @@
|
|
|
605
703
|
|
|
606
704
|
<div class="om-field ${r?"om-hidden":""}">
|
|
607
705
|
<label class="om-label">API Key</label>
|
|
608
|
-
<
|
|
609
|
-
|
|
610
|
-
|
|
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>`:""}
|
|
611
716
|
</div>
|
|
612
717
|
|
|
613
|
-
<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>
|
|
614
722
|
|
|
615
|
-
${o.hasApiKey
|
|
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>`:""}
|
|
616
727
|
</div>
|
|
617
728
|
</div>
|
|
618
|
-
`}function
|
|
729
|
+
`}function pe(){if(!o.hasApiKey||!o.provider)return`
|
|
619
730
|
<div class="om-panel-header">
|
|
620
731
|
<span class="om-panel-title">Chat</span>
|
|
621
732
|
<button class="om-panel-close" data-action="close">×</button>
|
|
@@ -627,7 +738,7 @@
|
|
|
627
738
|
</div>
|
|
628
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>'),`
|
|
629
740
|
<div class="om-panel-header">
|
|
630
|
-
<span class="om-panel-title">Chat \u2014 ${
|
|
741
|
+
<span class="om-panel-title">Chat \u2014 ${P[o.provider]?.name||o.provider} / ${o.model}</span>
|
|
631
742
|
<button class="om-panel-close" data-action="close">×</button>
|
|
632
743
|
</div>
|
|
633
744
|
<div class="om-panel-body">
|
|
@@ -645,5 +756,5 @@
|
|
|
645
756
|
</button>
|
|
646
757
|
</div>
|
|
647
758
|
</div>
|
|
648
|
-
`}function
|
|
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());})();
|
|
649
760
|
//# sourceMappingURL=index.global.js.map
|