@lensmcp/react-instrumentation 1.25.24 → 1.25.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import type { EventLoopIdentity } from '@lensmcp/protocol-types';
2
+ export declare function browserLoopIdentity(): EventLoopIdentity | undefined;
3
+ /** Observer callbacks run after the long task: stamping the currently active flow would blame the wrong action. */
4
+ export declare function publishLoopStall(entry: Record<string, unknown>, mechanism: 'long-animation-frame' | 'longtask', timeOrigin: number): void;
5
+ export declare function publishLoopCoverage(mode: 'long-animation-frame' | 'longtask' | undefined): void;
@@ -0,0 +1 @@
1
+ "use strict";var _=Object.defineProperty;var a=(r,t)=>_(r,"name",{value:t,configurable:!0});var w=Object.defineProperty,o=a((r,t)=>w(r,"name",{value:t,configurable:!0}),"o");import{publish as m}from"./publish.js";import{replayMark as y}from"./replay-anchors.js";const h="__LENSMCP_LOOP_IDENTITY__";export function browserLoopIdentity(){if(typeof window>"u"||typeof performance>"u")return;const r=globalThis;let t=r[h];if(!t){let e;try{e=sessionStorage.getItem("lensmcp:tabId")??void 0}catch{}t={id:`browser:${e??Math.random().toString(36).slice(2)}:${performance.timeOrigin}`,runtime:"browser",project:typeof r.__LENSMCP_APP__=="string"?r.__LENSMCP_APP__:location.host||"app",...e?{tabId:e}:{}},r[h]=t}const n=r.__LENSMCP_REPLAY__;return n?.loadId?{...t,loadId:n.loadId}:t}a(browserLoopIdentity,"browserLoopIdentity"),o(browserLoopIdentity,"browserLoopIdentity");const c=o(r=>typeof r=="number"&&Number.isFinite(r)?Math.max(0,r):0,"finite"),b=o((r,t=200)=>typeof r=="string"&&r?r.slice(0,t):void 0,"short"),v=o(r=>{if(!(typeof r!="string"||!r))try{const t=new URL(r,location.href);return t.username="",t.password="",t.search="",t.hash="",t.href.slice(0,512)}catch{return}},"scriptUrl");export function publishLoopStall(r,t,n){const e=browserLoopIdentity(),s=c(r.duration);if(!e||s<50)return;const p=n+c(r.startTime),u=Array.isArray(r.scripts)?r.scripts:[],g=u.slice(0,8).flatMap(l=>{if(!l||typeof l!="object")return[];const i=l,f=v(i.sourceURL);return f?[{url:f,functionName:b(i.sourceFunctionName),invoker:b(i.invoker),startAt:n+c(i.startTime),durationMs:c(i.duration)}]:[]}),d=`${e.id}:${t}:${p}`;m({source:"react",category:"performance",severity:s>=1e3?"error":"warning",detached:!0,title:`Main thread blocked for ${s.toFixed(1)}ms`,fingerprint:"perf:browser-event-loop-stall",raw:{kind:"event-loop-stall",incidentId:d,loop:e,mechanism:t,state:"recovered",startedAt:p,durationMs:s,scripts:g,scriptsTruncated:u.length>8}}),y("lens/stall",{incidentId:d,startedAt:p,durationMs:s})}a(publishLoopStall,"publishLoopStall"),o(publishLoopStall,"publishLoopStall");export function publishLoopCoverage(r){const t=browserLoopIdentity();t&&m({source:"react",category:"performance",detached:!0,title:"Browser loop monitoring",fingerprint:"perf:browser-loop-status",raw:{kind:"event-loop-status",loop:t,coverage:r?`${r}; browser main thread only. Permanent hangs and browser workers are not measured.`:"Long-task APIs unavailable in this browser."}})}a(publishLoopCoverage,"publishLoopCoverage"),o(publishLoopCoverage,"publishLoopCoverage");
@@ -28,7 +28,8 @@ export declare class PagePerf {
28
28
  private scripts;
29
29
  /** Long animation frames are the better long task: they include rendering. Seen at all, `longtask` is not kept. */
30
30
  private loaf;
31
- constructor(host: PerfHost);
31
+ readonly longTaskMode: 'long-animation-frame' | 'longtask' | undefined;
32
+ constructor(host: PerfHost, onLong?: (entry: Record<string, unknown>, mode: 'long-animation-frame' | 'longtask', timeOrigin: number) => void);
32
33
  /** What the browser measured within one visit's window. */
33
34
  window(w: PerfWindow): PerfOut;
34
35
  private push;
package/lib/page-perf.js CHANGED
@@ -1 +1 @@
1
- "use strict";var k=Object.defineProperty;var c=(o,e)=>k(o,"name",{value:e,configurable:!0});var E=Object.defineProperty,a=c((o,e)=>E(o,"name",{value:e,configurable:!0}),"a");const M=600,T=3e3,r=a(o=>typeof o=="number"&&Number.isFinite(o)?o:0,"num"),h=a(o=>Math.round(o*10)/10,"r1");export class PagePerf{static{c(this,"PagePerf")}static{a(this,"PagePerf")}constructor(e){this.host=e,this.marks=[],this.scripts=[],this.loaf=!1;const i=a(s=>e.timeOrigin+r(s.startTime),"at");e.observe("largest-contentful-paint",s=>{for(const t of s)this.push({type:"lcp",at:i(t),dur:0,value:r(t.startTime)})}),e.observe("layout-shift",s=>{for(const t of s)t.hadRecentInput!==!0&&this.push({type:"shift",at:i(t),dur:0,value:r(t.value)})}),e.observe("event",s=>{for(const t of s)r(t.interactionId)>0&&this.push({type:"event",at:i(t),dur:r(t.duration),value:0})}),this.loaf=e.observe("long-animation-frame",s=>{for(const t of s)this.push({type:"long",at:i(t),dur:r(t.duration),value:0})}),this.loaf||e.observe("longtask",s=>{for(const t of s)this.push({type:"long",at:i(t),dur:r(t.duration),value:0})}),e.observe("resource",s=>{for(const t of s)t.initiatorType!=="script"&&!/\.(m?js|tsx?|jsx)(\?|$)/.test(String(t.name??""))||/\/@lensmcp\//.test(String(t.name??""))||(this.scripts.push({at:i(t),kb:(r(t.transferSize)||r(t.encodedBodySize))/1024}),this.scripts.length>3e3&&this.scripts.splice(0,this.scripts.length-3e3))})}window(e){const i=a(n=>n.at>=e.startAt&&n.at<=e.toAt,"inside"),s={};if(e.hard){const n=this.host.navigation();n&&(r(n.responseStart)>0&&(s.ttfb=h(r(n.responseStart))),r(n.domContentLoadedEventEnd)>0&&(s.dcl=h(r(n.domContentLoadedEventEnd))),r(n.loadEventEnd)>0&&(s.load=h(r(n.loadEventEnd))));const g=this.host.paint("first-contentful-paint");g!==void 0&&(s.fcp=h(g));const y=this.marks.filter(b=>b.type==="lcp"&&b.at<=e.toAt).at(-1);y&&(s.lcp=h(y.value))}let t=0,p=0,u=0,d=0,l=0;for(const n of this.marks)i(n)&&(n.type==="shift"?t+=n.value:n.type==="event"?p=Math.max(p,n.dur):n.type==="long"&&(u++,d+=n.dur,l=Math.max(l,n.dur)));t>0&&(s.cls=Math.round(t*1e3)/1e3),p>0&&(s.inp=h(p));let f=0,m=0;for(const n of this.scripts)n.at<e.startAt||n.at>e.toAt||(f++,m+=n.kb);const v=this.host.heapBytes();return{...Object.keys(s).length?{vitals:s}:{},...u?{longTasks:{n:u,totalMs:h(d),maxMs:h(l)}}:{},...v!==void 0?{heapMb:h(v/(1<<20))}:{},...f?{chunks:{n:f,kb:Math.round(m)}}:{}}}push(e){this.marks.push(e),this.marks.length>600&&this.marks.splice(0,this.marks.length-600)}}export function browserPerfHost(){const o=globalThis,e=o.performance,i=o.PerformanceObserver;if(!e||!i||typeof e.timeOrigin!="number")return;const s=new Set(i.supportedEntryTypes??[]);return{timeOrigin:e.timeOrigin,observe(t,p){if(!s.has(t))return!1;try{return new i(u=>p(u.getEntries())).observe({type:t,buffered:!0,...t==="event"?{durationThreshold:16}:{}}),!0}catch{return!1}},navigation:a(()=>e.getEntriesByType?.("navigation")?.[0]?.toJSON?.(),"navigation"),paint:a(t=>e.getEntriesByName?.(t,"paint")?.[0]?.startTime,"paint"),heapBytes:a(()=>e.memory?.usedJSHeapSize,"heapBytes")}}c(browserPerfHost,"browserPerfHost"),a(browserPerfHost,"browserPerfHost");
1
+ "use strict";var k=Object.defineProperty;var l=(r,e)=>k(r,"name",{value:e,configurable:!0});var E=Object.defineProperty,a=l((r,e)=>E(r,"name",{value:e,configurable:!0}),"a");const S=600,T=3e3,i=a(r=>typeof r=="number"&&Number.isFinite(r)?r:0,"num"),h=a(r=>Math.round(r*10)/10,"r1");export class PagePerf{static{l(this,"PagePerf")}static{a(this,"PagePerf")}constructor(e,p){this.host=e,this.marks=[],this.scripts=[],this.loaf=!1;const o=a(s=>e.timeOrigin+i(s.startTime),"at");e.observe("largest-contentful-paint",s=>{for(const t of s)this.push({type:"lcp",at:o(t),dur:0,value:i(t.startTime)})}),e.observe("layout-shift",s=>{for(const t of s)t.hadRecentInput!==!0&&this.push({type:"shift",at:o(t),dur:0,value:i(t.value)})}),e.observe("event",s=>{for(const t of s)i(t.interactionId)>0&&this.push({type:"event",at:o(t),dur:i(t.duration),value:0})}),this.loaf=e.observe("long-animation-frame",s=>{for(const t of s)this.push({type:"long",at:o(t),dur:i(t.duration),value:0}),p?.(t,"long-animation-frame",e.timeOrigin)}),this.loaf&&(this.longTaskMode="long-animation-frame"),this.loaf||e.observe("longtask",s=>{for(const t of s)this.push({type:"long",at:o(t),dur:i(t.duration),value:0}),p?.(t,"longtask",e.timeOrigin)})&&(this.longTaskMode="longtask"),e.observe("resource",s=>{for(const t of s)t.initiatorType!=="script"&&!/\.(m?js|tsx?|jsx)(\?|$)/.test(String(t.name??""))||/\/@lensmcp\//.test(String(t.name??""))||(this.scripts.push({at:o(t),kb:(i(t.transferSize)||i(t.encodedBodySize))/1024}),this.scripts.length>3e3&&this.scripts.splice(0,this.scripts.length-3e3))})}window(e){const p=a(n=>n.at>=e.startAt&&n.at<=e.toAt,"inside"),o={};if(e.hard){const n=this.host.navigation();n&&(i(n.responseStart)>0&&(o.ttfb=h(i(n.responseStart))),i(n.domContentLoadedEventEnd)>0&&(o.dcl=h(i(n.domContentLoadedEventEnd))),i(n.loadEventEnd)>0&&(o.load=h(i(n.loadEventEnd))));const v=this.host.paint("first-contentful-paint");v!==void 0&&(o.fcp=h(v));const y=this.marks.filter(b=>b.type==="lcp"&&b.at<=e.toAt).at(-1);y&&(o.lcp=h(y.value))}let s=0,t=0,u=0,d=0,c=0;for(const n of this.marks)p(n)&&(n.type==="shift"?s+=n.value:n.type==="event"?t=Math.max(t,n.dur):n.type==="long"&&(u++,d+=n.dur,c=Math.max(c,n.dur)));s>0&&(o.cls=Math.round(s*1e3)/1e3),t>0&&(o.inp=h(t));let f=0,m=0;for(const n of this.scripts)n.at<e.startAt||n.at>e.toAt||(f++,m+=n.kb);const g=this.host.heapBytes();return{...Object.keys(o).length?{vitals:o}:{},...u?{longTasks:{n:u,totalMs:h(d),maxMs:h(c)}}:{},...g!==void 0?{heapMb:h(g/(1<<20))}:{},...f?{chunks:{n:f,kb:Math.round(m)}}:{}}}push(e){this.marks.push(e),this.marks.length>600&&this.marks.splice(0,this.marks.length-600)}}export function browserPerfHost(){const r=globalThis,e=r.performance,p=r.PerformanceObserver;if(!e||!p||typeof e.timeOrigin!="number")return;const o=new Set(p.supportedEntryTypes??[]);return{timeOrigin:e.timeOrigin,observe(s,t){if(!o.has(s))return!1;try{return new p(u=>t(u.getEntries())).observe({type:s,buffered:!0,...s==="event"?{durationThreshold:16}:{}}),!0}catch{return!1}},navigation:a(()=>e.getEntriesByType?.("navigation")?.[0]?.toJSON?.(),"navigation"),paint:a(s=>e.getEntriesByName?.(s,"paint")?.[0]?.startTime,"paint"),heapBytes:a(()=>e.memory?.usedJSHeapSize,"heapBytes")}}l(browserPerfHost,"browserPerfHost"),a(browserPerfHost,"browserPerfHost");
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var i=(t,e)=>g(t,"name",{value:e,configurable:!0});var u=Object.defineProperty,o=i((t,e)=>u(t,"name",{value:e,configurable:!0}),"a");import{publish as l}from"./publish.js";import{PageVisitTracker as v}from"./page-visits.js";import{browserPerfHost as _,PagePerf as P}from"./page-perf.js";import{replayCheckpoint as w,replayMark as f}from"./replay-anchors.js";const d="__LENSMCP_PAGE_VISITS__";function y(){return typeof window<"u"&&typeof location<"u"&&typeof document<"u"}i(y,"_"),o(y,"browser");function p(){if(!y())return;const t=globalThis,e=t[d];if(e===!1)return;if(e)return e;const a=typeof t.__LENSMCP_APP__=="string"&&t.__LENSMCP_APP__?t.__LENSMCP_APP__:location.host||"app";let s;try{const r=_();s=r?new P(r):void 0}catch{s=void 0}const n={tracker:new v({app:a,...s?{perf:o(r=>s.window(r),"perf")}:{},emit:o((r,c)=>{l({source:"react",category:"performance",severity:r.readyBy==="timeout"?"warning":"info",title:c,fingerprint:`page-visit:${r.visitId}:${r.phase}`,detached:!0,raw:r}),replayVisit(r)},"emit"),onStart:replayVisitStart,tabId:o(()=>{try{return sessionStorage.getItem("lensmcp:tabId")??void 0}catch{return}},"tabId"),base:o(()=>location.href,"base")}),hardStarted:!1};t[d]=n;try{window.addEventListener("beforeunload",()=>n.tracker.pagehide()),window.addEventListener("pagehide",()=>n.tracker.pagehide()),window.addEventListener("error",r=>n.tracker.error(r.message||"error")),window.addEventListener("unhandledrejection",r=>{const c=r.reason;n.tracker.error(c instanceof Error?`${c.name}: ${c.message}`:String(c))})}catch{}return n}i(p,"p"),o(p,"shared");export function replayVisit(t){f("lens/visit",{visitId:t.visitId,phase:t.phase,...t.pattern?{pattern:t.pattern}:{},...t.readyBy?{readyBy:t.readyBy}:{},...t.readyMs!==void 0?{readyMs:t.readyMs}:{}}),t.phase==="ready"&&t.nav==="spa"&&t.readyBy!=="left"&&w()}i(replayVisit,"replayVisit"),o(replayVisit,"replayVisit");export function replayVisitStart(t){f("lens/visit",{visitId:t.visitId,phase:"start",path:t.path,nav:t.nav,startAt:t.startAt})}i(replayVisitStart,"replayVisitStart"),o(replayVisitStart,"replayVisitStart");export function startHardPageVisit(t){const e=p();if(!(!e||e.hardStarted)){e.hardStarted=!0;try{const a=Date.now(),s=typeof performance<"u"&&typeof performance.timeOrigin=="number"?Math.round(performance.timeOrigin):a,n=(typeof performance<"u"&&typeof performance.getEntriesByType=="function"?performance.getEntriesByType("navigation")[0]:void 0)?.type,r=n==="navigate"||n==="reload"||n==="back_forward"?n:void 0;e.tracker.hard({path:location.pathname,startAt:Math.min(s,a),appStartAt:a,...r?{navType:r}:{},...h()?{cause:"hmr"}:{},...t?{flowId:t}:{}})}catch{}}}i(startHardPageVisit,"startHardPageVisit"),o(startHardPageVisit,"startHardPageVisit");function h(){if(globalThis.__LENSMCP_RELOAD_CAUSE__)return!0;try{return!!sessionStorage.getItem("lensmcp:reloadCause")}catch{return!1}}i(h,"P"),o(h,"hmrReload");export function notePageNavigation(t,e,a){try{p()?.tracker.navigate({path:t,how:e,...a?{flowId:a}:{}})}catch{}}i(notePageNavigation,"notePageNavigation"),o(notePageNavigation,"notePageNavigation");export function pageVisitOpen(){const t=globalThis[d];return!!t&&t.tracker.open()}i(pageVisitOpen,"pageVisitOpen"),o(pageVisitOpen,"pageVisitOpen");export function notePageFetch(t,e,a,s,n){const r=p();if(r)try{const c=r.tracker.fetchStarted({method:e,url:a,...s?{rid:s}:{},...n?{flowId:n}:{}});t.then(m=>c(m.status),()=>c(0))}catch{}}i(notePageFetch,"notePageFetch"),o(notePageFetch,"notePageFetch");export function notePageCommit(t,e){const a=p();if(a&&(a.commitsBy??=t,a.commitsBy===t))try{a.tracker.commit(e)}catch{}}i(notePageCommit,"notePageCommit"),o(notePageCommit,"notePageCommit");export function notePageState(t,e){const a=globalThis[d];if(a)try{a.tracker.storeUpdated(t,e)}catch{}}i(notePageState,"notePageState"),o(notePageState,"notePageState");
1
+ "use strict";var u=Object.defineProperty;var i=(t,e)=>u(t,"name",{value:e,configurable:!0});var l=Object.defineProperty,o=i((t,e)=>l(t,"name",{value:e,configurable:!0}),"a");import{publish as v}from"./publish.js";import{PageVisitTracker as _}from"./page-visits.js";import{browserPerfHost as P,PagePerf as w}from"./page-perf.js";import{replayCheckpoint as S,replayMark as f}from"./replay-anchors.js";import{publishLoopCoverage as h,publishLoopStall as b}from"./loop-monitor.js";const d="__LENSMCP_PAGE_VISITS__";function y(){return typeof window<"u"&&typeof location<"u"&&typeof document<"u"}i(y,"P"),o(y,"browser");function p(){if(!y())return;const t=globalThis,e=t[d];if(e===!1)return;if(e)return e;const a=typeof t.__LENSMCP_APP__=="string"&&t.__LENSMCP_APP__?t.__LENSMCP_APP__:location.host||"app";let s;try{const r=P();s=r?new w(r,b):void 0,h(s?.longTaskMode),setInterval(()=>h(s?.longTaskMode),6e4)}catch{s=void 0}const n={tracker:new _({app:a,...s?{perf:o(r=>s.window(r),"perf")}:{},emit:o((r,c)=>{v({source:"react",category:"performance",severity:r.readyBy==="timeout"?"warning":"info",title:c,fingerprint:`page-visit:${r.visitId}:${r.phase}`,detached:!0,raw:r}),replayVisit(r)},"emit"),onStart:replayVisitStart,tabId:o(()=>{try{return sessionStorage.getItem("lensmcp:tabId")??void 0}catch{return}},"tabId"),base:o(()=>location.href,"base")}),hardStarted:!1};t[d]=n;try{window.addEventListener("beforeunload",()=>n.tracker.pagehide()),window.addEventListener("pagehide",()=>n.tracker.pagehide()),window.addEventListener("error",r=>n.tracker.error(r.message||"error")),window.addEventListener("unhandledrejection",r=>{const c=r.reason;n.tracker.error(c instanceof Error?`${c.name}: ${c.message}`:String(c))})}catch{}return n}i(p,"p"),o(p,"shared");export function replayVisit(t){f("lens/visit",{visitId:t.visitId,phase:t.phase,...t.pattern?{pattern:t.pattern}:{},...t.readyBy?{readyBy:t.readyBy}:{},...t.readyMs!==void 0?{readyMs:t.readyMs}:{}}),t.phase==="ready"&&t.nav==="spa"&&t.readyBy!=="left"&&S()}i(replayVisit,"replayVisit"),o(replayVisit,"replayVisit");export function replayVisitStart(t){f("lens/visit",{visitId:t.visitId,phase:"start",path:t.path,nav:t.nav,startAt:t.startAt})}i(replayVisitStart,"replayVisitStart"),o(replayVisitStart,"replayVisitStart");export function startHardPageVisit(t){const e=p();if(!(!e||e.hardStarted)){e.hardStarted=!0;try{const a=Date.now(),s=typeof performance<"u"&&typeof performance.timeOrigin=="number"?Math.round(performance.timeOrigin):a,n=(typeof performance<"u"&&typeof performance.getEntriesByType=="function"?performance.getEntriesByType("navigation")[0]:void 0)?.type,r=n==="navigate"||n==="reload"||n==="back_forward"?n:void 0;e.tracker.hard({path:location.pathname,startAt:Math.min(s,a),appStartAt:a,...r?{navType:r}:{},...m()?{cause:"hmr"}:{},...t?{flowId:t}:{}})}catch{}}}i(startHardPageVisit,"startHardPageVisit"),o(startHardPageVisit,"startHardPageVisit");function m(){if(globalThis.__LENSMCP_RELOAD_CAUSE__)return!0;try{return!!sessionStorage.getItem("lensmcp:reloadCause")}catch{return!1}}i(m,"S"),o(m,"hmrReload");export function notePageNavigation(t,e,a){try{p()?.tracker.navigate({path:t,how:e,...a?{flowId:a}:{}})}catch{}}i(notePageNavigation,"notePageNavigation"),o(notePageNavigation,"notePageNavigation");export function pageVisitOpen(){const t=globalThis[d];return!!t&&t.tracker.open()}i(pageVisitOpen,"pageVisitOpen"),o(pageVisitOpen,"pageVisitOpen");export function notePageFetch(t,e,a,s,n){const r=p();if(r)try{const c=r.tracker.fetchStarted({method:e,url:a,...s?{rid:s}:{},...n?{flowId:n}:{}});t.then(g=>c(g.status),()=>c(0))}catch{}}i(notePageFetch,"notePageFetch"),o(notePageFetch,"notePageFetch");export function notePageCommit(t,e){const a=p();if(a&&(a.commitsBy??=t,a.commitsBy===t))try{a.tracker.commit(e)}catch{}}i(notePageCommit,"notePageCommit"),o(notePageCommit,"notePageCommit");export function notePageState(t,e){const a=globalThis[d];if(a)try{a.tracker.storeUpdated(t,e)}catch{}}i(notePageState,"notePageState"),o(notePageState,"notePageState");
package/lib/publish.js CHANGED
@@ -1 +1 @@
1
- "use strict";var W=Object.defineProperty;var t=(e,o)=>W(e,"name",{value:o,configurable:!0});var U=Object.defineProperty,i=t((e,o)=>U(e,"name",{value:o,configurable:!0}),"t");import{createEventFloodGuard as $,estimateJsonBytes as q}from"@lensmcp/protocol-types";import{replayMark as M}from"./replay-anchors.js";const s=[],X=200,S=(()=>{const e=typeof process<"u"?process.env?.LENSMCP_PUBLISH_QUEUE_BYTES:void 0,o=Number(e);return Number.isFinite(o)&&o>0?Math.floor(o):1024*1024})(),I=[];let d=0;function L(e){const o=q(e,S);for(s.push(e),I.push(o),d+=o;s.length>X||d>S&&s.length>1;)s.shift(),d-=I.shift()??0;s.length===0&&(d=0)}t(L,"P"),i(L,"enqueue");function E(){const e=s.shift();return d-=I.shift()??0,s.length===0&&(d=0),e}t(E,"C"),i(E,"dequeue");export function queuedByteCount(){return d}t(queuedByteCount,"queuedByteCount"),i(queuedByteCount,"queuedByteCount");const p=[],F=4e3;let l;export const DEFAULT_AMBIENT_FLOW_MAX_MS=3e4;let y;function N(e){if(e==="off"||e==="Infinity")return 1/0;const o=typeof e=="string"&&e.trim()!==""?Number(e):e;if(!(typeof o!="number"||Number.isNaN(o)||o<0))return o===0||o===1/0?1/0:o}t(N,"m"),i(N,"parseMaxLifetime");function B(){if(y!==void 0)return y;const e=N(globalThis.__LENSMCP_AMBIENT_FLOW_MAX_MS__);return e!==void 0?e:N(typeof process<"u"?process.env?.LENSMCP_AMBIENT_FLOW_MAX_MS:void 0)??DEFAULT_AMBIENT_FLOW_MAX_MS}t(B,"X"),i(B,"ambientMaxMs");export function configureAmbientFlows(e){y=e.maxLifetimeMs===void 0?void 0:N(e.maxLifetimeMs)}t(configureAmbientFlows,"configureAmbientFlows"),i(configureAmbientFlows,"configureAmbientFlows");const c=new Map,j=16;function k(e){for(c.set(e,{bornAt:Date.now()});c.size>j;)c.delete(c.keys().next().value)}t(k,"Q"),i(k,"trackAmbient");function b(e){const o=c.get(e.flowId);if(!o)return!1;const n=B();return n!==1/0&&Date.now()-o.bornAt>=n}t(b,"x"),i(b,"ambientExhausted");export function extendFlowWindow(e){const o=e??currentFlow()??l?.spec;o&&(b(o)||(l={spec:o,until:Date.now()+F}))}t(extendFlowWindow,"extendFlowWindow"),i(extendFlowWindow,"extendFlowWindow");function a(){return l&&Date.now()<l.until?l.spec:void 0}t(a,"y"),i(a,"windowedFlow");export function activeFlow(){return currentFlow()??a()}t(activeFlow,"activeFlow"),i(activeFlow,"activeFlow");export function beginBackgroundFlow(e){const o={flowId:h(),originType:e.originType,...e.originNodeId?{originNodeId:e.originNodeId}:{}};return l={spec:o,until:Date.now()+F},k(o.flowId),publish({source:"react",category:"runtime",severity:"info",title:e.originType,fingerprint:_(e.originNodeId??e.originType,o.flowId),raw:{kind:"flow-origin",originNodeId:e.originNodeId,...e.continuesFlowId?{continuesFlowId:e.continuesFlowId}:{}}}),M("lens/flow",{flowId:o.flowId,kind:e.originType,...e.originNodeId?{originNodeId:e.originNodeId}:{}}),o}t(beginBackgroundFlow,"beginBackgroundFlow"),i(beginBackgroundFlow,"beginBackgroundFlow");export function flowForNewActivity(){const e=currentFlow();if(e)return e;const o=a();if(o)return b(o)?beginBackgroundFlow({originType:"timer",originNodeId:typeof location<"u"?`ambient:${location.pathname}`:"ambient",continuesFlowId:o.flowId}):o}t(flowForNewActivity,"flowForNewActivity"),i(flowForNewActivity,"flowForNewActivity");export const FLOW_ORIGIN_FINGERPRINT_PREFIX="flow-origin:";function _(e,o){return`${FLOW_ORIGIN_FINGERPRINT_PREFIX}${e}:${o}`}t(_,"S"),i(_,"originFingerprint");export function setPublisher(e){if(globalThis.__LENSMCP_PUBLISH__=e,e)for(;s.length;){const o=E();if(o)try{e(o)}catch{}}}t(setPublisher,"setPublisher"),i(setPublisher,"setPublisher");export function runInFlow(e,o){p.push(e),l={spec:e,until:Date.now()+F};try{return o()}finally{p.pop()}}t(runInFlow,"runInFlow"),i(runInFlow,"runInFlow");export function currentFlow(){return p[p.length-1]}t(currentFlow,"currentFlow"),i(currentFlow,"currentFlow");const A=Symbol.for("lensmcp.flowed"),P=2e3,f=new Map;function D(e){if(e==null||typeof e!="object")return;const o=e,n=o.nativeEvent;if(n!=null&&typeof n=="object"){const r=n.isTrusted;if(typeof r=="boolean")return r}if(typeof o.isTrusted=="boolean")return o.isTrusted}t(D,"$"),i(D,"eventTrust");function C(e){if(!(f.size<=64))for(const[o,n]of f)e>=n.until&&f.delete(o)}t(C,"q"),i(C,"pruneInputBursts");export function withFlow(e,o={}){if(typeof e!="function"||e[A])return e;const n=i(()=>{publish({source:"react",category:"runtime",severity:"info",title:o.originType??"user-click",fingerprint:_(o.originNodeId??"unknown",currentFlow()?.flowId??""),raw:{kind:"flow-origin",originNodeId:o.originNodeId}});const u=currentFlow()?.flowId;u&&M("lens/flow",{flowId:u,kind:o.originType??"user-click",...o.originNodeId?{originNodeId:o.originNodeId}:{}})},"publishOrigin"),r=i(function(...u){if(o.originType==="input-change"){if(D(u[0])===!1)return currentFlow()==null&&a()!=null&&extendFlowWindow(),e(...u);const v=o.originNodeId??"input",g=Date.now(),w=f.get(v);if(w&&g<w.until)return w.until=g+P,runInFlow(w.spec,()=>e(...u));const x={flowId:h(),originType:"input-change",originNodeId:o.originNodeId};return f.set(v,{spec:x,until:g+P}),C(g),runInFlow(x,()=>(n(),e(...u)))}const O=h();return runInFlow({flowId:O,originType:o.originType??"user-click",originNodeId:o.originNodeId},()=>(n(),e(...u)))},"flowed");return r[A]=!0,r}t(withFlow,"withFlow"),i(withFlow,"withFlow");let m=0;function h(){return m=(m+1)%65535,`flow:${Date.now().toString(36)}:${m.toString(36)}`}t(h,"E"),i(h,"newFlowId");export function publish(e){if(e.detached){const{detached:r,...u}=e;T(u);return}const o=currentFlow()??(e.context?.flowId?void 0:a()),n=o==null?e:{...e,context:{...o.flowId?{flowId:o.flowId}:{},...o.originType?{originType:o.originType}:{},...o.originNodeId?{originNodeId:o.originNodeId}:{},...o.causedByNodeId?{causedByNodeId:o.causedByNodeId}:{},...e.context}};T(n)}t(publish,"publish"),i(publish,"publish");function T(e){const o=globalThis.__LENSMCP_PUBLISH__;if(o)try{o(e);return}catch{}L(e)}t(T,"B"),i(T,"deliver");const z=$({burst:30,perSec:5});export function publishLazy(e,o){const n=e.startsWith(FLOW_ORIGIN_FINGERPRINT_PREFIX)?{ok:!0,suppressed:0}:z.admit(e);if(!n.ok)return;const r=o();if(n.suppressed>0&&r.raw!==null&&typeof r.raw=="object"){publish({...r,raw:{...r.raw,floodSuppressed:n.suppressed}});return}publish(r)}t(publishLazy,"publishLazy"),i(publishLazy,"publishLazy");export function resetFlowStateForTests(){p.length=0,l=void 0,c.clear(),f.clear(),y=void 0}t(resetFlowStateForTests,"resetFlowStateForTests"),i(resetFlowStateForTests,"resetFlowStateForTests");export function drainQueue(){return I.length=0,d=0,s.splice(0,s.length)}t(drainQueue,"drainQueue"),i(drainQueue,"drainQueue");
1
+ "use strict";var W=Object.defineProperty;var t=(e,o)=>W(e,"name",{value:o,configurable:!0});var U=Object.defineProperty,i=t((e,o)=>U(e,"name",{value:o,configurable:!0}),"t");import{createEventFloodGuard as $,estimateJsonBytes as q}from"@lensmcp/protocol-types";import{replayMark as L}from"./replay-anchors.js";import{browserLoopIdentity as z}from"./loop-monitor.js";const u=[],R=200,S=(()=>{const e=typeof process<"u"?process.env?.LENSMCP_PUBLISH_QUEUE_BYTES:void 0,o=Number(e);return Number.isFinite(o)&&o>0?Math.floor(o):1024*1024})(),I=[];let d=0;function E(e){const o=q(e,S);for(u.push(e),I.push(o),d+=o;u.length>R||d>S&&u.length>1;)u.shift(),d-=I.shift()??0;u.length===0&&(d=0)}t(E,"C"),i(E,"enqueue");function B(){const e=u.shift();return d-=I.shift()??0,u.length===0&&(d=0),e}t(B,"X"),i(B,"dequeue");export function queuedByteCount(){return d}t(queuedByteCount,"queuedByteCount"),i(queuedByteCount,"queuedByteCount");const p=[],F=4e3;let c;export const DEFAULT_AMBIENT_FLOW_MAX_MS=3e4;let y;function N(e){if(e==="off"||e==="Infinity")return 1/0;const o=typeof e=="string"&&e.trim()!==""?Number(e):e;if(!(typeof o!="number"||Number.isNaN(o)||o<0))return o===0||o===1/0?1/0:o}t(N,"m"),i(N,"parseMaxLifetime");function k(){if(y!==void 0)return y;const e=N(globalThis.__LENSMCP_AMBIENT_FLOW_MAX_MS__);return e!==void 0?e:N(typeof process<"u"?process.env?.LENSMCP_AMBIENT_FLOW_MAX_MS:void 0)??DEFAULT_AMBIENT_FLOW_MAX_MS}t(k,"Q"),i(k,"ambientMaxMs");export function configureAmbientFlows(e){y=e.maxLifetimeMs===void 0?void 0:N(e.maxLifetimeMs)}t(configureAmbientFlows,"configureAmbientFlows"),i(configureAmbientFlows,"configureAmbientFlows");const l=new Map,X=16;function A(e){for(l.set(e,{bornAt:Date.now()});l.size>X;)l.delete(l.keys().next().value)}t(A,"q"),i(A,"trackAmbient");function m(e){const o=l.get(e.flowId);if(!o)return!1;const n=k();return n!==1/0&&Date.now()-o.bornAt>=n}t(m,"x"),i(m,"ambientExhausted");export function extendFlowWindow(e){const o=e??currentFlow()??c?.spec;o&&(m(o)||(c={spec:o,until:Date.now()+F}))}t(extendFlowWindow,"extendFlowWindow"),i(extendFlowWindow,"extendFlowWindow");function a(){return c&&Date.now()<c.until?c.spec:void 0}t(a,"y"),i(a,"windowedFlow");export function activeFlow(){return currentFlow()??a()}t(activeFlow,"activeFlow"),i(activeFlow,"activeFlow");export function beginBackgroundFlow(e){const o={flowId:h(),originType:e.originType,...e.originNodeId?{originNodeId:e.originNodeId}:{}};return c={spec:o,until:Date.now()+F},A(o.flowId),publish({source:"react",category:"runtime",severity:"info",title:e.originType,fingerprint:_(e.originNodeId??e.originType,o.flowId),raw:{kind:"flow-origin",originNodeId:e.originNodeId,...e.continuesFlowId?{continuesFlowId:e.continuesFlowId}:{}}}),L("lens/flow",{flowId:o.flowId,kind:e.originType,...e.originNodeId?{originNodeId:e.originNodeId}:{}}),o}t(beginBackgroundFlow,"beginBackgroundFlow"),i(beginBackgroundFlow,"beginBackgroundFlow");export function flowForNewActivity(){const e=currentFlow();if(e)return e;const o=a();if(o)return m(o)?beginBackgroundFlow({originType:"timer",originNodeId:typeof location<"u"?`ambient:${location.pathname}`:"ambient",continuesFlowId:o.flowId}):o}t(flowForNewActivity,"flowForNewActivity"),i(flowForNewActivity,"flowForNewActivity");export const FLOW_ORIGIN_FINGERPRINT_PREFIX="flow-origin:";function _(e,o){return`${FLOW_ORIGIN_FINGERPRINT_PREFIX}${e}:${o}`}t(_,"S"),i(_,"originFingerprint");export function setPublisher(e){if(globalThis.__LENSMCP_PUBLISH__=e,e)for(;u.length;){const o=B();if(o)try{e(o)}catch{}}}t(setPublisher,"setPublisher"),i(setPublisher,"setPublisher");export function runInFlow(e,o){p.push(e),c={spec:e,until:Date.now()+F};try{return o()}finally{p.pop()}}t(runInFlow,"runInFlow"),i(runInFlow,"runInFlow");export function currentFlow(){return p[p.length-1]}t(currentFlow,"currentFlow"),i(currentFlow,"currentFlow");const P=Symbol.for("lensmcp.flowed"),D=2e3,f=new Map;function C(e){if(e==null||typeof e!="object")return;const o=e,n=o.nativeEvent;if(n!=null&&typeof n=="object"){const r=n.isTrusted;if(typeof r=="boolean")return r}if(typeof o.isTrusted=="boolean")return o.isTrusted}t(C,"G"),i(C,"eventTrust");function O(e){if(!(f.size<=64))for(const[o,n]of f)e>=n.until&&f.delete(o)}t(O,"R"),i(O,"pruneInputBursts");export function withFlow(e,o={}){if(typeof e!="function"||e[P])return e;const n=i(()=>{publish({source:"react",category:"runtime",severity:"info",title:o.originType??"user-click",fingerprint:_(o.originNodeId??"unknown",currentFlow()?.flowId??""),raw:{kind:"flow-origin",originNodeId:o.originNodeId}});const s=currentFlow()?.flowId;s&&L("lens/flow",{flowId:s,kind:o.originType??"user-click",...o.originNodeId?{originNodeId:o.originNodeId}:{}})},"publishOrigin"),r=i(function(...s){if(o.originType==="input-change"){if(C(s[0])===!1)return currentFlow()==null&&a()!=null&&extendFlowWindow(),e(...s);const v=o.originNodeId??"input",w=Date.now(),g=f.get(v);if(g&&w<g.until)return g.until=w+D,runInFlow(g.spec,()=>e(...s));const M={flowId:h(),originType:"input-change",originNodeId:o.originNodeId};return f.set(v,{spec:M,until:w+D}),O(w),runInFlow(M,()=>(n(),e(...s)))}const b=h();return runInFlow({flowId:b,originType:o.originType??"user-click",originNodeId:o.originNodeId},()=>(n(),e(...s)))},"flowed");return r[P]=!0,r}t(withFlow,"withFlow"),i(withFlow,"withFlow");let T=0;function h(){return T=(T+1)%65535,`flow:${Date.now().toString(36)}:${T.toString(36)}`}t(h,"b"),i(h,"newFlowId");export function publish(e){const o=z();if(o&&(e={...e,raw:{...e.raw,loopId:o.id}}),e.detached){const{detached:s,...b}=e;x(b);return}const n=currentFlow()??(e.context?.flowId?void 0:a()),r=n==null?e:{...e,context:{...n.flowId?{flowId:n.flowId}:{},...n.originType?{originType:n.originType}:{},...n.originNodeId?{originNodeId:n.originNodeId}:{},...n.causedByNodeId?{causedByNodeId:n.causedByNodeId}:{},...e.context}};x(r)}t(publish,"publish"),i(publish,"publish");function x(e){const o=globalThis.__LENSMCP_PUBLISH__;if(o)try{o(e);return}catch{}E(e)}t(x,"B"),i(x,"deliver");const j=$({burst:30,perSec:5});export function publishLazy(e,o){const n=e.startsWith(FLOW_ORIGIN_FINGERPRINT_PREFIX)?{ok:!0,suppressed:0}:j.admit(e);if(!n.ok)return;const r=o();if(n.suppressed>0&&r.raw!==null&&typeof r.raw=="object"){publish({...r,raw:{...r.raw,floodSuppressed:n.suppressed}});return}publish(r)}t(publishLazy,"publishLazy"),i(publishLazy,"publishLazy");export function resetFlowStateForTests(){p.length=0,c=void 0,l.clear(),f.clear(),y=void 0}t(resetFlowStateForTests,"resetFlowStateForTests"),i(resetFlowStateForTests,"resetFlowStateForTests");export function drainQueue(){return I.length=0,d=0,u.splice(0,u.length)}t(drainQueue,"drainQueue"),i(drainQueue,"drainQueue");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/react-instrumentation",
3
- "version": "1.25.24",
3
+ "version": "1.25.25",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -19,7 +19,7 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@lensmcp/protocol-types": "1.25.24",
22
+ "@lensmcp/protocol-types": "1.25.25",
23
23
  "tslib": "^2.3.0"
24
24
  },
25
25
  "peerDependencies": {