openmagic 0.33.1 → 0.33.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 +10 -3
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +2 -2
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
|
@@ -390,7 +390,7 @@
|
|
|
390
390
|
${r.outerHTML}
|
|
391
391
|
</div>
|
|
392
392
|
</foreignObject>
|
|
393
|
-
</svg>`,i=new Blob([l],{type:"image/svg+xml;charset=utf-8"}),d=URL.createObjectURL(i);return new Promise(c=>{let p=new Image,h=document.createElement("canvas"),x=Math.min(window.devicePixelRatio||1,2);h.width=s*x,h.height=o*x,p.onload=()=>{URL.revokeObjectURL(d);let w=h.getContext("2d");if(!w){c(null);return}w.scale(x,x),w.drawImage(p,0,0);try{c(h.toDataURL("image/png",.8))}catch{c(null)}},p.onerror=()=>{URL.revokeObjectURL(d),c(null)},setTimeout(()=>{URL.revokeObjectURL(d),c(null)},5e3),p.src=d})}async function dt(t){let e=t||document.documentElement,s=e.getBoundingClientRect(),o=document.createElement("canvas");o.width=400,o.height=300;let r=o.getContext("2d");return r?(r.fillStyle="#1a1a2e",r.fillRect(0,0,400,300),r.fillStyle="#e0e0e0",r.font="14px system-ui",r.fillText(`Element: <${e.tagName.toLowerCase()}>`,20,30),r.fillStyle="#888",r.font="12px system-ui",r.fillText(`Size: ${Math.round(s.width)}x${Math.round(s.height)}`,20,55),r.fillText(`Classes: ${(e.className||"").toString().slice(0,40)}`,20,75),r.fillText(`Page: ${window.location.pathname}`,20,95),r.fillStyle="#6c5ce7",r.font="11px system-ui",r.fillText("(Full screenshot unavailable \u2014 context sent as metadata)",20,130),o.toDataURL("image/png")):null}function qe(t,e,s){if(e>s)return null;try{let o=t.cloneNode(!1);if(o.tagName==="SCRIPT"||o.tagName==="STYLE"||o.tagName==="SVG"||o.tagName==="CANVAS"||o.tagName==="VIDEO"||o.tagName==="IFRAME")return null;let r=window.getComputedStyle(t),l=["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 l){let c=r.getPropertyValue(d);c&&c!=="normal"&&c!=="none"&&c!=="auto"&&c!=="0px"&&(i+=`${d}:${c};`)}o.setAttribute("style",i);for(let d=0;d<t.children.length&&d<20;d++){let c=qe(t.children[d],e+1,s);c&&o.appendChild(c)}return o}catch{return null}}var ae=[];var je=!1;function Be(){if(je)return;je=!0;let t=window.fetch;window.fetch=async function(...o){let r=new Request(...o),l={method:r.method,url:r.url,timestamp:Date.now()};try{let i=await t.apply(this,o);return l.status=i.status,l.duration=Date.now()-l.timestamp,we(l),i}catch(i){throw l.status=0,l.duration=Date.now()-l.timestamp,we(l),i}};let e=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,r,...l){return this.__om_method=o,this.__om_url=r,this.__om_start=Date.now(),e.apply(this,[o,r,...l])},XMLHttpRequest.prototype.send=function(...o){return this.addEventListener("loadend",()=>{we({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 we(t){t.url.includes("__openmagic__")||(ae.push(t),ae.length>50&&ae.shift())}function ie(){return[...ae]}var re=[],pt=100,ze=!1;function Fe(){if(ze)return;ze=!0;let t=["log","warn","error","info","debug"];for(let e of t){let s=console[e];console[e]=function(...o){re.push({level:e,args:o.map(r=>{try{return typeof r=="object"?JSON.stringify(r).slice(0,500):String(r)}catch{return String(r)}}),timestamp:Date.now()}),re.length>pt&&re.shift(),s.apply(console,o)}}}function le(){return[...re]}function Ue(t,e){return{selectedElement:t?{tagName:t.tagName,id:t.id,className:t.className,textContent:t.textContent,outerHTML:t.outerHTML,cssSelector:t.cssSelector,computedStyles:t.computedStyles}:void 0,screenshot:e||void 0,networkLogs:ie().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:le().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var k={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>',bug:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m8 2 1.88 1.88M14.12 3.88 16 2M9 7.13v-1a3.003 3.003 0 1 1 6 0v1"/><path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6"/><path d="M12 20v-9"/><path d="M6.53 9C4.6 8.8 3 7.1 3 5"/><path d="M6 13H2"/><path d="M3 21c0-2.1 1.7-3.9 3.8-4"/><path d="M20.97 5c0 2.1-1.6 3.8-3.5 4"/><path d="M22 13h-4"/><path d="M17.2 17c2.1.1 3.8 1.9 3.8 4"/></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>'},B={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 de(t){let e=new TextEncoder().encode(t),s="";for(let o=0;o<e.length;o+=32768)s+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(s)}function X(t){let e=atob(t),s=new Uint8Array(e.length);for(let o=0;o<e.length;o++)s[o]=e.charCodeAt(o);return new TextDecoder().decode(s)}var Ee="0.33.1",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},E,C,z,Xe,Le,D;function mt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function ut(){try{let t=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");t.messages?.length&&(n.messages=t.messages),t.provider&&(n.provider=t.provider),t.model&&(n.model=t.model),t.panelOpen&&(n.panelOpen=t.panelOpen,n.activePanel=t.activePanel||"")}catch{}}function We(){if(document.querySelector("openmagic-toolbar"))return;ut();let t=document.createElement("openmagic-toolbar");t.dataset.openmagic="true",E=t.attachShadow({mode:"closed"});let e=document.createElement("style");e.textContent=Ce,E.appendChild(e);let s=document.createElement("div");E.appendChild(s),s.innerHTML=ht(),C=s.querySelector(".om-toolbar"),z=s.querySelector(".om-prompt-input"),Xe=s.querySelector(".om-prompt-context"),Le=s.querySelector(".om-panel"),D=s.querySelector(".om-panel-body"),document.body.appendChild(t),gt(s),Lt();try{let i=JSON.parse(localStorage.getItem("__om_pos__")||"");i?.left&&i?.top&&(C.style.left=i.left,C.style.top=i.top,C.style.right="auto",C.style.bottom="auto")}catch{}Be(),Fe(),Ct();let r=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,l=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);r&&xe(l,r).then(()=>(n.connected=!0,pe(),M("config.get"))).then(i=>{let d=i.payload?.provider||"",c=i.payload?.model||"";n.provider=n.provider||d,n.model=n.model||c,n.configuredProviders=i.payload?.apiKeys||{},n.hasApiKey=n.configuredProviders[n.provider]||!1,n.roots=i.payload?.roots||[],n.panelOpen&&n.activePanel?F(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&F("settings"),se()}).catch(()=>{n.connected=!1,pe()})}function ht(){return`
|
|
393
|
+
</svg>`,i=new Blob([l],{type:"image/svg+xml;charset=utf-8"}),d=URL.createObjectURL(i);return new Promise(c=>{let p=new Image,h=document.createElement("canvas"),x=Math.min(window.devicePixelRatio||1,2);h.width=s*x,h.height=o*x,p.onload=()=>{URL.revokeObjectURL(d);let w=h.getContext("2d");if(!w){c(null);return}w.scale(x,x),w.drawImage(p,0,0);try{c(h.toDataURL("image/png",.8))}catch{c(null)}},p.onerror=()=>{URL.revokeObjectURL(d),c(null)},setTimeout(()=>{URL.revokeObjectURL(d),c(null)},5e3),p.src=d})}async function dt(t){let e=t||document.documentElement,s=e.getBoundingClientRect(),o=document.createElement("canvas");o.width=400,o.height=300;let r=o.getContext("2d");return r?(r.fillStyle="#1a1a2e",r.fillRect(0,0,400,300),r.fillStyle="#e0e0e0",r.font="14px system-ui",r.fillText(`Element: <${e.tagName.toLowerCase()}>`,20,30),r.fillStyle="#888",r.font="12px system-ui",r.fillText(`Size: ${Math.round(s.width)}x${Math.round(s.height)}`,20,55),r.fillText(`Classes: ${(e.className||"").toString().slice(0,40)}`,20,75),r.fillText(`Page: ${window.location.pathname}`,20,95),r.fillStyle="#6c5ce7",r.font="11px system-ui",r.fillText("(Full screenshot unavailable \u2014 context sent as metadata)",20,130),o.toDataURL("image/png")):null}function qe(t,e,s){if(e>s)return null;try{let o=t.cloneNode(!1);if(o.tagName==="SCRIPT"||o.tagName==="STYLE"||o.tagName==="SVG"||o.tagName==="CANVAS"||o.tagName==="VIDEO"||o.tagName==="IFRAME")return null;let r=window.getComputedStyle(t),l=["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 l){let c=r.getPropertyValue(d);c&&c!=="normal"&&c!=="none"&&c!=="auto"&&c!=="0px"&&(i+=`${d}:${c};`)}o.setAttribute("style",i);for(let d=0;d<t.children.length&&d<20;d++){let c=qe(t.children[d],e+1,s);c&&o.appendChild(c)}return o}catch{return null}}var ae=[];var je=!1;function Be(){if(je)return;je=!0;let t=window.fetch;window.fetch=async function(...o){let r=new Request(...o),l={method:r.method,url:r.url,timestamp:Date.now()};try{let i=await t.apply(this,o);return l.status=i.status,l.duration=Date.now()-l.timestamp,we(l),i}catch(i){throw l.status=0,l.duration=Date.now()-l.timestamp,we(l),i}};let e=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(o,r,...l){return this.__om_method=o,this.__om_url=r,this.__om_start=Date.now(),e.apply(this,[o,r,...l])},XMLHttpRequest.prototype.send=function(...o){return this.addEventListener("loadend",()=>{we({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 we(t){t.url.includes("__openmagic__")||(ae.push(t),ae.length>50&&ae.shift())}function ie(){return[...ae]}var re=[],pt=100,ze=!1;function Fe(){if(ze)return;ze=!0;let t=["log","warn","error","info","debug"];for(let e of t){let s=console[e];console[e]=function(...o){re.push({level:e,args:o.map(r=>{try{return typeof r=="object"?JSON.stringify(r).slice(0,500):String(r)}catch{return String(r)}}),timestamp:Date.now()}),re.length>pt&&re.shift(),s.apply(console,o)}}}function le(){return[...re]}function Ue(t,e){return{selectedElement:t?{tagName:t.tagName,id:t.id,className:t.className,textContent:t.textContent,outerHTML:t.outerHTML,cssSelector:t.cssSelector,computedStyles:t.computedStyles}:void 0,screenshot:e||void 0,networkLogs:ie().map(s=>({method:s.method,url:s.url,status:s.status,duration:s.duration,timestamp:s.timestamp})),consoleLogs:le().map(s=>({level:s.level,args:s.args,timestamp:s.timestamp}))}}var k={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>',bug:'<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="m8 2 1.88 1.88M14.12 3.88 16 2M9 7.13v-1a3.003 3.003 0 1 1 6 0v1"/><path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6"/><path d="M12 20v-9"/><path d="M6.53 9C4.6 8.8 3 7.1 3 5"/><path d="M6 13H2"/><path d="M3 21c0-2.1 1.7-3.9 3.8-4"/><path d="M20.97 5c0 2.1-1.6 3.8-3.5 4"/><path d="M22 13h-4"/><path d="M17.2 17c2.1.1 3.8 1.9 3.8 4"/></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>'},B={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 de(t){let e=new TextEncoder().encode(t),s="";for(let o=0;o<e.length;o+=32768)s+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(s)}function X(t){let e=atob(t),s=new Uint8Array(e.length);for(let o=0;o<e.length;o++)s[o]=e.charCodeAt(o);return new TextDecoder().decode(s)}var Ee="0.33.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},E,C,z,Xe,Le,D;function mt(){try{sessionStorage.setItem("__om_state__",JSON.stringify({messages:n.messages,provider:n.provider,model:n.model,panelOpen:n.panelOpen,activePanel:n.activePanel}))}catch{}}function ut(){try{let t=JSON.parse(sessionStorage.getItem("__om_state__")||"{}");t.messages?.length&&(n.messages=t.messages),t.provider&&(n.provider=t.provider),t.model&&(n.model=t.model),t.panelOpen&&(n.panelOpen=t.panelOpen,n.activePanel=t.activePanel||"")}catch{}}function We(){if(document.querySelector("openmagic-toolbar"))return;ut();let t=document.createElement("openmagic-toolbar");t.dataset.openmagic="true",E=t.attachShadow({mode:"closed"});let e=document.createElement("style");e.textContent=Ce,E.appendChild(e);let s=document.createElement("div");E.appendChild(s),s.innerHTML=ht(),C=s.querySelector(".om-toolbar"),z=s.querySelector(".om-prompt-input"),Xe=s.querySelector(".om-prompt-context"),Le=s.querySelector(".om-panel"),D=s.querySelector(".om-panel-body"),document.body.appendChild(t),gt(s),Lt();try{let i=JSON.parse(localStorage.getItem("__om_pos__")||"");i?.left&&i?.top&&(C.style.left=i.left,C.style.top=i.top,C.style.right="auto",C.style.bottom="auto")}catch{}Be(),Fe(),Ct();let r=document.querySelector("script[data-openmagic-token]")?.dataset.openmagicToken||window.__OPENMAGIC_TOKEN__,l=parseInt(window.location.port,10)||(window.location.protocol==="https:"?443:80);r&&xe(l,r).then(()=>(n.connected=!0,pe(),M("config.get"))).then(i=>{let d=i.payload?.provider||"",c=i.payload?.model||"";n.provider=n.provider||d,n.model=n.model||c,n.configuredProviders=i.payload?.apiKeys||{},n.hasApiKey=n.configuredProviders[n.provider]||!1,n.roots=i.payload?.roots||[],n.panelOpen&&n.activePanel?F(n.activePanel):(!n.provider||!n.hasApiKey&&!Object.values(n.configuredProviders).some(Boolean))&&F("settings"),se()}).catch(()=>{n.connected=!1,pe()})}function ht(){return`
|
|
394
394
|
<div class="om-toolbar">
|
|
395
395
|
<div class="om-toolbar-header">
|
|
396
396
|
<span class="om-grab">${k.grip}</span>
|
|
@@ -483,7 +483,7 @@
|
|
|
483
483
|
// [FILE TRUNCATED \u2014 showing ${G} of ${T.length} chars]`),u.push({path:$,content:P}),f.add($),b+=P.length}}catch{}break}}if(u.length<=2&&b<o){let Q=["layout.tsx","layout.jsx","layout.js","layout.ts"],$=y.path.replace(/\/[^/]+$/,""),A=0;for(;$&&A<4&&b<o;){let j=!1;for(let G of Q){let P=`${$}/${G}`;if(f.has(P)){j=!0;break}try{let K=await M("fs.read",{path:v?`${v}/${P}`:P}).catch(()=>null),U=String(K?.payload?.content||"");if(U){let V=Math.min(4e3,o-b),he=U.slice(0,V);U.length>V&&(he+=`
|
|
484
484
|
// [TRUNCATED]`),u.push({path:P,content:he}),f.add(P),b+=he.length,j=!0;break}}catch{}}let T=$.replace(/\/[^/]+$/,"");if(T===$||!T)break;$=T,A++}}let Qe=L.matchAll(/(?:import|from)\s+['"]\.?\.\/([\w/.-]+)['"]/g);for(let Q of Qe){if(b>=o)break;let $=Q[1],A=y.path.replace(/\/[^/]+$/,""),j=[`${A}/${$}`,`${A}/${$}.tsx`,`${A}/${$}.ts`,`${A}/${$}.jsx`,`${A}/${$}.js`,`${A}/${$}/index.tsx`,`${A}/${$}/index.ts`];for(let T of j){if(f.has(T))break;if(h.find(P=>P.path===T)){try{let P=await M("fs.read",{path:v?`${v}/${T}`:T}),K=String(P?.payload?.content||"");if(K){let U=Math.min(8e3,o-b),V=K.slice(0,U);K.length>U&&(V+=`
|
|
485
485
|
// [FILE TRUNCATED \u2014 showing ${U} of ${K.length} chars]`),u.push({path:T,content:V}),f.add(T),b+=V.length}}catch{}break}}}}catch{}}if(b<o)try{let y=n.roots[0]||"",v=await M("fs.read",{path:y?`${y}/package.json`:"package.json"}),S=String(v?.payload?.content||"");if(S)try{let R=JSON.parse(S),L={...R.dependencies,...R.devDependencies},I=JSON.stringify(L,null,2);u.push({path:"package.json (dependencies)",content:I.slice(0,2e3)})}catch{u.push({path:"package.json",content:S.slice(0,2e3)})}}catch{}if(b<o){let y=n.roots[0]||"",v=["tailwind.config.ts","tailwind.config.js","tailwind.config.mjs","src/app/globals.css","src/styles/globals.css","styles/globals.css","app/globals.css","src/index.css","src/global.css"];for(let S of v)if(!(b>=o||f.has(S)))try{let R=y?`${y}/${S}`:S,L=await M("fs.read",{path:R}).catch(()=>null),I=String(L?.payload?.content||"");if(I){let W=Math.min(4e3,o-b),Z=I.slice(0,W);I.length>W&&(Z+=`
|
|
486
|
-
/* [TRUNCATED] */`),u.push({path:S,content:Z}),f.add(S),b+=Z.length}}catch{}}if(u.length){e.files=u;let y=u.map(v=>v.path.split("/").pop()).join(", ");l&&(l.innerHTML=`<span class="om-spinner"></span> Thinking... (${u.length} files: ${y})`)}n.groundedFiles=u.map(y=>y.path)}catch{}let i=4,d=0;try{for(;d<=i;){n.streamContent="";let c=await Ne("llm.chat",{provider:n.provider,model:n.model,messages:n.messages.map(a=>({role:a.role,content:a.content})),context:e},a=>{n.streamContent+=a}),p=n.streamContent||c?.content||"",h=p.match(/NEED_FILE:\s*"?([^\s"}\]]+)"?/)||p.match(/(?:need|provide|show|read|see|contents?\s+of)\s+(?:the\s+)?(?:file\s+)?[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i)||p.match(/(?:source\s+(?:file|code)\s+(?:for|of|at))\s+[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i);if(h&&d<i){let a=h[1].trim();d++;let g=D.querySelector(".om-msg-assistant:last-child");g&&(g.innerHTML=`<span class="om-spinner"></span> Reading ${a}...`);try{let m=n.roots[0]||"",u=m?`${m}/${a}`:a,f,b=[u];a!==u&&b.push(a);let y=a.split("/").pop()||a,v=m?`${m}/${y}`:y;v!==u&&v!==a&&b.push(v);for(let S of b){let R=await M("fs.read",{path:S}).catch(()=>null);if(R?.payload?.content){f=String(R.payload.content);break}}if(f)e.files||(e.files=[]),e.files.push({path:a,content:f.slice(0,8e3)});else{n.messages.push({role:"system",content:`Could not read ${a}`});break}}catch{n.messages.push({role:"system",content:`File not found: ${a}`});break}continue}let x=p.match(/SEARCH_FILES:\s*"([^"]+)"(?:\s+in\s+(\S+))?/);if(x&&d<i){let a=x[1],g=x[2]||"";d++;let m=D.querySelector(".om-msg-assistant:last-child");m&&(m.innerHTML=`<span class="om-spinner"></span> Searching: "${a}"...`);try{let f=(await M("fs.grep",{pattern:a,path:g}))?.payload?.results||[];f.length&&(e.searchResults||(e.searchResults=[]),e.searchResults.push({query:a,matches:f}))}catch{}continue}let w=p;try{let a=JSON.parse(p);a.explanation&&(w=a.explanation)}catch{let a=p.match(/```(?:json)?\s*([\s\S]*?)```/);if(a)try{let g=JSON.parse(a[1]);g.explanation&&(w=g.explanation)}catch{}}if(n.messages.push({role:"assistant",content:w}),c?.modifications?.length){let a=Math.random().toString(36).slice(2),g=c.modifications.filter(m=>m.type==="edit"&&m.file&&m.search&&m.replace||m.type==="create"&&m.file&&m.content);yt(g.length);for(let m of c.modifications)if(m.type==="edit"&&m.file&&m.search&&m.replace){let u=Math.random().toString(36).slice(2),f=JSON.stringify({id:u,file:m.file,search:m.search,replace:m.replace,groupId:a});n.messages.push({role:"system",content:`__DIFF__${de(f)}`})}else if(m.type==="create"&&m.file&&m.content){let u=Math.random().toString(36).slice(2),f=JSON.stringify({id:u,file:m.file,search:"",replace:m.content,type:"create",groupId:a});n.messages.push({role:"system",content:`__DIFF__${de(f)}`})}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(c){n.messages.push({role:"system",content:`Error: ${c.message}`})}n.streaming=!1,n.streamContent="",n.attachments=[],Te(),H(),Y()}function $t(){let t=window.performance,e=t.getEntriesByType("navigation")[0],s=t.getEntriesByType("paint"),o=t.getEntriesByType("resource").slice(-20),r=ie(),l=le(),i=[];i.push("--- Network & Performance Capture ---"),e&&(i.push(`Page load: ${Math.round(e.loadEventEnd-e.startTime)}ms`),i.push(`DOM ready: ${Math.round(e.domContentLoadedEventEnd-e.startTime)}ms`),i.push(`TTFB: ${Math.round(e.responseStart-e.startTime)}ms`));let d=s.find(c=>c.name==="first-contentful-paint");if(d&&i.push(`FCP: ${Math.round(d.startTime)}ms`),o.length){let c=o.filter(h=>h.initiatorType==="fetch"||h.initiatorType==="xmlhttprequest"),p=c.length>0?c:o;i.push(`
|
|
486
|
+
/* [TRUNCATED] */`),u.push({path:S,content:Z}),f.add(S),b+=Z.length}}catch{}}if(u.length){e.files=u;let y=u.map(v=>v.path.split("/").pop()).join(", ");l&&(l.innerHTML=`<span class="om-spinner"></span> Thinking... (${u.length} files: ${y})`)}n.groundedFiles=u.map(y=>y.path)}catch{}let i=4,d=0;try{for(;d<=i;){n.streamContent="";let c=await Ne("llm.chat",{provider:n.provider,model:n.model,messages:n.messages.map(a=>({role:a.role,content:a.content})),context:e},a=>{n.streamContent+=a}),p=n.streamContent||c?.content||"",h=p.match(/NEED_FILE:\s*"?([^\s"}\]]+)"?/)||p.match(/(?:need|provide|show|read|see|contents?\s+of)\s+(?:the\s+)?(?:file\s+)?[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i)||p.match(/(?:source\s+(?:file|code)\s+(?:for|of|at))\s+[`"']?([a-zA-Z0-9_/.@-]+\.[a-z]{1,5})[`"']?/i);if(h&&d<i){let a=h[1].trim();d++;let g=D.querySelector(".om-msg-assistant:last-child");g&&(g.innerHTML=`<span class="om-spinner"></span> Reading ${a}...`);try{let m=n.roots[0]||"",u=m?`${m}/${a}`:a,f,b=[u];a!==u&&b.push(a);let y=a.split("/").pop()||a,v=m?`${m}/${y}`:y;v!==u&&v!==a&&b.push(v);for(let S of b){let R=await M("fs.read",{path:S}).catch(()=>null);if(R?.payload?.content){f=String(R.payload.content);break}}if(f)e.files||(e.files=[]),e.files.push({path:a,content:f.slice(0,8e3)});else{n.messages.push({role:"system",content:`Could not read ${a}`});break}}catch{n.messages.push({role:"system",content:`File not found: ${a}`});break}continue}let x=p.match(/SEARCH_FILES:\s*"([^"]+)"(?:\s+in\s+(\S+))?/);if(x&&d<i){let a=x[1],g=x[2]||"";d++;let m=D.querySelector(".om-msg-assistant:last-child");m&&(m.innerHTML=`<span class="om-spinner"></span> Searching: "${a}"...`);try{let f=(await Promise.race([M("fs.grep",{pattern:a,path:g}),new Promise((b,y)=>setTimeout(()=>y(new Error("grep timeout")),5e3))]))?.payload?.results||[];f.length&&(e.searchResults||(e.searchResults=[]),e.searchResults.push({query:a,matches:f}))}catch{}continue}let w=p;try{let a=JSON.parse(p);a.explanation&&(w=a.explanation)}catch{let a=p.match(/```(?:json)?\s*([\s\S]*?)```/);if(a)try{let g=JSON.parse(a[1]);g.explanation&&(w=g.explanation)}catch{}}if(n.messages.push({role:"assistant",content:w}),c?.modifications?.length){let a=Math.random().toString(36).slice(2),g=c.modifications.filter(m=>m.type==="edit"&&m.file&&m.search&&m.replace||m.type==="create"&&m.file&&m.content);yt(g.length);for(let m of c.modifications)if(m.type==="edit"&&m.file&&m.search&&m.replace){let u=Math.random().toString(36).slice(2),f=JSON.stringify({id:u,file:m.file,search:m.search,replace:m.replace,groupId:a});n.messages.push({role:"system",content:`__DIFF__${de(f)}`})}else if(m.type==="create"&&m.file&&m.content){let u=Math.random().toString(36).slice(2),f=JSON.stringify({id:u,file:m.file,search:"",replace:m.content,type:"create",groupId:a});n.messages.push({role:"system",content:`__DIFF__${de(f)}`})}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(c){n.messages.push({role:"system",content:`Error: ${c.message}`})}n.streaming=!1,n.streamContent="",n.attachments=[],Te(),H(),Y()}function $t(){let t=window.performance,e=t.getEntriesByType("navigation")[0],s=t.getEntriesByType("paint"),o=t.getEntriesByType("resource").slice(-20),r=ie(),l=le(),i=[];i.push("--- Network & Performance Capture ---"),e&&(i.push(`Page load: ${Math.round(e.loadEventEnd-e.startTime)}ms`),i.push(`DOM ready: ${Math.round(e.domContentLoadedEventEnd-e.startTime)}ms`),i.push(`TTFB: ${Math.round(e.responseStart-e.startTime)}ms`));let d=s.find(c=>c.name==="first-contentful-paint");if(d&&i.push(`FCP: ${Math.round(d.startTime)}ms`),o.length){let c=o.filter(h=>h.initiatorType==="fetch"||h.initiatorType==="xmlhttprequest"),p=c.length>0?c:o;i.push(`
|
|
487
487
|
All network requests (${p.length}):`);for(let h of p.slice(-30)){let x=h.name.length>80?"..."+h.name.slice(-77):h.name,w=h.responseStatus||"";i.push(` ${Math.round(h.duration)}ms ${w?`[${w}]`:""} ${x}`)}}if(r.length){i.push(`
|
|
488
488
|
Fetch/XHR requests (${r.length}):`);for(let c of r.slice(-20))i.push(` ${c.method} ${c.url.slice(0,80)} \u2192 ${c.status||"pending"} (${c.duration||"?"}ms)`)}if(l.length){let c=l.filter(h=>h.level==="error"),p=l.filter(h=>h.level==="warn");c.length&&i.push(`
|
|
489
489
|
Console errors: ${c.length}`),p.length&&i.push(`Console warnings: ${p.length}`)}if(o.length>5){let c=[...o].sort((p,h)=>h.duration-p.duration).slice(0,5);i.push(`
|