@lensmcp/react-instrumentation 1.25.21 → 1.25.22

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.
@@ -1 +1 @@
1
- "use strict";var L=Object.defineProperty;var l=(o,e)=>L(o,"name",{value:e,configurable:!0});var P=Object.defineProperty,c=l((o,e)=>P(o,"name",{value:e,configurable:!0}),"l"),R=Object.defineProperty,d=c((o,e)=>R(o,"name",{value:e,configurable:!0}),"a");const F=4;export function displaySourcePath(o,e){const n=d(u=>u.replace(/\\/g,"/").replace(/\/+$/,"").split("/"),"segments"),t=n(o),r=n(e);let i=0;for(;i<t.length&&i<r.length&&t[i]===r[i];)i++;const a=r.length-i;if(i===0||a>4)return`<external>/${t[t.length-1]??"unknown"}`;const s=t.slice(i);return s.length===0?"<external>/unknown":[...new Array(a).fill(".."),...s].join("/")}l(displaySourcePath,"displaySourcePath"),c(displaySourcePath,"displaySourcePath"),d(displaySourcePath,"displaySourcePath");const j="@lensmcp/react-instrumentation",C=new Map([["useEffect","tracedUseEffect"],["useMemo","tracedUseMemo"],["useCallback","tracedUseCallback"]]),J=new Set(C.values());function m(o){return`useLensmcp_${o}`}l(m,"m"),c(m,"S"),d(m,"tracedHookLocalName");function f(o){return J.has(o)?m(o):o}l(f,"f"),c(f,"b"),d(f,"helperLocalName");const X=["onClick","onDoubleClick","onContextMenu","onSubmit","onChange"],$=new Map([["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??X),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(i=>i.leadingComments??[])??[]).some(i=>i.value.includes("@lensmcp-ignore"))&&(t.fileIgnored=!0);const r=t.file?.opts?.filename;r&&(t.relativePath=displaySourcePath(r,t.opts.rootDir??process.cwd()))},exit(n,t){if(t.fileIgnored)return;const r=[...t.needHelpers??[]];if(t.needRoot&&r.push("LensmcpRoot","installFlowFetch"),r.length===0)return;const i=x(n.node.body,j,e),a=r.filter(s=>i.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(j))),t.needRoot){const s=n.node.body.findIndex(p=>!e.isImportDeclaration(p)),u=e.expressionStatement(e.callExpression(e.identifier("installFlowFetch"),[]));n.node.body.splice(s<0?n.node.body.length:s,0,u)}}},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 r=n.node.callee,i=t.opts.autoWrapHooks!==!1&&e.isIdentifier(r)?C.get(r.name):void 0;if(i){const a=`${t.relativePath??"(anon)"}:${n.node.loc?.start.line??0}:${t.hookIndex++}`;n.node.callee=e.identifier(m(i)),n.node.arguments.unshift(e.stringLiteral(a)),t.needHelpers.add(i);return}if(t.opts.autoWrapRoot!==!1&&e.isMemberExpression(r)&&e.isIdentifier(r.property,{name:"render"})&&(h(r.object,e)||e.isIdentifier(r.object)&&t.rootVars?.has(r.object.name))&&n.node.arguments.length>=1){const a=n.node.arguments[0];a&&!S(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 r=n.node.attributes;if(g(r,"data-agent-component")||g(r,"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,u=t.relativePath??"(anon)";for(const p of n.node.attributes){if(p.type!=="JSXAttribute"||p.name.type!=="JSXIdentifier"||!t.flowEvents.has(p.name.name)||!p.value||p.value.type!=="JSXExpressionContainer")continue;const b=p.value.expression;if(b.type==="JSXEmptyExpression"||y(b,e))continue;const v=p.name.name;p.value.expression=e.callExpression(e.identifier("withFlow"),[b,e.objectExpression([e.objectProperty(e.identifier("originType"),e.stringLiteral($.get(v)??"user-click")),e.objectProperty(e.identifier("originNodeId"),e.stringLiteral(`ui:${u}:${s}:${v}`))])]),t.needHelpers.add("withFlow")}}const i=E(n.node.name);if(!i||I(i))return;const a=[e.jsxAttribute(e.jsxIdentifier("data-agent-component"),e.stringLiteral(i))];if(t.opts.includeSource!==!1){const s=n.node.loc?.start.line??0,u=t.relativePath??"(anon)";a.push(e.jsxAttribute(e.jsxIdentifier("data-agent-source"),e.stringLiteral(`${u}:${s}`)))}n.node.attributes.push(...a)}}}}l(w,"j"),c(w,"v"),d(w,"lensmcpBabelPlugin");function g(o,e){return o.some(n=>n.type==="JSXAttribute"&&n.name.type==="JSXIdentifier"&&n.name.name===e)}l(g,"g"),c(g,"x"),d(g,"hasAttr");function x(o,e,n){const t=new Map;for(const r of o)if(n.isImportDeclaration(r)&&r.source.value===e)for(const i of r.specifiers)n.isImportSpecifier(i)&&n.isIdentifier(i.imported)&&t.set(i.local.name,i.imported.name);return t}l(x,"I"),c(x,"L"),d(x,"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,"h"),c(h,"I"),d(h,"isRootFactoryCall");function y(o,e){return e.isCallExpression(o)&&e.isIdentifier(o.callee,{name:"withFlow"})}l(y,"S"),c(y,"j"),d(y,"isAlreadyWithFlow");function S(o,e){return e.isJSXElement(o)&&e.isJSXIdentifier(o.openingElement.name,{name:"LensmcpRoot"})}l(S,"E"),c(S,"A"),d(S,"isAlreadyLensmcpRoot");const M=new Set(["Fragment","StrictMode","Suspense","SuspenseList","Profiler"]);function I(o){const e=o.split(".").pop()??o;return M.has(e)?!0:e.endsWith("Provider")||e.endsWith("Consumer")}l(I,"w"),c(I,"P"),d(I,"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}}l(E,"v"),c(E,"R"),d(E,"describeElementName");
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 m=Object.defineProperty;var t=(n,e)=>m(n,"name",{value:e,configurable:!0});var p=Object.defineProperty,o=t((n,e)=>p(n,"name",{value:e,configurable:!0}),"t"),_=Object.defineProperty,c=o((n,e)=>_(n,"name",{value:e,configurable:!0}),"r");import{useId as f,useRef as s}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 i=e.A,r=((typeof i?.getOwner=="function"?i.getOwner():null)??e.owner??e.ReactCurrentOwner?.current)?.type;if(!r)return;if(typeof r=="string")return r;const u=r.displayName??r.name;return typeof u=="string"&&u.length>0?u:void 0}catch{return}}t(readOwnerName,"readOwnerName"),o(readOwnerName,"readOwnerName"),c(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"),c(composeComponentIdentity,"composeComponentIdentity");function a(){try{return readOwnerName(require("react"))}catch{return}}t(a,"i"),o(a,"f"),c(a,"currentOwnerName");export function useComponentIdentity(){const n=f(),e=s(void 0);return e.current||(e.current=composeComponentIdentity(n,a())),e.current}t(useComponentIdentity,"useComponentIdentity"),o(useComponentIdentity,"useComponentIdentity"),c(useComponentIdentity,"useComponentIdentity");
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 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");
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");
@@ -1 +1 @@
1
- "use strict";var L=Object.defineProperty;var u=(e,t)=>L(e,"name",{value:t,configurable:!0});var W=Object.defineProperty,f=u((e,t)=>W(e,"name",{value:t,configurable:!0}),"u"),G=Object.defineProperty,m=f((e,t)=>G(e,"name",{value:t,configurable:!0}),"d");import{makeInstanceId as $}from"./identity.js";import{publish as N}from"./publish.js";import{notePageCommit as K}from"./page-visit-runtime.js";import{patternOf as Z,routeMatchesOf as q}from"./router-pattern.js";const B=1,H=0,U=1,Y=11,J=13,_=14,Q=15,k=15e3,z=25,j=15,X=8,M=(typeof process<"u"?process.env?.LENSMCP_RENDER_INCLUDE_INTERNALS:void 0)==="1",V=new Set(["Insertion","EmotionGlobal","EmotionCssPropInternal","GlobalStyles","ThemeProvider","CacheProvider"]);function v(e){return!!(V.has(e)||e.startsWith("Styled(")&&/^Styled\([a-z][a-zA-Z0-9-]*\)$/.test(e)||e==="lensmcp-root"||e.startsWith("Lensmcp"))}u(v,"I"),f(v,"R"),m(v,"isInternalRender");let w=!1,I=!1;const ee={};function P(e){const t=e.type;if(!(t==null||typeof t=="string"))switch(e.tag){case H:case U:return t.displayName||t.name||void 0;case Y:return t.displayName||t.render?.displayName||t.render?.name||void 0;case _:case Q:return t.displayName||t.type?.displayName||t.type?.name||t.name||void 0;default:return}}u(P,"k"),f(P,"O"),m(P,"componentNameOf");function C(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>=X))break;return r}u(C,"z"),f(C,"H"),m(C,"changedPropKeys");const R=new WeakMap;function S(e,t){const s=R.get(e);if(s)return s;const r=e.alternate,o=(r?R.get(r):void 0)??$(t).instanceId;return R.set(e,o),r&&R.set(r,o),o}u(S,"F"),f(S,"Y"),m(S,"stableInstanceId");const E=m(e=>e.alternate==null||e.child!==e.alternate.child,"childrenChanged");function F(e){const t=[];let s=0,r=!1,o,l=!1;const a=[],i=m((n,d,p)=>{for(let g=n.child;g;g=g.sibling)a.push({node:g,parentName:d,...p?{wrapperName:p}:{}})},"pushChildren");for(E(e.current)&&i(e.current,void 0);a.length>0;){const{node:n,parentName:d,wrapperName:p}=a.pop();if(s+=1,s>k){r=!0;break}let g=d;const b=n.memoizedProps?q(n.memoizedProps):void 0;if(b&&b.length>=(o?.length??0)&&(o=b),n.tag===J&&n.memoizedState!=null&&(l=!0),n.tag===_){E(n)&&i(n,d,P(n));continue}const c=P(n)??p,A=(n.flags&B)!==0;if(c&&A){const O=n.alternate==null,y=[];if(!O){const T=C(n);T.length>0&&y.push({type:"props",changedKeys:T}),d&&y.push({type:"parent-render",parentRenderId:d}),y.length===0&&y.push({type:"react-state",hookIndex:-1})}t.push({name:c,instanceId:S(n,`react:component:(fiber):${c}`),phase:O?"mount":"update",durationMs:typeof n.actualDuration=="number"?n.actualDuration:0,why:y,parentName:d}),g=c}E(n)&&i(n,g)}const h=o?Z(o):void 0;return{renders:t,cut:r,suspense:l,...h?{pattern:h}:{}}}u(F,"O"),f(F,"Z"),m(F,"collectCommitRenders");let x;export function activeCommitId(){return x}u(activeCommitId,"activeCommitId"),f(activeCommitId,"activeCommitId"),m(activeCommitId,"activeCommitId");export function fiberRendersActive(){return w&&!I}u(fiberRendersActive,"fiberRendersActive"),f(fiberRendersActive,"fiberRendersActive"),m(fiberRendersActive,"fiberRendersActive");function D(e,t,s=!1){const r=M?e:e.filter(a=>!v(a.name));if(r.length===0)return;const o=$("react:commit").instanceId;x=o;const l=r.length>z?[...r].sort((a,i)=>i.durationMs-a.durationMs).slice(0,z):r;for(const a of l){const i=`react:component:(fiber):${a.name}`,{instanceId:h}=$(i),n={id:h,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 ${k} 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:k}:{}}})}}u(D,"x"),f(D,"q"),m(D,"publishRecords");export function installFiberRenderPublisher(){if(w||I||typeof window>"u")return;const e=window.__LENSMCP_FIBER__;if(!e||typeof e.subscribe!="function")return;w=!0;let t=j,s=0;const r=new Map;let o=0,l;const a=m(()=>{if(l=void 0,t=j,s===0)return;const i=[...r.entries()].sort((d,p)=>p[1]-d[1]).slice(0,5),h=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 ${h}${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,h)=>{if(!I)try{if(!h||!h.current)return;const{renders:n,cut:d,pattern:p,suspense:g}=F(h),b=M?n:n.filter(c=>!v(c.name));if(K(ee,{at:Date.now(),renders:b.map(c=>({name:c.name,ms:c.durationMs,mount:c.phase==="mount"})),storm:t<=0,suspense:g,...p?{pattern:p}:{}}),n.length===0)return;if(t>0)t-=1,D(n,Date.now(),d);else{s+=1;for(const c of n){if(!M&&v(c.name)){o+=1;continue}r.set(c.name,(r.get(c.name)??0)+1)}}l||(l=setTimeout(a,1e3))}catch{I=!0}})}u(installFiberRenderPublisher,"installFiberRenderPublisher"),f(installFiberRenderPublisher,"installFiberRenderPublisher"),m(installFiberRenderPublisher,"installFiberRenderPublisher");export function resetFiberRenderPublisherForTests(){w=!1,I=!1}u(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests"),f(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests"),m(resetFiberRenderPublisherForTests,"resetFiberRenderPublisherForTests");
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 B=Object.defineProperty;var f=(e,o)=>B(e,"name",{value:o,configurable:!0});var V=Object.defineProperty,g=f((e,o)=>V(e,"name",{value:o,configurable:!0}),"f"),X=Object.defineProperty,c=g((e,o)=>X(e,"name",{value:o,configurable:!0}),"c");import{beginBackgroundFlow as K,extendFlowWindow as A,flowForNewActivity as j,publish as E}from"./publish.js";import{installRouteFlows as z}from"./route-flows.js";import{notePageFetch as x,pageVisitOpen as C,startHardPageVisit as J}from"./page-visit-runtime.js";import{replayActive as G,replayLeg as L}from"./replay-anchors.js";export function mayPropagateTo(e,o=[]){const d=typeof location<"u"?location.href:void 0;let u;try{u=new URL(e,d)}catch{return!1}if(typeof location<"u"&&u.origin===location.origin||_(u.hostname))return!0;for(const i of o){let l;try{l=new URL(i).origin}catch{continue}if(l===u.origin)return!0}return!1}f(mayPropagateTo,"mayPropagateTo"),g(mayPropagateTo,"mayPropagateTo"),c(mayPropagateTo,"mayPropagateTo");const Q=new Set(["localhost","[::1]","::1"]);function _(e){const o=e.toLowerCase();return Q.has(o)||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(o)}f(_,"O"),g(_,"B"),c(_,"isLoopbackHost");function $(){const e=globalThis.__LENSMCP_FLOW_PROPAGATE__;return Array.isArray(e)?e.filter(o=>typeof o=="string"):typeof e=="string"?e.split(",").map(o=>o.trim()).filter(Boolean):[]}f($,"$"),g($,"E"),c($,"globalPropagateList");function F(){return Date.now().toString(36)+Math.random().toString(36).slice(2,12)}f(F,"S"),g(F,"k"),c(F,"newRequestId");function I(e){return typeof e=="string"?e:e instanceof URL?e.href:e.url??String(e)}f(I,"y"),g(I,"H"),c(I,"urlOf");const U=Symbol.for("lensmcp.flow-fetch"),D=Symbol.for("lensmcp.flow-fetch.recorded-leg");function b(e){return{...e,[D]:!0}}f(b,"x"),g(b,"R"),c(b,"markRecorded");let W=!1;export function installFlowFetch(e={}){const o=globalThis;if(typeof o.fetch!="function")return()=>{};if(o.fetch[U])return()=>{};if(!W&&typeof location<"u"&&typeof document<"u"){W=!0;const t=K({originType:"page-load",originNodeId:`page:${location.pathname}`});J(t.flowId)}const d=e.flowHeader??"x-lensmcp-flow-id",u=e.originHeader??"x-lensmcp-origin-node-id",i=e.requestHeader??"x-request-id",l=e.propagateTo??[],a=o.fetch.bind(globalThis);globalThis.__LENSMCP_FLOW_FETCH__=!0;const h=c(((t,r)=>{if(r?.[D])return a(t,r);const w=j();if(!w?.flowId){if(!C()&&!G())return a(t,r);const m=I(t);if(!mayPropagateTo(m,[...l,...$()])){const P=a(t,b(r));return x(P,y(t,r),m,void 0,void 0),L(P,y(t,r),m,void 0,void 0),P}const S=new Headers(r?.headers??(typeof t=="object"&&t!==null&&"headers"in t?t.headers:void 0)??void 0),k=S.get(i)??F();S.has(i)||S.set(i,k);const R=a(t,{...b(r),headers:S});return x(R,y(t,r),m,k,void 0),L(R,y(t,r),m,k,void 0),R}if(!mayPropagateTo(I(t),[...l,...$()])){const m=a(t,b(r));return q(w,t,r,m,void 0),x(m,y(t,r),I(t),void 0,w.flowId),L(m,y(t,r),I(t),void 0,w.flowId),m}const v=typeof t=="object"&&t!==null&&"headers"in t?t.headers:void 0,p=new Headers(r?.headers??v??void 0);p.has(d)||p.set(d,w.flowId),w.originNodeId&&!p.has(u)&&p.set(u,w.originNodeId);const H=p.get(i)??F();p.has(i)||p.set(i,H);const T=a(t,{...b(r),headers:p});return q(w,t,r,T,H),x(T,y(t,r),I(t),H,w.flowId),L(T,y(t,r),I(t),H,w.flowId),T}),"patched");h[U]=!0,o.fetch=h;const n=M({flowHeader:d,originHeader:u,requestHeader:i,propagate:c(t=>mayPropagateTo(t,[...l,...$()]),"propagate")}),s=e.routeFlows===!1?()=>{}:z();return()=>{s(),n(),o.fetch=a}}f(installFlowFetch,"installFlowFetch"),g(installFlowFetch,"installFlowFetch"),c(installFlowFetch,"installFlowFetch");const N=Symbol.for("lensmcp.flow-xhr");function M(e){const o=globalThis.XMLHttpRequest;if(typeof o!="function")return()=>{};const d=o.prototype;if(d[N])return()=>{};const u=d.open,i=d.send,l=d.setRequestHeader,a=new WeakMap;d.open=c(function(n,s,...t){return a.set(this,{method:String(n).toUpperCase(),url:String(s),headers:new Map}),u.call(this,n,s,...t)},"patchedOpen"),d.setRequestHeader=c(function(n,s){return a.get(this)?.headers.set(String(n).toLowerCase(),String(s)),l.call(this,n,s)},"patchedSetHeader"),d.send=c(function(n){const s=a.get(this);if(s)try{h(this,s)}catch{}return i.call(this,n)},"patchedSend"),d[N]=!0;function h(n,s){const t=j(),r=C(),w=G();if(!t?.flowId&&!r&&!w)return;let v;e.propagate(s.url)&&(t?.flowId&&(s.headers.has(e.flowHeader)||l.call(n,e.flowHeader,t.flowId),t.originNodeId&&!s.headers.has(e.originHeader)&&l.call(n,e.originHeader,t.originNodeId)),v=s.headers.get(e.requestHeader)??F(),s.headers.has(e.requestHeader)||l.call(n,e.requestHeader,v));const p=new Promise((H,T)=>{n.addEventListener("loadend",()=>n.status===0?T(new Error("XMLHttpRequest failed")):H({status:n.status,statusText:n.statusText,ok:n.status>=200&&n.status<300}),{once:!0})});t?.flowId&&q(t,s.url,{method:s.method},p,v,"xhr"),(t?.flowId||r)&&x(p,s.method,s.url,v,t?.flowId),L(p,s.method,s.url,v,t?.flowId),p.catch(()=>{})}return f(h,"p"),g(h,"g"),c(h,"xhrLeg"),()=>{d.open=u,d.send=i,d.setRequestHeader=l,delete d[N]}}f(M,"U"),g(M,"K"),c(M,"installFlowXhr");function y(e,o){return o?.method??(typeof e=="object"&&e!==null&&"method"in e?e.method??"GET":"GET")}f(y,"m"),g(y,"y"),c(y,"methodOf");function O(e){const o=typeof location<"u"?location.href:void 0;try{return new URL(e,o).href}catch{return}}f(O,"D"),g(O,"V"),c(O,"absoluteHref");function q(e,o,d,u,i,l){const a=I(o),h=O(a),n=d?.method??(typeof o=="object"&&o!==null&&"method"in o?o.method??"GET":"GET"),s=Date.now(),t={flowId:e.flowId,...e.originType?{originType:e.originType}:{},...e.originNodeId?{originNodeId:e.originNodeId}:{},...i?{requestId:i}:{}};E({source:"react",category:"network",severity:"info",title:`fetch ${n} ${a}`,fingerprint:`flow-fetch:${n}:${a}`,context:t,raw:{kind:"fetch-start",url:a,method:n,...h?{href:h}:{},...i?{requestId:i}:{},...l?{transport:l}:{}}}),u.then(r=>{A(e),E({source:"react",category:"network",severity:r.ok||r.status===304?"info":"error",title:`fetch ${n} ${a} \u2192 ${r.status}${r.statusText?` ${r.statusText}`:""}`,fingerprint:`flow-fetch:${n}:${a}:${r.status}`,context:t,raw:{kind:"fetch-done",url:a,...h?{href:h}:{},...i?{requestId:i}:{},method:n,status:r.status,statusText:r.statusText,ok:r.ok,startedAt:s,durationMs:Date.now()-s}})},r=>{A(e),E({source:"react",category:"network",severity:"error",title:`fetch ${n} ${a} failed`,message:r instanceof Error?r.message:String(r),fingerprint:`flow-fetch:${n}:${a}:error`,context:t,raw:{kind:"fetch-error",url:a,...h?{href:h}:{},...i?{requestId:i}:{},method:n,startedAt:s,durationMs:Date.now()-s}})})}f(q,"q"),g(q,"x"),c(q,"publishFetchLeg");
1
+ "use strict";var W=Object.defineProperty;var f=(e,r)=>W(e,"name",{value:r,configurable:!0});var X=Object.defineProperty,c=f((e,r)=>X(e,"name",{value:r,configurable:!0}),"c");import{beginBackgroundFlow as B,extendFlowWindow as N,flowForNewActivity as P,publish as _}from"./publish.js";import{installRouteFlows as V}from"./route-flows.js";import{notePageFetch as T,pageVisitOpen as M,startHardPageVisit as K}from"./page-visit-runtime.js";import{replayActive as A,replayLeg as b}from"./replay-anchors.js";export function mayPropagateTo(e,r=[]){const d=typeof location<"u"?location.href:void 0;let u;try{u=new URL(e,d)}catch{return!1}if(typeof location<"u"&&u.origin===location.origin||O(u.hostname))return!0;for(const a of r){let l;try{l=new URL(a).origin}catch{continue}if(l===u.origin)return!0}return!1}f(mayPropagateTo,"mayPropagateTo"),c(mayPropagateTo,"mayPropagateTo");const z=new Set(["localhost","[::1]","::1"]);function O(e){const r=e.toLowerCase();return z.has(r)||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(r)}f(O,"B"),c(O,"isLoopbackHost");function $(){const e=globalThis.__LENSMCP_FLOW_PROPAGATE__;return Array.isArray(e)?e.filter(r=>typeof r=="string"):typeof e=="string"?e.split(",").map(r=>r.trim()).filter(Boolean):[]}f($,"E"),c($,"globalPropagateList");function S(){return Date.now().toString(36)+Math.random().toString(36).slice(2,12)}f(S,"k"),c(S,"newRequestId");function y(e){return typeof e=="string"?e:e instanceof URL?e.href:e.url??String(e)}f(y,"H"),c(y,"urlOf");const C=Symbol.for("lensmcp.flow-fetch"),j=Symbol.for("lensmcp.flow-fetch.recorded-leg");function x(e){return{...e,[j]:!0}}f(x,"R"),c(x,"markRecorded");let G=!1;export function installFlowFetch(e={}){const r=globalThis;if(typeof r.fetch!="function")return()=>{};if(r.fetch[C])return()=>{};if(!G&&typeof location<"u"&&typeof document<"u"){G=!0;const t=B({originType:"page-load",originNodeId:`page:${location.pathname}`});K(t.flowId)}const d=e.flowHeader??"x-lensmcp-flow-id",u=e.originHeader??"x-lensmcp-origin-node-id",a=e.requestHeader??"x-request-id",l=e.propagateTo??[],s=r.fetch.bind(globalThis);globalThis.__LENSMCP_FLOW_FETCH__=!0;const p=c(((t,o)=>{if(o?.[j])return s(t,o);const g=P();if(!g?.flowId){if(!M()&&!A())return s(t,o);const w=y(t);if(!mayPropagateTo(w,[...l,...$()])){const R=s(t,x(o));return T(R,m(t,o),w,void 0,void 0),b(R,m(t,o),w,void 0,void 0),R}const L=new Headers(o?.headers??(typeof t=="object"&&t!==null&&"headers"in t?t.headers:void 0)??void 0),F=L.get(a)??S();L.has(a)||L.set(a,F);const k=s(t,{...x(o),headers:L});return T(k,m(t,o),w,F,void 0),b(k,m(t,o),w,F,void 0),k}if(!mayPropagateTo(y(t),[...l,...$()])){const w=s(t,x(o));return q(g,t,o,w,void 0),T(w,m(t,o),y(t),void 0,g.flowId),b(w,m(t,o),y(t),void 0,g.flowId),w}const I=typeof t=="object"&&t!==null&&"headers"in t?t.headers:void 0,h=new Headers(o?.headers??I??void 0);h.has(d)||h.set(d,g.flowId),g.originNodeId&&!h.has(u)&&h.set(u,g.originNodeId);const H=h.get(a)??S();h.has(a)||h.set(a,H);const v=s(t,{...x(o),headers:h});return q(g,t,o,v,H),T(v,m(t,o),y(t),H,g.flowId),b(v,m(t,o),y(t),H,g.flowId),v}),"patched");p[C]=!0,r.fetch=p;const n=U({flowHeader:d,originHeader:u,requestHeader:a,propagate:c(t=>mayPropagateTo(t,[...l,...$()]),"propagate")}),i=e.routeFlows===!1?()=>{}:V();return()=>{i(),n(),r.fetch=s}}f(installFlowFetch,"installFlowFetch"),c(installFlowFetch,"installFlowFetch");const E=Symbol.for("lensmcp.flow-xhr");function U(e){const r=globalThis.XMLHttpRequest;if(typeof r!="function")return()=>{};const d=r.prototype;if(d[E])return()=>{};const u=d.open,a=d.send,l=d.setRequestHeader,s=new WeakMap;d.open=c(function(n,i,...t){return s.set(this,{method:String(n).toUpperCase(),url:String(i),headers:new Map}),u.call(this,n,i,...t)},"patchedOpen"),d.setRequestHeader=c(function(n,i){return s.get(this)?.headers.set(String(n).toLowerCase(),String(i)),l.call(this,n,i)},"patchedSetHeader"),d.send=c(function(n){const i=s.get(this);if(i)try{p(this,i)}catch{}return a.call(this,n)},"patchedSend"),d[E]=!0;function p(n,i){const t=P(),o=M(),g=A();if(!t?.flowId&&!o&&!g)return;let I;e.propagate(i.url)&&(t?.flowId&&(i.headers.has(e.flowHeader)||l.call(n,e.flowHeader,t.flowId),t.originNodeId&&!i.headers.has(e.originHeader)&&l.call(n,e.originHeader,t.originNodeId)),I=i.headers.get(e.requestHeader)??S(),i.headers.has(e.requestHeader)||l.call(n,e.requestHeader,I));const h=new Promise((H,v)=>{n.addEventListener("loadend",()=>n.status===0?v(new Error("XMLHttpRequest failed")):H({status:n.status,statusText:n.statusText,ok:n.status>=200&&n.status<300}),{once:!0})});t?.flowId&&q(t,i.url,{method:i.method},h,I,"xhr"),(t?.flowId||o)&&T(h,i.method,i.url,I,t?.flowId),b(h,i.method,i.url,I,t?.flowId),h.catch(()=>{})}return f(p,"g"),c(p,"xhrLeg"),()=>{d.open=u,d.send=a,d.setRequestHeader=l,delete d[E]}}f(U,"K"),c(U,"installFlowXhr");function m(e,r){return r?.method??(typeof e=="object"&&e!==null&&"method"in e?e.method??"GET":"GET")}f(m,"y"),c(m,"methodOf");function D(e){const r=typeof location<"u"?location.href:void 0;try{return new URL(e,r).href}catch{return}}f(D,"V"),c(D,"absoluteHref");function q(e,r,d,u,a,l){const s=y(r),p=D(s),n=d?.method??(typeof r=="object"&&r!==null&&"method"in r?r.method??"GET":"GET"),i=Date.now(),t={flowId:e.flowId,...e.originType?{originType:e.originType}:{},...e.originNodeId?{originNodeId:e.originNodeId}:{},...a?{requestId:a}:{}};_({source:"react",category:"network",severity:"info",title:`fetch ${n} ${s}`,fingerprint:`flow-fetch:${n}:${s}`,context:t,raw:{kind:"fetch-start",url:s,method:n,...p?{href:p}:{},...a?{requestId:a}:{},...l?{transport:l}:{}}}),u.then(o=>{N(e),_({source:"react",category:"network",severity:o.ok||o.status===304?"info":"error",title:`fetch ${n} ${s} \u2192 ${o.status}${o.statusText?` ${o.statusText}`:""}`,fingerprint:`flow-fetch:${n}:${s}:${o.status}`,context:t,raw:{kind:"fetch-done",url:s,...p?{href:p}:{},...a?{requestId:a}:{},method:n,status:o.status,statusText:o.statusText,ok:o.ok,startedAt:i,durationMs:Date.now()-i}})},o=>{N(e),_({source:"react",category:"network",severity:"error",title:`fetch ${n} ${s} failed`,message:o instanceof Error?o.message:String(o),fingerprint:`flow-fetch:${n}:${s}:error`,context:t,raw:{kind:"fetch-error",url:s,...p?{href:p}:{},...a?{requestId:a}:{},method:n,startedAt:i,durationMs:Date.now()-i}})})}f(q,"x"),c(q,"publishFetchLeg");
package/lib/hoc.js CHANGED
@@ -1 +1 @@
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");
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 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");
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");
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var i=(e,r)=>w(e,"name",{value:r,configurable:!0});var L=Object.defineProperty,u=i((e,r)=>L(e,"name",{value:r,configurable:!0}),"i"),M=Object.defineProperty,m=u((e,r)=>M(e,"name",{value:r,configurable:!0}),"c");import{jsx as f}from"react/jsx-runtime";import{Profiler as P,useMemo as $,useRef as s}from"react";import{LensmcpContext as j}from"./context.js";import{publish as x}from"./publish.js";import{makeInstanceId as k}from"./identity.js";import{fiberRendersActive as D,installFiberRenderPublisher as O}from"./fiber-renders.js";typeof window<"u"&&O();export function LensmcpRoot(e){const r=e.rendererId??"lensmcp-root",l=$(()=>({rendererId:r,page:e.page,route:e.route}),[r,e.page,e.route]),g=s(new Map),c=s(new Map),d=s(void 0),v=m((n,p,I,b,R,h)=>{const a=`render:${r}:${n}`,{instanceId:o}=k(a);let t=c.current.get(n);t===void 0&&(t=o,c.current.set(n,t));const y={id:o,parentRenderId:d.current,componentInstanceId:t,componentLogicalId:a,componentName:n,page:e.page,route:e.route,rendererId:r,phase:p==="mount"?"mount":"update",actualDurationMs:I,baseDurationMs:b,startTime:R,commitTime:h,why:[{type:"force",reason:"profiler-onrender"}]};d.current=o,g.current.set(n,o),!D()&&x({source:"react",category:"render",severity:"info",title:`render ${n} (${p})`,fingerprint:`react-render:${a}`,raw:{kind:"render",render:y}})},"onRender");return f(j.Provider,{value:l,children:f(P,{id:r,onRender:v,children:e.children})})}i(LensmcpRoot,"LensmcpRoot"),u(LensmcpRoot,"LensmcpRoot"),m(LensmcpRoot,"LensmcpRoot");
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 E=Object.defineProperty;var c=(n,e)=>E(n,"name",{value:e,configurable:!0});var P=Object.defineProperty,d=c((n,e)=>P(n,"name",{value:e,configurable:!0}),"c"),S=Object.defineProperty,a=d((n,e)=>S(n,"name",{value:e,configurable:!0}),"a");const M=600,O=3e3,o=a(n=>typeof n=="number"&&Number.isFinite(n)?n:0,"num"),h=a(n=>Math.round(n*10)/10,"r1");export class PagePerf{static{c(this,"PagePerf")}static{d(this,"PagePerf")}static{a(this,"PagePerf")}constructor(e){this.host=e,this.marks=[],this.scripts=[],this.loaf=!1;const i=a(s=>e.timeOrigin+o(s.startTime),"at");e.observe("largest-contentful-paint",s=>{for(const t of s)this.push({type:"lcp",at:i(t),dur:0,value:o(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:o(t.value)})}),e.observe("event",s=>{for(const t of s)o(t.interactionId)>0&&this.push({type:"event",at:i(t),dur:o(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:o(t.duration),value:0})}),this.loaf||e.observe("longtask",s=>{for(const t of s)this.push({type:"long",at:i(t),dur:o(t.duration),value:0})}),e.observe("resource",s=>{for(const t of s)t.initiatorType!=="script"&&!/\.(m?js|tsx?|jsx)(\?|$)/.test(String(t.name??""))||/\/@lensmcp\//.test(String(t.name??""))||(this.scripts.push({at:i(t),kb:(o(t.transferSize)||o(t.encodedBodySize))/1024}),this.scripts.length>3e3&&this.scripts.splice(0,this.scripts.length-3e3))})}window(e){const i=a(r=>r.at>=e.startAt&&r.at<=e.toAt,"inside"),s={};if(e.hard){const r=this.host.navigation();r&&(o(r.responseStart)>0&&(s.ttfb=h(o(r.responseStart))),o(r.domContentLoadedEventEnd)>0&&(s.dcl=h(o(r.domContentLoadedEventEnd))),o(r.loadEventEnd)>0&&(s.load=h(o(r.loadEventEnd))));const y=this.host.paint("first-contentful-paint");y!==void 0&&(s.fcp=h(y));const b=this.marks.filter(k=>k.type==="lcp"&&k.at<=e.toAt).at(-1);b&&(s.lcp=h(b.value))}let t=0,p=0,u=0,v=0,f=0;for(const r of this.marks)i(r)&&(r.type==="shift"?t+=r.value:r.type==="event"?p=Math.max(p,r.dur):r.type==="long"&&(u++,v+=r.dur,f=Math.max(f,r.dur)));t>0&&(s.cls=Math.round(t*1e3)/1e3),p>0&&(s.inp=h(p));let l=0,m=0;for(const r of this.scripts)r.at<e.startAt||r.at>e.toAt||(l++,m+=r.kb);const g=this.host.heapBytes();return{...Object.keys(s).length?{vitals:s}:{},...u?{longTasks:{n:u,totalMs:h(v),maxMs:h(f)}}:{},...g!==void 0?{heapMb:h(g/(1<<20))}:{},...l?{chunks:{n:l,kb:Math.round(m)}}:{}}}push(e){this.marks.push(e),this.marks.length>600&&this.marks.splice(0,this.marks.length-600)}}export function browserPerfHost(){const n=globalThis,e=n.performance,i=n.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"),d(browserPerfHost,"browserPerfHost"),a(browserPerfHost,"browserPerfHost");
1
+ "use strict";var k=Object.defineProperty;var c=(o,e)=>k(o,"name",{value:e,configurable:!0});var E=Object.defineProperty,a=c((o,e)=>E(o,"name",{value:e,configurable:!0}),"a");const M=600,T=3e3,r=a(o=>typeof o=="number"&&Number.isFinite(o)?o:0,"num"),h=a(o=>Math.round(o*10)/10,"r1");export class PagePerf{static{c(this,"PagePerf")}static{a(this,"PagePerf")}constructor(e){this.host=e,this.marks=[],this.scripts=[],this.loaf=!1;const i=a(s=>e.timeOrigin+r(s.startTime),"at");e.observe("largest-contentful-paint",s=>{for(const t of s)this.push({type:"lcp",at:i(t),dur:0,value:r(t.startTime)})}),e.observe("layout-shift",s=>{for(const t of s)t.hadRecentInput!==!0&&this.push({type:"shift",at:i(t),dur:0,value:r(t.value)})}),e.observe("event",s=>{for(const t of s)r(t.interactionId)>0&&this.push({type:"event",at:i(t),dur:r(t.duration),value:0})}),this.loaf=e.observe("long-animation-frame",s=>{for(const t of s)this.push({type:"long",at:i(t),dur:r(t.duration),value:0})}),this.loaf||e.observe("longtask",s=>{for(const t of s)this.push({type:"long",at:i(t),dur:r(t.duration),value:0})}),e.observe("resource",s=>{for(const t of s)t.initiatorType!=="script"&&!/\.(m?js|tsx?|jsx)(\?|$)/.test(String(t.name??""))||/\/@lensmcp\//.test(String(t.name??""))||(this.scripts.push({at:i(t),kb:(r(t.transferSize)||r(t.encodedBodySize))/1024}),this.scripts.length>3e3&&this.scripts.splice(0,this.scripts.length-3e3))})}window(e){const i=a(n=>n.at>=e.startAt&&n.at<=e.toAt,"inside"),s={};if(e.hard){const n=this.host.navigation();n&&(r(n.responseStart)>0&&(s.ttfb=h(r(n.responseStart))),r(n.domContentLoadedEventEnd)>0&&(s.dcl=h(r(n.domContentLoadedEventEnd))),r(n.loadEventEnd)>0&&(s.load=h(r(n.loadEventEnd))));const g=this.host.paint("first-contentful-paint");g!==void 0&&(s.fcp=h(g));const y=this.marks.filter(b=>b.type==="lcp"&&b.at<=e.toAt).at(-1);y&&(s.lcp=h(y.value))}let t=0,p=0,u=0,d=0,l=0;for(const n of this.marks)i(n)&&(n.type==="shift"?t+=n.value:n.type==="event"?p=Math.max(p,n.dur):n.type==="long"&&(u++,d+=n.dur,l=Math.max(l,n.dur)));t>0&&(s.cls=Math.round(t*1e3)/1e3),p>0&&(s.inp=h(p));let f=0,m=0;for(const n of this.scripts)n.at<e.startAt||n.at>e.toAt||(f++,m+=n.kb);const v=this.host.heapBytes();return{...Object.keys(s).length?{vitals:s}:{},...u?{longTasks:{n:u,totalMs:h(d),maxMs:h(l)}}:{},...v!==void 0?{heapMb:h(v/(1<<20))}:{},...f?{chunks:{n:f,kb:Math.round(m)}}:{}}}push(e){this.marks.push(e),this.marks.length>600&&this.marks.splice(0,this.marks.length-600)}}export function browserPerfHost(){const o=globalThis,e=o.performance,i=o.PerformanceObserver;if(!e||!i||typeof e.timeOrigin!="number")return;const s=new Set(i.supportedEntryTypes??[]);return{timeOrigin:e.timeOrigin,observe(t,p){if(!s.has(t))return!1;try{return new i(u=>p(u.getEntries())).observe({type:t,buffered:!0,...t==="event"?{durationThreshold:16}:{}}),!0}catch{return!1}},navigation:a(()=>e.getEntriesByType?.("navigation")?.[0]?.toJSON?.(),"navigation"),paint:a(t=>e.getEntriesByName?.(t,"paint")?.[0]?.startTime,"paint"),heapBytes:a(()=>e.memory?.usedJSHeapSize,"heapBytes")}}c(browserPerfHost,"browserPerfHost"),a(browserPerfHost,"browserPerfHost");
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var i=(e,t)=>u(e,"name",{value:t,configurable:!0});var l=Object.defineProperty,s=i((e,t)=>l(e,"name",{value:t,configurable:!0}),"i"),v=Object.defineProperty,n=s((e,t)=>v(e,"name",{value:t,configurable:!0}),"a");import{publish as P}from"./publish.js";import{PageVisitTracker as _}from"./page-visits.js";import{browserPerfHost as w,PagePerf as S}from"./page-perf.js";import{replayCheckpoint as b,replayMark as h}from"./replay-anchors.js";const f="__LENSMCP_PAGE_VISITS__";function g(){return typeof window<"u"&&typeof location<"u"&&typeof document<"u"}i(g,"y"),s(g,"_"),n(g,"browser");function d(){if(!g())return;const e=globalThis,t=e[f];if(t===!1)return;if(t)return t;const a=typeof e.__LENSMCP_APP__=="string"&&e.__LENSMCP_APP__?e.__LENSMCP_APP__:location.host||"app";let c;try{const r=w();c=r?new S(r):void 0}catch{c=void 0}const o={tracker:new _({app:a,...c?{perf:n(r=>c.window(r),"perf")}:{},emit:n((r,p)=>{P({source:"react",category:"performance",severity:r.readyBy==="timeout"?"warning":"info",title:p,fingerprint:`page-visit:${r.visitId}:${r.phase}`,detached:!0,raw:r}),replayVisit(r)},"emit"),onStart:replayVisitStart,tabId:n(()=>{try{return sessionStorage.getItem("lensmcp:tabId")??void 0}catch{return}},"tabId"),base:n(()=>location.href,"base")}),hardStarted:!1};e[f]=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 p=r.reason;o.tracker.error(p instanceof Error?`${p.name}: ${p.message}`:String(p))})}catch{}return o}i(d,"p"),s(d,"p"),n(d,"shared");export function replayVisit(e){h("lens/visit",{visitId:e.visitId,phase:e.phase,...e.pattern?{pattern:e.pattern}:{},...e.readyBy?{readyBy:e.readyBy}:{},...e.readyMs!==void 0?{readyMs:e.readyMs}:{}}),e.phase==="ready"&&e.nav==="spa"&&e.readyBy!=="left"&&b()}i(replayVisit,"replayVisit"),s(replayVisit,"replayVisit"),n(replayVisit,"replayVisit");export function replayVisitStart(e){h("lens/visit",{visitId:e.visitId,phase:"start",path:e.path,nav:e.nav,startAt:e.startAt})}i(replayVisitStart,"replayVisitStart"),s(replayVisitStart,"replayVisitStart"),n(replayVisitStart,"replayVisitStart");export function startHardPageVisit(e){const t=d();if(!(!t||t.hardStarted)){t.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;t.tracker.hard({path:location.pathname,startAt:Math.min(c,a),appStartAt:a,...r?{navType:r}:{},...y()?{cause:"hmr"}:{},...e?{flowId:e}:{}})}catch{}}}i(startHardPageVisit,"startHardPageVisit"),s(startHardPageVisit,"startHardPageVisit"),n(startHardPageVisit,"startHardPageVisit");function y(){if(globalThis.__LENSMCP_RELOAD_CAUSE__)return!0;try{return!!sessionStorage.getItem("lensmcp:reloadCause")}catch{return!1}}i(y,"h"),s(y,"P"),n(y,"hmrReload");export function notePageNavigation(e,t,a){try{d()?.tracker.navigate({path:e,how:t,...a?{flowId:a}:{}})}catch{}}i(notePageNavigation,"notePageNavigation"),s(notePageNavigation,"notePageNavigation"),n(notePageNavigation,"notePageNavigation");export function pageVisitOpen(){const e=globalThis[f];return!!e&&e.tracker.open()}i(pageVisitOpen,"pageVisitOpen"),s(pageVisitOpen,"pageVisitOpen"),n(pageVisitOpen,"pageVisitOpen");export function notePageFetch(e,t,a,c,o){const r=d();if(r)try{const p=r.tracker.fetchStarted({method:t,url:a,...c?{rid:c}:{},...o?{flowId:o}:{}});e.then(m=>p(m.status),()=>p(0))}catch{}}i(notePageFetch,"notePageFetch"),s(notePageFetch,"notePageFetch"),n(notePageFetch,"notePageFetch");export function notePageCommit(e,t){const a=d();if(a&&(a.commitsBy??=e,a.commitsBy===e))try{a.tracker.commit(t)}catch{}}i(notePageCommit,"notePageCommit"),s(notePageCommit,"notePageCommit"),n(notePageCommit,"notePageCommit");export function notePageState(e,t){const a=globalThis[f];if(a)try{a.tracker.storeUpdated(e,t)}catch{}}i(notePageState,"notePageState"),s(notePageState,"notePageState"),n(notePageState,"notePageState");
1
+ "use strict";var g=Object.defineProperty;var i=(t,e)=>g(t,"name",{value:e,configurable:!0});var u=Object.defineProperty,o=i((t,e)=>u(t,"name",{value:e,configurable:!0}),"a");import{publish as l}from"./publish.js";import{PageVisitTracker as v}from"./page-visits.js";import{browserPerfHost as _,PagePerf as P}from"./page-perf.js";import{replayCheckpoint as w,replayMark as f}from"./replay-anchors.js";const d="__LENSMCP_PAGE_VISITS__";function y(){return typeof window<"u"&&typeof location<"u"&&typeof document<"u"}i(y,"_"),o(y,"browser");function p(){if(!y())return;const t=globalThis,e=t[d];if(e===!1)return;if(e)return e;const a=typeof t.__LENSMCP_APP__=="string"&&t.__LENSMCP_APP__?t.__LENSMCP_APP__:location.host||"app";let s;try{const r=_();s=r?new P(r):void 0}catch{s=void 0}const n={tracker:new v({app:a,...s?{perf:o(r=>s.window(r),"perf")}:{},emit:o((r,c)=>{l({source:"react",category:"performance",severity:r.readyBy==="timeout"?"warning":"info",title:c,fingerprint:`page-visit:${r.visitId}:${r.phase}`,detached:!0,raw:r}),replayVisit(r)},"emit"),onStart:replayVisitStart,tabId:o(()=>{try{return sessionStorage.getItem("lensmcp:tabId")??void 0}catch{return}},"tabId"),base:o(()=>location.href,"base")}),hardStarted:!1};t[d]=n;try{window.addEventListener("beforeunload",()=>n.tracker.pagehide()),window.addEventListener("pagehide",()=>n.tracker.pagehide()),window.addEventListener("error",r=>n.tracker.error(r.message||"error")),window.addEventListener("unhandledrejection",r=>{const c=r.reason;n.tracker.error(c instanceof Error?`${c.name}: ${c.message}`:String(c))})}catch{}return n}i(p,"p"),o(p,"shared");export function replayVisit(t){f("lens/visit",{visitId:t.visitId,phase:t.phase,...t.pattern?{pattern:t.pattern}:{},...t.readyBy?{readyBy:t.readyBy}:{},...t.readyMs!==void 0?{readyMs:t.readyMs}:{}}),t.phase==="ready"&&t.nav==="spa"&&t.readyBy!=="left"&&w()}i(replayVisit,"replayVisit"),o(replayVisit,"replayVisit");export function replayVisitStart(t){f("lens/visit",{visitId:t.visitId,phase:"start",path:t.path,nav:t.nav,startAt:t.startAt})}i(replayVisitStart,"replayVisitStart"),o(replayVisitStart,"replayVisitStart");export function startHardPageVisit(t){const e=p();if(!(!e||e.hardStarted)){e.hardStarted=!0;try{const a=Date.now(),s=typeof performance<"u"&&typeof performance.timeOrigin=="number"?Math.round(performance.timeOrigin):a,n=(typeof performance<"u"&&typeof performance.getEntriesByType=="function"?performance.getEntriesByType("navigation")[0]:void 0)?.type,r=n==="navigate"||n==="reload"||n==="back_forward"?n:void 0;e.tracker.hard({path:location.pathname,startAt:Math.min(s,a),appStartAt:a,...r?{navType:r}:{},...h()?{cause:"hmr"}:{},...t?{flowId:t}:{}})}catch{}}}i(startHardPageVisit,"startHardPageVisit"),o(startHardPageVisit,"startHardPageVisit");function h(){if(globalThis.__LENSMCP_RELOAD_CAUSE__)return!0;try{return!!sessionStorage.getItem("lensmcp:reloadCause")}catch{return!1}}i(h,"P"),o(h,"hmrReload");export function notePageNavigation(t,e,a){try{p()?.tracker.navigate({path:t,how:e,...a?{flowId:a}:{}})}catch{}}i(notePageNavigation,"notePageNavigation"),o(notePageNavigation,"notePageNavigation");export function pageVisitOpen(){const t=globalThis[d];return!!t&&t.tracker.open()}i(pageVisitOpen,"pageVisitOpen"),o(pageVisitOpen,"pageVisitOpen");export function notePageFetch(t,e,a,s,n){const r=p();if(r)try{const c=r.tracker.fetchStarted({method:e,url:a,...s?{rid:s}:{},...n?{flowId:n}:{}});t.then(m=>c(m.status),()=>c(0))}catch{}}i(notePageFetch,"notePageFetch"),o(notePageFetch,"notePageFetch");export function notePageCommit(t,e){const a=p();if(a&&(a.commitsBy??=t,a.commitsBy===t))try{a.tracker.commit(e)}catch{}}i(notePageCommit,"notePageCommit"),o(notePageCommit,"notePageCommit");export function notePageState(t,e){const a=globalThis[d];if(a)try{a.tracker.storeUpdated(t,e)}catch{}}i(notePageState,"notePageState"),o(notePageState,"notePageState");
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var l=(r,t)=>f(r,"name",{value:t,configurable:!0});var y=Object.defineProperty,u=l((r,t)=>y(r,"name",{value:t,configurable:!0}),"l"),A=Object.defineProperty,d=u((r,t)=>A(r,"name",{value:t,configurable:!0}),"o");export const QUIET_MS=100,READY_CAP_MS=3e4,NO_COMMIT_MS=1e3,END_AFTER_READY_MS=6e4;const C=60,S=200,q=8,k=20,w={now:d(()=>Date.now(),"now"),setTimeout:d((r,t)=>setTimeout(r,t),"setTimeout"),clearTimeout:d(r=>clearTimeout(r),"clearTimeout")},c=d((r,t=200)=>r.length>t?r.slice(0,t):r,"clip");function v(r){let t=2166136261;for(let s=0;s<r.length;s++)t^=r.charCodeAt(s),t=Math.imul(t,16777619);return(t>>>0).toString(36)}l(v,"u"),u(v,"l"),d(v,"shortHash");export function templatePath(r){return r.split("/").map(t=>/^\d+$/.test(t)||/^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(t)||/^[0-9a-zA-Z_-]{20,}$/.test(t)?":id":t).join("/")}l(templatePath,"templatePath"),u(templatePath,"templatePath"),d(templatePath,"templatePath");const T=d(()=>({commits:0,renders:0,renderMs:0,maxCommitMs:0,stormCommits:0,mounts:0,suspenseWaits:0,byName:new Map}),"newTally");let g=0;const M=d(r=>`pv-${r.toString(36)}-${(++g).toString(36)}${Math.random().toString(36).slice(2,6)}`,"newVisitId");export class PageVisitTracker{static{l(this,"PageVisitTracker")}static{u(this,"PageVisitTracker")}static{d(this,"PageVisitTracker")}constructor(t){this.opts=t,this.clock=t.clock??w}current(){return this.visit}open(){return this.visit!==void 0}hard(t){this.begin({nav:"hard",path:t.path,startAt:t.startAt,appStartAt:t.appStartAt,...t.navType?{navType:t.navType}:{},...t.cause?{cause:t.cause}:{},...t.flowId?{flowId:t.flowId}:{}})}navigate(t){const s=this.visit;if(!(s&&c(t.path)===s.path)){if(s&&t.how==="replace"&&s.readyAt===void 0){s.redirectedFrom??=s.path,s.path=c(t.path),s.pattern=void 0,t.flowId&&s.flowIds.add(t.flowId);return}this.begin({nav:"spa",path:t.path,startAt:this.clock.now(),navType:t.how,...t.flowId?{flowId:t.flowId}:{}})}}fetchStarted(t){const s=this.visit;if(!s)return()=>{};const e=this.clock.now();t.flowId&&s.flowIds.add(t.flowId);const o=this.where(t.url),a=s.readyAt!==void 0;let i;if(s.requests.length<60?(i={rid:t.rid??"",m:t.method.toUpperCase(),p:o.p,...o.qh?{qh:o.qh}:{},s:Math.max(0,e-s.startAt),...t.flowId?{flowId:t.flowId}:{},...a?{late:!0}:{}},s.requests.push(i)):s.dropped++,a)return s.after.requests++,s.after.templates.size<20&&s.after.templates.add(`${t.method.toUpperCase()} ${templatePath(o.path)}`),m=>{i&&(i.d=Math.max(0,this.clock.now()-s.startAt-i.s),i.st=m)};s.open++,this.cancelCandidate(s),this.clearTimer(s,"noCommit");let p=!1;return m=>{p||(p=!0,i&&(i.d=Math.max(0,this.clock.now()-s.startAt-i.s),i.st=m),!(this.visit!==s||s.readyAt!==void 0)&&(s.open=Math.max(0,s.open-1),s.open===0&&(s.noCommit=this.clock.setTimeout(()=>{s.noCommit=void 0,this.visit===s&&s.readyAt===void 0&&s.open===0&&this.ready(s,s.lastCommitAt??this.clock.now(),"no-commit")},1e3))))}}commit(t){const s=this.visit;if(s){if(t.pattern&&s.readyBy===void 0&&(s.pattern=t.pattern),s.readyAt!==void 0){s.after.renders+=t.renders.length;return}if(t.renders.length>0){const e=s.r;e.commits++,e.renders+=t.renders.length;let o=0;for(const a of t.renders){a.ms>o&&(o=a.ms),a.mount&&e.mounts++;const i=e.byName.get(a.name);i?(i.n++,i.ms+=a.ms):e.byName.set(a.name,{n:1,ms:a.ms})}e.renderMs+=o,o>e.maxCommitMs&&(e.maxCommitMs=o),t.storm&&e.stormCommits++}if(t.suspense&&s.r.suspenseWaits++,s.lastCommitAt=t.at,this.clearTimer(s,"noCommit"),s.open>0||t.suspense){this.cancelCandidate(s);return}this.cancelCandidate(s),s.candidate=t.at,s.quiet=this.clock.setTimeout(()=>{s.quiet=void 0,!(this.visit!==s||s.readyAt!==void 0||s.candidate===void 0)&&this.ready(s,s.candidate,s.requests.length?"settled":"no-requests")},100)}}storeUpdated(t,s){const e=this.visit;if(!e)return;if(e.readyAt!==void 0){e.after.updates++;return}e.updates++;const o=`${t}\0${s}`,a=e.byStore.get(o);a?a.n++:e.byStore.size<200&&e.byStore.set(o,{store:t,path:c(s,120),n:1})}error(t){const s=this.visit;s&&(s.errors++,s.firstError??=c(t,200))}pagehide(){this.visit&&this.finish(this.visit)}begin(t){this.visit&&this.finish(this.visit);const s={id:M(t.startAt),nav:t.nav,...t.navType?{navType:t.navType}:{},...t.cause?{cause:t.cause}:{},path:c(t.path),startAt:t.startAt,...t.appStartAt!==void 0?{appStartAt:t.appStartAt}:{},flowIds:new Set(t.flowId?[t.flowId]:[]),requests:[],dropped:0,open:0,r:T(),updates:0,byStore:new Map,errors:0,after:{requests:0,templates:new Set,renders:0,updates:0}};this.visit=s;try{this.opts.onStart?.({visitId:s.id,path:s.path,nav:s.nav,startAt:s.startAt})}catch{}s.cap=this.clock.setTimeout(()=>{s.cap=void 0,this.visit===s&&s.readyAt===void 0&&this.ready(s,this.clock.now(),"timeout")},Math.max(0,3e4-(this.clock.now()-s.startAt)))}ready(t,s,e){t.readyAt=e==="left"?void 0:s,t.readyBy=e,this.clearTimer(t,"quiet"),this.clearTimer(t,"noCommit"),this.clearTimer(t,"cap"),t.candidate=void 0,this.send(t,"ready"),e!=="left"&&(t.end=this.clock.setTimeout(()=>{t.end=void 0,this.visit===t&&this.finish(t)},6e4))}finish(t){t.readyBy===void 0&&this.ready(t,this.clock.now(),"left");for(const s of["quiet","noCommit","cap","end"])this.clearTimer(t,s);this.send(t,"end"),this.visit===t&&(this.visit=void 0)}send(t,s){const e=t.r,o=this.opts.tabId?.(),a=t.readyAt!==void 0?Math.max(0,t.readyAt-t.startAt):void 0,i={kind:"page-visit",phase:s,visitId:t.id,...o?{tabId:o}:{},app:this.opts.app,...t.pattern?{pattern:t.pattern}:{},path:t.path,nav:t.nav,...t.navType?{navType:t.navType}:{},...t.cause?{cause:t.cause}:{},...t.redirectedFrom?{redirectedFrom:t.redirectedFrom}:{},startAt:t.startAt,...t.readyAt!==void 0?{readyAt:t.readyAt}:{},...t.readyBy?{readyBy:t.readyBy}:{},...a!==void 0?{readyMs:a}:{},...a!==void 0&&t.appStartAt!==void 0?{appReadyMs:Math.max(0,t.readyAt-t.appStartAt)}:{},...s==="end"?{endAt:this.clock.now()}:{},flowIds:[...t.flowIds].slice(0,20),requests:t.requests.map(n=>({...n})),...t.dropped?{requestsDropped:t.dropped}:{},renders:{commits:e.commits,renders:e.renders,renderMs:Math.round(e.renderMs*10)/10,maxCommitMs:Math.round(e.maxCommitMs*10)/10,stormCommits:e.stormCommits,mounts:e.mounts,suspenseWaits:e.suspenseWaits,top:[...e.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:t.updates,top:[...t.byStore.values()].sort((n,h)=>h.n-n.n).slice(0,8)},errors:{n:t.errors,...t.firstError?{first:t.firstError}:{}},...s==="end"?{afterReady:{requests:t.after.requests,templates:[...t.after.templates],renders:t.after.renders,updates:t.after.updates}}:{}};try{const n=s==="ready"?t.readyAt??this.clock.now():this.clock.now();this.opts.perf&&Object.assign(i,this.opts.perf({startAt:t.startAt,toAt:n,hard:t.nav==="hard"}))}catch{}const p=t.pattern??t.path,m=s==="end"?`page visit ended ${p}`:t.readyBy==="left"?`page left before ready ${p}`:t.readyBy==="timeout"?`page not ready in ${3e4/1e3}s ${p} \u2014 ${t.requests.filter(n=>n.d===void 0).length} requests open`:`page ready ${p} \xB7 ${a} ms`;try{this.opts.emit(i,m)}catch{}}where(t){try{const s=new URL(t,this.opts.base?.()??"http://localhost/"),e=s.search.length>1?v(s.search):void 0;return{p:c(`${s.host}${s.pathname}`),path:s.pathname,...e?{qh:e}:{}}}catch{const[s=""]=t.split("?");return{p:c(s),path:s}}}cancelCandidate(t){t.candidate=void 0,this.clearTimer(t,"quiet")}clearTimer(t,s){t[s]!==void 0&&(this.clock.clearTimeout(t[s]),t[s]=void 0)}}
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;try{this.opts.onStart?.({visitId:t.id,path:t.path,nav:t.nav,startAt:t.startAt})}catch{}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 $=Object.defineProperty;var e=(o,n)=>$(o,"name",{value:n,configurable:!0});var q=Object.defineProperty,i=e((o,n)=>q(o,"name",{value:n,configurable:!0}),"t"),U=Object.defineProperty,t=i((o,n)=>U(o,"name",{value:n,configurable:!0}),"t");import{createEventFloodGuard as j,estimateJsonBytes as z}from"@lensmcp/protocol-types";import{replayMark as P}from"./replay-anchors.js";const l=[],X=200,C=(()=>{const o=typeof process<"u"?process.env?.LENSMCP_PUBLISH_QUEUE_BYTES:void 0,n=Number(o);return Number.isFinite(n)&&n>0?Math.floor(n):1024*1024})(),F=[];let c=0;function v(o){const n=z(o,C);for(l.push(o),F.push(n),c+=n;l.length>X||c>C&&l.length>1;)l.shift(),c-=F.shift()??0;l.length===0&&(c=0)}e(v,"L"),i(v,"P"),t(v,"enqueue");function T(){const o=l.shift();return c-=F.shift()??0,l.length===0&&(c=0),o}e(T,"E"),i(T,"C"),t(T,"dequeue");export function queuedByteCount(){return c}e(queuedByteCount,"queuedByteCount"),i(queuedByteCount,"queuedByteCount"),t(queuedByteCount,"queuedByteCount");const w=[],x=4e3;let d;export const DEFAULT_AMBIENT_FLOW_MAX_MS=3e4;let b;function g(o){if(o==="off"||o==="Infinity")return 1/0;const n=typeof o=="string"&&o.trim()!==""?Number(o):o;if(!(typeof n!="number"||Number.isNaN(n)||n<0))return n===0||n===1/0?1/0:n}e(g,"N"),i(g,"m"),t(g,"parseMaxLifetime");function M(){if(b!==void 0)return b;const o=g(globalThis.__LENSMCP_AMBIENT_FLOW_MAX_MS__);return o!==void 0?o:g(typeof process<"u"?process.env?.LENSMCP_AMBIENT_FLOW_MAX_MS:void 0)??DEFAULT_AMBIENT_FLOW_MAX_MS}e(M,"B"),i(M,"X"),t(M,"ambientMaxMs");export function configureAmbientFlows(o){b=o.maxLifetimeMs===void 0?void 0:g(o.maxLifetimeMs)}e(configureAmbientFlows,"configureAmbientFlows"),i(configureAmbientFlows,"configureAmbientFlows"),t(configureAmbientFlows,"configureAmbientFlows");const f=new Map,Q=16;function S(o){for(f.set(o,{bornAt:Date.now()});f.size>Q;)f.delete(f.keys().next().value)}e(S,"k"),i(S,"Q"),t(S,"trackAmbient");function h(o){const n=f.get(o.flowId);if(!n)return!1;const r=M();return r!==1/0&&Date.now()-n.bornAt>=r}e(h,"b"),i(h,"x"),t(h,"ambientExhausted");export function extendFlowWindow(o){const n=o??currentFlow()??d?.spec;n&&(h(n)||(d={spec:n,until:Date.now()+x}))}e(extendFlowWindow,"extendFlowWindow"),i(extendFlowWindow,"extendFlowWindow"),t(extendFlowWindow,"extendFlowWindow");function p(){return d&&Date.now()<d.until?d.spec:void 0}e(p,"a"),i(p,"y"),t(p,"windowedFlow");export function activeFlow(){return currentFlow()??p()}e(activeFlow,"activeFlow"),i(activeFlow,"activeFlow"),t(activeFlow,"activeFlow");export function beginBackgroundFlow(o){const n={flowId:I(),originType:o.originType,...o.originNodeId?{originNodeId:o.originNodeId}:{}};return d={spec:n,until:Date.now()+x},S(n.flowId),publish({source:"react",category:"runtime",severity:"info",title:o.originType,fingerprint:m(o.originNodeId??o.originType,n.flowId),raw:{kind:"flow-origin",originNodeId:o.originNodeId,...o.continuesFlowId?{continuesFlowId:o.continuesFlowId}:{}}}),P("lens/flow",{flowId:n.flowId,kind:o.originType,...o.originNodeId?{originNodeId:o.originNodeId}:{}}),n}e(beginBackgroundFlow,"beginBackgroundFlow"),i(beginBackgroundFlow,"beginBackgroundFlow"),t(beginBackgroundFlow,"beginBackgroundFlow");export function flowForNewActivity(){const o=currentFlow();if(o)return o;const n=p();if(n)return h(n)?beginBackgroundFlow({originType:"timer",originNodeId:typeof location<"u"?`ambient:${location.pathname}`:"ambient",continuesFlowId:n.flowId}):n}e(flowForNewActivity,"flowForNewActivity"),i(flowForNewActivity,"flowForNewActivity"),t(flowForNewActivity,"flowForNewActivity");export const FLOW_ORIGIN_FINGERPRINT_PREFIX="flow-origin:";function m(o,n){return`${FLOW_ORIGIN_FINGERPRINT_PREFIX}${o}:${n}`}e(m,"_"),i(m,"S"),t(m,"originFingerprint");export function setPublisher(o){if(globalThis.__LENSMCP_PUBLISH__=o,o)for(;l.length;){const n=T();if(n)try{o(n)}catch{}}}e(setPublisher,"setPublisher"),i(setPublisher,"setPublisher"),t(setPublisher,"setPublisher");export function runInFlow(o,n){w.push(o),d={spec:o,until:Date.now()+x};try{return n()}finally{w.pop()}}e(runInFlow,"runInFlow"),i(runInFlow,"runInFlow"),t(runInFlow,"runInFlow");export function currentFlow(){return w[w.length-1]}e(currentFlow,"currentFlow"),i(currentFlow,"currentFlow"),t(currentFlow,"currentFlow");const D=Symbol.for("lensmcp.flowed"),O=2e3,a=new Map;function B(o){if(o==null||typeof o!="object")return;const n=o,r=n.nativeEvent;if(r!=null&&typeof r=="object"){const u=r.isTrusted;if(typeof u=="boolean")return u}if(typeof n.isTrusted=="boolean")return n.isTrusted}e(B,"D"),i(B,"$"),t(B,"eventTrust");function L(o){if(!(a.size<=64))for(const[n,r]of a)o>=r.until&&a.delete(n)}e(L,"C"),i(L,"q"),t(L,"pruneInputBursts");export function withFlow(o,n={}){if(typeof o!="function"||o[D])return o;const r=t(()=>{publish({source:"react",category:"runtime",severity:"info",title:n.originType??"user-click",fingerprint:m(n.originNodeId??"unknown",currentFlow()?.flowId??""),raw:{kind:"flow-origin",originNodeId:n.originNodeId}});const s=currentFlow()?.flowId;s&&P("lens/flow",{flowId:s,kind:n.originType??"user-click",...n.originNodeId?{originNodeId:n.originNodeId}:{}})},"publishOrigin"),u=t(function(...s){if(n.originType==="input-change"){if(B(s[0])===!1)return currentFlow()==null&&p()!=null&&extendFlowWindow(),o(...s);const k=n.originNodeId??"input",y=Date.now(),N=a.get(k);if(N&&y<N.until)return N.until=y+O,runInFlow(N.spec,()=>o(...s));const A={flowId:I(),originType:"input-change",originNodeId:n.originNodeId};return a.set(k,{spec:A,until:y+O}),L(y),runInFlow(A,()=>(r(),o(...s)))}const W=I();return runInFlow({flowId:W,originType:n.originType??"user-click",originNodeId:n.originNodeId},()=>(r(),o(...s)))},"flowed");return u[D]=!0,u}e(withFlow,"withFlow"),i(withFlow,"withFlow"),t(withFlow,"withFlow");let E=0;function I(){return E=(E+1)%65535,`flow:${Date.now().toString(36)}:${E.toString(36)}`}e(I,"h"),i(I,"E"),t(I,"newFlowId");export function publish(o){if(o.detached){const{detached:u,...s}=o;_(s);return}const n=currentFlow()??(o.context?.flowId?void 0:p()),r=n==null?o:{...o,context:{...n.flowId?{flowId:n.flowId}:{},...n.originType?{originType:n.originType}:{},...n.originNodeId?{originNodeId:n.originNodeId}:{},...n.causedByNodeId?{causedByNodeId:n.causedByNodeId}:{},...o.context}};_(r)}e(publish,"publish"),i(publish,"publish"),t(publish,"publish");function _(o){const n=globalThis.__LENSMCP_PUBLISH__;if(n)try{n(o);return}catch{}v(o)}e(_,"T"),i(_,"B"),t(_,"deliver");const R=j({burst:30,perSec:5});export function publishLazy(o,n){const r=o.startsWith(FLOW_ORIGIN_FINGERPRINT_PREFIX)?{ok:!0,suppressed:0}:R.admit(o);if(!r.ok)return;const u=n();if(r.suppressed>0&&u.raw!==null&&typeof u.raw=="object"){publish({...u,raw:{...u.raw,floodSuppressed:r.suppressed}});return}publish(u)}e(publishLazy,"publishLazy"),i(publishLazy,"publishLazy"),t(publishLazy,"publishLazy");export function resetFlowStateForTests(){w.length=0,d=void 0,f.clear(),a.clear(),b=void 0}e(resetFlowStateForTests,"resetFlowStateForTests"),i(resetFlowStateForTests,"resetFlowStateForTests"),t(resetFlowStateForTests,"resetFlowStateForTests");export function drainQueue(){return F.length=0,c=0,l.splice(0,l.length)}e(drainQueue,"drainQueue"),i(drainQueue,"drainQueue"),t(drainQueue,"drainQueue");
1
+ "use strict";var W=Object.defineProperty;var t=(e,o)=>W(e,"name",{value:o,configurable:!0});var U=Object.defineProperty,i=t((e,o)=>U(e,"name",{value:o,configurable:!0}),"t");import{createEventFloodGuard as $,estimateJsonBytes as q}from"@lensmcp/protocol-types";import{replayMark as M}from"./replay-anchors.js";const s=[],X=200,S=(()=>{const e=typeof process<"u"?process.env?.LENSMCP_PUBLISH_QUEUE_BYTES:void 0,o=Number(e);return Number.isFinite(o)&&o>0?Math.floor(o):1024*1024})(),I=[];let d=0;function L(e){const o=q(e,S);for(s.push(e),I.push(o),d+=o;s.length>X||d>S&&s.length>1;)s.shift(),d-=I.shift()??0;s.length===0&&(d=0)}t(L,"P"),i(L,"enqueue");function E(){const e=s.shift();return d-=I.shift()??0,s.length===0&&(d=0),e}t(E,"C"),i(E,"dequeue");export function queuedByteCount(){return d}t(queuedByteCount,"queuedByteCount"),i(queuedByteCount,"queuedByteCount");const p=[],F=4e3;let l;export const DEFAULT_AMBIENT_FLOW_MAX_MS=3e4;let y;function N(e){if(e==="off"||e==="Infinity")return 1/0;const o=typeof e=="string"&&e.trim()!==""?Number(e):e;if(!(typeof o!="number"||Number.isNaN(o)||o<0))return o===0||o===1/0?1/0:o}t(N,"m"),i(N,"parseMaxLifetime");function B(){if(y!==void 0)return y;const e=N(globalThis.__LENSMCP_AMBIENT_FLOW_MAX_MS__);return e!==void 0?e:N(typeof process<"u"?process.env?.LENSMCP_AMBIENT_FLOW_MAX_MS:void 0)??DEFAULT_AMBIENT_FLOW_MAX_MS}t(B,"X"),i(B,"ambientMaxMs");export function configureAmbientFlows(e){y=e.maxLifetimeMs===void 0?void 0:N(e.maxLifetimeMs)}t(configureAmbientFlows,"configureAmbientFlows"),i(configureAmbientFlows,"configureAmbientFlows");const c=new Map,j=16;function k(e){for(c.set(e,{bornAt:Date.now()});c.size>j;)c.delete(c.keys().next().value)}t(k,"Q"),i(k,"trackAmbient");function b(e){const o=c.get(e.flowId);if(!o)return!1;const n=B();return n!==1/0&&Date.now()-o.bornAt>=n}t(b,"x"),i(b,"ambientExhausted");export function extendFlowWindow(e){const o=e??currentFlow()??l?.spec;o&&(b(o)||(l={spec:o,until:Date.now()+F}))}t(extendFlowWindow,"extendFlowWindow"),i(extendFlowWindow,"extendFlowWindow");function a(){return l&&Date.now()<l.until?l.spec:void 0}t(a,"y"),i(a,"windowedFlow");export function activeFlow(){return currentFlow()??a()}t(activeFlow,"activeFlow"),i(activeFlow,"activeFlow");export function beginBackgroundFlow(e){const o={flowId:h(),originType:e.originType,...e.originNodeId?{originNodeId:e.originNodeId}:{}};return l={spec:o,until:Date.now()+F},k(o.flowId),publish({source:"react",category:"runtime",severity:"info",title:e.originType,fingerprint:_(e.originNodeId??e.originType,o.flowId),raw:{kind:"flow-origin",originNodeId:e.originNodeId,...e.continuesFlowId?{continuesFlowId:e.continuesFlowId}:{}}}),M("lens/flow",{flowId:o.flowId,kind:e.originType,...e.originNodeId?{originNodeId:e.originNodeId}:{}}),o}t(beginBackgroundFlow,"beginBackgroundFlow"),i(beginBackgroundFlow,"beginBackgroundFlow");export function flowForNewActivity(){const e=currentFlow();if(e)return e;const o=a();if(o)return b(o)?beginBackgroundFlow({originType:"timer",originNodeId:typeof location<"u"?`ambient:${location.pathname}`:"ambient",continuesFlowId:o.flowId}):o}t(flowForNewActivity,"flowForNewActivity"),i(flowForNewActivity,"flowForNewActivity");export const FLOW_ORIGIN_FINGERPRINT_PREFIX="flow-origin:";function _(e,o){return`${FLOW_ORIGIN_FINGERPRINT_PREFIX}${e}:${o}`}t(_,"S"),i(_,"originFingerprint");export function setPublisher(e){if(globalThis.__LENSMCP_PUBLISH__=e,e)for(;s.length;){const o=E();if(o)try{e(o)}catch{}}}t(setPublisher,"setPublisher"),i(setPublisher,"setPublisher");export function runInFlow(e,o){p.push(e),l={spec:e,until:Date.now()+F};try{return o()}finally{p.pop()}}t(runInFlow,"runInFlow"),i(runInFlow,"runInFlow");export function currentFlow(){return p[p.length-1]}t(currentFlow,"currentFlow"),i(currentFlow,"currentFlow");const A=Symbol.for("lensmcp.flowed"),P=2e3,f=new Map;function D(e){if(e==null||typeof e!="object")return;const o=e,n=o.nativeEvent;if(n!=null&&typeof n=="object"){const r=n.isTrusted;if(typeof r=="boolean")return r}if(typeof o.isTrusted=="boolean")return o.isTrusted}t(D,"$"),i(D,"eventTrust");function C(e){if(!(f.size<=64))for(const[o,n]of f)e>=n.until&&f.delete(o)}t(C,"q"),i(C,"pruneInputBursts");export function withFlow(e,o={}){if(typeof e!="function"||e[A])return e;const n=i(()=>{publish({source:"react",category:"runtime",severity:"info",title:o.originType??"user-click",fingerprint:_(o.originNodeId??"unknown",currentFlow()?.flowId??""),raw:{kind:"flow-origin",originNodeId:o.originNodeId}});const u=currentFlow()?.flowId;u&&M("lens/flow",{flowId:u,kind:o.originType??"user-click",...o.originNodeId?{originNodeId:o.originNodeId}:{}})},"publishOrigin"),r=i(function(...u){if(o.originType==="input-change"){if(D(u[0])===!1)return currentFlow()==null&&a()!=null&&extendFlowWindow(),e(...u);const v=o.originNodeId??"input",g=Date.now(),w=f.get(v);if(w&&g<w.until)return w.until=g+P,runInFlow(w.spec,()=>e(...u));const x={flowId:h(),originType:"input-change",originNodeId:o.originNodeId};return f.set(v,{spec:x,until:g+P}),C(g),runInFlow(x,()=>(n(),e(...u)))}const O=h();return runInFlow({flowId:O,originType:o.originType??"user-click",originNodeId:o.originNodeId},()=>(n(),e(...u)))},"flowed");return r[A]=!0,r}t(withFlow,"withFlow"),i(withFlow,"withFlow");let m=0;function h(){return m=(m+1)%65535,`flow:${Date.now().toString(36)}:${m.toString(36)}`}t(h,"E"),i(h,"newFlowId");export function publish(e){if(e.detached){const{detached:r,...u}=e;T(u);return}const o=currentFlow()??(e.context?.flowId?void 0:a()),n=o==null?e:{...e,context:{...o.flowId?{flowId:o.flowId}:{},...o.originType?{originType:o.originType}:{},...o.originNodeId?{originNodeId:o.originNodeId}:{},...o.causedByNodeId?{causedByNodeId:o.causedByNodeId}:{},...e.context}};T(n)}t(publish,"publish"),i(publish,"publish");function T(e){const o=globalThis.__LENSMCP_PUBLISH__;if(o)try{o(e);return}catch{}L(e)}t(T,"B"),i(T,"deliver");const z=$({burst:30,perSec:5});export function publishLazy(e,o){const n=e.startsWith(FLOW_ORIGIN_FINGERPRINT_PREFIX)?{ok:!0,suppressed:0}:z.admit(e);if(!n.ok)return;const r=o();if(n.suppressed>0&&r.raw!==null&&typeof r.raw=="object"){publish({...r,raw:{...r.raw,floodSuppressed:n.suppressed}});return}publish(r)}t(publishLazy,"publishLazy"),i(publishLazy,"publishLazy");export function resetFlowStateForTests(){p.length=0,l=void 0,c.clear(),f.clear(),y=void 0}t(resetFlowStateForTests,"resetFlowStateForTests"),i(resetFlowStateForTests,"resetFlowStateForTests");export function drainQueue(){return I.length=0,d=0,s.splice(0,s.length)}t(drainQueue,"drainQueue"),i(drainQueue,"drainQueue");
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var r=(e,t)=>f(e,"name",{value:t,configurable:!0});var y=Object.defineProperty,n=r((e,t)=>y(e,"name",{value:t,configurable:!0}),"n"),h=Object.defineProperty,a=n((e,t)=>h(e,"name",{value:t,configurable:!0}),"t");function c(){const e=globalThis.__LENSMCP_REPLAY__;return e&&typeof e.mark=="function"?e:void 0}r(c,"a"),n(c,"c"),a(c,"handle");export function replayActive(){return c()!==void 0}r(replayActive,"replayActive"),n(replayActive,"replayActive"),a(replayActive,"replayActive");export function replayMark(e,t){const i=c();if(i)try{i.mark(e,t)}catch{}}r(replayMark,"replayMark"),n(replayMark,"replayMark"),a(replayMark,"replayMark");export function replayCheckpoint(){const e=c();if(!(!e||typeof e.checkpoint!="function"))try{e.checkpoint()}catch{}}r(replayCheckpoint,"replayCheckpoint"),n(replayCheckpoint,"replayCheckpoint"),a(replayCheckpoint,"replayCheckpoint");export function replayLeg(e,t,i,s,l){if(!replayActive())return;const u=Date.now(),p={...s?{requestId:s}:{},...l?{flowId:l}:{}};replayMark("lens/request",{...p,method:t,url:i}),e.then(o=>replayMark("lens/response",{...p,status:o.status,ms:Date.now()-u}),o=>replayMark("lens/response",{...p,error:o instanceof Error?o.message:String(o),ms:Date.now()-u}))}r(replayLeg,"replayLeg"),n(replayLeg,"replayLeg"),a(replayLeg,"replayLeg");
1
+ "use strict";var l=Object.defineProperty;var n=(e,t)=>l(e,"name",{value:t,configurable:!0});var f=Object.defineProperty,o=n((e,t)=>f(e,"name",{value:t,configurable:!0}),"t");function a(){const e=globalThis.__LENSMCP_REPLAY__;return e&&typeof e.mark=="function"?e:void 0}n(a,"c"),o(a,"handle");export function replayActive(){return a()!==void 0}n(replayActive,"replayActive"),o(replayActive,"replayActive");export function replayMark(e,t){const c=a();if(c)try{c.mark(e,t)}catch{}}n(replayMark,"replayMark"),o(replayMark,"replayMark");export function replayCheckpoint(){const e=a();if(!(!e||typeof e.checkpoint!="function"))try{e.checkpoint()}catch{}}n(replayCheckpoint,"replayCheckpoint"),o(replayCheckpoint,"replayCheckpoint");export function replayLeg(e,t,c,i,p){if(!replayActive())return;const u=Date.now(),s={...i?{requestId:i}:{},...p?{flowId:p}:{}};replayMark("lens/request",{...s,method:t,url:c}),e.then(r=>replayMark("lens/response",{...s,status:r.status,ms:Date.now()-u}),r=>replayMark("lens/response",{...s,error:r instanceof Error?r.message:String(r),ms:Date.now()-u}))}n(replayLeg,"replayLeg"),o(replayLeg,"replayLeg");
@@ -1 +1 @@
1
- "use strict";var F=Object.defineProperty;var i=(t,e)=>F(t,"name",{value:e,configurable:!0});var I=Object.defineProperty,c=i((t,e)=>I(t,"name",{value:e,configurable:!0}),"i"),_=Object.defineProperty,n=c((t,e)=>_(t,"name",{value:e,configurable:!0}),"n");import{activeFlow as K,beginBackgroundFlow as P}from"./publish.js";import{notePageNavigation as R}from"./page-visit-runtime.js";const B=200,T=1e3,j=new Set(["page-load","route-load","timer"]),x='a[href], button, [role="link"], [role="button"]';function f(t){if(t.isTrusted!==!0)return!1;const e=t;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return!1;if(t.type==="click")return e.button===0;if(t.type!=="keydown"||e.key!=="Enter"&&e.key!==" ")return!1;const o=t.target;return typeof o?.closest=="function"&&o.closest(x)!=null}i(f,"S"),c(f,"R"),n(f,"isGesture");function h(){const t=globalThis.window;if(!t?.history||!t.location||typeof t.addEventListener!="function"||typeof t.removeEventListener!="function")return;const e=t.__LENSMCP_NAV__;return e&&typeof e.subscribe=="function"?{history:t.history,location:t.location,navBus:e,addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t),...t.document?{document:t.document}:{}}:t}i(h,"N"),c(h,"B"),n(h,"browserEnvironment");export function routeNodeId(t){return`route:${t.length>B?t.slice(0,B):t}`}i(routeNodeId,"routeNodeId"),c(routeNodeId,"routeNodeId"),n(routeNodeId,"routeNodeId");let m;export function installRouteFlows(t=h()){if(!t)return()=>{};if(m)return()=>{};let e=t.location.pathname,o=!0,u;const w=n(a=>{if(!o)return;const r=t.location.pathname;if(r===e)return;e=r;const y=u!==void 0&&Date.now()-u<T;u=void 0;const s=K(),N=s&&!(y&&j.has(s.originType??""))?s:void 0;R(r,a,N?.flowId),!N&&P({originType:"route-load",originNodeId:routeNodeId(r)})},"navigated"),l=n(a=>{try{o&&f(a)&&(u=Date.now())}catch{}},"heard"),b=n((a,r)=>n(function(...y){const s=a.apply(this,y);try{w(r)}catch{}return s},"wrapped"),"wrap"),E=t.history.pushState,g=t.history.replaceState,L=b(E,"push"),k=b(g,"replace"),d=n(()=>w("pop"),"popped");t.history.pushState=L,t.history.replaceState=k;const v=t.navBus?t.navBus.subscribe(d):void 0;v||t.addEventListener("popstate",d,{capture:!0});const p=t.document;p?.addEventListener("click",l,{capture:!0,passive:!0}),p?.addEventListener("keydown",l,{capture:!0,passive:!0});const S=n(()=>{o=!1,v?v():t.removeEventListener("popstate",d,{capture:!0}),p?.removeEventListener("click",l,{capture:!0}),p?.removeEventListener("keydown",l,{capture:!0}),t.history.pushState===L&&(t.history.pushState=E),t.history.replaceState===k&&(t.history.replaceState=g),m=void 0},"uninstall");return m=S,S}i(installRouteFlows,"installRouteFlows"),c(installRouteFlows,"installRouteFlows"),n(installRouteFlows,"installRouteFlows");
1
+ "use strict";var _=Object.defineProperty;var i=(e,t)=>_(e,"name",{value:t,configurable:!0});var B=Object.defineProperty,n=i((e,t)=>B(e,"name",{value:t,configurable:!0}),"n");import{activeFlow as I,beginBackgroundFlow as T}from"./publish.js";import{notePageNavigation as F}from"./page-visit-runtime.js";const k=200,K=1e3,P=new Set(["page-load","route-load","timer"]),R='a[href], button, [role="link"], [role="button"]';function S(e){if(e.isTrusted!==!0)return!1;const t=e;if(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return!1;if(e.type==="click")return t.button===0;if(e.type!=="keydown"||t.key!=="Enter"&&t.key!==" ")return!1;const o=e.target;return typeof o?.closest=="function"&&o.closest(R)!=null}i(S,"R"),n(S,"isGesture");function N(){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.document?{document:e.document}:{}}:e}i(N,"B"),n(N,"browserEnvironment");export function routeNodeId(e){return`route:${e.length>k?e.slice(0,k):e}`}i(routeNodeId,"routeNodeId"),n(routeNodeId,"routeNodeId");let y;export function installRouteFlows(e=N()){if(!e)return()=>{};if(y)return()=>{};let t=e.location.pathname,o=!0,c;const f=n(s=>{if(!o)return;const r=e.location.pathname;if(r===t)return;t=r;const v=c!==void 0&&Date.now()-c<K;c=void 0;const a=I(),L=a&&!(v&&P.has(a.originType??""))?a:void 0;F(r,s,L?.flowId),!L&&T({originType:"route-load",originNodeId:routeNodeId(r)})},"navigated"),u=n(s=>{try{o&&S(s)&&(c=Date.now())}catch{}},"heard"),h=n((s,r)=>n(function(...v){const a=s.apply(this,v);try{f(r)}catch{}return a},"wrapped"),"wrap"),m=e.history.pushState,w=e.history.replaceState,E=h(m,"push"),b=h(w,"replace"),l=n(()=>f("pop"),"popped");e.history.pushState=E,e.history.replaceState=b;const d=e.navBus?e.navBus.subscribe(l):void 0;d||e.addEventListener("popstate",l,{capture:!0});const p=e.document;p?.addEventListener("click",u,{capture:!0,passive:!0}),p?.addEventListener("keydown",u,{capture:!0,passive:!0});const g=n(()=>{o=!1,d?d():e.removeEventListener("popstate",l,{capture:!0}),p?.removeEventListener("click",u,{capture:!0}),p?.removeEventListener("keydown",u,{capture:!0}),e.history.pushState===E&&(e.history.pushState=m),e.history.replaceState===b&&(e.history.replaceState=w),y=void 0},"uninstall");return y=g,g}i(installRouteFlows,"installRouteFlows"),n(installRouteFlows,"installRouteFlows");
@@ -1 +1 @@
1
- "use strict";var i=Object.defineProperty;var n=(e,t)=>i(e,"name",{value:t,configurable:!0});var u=Object.defineProperty,a=n((e,t)=>u(e,"name",{value:t,configurable:!0}),"n"),s=Object.defineProperty,c=a((e,t)=>s(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"),a(routeMatchesOf,"routeMatchesOf"),c(routeMatchesOf,"routeMatchesOf");export function patternOf(e){if(!e.length)return;let t="";for(const f of e){const o=f?.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"),a(patternOf,"patternOf"),c(patternOf,"patternOf");
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 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");
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");
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var d=(e,n)=>w(e,"name",{value:n,configurable:!0});var H=Object.defineProperty,f=d((e,n)=>H(e,"name",{value:n,configurable:!0}),"p"),M=Object.defineProperty,m=f((e,n)=>M(e,"name",{value:n,configurable:!0}),"p");import{useCallback as $,useEffect as C,useMemo as U,useRef as I}from"react";import{useComponentIdentity as y}from"./component-identity.js";import{useLensmcpContext as v}from"./context.js";import{depsHash as g}from"./identity.js";import{publish as l}from"./publish.js";import{activeCommitId as h}from"./fiber-renders.js";export function tracedUseEffect(e,n,r){const a=v(),s=y(),u=i(e),t=I(void 0);C(()=>{const o=typeof performance<"u"&&performance.now?performance.now():Date.now(),c=g(r),p=t.current;t.current=c;let k;try{k=n()}finally{const b=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:{...h()?{commitId:h()}:{},hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,depsHash:c,prevDepsHash:p,durationMs:Math.max(0,b-o)}}})}return()=>{typeof k=="function"&&k(),l({source:"react",category:"render",severity:"info",title:`effect-cleanup ${e}`,fingerprint:`effect-cleanup:${e}`,raw:{kind:"effect-run",effect:{...h()?{commitId:h()}:{},hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,depsHash:t.current??c,durationMs:0,cleanupRan:!0}}})}},r)}d(tracedUseEffect,"tracedUseEffect"),f(tracedUseEffect,"tracedUseEffect"),m(tracedUseEffect,"tracedUseEffect");export function tracedUseMemo(e,n,r){const a=v(),s=y(),u=i(e),t=I(void 0),o=g(r),c=o!==t.current,p=U(n,r??[]);return c&&l({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:o,prevDepsHash:t.current,recomputed:!0}}}),t.current=o,p}d(tracedUseMemo,"tracedUseMemo"),f(tracedUseMemo,"tracedUseMemo"),m(tracedUseMemo,"tracedUseMemo");export function tracedUseCallback(e,n,r){const a=v(),s=y(),u=i(e),t=I(void 0),o=g(r),c=o!==t.current,p=$(n,r??[]);return c&&l({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:o,prevDepsHash:t.current,recomputed:!0}}}),t.current=o,p}d(tracedUseCallback,"tracedUseCallback"),f(tracedUseCallback,"tracedUseCallback"),m(tracedUseCallback,"tracedUseCallback");function i(e){const n=I(void 0);return n.current||(n.current=`${e}#${Math.random()*1e9|0}`),n.current}d(i,"l"),f(i,"H"),m(i,"useStableHookInstance");
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.21",
3
+ "version": "1.25.22",
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.21",
22
+ "@lensmcp/protocol-types": "1.25.22",
23
23
  "tslib": "^2.3.0"
24
24
  },
25
25
  "peerDependencies": {