@lensmcp/react-instrumentation 1.19.0 → 1.20.0
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/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/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 j=Object.defineProperty;var d=(i,e)=>j(i,"name",{value:e,configurable:!0});var C=Object.defineProperty,c=d((i,e)=>C(i,"name",{value:e,configurable:!0}),"d"),J=Object.defineProperty,p=c((i,e)=>J(i,"name",{value:e,configurable:!0}),"a");const v="@lensmcp/react-instrumentation",w={useEffect:"tracedUseEffect",useMemo:"tracedUseMemo",useCallback:"tracedUseCallback"},R=["onClick","onDoubleClick","onContextMenu","onSubmit","onChange"],P={onSubmit:"form-submit",onChange:"input-change"};export default function E(i){const e=i.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(a=>a.leadingComments??[])??[]).some(a=>a.value.includes("@lensmcp-ignore"))&&(t.fileIgnored=!0);const o=t.file?.opts?.filename,r=t.opts.rootDir??process.cwd();o&&o.startsWith(r)?t.relativePath=o.slice(r.length).replace(/^\/+/,""):o&&(t.relativePath=o)},exit(n,t){if(t.fileIgnored)return;const o=[...t.needHelpers??[]];if(t.needRoot&&o.push("LensmcpRoot","installFlowFetch"),o.length===0)return;const r=b(n.node.body,v,e),a=o.filter(s=>!r.has(s));if(a.length>0&&n.node.body.unshift(e.importDeclaration(a.map(s=>e.importSpecifier(e.identifier(s),e.identifier(s))),e.stringLiteral(v))),t.needRoot){const s=n.node.body.findIndex(l=>!e.isImportDeclaration(l)),m=e.expressionStatement(e.callExpression(e.identifier("installFlowFetch"),[]));n.node.body.splice(s<0?n.node.body.length:s,0,m)}}},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 o=n.node.callee;if(t.opts.autoWrapHooks!==!1&&e.isIdentifier(o)&&w[o.name]){const r=w[o.name],a=`${t.relativePath??"(anon)"}:${n.node.loc?.start.line??0}:${t.hookIndex++}`;n.node.callee=e.identifier(r),n.node.arguments.unshift(e.stringLiteral(a)),t.needHelpers.add(r);return}if(t.opts.autoWrapRoot!==!1&&e.isMemberExpression(o)&&e.isIdentifier(o.property,{name:"render"})&&(f(o.object,e)||e.isIdentifier(o.object)&&t.rootVars?.has(o.object.name))&&n.node.arguments.length>=1){const r=n.node.arguments[0];r&&!x(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 o=n.node.attributes;if(u(o,"data-agent-component")||u(o,"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,m=t.relativePath??"(anon)";for(const l of n.node.attributes){if(l.type!=="JSXAttribute"||l.name.type!=="JSXIdentifier"||!t.flowEvents.has(l.name.name)||!l.value||l.value.type!=="JSXExpressionContainer")continue;const g=l.value.expression;if(g.type==="JSXEmptyExpression"||h(g,e))continue;const S=l.name.name;l.value.expression=e.callExpression(e.identifier("withFlow"),[g,e.objectExpression([e.objectProperty(e.identifier("originType"),e.stringLiteral(P[S]??"user-click")),e.objectProperty(e.identifier("originNodeId"),e.stringLiteral(`ui:${m}:${s}:${S}`))])]),t.needHelpers.add("withFlow")}}const r=y(n.node.name);if(!r||I(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,m=t.relativePath??"(anon)";a.push(e.jsxAttribute(e.jsxIdentifier("data-agent-source"),e.stringLiteral(`${m}:${s}`)))}n.node.attributes.push(...a)}}}}d(E,"v"),c(E,"y"),p(E,"lensmcpBabelPlugin");function u(i,e){return i.some(n=>n.type==="JSXAttribute"&&n.name.type==="JSXIdentifier"&&n.name.name===e)}d(u,"u"),c(u,"b"),p(u,"hasAttr");function b(i,e,n){const t=new Set;for(const o of i)if(n.isImportDeclaration(o)&&o.source.value===e)for(const r of o.specifiers)n.isImportSpecifier(r)&&n.isIdentifier(r.imported)&&t.add(r.imported.name);return t}d(b,"x"),c(b,"h"),p(b,"collectImported");function f(i,e){if(!e.isCallExpression(i))return!1;const n=i.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}d(f,"f"),c(f,"I"),p(f,"isRootFactoryCall");function h(i,e){return e.isCallExpression(i)&&e.isIdentifier(i.callee,{name:"withFlow"})}d(h,"I"),c(h,"v"),p(h,"isAlreadyWithFlow");function x(i,e){return e.isJSXElement(i)&&e.isJSXIdentifier(i.openingElement.name,{name:"LensmcpRoot"})}d(x,"y"),c(x,"C"),p(x,"isAlreadyLensmcpRoot");const X=new Set(["Fragment","StrictMode","Suspense","SuspenseList","Profiler"]);function I(i){const e=i.split(".").pop()??i;return X.has(e)?!0:e.endsWith("Provider")||e.endsWith("Consumer")}d(I,"E"),c(I,"L"),p(I,"isUnstampableElement");function y(i){switch(i.type){case"JSXIdentifier":return i.name;case"JSXMemberExpression":{const e=[];let n=i;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`${i.namespace.name}:${i.name.name}`;default:return}}d(y,"S"),c(y,"P"),p(y,"describeElementName");
|
package/lib/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var n=(e,t)=>o(e,"name",{value:t,configurable:!0});var s=Object.defineProperty,r=n((e,t)=>s(e,"name",{value:t,configurable:!0}),"n"),c=Object.defineProperty,a=r((e,t)=>c(e,"name",{value:t,configurable:!0}),"t");import{createContext as p,useContext as u}from"react";const m={rendererId:"lensmcp-root"};export const LensmcpContext=p(m);export function useLensmcpContext(){return u(LensmcpContext)}n(useLensmcpContext,"useLensmcpContext"),r(useLensmcpContext,"useLensmcpContext"),a(useLensmcpContext,"useLensmcpContext");
|
package/lib/fiber-renders.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=Object.defineProperty;var d=(t,e)=>I(t,"name",{value:e,configurable:!0});var R=Object.defineProperty,u=d((t,e)=>R(t,"name",{value:e,configurable:!0}),"d"),$=Object.defineProperty,l=u((t,e)=>$(t,"name",{value:e,configurable:!0}),"d");import{makeInstanceId as k}from"./identity.js";import{publish as h}from"./publish.js";const M=1,D=0,j=1,O=11,T=14,_=15,x=15e3,P=25,F=15,C=8;let b=!1,f=!1;function g(t){const e=t.type;if(!(e==null||typeof e=="string"))switch(t.tag){case D:case j:return e.displayName||e.name||void 0;case O:return e.displayName||e.render?.displayName||e.render?.name||void 0;case T:case _:return e.displayName||e.type?.displayName||e.type?.name||e.name||void 0;default:return}}d(g,"w"),u(g,"k"),l(g,"componentNameOf");function y(t){const e=t.alternate?.memoizedProps,o=t.memoizedProps;if(!e||!o||e===o)return[];const n=[];for(const r of Object.keys(o))if(r!=="children"&&!Object.is(e[r],o[r])&&(n.push(r),n.length>=C))break;return n}d(y,"N"),u(y,"C"),l(y,"changedPropKeys");function v(t){const e=[];let o=0;const n=[];for(t.current.child&&n.push({node:t.current.child,parentName:void 0});n.length>0;){const{node:r,parentName:a}=n.pop();if(o+=1,o>x)break;let c=a;const s=g(r),i=(r.flags&M)!==0;if(s&&i){const p=r.alternate==null,m=[];if(!p){const N=y(r);N.length>0&&m.push({type:"props",changedKeys:N}),a&&m.push({type:"parent-render",parentRenderId:a}),m.length===0&&m.push({type:"react-state",hookIndex:-1})}e.push({name:s,phase:p?"mount":"update",durationMs:typeof r.actualDuration=="number"?r.actualDuration:0,why:m,parentName:a}),c=s}r.sibling&&n.push({node:r.sibling,parentName:a}),r.child&&n.push({node:r.child,parentName:c})}return e}d(v,"v"),u(v,"D"),l(v,"collectCommitRenders");function w(t,e){const o=t.length>P?[...t].sort((n,r)=>r.durationMs-n.durationMs).slice(0,P):t;for(const n of o){const r=`react:component:(fiber):${n.name}`,{instanceId:a}=k(r),c={id:a,componentInstanceId:a,componentLogicalId:r,componentName:n.name,rendererId:"fiber",phase:n.phase,actualDurationMs:n.durationMs,baseDurationMs:n.durationMs,startTime:e,commitTime:e,why:n.why};h({source:"react",category:"render",severity:"info",title:`render ${n.name} (${n.phase})`,fingerprint:`react-render:${r}`,raw:{kind:"render",render:c}})}t.length>o.length&&h({source:"react",category:"render",severity:"debug",title:`render commit truncated: ${t.length-o.length} of ${t.length} renders dropped (per-commit cap)`,fingerprint:"react-render:commit-truncated",raw:{kind:"render-commit-truncated",total:t.length,published:o.length}})}d(w,"I"),u(w,"P"),l(w,"publishRecords");export function installFiberRenderPublisher(){if(b||f||typeof window>"u")return;const t=window.__LENSMCP_FIBER__;if(!t||typeof t.subscribe!="function")return;b=!0;let e=F,o=0;const n=new Map;let r;const a=l(()=>{if(r=void 0,e=F,o===0)return;const c=[...n.entries()].sort((s,i)=>i[1]-s[1]).slice(0,5);h({source:"react",category:"render",severity:"warning",title:`render storm: ${o} commits/s over budget \u2014 top: ${c.map(([s,i])=>`${s}\xD7${i}`).join(", ")}`,fingerprint:"react-render:storm",raw:{kind:"render-storm",commits:o,components:Object.fromEntries(c)}}),o=0,n.clear()},"flushStorm");t.subscribe((c,s)=>{if(!f)try{if(!s||!s.current)return;const i=v(s);if(i.length===0)return;if(e>0)e-=1,w(i,Date.now());else{o+=1;for(const p of i)n.set(p.name,(n.get(p.name)??0)+1)}r||(r=setTimeout(a,1e3))}catch{f=!0}})}d(installFiberRenderPublisher,"installFiberRenderPublisher"),u(installFiberRenderPublisher,"installFiberRenderPublisher"),l(installFiberRenderPublisher,"installFiberRenderPublisher");export function resetFiberRenderPublisherForTests(){b=!1,f=!1}d(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests"),u(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests"),l(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests");
|
package/lib/flow-fetch.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var $=Object.defineProperty;var l=(o,e)=>$(o,"name",{value:e,configurable:!0});var
|
|
1
|
+
"use strict";var $=Object.defineProperty;var l=(o,e)=>$(o,"name",{value:e,configurable:!0});var T=Object.defineProperty,f=l((o,e)=>T(o,"name",{value:e,configurable:!0}),"l"),b=Object.defineProperty,h=f((o,e)=>b(o,"name",{value:e,configurable:!0}),"f");import{activeFlow as F,beginBackgroundFlow as v,extendFlowWindow as p,publish as u}from"./publish.js";let y=!1;export function installFlowFetch(o={}){const e=globalThis;if(typeof e.fetch!="function")return()=>{};!y&&typeof location<"u"&&typeof document<"u"&&(y=!0,v({originType:"page-load",originNodeId:`page:${location.pathname}`}));const c=o.flowHeader??"x-lensmcp-flow-id",d=o.originHeader??"x-lensmcp-origin-node-id",r=e.fetch.bind(globalThis);globalThis.__LENSMCP_FLOW_FETCH__=!0;const i=h(((n,a)=>{const t=F();if(!t?.flowId)return r(n,a);const m=typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0,s=new Headers(a?.headers??m??void 0);s.has(c)||s.set(c,t.flowId),t.originNodeId&&!s.has(d)&&s.set(d,t.originNodeId);const w=r(n,{...a,headers:s});return g(t,n,a,w),w}),"patched");return e.fetch=i,()=>{e.fetch=r}}l(installFlowFetch,"installFlowFetch"),f(installFlowFetch,"installFlowFetch"),h(installFlowFetch,"installFlowFetch");function g(o,e,c,d){const r=typeof e=="string"?e:e instanceof URL?e.href:e.url??String(e),i=c?.method??(typeof e=="object"&&e!==null&&"method"in e?e.method??"GET":"GET"),n=Date.now(),a={flowId:o.flowId,...o.originType?{originType:o.originType}:{},...o.originNodeId?{originNodeId:o.originNodeId}:{}};u({source:"react",category:"network",severity:"info",title:`fetch ${i} ${r}`,fingerprint:`flow-fetch:${i}:${r}`,raw:{kind:"fetch-start",url:r,method:i}}),d.then(t=>{p(o),u({source:"react",category:"network",severity:t.ok?"info":"error",title:`fetch ${i} ${r} \u2192 ${t.status}${t.statusText?` ${t.statusText}`:""}`,fingerprint:`flow-fetch:${i}:${r}:${t.status}`,context:a,raw:{kind:"fetch-done",url:r,method:i,status:t.status,statusText:t.statusText,ok:t.ok,startedAt:n,durationMs:Date.now()-n}})},t=>{p(o),u({source:"react",category:"network",severity:"error",title:`fetch ${i} ${r} failed`,message:t instanceof Error?t.message:String(t),fingerprint:`flow-fetch:${i}:${r}:error`,context:a,raw:{kind:"fetch-error",url:r,method:i,startedAt:n,durationMs:Date.now()-n}})})}l(g,"p"),f(g,"m"),h(g,"publishFetchLeg");
|
package/lib/hoc.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var w=Object.defineProperty;var a=(e,n)=>w(e,"name",{value:n,configurable:!0});var I=Object.defineProperty,i=a((e,n)=>I(e,"name",{value:n,configurable:!0}),"o"),b=Object.defineProperty,m=i((e,n)=>b(e,"name",{value:n,configurable:!0}),"t");import{jsx as s}from"react/jsx-runtime";import{Profiler as $}from"react";import{publish as g}from"./publish.js";import{makeInstanceId as v}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 o(u){let d;return s($,{id:t,onRender:m((C,p,f,l,T,y)=>{const{instanceId:c}=v(t),h={id:c,parentRenderId:d,componentInstanceId:c,componentLogicalId:t,componentName:r,phase:p==="mount"?"mount":"update",actualDurationMs:f,baseDurationMs:l,startTime:T,commitTime:y,why:[{type:"force",reason:"withTraceComponent"}]};d=c,g({source:"react",category:"render",severity:"info",title:`render ${r} (${p})`,fingerprint:`react-render:${t}`,raw:{kind:"render",render:h}})},"onRender"),children:s(e,{...u})})}return a(o,"a"),i(o,"a"),m(o,"Traced"),o.displayName=`Traced(${r})`,o}a(withTraceComponent,"withTraceComponent"),i(withTraceComponent,"withTraceComponent"),m(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 n=(e,t)=>f(e,"name",{value:t,configurable:!0});var p=Object.defineProperty,o=n((e,t)=>p(e,"name",{value:t,configurable:!0}),"e"),I=Object.defineProperty,r=o((e,t)=>I(e,"name",{value:t,configurable:!0}),"n");const l=new Map;let s=0;export function nextGeneration(e){const t=(l.get(e)??0)+1;return l.set(e,t),t}n(nextGeneration,"nextGeneration"),o(nextGeneration,"nextGeneration"),r(nextGeneration,"nextGeneration");export function shortHash(){return s=(s+1)%4294967295,(Date.now()&4095^s).toString(36).slice(-4)}n(shortHash,"shortHash"),o(shortHash,"shortHash"),r(shortHash,"shortHash");export function componentLogicalId(e,t){return`react:component:${e}:${t}`}n(componentLogicalId,"componentLogicalId"),o(componentLogicalId,"componentLogicalId"),r(componentLogicalId,"componentLogicalId");export function hookLogicalId(e,t,i,c){return`react:hook:${e}:${t}:${i}:${c}`}n(hookLogicalId,"hookLogicalId"),o(hookLogicalId,"hookLogicalId"),r(hookLogicalId,"hookLogicalId");export function slotLogicalId(e,t,i){return`react:slot:${e}:${t}:${i}`}n(slotLogicalId,"slotLogicalId"),o(slotLogicalId,"slotLogicalId"),r(slotLogicalId,"slotLogicalId");export function makeInstanceId(e){const t=nextGeneration(e);return{instanceId:`${e}#${t}#${shortHash()}`,generation:t}}n(makeInstanceId,"makeInstanceId"),o(makeInstanceId,"makeInstanceId"),r(makeInstanceId,"makeInstanceId");export function depsHash(e){if(!e)return"no-deps";let t=5381;const i=r(c=>{for(let a=0;a<c.length;a++)t=t*33^c.charCodeAt(a);t=t*33^59},"mix");for(const c of e){if(c===null){i("null");continue}const a=typeof c;i(a==="object"||a==="function"?`ref:${u(c)}`:`${a}:${String(c)}`)}return(t>>>0).toString(36)}n(depsHash,"depsHash"),o(depsHash,"depsHash"),r(depsHash,"depsHash");const d=new WeakMap;let g=1;function u(e){let t=d.get(e);return t===void 0&&(t=g++,d.set(e,t)),t}n(u,"l"),o(u,"p"),r(u,"refId");export function resetIdentityState(){l.clear(),s=0}n(resetIdentityState,"resetIdentityState"),o(resetIdentityState,"resetIdentityState"),r(resetIdentityState,"resetIdentityState");
|
package/lib/lensmcp-root.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var y=Object.defineProperty;var a=(e,r)=>y(e,"name",{value:r,configurable:!0});var h=Object.defineProperty,c=a((e,r)=>h(e,"name",{value:r,configurable:!0}),"a"),w=Object.defineProperty,s=c((e,r)=>w(e,"name",{value:r,configurable:!0}),"d");import{jsx as m}from"react/jsx-runtime";import{Profiler as L,useMemo as $,useRef as p}from"react";import{LensmcpContext as M}from"./context.js";import{publish as P}from"./publish.js";import{makeInstanceId as x}from"./identity.js";import{installFiberRenderPublisher as j}from"./fiber-renders.js";typeof window<"u"&&j();export function LensmcpRoot(e){const r=e.rendererId??"lensmcp-root",u=$(()=>({rendererId:r,page:e.page,route:e.route}),[r,e.page,e.route]),f=p(new Map),i=p(void 0),l=s((n,d,g,v,I,b)=>{const t=`render:${r}:${n}`,{instanceId:o}=x(t),R={id:o,parentRenderId:i.current,componentInstanceId:o,componentLogicalId:t,componentName:n,page:e.page,route:e.route,rendererId:r,phase:d==="mount"?"mount":"update",actualDurationMs:g,baseDurationMs:v,startTime:I,commitTime:b,why:[{type:"force",reason:"profiler-onrender"}]};i.current=o,f.current.set(n,o),P({source:"react",category:"render",severity:"info",title:`render ${n} (${d})`,fingerprint:`react-render:${t}`,raw:{kind:"render",render:R}})},"onRender");return m(M.Provider,{value:u,children:m(L,{id:r,onRender:l,children:e.children})})}a(LensmcpRoot,"LensmcpRoot"),c(LensmcpRoot,"LensmcpRoot"),s(LensmcpRoot,"LensmcpRoot");
|
package/lib/publish.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var x=Object.defineProperty;var i=(n,o)=>x(n,"name",{value:o,configurable:!0});var B=Object.defineProperty,t=i((n,o)=>B(n,"name",{value:o,configurable:!0}),"i"),_=Object.defineProperty,e=t((n,o)=>_(n,"name",{value:o,configurable:!0}),"t");const l=[],S=200,a=[],k=4e3;let c;export function extendFlowWindow(n){const o=n??currentFlow()??c?.spec;o&&(c={spec:o,until:Date.now()+4e3})}i(extendFlowWindow,"extendFlowWindow"),t(extendFlowWindow,"extendFlowWindow"),e(extendFlowWindow,"extendFlowWindow");function f(){return c&&Date.now()<c.until?c.spec:void 0}i(f,"p"),t(f,"w"),e(f,"windowedFlow");export function activeFlow(){return currentFlow()??f()}i(activeFlow,"activeFlow"),t(activeFlow,"activeFlow"),e(activeFlow,"activeFlow");export function beginBackgroundFlow(n){const o={flowId:g(),originType:n.originType,...n.originNodeId?{originNodeId:n.originNodeId}:{}};return c={spec:o,until:Date.now()+4e3},publish({source:"react",category:"runtime",severity:"info",title:n.originType,fingerprint:`flow-origin:${n.originNodeId??n.originType}`,raw:{kind:"flow-origin",originNodeId:n.originNodeId}}),o}i(beginBackgroundFlow,"beginBackgroundFlow"),t(beginBackgroundFlow,"beginBackgroundFlow"),e(beginBackgroundFlow,"beginBackgroundFlow");export function setPublisher(n){if(globalThis.__LENSMCP_PUBLISH__=n,n)for(;l.length;){const o=l.shift();if(o)try{n(o)}catch{}}}i(setPublisher,"setPublisher"),t(setPublisher,"setPublisher"),e(setPublisher,"setPublisher");export function runInFlow(n,o){a.push(n),c={spec:n,until:Date.now()+4e3};try{return o()}finally{a.pop()}}i(runInFlow,"runInFlow"),t(runInFlow,"runInFlow"),e(runInFlow,"runInFlow");export function currentFlow(){return a[a.length-1]}i(currentFlow,"currentFlow"),t(currentFlow,"currentFlow"),e(currentFlow,"currentFlow");const F=Symbol.for("lensmcp.flowed"),T=2e3,s=new Map;function I(n){if(n==null||typeof n!="object")return;const o=n,r=o.nativeEvent;if(r!=null&&typeof r=="object"){const u=r.isTrusted;if(typeof u=="boolean")return u}if(typeof o.isTrusted=="boolean")return o.isTrusted}i(I,"T"),t(I,"S"),e(I,"eventTrust");function y(n){if(!(s.size<=64))for(const[o,r]of s)n>=r.until&&s.delete(o)}i(y,"b"),t(y,"F"),e(y,"pruneInputBursts");export function withFlow(n,o={}){if(typeof n!="function"||n[F])return n;const r=e(()=>{publish({source:"react",category:"runtime",severity:"info",title:o.originType??"user-click",fingerprint:`flow-origin:${o.originNodeId??"unknown"}`,raw:{kind:"flow-origin",originNodeId:o.originNodeId}})},"publishOrigin"),u=e(function(...d){if(o.originType==="input-change"){if(I(d[0])===!1)return currentFlow()==null&&f()!=null&&extendFlowWindow(),n(...d);const N=o.originNodeId??"input",w=Date.now(),p=s.get(N);if(p&&w<p.until)return p.until=w+T,runInFlow(p.spec,()=>n(...d));const b={flowId:g(),originType:"input-change",originNodeId:o.originNodeId};return s.set(N,{spec:b,until:w+T}),y(w),runInFlow(b,()=>(r(),n(...d)))}const v=g();return runInFlow({flowId:v,originType:o.originType??"user-click",originNodeId:o.originNodeId},()=>(r(),n(...d)))},"flowed");return u[F]=!0,u}i(withFlow,"withFlow"),t(withFlow,"withFlow"),e(withFlow,"withFlow");let h=0;function g(){return h=(h+1)%65535,`flow:${Date.now().toString(36)}:${h.toString(36)}`}i(g,"w"),t(g,"g"),e(g,"newFlowId");export function publish(n){const o=currentFlow()??(n.context?.flowId?void 0:f()),r=o==null?n:{...n,context:{...o.flowId?{flowId:o.flowId}:{},...o.originType?{originType:o.originType}:{},...o.originNodeId?{originNodeId:o.originNodeId}:{},...o.causedByNodeId?{causedByNodeId:o.causedByNodeId}:{},...n.context}},u=globalThis.__LENSMCP_PUBLISH__;if(u)try{u(r);return}catch{}l.length>=200&&l.shift(),l.push(r)}i(publish,"publish"),t(publish,"publish"),e(publish,"publish");export function drainQueue(){return l.splice(0,l.length)}i(drainQueue,"drainQueue"),t(drainQueue,"drainQueue"),e(drainQueue,"drainQueue");
|
package/lib/trace-slot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var o=(t,n)=>p(t,"name",{value:n,configurable:!0});var d=Object.defineProperty,a=o((t,n)=>d(t,"name",{value:n,configurable:!0}),"o"),l=Object.defineProperty,f=a((t,n)=>l(t,"name",{value:n,configurable:!0}),"c");import{jsx as y}from"react/jsx-runtime";import{Children as I,Fragment as g,useEffect as b,useRef as m}from"react";import{publish as h}from"./publish.js";import{makeInstanceId as v}from"./identity.js";import{useLensmcpContext as C}from"./context.js";export function TraceSlot(t){const n=C(),e=m(void 0),c=m(void 0);c.current||(c.current=v(`react:slot:${t.id}`).instanceId);const s=c.current,r=i(t.children);return b(()=>{if(e.current!==r){const u=e.current;e.current=r,h({source:"react",category:"render",severity:"info",title:`slot ${t.id}: ${u??"(none)"} \u2192 ${r}`,fingerprint:`slot-change:${t.id}`,raw:{kind:"slot-content-changed",slot:{slotLogicalId:`react:slot:${t.id}`,slotInstanceId:s,fromComponent:u,toComponent:r,componentInstanceId:n.componentInstanceId}}})}},[r,t.id,s,n.componentInstanceId]),y(g,{children:t.children})}o(TraceSlot,"TraceSlot"),a(TraceSlot,"TraceSlot"),f(TraceSlot,"TraceSlot");function i(t){const n=I.toArray(t)[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 e=n.type;return typeof e=="string"?e:typeof e=="function"?e.displayName??e.name??"AnonymousComponent":"unknown"}return"unknown"}o(i,"f"),a(i,"g"),f(i,"describeChild");
|
package/lib/traced-hooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var g=Object.defineProperty;var u=(e,r)=>g(e,"name",{value:r,configurable:!0});var v=Object.defineProperty,p=u((e,r)=>v(e,"name",{value:r,configurable:!0}),"u"),b=Object.defineProperty,i=p((e,r)=>b(e,"name",{value:r,configurable:!0}),"f");import{useCallback as w,useEffect as M,useMemo as $,useRef as m}from"react";import{useLensmcpContext as h}from"./context.js";import{depsHash as k}from"./identity.js";import{publish as l}from"./publish.js";export function tracedUseEffect(e,r,t){const a=h(),s=d(e),n=m(void 0);M(()=>{const o=typeof performance<"u"&&performance.now?performance.now():Date.now(),c=k(t),f=n.current;n.current=c;let I;try{I=r()}finally{const y=typeof performance<"u"&&performance.now?performance.now():Date.now();l({source:"react",category:"render",severity:"info",title:`effect-run ${e}`,fingerprint:`effect-run:${e}`,raw:{kind:"effect-run",effect:{hookInstanceId:s,hookLogicalId:e,componentInstanceId:a.componentInstanceId,depsHash:c,prevDepsHash:f,durationMs:Math.max(0,y-o)}}})}return()=>{typeof I=="function"&&I(),l({source:"react",category:"render",severity:"info",title:`effect-cleanup ${e}`,fingerprint:`effect-cleanup:${e}`,raw:{kind:"effect-run",effect:{hookInstanceId:s,hookLogicalId:e,componentInstanceId:a.componentInstanceId,depsHash:n.current??c,durationMs:0,cleanupRan:!0}}})}},t)}u(tracedUseEffect,"tracedUseEffect"),p(tracedUseEffect,"tracedUseEffect"),i(tracedUseEffect,"tracedUseEffect");export function tracedUseMemo(e,r,t){const a=h(),s=d(e),n=m(void 0),o=k(t),c=o!==n.current,f=$(r,t??[]);return c&&l({source:"react",category:"render",severity:"debug",title:`useMemo recomputed ${e}`,fingerprint:`hook-run:${e}`,raw:{kind:"hook-run",hook:{hookInstanceId:s,hookLogicalId:e,componentInstanceId:a.componentInstanceId,hookType:"useMemo",depsHash:o,prevDepsHash:n.current,recomputed:!0}}}),n.current=o,f}u(tracedUseMemo,"tracedUseMemo"),p(tracedUseMemo,"tracedUseMemo"),i(tracedUseMemo,"tracedUseMemo");export function tracedUseCallback(e,r,t){const a=h(),s=d(e),n=m(void 0),o=k(t),c=o!==n.current,f=w(r,t??[]);return c&&l({source:"react",category:"render",severity:"debug",title:`useCallback recomputed ${e}`,fingerprint:`hook-run:${e}`,raw:{kind:"hook-run",hook:{hookInstanceId:s,hookLogicalId:e,componentInstanceId:a.componentInstanceId,hookType:"useCallback",depsHash:o,prevDepsHash:n.current,recomputed:!0}}}),n.current=o,f}u(tracedUseCallback,"tracedUseCallback"),p(tracedUseCallback,"tracedUseCallback"),i(tracedUseCallback,"tracedUseCallback");function d(e){const r=m(void 0);return r.current||(r.current=`${e}#${Math.random()*1e9|0}`),r.current}u(d,"m"),p(d,"y"),i(d,"useStableHookInstance");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/react-instrumentation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
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.
|
|
22
|
+
"@lensmcp/protocol-types": "1.20.0",
|
|
23
23
|
"tslib": "^2.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|