@lensmcp/core 1.20.0 → 1.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/event-bus.js CHANGED
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var e=(o,s)=>c(o,"name",{value:s,configurable:!0});export class EventBus{static{e(this,"EventBus")}constructor(s={}){this.subs=new Set,this.dropped=0,this.capacity=s.capacity??1e4,this.onDrop=s.onDrop,this.transform=s.transform}publish(s){if(this.subs.size>this.capacity){this.dropped++,this.onDrop?.(1);return}let t=s;if(this.transform)try{t=this.transform(s)??s}catch{t=s}for(const r of this.subs)if(!(r.filter&&!r.filter(t)))try{const i=r.handler(t);i&&typeof i.then=="function"&&i.catch(()=>{})}catch{}}subscribe(s,t){const r={handler:s,filter:t};return this.subs.add(r),()=>{this.subs.delete(r)}}droppedCount(){return this.dropped}subscriberCount(){return this.subs.size}}
1
+ "use strict";var o=Object.defineProperty;var n=(e,t)=>o(e,"name",{value:t,configurable:!0});var c=Object.defineProperty,h=n((e,t)=>c(e,"name",{value:t,configurable:!0}),"e");export class EventBus{static{n(this,"EventBus")}static{h(this,"EventBus")}constructor(t={}){this.subs=new Set,this.dropped=0,this.capacity=t.capacity??1e4,this.onDrop=t.onDrop,this.transform=t.transform}publish(t){if(this.subs.size>this.capacity){this.dropped++,this.onDrop?.(1);return}let s=t;if(this.transform)try{s=this.transform(t)??t}catch{s=t}for(const r of this.subs)if(!(r.filter&&!r.filter(s)))try{const i=r.handler(s);i&&typeof i.then=="function"&&i.catch(()=>{})}catch{}}subscribe(t,s){const r={handler:t,filter:s};return this.subs.add(r),()=>{this.subs.delete(r)}}droppedCount(){return this.dropped}subscriberCount(){return this.subs.size}}
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var e=(t,n)=>o(t,"name",{value:n,configurable:!0});const F=2166136261,S=16777619;function i(t){let n=2166136261;for(let r=0;r<t.length;r++)n^=t.charCodeAt(r),n=Math.imul(n,16777619);return(n>>>0).toString(16).padStart(8,"0")}e(i,"fnv1a32");export function fingerprint(t){const n=[t.kind,t.identity,t.file??"",t.detail??""];return`${t.kind}:${i(n.join("|"))}`}e(fingerprint,"fingerprint");
1
+ "use strict";var a=Object.defineProperty;var r=(n,e)=>a(n,"name",{value:e,configurable:!0});var f=Object.defineProperty,i=r((n,e)=>f(n,"name",{value:e,configurable:!0}),"e");const l=2166136261,u=16777619;function o(n){let e=2166136261;for(let t=0;t<n.length;t++)e^=n.charCodeAt(t),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}r(o,"i"),i(o,"fnv1a32");export function fingerprint(n){const e=[n.kind,n.identity,n.file??"",n.detail??""];return`${n.kind}:${o(e.join("|"))}`}r(fingerprint,"fingerprint"),i(fingerprint,"fingerprint");
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var u=(o,d)=>m(o,"name",{value:d,configurable:!0});function f(o){const d=o.raw??null,c=d?.kind,s=o.context,a={id:o.id,parentTraceNodeId:s.causedByNodeId??s.originNodeId,lifecycle:"completed",context:s,startTime:o.timestamp,attributes:{...d??{}}};if(o.source==="react"&&c==="render"){const t=d;return{parentAxis:"render",node:{...a,type:"render",logicalId:t.render?.componentLogicalId,instanceId:t.render?.componentInstanceId,name:`render ${t.render?.componentName??"?"}`,durationMs:t.render?.actualDurationMs}}}if(o.source==="valtio"&&c==="state-update"){const t=d;return{parentAxis:"state",node:{...a,type:"state-update",logicalId:t.update?.storeId,name:`${t.update?.storeId??"?"}.${t.update?.path??"?"}`}}}if(o.source==="nestjs"&&c==="server-request"){const t=d;return{parentAxis:"backend",node:{...a,type:"server-request",name:`${t.request?.method??"?"} ${t.request?.route??"?"}`,durationMs:t.request?.durationMs}}}if(c==="loop")return{parentAxis:"performance",node:{...a,type:"loop",name:"loop",durationMs:d.loop?.durationMs}};if(o.source==="client-runtime"&&c==="user-action"){const t=d;return{parentAxis:"caused",node:{...a,type:"ui-event",logicalId:t.origin?.nodeId,name:t.origin?.label??o.title}}}}u(f,"eventToNode");export function buildGraphFromEvents(o,d){const c=[...d].sort((n,e)=>n.timestamp-e.timestamp),s=[];for(const n of c){const e=f(n);e&&(o.addNode(e.node),s.push(e))}let a=0;const t=u((n,e,r,i)=>{const l={id:`${r}:${n}->${e}`,from:n,to:e,axis:r,type:i,timestamp:o.getNode(e)?.startTime??0};o.addEdge(l),a++},"addEdge");for(const n of s){const e=n.node.context.causedByNodeId;e&&o.getNode(e)&&t(e,n.node.id,n.parentAxis??"caused","caused-by")}const p=new Map;for(const n of s){const e=n.node.context.flowId;if(!e)continue;let r=p.get(e);r||(r=[],p.set(e,r)),r.push(n)}for(const n of p.values())for(let e=1;e<n.length;e++){const r=n[e-1].node,i=n[e].node;i.context.causedByNodeId!==r.id&&t(r.id,i.id,"caused","flow-sequence")}return{nodeCount:s.length,edgeCount:a}}u(buildGraphFromEvents,"buildGraphFromEvents");
1
+ "use strict";var g=Object.defineProperty;var u=(t,r)=>g(t,"name",{value:r,configurable:!0});var I=Object.defineProperty,l=u((t,r)=>I(t,"name",{value:r,configurable:!0}),"u");function m(t){const r=t.raw??null,c=r?.kind,s=t.context,a={id:t.id,parentTraceNodeId:s.causedByNodeId??s.originNodeId,lifecycle:"completed",context:s,startTime:t.timestamp,attributes:{...r??{}}};if(t.source==="react"&&c==="render"){const n=r;return{parentAxis:"render",node:{...a,type:"render",logicalId:n.render?.componentLogicalId,instanceId:n.render?.componentInstanceId,name:`render ${n.render?.componentName??"?"}`,durationMs:n.render?.actualDurationMs}}}if(t.source==="valtio"&&c==="state-update"){const n=r;return{parentAxis:"state",node:{...a,type:"state-update",logicalId:n.update?.storeId,name:`${n.update?.storeId??"?"}.${n.update?.path??"?"}`}}}if(t.source==="nestjs"&&c==="server-request"){const n=r;return{parentAxis:"backend",node:{...a,type:"server-request",name:`${n.request?.method??"?"} ${n.request?.route??"?"}`,durationMs:n.request?.durationMs}}}if(c==="loop")return{parentAxis:"performance",node:{...a,type:"loop",name:"loop",durationMs:r.loop?.durationMs}};if(t.source==="client-runtime"&&c==="user-action"){const n=r;return{parentAxis:"caused",node:{...a,type:"ui-event",logicalId:n.origin?.nodeId,name:n.origin?.label??t.title}}}}u(m,"f"),l(m,"eventToNode");export function buildGraphFromEvents(t,r){const c=[...r].sort((o,e)=>o.timestamp-e.timestamp),s=[];for(const o of c){const e=m(o);e&&(t.addNode(e.node),s.push(e))}let a=0;const n=l((o,e,d,i)=>{const f={id:`${d}:${o}->${e}`,from:o,to:e,axis:d,type:i,timestamp:t.getNode(e)?.startTime??0};t.addEdge(f),a++},"addEdge");for(const o of s){const e=o.node.context.causedByNodeId;e&&t.getNode(e)&&n(e,o.node.id,o.parentAxis??"caused","caused-by")}const p=new Map;for(const o of s){const e=o.node.context.flowId;if(!e)continue;let d=p.get(e);d||(d=[],p.set(e,d)),d.push(o)}for(const o of p.values())for(let e=1;e<o.length;e++){const d=o[e-1].node,i=o[e].node;i.context.causedByNodeId!==d.id&&n(d.id,i.id,"caused","flow-sequence")}return{nodeCount:s.length,edgeCount:a}}u(buildGraphFromEvents,"buildGraphFromEvents"),l(buildGraphFromEvents,"buildGraphFromEvents");
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var l=(f,t)=>w(f,"name",{value:t,configurable:!0});const b=4,M=1e3;export class GraphStore{static{l(this,"GraphStore")}constructor(){this.nodes=new Map,this.edges=new Map,this.byParent=new Map,this.byFlow=new Map,this.byLogical=new Map,this.byInstance=new Map,this.byRequest=new Map,this.outByAxis=new Map,this.inByAxis=new Map}addNode(t){this.nodes.set(t.id,t),t.parentTraceNodeId&&this.addToIndex(this.byParent,t.parentTraceNodeId,t.id),t.context.flowId&&this.addToIndex(this.byFlow,t.context.flowId,t.id),t.logicalId&&this.addToIndex(this.byLogical,t.logicalId,t.id),t.instanceId&&this.addToIndex(this.byInstance,t.instanceId,t.id),t.context.requestId&&this.addToIndex(this.byRequest,t.context.requestId,t.id)}updateNode(t,e){const i=this.nodes.get(t);if(!i)throw new Error(`Unknown node: ${t}`);const s={...i,...e,id:i.id};return this.nodes.set(t,s),s}getNode(t){return this.nodes.get(t)}addEdge(t){this.edges.set(t.id,t);let e=this.outByAxis.get(t.axis);e||(e=new Map,this.outByAxis.set(t.axis,e)),this.addToIndex(e,t.from,t.id);let i=this.inByAxis.get(t.axis);i||(i=new Map,this.inByAxis.set(t.axis,i)),this.addToIndex(i,t.to,t.id)}getEdge(t){return this.edges.get(t)}childrenOf(t){return this.materialiseNodes(this.byParent.get(t))}nodesInFlow(t){return this.materialiseNodes(this.byFlow.get(t))}nodesByLogical(t){return this.materialiseNodes(this.byLogical.get(t))}nodesByInstance(t){return this.materialiseNodes(this.byInstance.get(t))}nodesByRequest(t){return this.materialiseNodes(this.byRequest.get(t))}traverse(t){const e=this.nodes.get(t.from);if(!e)return{nodes:[],edges:[]};const i=Array.isArray(t.lens)?t.lens:[t.lens],s=t.direction??"both",x=t.depth??4,y=t.maxNodes??1e3,o=new Set,c=new Set,h=[{id:e.id,d:0}];for(;h.length&&!(o.size>=y);){const{id:n,d:u}=h.shift();if(!o.has(n)&&(o.add(n),!(u>=x)))for(const g of i){if(s==="out"||s==="both"){const d=this.outByAxis.get(g)?.get(n);if(d)for(const a of d){c.add(a);const r=this.edges.get(a);o.has(r.to)||h.push({id:r.to,d:u+1})}}if(s==="in"||s==="both"){const d=this.inByAxis.get(g)?.get(n);if(d)for(const a of d){c.add(a);const r=this.edges.get(a);o.has(r.from)||h.push({id:r.from,d:u+1})}}}}return{nodes:this.materialiseNodes(o),edges:[...c].map(n=>this.edges.get(n)).filter(n=>!!n)}}nodeCount(){return this.nodes.size}edgeCount(){return this.edges.size}addToIndex(t,e,i){let s=t.get(e);s||(s=new Set,t.set(e,s)),s.add(i)}materialiseNodes(t){if(!t)return[];const e=[];for(const i of t){const s=this.nodes.get(i);s&&e.push(s)}return e}}
1
+ "use strict";var w=Object.defineProperty;var l=(h,e)=>w(h,"name",{value:e,configurable:!0});var p=Object.defineProperty,I=l((h,e)=>p(h,"name",{value:e,configurable:!0}),"l");const m=4,N=1e3;export class GraphStore{static{l(this,"GraphStore")}static{I(this,"GraphStore")}constructor(){this.nodes=new Map,this.edges=new Map,this.byParent=new Map,this.byFlow=new Map,this.byLogical=new Map,this.byInstance=new Map,this.byRequest=new Map,this.outByAxis=new Map,this.inByAxis=new Map}addNode(e){this.nodes.set(e.id,e),e.parentTraceNodeId&&this.addToIndex(this.byParent,e.parentTraceNodeId,e.id),e.context.flowId&&this.addToIndex(this.byFlow,e.context.flowId,e.id),e.logicalId&&this.addToIndex(this.byLogical,e.logicalId,e.id),e.instanceId&&this.addToIndex(this.byInstance,e.instanceId,e.id),e.context.requestId&&this.addToIndex(this.byRequest,e.context.requestId,e.id)}updateNode(e,s){const i=this.nodes.get(e);if(!i)throw new Error(`Unknown node: ${e}`);const t={...i,...s,id:i.id};return this.nodes.set(e,t),t}getNode(e){return this.nodes.get(e)}addEdge(e){this.edges.set(e.id,e);let s=this.outByAxis.get(e.axis);s||(s=new Map,this.outByAxis.set(e.axis,s)),this.addToIndex(s,e.from,e.id);let i=this.inByAxis.get(e.axis);i||(i=new Map,this.inByAxis.set(e.axis,i)),this.addToIndex(i,e.to,e.id)}getEdge(e){return this.edges.get(e)}childrenOf(e){return this.materialiseNodes(this.byParent.get(e))}nodesInFlow(e){return this.materialiseNodes(this.byFlow.get(e))}nodesByLogical(e){return this.materialiseNodes(this.byLogical.get(e))}nodesByInstance(e){return this.materialiseNodes(this.byInstance.get(e))}nodesByRequest(e){return this.materialiseNodes(this.byRequest.get(e))}traverse(e){const s=this.nodes.get(e.from);if(!s)return{nodes:[],edges:[]};const i=Array.isArray(e.lens)?e.lens:[e.lens],t=e.direction??"both",f=e.depth??4,x=e.maxNodes??1e3,n=new Set,g=new Set,c=[{id:s.id,d:0}];for(;c.length&&!(n.size>=x);){const{id:d,d:u}=c.shift();if(!n.has(d)&&(n.add(d),!(u>=f)))for(const y of i){if(t==="out"||t==="both"){const o=this.outByAxis.get(y)?.get(d);if(o)for(const a of o){g.add(a);const r=this.edges.get(a);n.has(r.to)||c.push({id:r.to,d:u+1})}}if(t==="in"||t==="both"){const o=this.inByAxis.get(y)?.get(d);if(o)for(const a of o){g.add(a);const r=this.edges.get(a);n.has(r.from)||c.push({id:r.from,d:u+1})}}}}return{nodes:this.materialiseNodes(n),edges:[...g].map(d=>this.edges.get(d)).filter(d=>!!d)}}nodeCount(){return this.nodes.size}edgeCount(){return this.edges.size}addToIndex(e,s,i){let t=e.get(s);t||(t=new Set,e.set(s,t)),t.add(i)}materialiseNodes(e){if(!e)return[];const s=[];for(const i of e){const t=this.nodes.get(i);t&&s.push(t)}return s}}
package/lib/patterns.js CHANGED
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var p=(u,l)=>w(u,"name",{value:l,configurable:!0});export function detectDbInLoop(u,l={}){const a=l.threshold??5,i=[];for(const r of u){const o=r.raw??null;if(o?.kind!=="loop"||!o.loop)continue;const e=o.loop.dbCallsInsideLoop??0;e>a&&i.push({kind:"db-in-loop",severity:"warning",title:`${e} DB calls inside a loop (${o.loop.iterations??"?"} iterations)`,evidence:[r.id],details:{dbCallsInsideLoop:e,iterations:o.loop.iterations,durationMs:o.loop.durationMs,threshold:a},detectedAt:r.timestamp})}return i}p(detectDbInLoop,"detectDbInLoop");export function detectNPlusOne(u,l={}){const a=l.threshold??3,i=new Map;for(const o of u){const e=o.raw??null;if(e?.kind!=="db-query"||!e.query?.signature)continue;const t=e.query.signature;let n=i.get(t);n||(n=[],i.set(t,n)),n.push(o)}const r=[];for(const[o,e]of i)e.length>=a&&r.push({kind:"n+1-query",severity:"warning",title:`Query repeated ${e.length}\xD7 \u2014 likely N+1`,evidence:e.map(t=>t.id),details:{signature:o,count:e.length,threshold:a},detectedAt:e[e.length-1].timestamp});return r}p(detectNPlusOne,"detectNPlusOne");export function detectRenderStorm(u,l={}){const a=l.threshold??5,i=l.windowMs??250,r=new Map;for(const e of u){if(e.source!=="react")continue;const t=e.raw??null;if(t?.kind!=="render"||!t.render?.componentInstanceId)continue;const n=t.render.componentInstanceId;let s=r.get(n);s||(s=[],r.set(n,s)),s.push(e)}const o=[];for(const[e,t]of r){t.sort((s,d)=>s.timestamp-d.timestamp);let n=0;for(let s=0;s<t.length;s++){for(;t[s].timestamp-t[n].timestamp>i;)n++;const d=s-n+1;if(d>a){const c=t.slice(n,s+1),h=c[0].raw.render?.componentName??e;o.push({kind:"render-storm",severity:"warning",title:`${h} rendered ${d}\xD7 in ${i}ms`,evidence:c.map(f=>f.id),details:{componentInstanceId:e,count:d,windowMs:i,threshold:a},detectedAt:c[c.length-1].timestamp});break}}}return o}p(detectRenderStorm,"detectRenderStorm");export function findSlowPath(u,l,a){const i=new Map,r=new Set;function o(t){const n=i.get(t);if(n)return n;if(r.has(t))return{path:[t],totalDurationMs:a(t)};r.add(t);const s=a(t),d=l.get(t)??[];let c;for(const f of d){const m=o(f);(!c||m.totalDurationMs>c.totalDurationMs)&&(c=m)}r.delete(t);const h=c?{path:[t,...c.path],totalDurationMs:s+c.totalDurationMs}:{path:[t],totalDurationMs:s};return i.set(t,h),h}p(o,"best");let e={path:[],totalDurationMs:0};for(const t of u){const n=o(t);n.totalDurationMs>e.totalDurationMs&&(e=n)}return e}p(findSlowPath,"findSlowPath");
1
+ "use strict";var g=Object.defineProperty;var p=(c,a)=>g(c,"name",{value:a,configurable:!0});var M=Object.defineProperty,f=p((c,a)=>M(c,"name",{value:a,configurable:!0}),"p");export function detectDbInLoop(c,a={}){const d=a.threshold??5,i=[];for(const s of c){const n=s.raw??null;if(n?.kind!=="loop"||!n.loop)continue;const e=n.loop.dbCallsInsideLoop??0;e>d&&i.push({kind:"db-in-loop",severity:"warning",title:`${e} DB calls inside a loop (${n.loop.iterations??"?"} iterations)`,evidence:[s.id],details:{dbCallsInsideLoop:e,iterations:n.loop.iterations,durationMs:n.loop.durationMs,threshold:d},detectedAt:s.timestamp})}return i}p(detectDbInLoop,"detectDbInLoop"),f(detectDbInLoop,"detectDbInLoop");export function detectNPlusOne(c,a={}){const d=a.threshold??3,i=new Map;for(const n of c){const e=n.raw??null;if(e?.kind!=="db-query"||!e.query?.signature)continue;const t=e.query.signature;let o=i.get(t);o||(o=[],i.set(t,o)),o.push(n)}const s=[];for(const[n,e]of i)e.length>=d&&s.push({kind:"n+1-query",severity:"warning",title:`Query repeated ${e.length}\xD7 \u2014 likely N+1`,evidence:e.map(t=>t.id),details:{signature:n,count:e.length,threshold:d},detectedAt:e[e.length-1].timestamp});return s}p(detectNPlusOne,"detectNPlusOne"),f(detectNPlusOne,"detectNPlusOne");export function detectRenderStorm(c,a={}){const d=a.threshold??5,i=a.windowMs??250,s=new Map;for(const e of c){if(e.source!=="react")continue;const t=e.raw??null;if(t?.kind!=="render"||!t.render?.componentInstanceId)continue;const o=t.render.componentInstanceId;let r=s.get(o);r||(r=[],s.set(o,r)),r.push(e)}const n=[];for(const[e,t]of s){t.sort((r,u)=>r.timestamp-u.timestamp);let o=0;for(let r=0;r<t.length;r++){for(;t[r].timestamp-t[o].timestamp>i;)o++;const u=r-o+1;if(u>d){const l=t.slice(o,r+1),h=l[0].raw.render?.componentName??e;n.push({kind:"render-storm",severity:"warning",title:`${h} rendered ${u}\xD7 in ${i}ms`,evidence:l.map(m=>m.id),details:{componentInstanceId:e,count:u,windowMs:i,threshold:d},detectedAt:l[l.length-1].timestamp});break}}}return n}p(detectRenderStorm,"detectRenderStorm"),f(detectRenderStorm,"detectRenderStorm");export function findSlowPath(c,a,d){const i=new Map,s=new Set;function n(t){const o=i.get(t);if(o)return o;if(s.has(t))return{path:[t],totalDurationMs:d(t)};s.add(t);const r=d(t),u=a.get(t)??[];let l;for(const m of u){const w=n(m);(!l||w.totalDurationMs>l.totalDurationMs)&&(l=w)}s.delete(t);const h=l?{path:[t,...l.path],totalDurationMs:r+l.totalDurationMs}:{path:[t],totalDurationMs:r};return i.set(t,h),h}p(n,"o"),f(n,"best");let e={path:[],totalDurationMs:0};for(const t of c){const o=n(t);o.totalDurationMs>e.totalDurationMs&&(e=o)}return e}p(findSlowPath,"findSlowPath"),f(findSlowPath,"findSlowPath");
package/lib/redact.js CHANGED
@@ -1 +1 @@
1
- "use strict";var E=Object.defineProperty;var o=(t,e)=>E(t,"name",{value:e,configurable:!0});export const REDACTED="REDACTED",MAX_TITLE_CHARS=300,MAX_MESSAGE_CHARS=4096,MAX_URL_CHARS=1024;const _=["token","secret","password","passwd","apikey","credential","assertion","signature"],p=new Set(["key","auth","authorization","jwt","code","sig","pwd","pass","session","sid","bearer","otp","cookie","set-cookie"]);export function isSecretParam(t){const e=t.toLowerCase();if(_.some(r=>e.includes(r)))return!0;for(const r of e.split(/[-_.]+/))if(r&&p.has(r))return!0;return!1}o(isSecretParam,"isSecretParam");const A=/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@\s]*@/i,u=/([?&#])([^=&#\s]+)=([^&#\s]*)/g;export function redactUrlParams(t){return t&&t.replace(A,`$1${REDACTED}@`).replace(u,(r,s,n)=>isSecretParam(n)?`${s}${n}=${REDACTED}`:r)}o(redactUrlParams,"redactUrlParams");export function redactUrl(t){return t&&clip(redactUrlParams(t),1024)}o(redactUrl,"redactUrl");const R=/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g,S=/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi,d=/\b(authorization|x-api-key|api-key|cookie|set-cookie|proxy-authorization)\b(\s*[:=]\s*)(["']?)([^\s"',;]{4,})\3/gi;export function redactText(t){return redactUrlParams(t).replace(d,(e,r,s,n)=>`${r}${s}${n}${REDACTED}${n}`).replace(R,REDACTED).replace(S,(e,r)=>`${r} ${REDACTED}`)}o(redactText,"redactText");export function clip(t,e){return t.length<=e?t:`${t.slice(0,e)}\u2026[lensmcp truncated: ${t.length-e} more chars]`}o(clip,"clip");export function safeText(t,e=4096){if(t!==void 0)return clip(redactText(t),e)}o(safeText,"safeText");export function safeTitle(t){return clip(redactText(t),300)}o(safeTitle,"safeTitle");const T=6,x=64;export function redactDeep(t,e=0){if(typeof t=="string")return redactText(t);if(t===null||typeof t!="object"||e>=T)return t;if(Array.isArray(t)){let n=!1;const i=t.map((c,a)=>{if(a>=x)return c;const f=redactDeep(c,e+1);return f!==c&&(n=!0),f});return n?i:t}let r=!1;const s={};for(const[n,i]of Object.entries(t)){const c=isSecretParam(n)&&i!==void 0&&i!==null?REDACTED:redactDeep(i,e+1);c!==i&&(r=!0),s[n]=c}return r?s:t}o(redactDeep,"redactDeep");
1
+ "use strict";var f=Object.defineProperty;var o=(e,r)=>f(e,"name",{value:r,configurable:!0});var l=Object.defineProperty,a=o((e,r)=>l(e,"name",{value:r,configurable:!0}),"o");export const REDACTED="REDACTED",MAX_TITLE_CHARS=300,MAX_MESSAGE_CHARS=4096,MAX_URL_CHARS=1024;const d=["token","secret","password","passwd","apikey","credential","assertion","signature"],x=new Set(["key","auth","authorization","jwt","code","sig","pwd","pass","session","sid","bearer","otp","cookie","set-cookie"]);export function isSecretParam(e){const r=e.toLowerCase();if(d.some(t=>r.includes(t)))return!0;for(const t of r.split(/[-_.]+/))if(t&&x.has(t))return!0;return!1}o(isSecretParam,"isSecretParam"),a(isSecretParam,"isSecretParam");const A=/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@\s]*@/i,$=/([?&#])([^=&#\s]+)=([^&#\s]*)/g;export function redactUrlParams(e){return e&&e.replace(A,`$1${REDACTED}@`).replace($,(r,t,s)=>isSecretParam(s)?`${t}${s}=${REDACTED}`:r)}o(redactUrlParams,"redactUrlParams"),a(redactUrlParams,"redactUrlParams");export function redactUrl(e){return e&&clip(redactUrlParams(e),1024)}o(redactUrl,"redactUrl"),a(redactUrl,"redactUrl");const _=/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g,b=/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi,y=/\b(authorization|x-api-key|api-key|cookie|set-cookie|proxy-authorization)\b(\s*[:=]\s*)(["']?)([^\s"',;]{4,})\3/gi;export function redactText(e){return redactUrlParams(e).replace(y,(r,t,s,n)=>`${t}${s}${n}${REDACTED}${n}`).replace(_,REDACTED).replace(b,(r,t)=>`${t} ${REDACTED}`)}o(redactText,"redactText"),a(redactText,"redactText");export function clip(e,r){return e.length<=r?e:`${e.slice(0,r)}\u2026[lensmcp truncated: ${e.length-r} more chars]`}o(clip,"clip"),a(clip,"clip");export function safeText(e,r=4096){if(e!==void 0)return clip(redactText(e),r)}o(safeText,"safeText"),a(safeText,"safeText");export function safeTitle(e){return clip(redactText(e),300)}o(safeTitle,"safeTitle"),a(safeTitle,"safeTitle");const T=6,g=64;export function redactDeep(e,r=0){if(typeof e=="string")return redactText(e);if(e===null||typeof e!="object"||r>=T)return e;if(Array.isArray(e)){let n=!1;const i=e.map((c,p)=>{if(p>=g)return c;const u=redactDeep(c,r+1);return u!==c&&(n=!0),u});return n?i:e}let t=!1;const s={};for(const[n,i]of Object.entries(e)){const c=isSecretParam(n)&&i!==void 0&&i!==null?REDACTED:redactDeep(i,r+1);c!==i&&(t=!0),s[n]=c}return t?s:e}o(redactDeep,"redactDeep"),a(redactDeep,"redactDeep");
@@ -1 +1 @@
1
- "use strict";var i=Object.defineProperty;var c=(t,r)=>i(t,"name",{value:r,configurable:!0});export class ReducerRegistry{static{c(this,"ReducerRegistry")}constructor(){this.reducers=[]}register(r,s){if(this.reducers.some(e=>e.name===r))throw new Error(`Reducer already registered: ${r}`);this.reducers.push({name:r,reducer:s})}list(){return this.reducers}async dispatch(r){for(const{reducer:s}of this.reducers)try{const e=s(r);e&&typeof e.then=="function"&&await e}catch{}}}
1
+ "use strict";var i=Object.defineProperty;var c=(t,e)=>i(t,"name",{value:e,configurable:!0});var u=Object.defineProperty,a=c((t,e)=>u(t,"name",{value:e,configurable:!0}),"c");export class ReducerRegistry{static{c(this,"ReducerRegistry")}static{a(this,"ReducerRegistry")}constructor(){this.reducers=[]}register(e,s){if(this.reducers.some(r=>r.name===e))throw new Error(`Reducer already registered: ${e}`);this.reducers.push({name:e,reducer:s})}list(){return this.reducers}async dispatch(e){for(const{reducer:s}of this.reducers)try{const r=s(e);r&&typeof r.then=="function"&&await r}catch{}}}
@@ -1 +1 @@
1
- "use strict";var h=Object.defineProperty;var o=(r,e)=>h(r,"name",{value:e,configurable:!0});export class ResourceStore{static{o(this,"ResourceStore")}constructor(){this.entries=new Map,this.subs=new Map}register(e,s){if(this.entries.has(e))throw new Error(`Resource already registered: ${e}`);return this.entries.set(e,{uri:e,produce:s,revision:0}),()=>{this.entries.delete(e),this.subs.delete(e)}}async read(e){const s=this.entries.get(e);if(!s)throw new Error(`Unknown resource: ${e}`);return s.produce()}list(){return[...this.entries.keys()]}async markDirty(e){const s=this.entries.get(e);if(!s)return;const t=await s.produce(),n=JSON.stringify(t);if(n===s.lastJson)return;s.lastJson=n,s.revision+=1;const i=this.subs.get(e);if(i)for(const c of i)try{c(e,s.revision)}catch{}}revision(e){return this.entries.get(e)?.revision}subscribe(e,s){let t=this.subs.get(e);return t||(t=new Set,this.subs.set(e,t)),t.add(s),()=>{t?.delete(s)}}}
1
+ "use strict";var u=Object.defineProperty;var i=(r,e)=>u(r,"name",{value:e,configurable:!0});var a=Object.defineProperty,h=i((r,e)=>a(r,"name",{value:e,configurable:!0}),"o");export class ResourceStore{static{i(this,"ResourceStore")}static{h(this,"ResourceStore")}constructor(){this.entries=new Map,this.subs=new Map}register(e,t){if(this.entries.has(e))throw new Error(`Resource already registered: ${e}`);return this.entries.set(e,{uri:e,produce:t,revision:0}),()=>{this.entries.delete(e),this.subs.delete(e)}}async read(e){const t=this.entries.get(e);if(!t)throw new Error(`Unknown resource: ${e}`);return t.produce()}list(){return[...this.entries.keys()]}async markDirty(e){const t=this.entries.get(e);if(!t)return;const s=await t.produce(),n=JSON.stringify(s);if(n===t.lastJson)return;t.lastJson=n,t.revision+=1;const o=this.subs.get(e);if(o)for(const c of o)try{c(e,t.revision)}catch{}}revision(e){return this.entries.get(e)?.revision}subscribe(e,t){let s=this.subs.get(e);return s||(s=new Set,this.subs.set(e,s)),s.add(t),()=>{s?.delete(t)}}}
package/lib/story.js CHANGED
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var c=(t,a)=>w(t,"name",{value:a,configurable:!0});export function groupByFlow(t){const a=new Map;for(const r of t){const e=r.context.flowId;if(!e)continue;let o=a.get(e);o||(o=[],a.set(e,o)),o.push(r)}return a}c(groupByFlow,"groupByFlow");export function compileStory(t,a={}){let r,e;if(a.flowId)e=a.flowId,r=t.filter(i=>i.context.flowId===e);else{const i=t.find(n=>n.context.flowId);if(!i)return;e=i.context.flowId,r=t.filter(n=>n.context.flowId===e)}if(r.length===0)return;r.sort((i,n)=>i.timestamp-n.timestamp);const o=1e3;r.length>o&&(r=[r[0],...r.slice(r.length-(o-1))]);const u=r[0],s=[];let l,f;for(const i of r){const n=g(i);if(n){if(s.push(n),n.kind==="render"||n.kind==="final-render"){const d=i.raw;d?.render&&(l={id:d.render.id,page:d.render.page,route:d.render.route,componentName:d.render.componentName})}else if(i.source==="visual"&&n.kind==="visual-violation"){const d=i.raw;d?.frame&&(f=d.frame.id)}}}for(let i=s.length-1;i>=0;i--)if(s[i].kind==="render"){s[i]={...s[i],kind:"final-render"};break}const m=r[0].timestamp,p=r[r.length-1].timestamp;return{flowId:e,origin:{type:u.context.originType,nodeId:u.context.originNodeId,at:u.timestamp},phases:s,finalState:l?{page:l.page,route:l.route,componentName:l.componentName,renderId:l.id,visualFrameId:f}:void 0,startedAt:m,endedAt:p,eventCount:r.length}}c(compileStory,"compileStory");function g(t){const r=(t.raw??null)?.kind;if(r==="flow-origin"||t.source==="client-runtime"&&r==="user-action"){const e=t.raw;return{kind:"user-action",at:t.timestamp,label:e?.origin?.label??t.title,eventIds:[t.id]}}if(t.source==="react"&&r==="render"){const e=t.raw;return{kind:"render",at:t.timestamp,label:`render ${e?.render?.componentName??"?"}`,eventIds:[t.id],details:e?.render?{componentName:e.render.componentName,durationMs:e.render.actualDurationMs}:void 0}}if(t.source==="react"&&r==="slot-content-changed"){const e=t.raw,o=e?.slot?.toComponent??"?";return{kind:/spinner|loader|loading/i.test(o)?"loading-ui":"idle-ui",at:t.timestamp,label:`slot ${e?.slot?.slotLogicalId??""} \u2192 ${o}`,eventIds:[t.id]}}if(t.source==="client-runtime"&&r==="route"){const e=t.raw;return{kind:"route-transition",at:t.timestamp,label:`route ${e?.from??""} \u2192 ${e?.url??""}`,eventIds:[t.id]}}if(t.source==="valtio"&&r==="state-update"){const e=t.raw;return{kind:"state-update",at:t.timestamp,label:`${e?.update?.storeId??"?"}.${e?.update?.path??"?"}`,eventIds:[t.id],details:e?.update}}if(t.source==="nestjs"&&r==="server-request"){const e=t.raw;return{kind:"backend-request",at:t.timestamp,label:`${e?.request?.method??"?"} ${e?.request?.route??"?"} \u2192 ${e?.request?.status??"?"}`,eventIds:[t.id],details:e?.request}}if(t.source==="chrome"&&t.category==="network")return{kind:"backend-request",at:t.timestamp,label:t.title,eventIds:[t.id]};if(t.source==="visual"&&r==="visual-violation"){const e=t.raw;return{kind:"visual-violation",at:t.timestamp,label:`${e?.violation?.ruleType??"rule"} ${e?.violation?.ruleId??""}`,eventIds:[t.id]}}}c(g,"classifyEvent");
1
+ "use strict";var w=Object.defineProperty;var u=(e,n)=>w(e,"name",{value:n,configurable:!0});var I=Object.defineProperty,m=u((e,n)=>I(e,"name",{value:n,configurable:!0}),"c");export function groupByFlow(e){const n=new Map;for(const t of e){const o=t.context.flowId;if(!o)continue;let s=n.get(o);s||(s=[],n.set(o,s)),s.push(t)}return n}u(groupByFlow,"groupByFlow"),m(groupByFlow,"groupByFlow");export function compileStory(e,n={}){let t,o;if(n.flowId)o=n.flowId,t=e.filter(r=>r.context.flowId===o);else{const r=e.find(i=>i.context.flowId);if(!r)return;o=r.context.flowId,t=e.filter(i=>i.context.flowId===o)}if(t.length===0)return;t.sort((r,i)=>r.timestamp-i.timestamp);const s=1e3;t.length>s&&(t=[t[0],...t.slice(t.length-(s-1))]);const c=t[0],d=[];let l,p;for(const r of t){const i=f(r);if(i){if(d.push(i),i.kind==="render"||i.kind==="final-render"){const a=r.raw;a?.render&&(l={id:a.render.id,page:a.render.page,route:a.render.route,componentName:a.render.componentName})}else if(r.source==="visual"&&i.kind==="visual-violation"){const a=r.raw;a?.frame&&(p=a.frame.id)}}}for(let r=d.length-1;r>=0;r--)if(d[r].kind==="render"){d[r]={...d[r],kind:"final-render"};break}const v=t[0].timestamp,g=t[t.length-1].timestamp;return{flowId:o,origin:{type:c.context.originType,nodeId:c.context.originNodeId,at:c.timestamp},phases:d,finalState:l?{page:l.page,route:l.route,componentName:l.componentName,renderId:l.id,visualFrameId:p}:void 0,startedAt:v,endedAt:g,eventCount:t.length}}u(compileStory,"compileStory"),m(compileStory,"compileStory");function f(e){const n=(e.raw??null)?.kind;if(n==="flow-origin"||e.source==="client-runtime"&&n==="user-action"){const t=e.raw;return{kind:"user-action",at:e.timestamp,label:t?.origin?.label??e.title,eventIds:[e.id]}}if(e.source==="react"&&n==="render"){const t=e.raw;return{kind:"render",at:e.timestamp,label:`render ${t?.render?.componentName??"?"}`,eventIds:[e.id],details:t?.render?{componentName:t.render.componentName,durationMs:t.render.actualDurationMs}:void 0}}if(e.source==="react"&&n==="slot-content-changed"){const t=e.raw,o=t?.slot?.toComponent??"?";return{kind:/spinner|loader|loading/i.test(o)?"loading-ui":"idle-ui",at:e.timestamp,label:`slot ${t?.slot?.slotLogicalId??""} \u2192 ${o}`,eventIds:[e.id]}}if(e.source==="client-runtime"&&n==="route"){const t=e.raw;return{kind:"route-transition",at:e.timestamp,label:`route ${t?.from??""} \u2192 ${t?.url??""}`,eventIds:[e.id]}}if(e.source==="valtio"&&n==="state-update"){const t=e.raw;return{kind:"state-update",at:e.timestamp,label:`${t?.update?.storeId??"?"}.${t?.update?.path??"?"}`,eventIds:[e.id],details:t?.update}}if(e.source==="nestjs"&&n==="server-request"){const t=e.raw;return{kind:"backend-request",at:e.timestamp,label:`${t?.request?.method??"?"} ${t?.request?.route??"?"} \u2192 ${t?.request?.status??"?"}`,eventIds:[e.id],details:t?.request}}if(e.source==="chrome"&&e.category==="network")return{kind:"backend-request",at:e.timestamp,label:e.title,eventIds:[e.id]};if(e.source==="visual"&&n==="visual-violation"){const t=e.raw;return{kind:"visual-violation",at:e.timestamp,label:`${t?.violation?.ruleType??"rule"} ${t?.violation?.ruleId??""}`,eventIds:[e.id]}}}u(f,"g"),m(f,"classifyEvent");
package/lib/thresholds.js CHANGED
@@ -1 +1 @@
1
- "use strict";var r=Object.defineProperty;var t=(o,e)=>r(o,"name",{value:e,configurable:!0});export const DEFAULT_THRESHOLDS={dbInLoop:5,nPlusOne:3,renderStorm:5,slowRouteMs:500,slowRenderMs:16,slowQueryMs:100};export function resolveThresholds(o){const e={...DEFAULT_THRESHOLDS};if(o)for(const n of Object.keys(DEFAULT_THRESHOLDS)){const s=o[n];typeof s=="number"&&Number.isFinite(s)&&s>=0&&(e[n]=s)}return e}t(resolveThresholds,"resolveThresholds");
1
+ "use strict";var t=Object.defineProperty;var s=(e,r)=>t(e,"name",{value:r,configurable:!0});var l=Object.defineProperty,u=s((e,r)=>l(e,"name",{value:r,configurable:!0}),"t");export const DEFAULT_THRESHOLDS={dbInLoop:5,nPlusOne:3,renderStorm:5,slowRouteMs:500,slowRenderMs:16,slowQueryMs:100};export function resolveThresholds(e){const r={...DEFAULT_THRESHOLDS};if(e)for(const n of Object.keys(DEFAULT_THRESHOLDS)){const o=e[n];typeof o=="number"&&Number.isFinite(o)&&o>=0&&(r[n]=o)}return r}s(resolveThresholds,"resolveThresholds"),u(resolveThresholds,"resolveThresholds");
package/lib/ulid.js CHANGED
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var r=(t,o)=>l(t,"name",{value:o,configurable:!0});const i="0123456789ABCDEFGHJKMNPQRSTVWXYZ",A=16;function s(t,o){let e="",n=t;for(let c=o-1;c>=0;c--){const u=n%32;e=i[u]+e,n=(n-u)/32}return e}r(s,"encodeTime");function a(t){const o=new Uint8Array(t);globalThis.crypto.getRandomValues(o);let e="";for(let n=0;n<t;n++)e+=i[(o[n]??0)&31];return e}r(a,"encodeRandom");export function ulid(t=Date.now()){return s(t,10)+a(16)}r(ulid,"ulid");
1
+ "use strict";var d=Object.defineProperty;var r=(e,n)=>d(e,"name",{value:n,configurable:!0});var f=Object.defineProperty,c=r((e,n)=>f(e,"name",{value:n,configurable:!0}),"r");const i="0123456789ABCDEFGHJKMNPQRSTVWXYZ",b=16;function l(e,n){let o="",t=e;for(let u=n-1;u>=0;u--){const a=t%32;o=i[a]+o,t=(t-a)/32}return o}r(l,"s"),c(l,"encodeTime");function s(e){const n=new Uint8Array(e);globalThis.crypto.getRandomValues(n);let o="";for(let t=0;t<e;t++)o+=i[(n[t]??0)&31];return o}r(s,"a"),c(s,"encodeRandom");export function ulid(e=Date.now()){return l(e,10)+s(16)}r(ulid,"ulid"),c(ulid,"ulid");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/core",
3
- "version": "1.20.0",
3
+ "version": "1.20.1",
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.20.0",
22
+ "@lensmcp/protocol-types": "1.20.1",
23
23
  "tslib": "^2.3.0"
24
24
  },
25
25
  "license": "Apache-2.0",