@lensmcp/react-instrumentation 1.25.11 → 1.25.13
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/babel-plugin.js +1 -1
- package/lib/component-identity.js +1 -1
- package/lib/context.js +1 -1
- package/lib/fiber-renders.js +1 -1
- package/lib/flow-fetch.js +1 -1
- package/lib/hoc.js +1 -1
- package/lib/identity.js +1 -1
- package/lib/lensmcp-root.js +1 -1
- package/lib/page-perf.js +1 -1
- package/lib/page-visit-runtime.js +1 -1
- package/lib/page-visits.js +1 -1
- package/lib/publish.js +1 -1
- package/lib/route-flows.js +1 -1
- package/lib/router-pattern.js +1 -1
- package/lib/trace-slot.js +1 -1
- package/lib/traced-hooks.js +1 -1
- package/package.json +2 -2
package/lib/babel-plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var l=(o,e)=>C(o,"name",{value:e,configurable:!0});var L=Object.defineProperty,c=l((o,e)=>L(o,"name",{value:e,configurable:!0}),"a");const $=4;export function displaySourcePath(o,e){const n=c(p=>p.replace(/\\/g,"/").replace(/\/+$/,"").split("/"),"segments"),t=n(o),i=n(e);let r=0;for(;r<t.length&&r<i.length&&t[r]===i[r];)r++;const a=i.length-r;if(r===0||a>4)return`<external>/${t[t.length-1]??"unknown"}`;const s=t.slice(r);return s.length===0?"<external>/unknown":[...new Array(a).fill(".."),...s].join("/")}l(displaySourcePath,"displaySourcePath"),c(displaySourcePath,"displaySourcePath");const x="@lensmcp/react-instrumentation",y=new Map([["useEffect","tracedUseEffect"],["useMemo","tracedUseMemo"],["useCallback","tracedUseCallback"]]),J=new Set(y.values());function m(o){return`useLensmcp_${o}`}l(m,"S"),c(m,"tracedHookLocalName");function f(o){return J.has(o)?m(o):o}l(f,"b"),c(f,"helperLocalName");const R=["onClick","onDoubleClick","onContextMenu","onSubmit","onChange"],P=new Map([["onSubmit","form-submit"],["onChange","input-change"]]);export default function j(o){const e=o.types;return{name:"@lensmcp/react-instrumentation/babel-plugin",visitor:{Program:{enter(n,t){if(t.needHelpers=new Set,t.needRoot=!1,t.hookIndex=0,t.flowEvents=new Set(t.opts.flowEvents??R),t.rootVars=new Set,t.opts.production??process.env.NODE_ENV==="production"){t.fileIgnored=!0;return}(n.node.body[0]?.leadingComments??n.node.directives.flatMap(r=>r.leadingComments??[])??[]).some(r=>r.value.includes("@lensmcp-ignore"))&&(t.fileIgnored=!0);const i=t.file?.opts?.filename;i&&(t.relativePath=displaySourcePath(i,t.opts.rootDir??process.cwd()))},exit(n,t){if(t.fileIgnored)return;const i=[...t.needHelpers??[]];if(t.needRoot&&i.push("LensmcpRoot","installFlowFetch"),i.length===0)return;const r=I(n.node.body,x,e),a=i.filter(s=>r.get(f(s))!==s);if(a.length>0&&n.node.body.unshift(e.importDeclaration(a.map(s=>e.importSpecifier(e.identifier(f(s)),e.identifier(s))),e.stringLiteral(x))),t.needRoot){const s=n.node.body.findIndex(d=>!e.isImportDeclaration(d)),p=e.expressionStatement(e.callExpression(e.identifier("installFlowFetch"),[]));n.node.body.splice(s<0?n.node.body.length:s,0,p)}}},VariableDeclarator(n,t){t.fileIgnored||t.opts.autoWrapRoot!==!1&&e.isIdentifier(n.node.id)&&n.node.init&&h(n.node.init,e)&&t.rootVars.add(n.node.id.name)},CallExpression(n,t){if(t.fileIgnored)return;const i=n.node.callee,r=t.opts.autoWrapHooks!==!1&&e.isIdentifier(i)?y.get(i.name):void 0;if(r){const a=`${t.relativePath??"(anon)"}:${n.node.loc?.start.line??0}:${t.hookIndex++}`;n.node.callee=e.identifier(m(r)),n.node.arguments.unshift(e.stringLiteral(a)),t.needHelpers.add(r);return}if(t.opts.autoWrapRoot!==!1&&e.isMemberExpression(i)&&e.isIdentifier(i.property,{name:"render"})&&(h(i.object,e)||e.isIdentifier(i.object)&&t.rootVars?.has(i.object.name))&&n.node.arguments.length>=1){const a=n.node.arguments[0];a&&!E(a,e)&&(n.node.arguments[0]=e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("LensmcpRoot"),[],!1),e.jsxClosingElement(e.jsxIdentifier("LensmcpRoot")),[e.jsxExpressionContainer(a)],!1),t.needRoot=!0)}},JSXOpeningElement(n,t){if(t.fileIgnored)return;const i=n.node.attributes;if(g(i,"data-agent-component")||g(i,"data-lensmcp-ignore")||(n.parent.leadingComments??n.node.leadingComments??[]).some(s=>s.value.includes("@lensmcp-ignore")))return;if(t.opts.autoFlowHandlers!==!1){const s=n.node.loc?.start.line??0,p=t.relativePath??"(anon)";for(const d of n.node.attributes){if(d.type!=="JSXAttribute"||d.name.type!=="JSXIdentifier"||!t.flowEvents.has(d.name.name)||!d.value||d.value.type!=="JSXExpressionContainer")continue;const u=d.value.expression;if(u.type==="JSXEmptyExpression"||S(u,e))continue;const b=d.name.name;d.value.expression=e.callExpression(e.identifier("withFlow"),[u,e.objectExpression([e.objectProperty(e.identifier("originType"),e.stringLiteral(P.get(b)??"user-click")),e.objectProperty(e.identifier("originNodeId"),e.stringLiteral(`ui:${p}:${s}:${b}`))])]),t.needHelpers.add("withFlow")}}const r=v(n.node.name);if(!r||w(r))return;const a=[e.jsxAttribute(e.jsxIdentifier("data-agent-component"),e.stringLiteral(r))];if(t.opts.includeSource!==!1){const s=n.node.loc?.start.line??0,p=t.relativePath??"(anon)";a.push(e.jsxAttribute(e.jsxIdentifier("data-agent-source"),e.stringLiteral(`${p}:${s}`)))}n.node.attributes.push(...a)}}}}l(j,"v"),c(j,"lensmcpBabelPlugin");function g(o,e){return o.some(n=>n.type==="JSXAttribute"&&n.name.type==="JSXIdentifier"&&n.name.name===e)}l(g,"x"),c(g,"hasAttr");function I(o,e,n){const t=new Map;for(const i of o)if(n.isImportDeclaration(i)&&i.source.value===e)for(const r of i.specifiers)n.isImportSpecifier(r)&&n.isIdentifier(r.imported)&&t.set(r.local.name,r.imported.name);return t}l(I,"L"),c(I,"collectImported");function h(o,e){if(!e.isCallExpression(o))return!1;const n=o.callee,t=new Set(["createRoot","hydrateRoot"]);return e.isIdentifier(n)?t.has(n.name):e.isMemberExpression(n)&&e.isIdentifier(n.property)?t.has(n.property.name):!1}l(h,"I"),c(h,"isRootFactoryCall");function S(o,e){return e.isCallExpression(o)&&e.isIdentifier(o.callee,{name:"withFlow"})}l(S,"j"),c(S,"isAlreadyWithFlow");function E(o,e){return e.isJSXElement(o)&&e.isJSXIdentifier(o.openingElement.name,{name:"LensmcpRoot"})}l(E,"A"),c(E,"isAlreadyLensmcpRoot");const X=new Set(["Fragment","StrictMode","Suspense","SuspenseList","Profiler"]);function w(o){const e=o.split(".").pop()??o;return X.has(e)?!0:e.endsWith("Provider")||e.endsWith("Consumer")}l(w,"P"),c(w,"isUnstampableElement");function v(o){switch(o.type){case"JSXIdentifier":return o.name;case"JSXMemberExpression":{const e=[];let n=o;for(;n.type==="JSXMemberExpression";)e.unshift(n.property.name),n=n.object;return n.type==="JSXIdentifier"&&e.unshift(n.name),e.join(".")}case"JSXNamespacedName":return`${o.namespace.name}:${o.name.name}`;default:return}}l(v,"R"),c(v,"describeElementName");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var t=(n,e)=>a(n,"name",{value:e,configurable:!0});var _=Object.defineProperty,o=t((n,e)=>_(n,"name",{value:e,configurable:!0}),"r");import{useId as p,useRef as m}from"react";export function readOwnerName(n){try{if(!n)return;const e=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE??n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;if(!e)return;const u=e.A,r=((typeof u?.getOwner=="function"?u.getOwner():null)??e.owner??e.ReactCurrentOwner?.current)?.type;if(!r)return;if(typeof r=="string")return r;const c=r.displayName??r.name;return typeof c=="string"&&c.length>0?c:void 0}catch{return}}t(readOwnerName,"readOwnerName"),o(readOwnerName,"readOwnerName");export function composeComponentIdentity(n,e){return{componentInstanceId:`react:component:${e??"fn"}${n}`,...e?{componentLogicalId:`react:component:${e}`,componentName:e}:{}}}t(composeComponentIdentity,"composeComponentIdentity"),o(composeComponentIdentity,"composeComponentIdentity");function i(){try{return readOwnerName(require("react"))}catch{return}}t(i,"f"),o(i,"currentOwnerName");export function useComponentIdentity(){const n=p(),e=m(void 0);return e.current||(e.current=composeComponentIdentity(n,i())),e.current}t(useComponentIdentity,"useComponentIdentity"),o(useComponentIdentity,"useComponentIdentity");
|
package/lib/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var n=(e,t)=>r(e,"name",{value:t,configurable:!0});var o=Object.defineProperty,s=n((e,t)=>o(e,"name",{value:t,configurable:!0}),"t");import{createContext as c,useContext as a}from"react";const p={rendererId:"lensmcp-root"};export const LensmcpContext=c(p);export function useLensmcpContext(){return a(LensmcpContext)}n(useLensmcpContext,"useLensmcpContext"),s(useLensmcpContext,"useLensmcpContext");
|
package/lib/fiber-renders.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var j=Object.defineProperty;var u=(e,t)=>j(e,"name",{value:t,configurable:!0});var A=Object.defineProperty,m=u((e,t)=>A(e,"name",{value:t,configurable:!0}),"d");import{makeInstanceId as $}from"./identity.js";import{publish as N}from"./publish.js";import{notePageCommit as W}from"./page-visit-runtime.js";import{patternOf as G,routeMatchesOf as K}from"./router-pattern.js";const B=1,U=0,Z=1,q=11,H=13,E=14,X=15,P=15e3,D=25,_=15,Y=8,R=(typeof process<"u"?process.env?.LENSMCP_RENDER_INCLUDE_INTERNALS:void 0)==="1",J=new Set(["Insertion","EmotionGlobal","EmotionCssPropInternal","GlobalStyles","ThemeProvider","CacheProvider"]);function I(e){return!!(J.has(e)||e.startsWith("Styled(")&&/^Styled\([a-z][a-zA-Z0-9-]*\)$/.test(e)||e==="lensmcp-root"||e.startsWith("Lensmcp"))}u(I,"R"),m(I,"isInternalRender");let v=!1,y=!1;const Q={};function k(e){const t=e.type;if(!(t==null||typeof t=="string"))switch(e.tag){case U:case Z:return t.displayName||t.name||void 0;case q:return t.displayName||t.render?.displayName||t.render?.name||void 0;case E:case X:return t.displayName||t.type?.displayName||t.type?.name||t.name||void 0;default:return}}u(k,"O"),m(k,"componentNameOf");function z(e){const t=e.alternate?.memoizedProps,s=e.memoizedProps;if(!t||!s||t===s)return[];const r=[];for(const o of Object.keys(s))if(o!=="children"&&!Object.is(t[o],s[o])&&(r.push(o),r.length>=Y))break;return r}u(z,"H"),m(z,"changedPropKeys");const w=new WeakMap;function F(e,t){const s=w.get(e);if(s)return s;const r=e.alternate,o=(r?w.get(r):void 0)??$(t).instanceId;return w.set(e,o),r&&w.set(r,o),o}u(F,"Y"),m(F,"stableInstanceId");const M=m(e=>e.alternate==null||e.child!==e.alternate.child,"childrenChanged");function O(e){const t=[];let s=0,r=!1,o,l=!1;const a=[],i=m((n,d,p)=>{for(let h=n.child;h;h=h.sibling)a.push({node:h,parentName:d,...p?{wrapperName:p}:{}})},"pushChildren");for(M(e.current)&&i(e.current,void 0);a.length>0;){const{node:n,parentName:d,wrapperName:p}=a.pop();if(s+=1,s>P){r=!0;break}let h=d;const g=n.memoizedProps?K(n.memoizedProps):void 0;if(g&&g.length>=(o?.length??0)&&(o=g),n.tag===H&&n.memoizedState!=null&&(l=!0),n.tag===E){M(n)&&i(n,d,k(n));continue}const c=k(n)??p,L=(n.flags&B)!==0;if(c&&L){const C=n.alternate==null,b=[];if(!C){const S=z(n);S.length>0&&b.push({type:"props",changedKeys:S}),d&&b.push({type:"parent-render",parentRenderId:d}),b.length===0&&b.push({type:"react-state",hookIndex:-1})}t.push({name:c,instanceId:F(n,`react:component:(fiber):${c}`),phase:C?"mount":"update",durationMs:typeof n.actualDuration=="number"?n.actualDuration:0,why:b,parentName:d}),h=c}M(n)&&i(n,h)}const f=o?G(o):void 0;return{renders:t,cut:r,suspense:l,...f?{pattern:f}:{}}}u(O,"Z"),m(O,"collectCommitRenders");let T;export function activeCommitId(){return T}u(activeCommitId,"activeCommitId"),m(activeCommitId,"activeCommitId");export function fiberRendersActive(){return v&&!y}u(fiberRendersActive,"fiberRendersActive"),m(fiberRendersActive,"fiberRendersActive");function x(e,t,s=!1){const r=R?e:e.filter(a=>!I(a.name));if(r.length===0)return;const o=$("react:commit").instanceId;T=o;const l=r.length>D?[...r].sort((a,i)=>i.durationMs-a.durationMs).slice(0,D):r;for(const a of l){const i=`react:component:(fiber):${a.name}`,{instanceId:f}=$(i),n={id:f,commitId:o,componentInstanceId:a.instanceId,componentLogicalId:i,componentName:a.name,rendererId:"fiber",phase:a.phase,actualDurationMs:a.durationMs,baseDurationMs:a.durationMs,startTime:t,commitTime:t,why:a.why};N({source:"react",category:"render",severity:"info",title:`render ${a.name} (${a.phase})`,fingerprint:`react-render:${i}`,raw:{kind:"render",render:n}})}if(r.length>l.length||s){const a=s?`at least ${r.length}`:String(r.length);N({source:"react",category:"render",severity:"debug",title:s?`render commit truncated: the walk stopped at ${P} fibers \u2014 ${a} renders, ${l.length} recorded`:`render commit truncated: ${r.length-l.length} of ${r.length} renders dropped (per-commit cap)`,fingerprint:"react-render:commit-truncated",raw:{kind:"render-commit-truncated",commitId:o,total:r.length,published:l.length,...s?{walkStoppedAt:P}:{}}})}}u(x,"q"),m(x,"publishRecords");export function installFiberRenderPublisher(){if(v||y||typeof window>"u")return;const e=window.__LENSMCP_FIBER__;if(!e||typeof e.subscribe!="function")return;v=!0;let t=_,s=0;const r=new Map;let o=0,l;const a=m(()=>{if(l=void 0,t=_,s===0)return;const i=[...r.entries()].sort((d,p)=>p[1]-d[1]).slice(0,5),f=i.length>0?`top: ${i.map(([d,p])=>`${d}\xD7${p}`).join(", ")}`:"no product component in the commits \u2014 all framework-internal",n=o>0?` (+${o} framework-internal)`:"";N({source:"react",category:"render",severity:"warning",title:`render storm: ${s} commits/s over budget \u2014 ${f}${n}`,fingerprint:"react-render:storm",raw:{kind:"render-storm",commits:s,components:Object.fromEntries(i),internalRenders:o}}),s=0,o=0,r.clear()},"flushStorm");e.subscribe((i,f)=>{if(!y)try{if(!f||!f.current)return;const{renders:n,cut:d,pattern:p,suspense:h}=O(f),g=R?n:n.filter(c=>!I(c.name));if(W(Q,{at:Date.now(),renders:g.map(c=>({name:c.name,ms:c.durationMs,mount:c.phase==="mount"})),storm:t<=0,suspense:h,...p?{pattern:p}:{}}),n.length===0)return;if(t>0)t-=1,x(n,Date.now(),d);else{s+=1;for(const c of n){if(!R&&I(c.name)){o+=1;continue}r.set(c.name,(r.get(c.name)??0)+1)}}l||(l=setTimeout(a,1e3))}catch{y=!0}})}u(installFiberRenderPublisher,"installFiberRenderPublisher"),m(installFiberRenderPublisher,"installFiberRenderPublisher");export function resetFiberRenderPublisherForTests(){v=!1,y=!1}u(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests"),m(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests");
|
package/lib/flow-fetch.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var q=Object.defineProperty;var c=(t,r)=>q(t,"name",{value:r,configurable:!0});var j=Object.defineProperty,f=c((t,r)=>j(t,"name",{value:r,configurable:!0}),"d");import{beginBackgroundFlow as G,extendFlowWindow as E,flowForNewActivity as M,publish as $}from"./publish.js";import{installRouteFlows as C}from"./route-flows.js";import{notePageFetch as b,pageVisitOpen as D,startHardPageVisit as U}from"./page-visit-runtime.js";export function mayPropagateTo(t,r=[]){const g=typeof location<"u"?location.href:void 0;let d;try{d=new URL(t,g)}catch{return!1}if(typeof location<"u"&&d.origin===location.origin||H(d.hostname))return!0;for(const n of r){let i;try{i=new URL(n).origin}catch{continue}if(i===d.origin)return!0}return!1}c(mayPropagateTo,"mayPropagateTo"),f(mayPropagateTo,"mayPropagateTo");const W=new Set(["localhost","[::1]","::1"]);function H(t){const r=t.toLowerCase();return W.has(r)||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(r)}c(H,"j"),f(H,"isLoopbackHost");function F(){const t=globalThis.__LENSMCP_FLOW_PROPAGATE__;return Array.isArray(t)?t.filter(r=>typeof r=="string"):typeof t=="string"?t.split(",").map(r=>r.trim()).filter(Boolean):[]}c(F,"k"),f(F,"globalPropagateList");function x(){return Date.now().toString(36)+Math.random().toString(36).slice(2,12)}c(x,"O"),f(x,"newRequestId");function w(t){return typeof t=="string"?t:t instanceof URL?t.href:t.url??String(t)}c(w,"w"),f(w,"urlOf");const N=Symbol.for("lensmcp.flow-fetch"),S=Symbol.for("lensmcp.flow-fetch.recorded-leg");function m(t){return{...t,[S]:!0}}c(m,"T"),f(m,"markRecorded");let R=!1;export function installFlowFetch(t={}){const r=globalThis;if(typeof r.fetch!="function")return()=>{};if(r.fetch[N])return()=>{};if(!R&&typeof location<"u"&&typeof document<"u"){R=!0;const e=G({originType:"page-load",originNodeId:`page:${location.pathname}`});U(e.flowId)}const g=t.flowHeader??"x-lensmcp-flow-id",d=t.originHeader??"x-lensmcp-origin-node-id",n=t.requestHeader??"x-request-id",i=t.propagateTo??[],s=r.fetch.bind(globalThis);globalThis.__LENSMCP_FLOW_FETCH__=!0;const a=f(((e,o)=>{if(o?.[S])return s(e,o);const l=M();if(!l?.flowId){if(!D())return s(e,o);const h=w(e);if(!mayPropagateTo(h,[...i,...F()])){const P=s(e,m(o));return b(P,y(e,o),h,void 0,void 0),P}const T=new Headers(o?.headers??(typeof e=="object"&&e!==null&&"headers"in e?e.headers:void 0)??void 0),L=T.get(n)??x();T.has(n)||T.set(n,L);const _=s(e,{...m(o),headers:T});return b(_,y(e,o),h,L,void 0),_}if(!mayPropagateTo(w(e),[...i,...F()])){const h=s(e,m(o));return k(l,e,o,h,void 0),b(h,y(e,o),w(e),void 0,l.flowId),h}const O=typeof e=="object"&&e!==null&&"headers"in e?e.headers:void 0,u=new Headers(o?.headers??O??void 0);u.has(g)||u.set(g,l.flowId),l.originNodeId&&!u.has(d)&&u.set(d,l.originNodeId);const v=u.get(n)??x();u.has(n)||u.set(n,v);const I=s(e,{...m(o),headers:u});return k(l,e,o,I,v),b(I,y(e,o),w(e),v,l.flowId),I}),"patched");a[N]=!0,r.fetch=a;const p=t.routeFlows===!1?()=>{}:C();return()=>{p(),r.fetch=s}}c(installFlowFetch,"installFlowFetch"),f(installFlowFetch,"installFlowFetch");function y(t,r){return r?.method??(typeof t=="object"&&t!==null&&"method"in t?t.method??"GET":"GET")}c(y,"b"),f(y,"methodOf");function A(t){const r=typeof location<"u"?location.href:void 0;try{return new URL(t,r).href}catch{return}}c(A,"U"),f(A,"absoluteHref");function k(t,r,g,d,n){const i=w(r),s=A(i),a=g?.method??(typeof r=="object"&&r!==null&&"method"in r?r.method??"GET":"GET"),p=Date.now(),e={flowId:t.flowId,...t.originType?{originType:t.originType}:{},...t.originNodeId?{originNodeId:t.originNodeId}:{},...n?{requestId:n}:{}};$({source:"react",category:"network",severity:"info",title:`fetch ${a} ${i}`,fingerprint:`flow-fetch:${a}:${i}`,context:e,raw:{kind:"fetch-start",url:i,method:a,...s?{href:s}:{},...n?{requestId:n}:{}}}),d.then(o=>{E(t),$({source:"react",category:"network",severity:o.ok||o.status===304?"info":"error",title:`fetch ${a} ${i} \u2192 ${o.status}${o.statusText?` ${o.statusText}`:""}`,fingerprint:`flow-fetch:${a}:${i}:${o.status}`,context:e,raw:{kind:"fetch-done",url:i,...s?{href:s}:{},...n?{requestId:n}:{},method:a,status:o.status,statusText:o.statusText,ok:o.ok,startedAt:p,durationMs:Date.now()-p}})},o=>{E(t),$({source:"react",category:"network",severity:"error",title:`fetch ${a} ${i} failed`,message:o instanceof Error?o.message:String(o),fingerprint:`flow-fetch:${a}:${i}:error`,context:e,raw:{kind:"fetch-error",url:i,...s?{href:s}:{},...n?{requestId:n}:{},method:a,startedAt:p,durationMs:Date.now()-p}})})}c(k,"P"),f(k,"publishFetchLeg");
|
package/lib/hoc.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=Object.defineProperty;var o=(e,n)=>I(e,"name",{value:n,configurable:!0});var T=Object.defineProperty,i=o((e,n)=>T(e,"name",{value:n,configurable:!0}),"t");import{jsx as d}from"react/jsx-runtime";import{Profiler as w}from"react";import{publish as $}from"./publish.js";import{makeInstanceId as g}from"./identity.js";export function withTraceComponent(e,n={}){const r=n.componentName??e.displayName??e.name??"TracedComponent",t=`react:component:${n.source??"(unknown)"}:${r}`;function a(p){let m;return d(w,{id:t,onRender:i((b,s,u,f,l,h)=>{const{instanceId:c}=g(t),y={id:c,parentRenderId:m,componentInstanceId:c,componentLogicalId:t,componentName:r,phase:s==="mount"?"mount":"update",actualDurationMs:u,baseDurationMs:f,startTime:l,commitTime:h,why:[{type:"force",reason:"withTraceComponent"}]};m=c,$({source:"react",category:"render",severity:"info",title:`render ${r} (${s})`,fingerprint:`react-render:${t}`,raw:{kind:"render",render:y}})},"onRender"),children:d(e,{...p})})}return o(a,"a"),i(a,"Traced"),a.displayName=`Traced(${r})`,a}o(withTraceComponent,"withTraceComponent"),i(withTraceComponent,"withTraceComponent");
|
package/lib/identity.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var e=(n,t)=>f(n,"name",{value:t,configurable:!0});var p=Object.defineProperty,o=e((n,t)=>p(n,"name",{value:t,configurable:!0}),"n");const s=new Map;let i=0;export function nextGeneration(n){const t=(s.get(n)??0)+1;return s.set(n,t),t}e(nextGeneration,"nextGeneration"),o(nextGeneration,"nextGeneration");export function shortHash(){return i=(i+1)%4294967295,(Date.now()&4095^i).toString(36).slice(-4)}e(shortHash,"shortHash"),o(shortHash,"shortHash");export function componentLogicalId(n,t){return`react:component:${n}:${t}`}e(componentLogicalId,"componentLogicalId"),o(componentLogicalId,"componentLogicalId");export function hookLogicalId(n,t,a,r){return`react:hook:${n}:${t}:${a}:${r}`}e(hookLogicalId,"hookLogicalId"),o(hookLogicalId,"hookLogicalId");export function slotLogicalId(n,t,a){return`react:slot:${n}:${t}:${a}`}e(slotLogicalId,"slotLogicalId"),o(slotLogicalId,"slotLogicalId");export function makeInstanceId(n){const t=nextGeneration(n);return{instanceId:`${n}#${t}#${shortHash()}`,generation:t}}e(makeInstanceId,"makeInstanceId"),o(makeInstanceId,"makeInstanceId");export function depsHash(n){if(!n)return"no-deps";let t=5381;const a=o(r=>{for(let c=0;c<r.length;c++)t=t*33^r.charCodeAt(c);t=t*33^59},"mix");for(const r of n){if(r===null){a("null");continue}const c=typeof r;a(c==="object"||c==="function"?`ref:${l(r)}`:`${c}:${String(r)}`)}return(t>>>0).toString(36)}e(depsHash,"depsHash"),o(depsHash,"depsHash");const u=new WeakMap;let d=1;function l(n){let t=u.get(n);return t===void 0&&(t=d++,u.set(n,t)),t}e(l,"p"),o(l,"refId");export function resetIdentityState(){s.clear(),i=0}e(resetIdentityState,"resetIdentityState"),o(resetIdentityState,"resetIdentityState");
|
package/lib/lensmcp-root.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var i=(e,r)=>w(e,"name",{value:r,configurable:!0});var
|
|
1
|
+
"use strict";var w=Object.defineProperty;var i=(e,r)=>w(e,"name",{value:r,configurable:!0});var y=Object.defineProperty,p=i((e,r)=>y(e,"name",{value:r,configurable:!0}),"c");import{jsx as u}from"react/jsx-runtime";import{Profiler as M,useMemo as $,useRef as s}from"react";import{LensmcpContext as L}from"./context.js";import{publish as P}from"./publish.js";import{makeInstanceId as x}from"./identity.js";import{fiberRendersActive as j,installFiberRenderPublisher as k}from"./fiber-renders.js";typeof window<"u"&&k();export function LensmcpRoot(e){const r=e.rendererId??"lensmcp-root",f=$(()=>({rendererId:r,page:e.page,route:e.route}),[r,e.page,e.route]),l=s(new Map),d=s(new Map),c=s(void 0),I=p((t,m,g,v,b,R)=>{const a=`render:${r}:${t}`,{instanceId:n}=x(a);let o=d.current.get(t);o===void 0&&(o=n,d.current.set(t,o));const h={id:n,parentRenderId:c.current,componentInstanceId:o,componentLogicalId:a,componentName:t,page:e.page,route:e.route,rendererId:r,phase:m==="mount"?"mount":"update",actualDurationMs:g,baseDurationMs:v,startTime:b,commitTime:R,why:[{type:"force",reason:"profiler-onrender"}]};c.current=n,l.current.set(t,n),!j()&&P({source:"react",category:"render",severity:"info",title:`render ${t} (${m})`,fingerprint:`react-render:${a}`,raw:{kind:"render",render:h}})},"onRender");return u(L.Provider,{value:f,children:u(M,{id:r,onRender:I,children:e.children})})}i(LensmcpRoot,"LensmcpRoot"),p(LensmcpRoot,"LensmcpRoot");
|
package/lib/page-perf.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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 T=600,M=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??""))||(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,v=0;for(const n of this.scripts)n.at<e.startAt||n.at>e.toAt||(f++,v+=n.kb);const m=this.host.heapBytes();return{...Object.keys(s).length?{vitals:s}:{},...u?{longTasks:{n:u,totalMs:h(d),maxMs:h(l)}}:{},...m!==void 0?{heapMb:h(m/(1<<20))}:{},...f?{chunks:{n:f,kb:Math.round(v)}}:{}}}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 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var i=(t,e)=>u(t,"name",{value:e,configurable:!0});var h=Object.defineProperty,n=i((t,e)=>h(t,"name",{value:e,configurable:!0}),"a");import{publish as y}from"./publish.js";import{PageVisitTracker as _}from"./page-visits.js";import{browserPerfHost as l,PagePerf as P}from"./page-perf.js";const p="__LENSMCP_PAGE_VISITS__";function f(){return typeof window<"u"&&typeof location<"u"&&typeof document<"u"}i(f,"y"),n(f,"browser");function d(){if(!f())return;const t=globalThis,e=t[p];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 c;try{const r=l();c=r?new P(r):void 0}catch{c=void 0}const o={tracker:new _({app:a,...c?{perf:n(r=>c.window(r),"perf")}:{},emit:n((r,s)=>y({source:"react",category:"performance",severity:r.readyBy==="timeout"?"warning":"info",title:s,fingerprint:`page-visit:${r.visitId}:${r.phase}`,detached:!0,raw:r}),"emit"),tabId:n(()=>{try{return sessionStorage.getItem("lensmcp:tabId")??void 0}catch{return}},"tabId"),base:n(()=>location.href,"base")}),hardStarted:!1};t[p]=o;try{window.addEventListener("beforeunload",()=>o.tracker.pagehide()),window.addEventListener("pagehide",()=>o.tracker.pagehide()),window.addEventListener("error",r=>o.tracker.error(r.message||"error")),window.addEventListener("unhandledrejection",r=>{const s=r.reason;o.tracker.error(s instanceof Error?`${s.name}: ${s.message}`:String(s))})}catch{}return o}i(d,"f"),n(d,"shared");export function startHardPageVisit(t){const e=d();if(!(!e||e.hardStarted)){e.hardStarted=!0;try{const a=Date.now(),c=typeof performance<"u"&&typeof performance.timeOrigin=="number"?Math.round(performance.timeOrigin):a,o=(typeof performance<"u"&&typeof performance.getEntriesByType=="function"?performance.getEntriesByType("navigation")[0]:void 0)?.type,r=o==="navigate"||o==="reload"||o==="back_forward"?o:void 0;e.tracker.hard({path:location.pathname,startAt:Math.min(c,a),appStartAt:a,...r?{navType:r}:{},...g()?{cause:"hmr"}:{},...t?{flowId:t}:{}})}catch{}}}i(startHardPageVisit,"startHardPageVisit"),n(startHardPageVisit,"startHardPageVisit");function g(){if(globalThis.__LENSMCP_RELOAD_CAUSE__)return!0;try{return!!sessionStorage.getItem("lensmcp:reloadCause")}catch{return!1}}i(g,"_"),n(g,"hmrReload");export function notePageNavigation(t,e,a){try{d()?.tracker.navigate({path:t,how:e,...a?{flowId:a}:{}})}catch{}}i(notePageNavigation,"notePageNavigation"),n(notePageNavigation,"notePageNavigation");export function pageVisitOpen(){const t=globalThis[p];return!!t&&t.tracker.open()}i(pageVisitOpen,"pageVisitOpen"),n(pageVisitOpen,"pageVisitOpen");export function notePageFetch(t,e,a,c,o){const r=d();if(r)try{const s=r.tracker.fetchStarted({method:e,url:a,...c?{rid:c}:{},...o?{flowId:o}:{}});t.then(m=>s(m.status),()=>s(0))}catch{}}i(notePageFetch,"notePageFetch"),n(notePageFetch,"notePageFetch");export function notePageCommit(t,e){const a=d();if(a&&(a.commitsBy??=t,a.commitsBy===t))try{a.tracker.commit(e)}catch{}}i(notePageCommit,"notePageCommit"),n(notePageCommit,"notePageCommit");export function notePageState(t,e){const a=globalThis[p];if(a)try{a.tracker.storeUpdated(t,e)}catch{}}i(notePageState,"notePageState"),n(notePageState,"notePageState");
|
package/lib/page-visits.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var l=(a,e)=>v(a,"name",{value:e,configurable:!0});var f=Object.defineProperty,d=l((a,e)=>f(a,"name",{value:e,configurable:!0}),"o");export const QUIET_MS=100,READY_CAP_MS=3e4,NO_COMMIT_MS=1e3,END_AFTER_READY_MS=6e4;const g=60,C=200,I=8,S=20,y={now:d(()=>Date.now(),"now"),setTimeout:d((a,e)=>setTimeout(a,e),"setTimeout"),clearTimeout:d(a=>clearTimeout(a),"clearTimeout")},c=d((a,e=200)=>a.length>e?a.slice(0,e):a,"clip");function u(a){let e=2166136261;for(let t=0;t<a.length;t++)e^=a.charCodeAt(t),e=Math.imul(e,16777619);return(e>>>0).toString(36)}l(u,"l"),d(u,"shortHash");export function templatePath(a){return a.split("/").map(e=>/^\d+$/.test(e)||/^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(e)||/^[0-9a-zA-Z_-]{20,}$/.test(e)?":id":e).join("/")}l(templatePath,"templatePath"),d(templatePath,"templatePath");const A=d(()=>({commits:0,renders:0,renderMs:0,maxCommitMs:0,stormCommits:0,mounts:0,suspenseWaits:0,byName:new Map}),"newTally");let w=0;const T=d(a=>`pv-${a.toString(36)}-${(++w).toString(36)}${Math.random().toString(36).slice(2,6)}`,"newVisitId");export class PageVisitTracker{static{l(this,"PageVisitTracker")}static{d(this,"PageVisitTracker")}constructor(e){this.opts=e,this.clock=e.clock??y}current(){return this.visit}open(){return this.visit!==void 0}hard(e){this.begin({nav:"hard",path:e.path,startAt:e.startAt,appStartAt:e.appStartAt,...e.navType?{navType:e.navType}:{},...e.cause?{cause:e.cause}:{},...e.flowId?{flowId:e.flowId}:{}})}navigate(e){const t=this.visit;if(!(t&&c(e.path)===t.path)){if(t&&e.how==="replace"&&t.readyAt===void 0){t.redirectedFrom??=t.path,t.path=c(e.path),t.pattern=void 0,e.flowId&&t.flowIds.add(e.flowId);return}this.begin({nav:"spa",path:e.path,startAt:this.clock.now(),navType:e.how,...e.flowId?{flowId:e.flowId}:{}})}}fetchStarted(e){const t=this.visit;if(!t)return()=>{};const s=this.clock.now();e.flowId&&t.flowIds.add(e.flowId);const o=this.where(e.url),r=t.readyAt!==void 0;let i;if(t.requests.length<60?(i={rid:e.rid??"",m:e.method.toUpperCase(),p:o.p,...o.qh?{qh:o.qh}:{},s:Math.max(0,s-t.startAt),...e.flowId?{flowId:e.flowId}:{},...r?{late:!0}:{}},t.requests.push(i)):t.dropped++,r)return t.after.requests++,t.after.templates.size<20&&t.after.templates.add(`${e.method.toUpperCase()} ${templatePath(o.path)}`),m=>{i&&(i.d=Math.max(0,this.clock.now()-t.startAt-i.s),i.st=m)};t.open++,this.cancelCandidate(t),this.clearTimer(t,"noCommit");let p=!1;return m=>{p||(p=!0,i&&(i.d=Math.max(0,this.clock.now()-t.startAt-i.s),i.st=m),!(this.visit!==t||t.readyAt!==void 0)&&(t.open=Math.max(0,t.open-1),t.open===0&&(t.noCommit=this.clock.setTimeout(()=>{t.noCommit=void 0,this.visit===t&&t.readyAt===void 0&&t.open===0&&this.ready(t,t.lastCommitAt??this.clock.now(),"no-commit")},1e3))))}}commit(e){const t=this.visit;if(t){if(e.pattern&&t.readyBy===void 0&&(t.pattern=e.pattern),t.readyAt!==void 0){t.after.renders+=e.renders.length;return}if(e.renders.length>0){const s=t.r;s.commits++,s.renders+=e.renders.length;let o=0;for(const r of e.renders){r.ms>o&&(o=r.ms),r.mount&&s.mounts++;const i=s.byName.get(r.name);i?(i.n++,i.ms+=r.ms):s.byName.set(r.name,{n:1,ms:r.ms})}s.renderMs+=o,o>s.maxCommitMs&&(s.maxCommitMs=o),e.storm&&s.stormCommits++}if(e.suspense&&t.r.suspenseWaits++,t.lastCommitAt=e.at,this.clearTimer(t,"noCommit"),t.open>0||e.suspense){this.cancelCandidate(t);return}this.cancelCandidate(t),t.candidate=e.at,t.quiet=this.clock.setTimeout(()=>{t.quiet=void 0,!(this.visit!==t||t.readyAt!==void 0||t.candidate===void 0)&&this.ready(t,t.candidate,t.requests.length?"settled":"no-requests")},100)}}storeUpdated(e,t){const s=this.visit;if(!s)return;if(s.readyAt!==void 0){s.after.updates++;return}s.updates++;const o=`${e}\0${t}`,r=s.byStore.get(o);r?r.n++:s.byStore.size<200&&s.byStore.set(o,{store:e,path:c(t,120),n:1})}error(e){const t=this.visit;t&&(t.errors++,t.firstError??=c(e,200))}pagehide(){this.visit&&this.finish(this.visit)}begin(e){this.visit&&this.finish(this.visit);const t={id:T(e.startAt),nav:e.nav,...e.navType?{navType:e.navType}:{},...e.cause?{cause:e.cause}:{},path:c(e.path),startAt:e.startAt,...e.appStartAt!==void 0?{appStartAt:e.appStartAt}:{},flowIds:new Set(e.flowId?[e.flowId]:[]),requests:[],dropped:0,open:0,r:A(),updates:0,byStore:new Map,errors:0,after:{requests:0,templates:new Set,renders:0,updates:0}};this.visit=t,t.cap=this.clock.setTimeout(()=>{t.cap=void 0,this.visit===t&&t.readyAt===void 0&&this.ready(t,this.clock.now(),"timeout")},Math.max(0,3e4-(this.clock.now()-t.startAt)))}ready(e,t,s){e.readyAt=s==="left"?void 0:t,e.readyBy=s,this.clearTimer(e,"quiet"),this.clearTimer(e,"noCommit"),this.clearTimer(e,"cap"),e.candidate=void 0,this.send(e,"ready"),s!=="left"&&(e.end=this.clock.setTimeout(()=>{e.end=void 0,this.visit===e&&this.finish(e)},6e4))}finish(e){e.readyBy===void 0&&this.ready(e,this.clock.now(),"left");for(const t of["quiet","noCommit","cap","end"])this.clearTimer(e,t);this.send(e,"end"),this.visit===e&&(this.visit=void 0)}send(e,t){const s=e.r,o=this.opts.tabId?.(),r=e.readyAt!==void 0?Math.max(0,e.readyAt-e.startAt):void 0,i={kind:"page-visit",phase:t,visitId:e.id,...o?{tabId:o}:{},app:this.opts.app,...e.pattern?{pattern:e.pattern}:{},path:e.path,nav:e.nav,...e.navType?{navType:e.navType}:{},...e.cause?{cause:e.cause}:{},...e.redirectedFrom?{redirectedFrom:e.redirectedFrom}:{},startAt:e.startAt,...e.readyAt!==void 0?{readyAt:e.readyAt}:{},...e.readyBy?{readyBy:e.readyBy}:{},...r!==void 0?{readyMs:r}:{},...r!==void 0&&e.appStartAt!==void 0?{appReadyMs:Math.max(0,e.readyAt-e.appStartAt)}:{},...t==="end"?{endAt:this.clock.now()}:{},flowIds:[...e.flowIds].slice(0,20),requests:e.requests.map(n=>({...n})),...e.dropped?{requestsDropped:e.dropped}:{},renders:{commits:s.commits,renders:s.renders,renderMs:Math.round(s.renderMs*10)/10,maxCommitMs:Math.round(s.maxCommitMs*10)/10,stormCommits:s.stormCommits,mounts:s.mounts,suspenseWaits:s.suspenseWaits,top:[...s.byName.entries()].sort((n,h)=>h[1].n-n[1].n||h[1].ms-n[1].ms).slice(0,8).map(([n,h])=>({name:n,n:h.n,ms:Math.round(h.ms*10)/10}))},store:{updates:e.updates,top:[...e.byStore.values()].sort((n,h)=>h.n-n.n).slice(0,8)},errors:{n:e.errors,...e.firstError?{first:e.firstError}:{}},...t==="end"?{afterReady:{requests:e.after.requests,templates:[...e.after.templates],renders:e.after.renders,updates:e.after.updates}}:{}};try{const n=t==="ready"?e.readyAt??this.clock.now():this.clock.now();this.opts.perf&&Object.assign(i,this.opts.perf({startAt:e.startAt,toAt:n,hard:e.nav==="hard"}))}catch{}const p=e.pattern??e.path,m=t==="end"?`page visit ended ${p}`:e.readyBy==="left"?`page left before ready ${p}`:e.readyBy==="timeout"?`page not ready in ${3e4/1e3}s ${p} \u2014 ${e.requests.filter(n=>n.d===void 0).length} requests open`:`page ready ${p} \xB7 ${r} ms`;try{this.opts.emit(i,m)}catch{}}where(e){try{const t=new URL(e,this.opts.base?.()??"http://localhost/"),s=t.search.length>1?u(t.search):void 0;return{p:c(`${t.host}${t.pathname}`),path:t.pathname,...s?{qh:s}:{}}}catch{const[t=""]=e.split("?");return{p:c(t),path:t}}}cancelCandidate(e){e.candidate=void 0,this.clearTimer(e,"quiet")}clearTimer(e,t){e[t]!==void 0&&(this.clock.clearTimeout(e[t]),e[t]=void 0)}}
|
package/lib/publish.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var O=Object.defineProperty;var t=(e,o)=>O(e,"name",{value:o,configurable:!0});var W=Object.defineProperty,n=t((e,o)=>W(e,"name",{value:o,configurable:!0}),"t");import{createEventFloodGuard as U,estimateJsonBytes as $}from"@lensmcp/protocol-types";const u=[],X=200,M=(()=>{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 s=0;function S(e){const o=$(e,M);for(u.push(e),I.push(o),s+=o;u.length>X||s>M&&u.length>1;)u.shift(),s-=I.shift()??0;u.length===0&&(s=0)}t(S,"k"),n(S,"enqueue");function L(){const e=u.shift();return s-=I.shift()??0,u.length===0&&(s=0),e}t(L,"D"),n(L,"dequeue");export function queuedByteCount(){return s}t(queuedByteCount,"queuedByteCount"),n(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,"N"),n(N,"parseMaxLifetime");function E(){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(E,"P"),n(E,"ambientMaxMs");export function configureAmbientFlows(e){y=e.maxLifetimeMs===void 0?void 0:N(e.maxLifetimeMs)}t(configureAmbientFlows,"configureAmbientFlows"),n(configureAmbientFlows,"configureAmbientFlows");const d=new Map,j=16;function B(e){for(d.set(e,{bornAt:Date.now()});d.size>j;)d.delete(d.keys().next().value)}t(B,"X"),n(B,"trackAmbient");function b(e){const o=d.get(e.flowId);if(!o)return!1;const i=E();return i!==1/0&&Date.now()-o.bornAt>=i}t(b,"h"),n(b,"ambientExhausted");export function extendFlowWindow(e){const o=e??currentFlow()??c?.spec;o&&(b(o)||(c={spec:o,until:Date.now()+F}))}t(extendFlowWindow,"extendFlowWindow"),n(extendFlowWindow,"extendFlowWindow");function a(){return c&&Date.now()<c.until?c.spec:void 0}t(a,"y"),n(a,"windowedFlow");export function activeFlow(){return currentFlow()??a()}t(activeFlow,"activeFlow"),n(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},B(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}:{}}}),o}t(beginBackgroundFlow,"beginBackgroundFlow"),n(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"),n(flowForNewActivity,"flowForNewActivity");export const FLOW_ORIGIN_FINGERPRINT_PREFIX="flow-origin:";function _(e,o){return`${FLOW_ORIGIN_FINGERPRINT_PREFIX}${e}:${o}`}t(_,"x"),n(_,"originFingerprint");export function setPublisher(e){if(globalThis.__LENSMCP_PUBLISH__=e,e)for(;u.length;){const o=L();if(o)try{e(o)}catch{}}}t(setPublisher,"setPublisher"),n(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"),n(runInFlow,"runInFlow");export function currentFlow(){return p[p.length-1]}t(currentFlow,"currentFlow"),n(currentFlow,"currentFlow");const A=Symbol.for("lensmcp.flowed"),P=2e3,f=new Map;function k(e){if(e==null||typeof e!="object")return;const o=e,i=o.nativeEvent;if(i!=null&&typeof i=="object"){const r=i.isTrusted;if(typeof r=="boolean")return r}if(typeof o.isTrusted=="boolean")return o.isTrusted}t(k,"v"),n(k,"eventTrust");function D(e){if(!(f.size<=64))for(const[o,i]of f)e>=i.until&&f.delete(o)}t(D,"Q"),n(D,"pruneInputBursts");export function withFlow(e,o={}){if(typeof e!="function"||e[A])return e;const i=n(()=>{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}})},"publishOrigin"),r=n(function(...l){if(o.originType==="input-change"){if(k(l[0])===!1)return currentFlow()==null&&a()!=null&&extendFlowWindow(),e(...l);const v=o.originNodeId??"input",w=Date.now(),g=f.get(v);if(g&&w<g.until)return g.until=w+P,runInFlow(g.spec,()=>e(...l));const x={flowId:h(),originType:"input-change",originNodeId:o.originNodeId};return f.set(v,{spec:x,until:w+P}),D(w),runInFlow(x,()=>(i(),e(...l)))}const C=h();return runInFlow({flowId:C,originType:o.originType??"user-click",originNodeId:o.originNodeId},()=>(i(),e(...l)))},"flowed");return r[A]=!0,r}t(withFlow,"withFlow"),n(withFlow,"withFlow");let m=0;function h(){return m=(m+1)%65535,`flow:${Date.now().toString(36)}:${m.toString(36)}`}t(h,"b"),n(h,"newFlowId");export function publish(e){if(e.detached){const{detached:r,...l}=e;T(l);return}const o=currentFlow()??(e.context?.flowId?void 0:a()),i=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(i)}t(publish,"publish"),n(publish,"publish");function T(e){const o=globalThis.__LENSMCP_PUBLISH__;if(o)try{o(e);return}catch{}S(e)}t(T,"L"),n(T,"deliver");const q=U({burst:30,perSec:5});export function publishLazy(e,o){const i=e.startsWith(FLOW_ORIGIN_FINGERPRINT_PREFIX)?{ok:!0,suppressed:0}:q.admit(e);if(!i.ok)return;const r=o();if(i.suppressed>0&&r.raw!==null&&typeof r.raw=="object"){publish({...r,raw:{...r.raw,floodSuppressed:i.suppressed}});return}publish(r)}t(publishLazy,"publishLazy"),n(publishLazy,"publishLazy");export function resetFlowStateForTests(){p.length=0,c=void 0,d.clear(),f.clear(),y=void 0}t(resetFlowStateForTests,"resetFlowStateForTests"),n(resetFlowStateForTests,"resetFlowStateForTests");export function drainQueue(){return I.length=0,s=0,u.splice(0,u.length)}t(drainQueue,"drainQueue"),n(drainQueue,"drainQueue");
|
package/lib/route-flows.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var w=Object.defineProperty;var r=(e,t)=>w(e,"name",{value:t,configurable:!0});var L=Object.defineProperty,o=r((e,t)=>L(e,"name",{value:t,configurable:!0}),"e");import{activeFlow as S,beginBackgroundFlow as N}from"./publish.js";import{notePageNavigation as _}from"./page-visit-runtime.js";const b=200;function g(){const e=globalThis.window;if(!e?.history||!e.location||typeof e.addEventListener!="function"||typeof e.removeEventListener!="function")return;const t=e.__LENSMCP_NAV__;return t&&typeof t.subscribe=="function"?{history:e.history,location:e.location,navBus:t,addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}:e}r(g,"v"),o(g,"browserEnvironment");export function routeNodeId(e){return`route:${e.length>b?e.slice(0,b):e}`}r(routeNodeId,"routeNodeId"),o(routeNodeId,"routeNodeId");let c;export function installRouteFlows(e=g()){if(!e)return()=>{};if(c)return()=>{};let t=e.location.pathname,p=!0;const l=o(u=>{if(!p)return;const n=e.location.pathname;if(n===t)return;t=n;const i=S();_(n,u,i?.flowId),!i&&N({originType:"route-load",originNodeId:routeNodeId(n)})},"navigated"),d=o((u,n)=>o(function(...i){const E=u.apply(this,i);try{l(n)}catch{}return E},"wrapped"),"wrap"),v=e.history.pushState,h=e.history.replaceState,f=d(v,"push"),y=d(h,"replace"),a=o(()=>l("pop"),"popped");e.history.pushState=f,e.history.replaceState=y;const s=e.navBus?e.navBus.subscribe(a):void 0;s||e.addEventListener("popstate",a,{capture:!0});const m=o(()=>{p=!1,s?s():e.removeEventListener("popstate",a,{capture:!0}),e.history.pushState===f&&(e.history.pushState=v),e.history.replaceState===y&&(e.history.replaceState=h),c=void 0},"uninstall");return c=m,m}r(installRouteFlows,"installRouteFlows"),o(installRouteFlows,"installRouteFlows");
|
package/lib/router-pattern.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var n=(e,t)=>f(e,"name",{value:t,configurable:!0});var i=Object.defineProperty,c=n((e,t)=>i(e,"name",{value:t,configurable:!0}),"r");export function routeMatchesOf(e){if(!e||typeof e!="object")return;const t=e;if(!t.match||typeof t.match!="object"||!t.match.route||typeof t.match.route!="object")return;const r=t.routeContext?.matches;return Array.isArray(r)?r:void 0}n(routeMatchesOf,"routeMatchesOf"),c(routeMatchesOf,"routeMatchesOf");export function patternOf(e){if(!e.length)return;let t="";for(const a of e){const o=a?.route?.path;typeof o!="string"||o===""||(t=o.startsWith("/")?o:`${t.replace(/\/?\*$/,"")}/${o}`)}const r=`/${t.split("/").filter(Boolean).join("/")}`;return r.length>300?r.slice(0,300):r}n(patternOf,"patternOf"),c(patternOf,"patternOf");
|
package/lib/trace-slot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var o=(e,n)=>m(e,"name",{value:n,configurable:!0});var p=Object.defineProperty,a=o((e,n)=>p(e,"name",{value:n,configurable:!0}),"c");import{jsx as d}from"react/jsx-runtime";import{Children as l,Fragment as y,useEffect as I,useRef as u}from"react";import{publish as g}from"./publish.js";import{makeInstanceId as b}from"./identity.js";import{useLensmcpContext as h}from"./context.js";export function TraceSlot(e){const n=h(),t=u(void 0),c=u(void 0);c.current||(c.current=b(`react:slot:${e.id}`).instanceId);const i=c.current,r=f(e.children);return I(()=>{if(t.current!==r){const s=t.current;t.current=r,g({source:"react",category:"render",severity:"info",title:`slot ${e.id}: ${s??"(none)"} \u2192 ${r}`,fingerprint:`slot-change:${e.id}`,raw:{kind:"slot-content-changed",slot:{slotLogicalId:`react:slot:${e.id}`,slotInstanceId:i,fromComponent:s,toComponent:r,componentInstanceId:n.componentInstanceId}}})}},[r,e.id,i,n.componentInstanceId]),d(y,{children:e.children})}o(TraceSlot,"TraceSlot"),a(TraceSlot,"TraceSlot");function f(e){const n=l.toArray(e)[0];if(!n)return"(empty)";if(typeof n=="string"||typeof n=="number")return"(text)";if(typeof n=="boolean")return"(boolean)";if(Array.isArray(n))return"(array)";if(typeof n=="object"&&n&&"type"in n){const t=n.type;return typeof t=="string"?t:typeof t=="function"?t.displayName??t.name??"AnonymousComponent":"unknown"}return"unknown"}o(f,"g"),a(f,"describeChild");
|
package/lib/traced-hooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.defineProperty;var p=(e,n)=>b(e,"name",{value:n,configurable:!0});var w=Object.defineProperty,f=p((e,n)=>w(e,"name",{value:n,configurable:!0}),"p");import{useCallback as $,useEffect as H,useMemo as M,useRef as i}from"react";import{useComponentIdentity as k}from"./component-identity.js";import{useLensmcpContext as y}from"./context.js";import{depsHash as v}from"./identity.js";import{publish as m}from"./publish.js";import{activeCommitId as I}from"./fiber-renders.js";export function tracedUseEffect(e,n,r){const a=y(),s=k(),u=l(e),o=i(void 0);H(()=>{const t=typeof performance<"u"&&performance.now?performance.now():Date.now(),c=v(r),d=o.current;o.current=c;let h;try{h=n()}finally{const g=typeof performance<"u"&&performance.now?performance.now():Date.now();m({source:"react",category:"render",severity:"info",title:`effect-run ${e}`,fingerprint:`effect-run:${e}`,raw:{kind:"effect-run",effect:{...I()?{commitId:I()}:{},hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,depsHash:c,prevDepsHash:d,durationMs:Math.max(0,g-t)}}})}return()=>{typeof h=="function"&&h(),m({source:"react",category:"render",severity:"info",title:`effect-cleanup ${e}`,fingerprint:`effect-cleanup:${e}`,raw:{kind:"effect-run",effect:{...I()?{commitId:I()}:{},hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,depsHash:o.current??c,durationMs:0,cleanupRan:!0}}})}},r)}p(tracedUseEffect,"tracedUseEffect"),f(tracedUseEffect,"tracedUseEffect");export function tracedUseMemo(e,n,r){const a=y(),s=k(),u=l(e),o=i(void 0),t=v(r),c=t!==o.current,d=M(n,r??[]);return c&&m({source:"react",category:"render",severity:"debug",title:`useMemo recomputed ${e}`,fingerprint:`hook-run:${e}`,raw:{kind:"hook-run",hook:{hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,hookType:"useMemo",depsHash:t,prevDepsHash:o.current,recomputed:!0}}}),o.current=t,d}p(tracedUseMemo,"tracedUseMemo"),f(tracedUseMemo,"tracedUseMemo");export function tracedUseCallback(e,n,r){const a=y(),s=k(),u=l(e),o=i(void 0),t=v(r),c=t!==o.current,d=$(n,r??[]);return c&&m({source:"react",category:"render",severity:"debug",title:`useCallback recomputed ${e}`,fingerprint:`hook-run:${e}`,raw:{kind:"hook-run",hook:{hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,hookType:"useCallback",depsHash:t,prevDepsHash:o.current,recomputed:!0}}}),o.current=t,d}p(tracedUseCallback,"tracedUseCallback"),f(tracedUseCallback,"tracedUseCallback");function l(e){const n=i(void 0);return n.current||(n.current=`${e}#${Math.random()*1e9|0}`),n.current}p(l,"H"),f(l,"useStableHookInstance");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/react-instrumentation",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.13",
|
|
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.
|
|
22
|
+
"@lensmcp/protocol-types": "1.25.13",
|
|
23
23
|
"tslib": "^2.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|