openmagic 0.28.5 → 0.28.6
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 +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +17 -17
- 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 $e=`
|
|
3
3
|
:host {
|
|
4
4
|
all: initial;
|
|
5
5
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
@@ -361,7 +361,7 @@
|
|
|
361
361
|
.om-msg:hover .om-copy-btn { opacity: 1; }
|
|
362
362
|
.om-copy-btn:hover { color: #ccc; background: rgba(0,0,0,0.5); }
|
|
363
363
|
.om-msg { position: relative; }
|
|
364
|
-
`;var C=null
|
|
364
|
+
`;var C=null,$=new Map,G=[],pe=[],B=!1,Le=!1,ce=null,de=0;function me(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function ue(e,o){return Le=!0,new Promise((s,n)=>{let a=!1,i=setTimeout(()=>{a||(a=!0,n(new Error("Handshake timeout")),C?.close())},1e4);try{let r=window.location.hostname||"127.0.0.1",p=window.location.protocol==="https:"?"wss:":"ws:";C=new WebSocket(`${p}//${r}:${e}/__openmagic__/ws`),C.onopen=()=>{let l=me();C.send(JSON.stringify({id:l,type:"handshake",payload:{token:o}})),$.set(l,d=>{if(d.type==="handshake.ok"){clearTimeout(i),B=!0,de=0;for(let c of pe)C?.send(c);pe=[],a||(a=!0,s())}else d.type==="error"&&(clearTimeout(i),a||(a=!0,n(new Error(d.payload?.message||"Handshake failed"))))})},C.onmessage=l=>{try{let d=JSON.parse(l.data);d.id&&$.has(d.id)&&($.get(d.id)(d),(d.type==="llm.done"||d.type==="llm.error"||!d.type.startsWith("llm."))&&$.delete(d.id));for(let c of G)c(d)}catch{}},C.onclose=()=>{let l=B;if(B=!1,$.forEach((d,c)=>{d({type:"error",id:c,payload:{message:"Connection lost"}})}),$.clear(),!l&&!a){clearTimeout(i),a=!0,n(new Error("WebSocket closed before handshake"));return}if(l&&Le&&!ce){let d=Math.min(2e3*Math.pow(1.5,de),3e4);de++,ce=setTimeout(()=>{ce=null,ue(e,o).then(()=>{for(let c of G)c({type:"reconnected",payload:{}})}).catch(()=>{})},d)}},C.onerror=()=>{!B&&!a&&(clearTimeout(i),a=!0,n(new Error("WebSocket connection failed")))}}catch(r){clearTimeout(i),a||(a=!0,n(r))}})}function Me(e){let o=JSON.stringify(e);C&&C.readyState===WebSocket.OPEN&&B?C.send(o):pe.push(o)}function v(e,o){return new Promise((s,n)=>{let a=me(),i=setTimeout(()=>{$.delete(a),n(new Error("Request timeout"))},3e4);$.set(a,r=>{clearTimeout(i),r.type==="error"?n(new Error(r.payload?.message||"Unknown error")):s(r)}),Me({id:a,type:e,payload:o})})}function Te(e,o,s){return new Promise((n,a)=>{let i=me(),r=setTimeout(()=>{$.delete(i),a(new Error("Stream timeout"))},12e4);$.set(i,p=>{p.type==="llm.chunk"?s(p.payload?.delta||""):p.type==="llm.done"?(clearTimeout(r),$.delete(i),n(p.payload)):(p.type==="llm.error"||p.type==="error")&&(clearTimeout(r),$.delete(i),a(new Error(p.payload?.message||"Stream error")))}),Me({id:i,type:e,payload:o})})}function Ce(e){return G.push(e),()=>{G=G.filter(o=>o!==e)}}function He(){return B}var Pe=["display","position","width","height","margin","padding","color","background-color","background","font-size","font-weight","font-family","border","border-radius","box-shadow","flex-direction","justify-content","align-items","gap","grid-template-columns","grid-template-rows","overflow","opacity","z-index","text-align","line-height","letter-spacing"];function _e(e){let o=window.getComputedStyle(e),s={};for(let c of Pe)s[c]=o.getPropertyValue(c);let n=e.getBoundingClientRect(),a={};if(e.parentElement&&e.parentElement!==document.body){let c=window.getComputedStyle(e.parentElement);for(let u of Pe)a[u]=c.getPropertyValue(u)}let i=[];if(e.parentElement){let c=Array.from(e.parentElement.children),u=c.indexOf(e),m=Math.max(0,u-3),h=Math.min(c.length,u+4);m>0&&i.push(`... ${m} elements before ...`);for(let x=m;x<h;x++){let A=c[x],b=A.tagName.toLowerCase(),O=(A.className||"").toString().slice(0,60);A===e?i.push(`[SELECTED] <${b} class="${O}">`):i.push(`<${b} class="${O}">`)}h<c.length&&i.push(`... ${c.length-h} elements after ...`)}let r=tt(e),p={};for(let c of Array.from(e.attributes))(c.name.startsWith("aria-")||c.name==="role"||c.name==="tabindex")&&(p[c.name]=c.value);let l=[];for(let c of Array.from(e.attributes))c.name.startsWith("on")&&l.push(c.name);let d=nt(e);return{tagName:e.tagName.toLowerCase(),id:e.id||"",className:e.className||"",textContent:(e.textContent||"").trim().slice(0,200),outerHTML:Ze(e),cssSelector:Qe(e),xpath:et(e),computedStyles:s,ancestry:Je(e),componentHint:Ye(e),rect:{x:n.x,y:n.y,width:n.width,height:n.height},parentStyles:a,siblings:i,matchedCssRules:r,viewport:{width:window.innerWidth,height:window.innerHeight},ariaAttributes:p,eventHandlers:l,reactProps:d}}function Je(e,o=5){let s=[],n=e.parentElement;for(;n&&n!==document.body&&s.length<o;){let a=n.tagName.toLowerCase(),i=(typeof n.className=="string"?n.className:"").split(/\s+/).filter(r=>r.length>1&&!r.startsWith("_")).slice(0,3).join(".");s.push(i?`${a}.${i}`:a),n=n.parentElement}return s}function Ye(e){let o=e;for(;o&&o!==document.body;){let s=o.getAttribute("data-component")||o.getAttribute("data-testid")||o.getAttribute("data-cy");if(s)return s;let n=Object.keys(o);for(let a of n)if(a.startsWith("__reactFiber")||a.startsWith("__reactInternalInstance"))try{let i=o[a],r=i?.type?.name||i?.type?.displayName||i?.return?.type?.name||i?.return?.type?.displayName;if(r&&r!=="div"&&r!=="span"&&r.length>1)return r}catch{}o=o.parentElement}return""}function Ze(e){let o=e.cloneNode(!0);o.querySelectorAll("script, style, svg").forEach(a=>a.remove());let n=o.outerHTML;if(n.length>2e3){let a=e.tagName.toLowerCase(),i=Array.from(e.attributes).map(p=>`${p.name}="${p.value}"`).join(" "),r=Array.from(e.children).slice(0,5).map(p=>`<${p.tagName.toLowerCase()} .../>`).join(`
|
|
365
365
|
`);n=`<${a} ${i}>
|
|
366
366
|
${r}
|
|
367
367
|
${e.children.length>5?`<!-- +${e.children.length-5} more children -->`:""}
|
|
@@ -379,7 +379,7 @@
|
|
|
379
379
|
${a.outerHTML}
|
|
380
380
|
</div>
|
|
381
381
|
</foreignObject>
|
|
382
|
-
</svg>`,r=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),p=URL.createObjectURL(r);return new Promise(l=>{let d=new Image,c=document.createElement("canvas"),u=Math.min(window.devicePixelRatio||1,2);c.width=s*u,c.height=n*u,d.onload=()=>{URL.revokeObjectURL(p);let m=c.getContext("2d");if(!m){l(null);return}m.scale(u,u),m.drawImage(d,0,0);try{l(c.toDataURL("image/png",.8))}catch{l(null)}},d.onerror=()=>{URL.revokeObjectURL(p),l(null)},setTimeout(()=>{URL.revokeObjectURL(p),l(null)},5e3),d.src=p})}async function st(e){let o=e||document.documentElement,s=o.getBoundingClientRect(),n=document.createElement("canvas");n.width=400,n.height=300;let a=n.getContext("2d");return a?(a.fillStyle="#1a1a2e",a.fillRect(0,0,400,300),a.fillStyle="#e0e0e0",a.font="14px system-ui",a.fillText(`Element: <${o.tagName.toLowerCase()}>`,20,30),a.fillStyle="#888",a.font="12px system-ui",a.fillText(`Size: ${Math.round(s.width)}x${Math.round(s.height)}`,20,55),a.fillText(`Classes: ${(o.className||"").toString().slice(0,40)}`,20,75),a.fillText(`Page: ${window.location.pathname}`,20,95),a.fillStyle="#6c5ce7",a.font="11px system-ui",a.fillText("(Full screenshot unavailable \u2014 context sent as metadata)",20,130),n.toDataURL("image/png")):null}function Oe(e,o,s){if(o>s)return null;try{let n=e.cloneNode(!1);if(n.tagName==="SCRIPT"||n.tagName==="STYLE"||n.tagName==="SVG"||n.tagName==="CANVAS"||n.tagName==="VIDEO"||n.tagName==="IFRAME")return null;let a=window.getComputedStyle(e),i=["display","position","width","height","margin","padding","color","background-color","background","font-size","font-weight","font-family","border","border-radius","flex-direction","justify-content","align-items","gap","grid-template-columns","text-align","overflow"],r="";for(let p of i){let l=a.getPropertyValue(p);l&&l!=="normal"&&l!=="none"&&l!=="auto"&&l!=="0px"&&(r+=`${p}:${l};`)}n.setAttribute("style",r);for(let p=0;p<e.children.length&&p<20;p++){let l=Oe(e.children[p],o+1,s);l&&n.appendChild(l)}return n}catch{return null}}var Q=[];var ze=!1;function De(){if(ze)return;ze=!0;let e=window.fetch;window.fetch=async function(...n){let a=new Request(...n),i={method:a.method,url:a.url,timestamp:Date.now()};try{let r=await e.apply(this,n);return i.status=r.status,i.duration=Date.now()-i.timestamp,ge(i),r}catch(r){throw i.status=0,i.duration=Date.now()-i.timestamp,ge(i),r}};let o=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(n,a,...i){return this.__om_method=n,this.__om_url=a,this.__om_start=Date.now(),o.apply(this,[n,a,...i])},XMLHttpRequest.prototype.send=function(...n){return this.addEventListener("loadend",()=>{ge({method:this.__om_method||"GET",url:this.__om_url||"",status:this.status,duration:Date.now()-(this.__om_start||Date.now()),timestamp:this.__om_start||Date.now()})}),s.apply(this,n)}}function ge(e){e.url.includes("__openmagic__")||(Q.push(e),Q.length>50&&Q.shift())}function he(){return[...Q]}var ee=[],at=100,qe=!1;function Ie(){if(qe)return;qe=!0;let e=["log","warn","error","info","debug"];for(let o of e){let s=console[o];console[o]=function(...n){ee.push({level:o,args:n.map(a=>{try{return typeof a=="object"?JSON.stringify(a).slice(0,500):String(a)}catch{return String(a)}}),timestamp:Date.now()}),ee.length>at&&ee.shift(),s.apply(console,n)}}}function fe(){return[...ee]}function Be(e,o){return{selectedElement:e?{tagName:e.tagName,id:e.id,className:e.className,textContent:e.textContent,outerHTML:e.outerHTML,cssSelector:e.cssSelector,computedStyles:e.computedStyles}:void 0,screenshot:o||void 0,networkLogs:he().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:fe().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var f={sparkle:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.582a.5.5 0 0 1 0 .962L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/></svg>',crosshair:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="22" y1="12" x2="18" y2="12"/><line x1="6" y1="12" x2="2" y2="12"/><line x1="12" y1="6" x2="12" y2="2"/><line x1="12" y1="22" x2="12" y2="18"/></svg>',camera:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg>',chat:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',settings:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>',send:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>',x:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',externalLink:'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',check:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>',copy:'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>',grip:'<svg width="7" height="14" viewBox="0 0 8 14" fill="currentColor"><circle cx="2" cy="2" r="1.2"/><circle cx="6" cy="2" r="1.2"/><circle cx="2" cy="7" r="1.2"/><circle cx="6" cy="7" r="1.2"/><circle cx="2" cy="12" r="1.2"/><circle cx="6" cy="12" r="1.2"/></svg>',network:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',activity:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>',paperclip:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>',image:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',trash:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',minus:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>'},F={openai:{name:"OpenAI",keyUrl:"https://platform.openai.com/api-keys",keyPlaceholder:"sk-...",models:[{id:"gpt-5.4",name:"GPT-5.4"},{id:"gpt-5.4-mini",name:"GPT-5.4 Mini"},{id:"gpt-5.2",name:"GPT-5.2 Thinking"},{id:"o3",name:"o3"},{id:"o4-mini",name:"o4-mini"},{id:"gpt-4.1",name:"GPT-4.1"},{id:"gpt-4.1-mini",name:"GPT-4.1 Mini"}]},anthropic:{name:"Anthropic",keyUrl:"https://console.anthropic.com/settings/keys",keyPlaceholder:"sk-ant-...",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6"},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6"},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5"}]},google:{name:"Google Gemini",keyUrl:"https://aistudio.google.com/apikey",keyPlaceholder:"AIza...",models:[{id:"gemini-3.1-pro-preview",name:"Gemini 3.1 Pro"},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash"},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash"}]},xai:{name:"xAI (Grok)",keyUrl:"https://console.x.ai/team/default/api-keys",keyPlaceholder:"xai-...",models:[{id:"grok-4.20-0309-reasoning",name:"Grok 4.20 Reasoning"},{id:"grok-4-1-fast-non-reasoning",name:"Grok 4.1 Fast"}]},deepseek:{name:"DeepSeek",keyUrl:"https://platform.deepseek.com/api_keys",keyPlaceholder:"sk-...",models:[{id:"deepseek-chat",name:"DeepSeek V3.2"},{id:"deepseek-reasoner",name:"DeepSeek R1"}]},mistral:{name:"Mistral",keyUrl:"https://console.mistral.ai/api-keys",keyPlaceholder:"...",models:[{id:"mistral-large-3-25-12",name:"Mistral Large 3"},{id:"codestral-2508",name:"Codestral"},{id:"devstral-2-25-12",name:"Devstral 2"}]},groq:{name:"Groq",keyUrl:"https://console.groq.com/keys",keyPlaceholder:"gsk_...",models:[{id:"meta-llama/llama-4-scout-17b-16e-instruct",name:"Llama 4 Scout"},{id:"llama-3.3-70b-versatile",name:"Llama 3.3 70B"}]},minimax:{name:"MiniMax",keyUrl:"https://platform.minimax.chat/user-center/basic-information/interface-key",keyPlaceholder:"MiniMax key...",models:[{id:"MiniMax-M2.7",name:"MiniMax M2.7"},{id:"MiniMax-M2.5",name:"MiniMax M2.5"}]},moonshot:{name:"Kimi (Moonshot)",keyUrl:"https://platform.moonshot.cn/console/api-keys",keyPlaceholder:"Moonshot key...",models:[{id:"kimi-k2.5",name:"Kimi K2.5"},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking"}]},qwen:{name:"Qwen (Alibaba)",keyUrl:"https://dashscope.console.aliyun.com/apiKey",keyPlaceholder:"DashScope key...",models:[{id:"qwen3.5-plus",name:"Qwen 3.5 Plus"},{id:"qwen-max",name:"Qwen Max"}]},zhipu:{name:"Zhipu AI (GLM)",keyUrl:"https://open.bigmodel.cn/usercenter/apikeys",keyPlaceholder:"Zhipu key...",models:[{id:"glm-5",name:"GLM-5"},{id:"glm-4.7",name:"GLM-4.7"}]},doubao:{name:"Doubao (ByteDance)",keyUrl:"https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey",keyPlaceholder:"Volcano key...",models:[{id:"doubao-seed-2-0-pro",name:"Doubao Seed 2.0 Pro"},{id:"doubao-seed-2-0-code",name:"Doubao Seed 2.0 Code"}]},ollama:{name:"Ollama (Local)",keyPlaceholder:"not required",local:!0,models:[]},openrouter:{name:"OpenRouter",keyUrl:"https://openrouter.ai/settings/keys",keyPlaceholder:"sk-or-...",models:[]}};function ne(e){let o=new TextEncoder().encode(e),s="";for(let n=0;n<o.length;n+=32768)s+=String.fromCharCode(...o.subarray(n,n+32768));return btoa(s)}function xe(e){let o=atob(e),s=new Uint8Array(o.length);for(let n=0;n<o.length;n++)s[n]=o.charCodeAt(n);return new TextDecoder().decode(s)}var Fe="0.28.5",t={connected:!1,panelOpen:!1,activePanel:"",selecting:!1,selectedElement:null,screenshot:null,messages:[],streaming:!1,streamContent:"",provider:"",model:"",hasApiKey:!1,configuredProviders:{},roots:[],updateAvailable:!1,latestVersion:"",saveStatus:"",networkCapture:!1,attachments:[],groundedFiles:[],minimized:!1},k,w,q,Ue,Se,N;function rt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:t.messages,provider:t.provider,model:t.model,panelOpen:t.panelOpen,activePanel:t.activePanel}))}catch{}}function it(){try{let e=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");e.messages?.length&&(t.messages=e.messages),e.provider&&(t.provider=e.provider),e.model&&(t.model=e.model),e.panelOpen&&(t.panelOpen=e.panelOpen,t.activePanel=e.activePanel||"")}catch{}}function je(){if(document.querySelector("openmagic-toolbar"))return;it();let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",k=e.attachShadow({mode:"closed"});let o=document.createElement("style");o.textContent=Ee,k.appendChild(o);let s=document.createElement("div");k.appendChild(s),s.innerHTML=lt(),w=s.querySelector(".om-toolbar"),q=s.querySelector(".om-prompt-input"),Ue=s.querySelector(".om-prompt-context"),Se=s.querySelector(".om-panel"),N=s.querySelector(".om-panel-body"),document.body.appendChild(e),ct(s),kt();try{let r=JSON.parse(localStorage.getItem("__om_pos__")||"");r?.left&&r?.top&&(w.style.left=r.left,w.style.top=r.top,w.style.right="auto",w.style.bottom="auto")}catch{}De(),Ie(),$t();let a=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,i=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);a&&ue(i,a).then(()=>(t.connected=!0,ve(),v("config.get"))).then(r=>{let p=r.payload?.provider||"",l=r.payload?.model||"";t.provider=t.provider||p,t.model=t.model||l,t.configuredProviders=r.payload?.apiKeys||{},t.hasApiKey=t.configuredProviders[t.provider]||!1,t.roots=r.payload?.roots||[],t.panelOpen&&t.activePanel?R(t.activePanel):(!t.provider||!t.hasApiKey&&!Object.values(t.configuredProviders).some(Boolean))&&R("settings"),J()}).catch(()=>{t.connected=!1,ve()})}function lt(){return`
|
|
382
|
+
</svg>`,r=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),p=URL.createObjectURL(r);return new Promise(l=>{let d=new Image,c=document.createElement("canvas"),u=Math.min(window.devicePixelRatio||1,2);c.width=s*u,c.height=n*u,d.onload=()=>{URL.revokeObjectURL(p);let m=c.getContext("2d");if(!m){l(null);return}m.scale(u,u),m.drawImage(d,0,0);try{l(c.toDataURL("image/png",.8))}catch{l(null)}},d.onerror=()=>{URL.revokeObjectURL(p),l(null)},setTimeout(()=>{URL.revokeObjectURL(p),l(null)},5e3),d.src=p})}async function st(e){let o=e||document.documentElement,s=o.getBoundingClientRect(),n=document.createElement("canvas");n.width=400,n.height=300;let a=n.getContext("2d");return a?(a.fillStyle="#1a1a2e",a.fillRect(0,0,400,300),a.fillStyle="#e0e0e0",a.font="14px system-ui",a.fillText(`Element: <${o.tagName.toLowerCase()}>`,20,30),a.fillStyle="#888",a.font="12px system-ui",a.fillText(`Size: ${Math.round(s.width)}x${Math.round(s.height)}`,20,55),a.fillText(`Classes: ${(o.className||"").toString().slice(0,40)}`,20,75),a.fillText(`Page: ${window.location.pathname}`,20,95),a.fillStyle="#6c5ce7",a.font="11px system-ui",a.fillText("(Full screenshot unavailable \u2014 context sent as metadata)",20,130),n.toDataURL("image/png")):null}function Oe(e,o,s){if(o>s)return null;try{let n=e.cloneNode(!1);if(n.tagName==="SCRIPT"||n.tagName==="STYLE"||n.tagName==="SVG"||n.tagName==="CANVAS"||n.tagName==="VIDEO"||n.tagName==="IFRAME")return null;let a=window.getComputedStyle(e),i=["display","position","width","height","margin","padding","color","background-color","background","font-size","font-weight","font-family","border","border-radius","flex-direction","justify-content","align-items","gap","grid-template-columns","text-align","overflow"],r="";for(let p of i){let l=a.getPropertyValue(p);l&&l!=="normal"&&l!=="none"&&l!=="auto"&&l!=="0px"&&(r+=`${p}:${l};`)}n.setAttribute("style",r);for(let p=0;p<e.children.length&&p<20;p++){let l=Oe(e.children[p],o+1,s);l&&n.appendChild(l)}return n}catch{return null}}var Q=[];var ze=!1;function De(){if(ze)return;ze=!0;let e=window.fetch;window.fetch=async function(...n){let a=new Request(...n),i={method:a.method,url:a.url,timestamp:Date.now()};try{let r=await e.apply(this,n);return i.status=r.status,i.duration=Date.now()-i.timestamp,ge(i),r}catch(r){throw i.status=0,i.duration=Date.now()-i.timestamp,ge(i),r}};let o=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(n,a,...i){return this.__om_method=n,this.__om_url=a,this.__om_start=Date.now(),o.apply(this,[n,a,...i])},XMLHttpRequest.prototype.send=function(...n){return this.addEventListener("loadend",()=>{ge({method:this.__om_method||"GET",url:this.__om_url||"",status:this.status,duration:Date.now()-(this.__om_start||Date.now()),timestamp:this.__om_start||Date.now()})}),s.apply(this,n)}}function ge(e){e.url.includes("__openmagic__")||(Q.push(e),Q.length>50&&Q.shift())}function he(){return[...Q]}var ee=[],at=100,qe=!1;function Ie(){if(qe)return;qe=!0;let e=["log","warn","error","info","debug"];for(let o of e){let s=console[o];console[o]=function(...n){ee.push({level:o,args:n.map(a=>{try{return typeof a=="object"?JSON.stringify(a).slice(0,500):String(a)}catch{return String(a)}}),timestamp:Date.now()}),ee.length>at&&ee.shift(),s.apply(console,n)}}}function fe(){return[...ee]}function Be(e,o){return{selectedElement:e?{tagName:e.tagName,id:e.id,className:e.className,textContent:e.textContent,outerHTML:e.outerHTML,cssSelector:e.cssSelector,computedStyles:e.computedStyles}:void 0,screenshot:o||void 0,networkLogs:he().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:fe().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var f={sparkle:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.582a.5.5 0 0 1 0 .962L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/></svg>',crosshair:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="22" y1="12" x2="18" y2="12"/><line x1="6" y1="12" x2="2" y2="12"/><line x1="12" y1="6" x2="12" y2="2"/><line x1="12" y1="22" x2="12" y2="18"/></svg>',camera:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg>',chat:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',settings:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>',send:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>',x:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',externalLink:'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>',check:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>',copy:'<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>',grip:'<svg width="7" height="14" viewBox="0 0 8 14" fill="currentColor"><circle cx="2" cy="2" r="1.2"/><circle cx="6" cy="2" r="1.2"/><circle cx="2" cy="7" r="1.2"/><circle cx="6" cy="7" r="1.2"/><circle cx="2" cy="12" r="1.2"/><circle cx="6" cy="12" r="1.2"/></svg>',network:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',activity:'<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>',paperclip:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>',image:'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>',trash:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>',minus:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>'},j={openai:{name:"OpenAI",keyUrl:"https://platform.openai.com/api-keys",keyPlaceholder:"sk-...",models:[{id:"gpt-5.4",name:"GPT-5.4"},{id:"gpt-5.4-mini",name:"GPT-5.4 Mini"},{id:"gpt-5.2",name:"GPT-5.2 Thinking"},{id:"o3",name:"o3"},{id:"o4-mini",name:"o4-mini"},{id:"gpt-4.1",name:"GPT-4.1"},{id:"gpt-4.1-mini",name:"GPT-4.1 Mini"}]},anthropic:{name:"Anthropic",keyUrl:"https://console.anthropic.com/settings/keys",keyPlaceholder:"sk-ant-...",models:[{id:"claude-opus-4-6",name:"Claude Opus 4.6"},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6"},{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5"}]},google:{name:"Google Gemini",keyUrl:"https://aistudio.google.com/apikey",keyPlaceholder:"AIza...",models:[{id:"gemini-3.1-pro-preview",name:"Gemini 3.1 Pro"},{id:"gemini-3-flash-preview",name:"Gemini 3 Flash"},{id:"gemini-2.5-pro",name:"Gemini 2.5 Pro"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash"}]},xai:{name:"xAI (Grok)",keyUrl:"https://console.x.ai/team/default/api-keys",keyPlaceholder:"xai-...",models:[{id:"grok-4.20-0309-reasoning",name:"Grok 4.20 Reasoning"},{id:"grok-4-1-fast-non-reasoning",name:"Grok 4.1 Fast"}]},deepseek:{name:"DeepSeek",keyUrl:"https://platform.deepseek.com/api_keys",keyPlaceholder:"sk-...",models:[{id:"deepseek-chat",name:"DeepSeek V3.2"},{id:"deepseek-reasoner",name:"DeepSeek R1"}]},mistral:{name:"Mistral",keyUrl:"https://console.mistral.ai/api-keys",keyPlaceholder:"...",models:[{id:"mistral-large-3-25-12",name:"Mistral Large 3"},{id:"codestral-2508",name:"Codestral"},{id:"devstral-2-25-12",name:"Devstral 2"}]},groq:{name:"Groq",keyUrl:"https://console.groq.com/keys",keyPlaceholder:"gsk_...",models:[{id:"meta-llama/llama-4-scout-17b-16e-instruct",name:"Llama 4 Scout"},{id:"llama-3.3-70b-versatile",name:"Llama 3.3 70B"}]},minimax:{name:"MiniMax",keyUrl:"https://platform.minimax.chat/user-center/basic-information/interface-key",keyPlaceholder:"MiniMax key...",models:[{id:"MiniMax-M2.7",name:"MiniMax M2.7"},{id:"MiniMax-M2.5",name:"MiniMax M2.5"}]},moonshot:{name:"Kimi (Moonshot)",keyUrl:"https://platform.moonshot.cn/console/api-keys",keyPlaceholder:"Moonshot key...",models:[{id:"kimi-k2.5",name:"Kimi K2.5"},{id:"kimi-k2-thinking",name:"Kimi K2 Thinking"}]},qwen:{name:"Qwen (Alibaba)",keyUrl:"https://dashscope.console.aliyun.com/apiKey",keyPlaceholder:"DashScope key...",models:[{id:"qwen3.5-plus",name:"Qwen 3.5 Plus"},{id:"qwen-max",name:"Qwen Max"}]},zhipu:{name:"Zhipu AI (GLM)",keyUrl:"https://open.bigmodel.cn/usercenter/apikeys",keyPlaceholder:"Zhipu key...",models:[{id:"glm-5",name:"GLM-5"},{id:"glm-4.7",name:"GLM-4.7"}]},doubao:{name:"Doubao (ByteDance)",keyUrl:"https://console.volcengine.com/ark/region:ark+cn-beijing/apiKey",keyPlaceholder:"Volcano key...",models:[{id:"doubao-seed-2-0-pro",name:"Doubao Seed 2.0 Pro"},{id:"doubao-seed-2-0-code",name:"Doubao Seed 2.0 Code"}]},ollama:{name:"Ollama (Local)",keyPlaceholder:"not required",local:!0,models:[]},openrouter:{name:"OpenRouter",keyUrl:"https://openrouter.ai/settings/keys",keyPlaceholder:"sk-or-...",models:[]}};function ne(e){let o=new TextEncoder().encode(e),s="";for(let n=0;n<o.length;n+=32768)s+=String.fromCharCode(...o.subarray(n,n+32768));return btoa(s)}function xe(e){let o=atob(e),s=new Uint8Array(o.length);for(let n=0;n<o.length;n++)s[n]=o.charCodeAt(n);return new TextDecoder().decode(s)}var Fe="0.28.6",t={connected:!1,panelOpen:!1,activePanel:"",selecting:!1,selectedElement:null,screenshot:null,messages:[],streaming:!1,streamContent:"",provider:"",model:"",hasApiKey:!1,configuredProviders:{},roots:[],updateAvailable:!1,latestVersion:"",saveStatus:"",networkCapture:!1,attachments:[],groundedFiles:[],minimized:!1},k,w,q,Ue,Se,N;function rt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:t.messages,provider:t.provider,model:t.model,panelOpen:t.panelOpen,activePanel:t.activePanel}))}catch{}}function it(){try{let e=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");e.messages?.length&&(t.messages=e.messages),e.provider&&(t.provider=e.provider),e.model&&(t.model=e.model),e.panelOpen&&(t.panelOpen=e.panelOpen,t.activePanel=e.activePanel||"")}catch{}}function je(){if(document.querySelector("openmagic-toolbar"))return;it();let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",k=e.attachShadow({mode:"closed"});let o=document.createElement("style");o.textContent=$e,k.appendChild(o);let s=document.createElement("div");k.appendChild(s),s.innerHTML=lt(),w=s.querySelector(".om-toolbar"),q=s.querySelector(".om-prompt-input"),Ue=s.querySelector(".om-prompt-context"),Se=s.querySelector(".om-panel"),N=s.querySelector(".om-panel-body"),document.body.appendChild(e),ct(s),kt();try{let r=JSON.parse(localStorage.getItem("__om_pos__")||"");r?.left&&r?.top&&(w.style.left=r.left,w.style.top=r.top,w.style.right="auto",w.style.bottom="auto")}catch{}De(),Ie(),Et();let a=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,i=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);a&&ue(i,a).then(()=>(t.connected=!0,ve(),v("config.get"))).then(r=>{let p=r.payload?.provider||"",l=r.payload?.model||"";t.provider=t.provider||p,t.model=t.model||l,t.configuredProviders=r.payload?.apiKeys||{},t.hasApiKey=t.configuredProviders[t.provider]||!1,t.roots=r.payload?.roots||[],t.panelOpen&&t.activePanel?R(t.activePanel):(!t.provider||!t.hasApiKey&&!Object.values(t.configuredProviders).some(Boolean))&&R("settings"),J()}).catch(()=>{t.connected=!1,ve()})}function lt(){return`
|
|
383
383
|
<div class="om-toolbar">
|
|
384
384
|
<div class="om-toolbar-header">
|
|
385
385
|
<span class="om-grab">${f.grip}</span>
|
|
@@ -413,10 +413,10 @@
|
|
|
413
413
|
<button class="om-prompt-send" data-action="prompt-send">${f.send}</button>
|
|
414
414
|
<input type="file" class="om-file-input om-hidden" accept="image/*" multiple />
|
|
415
415
|
</div>
|
|
416
|
-
</div>`}function ct(e){e.addEventListener("click",n=>{let a=n.target.closest("[data-action]");if(!a)return;n.preventDefault(),n.stopPropagation();let i=a.dataset.action;gt(i,a)}),e.addEventListener("change",n=>{let a=n.target,i=a.dataset.field;i&&(i==="provider"?(t.provider=a.value,t.model=
|
|
416
|
+
</div>`}function ct(e){e.addEventListener("click",n=>{let a=n.target.closest("[data-action]");if(!a)return;n.preventDefault(),n.stopPropagation();let i=a.dataset.action;gt(i,a)}),e.addEventListener("change",n=>{let a=n.target,i=a.dataset.field;i&&(i==="provider"?(t.provider=a.value,t.model=j[t.provider]?.models[0]?.id||"",t.hasApiKey=t.configuredProviders[t.provider]||j[t.provider]?.local||!1,t.saveStatus="",S()):i==="model"&&(t.model=a.value))}),q.addEventListener("keydown",n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),we())});let o=e.querySelector(".om-file-input");o&&o.addEventListener("change",()=>{be(o.files),o.value=""});let s=e.querySelector(".om-prompt-row");s&&(s.addEventListener("dragover",n=>{n.preventDefault(),s.style.borderColor="rgba(108, 92, 231, 0.5)"}),s.addEventListener("dragleave",()=>{s.style.borderColor=""}),s.addEventListener("drop",n=>{n.preventDefault(),s.style.borderColor="";let a=n.dataTransfer;a?.files?.length&&be(a.files)}),q.addEventListener("paste",n=>{let a=n.clipboardData?.items;if(a){for(let i=0;i<a.length;i++)if(a[i].type.startsWith("image/")){let r=a[i].getAsFile();if(r){let p=new DataTransfer;p.items.add(r),be(p.files)}}}})),Ce(n=>{n.type==="reconnected"&&(t.connected=!0,ve())}),document.addEventListener("keydown",n=>{if((n.ctrlKey||n.metaKey)&&n.shiftKey&&(n.key==="O"||n.key==="o")){if(n.preventDefault(),t.minimized){t.minimized=!1,w.querySelectorAll(".om-pill-btn:not([data-action='minimize']), .om-pill-divider, .om-status-dot").forEach(r=>r.style.display="");let i=k.querySelector(".om-prompt-row");i&&i.classList.remove("om-hidden")}else t.panelOpen?oe():R("chat");return}if(n.key==="Escape"){if(t.selecting)return;t.panelOpen&&(oe(),n.preventDefault())}}),q.addEventListener("keydown",n=>{(n.ctrlKey||n.metaKey)&&n.key==="Enter"&&(n.preventDefault(),we())})}function Ke(e){return t.roots.length>0?t.roots[0]+"/"+e:e}function dt(e,o){let s=o.split(`
|
|
417
417
|
`).map(r=>r.trim()).filter(r=>r.length>0);if(s.length===0)return null;let n=e.split(`
|
|
418
418
|
`),a=s[0],i=s[s.length-1];for(let r=0;r<n.length;r++){if(n[r].trim()!==a||r+s.length>n.length)continue;let p=!0;for(let l=0;l<s.length;l++)if(n[r+l].trim()!==s[l]){p=!1;break}if(p){let l=0;for(let c=0;c<r;c++)l+=n[c].length+1;let d=l;for(let c=r;c<r+s.length;c++)d+=n[c].length+1;return d>0&&d<=e.length&&e[d-1]===`
|
|
419
|
-
`&&d--,{start:l,end:d}}}return null}async function pt(e){let o=e.dataset.file,s=e.dataset.search,n=e.dataset.replace;if(!o||!s||!n)return;let a,i;try{a=xe(s),i=xe(n)}catch{t.messages.push({role:"system",content:`Failed to decode diff data for ${o}`}),S();return}let r=e.closest(".om-diff-card"),p=Ke(o);if(r){let l=r.querySelector(".om-diff-actions");l&&(l.innerHTML='<span class="om-spinner"></span> Applying...')}try{if(!a&&i){if((await v("fs.write",{path:p,content:i}))?.payload?.ok===!1)t.messages.push({role:"system",content:`Write failed: ${o}`});else{let u=r?.dataset.diffIdx;u!==void 0?t.messages[parseInt(u)]={role:"system",content:`Created ${o}`}:t.messages.push({role:"system",content:`Created ${o}`})}S(),
|
|
419
|
+
`&&d--,{start:l,end:d}}}return null}async function pt(e){let o=e.dataset.file,s=e.dataset.search,n=e.dataset.replace;if(!o||!s||!n)return;let a,i;try{a=xe(s),i=xe(n)}catch{t.messages.push({role:"system",content:`Failed to decode diff data for ${o}`}),S();return}let r=e.closest(".om-diff-card"),p=Ke(o);if(r){let l=r.querySelector(".om-diff-actions");l&&(l.innerHTML='<span class="om-spinner"></span> Applying...')}try{if(!a&&i){if((await v("fs.write",{path:p,content:i}))?.payload?.ok===!1)t.messages.push({role:"system",content:`Write failed: ${o}`});else{let u=r?.dataset.diffIdx;u!==void 0?t.messages[parseInt(u)]={role:"system",content:`Created ${o}`}:t.messages.push({role:"system",content:`Created ${o}`})}S(),F();return}let d=(await v("fs.read",{path:p}))?.payload?.content;if(!d)t.messages.push({role:"system",content:`Could not read ${o} \u2014 file may not exist at ${p}`});else{let c=d.split(a).length-1;if(c===1){let u=await v("fs.write",{path:p,content:d.replace(a,i)});if(u?.payload?.ok===!1)t.messages.push({role:"system",content:`Write failed: ${o} - ${u.payload?.error||"unknown"}`});else{let m=r?.dataset.diffIdx;m!==void 0?t.messages[parseInt(m)]={role:"system",content:`Applied change to ${o}`}:t.messages.push({role:"system",content:`Applied change to ${o}`})}}else if(c>1)t.messages.push({role:"system",content:`Found ${c} exact matches in ${o} \u2014 expected 1. Edit not applied.`});else{let u=dt(d,a);if(u){let m=d.slice(0,u.start)+i+d.slice(u.end),h=await v("fs.write",{path:p,content:m});if(h?.payload?.ok===!1)t.messages.push({role:"system",content:`Write failed: ${o} - ${h.payload?.error||"unknown"}`});else{let x=r?.dataset.diffIdx;x!==void 0?t.messages[parseInt(x)]={role:"system",content:`Applied change to ${o} (fuzzy match \u2014 whitespace adjusted)`}:t.messages.push({role:"system",content:`Applied change to ${o} (fuzzy match)`})}}else t.messages.push({role:"system",content:`No matching code found in ${o}. The file may have changed since the suggestion.`})}}}catch(l){t.messages.push({role:"system",content:`Failed to apply: ${o} \u2014 ${l.message}`})}S(),F()}function mt(e){let o=e.dataset.idx;if(o!==void 0){let s=parseInt(o),a=t.messages[s]?.content.split("__")?.[3]||"file";t.messages[s]={role:"system",content:`Rejected change to ${a}`}}S(),F()}async function ut(e){let o=e.dataset.file;if(!o)return;let s=Ke(o),n=s+".openmagic-backup";try{let i=(await v("fs.read",{path:n}))?.payload?.content;i?(await v("fs.write",{path:s,content:i}),t.messages.push({role:"system",content:`Reverted change to ${o}`})):t.messages.push({role:"system",content:`No backup found for ${o}`})}catch{t.messages.push({role:"system",content:`Could not revert ${o} \u2014 backup may not exist`})}S()}function gt(e,o){switch(e){case"select":vt();break;case"screenshot":wt();break;case"chat":ye("chat");break;case"settings":ye("settings");break;case"close-panel":oe();break;case"prompt-send":we();break;case"save-settings":yt();break;case"get-key":{let s=o.dataset.url;s&&window.open(s,"_blank","noopener");break}case"change-key":{let s=k.querySelector("[data-key-change]");s&&s.classList.remove("om-hidden"),o.style.display="none";break}case"network":ye("chat"),bt();break;case"attach-image":xt();break;case"remove-attachment":{let s=parseInt(o.dataset.idx||"0",10);t.attachments.splice(s,1),Ee();break}case"apply-diff":pt(o);break;case"reject-diff":mt(o);break;case"undo-diff":ut(o);break;case"clear-chat":{t.messages=[];try{sessionStorage.removeItem("__om_state__")}catch{}S();break}case"copy-msg":{let s=parseInt(o.dataset.idx||"0",10),n=t.messages[s];if(n){try{navigator.clipboard.writeText(n.content)}catch{}o.innerHTML=f.check,setTimeout(()=>{o.innerHTML=f.copy},1500)}break}case"clear-element":t.selectedElement=null,X();break;case"clear-screenshot":t.screenshot=null,X();break;case"minimize":{t.minimized=!t.minimized;let s=k.querySelector(".om-panel"),n=k.querySelector(".om-prompt-row"),a=k.querySelector(".om-prompt-attachments"),i=w.querySelectorAll(".om-pill-btn:not([data-action='minimize']), .om-pill-divider, .om-status-dot");t.minimized?(s&&s.classList.add("om-hidden"),n&&n.classList.add("om-hidden"),a&&a.classList.add("om-hidden"),i.forEach(r=>r.style.display="none")):(n&&n.classList.remove("om-hidden"),a&&a.classList.remove("om-hidden"),i.forEach(r=>r.style.display=""),t.panelOpen&&t.activePanel&&s&&s.classList.remove("om-hidden"));break}}}function ve(){let e=k.querySelector(".om-status-dot");e&&(e.className=`om-status-dot ${t.connected?"connected":"disconnected"}`)}function J(){k.querySelectorAll(".om-pill-btn").forEach(e=>{let o=e.dataset.action;e.classList.toggle("active",o===t.activePanel||o==="select"&&t.selecting)})}function X(){let e=[];t.selectedElement&&e.push(`<span class="om-prompt-chip">${t.selectedElement.tagName}${t.selectedElement.id?"#"+t.selectedElement.id:""} <button class="om-prompt-chip-x" data-action="clear-element">${f.x}</button></span>`),t.screenshot&&e.push(`<span class="om-prompt-chip">Screenshot <button class="om-prompt-chip-x" data-action="clear-screenshot">${f.x}</button></span>`),t.attachments.length&&e.push(`<span class="om-prompt-chip">${t.attachments.length} image${t.attachments.length>1?"s":""}</span>`),t.groundedFiles.length&&e.push(`<span class="om-prompt-chip">${t.groundedFiles.length} files grounded</span>`),Ue.innerHTML=e.join("")}function R(e){t.panelOpen=!0,t.activePanel=e,Se.classList.remove("om-hidden");let o=k.querySelector(".om-panel-title");o&&(o.textContent=e==="settings"?"Settings":"Chat"),S(),J()}function oe(){t.panelOpen=!1,t.activePanel="",Se.classList.add("om-hidden"),J()}function ye(e){t.panelOpen&&t.activePanel===e?oe():R(e)}function S(){t.activePanel==="settings"?N.innerHTML=ht():t.activePanel==="chat"&&(N.innerHTML=ft(),F()),rt()}function ht(){let e=Object.entries(j).map(([h,x])=>{let b=t.configuredProviders[h]||x.local?" \u2713":"";return`<option value="${h}" ${t.provider===h?"selected":""}>${x.name}${b}</option>`}).join(""),o=j[t.provider],s=o?o.models.map(h=>`<option value="${h.id}" ${t.model===h.id?"selected":""}>${h.name}</option>`).join(""):'<option value="">Select provider first</option>',n=o?.local||!1,a=o?.keyUrl||"",i=o?.keyPlaceholder||"Enter API key...",r=t.configuredProviders[t.provider]||!1,p=t.updateAvailable?`<div class="om-update-banner">v${t.latestVersion} available <code class="om-update-cmd">npx openmagic@latest</code></div>`:"",l=r||n?`<div class="om-status om-status-success">${f.check} ${o?.name||"Provider"} connected</div>`:"",d=t.saveStatus==="saving"?'<span class="om-spinner"></span> Saving...':t.saveStatus==="saved"?`${f.check} Saved`:"Save",c=t.saveStatus==="saving"?"om-btn om-btn-saving":t.saveStatus==="saved"?"om-btn om-btn-saved":"om-btn",u=t.saveStatus==="saving"?"disabled":"",m="";return!n&&t.provider&&(r?m=`
|
|
420
420
|
<div class="om-field">
|
|
421
421
|
<label class="om-label">API Key</label>
|
|
422
422
|
<div class="om-key-configured">
|
|
@@ -451,25 +451,25 @@
|
|
|
451
451
|
${m}
|
|
452
452
|
<button class="${c}" data-action="save-settings" ${u}>${d}</button>
|
|
453
453
|
${l}
|
|
454
|
-
</div>`}function ft(){if(!t.provider||!t.hasApiKey&&!
|
|
455
|
-
<div class="om-diff-file">${
|
|
456
|
-
${r.search?`<div class="om-diff-removed">${
|
|
457
|
-
<div class="om-diff-added">${
|
|
454
|
+
</div>`}function ft(){if(!t.provider||!t.hasApiKey&&!j[t.provider]?.local)return'<div class="om-status om-status-error">Configure your provider in Settings first</div>';let e=t.messages.map((n,a)=>{if(n.content.startsWith("__DIFF__"))try{let r=JSON.parse(xe(n.content.slice(8))),p=r.type==="create"||!r.search&&r.replace,l=ne(r.search||""),d=ne(r.replace||"");return`<div class="om-diff-card" data-diff-idx="${a}">
|
|
455
|
+
<div class="om-diff-file">${_(p?"Create new file":"Edit")}: ${_(r.file)}</div>
|
|
456
|
+
${r.search?`<div class="om-diff-removed">${_(r.search.slice(0,200))}</div>`:""}
|
|
457
|
+
<div class="om-diff-added">${_((r.replace||"").slice(0,300))}</div>
|
|
458
458
|
<div class="om-diff-actions">
|
|
459
|
-
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${
|
|
459
|
+
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${_(r.file)}" data-search="${l}" data-replace="${d}">Apply</button>
|
|
460
460
|
<button class="om-btn-secondary om-btn-sm" data-action="reject-diff" data-idx="${a}">Reject</button>
|
|
461
461
|
</div>
|
|
462
|
-
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(n.content.startsWith("Applied change to ")){let r=n.content.replace("Applied change to ","").replace(" (fuzzy match \u2014 whitespace adjusted)","").replace(" (fuzzy match)","");return`<div class="om-msg om-msg-system">${
|
|
463
|
-
// [FILE TRUNCATED \u2014 showing ${U} of ${D.length} chars]`),b.push({path:g.path,content:ae}),O.add(g.path),
|
|
464
|
-
// [FILE TRUNCATED \u2014 showing ${Y} of ${T.length} chars]`),b.push({path
|
|
465
|
-
// [FILE TRUNCATED \u2014 showing ${ie} of ${Z.length} chars]`),b.push({path:T,content:le}),O.add(T),
|
|
462
|
+
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(n.content.startsWith("Applied change to ")){let r=n.content.replace("Applied change to ","").replace(" (fuzzy match \u2014 whitespace adjusted)","").replace(" (fuzzy match)","");return`<div class="om-msg om-msg-system">${_(n.content)} <button class="om-undo-btn" data-action="undo-diff" data-file="${_(r)}">Undo</button></div>`}let i=n.role==="user"||n.role==="assistant"?`<button class="om-copy-btn" data-action="copy-msg" data-idx="${a}" title="Copy">${f.copy}</button>`:"";return n.role==="assistant"?`<div class="om-msg om-msg-assistant">${St(n.content)}${i}</div>`:`<div class="om-msg om-msg-${n.role}">${_(n.content)}${i}</div>`}).join(""),o=t.streaming?'<div class="om-msg om-msg-assistant"><span class="om-spinner"></span> Generating response...</div>':"";return`<div class="om-chat-messages">${!t.messages.length&&!t.streaming?'<div class="om-chat-empty">Select an element or type below to start</div>':""}${e}${o}</div>`}function F(){requestAnimationFrame(()=>{let e=N.querySelector(".om-chat-messages");e&&(e.scrollTop=e.scrollHeight)})}async function yt(){let o=N.querySelector('[data-field="apiKey"]')?.value||"";if(!t.provider){t.saveStatus="error",te(),setTimeout(()=>{t.saveStatus="",S()},2e3);return}if(!He()){t.saveStatus="error",te();let n=N.querySelector('[data-action="save-settings"]');n&&(n.innerHTML="Not connected - check terminal"),setTimeout(()=>{t.saveStatus="",S()},3e3);return}let s={provider:t.provider,model:t.model};o&&(s.apiKey=o),t.saveStatus="saving",te();try{let n=await Promise.race([v("config.set",s),new Promise((a,i)=>setTimeout(()=>i(new Error("Save timed out")),8e3))]);o&&t.provider&&(t.configuredProviders[t.provider]=!0),t.hasApiKey=!!(o||t.configuredProviders[t.provider]),t.saveStatus="saved",te(),setTimeout(()=>{t.saveStatus="",t.activePanel==="settings"&&R("chat")},1200)}catch(n){t.saveStatus="error";let a=N.querySelector('[data-action="save-settings"]'),i=(n?.message||"").includes("timeout")?"Connection timeout - is the CLI running?":(n?.message||"").includes("connected")?"Not connected to OpenMagic server":`Save failed: ${n?.message||"Unknown error"}`;a&&(a.innerHTML=i,a.className="om-btn",a.disabled=!1),setTimeout(()=>{t.saveStatus="",S()},4e3)}}function te(){let e=N.querySelector('[data-action="save-settings"]');e&&(t.saveStatus==="saving"?(e.innerHTML='<span class="om-spinner"></span> Saving...',e.className="om-btn om-btn-saving",e.disabled=!0):t.saveStatus==="saved"?(e.innerHTML=`${f.check} Saved`,e.className="om-btn om-btn-saved",e.disabled=!1):t.saveStatus==="error"?(e.innerHTML="Save failed - try again",e.className="om-btn",e.disabled=!1):(e.innerHTML="Save",e.className="om-btn",e.disabled=!1))}async function we(){let e=q.value.trim();if(!e||t.streaming)return;if(!t.provider||!t.hasApiKey&&!j[t.provider]?.local){R("settings");return}t.messages.push({role:"user",content:e}),t.streaming=!0,t.streamContent="",q.value="",R("chat");let o=Be(t.selectedElement,t.screenshot);o.pageUrl=window.location.href,o.pageTitle=document.title,t.attachments.length>0&&(o.screenshot||(o.screenshot=t.attachments[0]),o.attachments=[...t.attachments]);let s=5,n=32e3,a=/\.(?:[cm]?[jt]sx?|svelte|vue|astro|html?|css|scss|less|php|py)$/i,i=N.querySelector(".om-msg-assistant:last-child");i&&(i.innerHTML='<span class="om-spinner"></span> Reading project files...');try{let l=await v("fs.list",{});l?.payload?.projectTree&&(o.projectTree=l.payload.projectTree);let c=(l?.payload?.files||[]).filter(g=>g.type==="file"&&a.test(g.path)),u=[e];if(t.selectedElement&&(t.selectedElement.id&&u.push(t.selectedElement.id),t.selectedElement.className&&u.push(t.selectedElement.className),t.selectedElement.textContent&&u.push(t.selectedElement.textContent.slice(0,100)),t.selectedElement.componentHint&&u.push(t.selectedElement.componentHint),t.selectedElement.ancestry))for(let g of t.selectedElement.ancestry)u.push(g);let m=u.filter(Boolean).join(" ").toLowerCase().split(/[^a-z0-9_-]+/).filter(g=>g.length>=2&&!["the","to","in","of","and","div","span","class","style"].includes(g)),x=window.location.pathname.split("/").filter(g=>g.length>1&&!/^\d+$/.test(g)),A=c.map(g=>{let y=0,M=g.path.toLowerCase();for(let P of x)M.includes(P.toLowerCase())&&(y+=15);if(t.selectedElement?.componentHint){let P=t.selectedElement.componentHint.toLowerCase();M.includes(P)&&(y+=12)}for(let P of m)M.includes(P)&&(y+=5);return/(component|page|route|layout|template|view)/.test(M)&&(y+=3),/page\.[jt]sx?$|layout\.[jt]sx?$|\+page\.svelte$/.test(M)&&(y+=5),{...g,score:y}}).sort((g,y)=>y.score-g.score),b=[],O=new Set,H=0;for(let g of A.slice(0,s)){if(g.score<=0||H>=n)break;try{let y=t.roots[0]||"",M=y?`${y}/${g.path}`:g.path,P=await v("fs.read",{path:M}),D=String(P?.payload?.content||"");if(!D)continue;let U=Math.min(8e3,n-H),ae=D.slice(0,U);D.length>U&&(ae+=`
|
|
463
|
+
// [FILE TRUNCATED \u2014 showing ${U} of ${D.length} chars]`),b.push({path:g.path,content:ae}),O.add(g.path),H+=ae.length;let Ge=g.path.replace(/\.[^.]+$/,""),We=[".module.css",".module.scss",".css",".scss",".styles.ts"];for(let re of We){let E=Ge+re;if(O.has(E)||H>=n)continue;if(c.find(K=>K.path===E)){try{let K=await v("fs.read",{path:y?`${y}/${E}`:E}),T=String(K?.payload?.content||"");if(T){let Y=Math.min(4e3,n-H),I=T.slice(0,Y);T.length>Y&&(I+=`
|
|
464
|
+
// [FILE TRUNCATED \u2014 showing ${Y} of ${T.length} chars]`),b.push({path:E,content:I}),O.add(E),H+=I.length}}catch{}break}}let Ve=D.matchAll(/(?:import|from)\s+['"]\.?\.\/([\w/.-]+)['"]/g);for(let re of Ve){if(H>=n)break;let E=re[1],z=g.path.replace(/\/[^/]+$/,""),K=[`${z}/${E}`,`${z}/${E}.tsx`,`${z}/${E}.ts`,`${z}/${E}.jsx`,`${z}/${E}.js`,`${z}/${E}/index.tsx`,`${z}/${E}/index.ts`];for(let T of K){if(O.has(T))break;if(c.find(I=>I.path===T)){try{let I=await v("fs.read",{path:y?`${y}/${T}`:T}),Z=String(I?.payload?.content||"");if(Z){let ie=Math.min(8e3,n-H),le=Z.slice(0,ie);Z.length>ie&&(le+=`
|
|
465
|
+
// [FILE TRUNCATED \u2014 showing ${ie} of ${Z.length} chars]`),b.push({path:T,content:le}),O.add(T),H+=le.length}}catch{}break}}}}catch{}}if(H<n)try{let g=t.roots[0]||"",y=await v("fs.read",{path:g?`${g}/package.json`:"package.json"}),M=String(y?.payload?.content||"");if(M)try{let P=JSON.parse(M),D={...P.dependencies,...P.devDependencies},U=JSON.stringify(D,null,2);b.push({path:"package.json (dependencies)",content:U.slice(0,2e3)})}catch{b.push({path:"package.json",content:M.slice(0,2e3)})}}catch{}if(b.length){o.files=b;let g=b.map(y=>y.path.split("/").pop()).join(", ");i&&(i.innerHTML=`<span class="om-spinner"></span> Thinking... (${b.length} files: ${g})`)}t.groundedFiles=b.map(g=>g.path)}catch{}let r=4,p=0;try{for(;p<=r;){t.streamContent="";let l=await Te("llm.chat",{provider:t.provider,model:t.model,messages:t.messages.map(m=>({role:m.role,content:m.content})),context:o},m=>{t.streamContent+=m}),d=t.streamContent||l?.content||"",c=d.match(/NEED_FILE:\s*"?([^\s"}\]]+)"?/)||d.match(/(?:need|provide|show|read|see|contents?\s+of)\s+(?:the\s+)?(?:file\s+)?[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i)||d.match(/(?:source\s+(?:file|code)\s+(?:for|of|at))\s+[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i);if(c&&!l?.modifications?.length&&p<r){let m=c[1].trim();p++,t.messages.push({role:"system",content:`Reading ${m}...`}),S();try{let h=t.roots[0]||"",x=h?`${h}/${m}`:m,A=await v("fs.read",{path:x}),b=String(A?.payload?.content||"");if(b)o.files||(o.files=[]),o.files.push({path:m,content:b.slice(0,8e3)}),t.messages.push({role:"assistant",content:d}),t.messages.push({role:"user",content:`Here is ${m}. Now please make the edit.`});else{t.messages.push({role:"system",content:`Could not read ${m}`});break}}catch{t.messages.push({role:"system",content:`File not found: ${m}`});break}continue}let u=d;try{let m=JSON.parse(d);m.explanation&&(u=m.explanation)}catch{let m=d.match(/```(?:json)?\s*([\s\S]*?)```/);if(m)try{let h=JSON.parse(m[1]);h.explanation&&(u=h.explanation)}catch{}}if(t.messages.push({role:"assistant",content:u}),l?.modifications?.length)for(let m of l.modifications)if(m.type==="edit"&&m.file&&m.search&&m.replace){let h=Math.random().toString(36).slice(2),x=JSON.stringify({id:h,file:m.file,search:m.search,replace:m.replace});t.messages.push({role:"system",content:`__DIFF__${ne(x)}`})}else if(m.type==="create"&&m.file&&m.content){let h=Math.random().toString(36).slice(2),x=JSON.stringify({id:h,file:m.file,search:"",replace:m.content,type:"create"});t.messages.push({role:"system",content:`__DIFF__${ne(x)}`})}else m.type==="delete"&&m.file&&t.messages.push({role:"system",content:`LLM proposed deleting ${m.file} \u2014 skipped (use edit with search/replace instead)`});break}}catch(l){t.messages.push({role:"system",content:`Error: ${l.message}`})}t.streaming=!1,t.streamContent="",t.attachments=[],Ee(),S(),F()}function bt(){let e=window.performance,o=e.getEntriesByType("navigation")[0],s=e.getEntriesByType("paint"),n=e.getEntriesByType("resource").slice(-20),a=he(),i=fe(),r=[];r.push("--- Network & Performance Capture ---"),o&&(r.push(`Page load: ${Math.round(o.loadEventEnd-o.startTime)}ms`),r.push(`DOM ready: ${Math.round(o.domContentLoadedEventEnd-o.startTime)}ms`),r.push(`TTFB: ${Math.round(o.responseStart-o.startTime)}ms`));let p=s.find(l=>l.name==="first-contentful-paint");if(p&&r.push(`FCP: ${Math.round(p.startTime)}ms`),n.length){let l=n.filter(c=>c.initiatorType==="fetch"||c.initiatorType==="xmlhttprequest"),d=l.length>0?l:n;r.push(`
|
|
466
466
|
All network requests (${d.length}):`);for(let c of d.slice(-30)){let u=c.name.length>80?"..."+c.name.slice(-77):c.name,m=c.responseStatus||"";r.push(` ${Math.round(c.duration)}ms ${m?`[${m}]`:""} ${u}`)}}if(a.length){r.push(`
|
|
467
467
|
Fetch/XHR requests (${a.length}):`);for(let l of a.slice(-20))r.push(` ${l.method} ${l.url.slice(0,80)} \u2192 ${l.status||"pending"} (${l.duration||"?"}ms)`)}if(i.length){let l=i.filter(c=>c.level==="error"),d=i.filter(c=>c.level==="warn");l.length&&r.push(`
|
|
468
468
|
Console errors: ${l.length}`),d.length&&r.push(`Console warnings: ${d.length}`)}if(n.length>5){let l=[...n].sort((d,c)=>c.duration-d.duration).slice(0,5);r.push(`
|
|
469
469
|
Slowest resources:`);for(let d of l)r.push(` ${Math.round(d.duration)}ms \u2014 ${d.name.split("/").pop()?.slice(0,60)}`)}t.messages.push({role:"system",content:r.join(`
|
|
470
|
-
`)}),S(),
|
|
470
|
+
`)}),S(),F(),X()}function xt(){let e=k.querySelector(".om-file-input");e&&e.click()}function be(e){if(e)for(let o=0;o<e.length&&t.attachments.length<5;o++){let s=e[o];if(!s.type.startsWith("image/")||s.size>10*1024*1024)continue;let n=new FileReader;n.onload=()=>{typeof n.result=="string"&&(t.attachments.push(n.result),Ee())},n.readAsDataURL(s)}}function Ee(){let e=k.querySelector(".om-prompt-attachments");if(e){if(!t.attachments.length){e.innerHTML="",e.classList.add("om-hidden");return}e.classList.remove("om-hidden"),e.innerHTML=t.attachments.map((o,s)=>`<div class="om-attachment-thumb">
|
|
471
471
|
<img src="${o}" alt="attachment" />
|
|
472
472
|
<button class="om-attachment-remove" data-action="remove-attachment" data-idx="${s}">${f.x}</button>
|
|
473
|
-
</div>`).join("")}}var W=null,V=null;function vt(){t.selecting?ke():se()}function se(){t.selecting=!0,document.body.style.cursor="crosshair",J(),V=o=>{let s=o.target;if(s.closest("openmagic-toolbar")||s.dataset?.openmagic)return;let n=s.getBoundingClientRect();Ne({x:n.x,y:n.y,width:n.width,height:n.height})},W=o=>{o.preventDefault(),o.stopPropagation();let s=o.target;s.closest("openmagic-toolbar")||s.dataset?.openmagic||(t.selectedElement=_e(s),ke(),X(),q.focus())};let e=o=>{o.key==="Escape"&&ke()};document.addEventListener("mousemove",V,!0),document.addEventListener("click",W,!0),document.addEventListener("keydown",e,!0),se._escHandler=e}function ke(){t.selecting=!1,document.body.style.cursor="",Re(),V&&(document.removeEventListener("mousemove",V,!0),V=null),W&&(document.removeEventListener("click",W,!0),W=null);let e=se._escHandler;e&&(document.removeEventListener("keydown",e,!0),se._escHandler=null),J()}async function wt(){let e;try{let n=t.selectedElement?.cssSelector?.trim();n&&(e=document.querySelector(n)||void 0)}catch{}let o=await Ae(e||void 0);o.data&&o.data.length>5e3?(t.screenshot=o.data,X(),q.focus()):(t.messages.push({role:"system",content:"Take a screenshot manually (Cmd+Shift+4 on Mac, Win+Shift+S on Windows), then paste it here (Ctrl+V) or drag it onto the prompt bar."}),R("chat"),S())}function kt(){let e=!1,o=0,s=0,n=0,a=0;w.addEventListener("mousedown",i=>{let r=i.target;if(r.closest("[data-action]")||!r.closest(".om-grab")&&!r.closest(".om-pill-brand"))return;e=!0,o=i.clientX,s=i.clientY;let p=w.getBoundingClientRect();n=p.left,a=p.top,i.preventDefault()}),document.addEventListener("mousemove",i=>{e&&(w.style.left=n+i.clientX-o+"px",w.style.top=a+i.clientY-s+"px",w.style.right="auto",w.style.bottom="auto")}),document.addEventListener("mouseup",()=>{if(e){e=!1;try{localStorage.setItem("__om_pos__",JSON.stringify({left:w.style.left,top:w.style.top}))}catch{}}})}function
|
|
474
|
-
`),s=
|
|
473
|
+
</div>`).join("")}}var W=null,V=null;function vt(){t.selecting?ke():se()}function se(){t.selecting=!0,document.body.style.cursor="crosshair",J(),V=o=>{let s=o.target;if(s.closest("openmagic-toolbar")||s.dataset?.openmagic)return;let n=s.getBoundingClientRect();Ne({x:n.x,y:n.y,width:n.width,height:n.height})},W=o=>{o.preventDefault(),o.stopPropagation();let s=o.target;s.closest("openmagic-toolbar")||s.dataset?.openmagic||(t.selectedElement=_e(s),ke(),X(),q.focus())};let e=o=>{o.key==="Escape"&&ke()};document.addEventListener("mousemove",V,!0),document.addEventListener("click",W,!0),document.addEventListener("keydown",e,!0),se._escHandler=e}function ke(){t.selecting=!1,document.body.style.cursor="",Re(),V&&(document.removeEventListener("mousemove",V,!0),V=null),W&&(document.removeEventListener("click",W,!0),W=null);let e=se._escHandler;e&&(document.removeEventListener("keydown",e,!0),se._escHandler=null),J()}async function wt(){let e;try{let n=t.selectedElement?.cssSelector?.trim();n&&(e=document.querySelector(n)||void 0)}catch{}let o=await Ae(e||void 0);o.data&&o.data.length>5e3?(t.screenshot=o.data,X(),q.focus()):(t.messages.push({role:"system",content:"Take a screenshot manually (Cmd+Shift+4 on Mac, Win+Shift+S on Windows), then paste it here (Ctrl+V) or drag it onto the prompt bar."}),R("chat"),S())}function kt(){let e=!1,o=0,s=0,n=0,a=0;w.addEventListener("mousedown",i=>{let r=i.target;if(r.closest("[data-action]")||!r.closest(".om-grab")&&!r.closest(".om-pill-brand"))return;e=!0,o=i.clientX,s=i.clientY;let p=w.getBoundingClientRect();n=p.left,a=p.top,i.preventDefault()}),document.addEventListener("mousemove",i=>{e&&(w.style.left=n+i.clientX-o+"px",w.style.top=a+i.clientY-s+"px",w.style.right="auto",w.style.bottom="auto")}),document.addEventListener("mouseup",()=>{if(e){e=!1;try{localStorage.setItem("__om_pos__",JSON.stringify({left:w.style.left,top:w.style.top}))}catch{}}})}function _(e){let o=document.createElement("div");return o.textContent=e,o.innerHTML}function St(e){let o=e.replace(/\\n/g,`
|
|
474
|
+
`),s=_(o);return s=s.replace(/```(\w*)\n([\s\S]*?)```/g,'<pre class="om-code-block"><code>$2</code></pre>'),s=s.replace(/`([^`]+)`/g,'<code class="om-inline-code">$1</code>'),s=s.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),s=s.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g,"<em>$1</em>"),s=s.replace(/^- (.+)$/gm,"• $1"),s=s.replace(/\n/g,"<br>"),s}function Et(){fetch("https://registry.npmjs.org/openmagic/latest",{headers:{Accept:"application/json"},signal:AbortSignal.timeout(5e3)}).then(e=>e.ok?e.json():null).then(e=>{if(!e?.version)return;let o=e.version.split(".").map(Number),s=Fe.split(".").map(Number);for(let n=0;n<3;n++){if((o[n]||0)>(s[n]||0)){t.updateAvailable=!0,t.latestVersion=e.version,$t();return}if((o[n]||0)<(s[n]||0))return}}).catch(()=>{})}function $t(){if(k.querySelector(".om-update-dot"))return;let o=document.createElement("span");o.className="om-update-dot",o.title=`v${t.latestVersion} available`,o.addEventListener("click",()=>R("settings"));let s=k.querySelector(".om-toolbar-header");s&&s.appendChild(o)}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",je):je());})();
|
|
475
475
|
//# sourceMappingURL=index.global.js.map
|