@lensmcp/react-instrumentation 1.23.10 → 1.23.11
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/publish.js +1 -1
- package/lib/route-flows.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 v=Object.defineProperty;var a=(o,e)=>v(o,"name",{value:e,configurable:!0});var j=Object.defineProperty,d=a((o,e)=>j(o,"name",{value:e,configurable:!0}),"c");const X=4;export function displaySourcePath(o,e){const n=d(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 l=i.length-r;if(r===0||l>4)return`<external>/${t[t.length-1]??"unknown"}`;const s=t.slice(r);return s.length===0?"<external>/unknown":[...new Array(l).fill(".."),...s].join("/")}a(displaySourcePath,"displaySourcePath"),d(displaySourcePath,"displaySourcePath");const h="@lensmcp/react-instrumentation",b={useEffect:"tracedUseEffect",useMemo:"tracedUseMemo",useCallback:"tracedUseCallback"},C=["onClick","onDoubleClick","onContextMenu","onSubmit","onChange"],R={onSubmit:"form-submit",onChange:"input-change"};export default function w(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??C),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=x(n.node.body,h,e),l=i.filter(s=>!r.has(s));if(l.length>0&&n.node.body.unshift(e.importDeclaration(l.map(s=>e.importSpecifier(e.identifier(s),e.identifier(s))),e.stringLiteral(h))),t.needRoot){const s=n.node.body.findIndex(c=>!e.isImportDeclaration(c)),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&&f(n.node.init,e)&&t.rootVars.add(n.node.id.name)},CallExpression(n,t){if(t.fileIgnored)return;const i=n.node.callee;if(t.opts.autoWrapHooks!==!1&&e.isIdentifier(i)&&b[i.name]){const r=b[i.name],l=`${t.relativePath??"(anon)"}:${n.node.loc?.start.line??0}:${t.hookIndex++}`;n.node.callee=e.identifier(r),n.node.arguments.unshift(e.stringLiteral(l)),t.needHelpers.add(r);return}if(t.opts.autoWrapRoot!==!1&&e.isMemberExpression(i)&&e.isIdentifier(i.property,{name:"render"})&&(f(i.object,e)||e.isIdentifier(i.object)&&t.rootVars?.has(i.object.name))&&n.node.arguments.length>=1){const r=n.node.arguments[0];r&&!I(r,e)&&(n.node.arguments[0]=e.jsxElement(e.jsxOpeningElement(e.jsxIdentifier("LensmcpRoot"),[],!1),e.jsxClosingElement(e.jsxIdentifier("LensmcpRoot")),[e.jsxExpressionContainer(r)],!1),t.needRoot=!0)}},JSXOpeningElement(n,t){if(t.fileIgnored)return;const i=n.node.attributes;if(m(i,"data-agent-component")||m(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 c of n.node.attributes){if(c.type!=="JSXAttribute"||c.name.type!=="JSXIdentifier"||!t.flowEvents.has(c.name.name)||!c.value||c.value.type!=="JSXExpressionContainer")continue;const u=c.value.expression;if(u.type==="JSXEmptyExpression"||y(u,e))continue;const g=c.name.name;c.value.expression=e.callExpression(e.identifier("withFlow"),[u,e.objectExpression([e.objectProperty(e.identifier("originType"),e.stringLiteral(R[g]??"user-click")),e.objectProperty(e.identifier("originNodeId"),e.stringLiteral(`ui:${p}:${s}:${g}`))])]),t.needHelpers.add("withFlow")}}const r=E(n.node.name);if(!r||S(r))return;const l=[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)";l.push(e.jsxAttribute(e.jsxIdentifier("data-agent-source"),e.stringLiteral(`${p}:${s}`)))}n.node.attributes.push(...l)}}}}a(w,"y"),d(w,"lensmcpBabelPlugin");function m(o,e){return o.some(n=>n.type==="JSXAttribute"&&n.name.type==="JSXIdentifier"&&n.name.name===e)}a(m,"S"),d(m,"hasAttr");function x(o,e,n){const t=new Set;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.add(r.imported.name);return t}a(x,"h"),d(x,"collectImported");function f(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}a(f,"b"),d(f,"isRootFactoryCall");function y(o,e){return e.isCallExpression(o)&&e.isIdentifier(o.callee,{name:"withFlow"})}a(y,"C"),d(y,"isAlreadyWithFlow");function I(o,e){return e.isJSXElement(o)&&e.isJSXIdentifier(o.openingElement.name,{name:"LensmcpRoot"})}a(I,"j"),d(I,"isAlreadyLensmcpRoot");const J=new Set(["Fragment","StrictMode","Suspense","SuspenseList","Profiler"]);function S(o){const e=o.split(".").pop()??o;return J.has(e)?!0:e.endsWith("Provider")||e.endsWith("Consumer")}a(S,"P"),d(S,"isUnstampableElement");function E(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}}a(E,"A"),d(E,"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 C=Object.defineProperty;var a=(
|
|
1
|
+
"use strict";var C=Object.defineProperty;var a=(n,e)=>C(n,"name",{value:e,configurable:!0});var D=Object.defineProperty,d=a((n,e)=>D(n,"name",{value:e,configurable:!0}),"c");import{makeInstanceId as g}from"./identity.js";import{publish as y}from"./publish.js";const S=1,_=0,T=1,F=11,L=14,x=15,O=15e3,v=25,w=15,j=8,N=(typeof process<"u"?process.env?.LENSMCP_RENDER_INCLUDE_INTERNALS:void 0)==="1",A=new Set(["Insertion","EmotionGlobal","EmotionCssPropInternal","GlobalStyles","ThemeProvider","CacheProvider"]);function I(n){return!!(A.has(n)||n.startsWith("Styled(")&&/^Styled\([a-z][a-zA-Z0-9-]*\)$/.test(n)||n==="lensmcp-root"||n.startsWith("Lensmcp"))}a(I,"b"),d(I,"isInternalRender");let h=!1,f=!1;function R(n){const e=n.type;if(!(e==null||typeof e=="string"))switch(n.tag){case _:case T:return e.displayName||e.name||void 0;case F:return e.displayName||e.render?.displayName||e.render?.name||void 0;case L:case x:return e.displayName||e.type?.displayName||e.type?.name||e.name||void 0;default:return}}a(R,"O"),d(R,"componentNameOf");function $(n){const e=n.alternate?.memoizedProps,r=n.memoizedProps;if(!e||!r||e===r)return[];const o=[];for(const t of Object.keys(r))if(t!=="children"&&!Object.is(e[t],r[t])&&(o.push(t),o.length>=j))break;return o}a($,"$"),d($,"changedPropKeys");const b=new WeakMap;function P(n,e){const r=b.get(n);if(r)return r;const o=n.alternate,t=(o?b.get(o):void 0)??g(e).instanceId;return b.set(n,t),o&&b.set(o,t),t}a(P,"v"),d(P,"stableInstanceId");function k(n){const e=[];let r=0;const o=[];for(n.current.child&&o.push({node:n.current.child,parentName:void 0});o.length>0;){const{node:t,parentName:i}=o.pop();if(r+=1,r>O)break;let l=i;const c=R(t),m=(t.flags&S)!==0;if(c&&m){const u=t.alternate==null,s=[];if(!u){const p=$(t);p.length>0&&s.push({type:"props",changedKeys:p}),i&&s.push({type:"parent-render",parentRenderId:i}),s.length===0&&s.push({type:"react-state",hookIndex:-1})}e.push({name:c,instanceId:P(t,`react:component:(fiber):${c}`),phase:u?"mount":"update",durationMs:typeof t.actualDuration=="number"?t.actualDuration:0,why:s,parentName:i}),l=c}t.sibling&&o.push({node:t.sibling,parentName:i}),t.child&&o.push({node:t.child,parentName:l})}return e}a(k,"L"),d(k,"collectCommitRenders");let M;export function activeCommitId(){return M}a(activeCommitId,"activeCommitId"),d(activeCommitId,"activeCommitId");export function fiberRendersActive(){return h&&!f}a(fiberRendersActive,"fiberRendersActive"),d(fiberRendersActive,"fiberRendersActive");function E(n,e){const r=N?n:n.filter(i=>!I(i.name));if(r.length===0)return;const o=g("react:commit").instanceId;M=o;const t=r.length>v?[...r].sort((i,l)=>l.durationMs-i.durationMs).slice(0,v):r;for(const i of t){const l=`react:component:(fiber):${i.name}`,{instanceId:c}=g(l),m={id:c,commitId:o,componentInstanceId:i.instanceId,componentLogicalId:l,componentName:i.name,rendererId:"fiber",phase:i.phase,actualDurationMs:i.durationMs,baseDurationMs:i.durationMs,startTime:e,commitTime:e,why:i.why};y({source:"react",category:"render",severity:"info",title:`render ${i.name} (${i.phase})`,fingerprint:`react-render:${l}`,raw:{kind:"render",render:m}})}r.length>t.length&&y({source:"react",category:"render",severity:"debug",title:`render commit truncated: ${r.length-t.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:t.length}})}a(E,"G"),d(E,"publishRecords");export function installFiberRenderPublisher(){if(h||f||typeof window>"u")return;const n=window.__LENSMCP_FIBER__;if(!n||typeof n.subscribe!="function")return;h=!0;let e=w,r=0;const o=new Map;let t=0,i;const l=d(()=>{if(i=void 0,e=w,r===0)return;const c=[...o.entries()].sort((s,p)=>p[1]-s[1]).slice(0,5),m=c.length>0?`top: ${c.map(([s,p])=>`${s}\xD7${p}`).join(", ")}`:"no product component in the commits \u2014 all framework-internal",u=t>0?` (+${t} framework-internal)`:"";y({source:"react",category:"render",severity:"warning",title:`render storm: ${r} commits/s over budget \u2014 ${m}${u}`,fingerprint:"react-render:storm",raw:{kind:"render-storm",commits:r,components:Object.fromEntries(c),internalRenders:t}}),r=0,t=0,o.clear()},"flushStorm");n.subscribe((c,m)=>{if(!f)try{if(!m||!m.current)return;const u=k(m);if(u.length===0)return;if(e>0)e-=1,E(u,Date.now());else{r+=1;for(const s of u){if(!N&&I(s.name)){t+=1;continue}o.set(s.name,(o.get(s.name)??0)+1)}}i||(i=setTimeout(l,1e3))}catch{f=!0}})}a(installFiberRenderPublisher,"installFiberRenderPublisher"),d(installFiberRenderPublisher,"installFiberRenderPublisher");export function resetFiberRenderPublisherForTests(){h=!1,f=!1}a(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests"),d(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests");
|
package/lib/flow-fetch.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var c=(t,e)=>v(t,"name",{value:e,configurable:!0});var N=Object.defineProperty,l=c((t,e)=>N(t,"name",{value:e,configurable:!0}),"f");import{beginBackgroundFlow as H,extendFlowWindow as b,flowForNewActivity as P,publish as p}from"./publish.js";import{installRouteFlows as R}from"./route-flows.js";export function mayPropagateTo(t,e=[]){const d=typeof location<"u"?location.href:void 0;let f;try{f=new URL(t,d)}catch{return!1}if(typeof location<"u"&&f.origin===location.origin||I(f.hostname))return!0;for(const n of e){let r;try{r=new URL(n).origin}catch{continue}if(r===f.origin)return!0}return!1}c(mayPropagateTo,"mayPropagateTo"),l(mayPropagateTo,"mayPropagateTo");const S=new Set(["localhost","[::1]","::1"]);function I(t){const e=t.toLowerCase();return S.has(e)||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(e)}c(I,"S"),l(I,"isLoopbackHost");function x(){const t=globalThis.__LENSMCP_FLOW_PROPAGATE__;return Array.isArray(t)?t.filter(e=>typeof e=="string"):typeof t=="string"?t.split(",").map(e=>e.trim()).filter(Boolean):[]}c(x,"N"),l(x,"globalPropagateList");function F(){return Date.now().toString(36)+Math.random().toString(36).slice(2,12)}c(F,"O"),l(F,"newRequestId");function w(t){return typeof t=="string"?t:t instanceof URL?t.href:t.url??String(t)}c(w,"$"),l(w,"urlOf");let L=!1;export function installFlowFetch(t={}){const e=globalThis;if(typeof e.fetch!="function")return()=>{};!L&&typeof location<"u"&&typeof document<"u"&&(L=!0,H({originType:"page-load",originNodeId:`page:${location.pathname}`}));const d=t.flowHeader??"x-lensmcp-flow-id",f=t.originHeader??"x-lensmcp-origin-node-id",n=t.requestHeader??"x-request-id",r=t.propagateTo??[],s=e.fetch.bind(globalThis);globalThis.__LENSMCP_FLOW_FETCH__=!0;const a=l(((i,o)=>{const g=P();if(!g?.flowId)return s(i,o);if(!mayPropagateTo(w(i),[...r,...x()])){const $=s(i,o);return y(g,i,o,$,void 0),$}const k=typeof i=="object"&&i!==null&&"headers"in i?i.headers:void 0,u=new Headers(o?.headers??k??void 0);u.has(d)||u.set(d,g.flowId),g.originNodeId&&!u.has(f)&&u.set(f,g.originNodeId);const m=u.get(n)??F();u.has(n)||u.set(n,m);const T=s(i,{...o,headers:u});return y(g,i,o,T,m),T}),"patched");e.fetch=a;const h=t.routeFlows===!1?()=>{}:R();return()=>{h(),e.fetch=s}}c(installFlowFetch,"installFlowFetch"),l(installFlowFetch,"installFlowFetch");function _(t){const e=typeof location<"u"?location.href:void 0;try{return new URL(t,e).href}catch{return}}c(_,"R"),l(_,"absoluteHref");function y(t,e,d,f,n){const r=w(e),s=_(r),a=d?.method??(typeof e=="object"&&e!==null&&"method"in e?e.method??"GET":"GET"),h=Date.now(),i={flowId:t.flowId,...t.originType?{originType:t.originType}:{},...t.originNodeId?{originNodeId:t.originNodeId}:{},...n?{requestId:n}:{}};p({source:"react",category:"network",severity:"info",title:`fetch ${a} ${r}`,fingerprint:`flow-fetch:${a}:${r}`,context:i,raw:{kind:"fetch-start",url:r,method:a,...s?{href:s}:{},...n?{requestId:n}:{}}}),f.then(o=>{b(t),p({source:"react",category:"network",severity:o.ok||o.status===304?"info":"error",title:`fetch ${a} ${r} \u2192 ${o.status}${o.statusText?` ${o.statusText}`:""}`,fingerprint:`flow-fetch:${a}:${r}:${o.status}`,context:i,raw:{kind:"fetch-done",url:r,...s?{href:s}:{},...n?{requestId:n}:{},method:a,status:o.status,statusText:o.statusText,ok:o.ok,startedAt:h,durationMs:Date.now()-h}})},o=>{b(t),p({source:"react",category:"network",severity:"error",title:`fetch ${a} ${r} failed`,message:o instanceof Error?o.message:String(o),fingerprint:`flow-fetch:${a}:${r}:error`,context:i,raw:{kind:"fetch-error",url:r,...s?{href:s}:{},...n?{requestId:n}:{},method:a,startedAt:h,durationMs:Date.now()-h}})})}c(y,"b"),l(y,"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/publish.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var t=(e,o)=>C(e,"name",{value:o,configurable:!0});var O=Object.defineProperty,n=t((e,o)=>O(e,"name",{value:o,configurable:!0}),"t");import{createEventFloodGuard as W,estimateJsonBytes as U}from"@lensmcp/protocol-types";const u=[],$=200,v=(()=>{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 M(e){const o=U(e,v);for(u.push(e),I.push(o),s+=o;u.length>$||s>v&&u.length>1;)u.shift(),s-=I.shift()??0;u.length===0&&(s=0)}t(M,"W"),n(M,"enqueue");function S(){const e=u.shift();return s-=I.shift()??0,u.length===0&&(s=0),e}t(S,"k"),n(S,"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,"parseMaxLifetime");function L(){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(L,"D"),n(L,"ambientMaxMs");export function configureAmbientFlows(e){y=e.maxLifetimeMs===void 0?void 0:N(e.maxLifetimeMs)}t(configureAmbientFlows,"configureAmbientFlows"),n(configureAmbientFlows,"configureAmbientFlows");const l=new Map,X=16;function E(e){for(l.set(e,{bornAt:Date.now()});l.size>X;)l.delete(l.keys().next().value)}t(E,"C"),n(E,"trackAmbient");function b(e){const o=l.get(e.flowId);if(!o)return!1;const i=L();return i!==1/0&&Date.now()-o.bornAt>=i}t(b,"x"),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,"g"),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},E(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(_,"M"),n(_,"originFingerprint");export function setPublisher(e){if(globalThis.__LENSMCP_PUBLISH__=e,e)for(;u.length;){const o=S();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 B=Symbol.for("lensmcp.flowed"),A=2e3,f=new Map;function P(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(P,"v"),n(P,"eventTrust");function k(e){if(!(f.size<=64))for(const[o,i]of f)e>=i.until&&f.delete(o)}t(k,"X"),n(k,"pruneInputBursts");export function withFlow(e,o={}){if(typeof e!="function"||e[B])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(...d){if(o.originType==="input-change"){if(P(d[0])===!1)return currentFlow()==null&&a()!=null&&extendFlowWindow(),e(...d);const T=o.originNodeId??"input",w=Date.now(),g=f.get(T);if(g&&w<g.until)return g.until=w+A,runInFlow(g.spec,()=>e(...d));const x={flowId:h(),originType:"input-change",originNodeId:o.originNodeId};return f.set(T,{spec:x,until:w+A}),k(w),runInFlow(x,()=>(i(),e(...d)))}const D=h();return runInFlow({flowId:D,originType:o.originType??"user-click",originNodeId:o.originNodeId},()=>(i(),e(...d)))},"flowed");return r[B]=!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,"E"),n(h,"newFlowId");export function publish(e){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}},r=globalThis.__LENSMCP_PUBLISH__;if(r)try{r(i);return}catch{}M(i)}t(publish,"publish"),n(publish,"publish");const j=W({burst:30,perSec:5});export function publishLazy(e,o){const i=e.startsWith(FLOW_ORIGIN_FINGERPRINT_PREFIX)?{ok:!0,suppressed:0}:j.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,l.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 g=Object.defineProperty;var n=(e,o)=>g(e,"name",{value:o,configurable:!0});var S=Object.defineProperty,t=n((e,o)=>S(e,"name",{value:o,configurable:!0}),"e");import{activeFlow as m,beginBackgroundFlow as E}from"./publish.js";const f=200;function y(){const e=globalThis.window;if(!(!e?.history||!e.location||typeof e.addEventListener!="function"||typeof e.removeEventListener!="function"))return e}n(y,"E"),t(y,"browserEnvironment");export function routeNodeId(e){return`route:${e.length>f?e.slice(0,f):e}`}n(routeNodeId,"routeNodeId"),t(routeNodeId,"routeNodeId");let a;export function installRouteFlows(e=y()){if(!e)return()=>{};if(a)return()=>{};let o=e.location.pathname,s=!0;const i=t(()=>{if(!s)return;const r=e.location.pathname;r!==o&&(o=r,!m()&&E({originType:"route-load",originNodeId:routeNodeId(r)}))},"navigated"),u=t(r=>t(function(...v){const w=r.apply(this,v);try{i()}catch{}return w},"wrapped"),"wrap"),c=e.history.pushState,l=e.history.replaceState,p=u(c),h=u(l);e.history.pushState=p,e.history.replaceState=h,e.addEventListener("popstate",i);const d=t(()=>{s=!1,e.removeEventListener("popstate",i),e.history.pushState===p&&(e.history.pushState=c),e.history.replaceState===h&&(e.history.replaceState=l),a=void 0},"uninstall");return a=d,d}n(installRouteFlows,"installRouteFlows"),t(installRouteFlows,"installRouteFlows");
|
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.23.
|
|
3
|
+
"version": "1.23.11",
|
|
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.23.
|
|
22
|
+
"@lensmcp/protocol-types": "1.23.11",
|
|
23
23
|
"tslib": "^2.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|