@lensmcp/client-runtime 1.23.2 → 1.23.3
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/lib/install.js +1 -1
- package/package.json +1 -1
package/lib/install.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var O=Object.defineProperty;var u=(t,o)=>O(t,"name",{value:o,configurable:!0});var T=Object.defineProperty,c=u((t,o)=>T(t,"name",{value:o,configurable:!0}),"l");const L="__LENSMCP_CLIENT__";export function installClientRuntime(t){if(typeof window>"u"||window[L])return;window[L]=!0;const o=t.wsUrl,S=t.reconnectIntervalMs??1e3;let a=null,k=!1;const g=[];let f=[],w=!1;const v=c(()=>{if(w=!1,!f.length)return;const n=f;if(f=[],a&&a.readyState===1)try{let e=0;for(;e<n.length;){const r=[];let d=0;for(;e<n.length&&r.length<200;){let i=JSON.stringify(n[e]);if(i.length>3e5&&(i=JSON.stringify({kind:"console",level:"warn",at:Date.now(),truncated:!0,args:[`[lensmcp] dropped an oversized ${String(n[e]?.kind)} event (${i.length} chars)`]})),r.length&&d+i.length>3e5)break;r.push(i),d+=i.length+1,e+=1}a.send(r.length===1?r[0]:`{"kind":"batch","at":${Date.now()},"events":[${r.join(",")}]}`)}return}catch{}for(const e of n)g.push(e)},"flushBatch"),s=c(n=>{n.at=Date.now(),f.push(n),w||(w=!0,setTimeout(v,0))},"send");window.addEventListener("pagehide",v);const p=c(()=>{try{a=new WebSocket(o)}catch{setTimeout(p,S);return}a.addEventListener("open",()=>{for(k=!0;g.length;){const n=g.splice(0,200);try{a.send(JSON.stringify(n.length===1?n[0]:{kind:"batch",at:Date.now(),events:n}))}catch{}}s({kind:"ready",userAgent:navigator.userAgent,url:location.href})}),a.addEventListener("close",()=>{k&&setTimeout(p,S)}),a.addEventListener("error",()=>{})},"open");p(),window.__LENSMCP_PUBLISH__=n=>{s({kind:"publish",...n})},window.addEventListener("error",n=>{const e=n.target;if(e&&e!==window&&e.tagName&&!n.message){s({kind:"resource-error",tagName:e.tagName.toLowerCase(),url:e.currentSrc||e.src||e.href||void 0});return}const r=n.error;s({kind:"error",message:n.message,name:r?.name,stack:h(r?.stack),source:n.filename,lineno:n.lineno,colno:n.colno})},!0),window.addEventListener("unhandledrejection",n=>{const e=n.reason;s({kind:"unhandledrejection",reason:h(N(e)),name:typeof e=="object"&&e?e.name:void 0,stack:typeof e=="object"&&e?h(e.stack):void 0})});const _=["log","info","warn","error","debug"];for(const n of _){const e=console[n];console[n]=function(...r){try{s({kind:"console",level:n,args:r.map(E)})}catch{}e.apply(console,r)}}const j=window.fetch.bind(window);window.fetch=async function(n,e){const r=e?.method??(typeof n=="object"&&n&&"method"in n?n.method:"GET"),d=typeof n=="string"?n:n instanceof URL?n.toString():n.url,i=Date.now();try{const l=await j(n,e);return s({kind:"fetch",method:r,url:d,status:l.status,statusText:l.statusText,ok:l.ok,durationMs:Date.now()-i}),l}catch(l){const b=l;throw s({kind:"fetch",method:r,url:d,error:b.message??String(b),durationMs:Date.now()-i}),l}};const C=history.pushState.bind(history),D=history.replaceState.bind(history),m=c(n=>s({kind:"route",url:location.href,from:n}),"notify");history.pushState=function(...n){const e=location.href,r=C(...n);return m(e),r},history.replaceState=function(...n){const e=location.href,r=D(...n);return m(e),r},window.addEventListener("popstate",()=>m())}u(installClientRuntime,"installClientRuntime"),c(installClientRuntime,"installClientRuntime");const y=4096;function h(t){return t===void 0||t.length<=y?t:`${t.slice(0,y)}\u2026[lensmcp truncated: ${t.length-y} more chars]`}u(h,"m"),c(h,"clipStack");function N(t){if(t==null)return String(t);if(typeof t=="string")return t;if(typeof t.message=="string"&&t.message)return t.message;try{const o=JSON.stringify(t);if(o&&o!=="{}"&&o!=="null")return o}catch{}return String(t)}u(N,"M"),c(N,"describeReason");function E(t){if(t===null)return null;const o=typeof t;if(o==="string"||o==="number"||o==="boolean")return t;try{return JSON.parse(JSON.stringify(t))}catch{return String(t)}}u(E,"C"),c(E,"safe");
|