openmagic 0.1.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.
@@ -0,0 +1,584 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var OpenMagicToolbar=(()=>{var P=`
3
+ :host {
4
+ all: initial;
5
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
6
+ font-size: 14px;
7
+ color: #e0e0e0;
8
+ line-height: 1.5;
9
+ }
10
+
11
+ * {
12
+ box-sizing: border-box;
13
+ margin: 0;
14
+ padding: 0;
15
+ }
16
+
17
+ /* Floating Pill */
18
+ .om-pill {
19
+ position: fixed;
20
+ bottom: 24px;
21
+ right: 24px;
22
+ z-index: 2147483647;
23
+ display: flex;
24
+ align-items: center;
25
+ gap: 4px;
26
+ padding: 8px 16px;
27
+ background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
28
+ border: 1px solid rgba(108, 92, 231, 0.3);
29
+ border-radius: 50px;
30
+ cursor: grab;
31
+ user-select: none;
32
+ box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(108, 92, 231, 0.1);
33
+ transition: box-shadow 0.2s, transform 0.2s;
34
+ }
35
+
36
+ .om-pill:hover {
37
+ box-shadow: 0 6px 32px rgba(108, 92, 231, 0.3), 0 0 0 1px rgba(108, 92, 231, 0.3);
38
+ transform: translateY(-1px);
39
+ }
40
+
41
+ .om-pill:active {
42
+ cursor: grabbing;
43
+ }
44
+
45
+ .om-pill-logo {
46
+ font-size: 18px;
47
+ line-height: 1;
48
+ }
49
+
50
+ .om-pill-text {
51
+ font-size: 12px;
52
+ font-weight: 600;
53
+ color: #a29bfe;
54
+ letter-spacing: 0.5px;
55
+ }
56
+
57
+ .om-pill-btn {
58
+ background: none;
59
+ border: none;
60
+ color: #e0e0e0;
61
+ cursor: pointer;
62
+ padding: 4px 8px;
63
+ border-radius: 6px;
64
+ font-size: 16px;
65
+ line-height: 1;
66
+ transition: background 0.15s;
67
+ display: flex;
68
+ align-items: center;
69
+ justify-content: center;
70
+ }
71
+
72
+ .om-pill-btn:hover {
73
+ background: rgba(108, 92, 231, 0.2);
74
+ }
75
+
76
+ .om-pill-btn.active {
77
+ background: rgba(108, 92, 231, 0.3);
78
+ color: #a29bfe;
79
+ }
80
+
81
+ .om-pill-divider {
82
+ width: 1px;
83
+ height: 20px;
84
+ background: rgba(255, 255, 255, 0.1);
85
+ margin: 0 4px;
86
+ }
87
+
88
+ /* Panel */
89
+ .om-panel {
90
+ position: fixed;
91
+ bottom: 80px;
92
+ right: 24px;
93
+ z-index: 2147483647;
94
+ width: 420px;
95
+ max-height: 600px;
96
+ background: #1a1a2e;
97
+ border: 1px solid rgba(108, 92, 231, 0.2);
98
+ border-radius: 16px;
99
+ box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5);
100
+ display: flex;
101
+ flex-direction: column;
102
+ overflow: hidden;
103
+ animation: om-slide-up 0.2s ease;
104
+ }
105
+
106
+ @keyframes om-slide-up {
107
+ from { opacity: 0; transform: translateY(8px); }
108
+ to { opacity: 1; transform: translateY(0); }
109
+ }
110
+
111
+ .om-panel-header {
112
+ display: flex;
113
+ align-items: center;
114
+ justify-content: space-between;
115
+ padding: 12px 16px;
116
+ border-bottom: 1px solid rgba(255, 255, 255, 0.05);
117
+ background: rgba(108, 92, 231, 0.05);
118
+ }
119
+
120
+ .om-panel-title {
121
+ font-size: 13px;
122
+ font-weight: 600;
123
+ color: #a29bfe;
124
+ }
125
+
126
+ .om-panel-close {
127
+ background: none;
128
+ border: none;
129
+ color: #666;
130
+ cursor: pointer;
131
+ font-size: 18px;
132
+ padding: 2px 6px;
133
+ border-radius: 4px;
134
+ line-height: 1;
135
+ }
136
+
137
+ .om-panel-close:hover {
138
+ color: #e0e0e0;
139
+ background: rgba(255, 255, 255, 0.05);
140
+ }
141
+
142
+ .om-panel-body {
143
+ flex: 1;
144
+ overflow-y: auto;
145
+ padding: 16px;
146
+ }
147
+
148
+ .om-panel-body::-webkit-scrollbar {
149
+ width: 6px;
150
+ }
151
+
152
+ .om-panel-body::-webkit-scrollbar-track {
153
+ background: transparent;
154
+ }
155
+
156
+ .om-panel-body::-webkit-scrollbar-thumb {
157
+ background: rgba(255, 255, 255, 0.1);
158
+ border-radius: 3px;
159
+ }
160
+
161
+ /* Chat */
162
+ .om-chat-messages {
163
+ display: flex;
164
+ flex-direction: column;
165
+ gap: 12px;
166
+ min-height: 200px;
167
+ max-height: 380px;
168
+ overflow-y: auto;
169
+ padding-bottom: 8px;
170
+ }
171
+
172
+ .om-chat-messages::-webkit-scrollbar {
173
+ width: 4px;
174
+ }
175
+
176
+ .om-chat-messages::-webkit-scrollbar-thumb {
177
+ background: rgba(255, 255, 255, 0.1);
178
+ border-radius: 2px;
179
+ }
180
+
181
+ .om-msg {
182
+ padding: 10px 14px;
183
+ border-radius: 12px;
184
+ font-size: 13px;
185
+ line-height: 1.5;
186
+ white-space: pre-wrap;
187
+ word-break: break-word;
188
+ }
189
+
190
+ .om-msg-user {
191
+ background: rgba(108, 92, 231, 0.15);
192
+ color: #e0e0e0;
193
+ margin-left: 32px;
194
+ border-bottom-right-radius: 4px;
195
+ }
196
+
197
+ .om-msg-assistant {
198
+ background: rgba(255, 255, 255, 0.03);
199
+ color: #ccc;
200
+ margin-right: 32px;
201
+ border-bottom-left-radius: 4px;
202
+ border: 1px solid rgba(255, 255, 255, 0.05);
203
+ }
204
+
205
+ .om-msg-system {
206
+ background: rgba(233, 69, 96, 0.1);
207
+ color: #e94560;
208
+ font-size: 12px;
209
+ text-align: center;
210
+ padding: 8px;
211
+ }
212
+
213
+ .om-chat-input-wrap {
214
+ display: flex;
215
+ gap: 8px;
216
+ margin-top: 12px;
217
+ }
218
+
219
+ .om-chat-input {
220
+ flex: 1;
221
+ background: rgba(255, 255, 255, 0.05);
222
+ border: 1px solid rgba(255, 255, 255, 0.1);
223
+ border-radius: 10px;
224
+ padding: 10px 14px;
225
+ color: #e0e0e0;
226
+ font-size: 13px;
227
+ font-family: inherit;
228
+ outline: none;
229
+ resize: none;
230
+ min-height: 40px;
231
+ max-height: 120px;
232
+ }
233
+
234
+ .om-chat-input:focus {
235
+ border-color: rgba(108, 92, 231, 0.5);
236
+ }
237
+
238
+ .om-chat-input::placeholder {
239
+ color: #555;
240
+ }
241
+
242
+ .om-chat-send {
243
+ background: #6c5ce7;
244
+ border: none;
245
+ color: white;
246
+ cursor: pointer;
247
+ padding: 10px 16px;
248
+ border-radius: 10px;
249
+ font-size: 13px;
250
+ font-weight: 600;
251
+ transition: background 0.15s;
252
+ white-space: nowrap;
253
+ }
254
+
255
+ .om-chat-send:hover {
256
+ background: #7c6cf7;
257
+ }
258
+
259
+ .om-chat-send:disabled {
260
+ background: #333;
261
+ color: #666;
262
+ cursor: not-allowed;
263
+ }
264
+
265
+ /* Settings */
266
+ .om-settings {
267
+ display: flex;
268
+ flex-direction: column;
269
+ gap: 16px;
270
+ }
271
+
272
+ .om-field {
273
+ display: flex;
274
+ flex-direction: column;
275
+ gap: 6px;
276
+ }
277
+
278
+ .om-label {
279
+ font-size: 11px;
280
+ font-weight: 600;
281
+ text-transform: uppercase;
282
+ letter-spacing: 0.5px;
283
+ color: #888;
284
+ }
285
+
286
+ .om-select, .om-input {
287
+ background: rgba(255, 255, 255, 0.05);
288
+ border: 1px solid rgba(255, 255, 255, 0.1);
289
+ border-radius: 8px;
290
+ padding: 10px 12px;
291
+ color: #e0e0e0;
292
+ font-size: 13px;
293
+ font-family: inherit;
294
+ outline: none;
295
+ width: 100%;
296
+ }
297
+
298
+ .om-select:focus, .om-input:focus {
299
+ border-color: rgba(108, 92, 231, 0.5);
300
+ }
301
+
302
+ .om-select option {
303
+ background: #1a1a2e;
304
+ color: #e0e0e0;
305
+ }
306
+
307
+ .om-btn {
308
+ background: #6c5ce7;
309
+ border: none;
310
+ color: white;
311
+ cursor: pointer;
312
+ padding: 10px 16px;
313
+ border-radius: 8px;
314
+ font-size: 13px;
315
+ font-weight: 600;
316
+ transition: background 0.15s;
317
+ }
318
+
319
+ .om-btn:hover {
320
+ background: #7c6cf7;
321
+ }
322
+
323
+ .om-btn-secondary {
324
+ background: rgba(255, 255, 255, 0.05);
325
+ color: #e0e0e0;
326
+ border: 1px solid rgba(255, 255, 255, 0.1);
327
+ }
328
+
329
+ .om-btn-secondary:hover {
330
+ background: rgba(255, 255, 255, 0.1);
331
+ }
332
+
333
+ .om-status {
334
+ font-size: 12px;
335
+ padding: 6px 10px;
336
+ border-radius: 6px;
337
+ text-align: center;
338
+ }
339
+
340
+ .om-status-success {
341
+ background: rgba(0, 184, 148, 0.1);
342
+ color: #00b894;
343
+ }
344
+
345
+ .om-status-error {
346
+ background: rgba(233, 69, 96, 0.1);
347
+ color: #e94560;
348
+ }
349
+
350
+ /* Context bar */
351
+ .om-context-bar {
352
+ display: flex;
353
+ gap: 6px;
354
+ flex-wrap: wrap;
355
+ margin-bottom: 8px;
356
+ }
357
+
358
+ .om-context-chip {
359
+ display: flex;
360
+ align-items: center;
361
+ gap: 4px;
362
+ padding: 4px 10px;
363
+ background: rgba(108, 92, 231, 0.1);
364
+ border: 1px solid rgba(108, 92, 231, 0.2);
365
+ border-radius: 20px;
366
+ font-size: 11px;
367
+ color: #a29bfe;
368
+ }
369
+
370
+ .om-context-chip-remove {
371
+ background: none;
372
+ border: none;
373
+ color: #a29bfe;
374
+ cursor: pointer;
375
+ font-size: 14px;
376
+ padding: 0 2px;
377
+ line-height: 1;
378
+ }
379
+
380
+ /* Diff */
381
+ .om-diff {
382
+ font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
383
+ font-size: 12px;
384
+ border-radius: 8px;
385
+ overflow: hidden;
386
+ border: 1px solid rgba(255, 255, 255, 0.05);
387
+ margin: 8px 0;
388
+ }
389
+
390
+ .om-diff-header {
391
+ padding: 8px 12px;
392
+ background: rgba(255, 255, 255, 0.03);
393
+ border-bottom: 1px solid rgba(255, 255, 255, 0.05);
394
+ color: #888;
395
+ font-size: 11px;
396
+ }
397
+
398
+ .om-diff-line {
399
+ padding: 2px 12px;
400
+ white-space: pre;
401
+ overflow-x: auto;
402
+ }
403
+
404
+ .om-diff-add {
405
+ background: rgba(0, 184, 148, 0.1);
406
+ color: #55efc4;
407
+ }
408
+
409
+ .om-diff-remove {
410
+ background: rgba(233, 69, 96, 0.1);
411
+ color: #fab1a0;
412
+ }
413
+
414
+ .om-diff-actions {
415
+ display: flex;
416
+ gap: 8px;
417
+ padding: 8px 12px;
418
+ border-top: 1px solid rgba(255, 255, 255, 0.05);
419
+ background: rgba(255, 255, 255, 0.02);
420
+ }
421
+
422
+ /* Element info */
423
+ .om-element-info {
424
+ background: rgba(255, 255, 255, 0.03);
425
+ border: 1px solid rgba(255, 255, 255, 0.05);
426
+ border-radius: 8px;
427
+ padding: 10px 12px;
428
+ font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
429
+ font-size: 11px;
430
+ color: #888;
431
+ margin: 8px 0;
432
+ max-height: 100px;
433
+ overflow-y: auto;
434
+ }
435
+
436
+ .om-hidden {
437
+ display: none !important;
438
+ }
439
+
440
+ /* Loading */
441
+ .om-loading {
442
+ display: flex;
443
+ align-items: center;
444
+ gap: 8px;
445
+ padding: 8px 12px;
446
+ color: #888;
447
+ font-size: 12px;
448
+ }
449
+
450
+ .om-spinner {
451
+ width: 16px;
452
+ height: 16px;
453
+ border: 2px solid rgba(108, 92, 231, 0.2);
454
+ border-top-color: #6c5ce7;
455
+ border-radius: 50%;
456
+ animation: om-spin 0.6s linear infinite;
457
+ }
458
+
459
+ @keyframes om-spin {
460
+ to { transform: rotate(360deg); }
461
+ }
462
+
463
+ /* Tooltip */
464
+ .om-tooltip {
465
+ position: absolute;
466
+ bottom: 100%;
467
+ left: 50%;
468
+ transform: translateX(-50%);
469
+ background: #1a1a2e;
470
+ color: #e0e0e0;
471
+ padding: 4px 8px;
472
+ border-radius: 4px;
473
+ font-size: 11px;
474
+ white-space: nowrap;
475
+ pointer-events: none;
476
+ opacity: 0;
477
+ transition: opacity 0.15s;
478
+ margin-bottom: 4px;
479
+ }
480
+
481
+ .om-pill-btn:hover .om-tooltip {
482
+ opacity: 1;
483
+ }
484
+ `;var m=null,p=new Map,V=[],E=[],k=!1,w=null;function L(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function S(e,n){return new Promise((t,i)=>{try{m=new WebSocket(`ws://127.0.0.1:${e}/__openmagic__/ws`),m.onopen=()=>{let r=L();M({id:r,type:"handshake",payload:{token:n}}),p.set(r,a=>{if(a.type==="handshake.ok"){k=!0;for(let s of E)m?.send(s);E=[],t()}else a.type==="error"&&i(new Error(a.payload?.message||"Handshake failed"))})},m.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 V)s(a)}catch{}},m.onclose=()=>{k=!1,w||(w=setTimeout(()=>{w=null,S(e,n).catch(()=>{})},2e3))},m.onerror=()=>{}}catch(r){i(r)}})}function M(e){let n=JSON.stringify(e);m&&k?m.send(n):E.push(n)}function g(e,n){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)}),M({id:r,type:e,payload:n})})}function $(e,n,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")))}),M({id:a,type:e,payload:n})})}var Q=["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 N(e){let n=window.getComputedStyle(e),t={};for(let r of Q)t[r]=n.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:Z(e),cssSelector:ee(e),xpath:te(e),computedStyles:t,rect:{x:i.x,y:i.y,width:i.width,height:i.height}}}function Z(e){let n=e.cloneNode(!0);n.querySelectorAll("script, style, svg").forEach(r=>r.remove());let i=n.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(`
485
+ `);i=`<${r} ${a}>
486
+ ${s}
487
+ ${e.children.length>5?`<!-- +${e.children.length-5} more children -->`:""}
488
+ </${r}>`}return i}function ee(e){if(e.id)return`#${e.id}`;let n=[],t=e;for(;t&&t!==document.body;){let i=t.tagName.toLowerCase();if(t.id){n.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})`}}n.unshift(i),t=t.parentElement}return n.join(" > ")}function te(e){let n=[],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;n.unshift(`${i.tagName.toLowerCase()}[${r}]`)}t=t.parentNode}return"/"+n.join("/")}var d=null;function O(e){d||(d=document.createElement("div"),d.style.cssText=`
489
+ position: fixed;
490
+ pointer-events: none;
491
+ z-index: 2147483646;
492
+ border: 2px solid #6c5ce7;
493
+ background: rgba(108, 92, 231, 0.1);
494
+ transition: all 0.1s ease;
495
+ `,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 oe(e):await ne()}catch(n){return console.warn("[OpenMagic] Screenshot capture failed:",n),null}}async function ne(){let e=document.createElement("canvas"),n=window.devicePixelRatio||1;e.width=window.innerWidth*n,e.height=window.innerHeight*n;let t=e.getContext("2d");t.scale(n,n);try{let i=await A(document.body),r=await z(i,window.innerWidth,window.innerHeight);return t.drawImage(r,0,0),e.toDataURL("image/png")}catch{return null}}async function oe(e){let n=e.getBoundingClientRect(),t=document.createElement("canvas"),i=window.devicePixelRatio||1;t.width=n.width*i,t.height=n.height*i;let r=t.getContext("2d");r.scale(i,i);try{let a=await A(e),s=await z(a,n.width,n.height);return r.drawImage(s,0,0),t.toDataURL("image/png")}catch{return null}}function A(e){return new Promise(n=>{let t=e.cloneNode(!0);q(e,t);let i=e.getBoundingClientRect(),r=i.width,a=i.height,s=`
496
+ <svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${a}">
497
+ <foreignObject width="100%" height="100%">
498
+ <div xmlns="http://www.w3.org/1999/xhtml" style="width:${r}px;height:${a}px;overflow:hidden;">
499
+ ${t.outerHTML}
500
+ </div>
501
+ </foreignObject>
502
+ </svg>`;n(s)})}function q(e,n){let t=window.getComputedStyle(e),i="";for(let s=0;s<t.length;s++){let l=t[s];i+=`${l}:${t.getPropertyValue(l)};`}n.style.cssText=i;let r=e.children,a=n.children;for(let s=0;s<r.length&&s<a.length;s++)q(r[s],a[s])}function z(e,n,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=n,a.height=t,a.src=l})}var b=[];var D=!1;function G(){if(D)return;D=!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,C(a),s}catch(s){throw a.status=0,a.duration=Date.now()-a.timestamp,C(a),s}};let n=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(),n.apply(this,[i,r,...a])},XMLHttpRequest.prototype.send=function(...i){return this.addEventListener("loadend",()=>{C({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 C(e){e.url.includes("__openmagic__")||(b.push(e),b.length>50&&b.shift())}function ae(){return[...b]}var x=[],ie=100,I=!1;function j(){if(I)return;I=!0;let e=["log","warn","error","info","debug"];for(let n of e){let t=console[n];console[n]=function(...i){x.push({level:n,args:i.map(r=>{try{return typeof r=="object"?JSON.stringify(r).slice(0,500):String(r)}catch{return String(r)}}),timestamp:Date.now()}),x.length>ie&&x.shift(),t.apply(console,i)}}}function re(){return[...x]}function K(e,n){return{selectedElement:e?{tagName:e.tagName,id:e.id,className:e.className,textContent:e.textContent,outerHTML:e.outerHTML,cssSelector:e.cssSelector,computedStyles:e.computedStyles}:void 0,screenshot:n||void 0,networkLogs:ae().map(t=>({method:t.method,url:t.url,status:t.status,duration:t.duration,timestamp:t.timestamp})),consoleLogs:re().map(t=>({level:t.level,args:t.args,timestamp:t.timestamp}))}}var T={openai:{name:"OpenAI",models:[{id:"gpt-4.1",name:"GPT-4.1"},{id:"gpt-4.1-mini",name:"GPT-4.1 Mini"},{id:"gpt-4.1-nano",name:"GPT-4.1 Nano"},{id:"gpt-4o",name:"GPT-4o"},{id:"gpt-4o-mini",name:"GPT-4o Mini"},{id:"o3",name:"o3 (Reasoning)"},{id:"o4-mini",name:"o4-mini (Reasoning)"}],keyPlaceholder:"sk-..."},anthropic:{name:"Anthropic",models:[{id:"claude-opus-4-20250514",name:"Claude Opus 4"},{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4"},{id:"claude-haiku-4-20250514",name:"Claude Haiku 4"}],keyPlaceholder:"sk-ant-..."},google:{name:"Google Gemini",models:[{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash"},{id:"gemini-2.0-flash",name:"Gemini 2.0 Flash"}],keyPlaceholder:"AIza..."},deepseek:{name:"DeepSeek",models:[{id:"deepseek-chat",name:"DeepSeek V3"},{id:"deepseek-reasoner",name:"DeepSeek R1"}],keyPlaceholder:"sk-..."},groq:{name:"Groq",models:[{id:"llama-3.3-70b-versatile",name:"Llama 3.3 70B"},{id:"llama-3.1-8b-instant",name:"Llama 3.1 8B"}],keyPlaceholder:"gsk_..."},mistral:{name:"Mistral",models:[{id:"mistral-large-latest",name:"Mistral Large"},{id:"codestral-latest",name:"Codestral"}],keyPlaceholder:"..."},xai:{name:"xAI (Grok)",models:[{id:"grok-3",name:"Grok 3"},{id:"grok-3-mini",name:"Grok 3 Mini"}],keyPlaceholder:"xai-..."},ollama:{name:"Ollama (Local)",models:[],keyPlaceholder:"not required",local:!0},openrouter:{name:"OpenRouter",models:[],keyPlaceholder:"sk-or-..."}},o={connected:!1,panelOpen:!1,activePanel:null,selecting:!1,selectedElement:null,screenshot:null,messages:[],streaming:!1,streamContent:"",provider:"",model:"",hasApiKey:!1,roots:[]},y,u;function F(){if(document.querySelector("openmagic-toolbar"))return;let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",y=e.attachShadow({mode:"closed"});let n=document.createElement("style");n.textContent=P,y.appendChild(n),u=document.createElement("div"),y.appendChild(u),document.body.appendChild(e),G(),j();let t=window.__OPENMAGIC_CONFIG__;t&&S(t.wsPort,t.token).then(()=>{o.connected=!0,g("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(u.innerHTML="",o.panelOpen&&o.activePanel){let n=document.createElement("div");n.className="om-panel",o.activePanel==="settings"?n.innerHTML=se():o.activePanel==="chat"&&(n.innerHTML=le()),u.appendChild(n),ce(n)}let e=document.createElement("div");if(e.className="om-pill",e.innerHTML=`
503
+ <span class="om-pill-logo">\u2728</span>
504
+ <span class="om-pill-text">Magic</span>
505
+ <span class="om-pill-divider"></span>
506
+ <button class="om-pill-btn ${o.selecting?"active":""}" data-action="select" title="Select Element">
507
+ \u{1F3AF}
508
+ </button>
509
+ <button class="om-pill-btn" data-action="screenshot" title="Screenshot">
510
+ \u{1F4F8}
511
+ </button>
512
+ <button class="om-pill-btn ${o.activePanel==="chat"?"active":""}" data-action="chat" title="Chat">
513
+ \u{1F4AC}
514
+ </button>
515
+ <button class="om-pill-btn ${o.activePanel==="settings"?"active":""}" data-action="settings" title="Settings">
516
+ \u2699\uFE0F
517
+ </button>
518
+ `,!o.connected){let n=document.createElement("span");n.style.cssText="width:8px;height:8px;border-radius:50%;background:#e94560;margin-left:4px;",e.appendChild(n)}u.appendChild(e),ge(e),e.querySelectorAll(".om-pill-btn").forEach(n=>{n.addEventListener("click",t=>{t.stopPropagation();let i=n.dataset.action;i==="select"?de():i==="screenshot"?me():i==="chat"?U("chat"):i==="settings"&&U("settings")})})}function se(){let e=Object.entries(T).map(([a,s])=>`<option value="${a}" ${o.provider===a?"selected":""}>${s.name}</option>`).join(""),n=T[o.provider],t=n?n.models.map(a=>`<option value="${a.id}" ${o.model===a.id?"selected":""}>${a.name}</option>`).join(""):'<option value="">Select a provider first</option>',i=n?.keyPlaceholder||"Enter API key...",r=n?.local||!1;return`
519
+ <div class="om-panel-header">
520
+ <span class="om-panel-title">Settings</span>
521
+ <button class="om-panel-close" data-action="close">&times;</button>
522
+ </div>
523
+ <div class="om-panel-body">
524
+ <div class="om-settings">
525
+ <div class="om-field">
526
+ <label class="om-label">Provider</label>
527
+ <select class="om-select" data-field="provider">
528
+ <option value="">Select Provider...</option>
529
+ ${e}
530
+ </select>
531
+ </div>
532
+
533
+ <div class="om-field">
534
+ <label class="om-label">Model</label>
535
+ <select class="om-select" data-field="model">
536
+ <option value="">Select Model...</option>
537
+ ${t}
538
+ </select>
539
+ </div>
540
+
541
+ <div class="om-field ${r?"om-hidden":""}">
542
+ <label class="om-label">API Key</label>
543
+ <input type="password" class="om-input" data-field="apiKey"
544
+ placeholder="${i}"
545
+ value="" />
546
+ </div>
547
+
548
+ <button class="om-btn" data-action="save-settings">Save Configuration</button>
549
+
550
+ ${o.hasApiKey?'<div class="om-status om-status-success">API key configured</div>':""}
551
+ </div>
552
+ </div>
553
+ `}function le(){if(!o.hasApiKey||!o.provider)return`
554
+ <div class="om-panel-header">
555
+ <span class="om-panel-title">Chat</span>
556
+ <button class="om-panel-close" data-action="close">&times;</button>
557
+ </div>
558
+ <div class="om-panel-body">
559
+ <div class="om-status om-status-error">
560
+ Configure your LLM provider in Settings first
561
+ </div>
562
+ </div>
563
+ `;let e=o.messages.map(i=>`<div class="om-msg om-msg-${i.role}">${H(i.content)}</div>`).join(""),n=o.streaming?`<div class="om-msg om-msg-assistant"><div class="om-loading"><div class="om-spinner"></div> Thinking...</div>${H(o.streamContent)}</div>`:"",t=[];return o.selectedElement&&t.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&&t.push('<span class="om-context-chip">\u{1F4F8} Screenshot <button class="om-context-chip-remove" data-action="clear-screenshot">&times;</button></span>'),`
564
+ <div class="om-panel-header">
565
+ <span class="om-panel-title">Chat \u2014 ${T[o.provider]?.name||o.provider} / ${o.model}</span>
566
+ <button class="om-panel-close" data-action="close">&times;</button>
567
+ </div>
568
+ <div class="om-panel-body">
569
+ ${t.length>0?`<div class="om-context-bar">${t.join("")}</div>`:""}
570
+ ${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>`:""}
571
+ <div class="om-chat-messages">
572
+ ${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>'}
573
+ ${n}
574
+ </div>
575
+ <div class="om-chat-input-wrap">
576
+ <textarea class="om-chat-input" placeholder="Describe the change you want..."
577
+ rows="1" ${o.streaming?"disabled":""}></textarea>
578
+ <button class="om-chat-send" data-action="send" ${o.streaming?"disabled":""}>
579
+ ${o.streaming?"...":"Send"}
580
+ </button>
581
+ </div>
582
+ </div>
583
+ `}function ce(e){e.querySelector('[data-action="close"]')?.addEventListener("click",()=>{o.panelOpen=!1,o.activePanel=null,c()}),e.querySelector('[data-field="provider"]')?.addEventListener("change",t=>{o.provider=t.target.value,o.model="",c()}),e.querySelector('[data-field="model"]')?.addEventListener("change",t=>{o.model=t.target.value}),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),g("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",()=>{X(e)});let n=e.querySelector(".om-chat-input");n?.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),X(e))}),n?.addEventListener("input",()=>{n.style.height="auto",n.style.height=Math.min(n.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 X(e){let n=e.querySelector(".om-chat-input");if(!n)return;let t=n.value.trim();if(!t||o.streaming)return;o.messages.push({role:"user",content:t}),o.streaming=!0,o.streamContent="",c();let i=K(o.selectedElement,o.screenshot);try{let r=await $("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=y.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 g("fs.read",{path:B(a.file)})).payload?.content;if(l&&l.includes(a.search)){let v=l.replace(a.search,a.replace);await g("fs.write",{path:B(a.file),content:v}),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 B(e){return o.roots.length>0?o.roots[0]+"/"+e:e}var h=null,f=null;function de(){o.selecting?W():pe()}function pe(){o.selecting=!0,document.body.style.cursor="crosshair",f=e=>{let n=e.target;if(Y(n))return;let t=n.getBoundingClientRect();O({x:t.x,y:t.y,width:t.width,height:t.height})},h=e=>{e.preventDefault(),e.stopPropagation();let n=e.target;Y(n)||(o.selectedElement=N(n),W(),o.activePanel!=="chat"&&(o.panelOpen=!0,o.activePanel="chat"),c())},document.addEventListener("mousemove",f,!0),document.addEventListener("click",h,!0),c()}function W(){o.selecting=!1,document.body.style.cursor="",_(),f&&(document.removeEventListener("mousemove",f,!0),f=null),h&&(document.removeEventListener("click",h,!0),h=null),c()}async function me(){let e=await R();e&&(o.screenshot=e,o.panelOpen=!0,o.activePanel="chat",c())}function U(e){o.panelOpen&&o.activePanel===e?(o.panelOpen=!1,o.activePanel=null):(o.panelOpen=!0,o.activePanel=e),c()}function ge(e){let n=!1,t=0,i=0,r=0,a=0;e.addEventListener("mousedown",s=>{if(s.target.closest(".om-pill-btn"))return;n=!0,t=s.clientX,i=s.clientY;let l=e.getBoundingClientRect();r=l.left,a=l.top,s.preventDefault()}),document.addEventListener("mousemove",s=>{if(!n)return;let l=s.clientX-t,v=s.clientY-i;e.style.position="fixed",e.style.left=r+l+"px",e.style.top=a+v+"px",e.style.right="auto",e.style.bottom="auto"}),document.addEventListener("mouseup",()=>{n=!1})}function Y(e){return!!e.closest("openmagic-toolbar")||!!e.dataset?.openmagic}function H(e){let n=document.createElement("div");return n.textContent=e,n.innerHTML}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",F):F());})();
584
+ //# sourceMappingURL=index.global.js.map