openmagic 0.28.0 → 0.28.2
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 +46 -46
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
|
@@ -361,85 +361,85 @@
|
|
|
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,$=new Map,G=[],pe=[],j=!1,Le=!1,ce=null,de=0;function me(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function ue(e,t){return Le=!0,new Promise((s,o)=>{let a=!1,r=setTimeout(()=>{a||(a=!0,o(new Error("Handshake timeout")),C?.close())},1e4);try{let i=window.location.hostname||"127.0.0.1",
|
|
364
|
+
`;var C=null,$=new Map,G=[],pe=[],j=!1,Le=!1,ce=null,de=0;function me(){return Math.random().toString(36).slice(2)+Date.now().toString(36)}function ue(e,t){return Le=!0,new Promise((s,o)=>{let a=!1,r=setTimeout(()=>{a||(a=!0,o(new Error("Handshake timeout")),C?.close())},1e4);try{let i=window.location.hostname||"127.0.0.1",d=window.location.protocol==="https:"?"wss:":"ws:";C=new WebSocket(`${d}//${i}:${e}/__openmagic__/ws`),C.onopen=()=>{let l=me();C.send(JSON.stringify({id:l,type:"handshake",payload:{token:t}})),$.set(l,c=>{if(c.type==="handshake.ok"){clearTimeout(r),j=!0,de=0;for(let p of pe)C?.send(p);pe=[],a||(a=!0,s())}else c.type==="error"&&(clearTimeout(r),a||(a=!0,o(new Error(c.payload?.message||"Handshake failed"))))})},C.onmessage=l=>{try{let c=JSON.parse(l.data);c.id&&$.has(c.id)&&($.get(c.id)(c),(c.type==="llm.done"||c.type==="llm.error"||!c.type.startsWith("llm."))&&$.delete(c.id));for(let p of G)p(c)}catch{}},C.onclose=()=>{let l=j;if(j=!1,$.forEach((c,p)=>{c({type:"error",id:p,payload:{message:"Connection lost"}})}),$.clear(),!l&&!a){clearTimeout(r),a=!0,o(new Error("WebSocket closed before handshake"));return}if(l&&Le&&!ce){let c=Math.min(2e3*Math.pow(1.5,de),3e4);de++,ce=setTimeout(()=>{ce=null,ue(e,t).then(()=>{for(let p of G)p({type:"reconnected",payload:{}})}).catch(()=>{})},c)}},C.onerror=()=>{!j&&!a&&(clearTimeout(r),a=!0,o(new Error("WebSocket connection failed")))}}catch(i){clearTimeout(r),a||(a=!0,o(i))}})}function Me(e){let t=JSON.stringify(e);C&&C.readyState===WebSocket.OPEN&&j?C.send(t):pe.push(t)}function v(e,t){return new Promise((s,o)=>{let a=me(),r=setTimeout(()=>{$.delete(a),o(new Error("Request timeout"))},3e4);$.set(a,i=>{clearTimeout(r),i.type==="error"?o(new Error(i.payload?.message||"Unknown error")):s(i)}),Me({id:a,type:e,payload:t})})}function Te(e,t,s){return new Promise((o,a)=>{let r=me(),i=setTimeout(()=>{$.delete(r),a(new Error("Stream timeout"))},12e4);$.set(r,d=>{d.type==="llm.chunk"?s(d.payload?.delta||""):d.type==="llm.done"?(clearTimeout(i),$.delete(r),o(d.payload)):(d.type==="llm.error"||d.type==="error")&&(clearTimeout(i),$.delete(r),a(new Error(d.payload?.message||"Stream error")))}),Me({id:r,type:e,payload:t})})}function Ce(e){return G.push(e),()=>{G=G.filter(t=>t!==e)}}function He(){return j}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 t=window.getComputedStyle(e),s={};for(let p of Pe)s[p]=t.getPropertyValue(p);let o=e.getBoundingClientRect(),a={};if(e.parentElement&&e.parentElement!==document.body){let p=window.getComputedStyle(e.parentElement);for(let u of Pe)a[u]=p.getPropertyValue(u)}let r=[];if(e.parentElement){let p=Array.from(e.parentElement.children),u=p.indexOf(e),m=Math.max(0,u-3),h=Math.min(p.length,u+4);m>0&&r.push(`... ${m} elements before ...`);for(let x=m;x<h;x++){let A=p[x],b=A.tagName.toLowerCase(),O=(A.className||"").toString().slice(0,60);A===e?r.push(`[SELECTED] <${b} class="${O}">`):r.push(`<${b} class="${O}">`)}h<p.length&&r.push(`... ${p.length-h} elements after ...`)}let i=tt(e),d={};for(let p of Array.from(e.attributes))(p.name.startsWith("aria-")||p.name==="role"||p.name==="tabindex")&&(d[p.name]=p.value);let l=[];for(let p of Array.from(e.attributes))p.name.startsWith("on")&&l.push(p.name);let c=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:o.x,y:o.y,width:o.width,height:o.height},parentStyles:a,siblings:r,matchedCssRules:i,viewport:{width:window.innerWidth,height:window.innerHeight},ariaAttributes:d,eventHandlers:l,reactProps:c}}function Je(e,t=5){let s=[],o=e.parentElement;for(;o&&o!==document.body&&s.length<t;){let a=o.tagName.toLowerCase(),r=(typeof o.className=="string"?o.className:"").split(/\s+/).filter(i=>i.length>1&&!i.startsWith("_")).slice(0,3).join(".");s.push(r?`${a}.${r}`:a),o=o.parentElement}return s}function Ye(e){let t=e;for(;t&&t!==document.body;){let s=t.getAttribute("data-component")||t.getAttribute("data-testid")||t.getAttribute("data-cy");if(s)return s;let o=Object.keys(t);for(let a of o)if(a.startsWith("__reactFiber")||a.startsWith("__reactInternalInstance"))try{let r=t[a],i=r?.type?.name||r?.type?.displayName||r?.return?.type?.name||r?.return?.type?.displayName;if(i&&i!=="div"&&i!=="span"&&i.length>1)return i}catch{}t=t.parentElement}return""}function Ze(e){let t=e.cloneNode(!0);t.querySelectorAll("script, style, svg").forEach(a=>a.remove());let o=t.outerHTML;if(o.length>2e3){let a=e.tagName.toLowerCase(),r=Array.from(e.attributes).map(d=>`${d.name}="${d.value}"`).join(" "),i=Array.from(e.children).slice(0,5).map(d=>`<${d.tagName.toLowerCase()} .../>`).join(`
|
|
365
365
|
`);o=`<${a} ${r}>
|
|
366
366
|
${i}
|
|
367
367
|
${e.children.length>5?`<!-- +${e.children.length-5} more children -->`:""}
|
|
368
|
-
</${a}>`}return o}function
|
|
368
|
+
</${a}>`}return o}function Qe(e){if(e.id)return`#${CSS.escape(e.id)}`;let t=[],s=e;for(;s&&s!==document.body;){let o=s.tagName.toLowerCase();if(s.id){t.unshift(`#${CSS.escape(s.id)}`);break}if(s.className&&typeof s.className=="string"){let r=s.className.trim().split(/\s+/).filter(i=>!i.startsWith("__")&&i.length<30).slice(0,2).map(i=>CSS.escape(i));r.length>0&&(o+="."+r.join("."))}let a=s.parentElement;if(a){let r=Array.from(a.children).filter(i=>i.tagName===s.tagName);if(r.length>1){let i=r.indexOf(s)+1;o+=`:nth-of-type(${i})`}}t.unshift(o),s=s.parentElement}return t.join(" > ")}function et(e){let t=[],s=e;for(;s&&s!==document;){if(s.nodeType===Node.ELEMENT_NODE){let o=s,a=1,r=o.previousElementSibling;for(;r;)r.tagName===o.tagName&&a++,r=r.previousElementSibling;t.unshift(`${o.tagName.toLowerCase()}[${a}]`)}s=s.parentNode}return"/"+t.join("/")}function tt(e){let t=[];try{for(let s of Array.from(document.styleSheets))try{let o=s.cssRules||s.rules;if(!o)continue;for(let a of Array.from(o))if(a instanceof CSSStyleRule)try{if(e.matches(a.selectorText)){let r=a.cssText;r.length>10&&r.length<500&&t.push(r)}}catch{}}catch{}}catch{}return t.slice(0,15)}function nt(e){try{let t=Object.keys(e);for(let s of t)if(s.startsWith("__reactFiber")||s.startsWith("__reactInternalInstance")){let o=e[s];if(!o?.memoizedProps)continue;let a=o.memoizedProps,r={},i=0;for(let[d,l]of Object.entries(a)){if(i>=10)break;if(d==="children")continue;let c=typeof l;c==="string"||c==="number"||c==="boolean"||l===null?(r[d]=l,i++):c==="function"?(r[d]="[function]",i++):Array.isArray(l)&&(r[d]=`[Array(${l.length})]`,i++)}return Object.keys(r).length>0?r:null}}catch{}return null}var L=null;function Ne(e){L||(L=document.createElement("div"),L.style.cssText=`
|
|
369
369
|
position: fixed;
|
|
370
370
|
pointer-events: none;
|
|
371
371
|
z-index: 2147483646;
|
|
372
372
|
border: 2px solid #6c5ce7;
|
|
373
373
|
background: rgba(108, 92, 231, 0.1);
|
|
374
374
|
transition: all 0.1s ease;
|
|
375
|
-
`,L.dataset.openmagic="highlight",document.body.appendChild(L)),L.style.left=`${e.x}px`,L.style.top=`${e.y}px`,L.style.width=`${e.width}px`,L.style.height=`${e.height}px`,L.style.display="block"}function Re(){L&&(L.style.display="none")}async function Ae(e){try{
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
</svg>`;t(i)})}function ze(e,t){let s=window.getComputedStyle(e),o="";for(let i=0;i<s.length;i++){let c=s[i];o+=`${c}:${s.getPropertyValue(c)};`}t.style.cssText=o;let a=e.children,r=t.children;for(let i=0;i<a.length&&i<r.length;i++)ze(a[i],r[i])}function De(e,t,s){return new Promise((o,a)=>{let r=new Image,i=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),c=URL.createObjectURL(i);r.onload=()=>{URL.revokeObjectURL(c),o(r)},r.onerror=()=>{URL.revokeObjectURL(c),a(new Error("Failed to load SVG image"))},r.width=t,r.height=s,r.src=c})}var Q=[];var qe=!1;function Be(){if(qe)return;qe=!0;let e=window.fetch;window.fetch=async function(...o){let a=new Request(...o),r={method:a.method,url:a.url,timestamp:Date.now()};try{let i=await e.apply(this,o);return r.status=i.status,r.duration=Date.now()-r.timestamp,ge(r),i}catch(i){throw r.status=0,r.duration=Date.now()-r.timestamp,ge(r),i}};let t=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,a,...r){return this.__om_method=o,this.__om_url=a,this.__om_start=Date.now(),t.apply(this,[o,a,...r])},XMLHttpRequest.prototype.send=function(...o){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,o)}}function ge(e){e.url.includes("__openmagic__")||(Q.push(e),Q.length>50&&Q.shift())}function he(){return[...Q]}var ee=[],it=100,Ie=!1;function je(){if(Ie)return;Ie=!0;let e=["log","warn","error","info","debug"];for(let t of e){let s=console[t];console[t]=function(...o){ee.push({level:t,args:o.map(a=>{try{return typeof a=="object"?JSON.stringify(a).slice(0,500):String(a)}catch{return String(a)}}),timestamp:Date.now()}),ee.length>it&&ee.shift(),s.apply(console,o)}}}function fe(){return[...ee]}function Fe(e,t){return{selectedElement:e?{tagName:e.tagName,id:e.id,className:e.className,textContent:e.textContent,outerHTML:e.outerHTML,cssSelector:e.cssSelector,computedStyles:e.computedStyles}:void 0,screenshot:t||void 0,networkLogs: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 h={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 t=new TextEncoder().encode(e),s="";for(let o=0;o<t.length;o+=32768)s+=String.fromCharCode(...t.subarray(o,o+32768));return btoa(s)}function xe(e){let t=atob(e),s=new Uint8Array(t.length);for(let o=0;o<t.length;o++)s[o]=t.charCodeAt(o);return new TextDecoder().decode(s)}var Ke="0.28.0",n={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},w,v,z,Ge,Ee,N;function lt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function ct(){try{let e=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");e.messages?.length&&(n.messages=e.messages),e.provider&&(n.provider=e.provider),e.model&&(n.model=e.model),e.panelOpen&&(n.panelOpen=e.panelOpen,n.activePanel=e.activePanel||"")}catch{}}function Ue(){if(document.querySelector("openmagic-toolbar"))return;ct();let e=document.createElement("openmagic-toolbar");e.dataset.openmagic="true",w=e.attachShadow({mode:"closed"});let t=document.createElement("style");t.textContent=$e,w.appendChild(t);let s=document.createElement("div");w.appendChild(s),s.innerHTML=dt(),v=s.querySelector(".om-toolbar"),z=s.querySelector(".om-prompt-input"),Ge=s.querySelector(".om-prompt-context"),Ee=s.querySelector(".om-panel"),N=s.querySelector(".om-panel-body"),document.body.appendChild(e),pt(s),St();try{let i=JSON.parse(localStorage.getItem("__om_pos__")||"");i?.left&&i?.top&&(v.style.left=i.left,v.style.top=i.top,v.style.right="auto",v.style.bottom="auto")}catch{}Be(),je(),Lt();let a=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,r=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);a&&ue(r,a).then(()=>(n.connected=!0,ve(),x("config.get"))).then(i=>{let c=i.payload?.provider||"",l=i.payload?.model||"";n.provider=n.provider||c,n.model=n.model||l,n.configuredProviders=i.payload?.apiKeys||{},n.hasApiKey=n.configuredProviders[n.provider]||!1,n.roots=i.payload?.roots||[],n.panelOpen&&n.activePanel?D(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&D("settings"),J()}).catch(()=>{n.connected=!1,ve()})}function dt(){return`
|
|
375
|
+
`,L.dataset.openmagic="highlight",document.body.appendChild(L)),L.style.left=`${e.x}px`,L.style.top=`${e.y}px`,L.style.width=`${e.width}px`,L.style.height=`${e.height}px`,L.style.display="block"}function Re(){L&&(L.style.display="none")}async function Ae(e){try{let t=e||document.body,s=await ot(t);if(s)return{data:s}}catch{}try{let t=await st(e);if(t)return{data:t}}catch(t){return{data:null,error:`Screenshot failed: ${t.message||"unknown error"}. Try using the image attachment button instead.`}}return{data:null,error:"Screenshot capture not available on this page. Try pasting or dragging an image instead."}}async function ot(e){let t=e.getBoundingClientRect(),s=Math.min(t.width||window.innerWidth,1920),o=Math.min(t.height||window.innerHeight,1080),a=Oe(e,0,4);if(!a)return null;let r=`
|
|
376
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${o}">
|
|
377
|
+
<foreignObject width="100%" height="100%">
|
|
378
|
+
<div xmlns="http://www.w3.org/1999/xhtml" style="width:${s}px;height:${o}px;overflow:hidden;">
|
|
379
|
+
${a.outerHTML}
|
|
380
|
+
</div>
|
|
381
|
+
</foreignObject>
|
|
382
|
+
</svg>`,i=new Blob([r],{type:"image/svg+xml;charset=utf-8"}),d=URL.createObjectURL(i);return new Promise(l=>{let c=new Image,p=document.createElement("canvas"),u=Math.min(window.devicePixelRatio||1,2);p.width=s*u,p.height=o*u,c.onload=()=>{URL.revokeObjectURL(d);let m=p.getContext("2d");if(!m){l(null);return}m.scale(u,u),m.drawImage(c,0,0);try{l(p.toDataURL("image/png",.8))}catch{l(null)}},c.onerror=()=>{URL.revokeObjectURL(d),l(null)},setTimeout(()=>{URL.revokeObjectURL(d),l(null)},5e3),c.src=d})}async function st(e){let t=e||document.documentElement,s=t.getBoundingClientRect(),o=document.createElement("canvas");o.width=400,o.height=300;let a=o.getContext("2d");return a?(a.fillStyle="#1a1a2e",a.fillRect(0,0,400,300),a.fillStyle="#e0e0e0",a.font="14px system-ui",a.fillText(`Element: <${t.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: ${(t.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),o.toDataURL("image/png")):null}function Oe(e,t,s){if(t>s)return null;try{let o=e.cloneNode(!1);if(o.tagName==="SCRIPT"||o.tagName==="STYLE"||o.tagName==="SVG"||o.tagName==="CANVAS"||o.tagName==="VIDEO"||o.tagName==="IFRAME")return null;let a=window.getComputedStyle(e),r=["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"],i="";for(let d of r){let l=a.getPropertyValue(d);l&&l!=="normal"&&l!=="none"&&l!=="auto"&&l!=="0px"&&(i+=`${d}:${l};`)}o.setAttribute("style",i);for(let d=0;d<e.children.length&&d<20;d++){let l=Oe(e.children[d],t+1,s);l&&o.appendChild(l)}return o}catch{return null}}var Q=[];var ze=!1;function qe(){if(ze)return;ze=!0;let e=window.fetch;window.fetch=async function(...o){let a=new Request(...o),r={method:a.method,url:a.url,timestamp:Date.now()};try{let i=await e.apply(this,o);return r.status=i.status,r.duration=Date.now()-r.timestamp,ge(r),i}catch(i){throw r.status=0,r.duration=Date.now()-r.timestamp,ge(r),i}};let t=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,a,...r){return this.__om_method=o,this.__om_url=a,this.__om_start=Date.now(),t.apply(this,[o,a,...r])},XMLHttpRequest.prototype.send=function(...o){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,o)}}function ge(e){e.url.includes("__openmagic__")||(Q.push(e),Q.length>50&&Q.shift())}function he(){return[...Q]}var ee=[],at=100,De=!1;function Ie(){if(De)return;De=!0;let e=["log","warn","error","info","debug"];for(let t of e){let s=console[t];console[t]=function(...o){ee.push({level:t,args:o.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,o)}}}function fe(){return[...ee]}function Be(e,t){return{selectedElement:e?{tagName:e.tagName,id:e.id,className:e.className,textContent:e.textContent,outerHTML:e.outerHTML,cssSelector:e.cssSelector,computedStyles:e.computedStyles}:void 0,screenshot:t||void 0,networkLogs: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 t=new TextEncoder().encode(e),s="";for(let o=0;o<t.length;o+=32768)s+=String.fromCharCode(...t.subarray(o,o+32768));return btoa(s)}function xe(e){let t=atob(e),s=new Uint8Array(t.length);for(let o=0;o<t.length;o++)s[o]=t.charCodeAt(o);return new TextDecoder().decode(s)}var Fe="0.28.2",n={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,D,Ue,Se,N;function rt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function it(){try{let e=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");e.messages?.length&&(n.messages=e.messages),e.provider&&(n.provider=e.provider),e.model&&(n.model=e.model),e.panelOpen&&(n.panelOpen=e.panelOpen,n.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 t=document.createElement("style");t.textContent=$e,k.appendChild(t);let s=document.createElement("div");k.appendChild(s),s.innerHTML=lt(),w=s.querySelector(".om-toolbar"),D=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 i=JSON.parse(localStorage.getItem("__om_pos__")||"");i?.left&&i?.top&&(w.style.left=i.left,w.style.top=i.top,w.style.right="auto",w.style.bottom="auto")}catch{}qe(),Ie(),Et();let a=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,r=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);a&&ue(r,a).then(()=>(n.connected=!0,ve(),v("config.get"))).then(i=>{let d=i.payload?.provider||"",l=i.payload?.model||"";n.provider=n.provider||d,n.model=n.model||l,n.configuredProviders=i.payload?.apiKeys||{},n.hasApiKey=n.configuredProviders[n.provider]||!1,n.roots=i.payload?.roots||[],n.panelOpen&&n.activePanel?R(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&R("settings"),J()}).catch(()=>{n.connected=!1,ve()})}function lt(){return`
|
|
383
383
|
<div class="om-toolbar">
|
|
384
384
|
<div class="om-toolbar-header">
|
|
385
|
-
<span class="om-grab">${
|
|
385
|
+
<span class="om-grab">${f.grip}</span>
|
|
386
386
|
<span class="om-pill-brand">
|
|
387
|
-
<span class="om-pill-icon">${
|
|
387
|
+
<span class="om-pill-icon">${f.sparkle}</span>
|
|
388
388
|
<span class="om-pill-text">OpenMagic</span>
|
|
389
389
|
</span>
|
|
390
390
|
<span class="om-pill-divider"></span>
|
|
391
|
-
<button class="om-pill-btn" data-action="select" title="Select element">${
|
|
392
|
-
<button class="om-pill-btn" data-action="screenshot" title="Screenshot">${
|
|
393
|
-
<button class="om-pill-btn" data-action="network" title="Network & Performance">${
|
|
391
|
+
<button class="om-pill-btn" data-action="select" title="Select element">${f.crosshair}</button>
|
|
392
|
+
<button class="om-pill-btn" data-action="screenshot" title="Screenshot">${f.camera}</button>
|
|
393
|
+
<button class="om-pill-btn" data-action="network" title="Network & Performance">${f.activity}</button>
|
|
394
394
|
<span class="om-pill-divider"></span>
|
|
395
|
-
<button class="om-pill-btn" data-action="chat" title="Chat">${
|
|
396
|
-
<button class="om-pill-btn" data-action="settings" title="Settings">${
|
|
397
|
-
<button class="om-pill-btn" data-action="minimize" title="Minimize">${
|
|
395
|
+
<button class="om-pill-btn" data-action="chat" title="Chat">${f.chat}</button>
|
|
396
|
+
<button class="om-pill-btn" data-action="settings" title="Settings">${f.settings}</button>
|
|
397
|
+
<button class="om-pill-btn" data-action="minimize" title="Minimize">${f.minus}</button>
|
|
398
398
|
<span class="om-status-dot disconnected"></span>
|
|
399
399
|
</div>
|
|
400
400
|
<div class="om-panel om-hidden">
|
|
401
401
|
<div class="om-panel-header">
|
|
402
402
|
<span class="om-panel-title"></span>
|
|
403
|
-
<span class="om-panel-version">v${
|
|
404
|
-
<button class="om-panel-clear" data-action="clear-chat" title="Clear chat">${
|
|
405
|
-
<button class="om-panel-close" data-action="close-panel">${
|
|
403
|
+
<span class="om-panel-version">v${Fe}</span>
|
|
404
|
+
<button class="om-panel-clear" data-action="clear-chat" title="Clear chat">${f.trash}</button>
|
|
405
|
+
<button class="om-panel-close" data-action="close-panel">${f.x}</button>
|
|
406
406
|
</div>
|
|
407
407
|
<div class="om-panel-body"></div>
|
|
408
408
|
</div>
|
|
409
409
|
<div class="om-prompt-attachments"></div>
|
|
410
410
|
<div class="om-prompt-row">
|
|
411
411
|
<div class="om-prompt-context"></div>
|
|
412
|
-
<button class="om-prompt-attach" data-action="attach-image" title="Attach image">${
|
|
412
|
+
<button class="om-prompt-attach" data-action="attach-image" title="Attach image">${f.paperclip}</button>
|
|
413
413
|
<input class="om-prompt-input" type="text" placeholder="Describe what to change..." autocomplete="off" />
|
|
414
|
-
<button class="om-prompt-send" data-action="prompt-send">${
|
|
414
|
+
<button class="om-prompt-send" data-action="prompt-send">${f.send}</button>
|
|
415
415
|
<input type="file" class="om-file-input om-hidden" accept="image/*" multiple />
|
|
416
416
|
</div>
|
|
417
|
-
</div>`}function
|
|
417
|
+
</div>`}function ct(e){e.addEventListener("click",o=>{let a=o.target.closest("[data-action]");if(!a)return;o.preventDefault(),o.stopPropagation();let r=a.dataset.action;gt(r,a)}),e.addEventListener("change",o=>{let a=o.target,r=a.dataset.field;r&&(r==="provider"?(n.provider=a.value,n.model=F[n.provider]?.models[0]?.id||"",n.hasApiKey=n.configuredProviders[n.provider]||F[n.provider]?.local||!1,n.saveStatus="",S()):r==="model"&&(n.model=a.value))}),D.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),we())});let t=e.querySelector(".om-file-input");t&&t.addEventListener("change",()=>{be(t.files),t.value=""});let s=e.querySelector(".om-prompt-row");s&&(s.addEventListener("dragover",o=>{o.preventDefault(),s.style.borderColor="rgba(108, 92, 231, 0.5)"}),s.addEventListener("dragleave",()=>{s.style.borderColor=""}),s.addEventListener("drop",o=>{o.preventDefault(),s.style.borderColor="";let a=o.dataTransfer;a?.files?.length&&be(a.files)}),D.addEventListener("paste",o=>{let a=o.clipboardData?.items;if(a){for(let r=0;r<a.length;r++)if(a[r].type.startsWith("image/")){let i=a[r].getAsFile();if(i){let d=new DataTransfer;d.items.add(i),be(d.files)}}}})),Ce(o=>{o.type==="reconnected"&&(n.connected=!0,ve())}),document.addEventListener("keydown",o=>{if((o.ctrlKey||o.metaKey)&&o.shiftKey&&(o.key==="O"||o.key==="o")){if(o.preventDefault(),n.minimized){n.minimized=!1,w.querySelectorAll(".om-pill-btn:not([data-action='minimize']), .om-pill-divider, .om-status-dot").forEach(i=>i.style.display="");let r=k.querySelector(".om-prompt-row");r&&r.classList.remove("om-hidden")}else n.panelOpen?oe():R("chat");return}if(o.key==="Escape"){if(n.selecting)return;n.panelOpen&&(oe(),o.preventDefault())}}),D.addEventListener("keydown",o=>{(o.ctrlKey||o.metaKey)&&o.key==="Enter"&&(o.preventDefault(),we())})}function Ke(e){return n.roots.length>0?n.roots[0]+"/"+e:e}function dt(e,t){let s=t.split(`
|
|
418
418
|
`).map(i=>i.trim()).filter(i=>i.length>0);if(s.length===0)return null;let o=e.split(`
|
|
419
|
-
`),a=s[0],r=s[s.length-1];for(let i=0;i<o.length;i++){if(o[i].trim()!==a||i+s.length>o.length)continue;let
|
|
420
|
-
`&&
|
|
419
|
+
`),a=s[0],r=s[s.length-1];for(let i=0;i<o.length;i++){if(o[i].trim()!==a||i+s.length>o.length)continue;let d=!0;for(let l=0;l<s.length;l++)if(o[i+l].trim()!==s[l]){d=!1;break}if(d){let l=0;for(let p=0;p<i;p++)l+=o[p].length+1;let c=l;for(let p=i;p<i+s.length;p++)c+=o[p].length+1;return c>0&&c<=e.length&&e[c-1]===`
|
|
420
|
+
`&&c--,{start:l,end:c}}}return null}async function pt(e){let t=e.dataset.file,s=e.dataset.search,o=e.dataset.replace;if(!t||!s||!o)return;let a,r;try{a=xe(s),r=xe(o)}catch{n.messages.push({role:"system",content:`Failed to decode diff data for ${t}`}),S();return}let i=e.closest(".om-diff-card"),d=Ke(t);if(i){let l=i.querySelector(".om-diff-actions");l&&(l.innerHTML='<span class="om-spinner"></span> Applying...')}try{if(!a&&r){if((await v("fs.write",{path:d,content:r}))?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${t}`});else{let u=i?.dataset.diffIdx;u!==void 0?n.messages[parseInt(u)]={role:"system",content:`Created ${t}`}:n.messages.push({role:"system",content:`Created ${t}`})}S(),B();return}let c=(await v("fs.read",{path:d}))?.payload?.content;if(!c)n.messages.push({role:"system",content:`Could not read ${t} \u2014 file may not exist at ${d}`});else{let p=c.split(a).length-1;if(p===1){let u=await v("fs.write",{path:d,content:c.replace(a,r)});if(u?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${t} - ${u.payload?.error||"unknown"}`});else{let m=i?.dataset.diffIdx;m!==void 0?n.messages[parseInt(m)]={role:"system",content:`Applied change to ${t}`}:n.messages.push({role:"system",content:`Applied change to ${t}`})}}else if(p>1)n.messages.push({role:"system",content:`Found ${p} exact matches in ${t} \u2014 expected 1. Edit not applied.`});else{let u=dt(c,a);if(u){let m=c.slice(0,u.start)+r+c.slice(u.end),h=await v("fs.write",{path:d,content:m});if(h?.payload?.ok===!1)n.messages.push({role:"system",content:`Write failed: ${t} - ${h.payload?.error||"unknown"}`});else{let x=i?.dataset.diffIdx;x!==void 0?n.messages[parseInt(x)]={role:"system",content:`Applied change to ${t} (fuzzy match \u2014 whitespace adjusted)`}:n.messages.push({role:"system",content:`Applied change to ${t} (fuzzy match)`})}}else n.messages.push({role:"system",content:`No matching code found in ${t}. The file may have changed since the suggestion.`})}}}catch(l){n.messages.push({role:"system",content:`Failed to apply: ${t} \u2014 ${l.message}`})}S(),B()}function mt(e){let t=e.dataset.idx;if(t!==void 0){let s=parseInt(t),a=n.messages[s]?.content.split("__")?.[3]||"file";n.messages[s]={role:"system",content:`Rejected change to ${a}`}}S(),B()}async function ut(e){let t=e.dataset.file;if(!t)return;let s=Ke(t),o=s+".openmagic-backup";try{let r=(await v("fs.read",{path:o}))?.payload?.content;r?(await v("fs.write",{path:s,content:r}),n.messages.push({role:"system",content:`Reverted change to ${t}`})):n.messages.push({role:"system",content:`No backup found for ${t}`})}catch{n.messages.push({role:"system",content:`Could not revert ${t} \u2014 backup may not exist`})}S()}function gt(e,t){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=t.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"),t.style.display="none";break}case"network":ye("chat"),bt();break;case"attach-image":xt();break;case"remove-attachment":{let s=parseInt(t.dataset.idx||"0",10);n.attachments.splice(s,1),Ee();break}case"apply-diff":pt(t);break;case"reject-diff":mt(t);break;case"undo-diff":ut(t);break;case"clear-chat":{n.messages=[];try{sessionStorage.removeItem("__om_state__")}catch{}S();break}case"copy-msg":{let s=parseInt(t.dataset.idx||"0",10),o=n.messages[s];if(o){try{navigator.clipboard.writeText(o.content)}catch{}t.innerHTML=f.check,setTimeout(()=>{t.innerHTML=f.copy},1500)}break}case"clear-element":n.selectedElement=null,X();break;case"clear-screenshot":n.screenshot=null,X();break;case"minimize":{n.minimized=!n.minimized;let s=k.querySelector(".om-panel"),o=k.querySelector(".om-prompt-row"),a=k.querySelector(".om-prompt-attachments"),r=w.querySelectorAll(".om-pill-btn:not([data-action='minimize']), .om-pill-divider, .om-status-dot");n.minimized?(s&&s.classList.add("om-hidden"),o&&o.classList.add("om-hidden"),a&&a.classList.add("om-hidden"),r.forEach(i=>i.style.display="none")):(o&&o.classList.remove("om-hidden"),a&&a.classList.remove("om-hidden"),r.forEach(i=>i.style.display=""),n.panelOpen&&n.activePanel&&s&&s.classList.remove("om-hidden"));break}}}function ve(){let e=k.querySelector(".om-status-dot");e&&(e.className=`om-status-dot ${n.connected?"connected":"disconnected"}`)}function J(){k.querySelectorAll(".om-pill-btn").forEach(e=>{let t=e.dataset.action;e.classList.toggle("active",t===n.activePanel||t==="select"&&n.selecting)})}function X(){let e=[];n.selectedElement&&e.push(`<span class="om-prompt-chip">${n.selectedElement.tagName}${n.selectedElement.id?"#"+n.selectedElement.id:""} <button class="om-prompt-chip-x" data-action="clear-element">${f.x}</button></span>`),n.screenshot&&e.push(`<span class="om-prompt-chip">Screenshot <button class="om-prompt-chip-x" data-action="clear-screenshot">${f.x}</button></span>`),n.attachments.length&&e.push(`<span class="om-prompt-chip">${n.attachments.length} image${n.attachments.length>1?"s":""}</span>`),n.groundedFiles.length&&e.push(`<span class="om-prompt-chip">${n.groundedFiles.length} files grounded</span>`),Ue.innerHTML=e.join("")}function R(e){n.panelOpen=!0,n.activePanel=e,Se.classList.remove("om-hidden");let t=k.querySelector(".om-panel-title");t&&(t.textContent=e==="settings"?"Settings":"Chat"),S(),J()}function oe(){n.panelOpen=!1,n.activePanel="",Se.classList.add("om-hidden"),J()}function ye(e){n.panelOpen&&n.activePanel===e?oe():R(e)}function S(){n.activePanel==="settings"?N.innerHTML=ht():n.activePanel==="chat"&&(N.innerHTML=ft(),B()),rt()}function ht(){let e=Object.entries(F).map(([h,x])=>{let b=n.configuredProviders[h]||x.local?" \u2713":"";return`<option value="${h}" ${n.provider===h?"selected":""}>${x.name}${b}</option>`}).join(""),t=F[n.provider],s=t?t.models.map(h=>`<option value="${h.id}" ${n.model===h.id?"selected":""}>${h.name}</option>`).join(""):'<option value="">Select provider first</option>',o=t?.local||!1,a=t?.keyUrl||"",r=t?.keyPlaceholder||"Enter API key...",i=n.configuredProviders[n.provider]||!1,d=n.updateAvailable?`<div class="om-update-banner">v${n.latestVersion} available <code class="om-update-cmd">npx openmagic@latest</code></div>`:"",l=i||o?`<div class="om-status om-status-success">${f.check} ${t?.name||"Provider"} connected</div>`:"",c=n.saveStatus==="saving"?'<span class="om-spinner"></span> Saving...':n.saveStatus==="saved"?`${f.check} Saved`:"Save",p=n.saveStatus==="saving"?"om-btn om-btn-saving":n.saveStatus==="saved"?"om-btn om-btn-saved":"om-btn",u=n.saveStatus==="saving"?"disabled":"",m="";return!o&&n.provider&&(i?m=`
|
|
421
421
|
<div class="om-field">
|
|
422
422
|
<label class="om-label">API Key</label>
|
|
423
423
|
<div class="om-key-configured">
|
|
424
|
-
${
|
|
424
|
+
${f.check} <span>Key configured</span>
|
|
425
425
|
<button class="om-btn-change-key" data-action="change-key">Change</button>
|
|
426
426
|
</div>
|
|
427
427
|
<div class="om-key-change-row om-hidden" data-key-change>
|
|
428
428
|
<div class="om-key-row">
|
|
429
429
|
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${r}" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
|
430
|
-
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${
|
|
430
|
+
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${f.externalLink} Get key</button>`:""}
|
|
431
431
|
</div>
|
|
432
432
|
</div>
|
|
433
|
-
</div>`:
|
|
433
|
+
</div>`:m=`
|
|
434
434
|
<div class="om-field">
|
|
435
435
|
<label class="om-label">API Key</label>
|
|
436
436
|
<div class="om-key-row">
|
|
437
437
|
<input type="text" class="om-input om-key-input" data-field="apiKey" placeholder="${r}" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
|
438
|
-
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${
|
|
438
|
+
${a?`<button class="om-btn-get-key" data-action="get-key" data-url="${a}">${f.externalLink} Get key</button>`:""}
|
|
439
439
|
</div>
|
|
440
440
|
${a?`<div class="om-key-hint"><a data-action="get-key" data-url="${a}">Get your ${t?.name||""} API key here</a></div>`:""}
|
|
441
441
|
</div>`),`
|
|
442
|
-
${
|
|
442
|
+
${d}
|
|
443
443
|
<div class="om-settings">
|
|
444
444
|
<div class="om-field">
|
|
445
445
|
<label class="om-label">Provider</label>
|
|
@@ -449,26 +449,26 @@
|
|
|
449
449
|
<label class="om-label">Model</label>
|
|
450
450
|
<select class="om-select" data-field="model"><option value="">Select Model...</option>${s}</select>
|
|
451
451
|
</div>
|
|
452
|
-
${
|
|
453
|
-
<button class="${p}" data-action="save-settings" ${
|
|
452
|
+
${m}
|
|
453
|
+
<button class="${p}" data-action="save-settings" ${u}>${c}</button>
|
|
454
454
|
${l}
|
|
455
|
-
</div>`}function
|
|
456
|
-
<div class="om-diff-file">${H(
|
|
455
|
+
</div>`}function ft(){if(!n.provider||!n.hasApiKey&&!F[n.provider]?.local)return'<div class="om-status om-status-error">Configure your provider in Settings first</div>';let e=n.messages.map((o,a)=>{if(o.content.startsWith("__DIFF__"))try{let i=JSON.parse(xe(o.content.slice(8))),d=i.type==="create"||!i.search&&i.replace,l=ne(i.search||""),c=ne(i.replace||"");return`<div class="om-diff-card" data-diff-idx="${a}">
|
|
456
|
+
<div class="om-diff-file">${H(d?"Create new file":"Edit")}: ${H(i.file)}</div>
|
|
457
457
|
${i.search?`<div class="om-diff-removed">${H(i.search.slice(0,200))}</div>`:""}
|
|
458
458
|
<div class="om-diff-added">${H((i.replace||"").slice(0,300))}</div>
|
|
459
459
|
<div class="om-diff-actions">
|
|
460
|
-
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${H(i.file)}" data-search="${l}" data-replace="${
|
|
460
|
+
<button class="om-btn om-btn-sm" data-action="apply-diff" data-file="${H(i.file)}" data-search="${l}" data-replace="${c}">Apply</button>
|
|
461
461
|
<button class="om-btn-secondary om-btn-sm" data-action="reject-diff" data-idx="${a}">Reject</button>
|
|
462
462
|
</div>
|
|
463
|
-
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(o.content.startsWith("Applied change to ")){let i=o.content.replace("Applied change to ","").replace(" (fuzzy match \u2014 whitespace adjusted)","").replace(" (fuzzy match)","");return`<div class="om-msg om-msg-system">${H(o.content)} <button class="om-undo-btn" data-action="undo-diff" data-file="${H(i)}">Undo</button></div>`}let r=o.role==="user"||o.role==="assistant"?`<button class="om-copy-btn" data-action="copy-msg" data-idx="${a}" title="Copy">${
|
|
464
|
-
// [FILE TRUNCATED \u2014 showing ${U} of ${q.length} chars]`),b.push({path:
|
|
465
|
-
// [FILE TRUNCATED \u2014 showing ${Y} of ${T.length} chars]`),b.push({path:
|
|
466
|
-
// [FILE TRUNCATED \u2014 showing ${ie} of ${Z.length} chars]`),b.push({path:T,content:le}),
|
|
467
|
-
Recent requests (${a.length}):`);for(let l of a.slice(-15))i.push(` ${l.method} ${l.url.slice(0,80)} \u2192 ${l.status||"pending"} (${l.duration||"?"}ms)`)}if(r.length){let l=r.filter(p=>p.level==="error"),
|
|
468
|
-
Console errors: ${l.length}`),
|
|
469
|
-
Slowest resources:`);for(let
|
|
470
|
-
`)}),
|
|
463
|
+
</div>`}catch{return'<div class="om-msg om-msg-system">Malformed diff data</div>'}if(o.content.startsWith("Applied change to ")){let i=o.content.replace("Applied change to ","").replace(" (fuzzy match \u2014 whitespace adjusted)","").replace(" (fuzzy match)","");return`<div class="om-msg om-msg-system">${H(o.content)} <button class="om-undo-btn" data-action="undo-diff" data-file="${H(i)}">Undo</button></div>`}let r=o.role==="user"||o.role==="assistant"?`<button class="om-copy-btn" data-action="copy-msg" data-idx="${a}" title="Copy">${f.copy}</button>`:"";return o.role==="assistant"?`<div class="om-msg om-msg-assistant">${St(o.content)}${r}</div>`:`<div class="om-msg om-msg-${o.role}">${H(o.content)}${r}</div>`}).join(""),t=n.streaming?`<div class="om-msg om-msg-assistant"><span class="om-spinner"></span>${H(n.streamContent)}</div>`:"";return`<div class="om-chat-messages">${!n.messages.length&&!n.streaming?'<div class="om-chat-empty">Select an element or type below to start</div>':""}${e}${t}</div>`}function B(){requestAnimationFrame(()=>{let e=N.querySelector(".om-chat-messages");e&&(e.scrollTop=e.scrollHeight)})}async function yt(){let t=N.querySelector('[data-field="apiKey"]')?.value||"";if(!n.provider){n.saveStatus="error",te(),setTimeout(()=>{n.saveStatus="",S()},2e3);return}if(!He()){n.saveStatus="error",te();let o=N.querySelector('[data-action="save-settings"]');o&&(o.innerHTML="Not connected - check terminal"),setTimeout(()=>{n.saveStatus="",S()},3e3);return}let s={provider:n.provider,model:n.model};t&&(s.apiKey=t),n.saveStatus="saving",te();try{let o=await Promise.race([v("config.set",s),new Promise((a,r)=>setTimeout(()=>r(new Error("Save timed out")),8e3))]);t&&n.provider&&(n.configuredProviders[n.provider]=!0),n.hasApiKey=!!(t||n.configuredProviders[n.provider]),n.saveStatus="saved",te(),setTimeout(()=>{n.saveStatus="",n.activePanel==="settings"&&R("chat")},1200)}catch(o){n.saveStatus="error";let a=N.querySelector('[data-action="save-settings"]'),r=(o?.message||"").includes("timeout")?"Connection timeout - is the CLI running?":(o?.message||"").includes("connected")?"Not connected to OpenMagic server":`Save failed: ${o?.message||"Unknown error"}`;a&&(a.innerHTML=r,a.className="om-btn",a.disabled=!1),setTimeout(()=>{n.saveStatus="",S()},4e3)}}function te(){let e=N.querySelector('[data-action="save-settings"]');e&&(n.saveStatus==="saving"?(e.innerHTML='<span class="om-spinner"></span> Saving...',e.className="om-btn om-btn-saving",e.disabled=!0):n.saveStatus==="saved"?(e.innerHTML=`${f.check} Saved`,e.className="om-btn om-btn-saved",e.disabled=!1):n.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=D.value.trim();if(!e||n.streaming)return;if(!n.provider||!n.hasApiKey&&!F[n.provider]?.local){R("settings");return}n.messages.push({role:"user",content:e}),n.streaming=!0,n.streamContent="",D.value="",R("chat");let t=Be(n.selectedElement,n.screenshot);t.pageUrl=window.location.href,t.pageTitle=document.title,n.attachments.length>0&&(t.screenshot||(t.screenshot=n.attachments[0]),t.attachments=[...n.attachments]);let s=5,o=32e3,a=/\.(?:[cm]?[jt]sx?|svelte|vue|astro|html?|css|scss|less|php|py)$/i,r=N.querySelector(".om-msg-assistant:last-child");r&&(r.innerHTML='<span class="om-spinner"></span> Reading project files...');try{let l=await v("fs.list",{});l?.payload?.projectTree&&(t.projectTree=l.payload.projectTree);let p=(l?.payload?.files||[]).filter(g=>g.type==="file"&&a.test(g.path)),u=[e];if(n.selectedElement&&(n.selectedElement.id&&u.push(n.selectedElement.id),n.selectedElement.className&&u.push(n.selectedElement.className),n.selectedElement.textContent&&u.push(n.selectedElement.textContent.slice(0,100)),n.selectedElement.componentHint&&u.push(n.selectedElement.componentHint),n.selectedElement.ancestry))for(let g of n.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=p.map(g=>{let y=0,M=g.path.toLowerCase();for(let _ of x)M.includes(_.toLowerCase())&&(y+=15);if(n.selectedElement?.componentHint){let _=n.selectedElement.componentHint.toLowerCase();M.includes(_)&&(y+=12)}for(let _ of m)M.includes(_)&&(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,P=0;for(let g of A.slice(0,s)){if(g.score<=0||P>=o)break;try{let y=n.roots[0]||"",M=y?`${y}/${g.path}`:g.path,_=await v("fs.read",{path:M}),q=String(_?.payload?.content||"");if(!q)continue;let U=Math.min(8e3,o-P),ae=q.slice(0,U);q.length>U&&(ae+=`
|
|
464
|
+
// [FILE TRUNCATED \u2014 showing ${U} of ${q.length} chars]`),b.push({path:g.path,content:ae}),O.add(g.path),P+=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)||P>=o)continue;if(p.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,o-P),I=T.slice(0,Y);T.length>Y&&(I+=`
|
|
465
|
+
// [FILE TRUNCATED \u2014 showing ${Y} of ${T.length} chars]`),b.push({path:E,content:I}),O.add(E),P+=I.length}}catch{}break}}let Ve=q.matchAll(/(?:import|from)\s+['"]\.?\.\/([\w/.-]+)['"]/g);for(let re of Ve){if(P>=o)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(p.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,o-P),le=Z.slice(0,ie);Z.length>ie&&(le+=`
|
|
466
|
+
// [FILE TRUNCATED \u2014 showing ${ie} of ${Z.length} chars]`),b.push({path:T,content:le}),O.add(T),P+=le.length}}catch{}break}}}}catch{}}if(P<o)try{let g=n.roots[0]||"",y=await v("fs.read",{path:g?`${g}/package.json`:"package.json"}),M=String(y?.payload?.content||"");if(M)try{let _=JSON.parse(M),q={..._.dependencies,..._.devDependencies},U=JSON.stringify(q,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){t.files=b;let g=b.map(y=>y.path.split("/").pop()).join(", ");r&&(r.innerHTML=`<span class="om-spinner"></span> Thinking... (${b.length} files: ${g})`)}n.groundedFiles=b.map(g=>g.path)}catch{}let i=4,d=0;try{for(;d<=i;){n.streamContent="";let l=await Te("llm.chat",{provider:n.provider,model:n.model,messages:n.messages.map(m=>({role:m.role,content:m.content})),context:t},m=>{n.streamContent+=m;let h=N.querySelector(".om-msg-assistant:last-child");h&&(h.innerHTML=`<span class="om-spinner"></span>${H(n.streamContent)}`,B())}),c=n.streamContent||l?.content||"",p=c.match(/NEED_FILE:\s*"?([^\s"}\]]+)"?/)||c.match(/(?:need|provide|show|read|see|contents?\s+of)\s+(?:the\s+)?(?:file\s+)?[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i)||c.match(/(?:source\s+(?:file|code)\s+(?:for|of|at))\s+[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i);if(p&&!l?.modifications?.length&&d<i){let m=p[1].trim();d++,n.messages.push({role:"system",content:`Reading ${m}...`}),S();try{let h=n.roots[0]||"",x=h?`${h}/${m}`:m,A=await v("fs.read",{path:x}),b=String(A?.payload?.content||"");if(b)t.files||(t.files=[]),t.files.push({path:m,content:b.slice(0,8e3)}),n.messages.push({role:"assistant",content:c}),n.messages.push({role:"user",content:`Here is ${m}. Now please make the edit.`});else{n.messages.push({role:"system",content:`Could not read ${m}`});break}}catch{n.messages.push({role:"system",content:`File not found: ${m}`});break}continue}let u=c;try{let m=JSON.parse(c);m.explanation&&(u=m.explanation)}catch{let m=c.match(/```(?:json)?\s*([\s\S]*?)```/);if(m)try{let h=JSON.parse(m[1]);h.explanation&&(u=h.explanation)}catch{}}if(n.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});n.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"});n.messages.push({role:"system",content:`__DIFF__${ne(x)}`})}else m.type==="delete"&&m.file&&n.messages.push({role:"system",content:`LLM proposed deleting ${m.file} \u2014 skipped (use edit with search/replace instead)`});break}}catch(l){n.messages.push({role:"system",content:`Error: ${l.message}`})}n.streaming=!1,n.streamContent="",n.attachments=[],Ee(),S(),B()}function bt(){let e=window.performance,t=e.getEntriesByType("navigation")[0],s=e.getEntriesByType("paint"),o=e.getEntriesByType("resource").slice(-20),a=he(),r=fe(),i=[];i.push("--- Network & Performance Capture ---"),t&&(i.push(`Page load: ${Math.round(t.loadEventEnd-t.startTime)}ms`),i.push(`DOM ready: ${Math.round(t.domContentLoadedEventEnd-t.startTime)}ms`),i.push(`TTFB: ${Math.round(t.responseStart-t.startTime)}ms`));let d=s.find(l=>l.name==="first-contentful-paint");if(d&&i.push(`FCP: ${Math.round(d.startTime)}ms`),a.length){i.push(`
|
|
467
|
+
Recent requests (${a.length}):`);for(let l of a.slice(-15))i.push(` ${l.method} ${l.url.slice(0,80)} \u2192 ${l.status||"pending"} (${l.duration||"?"}ms)`)}if(r.length){let l=r.filter(p=>p.level==="error"),c=r.filter(p=>p.level==="warn");l.length&&i.push(`
|
|
468
|
+
Console errors: ${l.length}`),c.length&&i.push(`Console warnings: ${c.length}`)}if(o.length){let l=[...o].sort((c,p)=>p.duration-c.duration).slice(0,5);i.push(`
|
|
469
|
+
Slowest resources:`);for(let c of l)i.push(` ${Math.round(c.duration)}ms \u2014 ${c.name.split("/").pop()?.slice(0,50)}`)}n.messages.push({role:"system",content:i.join(`
|
|
470
|
+
`)}),S(),B(),X()}function xt(){let e=k.querySelector(".om-file-input");e&&e.click()}function be(e){if(e)for(let t=0;t<e.length&&n.attachments.length<5;t++){let s=e[t];if(!s.type.startsWith("image/")||s.size>10*1024*1024)continue;let o=new FileReader;o.onload=()=>{typeof o.result=="string"&&(n.attachments.push(o.result),Ee())},o.readAsDataURL(s)}}function Ee(){let e=k.querySelector(".om-prompt-attachments");if(e){if(!n.attachments.length){e.innerHTML="",e.classList.add("om-hidden");return}e.classList.remove("om-hidden"),e.innerHTML=n.attachments.map((t,s)=>`<div class="om-attachment-thumb">
|
|
471
471
|
<img src="${t}" alt="attachment" />
|
|
472
|
-
<button class="om-attachment-remove" data-action="remove-attachment" data-idx="${s}">${
|
|
473
|
-
</div>`).join("")}}var W=null,V=null;function
|
|
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(){n.selecting?ke():se()}function se(){n.selecting=!0,document.body.style.cursor="crosshair",J(),V=t=>{let s=t.target;if(s.closest("openmagic-toolbar")||s.dataset?.openmagic)return;let o=s.getBoundingClientRect();Ne({x:o.x,y:o.y,width:o.width,height:o.height})},W=t=>{t.preventDefault(),t.stopPropagation();let s=t.target;s.closest("openmagic-toolbar")||s.dataset?.openmagic||(n.selectedElement=_e(s),ke(),X(),D.focus())};let e=t=>{t.key==="Escape"&&ke()};document.addEventListener("mousemove",V,!0),document.addEventListener("click",W,!0),document.addEventListener("keydown",e,!0),se._escHandler=e}function ke(){n.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 s=n.selectedElement?.cssSelector?.trim();s&&(e=document.querySelector(s)||void 0)}catch{}let t=await Ae(e||void 0);t.data?(n.screenshot=t.data,X(),D.focus()):t.error&&(n.messages.push({role:"system",content:t.error}),R("chat"),S())}function kt(){let e=!1,t=0,s=0,o=0,a=0;w.addEventListener("mousedown",r=>{let i=r.target;if(i.closest("[data-action]")||!i.closest(".om-grab")&&!i.closest(".om-pill-brand"))return;e=!0,t=r.clientX,s=r.clientY;let d=w.getBoundingClientRect();o=d.left,a=d.top,r.preventDefault()}),document.addEventListener("mousemove",r=>{e&&(w.style.left=o+r.clientX-t+"px",w.style.top=a+r.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 H(e){let t=document.createElement("div");return t.textContent=e,t.innerHTML}function St(e){let t=H(e);return t=t.replace(/```(\w*)\n([\s\S]*?)```/g,'<pre class="om-code-block"><code>$2</code></pre>'),t=t.replace(/`([^`]+)`/g,'<code class="om-inline-code">$1</code>'),t=t.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),t=t.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g,"<em>$1</em>"),t=t.replace(/\n/g,"<br>"),t}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 t=e.version.split(".").map(Number),s=Fe.split(".").map(Number);for(let o=0;o<3;o++){if((t[o]||0)>(s[o]||0)){n.updateAvailable=!0,n.latestVersion=e.version,$t();return}if((t[o]||0)<(s[o]||0))return}}).catch(()=>{})}function $t(){if(k.querySelector(".om-update-dot"))return;let t=document.createElement("span");t.className="om-update-dot",t.title=`v${n.latestVersion} available`,t.addEventListener("click",()=>R("settings"));let s=k.querySelector(".om-toolbar-header");s&&s.appendChild(t)}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",je):je());})();
|
|
474
474
|
//# sourceMappingURL=index.global.js.map
|