@lensmcp/core 1.25.79 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +1 -1
  3. package/lib/ai-content.js +1 -1
  4. package/lib/answer-budget.js +2 -2
  5. package/lib/bus-rotation.js +1 -1
  6. package/lib/capture-off.js +1 -1
  7. package/lib/event-bus.js +1 -1
  8. package/lib/event-loop-history.js +1 -1
  9. package/lib/event-loop.d.ts +9 -1
  10. package/lib/event-loop.js +1 -1
  11. package/lib/event-redactor.js +1 -1
  12. package/lib/fingerprint.js +1 -1
  13. package/lib/flow-categories.js +1 -1
  14. package/lib/flow-segments.js +1 -1
  15. package/lib/flow-shape.d.ts +15 -8
  16. package/lib/flow-shape.js +1 -1
  17. package/lib/flows-config.js +1 -1
  18. package/lib/graph-from-events.js +1 -1
  19. package/lib/graph-store.js +1 -1
  20. package/lib/headless-flow.js +1 -1
  21. package/lib/http-exchange.js +1 -1
  22. package/lib/http-shape.js +1 -1
  23. package/lib/key-pattern.js +1 -1
  24. package/lib/lens-config.d.ts +14 -0
  25. package/lib/lens-config.js +1 -0
  26. package/lib/lens-dir.d.ts +9 -0
  27. package/lib/lens-dir.js +7 -7
  28. package/lib/lens-events.js +2 -2
  29. package/lib/lens-store.d.ts +37 -0
  30. package/lib/lens-store.js +1 -0
  31. package/lib/patterns.d.ts +28 -12
  32. package/lib/patterns.js +1 -1
  33. package/lib/performance-window.d.ts +20 -3
  34. package/lib/performance-window.js +2 -2
  35. package/lib/pg-errors.js +1 -1
  36. package/lib/queue-signals.d.ts +7 -0
  37. package/lib/queue-signals.js +1 -0
  38. package/lib/redact.js +1 -1
  39. package/lib/redis-expiry.js +1 -1
  40. package/lib/reducer-registry.js +1 -1
  41. package/lib/replay-store.js +1 -1
  42. package/lib/resource-store.js +1 -1
  43. package/lib/route-template.js +1 -1
  44. package/lib/service-hop.js +1 -1
  45. package/lib/settings.js +2 -2
  46. package/lib/sql-shape.js +3 -3
  47. package/lib/sql-values.js +1 -1
  48. package/lib/stores.js +2 -2
  49. package/lib/story.js +1 -1
  50. package/lib/thresholds.js +1 -1
  51. package/lib/ulid.js +1 -1
  52. package/package.json +17 -2
package/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './lib/flow-shape.js';
15
15
  export * from './lib/flow-segments.js';
16
16
  export * from './lib/flow-categories.js';
17
17
  export * from './lib/headless-flow.js';
18
+ export * from './lib/queue-signals.js';
18
19
  export * from './lib/service-hop.js';
19
20
  export * from './lib/flows-config.js';
20
21
  export * from './lib/patterns.js';
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";export*from"./lib/common.js";export*from"./lib/ulid.js";export*from"./lib/event-bus.js";export*from"./lib/event-redactor.js";export*from"./lib/resource-store.js";export*from"./lib/answer-budget.js";export*from"./lib/graph-store.js";export*from"./lib/fingerprint.js";export*from"./lib/reducer-registry.js";export*from"./lib/story.js";export*from"./lib/route-template.js";export*from"./lib/sql-shape.js";export*from"./lib/http-shape.js";export*from"./lib/flow-shape.js";export*from"./lib/flow-segments.js";export*from"./lib/flow-categories.js";export*from"./lib/headless-flow.js";export*from"./lib/service-hop.js";export*from"./lib/flows-config.js";export*from"./lib/patterns.js";export*from"./lib/thresholds.js";export*from"./lib/performance-window.js";export*from"./lib/event-loop.js";export*from"./lib/event-loop-history.js";export*from"./lib/graph-from-events.js";
1
+ "use strict";export*from"./lib/common.js";export*from"./lib/ulid.js";export*from"./lib/event-bus.js";export*from"./lib/event-redactor.js";export*from"./lib/resource-store.js";export*from"./lib/answer-budget.js";export*from"./lib/graph-store.js";export*from"./lib/fingerprint.js";export*from"./lib/reducer-registry.js";export*from"./lib/story.js";export*from"./lib/route-template.js";export*from"./lib/sql-shape.js";export*from"./lib/http-shape.js";export*from"./lib/flow-shape.js";export*from"./lib/flow-segments.js";export*from"./lib/flow-categories.js";export*from"./lib/headless-flow.js";export*from"./lib/queue-signals.js";export*from"./lib/service-hop.js";export*from"./lib/flows-config.js";export*from"./lib/patterns.js";export*from"./lib/thresholds.js";export*from"./lib/performance-window.js";export*from"./lib/event-loop.js";export*from"./lib/event-loop-history.js";export*from"./lib/graph-from-events.js";
package/lib/ai-content.js CHANGED
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var r=(t,i)=>a(t,"name",{value:i,configurable:!0});var s=Object.defineProperty,n=r((t,i)=>s(t,"name",{value:i,configurable:!0}),"r");import*as c from"node:fs";import{dirname as l,join as o}from"node:path";export const AI_CONTENT_DIR="ai";const d=/^ai_[0-9a-z]{8,40}$/;export const isAiCallId=n(t=>typeof t=="string"&&d.test(t),"isAiCallId");export function aiContentDir(t){return o(l(t),AI_CONTENT_DIR)}r(aiContentDir,"aiContentDir"),n(aiContentDir,"aiContentDir");export function aiContentFile(t,i){if(!isAiCallId(i))throw new Error("invalid ai call id");return o(aiContentDir(t),`${i}.json`)}r(aiContentFile,"aiContentFile"),n(aiContentFile,"aiContentFile");export function readAiContent(t,i){if(isAiCallId(i))try{const e=JSON.parse(c.readFileSync(aiContentFile(t,i),"utf8"));return e&&e.schemaVersion===1&&e.id===i?e:void 0}catch{return}}r(readAiContent,"readAiContent"),n(readAiContent,"readAiContent");
1
+ "use strict";var c=Object.defineProperty;var n=(e,t)=>c(e,"name",{value:t,configurable:!0});var s=Object.defineProperty,i=n((e,t)=>s(e,"name",{value:t,configurable:!0}),"r"),l=Object.defineProperty,o=i((e,t)=>l(e,"name",{value:t,configurable:!0}),"r");import*as d from"node:fs";import{dirname as f,join as a}from"node:path";export const AI_CONTENT_DIR="ai";const u=/^ai_[0-9a-z]{8,40}$/;export const isAiCallId=o(e=>typeof e=="string"&&u.test(e),"isAiCallId");export function aiContentDir(e){return a(f(e),AI_CONTENT_DIR)}n(aiContentDir,"aiContentDir"),i(aiContentDir,"aiContentDir"),o(aiContentDir,"aiContentDir");export function aiContentFile(e,t){if(!isAiCallId(t))throw new Error("invalid ai call id");return a(aiContentDir(e),`${t}.json`)}n(aiContentFile,"aiContentFile"),i(aiContentFile,"aiContentFile"),o(aiContentFile,"aiContentFile");export function readAiContent(e,t){if(isAiCallId(t))try{const r=JSON.parse(d.readFileSync(aiContentFile(e,t),"utf8"));return r&&r.schemaVersion===1&&r.id===t?r:void 0}catch{return}}n(readAiContent,"readAiContent"),i(readAiContent,"readAiContent"),o(readAiContent,"readAiContent");
@@ -1,2 +1,2 @@
1
- "use strict";var L=Object.defineProperty;var m=(e,n)=>L(e,"name",{value:n,configurable:!0});var Y=Object.defineProperty,f=m((e,n)=>Y(e,"name",{value:n,configurable:!0}),"h");import{boundedClone as z}from"@lensmcp/protocol-types";export const DEFAULT_ANSWER_BUDGET_BYTES=24*1024,ANSWER_BUDGET_ENV="LENSMCP_ANSWER_BUDGET_BYTES",MIN_ANSWER_BUDGET_BYTES=2*1024,ANSWER_CUT_KEY="cutToFit",MAX_CUT_NOTE_BYTES=120,FITTED_STRING_CHARS=1500,REPEATED_STRING_MIN_CHARS=200;const C=600,V=32,H=new Set(["timestamp","startedAt","startTime","at","emittedAt","lastSeenAt","endedAt","endTime","t","ts","time"]),K=f(e=>typeof e=="number"&&e>=1e11&&e<=1e14,"isEpochMs"),J=.95;export function answerBudgetBytes(e=process.env){const n=e[ANSWER_BUDGET_ENV];if(n===void 0||n.trim()==="")return DEFAULT_ANSWER_BUDGET_BYTES;const r=Number(n);return!Number.isFinite(r)||r<0?DEFAULT_ANSWER_BUDGET_BYTES:r===0?Number.POSITIVE_INFINITY:Math.max(MIN_ANSWER_BUDGET_BYTES,Math.floor(r))}m(answerBudgetBytes,"answerBudgetBytes"),f(answerBudgetBytes,"answerBudgetBytes");export function utf8Bytes(e){let n=0;for(let r=0;r<e.length;r++){const o=e.charCodeAt(r);o<128?n+=1:o<2048?n+=2:o>=55296&&o<=56319&&r+1<e.length&&(e.charCodeAt(r+1)&64512)===56320?(n+=4,r+=1):n+=3}return n}m(utf8Bytes,"utf8Bytes"),f(utf8Bytes,"utf8Bytes");export function jsonBytes(e){let n;try{n=JSON.stringify(e)}catch{return Number.POSITIVE_INFINITY}return n===void 0?0:utf8Bytes(n)}m(jsonBytes,"jsonBytes"),f(jsonBytes,"jsonBytes");const R=f(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isRecord");function O(e){if(!R(e))return!1;const n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}m(O,"C"),f(O,"isPlain");export function newestEndOf(e){const n=e[0];if(e.length<2||!R(n))return;let r;for(const o of Object.keys(n)){if(typeof n[o]!="number"||!(H.has(o)||K(n[o])))continue;let s=0,i=0,u=!0,a=n[o];for(let y=1;y<e.length;y++){const x=e[y],d=R(x)?x[o]:void 0;if(typeof d!="number"){u=!1;break}d>a?s+=1:d<a&&(i+=1),a=d}const h=s+i;if(!u||h===0)continue;const l=Math.max(s,i)/h;l>=J&&(!r||l>r.agreement)&&(r={end:s>=i?"end":"start",agreement:l})}return r?.end}m(newestEndOf,"newestEndOf"),f(newestEndOf,"newestEndOf");export function newestFirst(e){return newestEndOf(e)==="end"?[...e].reverse():e.slice()}m(newestFirst,"newestFirst"),f(newestFirst,"newestFirst");export function shortenText(e,n){if(e.length<=n)return e;let r=Math.max(0,n);const o=e.lastIndexOf(`
2
- `,r);return o>=r/2&&(r=o),r>0&&(e.charCodeAt(r-1)&64512)===55296&&(r-=1),`${e.slice(0,r)}\u2026[lensmcp truncated: ${e.length-r} more chars]`}m(shortenText,"shortenText"),f(shortenText,"shortenText");export function fitList(e,n,r={}){const o=e.length,s=e.reduce((c,w)=>c+jsonBytes(w)+1,2);if(s<=n)return{items:e.slice(),total:o,returned:o,kept:"all",shortenedStrings:0,repeatedStrings:0,bytes:s};const i=r.newest??newestEndOf(e),u=i??r.keep??"start",a=r.name??"items",h=r.maxStringChars??FITTED_STRING_CHARS,l=u==="start"?e:[...e].reverse(),y=String(Math.max(0,o-1)).length,x=new Map,d=[],b=[];let E=2,_=0,$=0;for(let c=0;c<l.length;c++){const w=new Map,T=[];let M=0;const A=f((t,p,g,G,W)=>{if(typeof t=="string"){if(t.length>=REPEATED_STRING_MIN_CHARS){const S=x.get(t)??w.get(t);if(S)return T.push({holder:G,key:W,owner:S.owner,path:S.path}),`\u2026[lensmcp: same text as ${a}[${"9".repeat(y)}]${S.path}]`;w.set(t,{owner:c,path:p})}return t.length>h?(M+=1,shortenText(t,h)):t}if(g>=V)return t;if(Array.isArray(t)){const S=[];return t.forEach((I,D)=>S.push(A(I,`${p}[${D}]`,g+1,S,D))),S}if(O(t)){const S={};for(const I of Object.keys(t))S[I]=A(t[I],`${p}.${I}`,g+1,S,I);return S}return t},"slim"),B=[];let N=A(l[c],"",0,B,0),v=jsonBytes(N)+1;if(b.length===0&&E+v>n)N=F(l[c],Math.max(0,n-E-1)),v=jsonBytes(N)+1,T.length=0,w.clear(),M=1;else if(E+v>n)break;b.push(N),E+=v,_+=M,$+=T.length;for(const[t,p]of w)x.set(t,p);for(const t of T)d.push(t.holder===B?{...t,holder:b,key:b.length-1}:t)}const k=b.length,j=f(c=>u==="start"?c:k-1-c,"indexOf");if(u==="end"){for(const c of d)c.holder===b&&(c.key=j(c.key));b.reverse()}for(const c of d)c.holder[c.key]=`\u2026[lensmcp: same text as ${a}[${j(c.owner)}]${c.path}]`;return{items:b,total:o,returned:k,kept:k===o?"all":i?"newest":u==="start"?"first":"last",shortenedStrings:_,repeatedStrings:$,bytes:jsonBytes(b)}}m(fitList,"fitList"),f(fitList,"fitList");function F(e,n){let r=Math.max(256,n),o=e;for(let s=0;s<6;s++){if(o=z(e,{rawByteLimit:r,maxStringBytes:Math.min(2e3,Math.max(128,Math.floor(r/4))),maxArrayItems:64}).value,jsonBytes(o)<=n)return o;r=Math.floor(r*.6)}return o}m(F,"D"),f(F,"clampTo");export function shareBudget(e,n){const r=e.map((i,u)=>({size:i,index:u})).sort((i,u)=>i.size-u.size),o=new Array(e.length).fill(0);let s=Math.max(0,n);return r.forEach(({size:i,index:u},a)=>{const h=Math.floor(s/(r.length-a));o[u]=Math.min(i,h),s-=o[u]}),o}m(shareBudget,"shareBudget"),f(shareBudget,"shareBudget");export function cutNote(e){return(e.lists?.length?"Cut to fit: each list in `lists` shows `returned` of `total`; every other count is of the whole.":"Cut to fit: large values were shortened; every count is of the whole.")+(e.more?" Rest: see `more`.":"")}m(cutNote,"cutNote"),f(cutNote,"cutNote");function P(e,n){const r={...e},o=new WeakSet([r]),s=[];let i=0;for(const u of n){const a=u.split("."),h=a[a.length-1];let l=r;for(const y of a.slice(0,-1)){const x=l[y];if(!O(x)){l=void 0;break}const d=o.has(x)?x:{...x};o.add(d),l[y]=d,l=d}!l||l[h]===void 0||l[h]===null||(s.push({keys:a,value:l[h]}),i+=jsonBytes(l[h]),l[h]=null)}return s.length?{body:r,parts:s,bytes:i}:void 0}m(P,"K"),f(P,"holdWhole");function U(e,n){for(const{keys:r,value:o}of n){let s=e;for(const i of r.slice(0,-1)){const u=s[i],a=O(u)?u:{};s[i]=a,s=a}s[r[r.length-1]]=o}return e}m(U,"z"),f(U,"putBack");export function fitAnswer(e,n,r={}){if(!Number.isFinite(n)||e===null||typeof e!="object")return{value:e};const o=jsonBytes(e);if(o<=n)return{value:e};const s=r.whole?.length&&O(e)?P(e,r.whole):void 0,i=s?s.body:e,u=s?jsonBytes(i):o,a=s?Math.max(MIN_ANSWER_BUDGET_BYTES,n-s.bytes):n;if(u<=a)return{value:e};const h=[];let l=0,y=0,x=!1,d;const b=f(()=>(d={budget:n,original:o,...h.length?{lists:h}:{},...l?{shortened:l}:{},...y?{repeated:y}:{},...x?{clamped:!0}:{},...s?{whole:s.parts.map(t=>t.keys.join("."))}:{},...r.more?{more:r.more}:{},note:cutNote({lists:h,more:r.more})},d),"describe"),E=f(t=>({value:s?U(t,s.parts):t,cut:d}),"done");if(Array.isArray(i)){const t=fitList(i,a);return t.kept!=="all"&&h.push({list:"items",total:t.total,returned:t.returned,kept:t.kept}),l=t.shortenedStrings,y=t.repeatedStrings,b(),E(t.items)}if(!O(i))return{value:e};const _=Object.keys(i),$=_.filter(t=>Array.isArray(i[t])&&i[t].length>0),k=$.map(t=>jsonBytes(i[t])),j=u-k.reduce((t,p)=>t+p,0),c=shareBudget(k,a-j-C),w={};$.forEach((t,p)=>{if(k[p]<=c[p])return;const g=fitList(i[t],c[p],{name:t,...r.newest?.[t]?{newest:r.newest[t]}:{}});w[t]=g.items,g.kept!=="all"&&h.push({list:t,total:g.total,returned:g.returned,kept:g.kept}),l+=g.shortenedStrings,y+=g.repeatedStrings});const T=f(t=>({[ANSWER_CUT_KEY]:b(),...t}),"assemble"),M={};for(const t of _)M[t]=t in w?w[t]:i[t];let A=T(M);if(jsonBytes(A)<=a)return E(A);x=!0;let B=Math.max(512,a-C);for(let t=0;t<6;t++){if(A=T(F(M,B)),jsonBytes(A)<=a)return E(A);B=Math.floor(B*.6)}const N={};let v=C;for(const t of _){const p=i[t];if(p!==null&&typeof p=="object")continue;const g=jsonBytes(p)+utf8Bytes(t)+4;if(v+g>a)break;N[t]=p,v+=g}return E(T(N))}m(fitAnswer,"fitAnswer"),f(fitAnswer,"fitAnswer");
1
+ "use strict";var z=Object.defineProperty;var p=(t,n)=>z(t,"name",{value:n,configurable:!0});var G=Object.defineProperty,y=p((t,n)=>G(t,"name",{value:n,configurable:!0}),"m"),V=Object.defineProperty,f=y((t,n)=>V(t,"name",{value:n,configurable:!0}),"h");import{boundedClone as H}from"@lensmcp/protocol-types";export const DEFAULT_ANSWER_BUDGET_BYTES=24*1024,ANSWER_BUDGET_ENV="LENSMCP_ANSWER_BUDGET_BYTES",MIN_ANSWER_BUDGET_BYTES=2*1024,ANSWER_CUT_KEY="cutToFit",MAX_CUT_NOTE_BYTES=120,FITTED_STRING_CHARS=1500,REPEATED_STRING_MIN_CHARS=200;const F=600,K=32,J=new Set(["timestamp","startedAt","startTime","at","emittedAt","lastSeenAt","endedAt","endTime","t","ts","time"]),X=f(t=>typeof t=="number"&&t>=1e11&&t<=1e14,"isEpochMs"),q=.95;export function answerBudgetBytes(t=process.env){const n=t[ANSWER_BUDGET_ENV];if(n===void 0||n.trim()==="")return DEFAULT_ANSWER_BUDGET_BYTES;const r=Number(n);return!Number.isFinite(r)||r<0?DEFAULT_ANSWER_BUDGET_BYTES:r===0?Number.POSITIVE_INFINITY:Math.max(MIN_ANSWER_BUDGET_BYTES,Math.floor(r))}p(answerBudgetBytes,"answerBudgetBytes"),y(answerBudgetBytes,"answerBudgetBytes"),f(answerBudgetBytes,"answerBudgetBytes");export function utf8Bytes(t){let n=0;for(let r=0;r<t.length;r++){const o=t.charCodeAt(r);o<128?n+=1:o<2048?n+=2:o>=55296&&o<=56319&&r+1<t.length&&(t.charCodeAt(r+1)&64512)===56320?(n+=4,r+=1):n+=3}return n}p(utf8Bytes,"utf8Bytes"),y(utf8Bytes,"utf8Bytes"),f(utf8Bytes,"utf8Bytes");export function jsonBytes(t){let n;try{n=JSON.stringify(t)}catch{return Number.POSITIVE_INFINITY}return n===void 0?0:utf8Bytes(n)}p(jsonBytes,"jsonBytes"),y(jsonBytes,"jsonBytes"),f(jsonBytes,"jsonBytes");const P=f(t=>typeof t=="object"&&t!==null&&!Array.isArray(t),"isRecord");function _(t){if(!P(t))return!1;const n=Object.getPrototypeOf(t);return n===Object.prototype||n===null}p(_,"O"),y(_,"C"),f(_,"isPlain");export function newestEndOf(t){const n=t[0];if(t.length<2||!P(n))return;let r;for(const o of Object.keys(n)){if(typeof n[o]!="number"||!(J.has(o)||X(n[o])))continue;let s=0,i=0,u=!0,a=n[o];for(let x=1;x<t.length;x++){const b=t[x],d=P(b)?b[o]:void 0;if(typeof d!="number"){u=!1;break}d>a?s+=1:d<a&&(i+=1),a=d}const h=s+i;if(!u||h===0)continue;const l=Math.max(s,i)/h;l>=q&&(!r||l>r.agreement)&&(r={end:s>=i?"end":"start",agreement:l})}return r?.end}p(newestEndOf,"newestEndOf"),y(newestEndOf,"newestEndOf"),f(newestEndOf,"newestEndOf");export function newestFirst(t){return newestEndOf(t)==="end"?[...t].reverse():t.slice()}p(newestFirst,"newestFirst"),y(newestFirst,"newestFirst"),f(newestFirst,"newestFirst");export function shortenText(t,n){if(t.length<=n)return t;let r=Math.max(0,n);const o=t.lastIndexOf(`
2
+ `,r);return o>=r/2&&(r=o),r>0&&(t.charCodeAt(r-1)&64512)===55296&&(r-=1),`${t.slice(0,r)}\u2026[lensmcp truncated: ${t.length-r} more chars]`}p(shortenText,"shortenText"),y(shortenText,"shortenText"),f(shortenText,"shortenText");export function fitList(t,n,r={}){const o=t.length,s=t.reduce((c,E)=>c+jsonBytes(E)+1,2);if(s<=n)return{items:t.slice(),total:o,returned:o,kept:"all",shortenedStrings:0,repeatedStrings:0,bytes:s};const i=r.newest??newestEndOf(t),u=i??r.keep??"start",a=r.name??"items",h=r.maxStringChars??FITTED_STRING_CHARS,l=u==="start"?t:[...t].reverse(),x=String(Math.max(0,o-1)).length,b=new Map,d=[],w=[];let A=2,I=0,C=0;for(let c=0;c<l.length;c++){const E=new Map,v=[];let B=0;const T=f((e,m,g,L,W)=>{if(typeof e=="string"){if(e.length>=REPEATED_STRING_MIN_CHARS){const S=b.get(e)??E.get(e);if(S)return v.push({holder:L,key:W,owner:S.owner,path:S.path}),`\u2026[lensmcp: same text as ${a}[${"9".repeat(x)}]${S.path}]`;E.set(e,{owner:c,path:m})}return e.length>h?(B+=1,shortenText(e,h)):e}if(g>=K)return e;if(Array.isArray(e)){const S=[];return e.forEach((j,D)=>S.push(T(j,`${m}[${D}]`,g+1,S,D))),S}if(_(e)){const S={};for(const j of Object.keys(e))S[j]=T(e[j],`${m}.${j}`,g+1,S,j);return S}return e},"slim"),O=[];let N=T(l[c],"",0,O,0),M=jsonBytes(N)+1;if(w.length===0&&A+M>n)N=R(l[c],Math.max(0,n-A-1)),M=jsonBytes(N)+1,v.length=0,E.clear(),B=1;else if(A+M>n)break;w.push(N),A+=M,I+=B,C+=v.length;for(const[e,m]of E)b.set(e,m);for(const e of v)d.push(e.holder===O?{...e,holder:w,key:w.length-1}:e)}const k=w.length,$=f(c=>u==="start"?c:k-1-c,"indexOf");if(u==="end"){for(const c of d)c.holder===w&&(c.key=$(c.key));w.reverse()}for(const c of d)c.holder[c.key]=`\u2026[lensmcp: same text as ${a}[${$(c.owner)}]${c.path}]`;return{items:w,total:o,returned:k,kept:k===o?"all":i?"newest":u==="start"?"first":"last",shortenedStrings:I,repeatedStrings:C,bytes:jsonBytes(w)}}p(fitList,"fitList"),y(fitList,"fitList"),f(fitList,"fitList");function R(t,n){let r=Math.max(256,n),o=t;for(let s=0;s<6;s++){if(o=H(t,{rawByteLimit:r,maxStringBytes:Math.min(2e3,Math.max(128,Math.floor(r/4))),maxArrayItems:64}).value,jsonBytes(o)<=n)return o;r=Math.floor(r*.6)}return o}p(R,"F"),y(R,"D"),f(R,"clampTo");export function shareBudget(t,n){const r=t.map((i,u)=>({size:i,index:u})).sort((i,u)=>i.size-u.size),o=new Array(t.length).fill(0);let s=Math.max(0,n);return r.forEach(({size:i,index:u},a)=>{const h=Math.floor(s/(r.length-a));o[u]=Math.min(i,h),s-=o[u]}),o}p(shareBudget,"shareBudget"),y(shareBudget,"shareBudget"),f(shareBudget,"shareBudget");export function cutNote(t){return(t.lists?.length?"Cut to fit: each list in `lists` shows `returned` of `total`; every other count is of the whole.":"Cut to fit: large values were shortened; every count is of the whole.")+(t.more?" Rest: see `more`.":"")}p(cutNote,"cutNote"),y(cutNote,"cutNote"),f(cutNote,"cutNote");function U(t,n){const r={...t},o=new WeakSet([r]),s=[];let i=0;for(const u of n){const a=u.split("."),h=a[a.length-1];let l=r;for(const x of a.slice(0,-1)){const b=l[x];if(!_(b)){l=void 0;break}const d=o.has(b)?b:{...b};o.add(d),l[x]=d,l=d}!l||l[h]===void 0||l[h]===null||(s.push({keys:a,value:l[h]}),i+=jsonBytes(l[h]),l[h]=null)}return s.length?{body:r,parts:s,bytes:i}:void 0}p(U,"P"),y(U,"K"),f(U,"holdWhole");function Y(t,n){for(const{keys:r,value:o}of n){let s=t;for(const i of r.slice(0,-1)){const u=s[i],a=_(u)?u:{};s[i]=a,s=a}s[r[r.length-1]]=o}return t}p(Y,"U"),y(Y,"z"),f(Y,"putBack");export function fitAnswer(t,n,r={}){if(!Number.isFinite(n)||t===null||typeof t!="object")return{value:t};const o=jsonBytes(t);if(o<=n)return{value:t};const s=r.whole?.length&&_(t)?U(t,r.whole):void 0,i=s?s.body:t,u=s?jsonBytes(i):o,a=s?Math.max(MIN_ANSWER_BUDGET_BYTES,n-s.bytes):n;if(u<=a)return{value:t};const h=[];let l=0,x=0,b=!1,d;const w=f(()=>(d={budget:n,original:o,...h.length?{lists:h}:{},...l?{shortened:l}:{},...x?{repeated:x}:{},...b?{clamped:!0}:{},...s?{whole:s.parts.map(e=>e.keys.join("."))}:{},...r.more?{more:r.more}:{},note:cutNote({lists:h,more:r.more})},d),"describe"),A=f(e=>({value:s?Y(e,s.parts):e,cut:d}),"done");if(Array.isArray(i)){const e=fitList(i,a);return e.kept!=="all"&&h.push({list:"items",total:e.total,returned:e.returned,kept:e.kept}),l=e.shortenedStrings,x=e.repeatedStrings,w(),A(e.items)}if(!_(i))return{value:t};const I=Object.keys(i),C=I.filter(e=>Array.isArray(i[e])&&i[e].length>0),k=C.map(e=>jsonBytes(i[e])),$=u-k.reduce((e,m)=>e+m,0),c=shareBudget(k,a-$-F),E={};C.forEach((e,m)=>{if(k[m]<=c[m])return;const g=fitList(i[e],c[m],{name:e,...r.newest?.[e]?{newest:r.newest[e]}:{}});E[e]=g.items,g.kept!=="all"&&h.push({list:e,total:g.total,returned:g.returned,kept:g.kept}),l+=g.shortenedStrings,x+=g.repeatedStrings});const v=f(e=>({[ANSWER_CUT_KEY]:w(),...e}),"assemble"),B={};for(const e of I)B[e]=e in E?E[e]:i[e];let T=v(B);if(jsonBytes(T)<=a)return A(T);b=!0;let O=Math.max(512,a-F);for(let e=0;e<6;e++){if(T=v(R(B,O)),jsonBytes(T)<=a)return A(T);O=Math.floor(O*.6)}const N={};let M=F;for(const e of I){const m=i[e];if(m!==null&&typeof m=="object")continue;const g=jsonBytes(m)+utf8Bytes(e)+4;if(M+g>a)break;N[e]=m,M+=g}return A(v(N))}p(fitAnswer,"fitAnswer"),y(fitAnswer,"fitAnswer"),f(fitAnswer,"fitAnswer");
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var i=(t,r)=>l(t,"name",{value:r,configurable:!0});var S=Object.defineProperty,u=i((t,r)=>S(t,"name",{value:r,configurable:!0}),"u");export const MAX_BUS_GENERATIONS=20,BUS_ROTATE_CHECK_BYTES=1048576;export function busCapsFromEnv(t=process.env){const r=Number(t.LENSMCP_EVENT_MAX_BYTES),e=Number(t.LENSMCP_EVENT_MAX_FILES);return{maxBytes:Number.isFinite(r)&&r>0?r:50*1024*1024,maxFiles:Number.isFinite(e)&&e>=1&&e<=20?Math.floor(e):5}}i(busCapsFromEnv,"busCapsFromEnv"),u(busCapsFromEnv,"busCapsFromEnv");export function rotateBusFile(t,r){const{fs:e,maxBytes:y,maxFiles:a}=r,n=`${t}.rotate.lock`,o=r.staleLockMs??3e4;let s;for(let c=0;c<2&&s===void 0;c++)try{s=e.openSync(n,"wx")}catch{try{if(Date.now()-e.statSync(n).mtimeMs<=o)return"busy";e.unlinkSync(n)}catch{}}if(s===void 0)return"busy";try{try{if(e.statSync(t).size<=y)return"not-needed"}catch{return"not-needed"}try{e.unlinkSync(`${t}.${a}`)}catch{}for(let c=a+1;c<=20;c++)try{e.unlinkSync(`${t}.${c}`)}catch{}for(let c=a-1;c>=1;c--)try{e.renameSync(`${t}.${c}`,`${t}.${c+1}`)}catch{}try{e.renameSync(t,`${t}.1`)}catch{}return"rotated"}finally{try{e.closeSync(s)}catch{}try{e.unlinkSync(n)}catch{}}}i(rotateBusFile,"rotateBusFile"),u(rotateBusFile,"rotateBusFile");export function createBusRotator(t,r){const{fs:e,maxBytes:y}=r,a=Math.max(0,Math.min(r.checkEveryBytes??1048576,y));let n=a,o=0;return s=>{if(n>=a||o+n>y)try{o=e.statSync(t).size,n=0,o>y&&rotateBusFile(t,r)==="rotated"&&(o=0)}catch{}n+=s}}i(createBusRotator,"createBusRotator"),u(createBusRotator,"createBusRotator");
1
+ "use strict";var m=Object.defineProperty;var i=(e,r)=>m(e,"name",{value:r,configurable:!0});var S=Object.defineProperty,y=i((e,r)=>S(e,"name",{value:r,configurable:!0}),"i"),f=Object.defineProperty,l=y((e,r)=>f(e,"name",{value:r,configurable:!0}),"u");export const MAX_BUS_GENERATIONS=20,BUS_ROTATE_CHECK_BYTES=1048576;export function busCapsFromEnv(e=process.env){const r=Number(e.LENSMCP_EVENT_MAX_BYTES),t=Number(e.LENSMCP_EVENT_MAX_FILES);return{maxBytes:Number.isFinite(r)&&r>0?r:50*1024*1024,maxFiles:Number.isFinite(t)&&t>=1&&t<=20?Math.floor(t):5}}i(busCapsFromEnv,"busCapsFromEnv"),y(busCapsFromEnv,"busCapsFromEnv"),l(busCapsFromEnv,"busCapsFromEnv");export function rotateBusFile(e,r){const{fs:t,maxBytes:u,maxFiles:a}=r,c=`${e}.rotate.lock`,o=r.staleLockMs??3e4;let s;for(let n=0;n<2&&s===void 0;n++)try{s=t.openSync(c,"wx")}catch{try{if(Date.now()-t.statSync(c).mtimeMs<=o)return"busy";t.unlinkSync(c)}catch{}}if(s===void 0)return"busy";try{try{if(t.statSync(e).size<=u)return"not-needed"}catch{return"not-needed"}try{t.unlinkSync(`${e}.${a}`)}catch{}for(let n=a+1;n<=20;n++)try{t.unlinkSync(`${e}.${n}`)}catch{}for(let n=a-1;n>=1;n--)try{t.renameSync(`${e}.${n}`,`${e}.${n+1}`)}catch{}try{t.renameSync(e,`${e}.1`)}catch{}return"rotated"}finally{try{t.closeSync(s)}catch{}try{t.unlinkSync(c)}catch{}}}i(rotateBusFile,"rotateBusFile"),y(rotateBusFile,"rotateBusFile"),l(rotateBusFile,"rotateBusFile");export function createBusRotator(e,r){const{fs:t,maxBytes:u}=r,a=Math.max(0,Math.min(r.checkEveryBytes??1048576,u));let c=a,o=0;return s=>{if(c>=a||o+c>u)try{o=t.statSync(e).size,c=0,o>u&&rotateBusFile(e,r)==="rotated"&&(o=0)}catch{}c+=s}}i(createBusRotator,"createBusRotator"),y(createBusRotator,"createBusRotator"),l(createBusRotator,"createBusRotator");
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var s=(r,t)=>d(r,"name",{value:t,configurable:!0});var S=Object.defineProperty,a=s((r,t)=>S(r,"name",{value:t,configurable:!0}),"s");export const CAPTURE_FILE_NAME="capture.json",CAPTURE_OFF_EVERY_MS=2e3;export function readCaptureOff(r){return readCapture(r).off}s(readCaptureOff,"readCaptureOff"),a(readCaptureOff,"readCaptureOff");export function readCapture(r){const t=new Map;try{const e=JSON.parse(r);if(e.parts&&typeof e.parts=="object"&&!Array.isArray(e.parts))for(const[o,p]of Object.entries(e.parts))Array.isArray(p)&&t.set(o,new Set(p.filter(c=>typeof c=="string")));return{off:new Set(Array.isArray(e.off)?e.off.filter(o=>typeof o=="string"&&o.length>0):[]),parts:t}}catch{return{off:new Set,parts:t}}}s(readCapture,"readCapture"),a(readCapture,"readCapture");export function isRecordOff(r,t,e){return!r.size||typeof t!="string"?!1:r.has(t)||typeof e=="string"&&r.has(`${t}:${e}`)}s(isRecordOff,"isRecordOff"),a(isRecordOff,"isRecordOff");export function createCaptureOff(r,t,e={}){const o=e.everyMs??2e3,p=e.now??(()=>Date.now());let c=-1/0,u,y=new Set,h=new Map;const i=a(()=>{u=void 0,y=new Set,h=new Map},"none"),O=a(n=>{c=n;const f=r();if(!f)return i();let l;try{l=t.statSync(f).mtimeMs}catch{return i()}if(l!==u)try{({off:y,parts:h}=readCapture(t.readFileSync(f,"utf8"))),u=l}catch{i()}},"refresh"),A=a(()=>{const n=p();n-c>=o&&O(n)},"look"),w=a(((n,f)=>{try{return A(),isRecordOff(y,n,f)}catch{return!1}}),"ask");return w.part=(n,f)=>{try{return A(),!!n&&h.get(n)?.has(f)===!0}catch{return!1}},w.reset=()=>{c=-1/0,i()},w}s(createCaptureOff,"createCaptureOff"),a(createCaptureOff,"createCaptureOff");
1
+ "use strict";var A=Object.defineProperty;var s=(r,e)=>A(r,"name",{value:e,configurable:!0});var S=Object.defineProperty,p=s((r,e)=>S(r,"name",{value:e,configurable:!0}),"s"),g=Object.defineProperty,n=p((r,e)=>g(r,"name",{value:e,configurable:!0}),"s");export const CAPTURE_FILE_NAME="capture.json",CAPTURE_OFF_EVERY_MS=2e3;export function readCaptureOff(r){return readCapture(r).off}s(readCaptureOff,"readCaptureOff"),p(readCaptureOff,"readCaptureOff"),n(readCaptureOff,"readCaptureOff");export function readCapture(r){const e=new Map;try{const t=JSON.parse(r);if(t.parts&&typeof t.parts=="object"&&!Array.isArray(t.parts))for(const[o,u]of Object.entries(t.parts))Array.isArray(u)&&e.set(o,new Set(u.filter(c=>typeof c=="string")));return{off:new Set(Array.isArray(t.off)?t.off.filter(o=>typeof o=="string"&&o.length>0):[]),parts:e}}catch{return{off:new Set,parts:e}}}s(readCapture,"readCapture"),p(readCapture,"readCapture"),n(readCapture,"readCapture");export function isRecordOff(r,e,t){return!r.size||typeof e!="string"?!1:r.has(e)||typeof t=="string"&&r.has(`${e}:${t}`)}s(isRecordOff,"isRecordOff"),p(isRecordOff,"isRecordOff"),n(isRecordOff,"isRecordOff");export function createCaptureOff(r,e,t={}){const o=t.everyMs??2e3,u=t.now??(()=>Date.now());let c=-1/0,y,O=new Set,d=new Map;const i=n(()=>{y=void 0,O=new Set,d=new Map},"none"),C=n(a=>{c=a;const f=r();if(!f)return i();let h;try{h=e.statSync(f).mtimeMs}catch{return i()}if(h!==y)try{({off:O,parts:d}=readCapture(e.readFileSync(f,"utf8"))),y=h}catch{i()}},"refresh"),w=n(()=>{const a=u();a-c>=o&&C(a)},"look"),l=n(((a,f)=>{try{return w(),isRecordOff(O,a,f)}catch{return!1}}),"ask");return l.part=(a,f)=>{try{return w(),!!a&&d.get(a)?.has(f)===!0}catch{return!1}},l.reset=()=>{c=-1/0,i()},l}s(createCaptureOff,"createCaptureOff"),p(createCaptureOff,"createCaptureOff"),n(createCaptureOff,"createCaptureOff");
package/lib/event-bus.js CHANGED
@@ -1 +1 @@
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
+ "use strict";var c=Object.defineProperty;var n=(s,t)=>c(s,"name",{value:t,configurable:!0});var a=Object.defineProperty,o=n((s,t)=>a(s,"name",{value:t,configurable:!0}),"n"),h=Object.defineProperty,u=o((s,t)=>h(s,"name",{value:t,configurable:!0}),"e");export class EventBus{static{n(this,"EventBus")}static{o(this,"EventBus")}static{u(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 r=t;if(this.transform)try{r=this.transform(t)??t}catch{r=t}for(const e of this.subs)if(!(e.filter&&!e.filter(r)))try{const i=e.handler(r);i&&typeof i.then=="function"&&i.catch(()=>{})}catch{}}subscribe(t,r){const e={handler:t,filter:r};return this.subs.add(e),()=>{this.subs.delete(e)}}droppedCount(){return this.dropped}subscriberCount(){return this.subs.size}}
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var m=(n,e)=>d(n,"name",{value:e,configurable:!0});var g=Object.defineProperty,p=m((n,e)=>g(n,"name",{value:e,configurable:!0}),"u");import{LOOP_STARTUP_MS as x,loopStartedAt as v}from"@lensmcp/protocol-types";export const LOOP_SAMPLE_MS=5e3,LOOP_ROLLUP_MS=3e5,LOOP_SAMPLE_HOURS=6;const O=720,h=p(n=>typeof n=="number"&&Number.isFinite(n)&&n>=0,"finite");export function parseLoopSamples(n){if(!Array.isArray(n))return[];const e=new Map;for(const a of n.slice(-O)){if(!Array.isArray(a)||a.length<5)continue;const[o,s,t,r,i]=a;!h(o)||o<=0||!h(s)||!h(t)||!h(r)||!h(i)||e.set(o,[o,s,t,r,Math.min(1,i)])}return[...e.values()].sort((a,o)=>a[0]-o[0])}m(parseLoopSamples,"parseLoopSamples"),p(parseLoopSamples,"parseLoopSamples");export const rollupOf=p(n=>({at:n[0],n:1,meanSum:n[1],p99:n[2],max:n[3],utilSum:n[4]}),"rollupOf");export function bucketRollups(n,e){const a=Math.max(1,Math.floor(e)),o=new Map;for(const t of n){if(!(t.n>0))continue;const r=Math.floor(t.at/a)*a,i=o.get(r);i?(i.n+=t.n,i.meanSum+=t.meanSum,i.utilSum+=t.utilSum,i.p99=Math.max(i.p99,t.p99),i.max=Math.max(i.max,t.max)):o.set(r,{...t,at:r})}const s=p((t,r)=>Number(t.toFixed(r)),"round");return[...o.values()].sort((t,r)=>t.at-r.at).map(t=>[t.at,s(t.meanSum/t.n,2),s(t.p99,2),s(t.max,2),s(t.utilSum/t.n,4)])}m(bucketRollups,"bucketRollups"),p(bucketRollups,"bucketRollups");const S=[5,10,15,30,60,120,300,600,900,1800,3600,7200,21600,43200,86400].map(n=>n*1e3);export function historyStep(n,e){const a=Math.max(e.minMs,e.requestedMs??0,n/(e.maxPoints??400));return S.find(o=>o>=a&&o%e.minMs===0)??S[S.length-1]}m(historyStep,"historyStep"),p(historyStep,"historyStep");export function historySource(n,e,a=LOOP_SAMPLE_HOURS){return n>=e-a*36e5-6e4?"samples":"rollups"}m(historySource,"historySource"),p(historySource,"historySource");export function bucketStalls(n,e){const a=Math.max(1,Math.floor(e)),o=new Map;for(const s of n){const t=Math.floor(s.startAt/a)*a,r=v(s.loopId),i=r!==void 0&&s.startAt<r+x,l=`${s.loopId}\0${t}\0${i}`,u=o.get(l);u?(u.count++,u.longestMs=Math.max(u.longestMs,s.durationMs),u.unresponsive||=s.unresponsive):o.set(l,{loopId:s.loopId,project:s.project,runtime:s.runtime,at:t,count:1,longestMs:s.durationMs,unresponsive:s.unresponsive,...i?{startup:!0}:{}})}return[...o.values()].sort((s,t)=>s.at-t.at||s.loopId.localeCompare(t.loopId)||+!!s.startup-+!!t.startup)}m(bucketStalls,"bucketStalls"),p(bucketStalls,"bucketStalls");export class LoopSampleRing{static{m(this,"LoopSampleRing")}static{p(this,"LoopSampleRing")}constructor(e=36e5,a=4e4){this.keepMs=e,this.maxSamples=a,this.rings=new Map,this.total=0,this.touches=0}add(e,a,o=Date.now()){const s=o-this.keepMs;let t=this.rings.get(e.id),r=0;for(const i of a){if(i[0]<s)continue;t||this.rings.set(e.id,t={loop:e,samples:[],touched:0});const l=t.samples,u=l[l.length-1];if(!u||i[0]>u[0])l.push(i);else{let c=0,f=l.length;for(;c<f;){const M=c+f>>1;l[M][0]<i[0]?c=M+1:f=M}if(l[c]?.[0]===i[0])continue;l.splice(c,0,i)}r++}return t&&r&&(t.loop=e,t.touched=++this.touches,this.total+=r),this.trim(s),r}read(e,a,o=Date.now()){this.trim(o-this.keepMs);const s=[];for(const t of this.rings.values()){const r=t.samples.filter(i=>i[0]>=e&&i[0]<a);r.length&&s.push({loop:t.loop,samples:r})}return s}get size(){return this.total}trim(e){for(const[a,o]of this.rings){let s=0;for(;s<o.samples.length&&o.samples[s][0]<e;)s++;s&&(o.samples.splice(0,s),this.total-=s),o.samples.length||this.rings.delete(a)}if(!(this.total<=this.maxSamples))for(const a of[...this.rings.values()].sort((o,s)=>o.touched-s.touched)){if(this.total<=this.maxSamples)break;this.total-=a.samples.length,this.rings.delete(a.loop.id)}}}
1
+ "use strict";var g=Object.defineProperty;var c=(e,o)=>g(e,"name",{value:o,configurable:!0});var x=Object.defineProperty,m=c((e,o)=>x(e,"name",{value:o,configurable:!0}),"m"),v=Object.defineProperty,p=m((e,o)=>v(e,"name",{value:o,configurable:!0}),"u");import{LOOP_STARTUP_MS as O,loopStartedAt as b}from"@lensmcp/protocol-types";export const LOOP_SAMPLE_MS=5e3,LOOP_ROLLUP_MS=3e5,LOOP_SAMPLE_HOURS=6;const L=720,f=p(e=>typeof e=="number"&&Number.isFinite(e)&&e>=0,"finite");export function parseLoopSamples(e){if(!Array.isArray(e))return[];const o=new Map;for(const r of e.slice(-L)){if(!Array.isArray(r)||r.length<5)continue;const[a,s,t,i,n]=r;!f(a)||a<=0||!f(s)||!f(t)||!f(i)||!f(n)||o.set(a,[a,s,t,i,Math.min(1,n)])}return[...o.values()].sort((r,a)=>r[0]-a[0])}c(parseLoopSamples,"parseLoopSamples"),m(parseLoopSamples,"parseLoopSamples"),p(parseLoopSamples,"parseLoopSamples");export const rollupOf=p(e=>({at:e[0],n:1,meanSum:e[1],p99:e[2],max:e[3],utilSum:e[4]}),"rollupOf");export function bucketRollups(e,o){const r=Math.max(1,Math.floor(o)),a=new Map;for(const t of e){if(!(t.n>0))continue;const i=Math.floor(t.at/r)*r,n=a.get(i);n?(n.n+=t.n,n.meanSum+=t.meanSum,n.utilSum+=t.utilSum,n.p99=Math.max(n.p99,t.p99),n.max=Math.max(n.max,t.max)):a.set(i,{...t,at:i})}const s=p((t,i)=>Number(t.toFixed(i)),"round");return[...a.values()].sort((t,i)=>t.at-i.at).map(t=>[t.at,s(t.meanSum/t.n,2),s(t.p99,2),s(t.max,2),s(t.utilSum/t.n,4)])}c(bucketRollups,"bucketRollups"),m(bucketRollups,"bucketRollups"),p(bucketRollups,"bucketRollups");const d=[5,10,15,30,60,120,300,600,900,1800,3600,7200,21600,43200,86400].map(e=>e*1e3);export function historyStep(e,o){const r=Math.max(o.minMs,o.requestedMs??0,e/(o.maxPoints??400));return d.find(a=>a>=r&&a%o.minMs===0)??d[d.length-1]}c(historyStep,"historyStep"),m(historyStep,"historyStep"),p(historyStep,"historyStep");export function historySource(e,o,r=LOOP_SAMPLE_HOURS){return e>=o-r*36e5-6e4?"samples":"rollups"}c(historySource,"historySource"),m(historySource,"historySource"),p(historySource,"historySource");export function bucketStalls(e,o){const r=Math.max(1,Math.floor(o)),a=new Map;for(const s of e){const t=Math.floor(s.startAt/r)*r,i=b(s.loopId),n=i!==void 0&&s.startAt<i+O,l=`${s.loopId}\0${t}\0${n}`,u=a.get(l);u?(u.count++,u.longestMs=Math.max(u.longestMs,s.durationMs),u.unresponsive||=s.unresponsive):a.set(l,{loopId:s.loopId,project:s.project,runtime:s.runtime,at:t,count:1,longestMs:s.durationMs,unresponsive:s.unresponsive,...n?{startup:!0}:{}})}return[...a.values()].sort((s,t)=>s.at-t.at||s.loopId.localeCompare(t.loopId)||+!!s.startup-+!!t.startup)}c(bucketStalls,"bucketStalls"),m(bucketStalls,"bucketStalls"),p(bucketStalls,"bucketStalls");export class LoopSampleRing{static{c(this,"LoopSampleRing")}static{m(this,"LoopSampleRing")}static{p(this,"LoopSampleRing")}constructor(o=36e5,r=4e4){this.keepMs=o,this.maxSamples=r,this.rings=new Map,this.total=0,this.touches=0}add(o,r,a=Date.now()){const s=a-this.keepMs;let t=this.rings.get(o.id),i=0;for(const n of r){if(n[0]<s)continue;t||this.rings.set(o.id,t={loop:o,samples:[],touched:0});const l=t.samples,u=l[l.length-1];if(!u||n[0]>u[0])l.push(n);else{let h=0,S=l.length;for(;h<S;){const M=h+S>>1;l[M][0]<n[0]?h=M+1:S=M}if(l[h]?.[0]===n[0])continue;l.splice(h,0,n)}i++}return t&&i&&(t.loop=o,t.touched=++this.touches,this.total+=i),this.trim(s),i}read(o,r,a=Date.now()){this.trim(a-this.keepMs);const s=[];for(const t of this.rings.values()){const i=t.samples.filter(n=>n[0]>=o&&n[0]<r);i.length&&s.push({loop:t.loop,samples:i})}return s}get size(){return this.total}trim(o){for(const[r,a]of this.rings){let s=0;for(;s<a.samples.length&&a.samples[s][0]<o;)s++;s&&(a.samples.splice(0,s),this.total-=s),a.samples.length||this.rings.delete(r)}if(!(this.total<=this.maxSamples))for(const r of[...this.rings.values()].sort((a,s)=>a.touched-s.touched)){if(this.total<=this.maxSamples)break;this.total-=r.samples.length,this.rings.delete(r.loop.id)}}}
@@ -1,14 +1,18 @@
1
- import type { BaseEvent, EventLoopIdentity, EventLoopIncident, EventLoopSample, EventLoopStatus } from '@lensmcp/protocol-types';
1
+ import { type BaseEvent, type EventLoopIdentity, type EventLoopIncident, type EventLoopSample, type EventLoopStatus } from '@lensmcp/protocol-types';
2
2
  import { LoopSampleRing } from './event-loop-history.js';
3
3
  export declare function eventLoopIdentity(v: unknown): EventLoopIdentity | undefined;
4
4
  /** Strictly project producer data. No raw request/response or AI content is copied into incident evidence. */
5
5
  export declare function eventLoopIncident(e: BaseEvent): EventLoopIncident | undefined;
6
+ /** How long a watchdog observation waits for its callback's incident before it is kept as one of its own. */
7
+ export declare const HEARTBEAT_SETTLE_MS = 5000;
6
8
  /** Bounded live index. Persist complete incident envelopes through onChange, not references to expiring events. */
7
9
  export declare class EventLoopIndex {
8
10
  private readonly onChange;
9
11
  /** Every sample an event carried, to be kept: the store skips what it holds already. */
10
12
  private readonly onSamples;
11
13
  private readonly incidents;
14
+ /** Watchdog observations not kept yet: their callback's incident may still come (`settle`). */
15
+ private readonly unsettled;
12
16
  private readonly loops;
13
17
  private recent;
14
18
  /** The last hour of each loop's 5 s samples (`raw.samples` of its `event-loop-lag` events). */
@@ -17,8 +21,12 @@ export declare class EventLoopIndex {
17
21
  /** Every sample an event carried, to be kept: the store skips what it holds already. */
18
22
  onSamples?: (loop: EventLoopIdentity, samples: EventLoopSample[]) => void);
19
23
  ingest(e: BaseEvent): void;
24
+ private keep;
25
+ /** Keeps each watchdog observation no callback's incident claimed within {@link HEARTBEAT_SETTLE_MS} of its last word. */
26
+ settle(now?: number): void;
20
27
  private attach;
21
28
  statuses(now?: number): EventLoopStatus[];
29
+ /** With a flow: the stalls that ran its code or overlapped it (`flowStalls` reads them apart), never LensMCP's own work. */
22
30
  list(flowId?: string): EventLoopIncident[];
23
31
  }
24
32
  export declare function setFlowLoopIncidents(read: (flowId: string) => EventLoopIncident[]): void;
package/lib/event-loop.js CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var u=(n,e)=>M(n,"name",{value:e,configurable:!0});var k=Object.defineProperty,l=u((n,e)=>k(n,"name",{value:e,configurable:!0}),"u");import{LoopSampleRing as S,parseLoopSamples as L}from"./event-loop-history.js";const v=l(n=>n&&typeof n=="object"&&!Array.isArray(n)?n:{},"object"),o=l(n=>typeof n=="number"&&Number.isFinite(n)&&n>=0?n:void 0,"number"),s=l((n,e=250)=>typeof n=="string"&&n?n.slice(0,e):void 0,"text"),T=40;export function eventLoopIdentity(n){const e=v(n),t=s(e.id),i=s(e.project);if(!(!t||!i||e.runtime!=="node"&&e.runtime!=="browser"))return{id:t,project:i,runtime:e.runtime,...o(e.pid)!==void 0?{pid:o(e.pid)}:{},...o(e.threadId)!==void 0?{threadId:o(e.threadId)}:{},...s(e.tabId)?{tabId:s(e.tabId)}:{},...s(e.loadId)?{loadId:s(e.loadId)}:{}}}u(eventLoopIdentity,"eventLoopIdentity"),l(eventLoopIdentity,"eventLoopIdentity");export function eventLoopIncident(n){const e=v(n.raw);if(e.kind!=="event-loop-stall")return;const t=eventLoopIdentity(e.loop),i=o(e.startedAt),d=o(e.durationMs),r=e.mechanism;if(!t||i===void 0||d===void 0||!["callback","heartbeat","long-animation-frame","longtask"].includes(String(r)))return;const h=e.state==="unresponsive"?"unresponsive":e.state==="unknown"?"unknown":"recovered",p=[];for(const g of Array.isArray(e.scripts)?e.scripts.slice(0,8):[]){const c=v(g),f=s(c.url,512);f&&p.push({url:f,durationMs:o(c.durationMs)??0,startAt:o(c.startAt)??i,...s(c.functionName)?{functionName:s(c.functionName)}:{},...s(c.invoker)?{invoker:s(c.invoker)}:{}})}const m=r==="callback"?s(n.context?.flowId):void 0;return{id:s(e.incidentId)??n.id,loop:t,startAt:i,durationMs:d,observedAt:n.timestamp,...h==="recovered"?{endAt:i+d}:{},state:h,mechanism:r,severity:d>=1e3?"error":"warning",...m?{flowId:m}:{},...s(n.context?.requestId)?{requestId:s(n.context?.requestId)}:{},...s(e.callbackType)?{callbackType:s(e.callbackType)}:{},scripts:p,evidence:[],evidenceTruncated:e.scriptsTruncated===!0||(o(e.droppedIncidents)??0)>0||(o(e.floodSuppressed)??0)>0,explanation:r==="callback"?"Synchronous callback wall time, including any GC or process descheduling. Execution context identifies the flow; overlapping operations are not proven causes.":r==="heartbeat"?"The loop missed its heartbeat. The observer cannot identify executing code; overlapping work may have been delayed.":"Browser-measured main-thread work. Script timings identify contributing scripts where supported; overlapping flows are associated by time only."}}u(eventLoopIncident,"eventLoopIncident"),l(eventLoopIncident,"eventLoopIncident");export class EventLoopIndex{static{u(this,"EventLoopIndex")}static{l(this,"EventLoopIndex")}constructor(e=()=>{},t=()=>{}){this.onChange=e,this.onSamples=t,this.incidents=new Map,this.loops=new Map,this.recent=[],this.history=new S}ingest(e){const t=v(e.raw),i=s(t.kind)??e.source,d=eventLoopIdentity(t.loop);if(d){const a=this.loops.get(d.id);if(!a||e.timestamp>=a.lastSeen)for(this.loops.set(d.id,{loop:d,lastSeen:e.timestamp,state:t.state==="unresponsive"?"unresponsive":t.state==="unknown"?"unknown":"observed",coverage:s(t.coverage,500)??a?.coverage??(d.runtime==="node"?"Instrumented Node thread":"Browser main thread; supported PerformanceObserver entries"),...a?{meanMs:a.meanMs,maxMs:a.maxMs,p99Ms:a.p99Ms,utilization:a.utilization}:{},...o(t.lagMs)!==void 0?{meanMs:o(t.lagMs),maxMs:o(t.maxMs),p99Ms:o(t.p99Ms),utilization:o(t.utilization)}:{}});this.loops.size>200;)this.loops.delete(this.loops.keys().next().value);if(i==="event-loop-lag"){const I=L(t.samples);I.length&&(this.history.add(d,I),this.onSamples(d,I))}}const r=eventLoopIncident(e);if(r){const a=this.incidents.get(r.id);if(a&&a.observedAt>r.observedAt)return;a&&(r.evidence=a.evidence.slice(),r.evidenceTruncated||=a.evidenceTruncated);for(const I of this.recent)this.attach(r,I);for(this.incidents.set(r.id,r);this.incidents.size>200;)this.incidents.delete(this.incidents.keys().next().value);this.onChange(r);return}if(i.startsWith("event-loop-"))return;const h=s(t.loopId);if(!h)return;const p=v(t.span),m=v(t.request),g=v(t.render),c=o(t.durationMs)??o(p.durationMs)??o(m.durationMs)??o(g.actualDurationMs)??0,f=o(t.startedAt)??o(p.startTime)??o(m.startedAt)??e.timestamp-c,w=o(p.syncDurationMs),b=o(p.syncStartedAt),y=w!==void 0&&w>=50&&b!==void 0,x={loopId:h,eventId:e.id,title:(e.title??i).slice(0,250),kind:i,startAt:y?b:f,endAt:y?b+w:f+c,...e.context?.flowId?{flowId:e.context.flowId}:{},...e.context?.requestId?{requestId:e.context.requestId}:{},relation:y?"executing":"overlap"};this.recent.push(x),this.recent.length>2e3&&this.recent.splice(0,this.recent.length-2e3);for(const a of this.incidents.values())this.attach(a,x)&&this.onChange(a)}attach(e,t){if(t.loopId!==e.loop.id||t.endAt<e.startAt||t.startAt>(e.endAt??e.observedAt)||e.evidence.some(r=>r.eventId===t.eventId))return!1;if(e.evidence.length>=T){const r=!e.evidenceTruncated;return e.evidenceTruncated=!0,r}const{loopId:i,...d}=t;return e.evidence.push(d),!0}statuses(e=Date.now()){return[...this.loops.values()].map(t=>({...t,state:e-t.lastSeen>9e4?"unknown":t.state})).sort((t,i)=>i.lastSeen-t.lastSeen)}list(e){return[...this.incidents.values()].filter(t=>!e||t.flowId===e||t.evidence.some(i=>i.flowId===e)).sort((t,i)=>i.startAt-t.startAt)}}let A=l(()=>[],"readIncidents");export function setFlowLoopIncidents(n){A=n}u(setFlowLoopIncidents,"setFlowLoopIncidents"),l(setFlowLoopIncidents,"setFlowLoopIncidents");export function flowLoopIncidents(n){return A(n)}u(flowLoopIncidents,"flowLoopIncidents"),l(flowLoopIncidents,"flowLoopIncidents");
1
+ "use strict";var q=Object.defineProperty;var v=(n,e)=>q(n,"name",{value:e,configurable:!0});var z=Object.defineProperty,b=v((n,e)=>z(n,"name",{value:e,configurable:!0}),"v"),C=Object.defineProperty,l=b((n,e)=>C(n,"name",{value:e,configurable:!0}),"l");import{lensOwnWork as L}from"@lensmcp/protocol-types";import{LoopSampleRing as N,parseLoopSamples as O}from"./event-loop-history.js";const I=l(n=>n&&typeof n=="object"&&!Array.isArray(n)?n:{},"object"),i=l(n=>typeof n=="number"&&Number.isFinite(n)&&n>=0?n:void 0,"number"),r=l((n,e=250)=>typeof n=="string"&&n?n.slice(0,e):void 0,"text"),S=40;export function eventLoopIdentity(n){const e=I(n),t=r(e.id),o=r(e.project);if(!(!t||!o||e.runtime!=="node"&&e.runtime!=="browser"))return{id:t,project:o,runtime:e.runtime,...i(e.pid)!==void 0?{pid:i(e.pid)}:{},...i(e.threadId)!==void 0?{threadId:i(e.threadId)}:{},...r(e.tabId)?{tabId:r(e.tabId)}:{},...r(e.loadId)?{loadId:r(e.loadId)}:{}}}v(eventLoopIdentity,"eventLoopIdentity"),b(eventLoopIdentity,"eventLoopIdentity"),l(eventLoopIdentity,"eventLoopIdentity");export function eventLoopIncident(n){const e=I(n.raw);if(e.kind!=="event-loop-stall")return;const t=eventLoopIdentity(e.loop),o=i(e.startedAt),c=i(e.durationMs),s=e.mechanism;if(!t||o===void 0||c===void 0||!["callback","heartbeat","long-animation-frame","longtask"].includes(String(s)))return;const A=e.state==="unresponsive"?"unresponsive":e.state==="unknown"?"unknown":"recovered",m=[];for(const k of Array.isArray(e.scripts)?e.scripts.slice(0,8):[]){const u=I(k),a=r(u.url,512);a&&m.push({url:a,durationMs:i(u.durationMs)??0,startAt:i(u.startAt)??o,...r(u.functionName)?{functionName:r(u.functionName)}:{},...r(u.invoker)?{invoker:r(u.invoker)}:{}})}const f=r(e.cause,64),M=i(e.lensMs),x=i(e.deferredMs),h=L({durationMs:c,...f?{cause:f}:{},...M!==void 0?{lensMs:M}:{}}),w=s==="callback"&&!h?r(n.context?.flowId):void 0,g=h?void 0:r(n.context?.requestId);return{id:r(e.incidentId)??n.id,loop:t,startAt:o,durationMs:c,observedAt:n.timestamp,...A==="recovered"?{endAt:o+c}:{},state:A,mechanism:s,severity:h?"info":c>=1e3?"error":"warning",...w?{flowId:w}:{},...g?{requestId:g}:{},...r(e.callbackType)?{callbackType:r(e.callbackType)}:{},...f?{cause:f}:{},...M!==void 0?{lensMs:M}:{},...x?{deferredMs:x}:{},scripts:m,evidence:[],evidenceTruncated:e.scriptsTruncated===!0||(i(e.droppedIncidents)??0)>0||(i(e.floodSuppressed)??0)>0,explanation:h?`${h}. The pause is the lens's, not the app's: no flow ran it. What overlapped it waited behind it.`:s==="callback"?"Synchronous callback wall time, including any GC or process descheduling. Execution context identifies the flow; overlapping operations are not proven causes.":s==="heartbeat"?"The loop missed its heartbeat. The observer cannot identify executing code; overlapping work may have been delayed.":"Browser-measured main-thread work. Script timings identify contributing scripts where supported; overlapping flows are associated by time only."}}v(eventLoopIncident,"eventLoopIncident"),b(eventLoopIncident,"eventLoopIncident"),l(eventLoopIncident,"eventLoopIncident");export const HEARTBEAT_SETTLE_MS=5e3;const E=l(n=>n.endAt??Math.max(n.observedAt,n.startAt+n.durationMs),"endOf");function y(n,e){return n.loop.id!==e.loop.id||e.durationMs<=0?!1:Math.min(E(n),E(e))-Math.max(n.startAt,e.startAt)>=e.durationMs/2}v(y,"x"),b(y,"T"),l(y,"sameStall");export class EventLoopIndex{static{v(this,"EventLoopIndex")}static{b(this,"EventLoopIndex")}static{l(this,"EventLoopIndex")}constructor(e=()=>{},t=()=>{}){this.onChange=e,this.onSamples=t,this.incidents=new Map,this.unsettled=new Set,this.loops=new Map,this.recent=[],this.history=new N}ingest(e){const t=I(e.raw),o=r(t.kind)??e.source,c=eventLoopIdentity(t.loop);if(c){const a=this.loops.get(c.id);if(!a||e.timestamp>=a.lastSeen)for(this.loops.set(c.id,{loop:c,lastSeen:e.timestamp,state:t.state==="unresponsive"?"unresponsive":t.state==="unknown"?"unknown":"observed",coverage:r(t.coverage,500)??a?.coverage??(c.runtime==="node"?"Instrumented Node thread":"Browser main thread; supported PerformanceObserver entries"),...a?{meanMs:a.meanMs,maxMs:a.maxMs,p99Ms:a.p99Ms,utilization:a.utilization}:{},...i(t.lagMs)!==void 0?{meanMs:i(t.lagMs),maxMs:i(t.maxMs),p99Ms:i(t.p99Ms),utilization:i(t.utilization)}:{}});this.loops.size>200;)this.loops.delete(this.loops.keys().next().value);if(o==="event-loop-lag"){const d=O(t.samples);d.length&&(this.history.add(c,d),this.onSamples(c,d))}}const s=eventLoopIncident(e);if(s){if(this.settle(e.timestamp),s.mechanism==="heartbeat"){const d=[...this.incidents.values()].find(p=>p.mechanism==="callback"&&y(p,s));if(d){d.heartbeatMs!==s.durationMs&&(d.heartbeatMs=s.durationMs,this.onChange(d));return}}const a=this.incidents.get(s.id);if(a&&a.observedAt>s.observedAt)return;if(a&&(s.evidence=a.evidence.slice(),s.evidenceTruncated||=a.evidenceTruncated),s.mechanism==="callback")for(const[d,p]of this.incidents)p.mechanism!=="heartbeat"||!y(s,p)||(s.heartbeatMs=Math.max(s.heartbeatMs??0,p.durationMs),s.evidence=[...new Map([...p.evidence,...s.evidence].map(T=>[T.eventId,T])).values()].slice(0,S),s.evidenceTruncated||=p.evidenceTruncated,this.unsettled.delete(d)||(s.id=d,s.observedAt=Math.max(s.observedAt,p.observedAt+1)),this.incidents.delete(d));for(const d of this.recent)this.attach(s,d);for(this.incidents.set(s.id,s);this.incidents.size>200;){const d=this.incidents.keys().next().value;this.keep(d),this.incidents.delete(d)}s.mechanism==="heartbeat"?this.unsettled.add(s.id):this.onChange(s);return}if(o.startsWith("event-loop-"))return;const A=r(t.loopId);if(!A)return;const m=I(t.span),f=I(t.request),M=I(t.render),x=i(t.durationMs)??i(m.durationMs)??i(f.durationMs)??i(M.actualDurationMs)??0,h=i(t.startedAt)??i(m.startTime)??i(f.startedAt)??e.timestamp-x,w=i(m.syncDurationMs),g=i(m.syncStartedAt),k=w!==void 0&&w>=50&&g!==void 0,u={loopId:A,eventId:e.id,title:(e.title??o).slice(0,250),kind:o,startAt:k?g:h,endAt:k?g+w:h+x,...e.context?.flowId?{flowId:e.context.flowId}:{},...e.context?.requestId?{requestId:e.context.requestId}:{},relation:k?"executing":"overlap"};this.recent.push(u),this.recent.length>2e3&&this.recent.splice(0,this.recent.length-2e3);for(const a of this.incidents.values())this.attach(a,u)&&!this.unsettled.has(a.id)&&this.onChange(a)}keep(e){const t=this.incidents.get(e);t&&this.unsettled.delete(e)&&this.onChange(t)}settle(e=Date.now()){for(const t of[...this.unsettled]){const o=this.incidents.get(t);(!o||e-o.observedAt>=HEARTBEAT_SETTLE_MS)&&this.keep(t),o||this.unsettled.delete(t)}}attach(e,t){if(t.loopId!==e.loop.id||t.endAt<e.startAt||t.startAt>(e.endAt??e.observedAt)||e.evidence.some(s=>s.eventId===t.eventId))return!1;if(e.evidence.length>=S){const s=!e.evidenceTruncated;return e.evidenceTruncated=!0,s}const{loopId:o,...c}=t;return e.evidence.push(c),!0}statuses(e=Date.now()){return[...this.loops.values()].map(t=>({...t,state:e-t.lastSeen>9e4?"unknown":t.state})).sort((t,o)=>o.lastSeen-t.lastSeen)}list(e){return[...this.incidents.values()].filter(t=>!e||!L(t)&&(t.flowId===e||t.evidence.some(o=>o.flowId===e))).sort((t,o)=>o.startAt-t.startAt)}}let j=l(()=>[],"readIncidents");export function setFlowLoopIncidents(n){j=n}v(setFlowLoopIncidents,"setFlowLoopIncidents"),b(setFlowLoopIncidents,"setFlowLoopIncidents"),l(setFlowLoopIncidents,"setFlowLoopIncidents");export function flowLoopIncidents(n){return j(n)}v(flowLoopIncidents,"flowLoopIncidents"),b(flowLoopIncidents,"flowLoopIncidents"),l(flowLoopIncidents,"flowLoopIncidents");
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var o=(r,t)=>u(r,"name",{value:t,configurable:!0});var l=Object.defineProperty,i=o((r,t)=>l(r,"name",{value:t,configurable:!0}),"a");import{MAX_MESSAGE_CHARS as S,MAX_TITLE_CHARS as T,redactDeep as y,redactSqlParams as _,redactText as p,safeText as E,safeTitle as g}from"./redact.js";export const BUS_REDACT_MAX_DEPTH=12;export function createEventRedactor(r={}){const t=r.maxDepth??BUS_REDACT_MAX_DEPTH;let s=0,a=0;return{redact(e){s+=1;const c=e.title===void 0?void 0:g(p(e.title)),n=e.message===void 0?void 0:E(p(e.message),S),d=e.raw===void 0?void 0:v(y(e.raw,0,t)),A=c!==e.title,f=n!==e.message,m=d!==e.raw;return!A&&!f&&!m?e:(a+=1,{...e,...c!==void 0?{title:c}:{},...n!==void 0?{message:n}:{},...d!==void 0?{raw:d}:{}})},stats:i(()=>({inspected:s,redacted:a}),"stats"),reset:i(()=>{s=0,a=0},"reset")}}o(createEventRedactor,"createEventRedactor"),i(createEventRedactor,"createEventRedactor");function v(r){if(!r||typeof r!="object"||Array.isArray(r))return r;const t=r,s=t.query,a=t.params;if(typeof s!="string"||!Array.isArray(a))return r;const e=_(s,a);return e===a?r:{...t,params:e}}o(v,"T"),i(v,"redactSqlShape");export{T as MAX_TITLE_CHARS};
1
+ "use strict";var m=Object.defineProperty;var o=(e,a)=>m(e,"name",{value:a,configurable:!0});var T=Object.defineProperty,v=o((e,a)=>T(e,"name",{value:a,configurable:!0}),"o"),y=Object.defineProperty,i=v((e,a)=>y(e,"name",{value:a,configurable:!0}),"a");import{MAX_MESSAGE_CHARS as E,MAX_TITLE_CHARS as S,redactDeep as _,redactSqlParams as g,redactText as f,safeText as R,safeTitle as x}from"./redact.js";export const BUS_REDACT_MAX_DEPTH=12;export function createEventRedactor(e={}){const a=e.maxDepth??BUS_REDACT_MAX_DEPTH;let s=0,r=0;return{redact(t){s+=1;const c=t.title===void 0?void 0:x(f(t.title)),n=t.message===void 0?void 0:R(f(t.message),E),d=t.raw===void 0?void 0:p(_(t.raw,0,a)),u=c!==t.title,A=n!==t.message,l=d!==t.raw;return!u&&!A&&!l?t:(r+=1,{...t,...c!==void 0?{title:c}:{},...n!==void 0?{message:n}:{},...d!==void 0?{raw:d}:{}})},stats:i(()=>({inspected:s,redacted:r}),"stats"),reset:i(()=>{s=0,r=0},"reset")}}o(createEventRedactor,"createEventRedactor"),v(createEventRedactor,"createEventRedactor"),i(createEventRedactor,"createEventRedactor");function p(e){if(!e||typeof e!="object"||Array.isArray(e))return e;const a=e,s=a.query,r=a.params;if(typeof s!="string"||!Array.isArray(r))return e;const t=g(s,r);return t===r?e:{...a,params:t}}o(p,"v"),v(p,"T"),i(p,"redactSqlShape");export{S as MAX_TITLE_CHARS};
@@ -1 +1 @@
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
+ "use strict";var f=Object.defineProperty;var r=(e,t)=>f(e,"name",{value:t,configurable:!0});var l=Object.defineProperty,n=r((e,t)=>l(e,"name",{value:t,configurable:!0}),"r"),u=Object.defineProperty,o=n((e,t)=>u(e,"name",{value:t,configurable:!0}),"e");const d=2166136261,g=16777619;function a(e){let t=2166136261;for(let i=0;i<e.length;i++)t^=e.charCodeAt(i),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}r(a,"o"),n(a,"i"),o(a,"fnv1a32");export function fingerprint(e){const t=[e.kind,e.identity,e.file??"",e.detail??""];return`${e.kind}:${a(t.join("|"))}`}r(fingerprint,"fingerprint"),n(fingerprint,"fingerprint"),o(fingerprint,"fingerprint");
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var c=(e,t)=>M(e,"name",{value:t,configurable:!0});var T=Object.defineProperty,s=c((e,t)=>T(e,"name",{value:t,configurable:!0}),"s");export const CATEGORY_ORDER=["user-action","page-load","navigation","api","ai","background","test","system","other"];const p=new Map;export function globMatch(e,t){let o=p.get(e);return o||(o=new RegExp(`^${e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".")}$`),p.size>500&&p.clear(),p.set(e,o)),o.test(t)}c(globMatch,"globMatch"),s(globMatch,"globMatch");const F=s(e=>/^[A-Z]+ /.test(e),"hasMethod");function w(e,t){return t.some(o=>o.route?F(e)?globMatch(e,`${o.method??"GET"} ${o.route}`):globMatch(e,o.route):!1)}c(w,"$"),s(w,"routeMatches");function m(e,t){return!([e.flowId,e.originType,e.origin,e.route,e.project].filter(o=>o!==void 0).length===0||e.flowId!==void 0&&!globMatch(e.flowId,t.flowId)||e.originType!==void 0&&e.originType!==t.origin.type||e.origin!==void 0&&!(t.origin.nodeId!==void 0&&globMatch(e.origin,t.origin.nodeId))||e.route!==void 0&&!w(e.route,t.segments)||e.project!==void 0&&!t.segments.some(o=>o.projects.some(n=>globMatch(e.project,n))))}c(m,"b"),s(m,"ruleMatches");const y=s(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObj"),g=s(e=>typeof e=="string"&&e!==""?e:void 0,"str"),f=s(e=>y(e.raw)?g(e.raw.kind)??"":"","kindOf"),k=s((e,t)=>{const o=Number(e.timestamp)||0,n=Number(t.timestamp)||0;return o<n||o===n&&e.id<t.id},"earlier");function $(e){let t,o;for(const a of e)f(a)==="flow-origin"&&(!t||k(a,t))&&(t=a),g(a.context?.originType)&&(!o||k(a,o))&&(o=a);const n=t??o;if(!n)return{};const r=y(n.raw)?n.raw:{},i=g(n.context?.originType)??(t?g(n.title):void 0),u=g(r.originNodeId)??g(n.context?.originNodeId);return{...i?{type:i}:{},...u?{nodeId:u}:{}}}c($,"O"),s($,"originOf");const S=/^(verify|e2e|test|smoke|load)[-_:]/i,z=s((e,t)=>S.test(e)||t!==void 0&&/^(ui:)?(tools|scripts?|e2e)\//.test(t),"isTestFlow"),x={"page-load":"page-load","user-click":"user-action","form-submit":"user-action","input-change":"user-action","double-click":"user-action","context-menu":"user-action","key-press":"user-action","route-load":"navigation","route-change":"navigation",navigation:"navigation","ai-turn":"ai",request:"api",timer:"background",cron:"background",interval:"background",queue:"background",job:"background","websocket-message":"background","hmr-update":"system"},A=new Set(["page-load","user-action","navigation"]),E=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;export function templatePath(e){return e.replace(/[?#].*$/,"").split("/").map(t=>E.test(t)||/^[0-9a-f]{16,}$/i.test(t)||/^\d{2,}$/.test(t)?":id":t).join("/")}c(templatePath,"templatePath"),s(templatePath,"templatePath");function I(e){const t=/^ui:(?:.*\/)?([^/:]+?)(?:\.[a-z]+)?:\d+:([A-Za-z]+)$/.exec(e);return t?`${t[1]} \xB7 ${t[2]}`:e}c(I,"q"),s(I,"componentOf");export function scriptFamily(e){let t=e.replace(/[-_:][0-9a-f]{6,}(?:-[0-9a-f]+)*$/i,"");return t=t.replace(/[-_:](?=[a-z0-9]*\d)[a-z0-9]{6,}$/i,""),t=t.replace(/[-_:]\d+$/,""),t||e}c(scriptFamily,"scriptFamily"),s(scriptFamily,"scriptFamily");function j(e,t,o,n){const r=t.nodeId,i=r?/^(page|route|ambient):(.*)$/.exec(r):null;if(i)return`${i[1]}:${templatePath(i[2])}`;if(t.type&&x[t.type]==="user-action"&&r)return I(r);if(e==="test")return scriptFamily(o.flowId);const u=o.segments.find(l=>l.kind==="request"&&l.route);if(u?.route)return`${u.method??"GET"} ${templatePath(u.route)}`;const a=n.find(l=>f(l)==="ai-call");return a&&y(a.raw)?`ai \xB7 ${g(a.raw.model)??g(a.raw.provider)??"call"}`:r?templatePath(r):void 0}c(j,"R"),s(j,"subjectOf");const _=10,B=1e3,N=3,R=500,C=1e3;function q(e,t){const o=new Set,n=t.segments.filter(i=>i.kind==="request");t.segments.some(i=>i.counts.errors>0)&&o.add("has-error"),n.some(i=>i.durationMs>=B)&&o.add("slow"),n.length>=_&&o.add("fan-out"),new Set(t.segments.flatMap(i=>i.projects)).size>=3&&o.add("multi-service"),e.some(i=>f(i)==="queue-enqueued")&&o.add("queue"),e.some(i=>f(i)==="ai-call"||i.source==="ai")&&o.add("ai"),t.stats.bookkeeping>=R&&t.stats.bookkeeping*2>=t.stats.events&&o.add("storm"),t.stats.events>=C&&o.add("large");const r=new Map;for(const i of n)(!i.part||i.part.index===1)&&r.set(i.label,(r.get(i.label)??0)+1);return[...r.values()].some(i=>i>=N)&&o.add("repeated-requests"),[...o].sort()}c(q,"G"),s(q,"tagsOf");export function classifyFlow(e,t,o=[]){const n=$(e),r={flowId:t.flowId,origin:n,segments:t.segments},i=q(e,t),u=s((d,O,b)=>{const h=j(d,n,t,e);return{category:d,decidedBy:O,...b!==void 0?{ruleIndex:b}:{},tags:i,origin:n,...h?{subject:h}:{}}},"done"),a=o.findIndex(d=>d.category&&m(d,r));if(a!==-1)return u(o[a].category,"rule",a);if(z(t.flowId,n.nodeId))return u("test","test");const l=n.type?x[n.type]:void 0;if(l)return u(l,"origin");if(i.includes("ai"))return u("ai","shape");const v=t.segments.filter(d=>d.kind==="request");return v.length>0?u(v.every(d=>d.requestId?.startsWith("job:"))?"background":"api","shape"):t.segments.length>0&&t.segments.every(d=>d.kind==="ambient")?u("system","shape"):u("other","shape")}c(classifyFlow,"classifyFlow"),s(classifyFlow,"classifyFlow");export function categoryOfSegment(e,t,o=[]){const n=o.find(r=>r.category&&(r.route!==void 0||r.project!==void 0)&&r.flowId===void 0&&r.origin===void 0&&r.originType===void 0&&m(r,{flowId:e.flowId,origin:t.origin,segments:[e]}));return n?n.category:e.kind==="request"?e.requestId?.startsWith("job:")?"background":"api":e.kind==="ambient"?"system":e.kind==="origin"&&A.has(t.category)?t.category:"ui"}c(categoryOfSegment,"categoryOfSegment"),s(categoryOfSegment,"categoryOfSegment");export function groupFlows(e){return groupByCategory(e).map(t=>{const o=new Map;for(const r of t.items){const i=o.get(r.subject);i?i.push(r):o.set(r.subject,[r])}const n=[...o.entries()].sort((r,i)=>(r[0]===void 0?1:0)-(i[0]===void 0?1:0)||i[1].length-r[1].length||String(r[0]).localeCompare(String(i[0]))).map(([r,i])=>({subject:r,count:i.length,items:i}));return{...t,subjects:n}})}c(groupFlows,"groupFlows"),s(groupFlows,"groupFlows");export function groupByCategory(e){const t=new Map;for(const n of e){const r=t.get(n.category);r?r.push(n):t.set(n.category,[n])}const o=s(n=>{const r=CATEGORY_ORDER.indexOf(n);return r===-1?CATEGORY_ORDER.length:r},"rank");return[...t.entries()].sort((n,r)=>o(n[0])-o(r[0])||(n[0]<r[0]?-1:n[0]>r[0]?1:0)).map(([n,r])=>({category:n,count:r.length,items:r}))}c(groupByCategory,"groupByCategory"),s(groupByCategory,"groupByCategory");
1
+ "use strict";var F=Object.defineProperty;var c=(e,t)=>F(e,"name",{value:t,configurable:!0});var T=Object.defineProperty,d=c((e,t)=>T(e,"name",{value:t,configurable:!0}),"c"),S=Object.defineProperty,s=d((e,t)=>S(e,"name",{value:t,configurable:!0}),"s");export const CATEGORY_ORDER=["user-action","page-load","navigation","api","ai","background","test","system","other"];const f=new Map;export function globMatch(e,t){let o=f.get(e);return o||(o=new RegExp(`^${e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".")}$`),f.size>500&&f.clear(),f.set(e,o)),o.test(t)}c(globMatch,"globMatch"),d(globMatch,"globMatch"),s(globMatch,"globMatch");const z=s(e=>/^[A-Z]+ /.test(e),"hasMethod");function v(e,t){return t.some(o=>o.route?z(e)?globMatch(e,`${o.method??"GET"} ${o.route}`):globMatch(e,o.route):!1)}c(v,"w"),d(v,"$"),s(v,"routeMatches");function m(e,t){return!([e.flowId,e.originType,e.origin,e.route,e.project].filter(o=>o!==void 0).length===0||e.flowId!==void 0&&!globMatch(e.flowId,t.flowId)||e.originType!==void 0&&e.originType!==t.origin.type||e.origin!==void 0&&!(t.origin.nodeId!==void 0&&globMatch(e.origin,t.origin.nodeId))||e.route!==void 0&&!v(e.route,t.segments)||e.project!==void 0&&!t.segments.some(o=>o.projects.some(r=>globMatch(e.project,r))))}c(m,"m"),d(m,"b"),s(m,"ruleMatches");const b=s(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObj"),l=s(e=>typeof e=="string"&&e!==""?e:void 0,"str"),y=s(e=>b(e.raw)?l(e.raw.kind)??"":"","kindOf"),O=s((e,t)=>{const o=Number(e.timestamp)||0,r=Number(t.timestamp)||0;return o<r||o===r&&e.id<t.id},"earlier");function h(e){let t,o;for(const a of e)y(a)==="flow-origin"&&(!t||O(a,t))&&(t=a),l(a.context?.originType)&&(!o||O(a,o))&&(o=a);const r=t??o;if(!r)return{};const n=b(r.raw)?r.raw:{},i=l(r.context?.originType)??(t?l(r.title):void 0),u=l(n.originNodeId)??l(r.context?.originNodeId);return{...i?{type:i}:{},...u?{nodeId:u}:{}}}c(h,"$"),d(h,"O"),s(h,"originOf");const B=/^(verify|e2e|test|smoke|load)[-_:]/i,A=s((e,t)=>B.test(e)||t!==void 0&&/^(ui:)?(tools|scripts?|e2e)\//.test(t),"isTestFlow"),q={"page-load":"page-load","user-click":"user-action","form-submit":"user-action","input-change":"user-action","double-click":"user-action","context-menu":"user-action","key-press":"user-action","route-load":"navigation","route-change":"navigation",navigation:"navigation","ai-turn":"ai",request:"api",timer:"background",cron:"background",interval:"background",queue:"background",job:"background","websocket-message":"background","hmr-update":"system"},C=new Set(["page-load","user-action","navigation"]),E=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;export function templatePath(e){return e.replace(/[?#].*$/,"").split("/").map(t=>E.test(t)||/^[0-9a-f]{16,}$/i.test(t)||/^\d{2,}$/.test(t)?":id":t).join("/")}c(templatePath,"templatePath"),d(templatePath,"templatePath"),s(templatePath,"templatePath");function w(e){const t=/^ui:(?:.*\/)?([^/:]+?)(?:\.[a-z]+)?:\d+:([A-Za-z]+)$/.exec(e);return t?`${t[1]} \xB7 ${t[2]}`:e}c(w,"I"),d(w,"q"),s(w,"componentOf");export function scriptFamily(e){let t=e.replace(/[-_:][0-9a-f]{6,}(?:-[0-9a-f]+)*$/i,"");return t=t.replace(/[-_:](?=[a-z0-9]*\d)[a-z0-9]{6,}$/i,""),t=t.replace(/[-_:]\d+$/,""),t||e}c(scriptFamily,"scriptFamily"),d(scriptFamily,"scriptFamily"),s(scriptFamily,"scriptFamily");function k(e,t,o,r){const n=t.nodeId,i=n?/^(page|route|ambient):(.*)$/.exec(n):null;if(i)return`${i[1]}:${templatePath(i[2])}`;if(t.type&&q[t.type]==="user-action"&&n)return w(n);if(e==="test")return scriptFamily(o.flowId);const u=o.segments.find(p=>p.kind==="request"&&p.route);if(u?.route)return`${u.method??"GET"} ${templatePath(u.route)}`;const a=r.find(p=>y(p)==="ai-call");return a&&b(a.raw)?`ai \xB7 ${l(a.raw.model)??l(a.raw.provider)??"call"}`:n?templatePath(n):void 0}c(k,"j"),d(k,"R"),s(k,"subjectOf");const R=10,_=1e3,N=3,P=500,G=1e3;function $(e,t){const o=new Set,r=t.segments.filter(i=>i.kind==="request");t.segments.some(i=>i.counts.errors>0)&&o.add("has-error"),r.some(i=>i.durationMs>=_)&&o.add("slow"),r.length>=R&&o.add("fan-out"),new Set(t.segments.flatMap(i=>i.projects)).size>=3&&o.add("multi-service"),e.some(i=>y(i)==="queue-enqueued")&&o.add("queue"),e.some(i=>y(i)==="ai-call"||i.source==="ai")&&o.add("ai"),t.stats.bookkeeping>=P&&t.stats.bookkeeping*2>=t.stats.events&&o.add("storm"),t.stats.events>=G&&o.add("large");const n=new Map;for(const i of r)(!i.part||i.part.index===1)&&n.set(i.label,(n.get(i.label)??0)+1);return[...n.values()].some(i=>i>=N)&&o.add("repeated-requests"),[...o].sort()}c($,"q"),d($,"G"),s($,"tagsOf");export function classifyFlow(e,t,o=[]){const r=h(e),n={flowId:t.flowId,origin:r,segments:t.segments},i=$(e,t),u=s((g,M,x)=>{const j=k(g,r,t,e);return{category:g,decidedBy:M,...x!==void 0?{ruleIndex:x}:{},tags:i,origin:r,...j?{subject:j}:{}}},"done"),a=o.findIndex(g=>g.category&&m(g,n));if(a!==-1)return u(o[a].category,"rule",a);if(A(t.flowId,r.nodeId))return u("test","test");const p=r.type?q[r.type]:void 0;if(p)return u(p,"origin");if(i.includes("ai"))return u("ai","shape");const I=t.segments.filter(g=>g.kind==="request");return I.length>0?u(I.every(g=>g.requestId?.startsWith("job:"))?"background":"api","shape"):t.segments.length>0&&t.segments.every(g=>g.kind==="ambient")?u("system","shape"):u("other","shape")}c(classifyFlow,"classifyFlow"),d(classifyFlow,"classifyFlow"),s(classifyFlow,"classifyFlow");export function categoryOfSegment(e,t,o=[]){const r=o.find(n=>n.category&&(n.route!==void 0||n.project!==void 0)&&n.flowId===void 0&&n.origin===void 0&&n.originType===void 0&&m(n,{flowId:e.flowId,origin:t.origin,segments:[e]}));return r?r.category:e.kind==="request"?e.requestId?.startsWith("job:")?"background":"api":e.kind==="ambient"?"system":e.kind==="origin"&&C.has(t.category)?t.category:"ui"}c(categoryOfSegment,"categoryOfSegment"),d(categoryOfSegment,"categoryOfSegment"),s(categoryOfSegment,"categoryOfSegment");export function groupFlows(e){return groupByCategory(e).map(t=>{const o=new Map;for(const n of t.items){const i=o.get(n.subject);i?i.push(n):o.set(n.subject,[n])}const r=[...o.entries()].sort((n,i)=>(n[0]===void 0?1:0)-(i[0]===void 0?1:0)||i[1].length-n[1].length||String(n[0]).localeCompare(String(i[0]))).map(([n,i])=>({subject:n,count:i.length,items:i}));return{...t,subjects:r}})}c(groupFlows,"groupFlows"),d(groupFlows,"groupFlows"),s(groupFlows,"groupFlows");export function groupByCategory(e){const t=new Map;for(const r of e){const n=t.get(r.category);n?n.push(r):t.set(r.category,[r])}const o=s(r=>{const n=CATEGORY_ORDER.indexOf(r);return n===-1?CATEGORY_ORDER.length:n},"rank");return[...t.entries()].sort((r,n)=>o(r[0])-o(n[0])||(r[0]<n[0]?-1:r[0]>n[0]?1:0)).map(([r,n])=>({category:r,count:n.length,items:n}))}c(groupByCategory,"groupByCategory"),d(groupByCategory,"groupByCategory"),s(groupByCategory,"groupByCategory");
@@ -1 +1 @@
1
- "use strict";var te=Object.defineProperty;var w=(e,t)=>te(e,"name",{value:t,configurable:!0});var se=Object.defineProperty,p=w((e,t)=>se(e,"name",{value:t,configurable:!0}),"p");export const DEFAULT_SEGMENT_OPTIONS={phaseGapMs:1500,burstGapMs:250,attachWindowMs:400,maxSegmentEvents:400,occurrenceSlackMs:10},FLOW_BOOKKEEPING_KINDS=new Set(["subscription-added","subscription-removed","hook-run","store-created","singleton-instance","visual-frame"]),SQL_ACCOUNT_KIND="db-request-account";const ne=new Set(["react","valtio","client-runtime","chrome","visual"]),x=p(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObj"),b=p(e=>typeof e=="string"&&e!==""?e:void 0,"str"),M=p(e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,"num"),T=new WeakMap;function A(e){let t=T.get(e);return t||(t=_(e),T.set(e,t)),t}w(A,"K"),p(A,"itemOf");function _(e){const t=x(e.raw)?e.raw:{},s=x(t.request)?t.request:{},o=x(t.span)?t.span:{},r=e.context??{},n=b(t.kind)??"",l=n===SQL_ACCOUNT_KIND,g=(l?M(t.lastEndedAt):void 0)??M(e.timestamp)??0,v=M(s.startedAt)??M(o.startTime)??M(t.startedAt)??(l?M(t.firstStartedAt):void 0),q=M(s.endedAt)??M(o.endTime)??(v!==void 0&&M(t.durationMs)!==void 0?v+t.durationMs:void 0),I=Math.min(g,v??g),$=Math.max(g,q??g),j=x(t.render)?t.render:{},a=x(t.update)?t.update:{},c=n==="render"?b(j.componentName):n==="state-update"?b(a.path)?.split(".").slice(0,2).join("."):void 0,d=b(t.queue),u=b(t.jobId),f=String(e.source),i=b(t.project)??b(r.projectName),m=n==="fetch-start"||n==="fetch-done"||n==="gateway-request";return{event:e,id:e.id,ts:g,from:I,to:$,kind:n,source:f,requestId:b(r.requestId),parentRequestId:b(r.parentRequestId),queueKey:d&&u?`${d}#${u}`:void 0,browser:ne.has(f)||f==="memory"&&i===void 0,bookkeeping:FLOW_BOOKKEEPING_KINDS.has(n),project:i,subject:c,route:m?B(b(t.url)):n==="server-request"?b(s.route):void 0,method:m?b(t.method):n==="server-request"?b(s.method):void 0}}w(_,"C"),p(_,"readItem");function B(e){if(!e)return;const t=e.search(/[?#]/),s=t===-1?e:e.slice(0,t),o=/^[a-z][a-z0-9+.-]*:\/\/[^/]*(\/.*)?$/i.exec(s);return o?o[1]??"/":s}w(B,"P"),p(B,"pathOnly");const oe=p(e=>e.split(".")[0],"rootOf"),U=p((e,t)=>e.reduce((s,o)=>Math.min(s,t(o)),1/0),"minOf"),D=p((e,t)=>e.reduce((s,o)=>Math.max(s,t(o)),-1/0),"maxOf"),K=p((e,t)=>e.ts-t.ts||(e.id<t.id?-1:e.id>t.id?1:0),"compare"),O=p(e=>e.requestId&&!e.requestId.startsWith("job:")?oe(e.requestId):void 0,"directFamilyOf");function z(e){if(e.requestId?.startsWith("job:"))return e.requestId.slice(4);if(e.queueKey&&e.kind!=="queue-enqueued"&&!e.requestId)return e.queueKey}w(z,"Q"),p(z,"jobKeyOf");function C(e,t){const s=e.filter(n=>!n.parentRequestId&&(n.kind==="server-request"||n.kind==="gateway-request"||n.kind==="fetch-start"||n.kind==="fetch-done")).sort((n,l)=>n.from-l.from||K(n,l));if(s.length<2)return[e];const o=[];for(const n of s){const l=o[o.length-1];l&&n.from<=l.to+t?l.to=Math.max(l.to,n.to):o.push({from:n.from,to:n.to})}if(o.length<2)return[e];const r=o.map(()=>[]);for(const n of e)r[t>=0?P(o,n.ts,t):L(o,n.ts,t)].push(n);return r.filter(n=>n.length>0)}w(C,"V"),p(C,"occurrencesOf");function L(e,t,s){const o=e.findIndex(n=>t>=n.from-s&&t<=n.to+s);if(o!==-1)return o;let r=0;for(let n=0;n<e.length;n+=1)e[n].from<=t&&(r=n);return r}w(L,"X"),p(L,"spanScan");function P(e,t,s){let o=0,r=e.length;for(;o<r;){const n=o+r>>1;e[n].to+s<t?o=n+1:r=n}if(o<e.length&&t>=e[o].from-s)return o;for(o=0,r=e.length;o<r;){const n=o+r>>1;e[n].from<=t?o=n+1:r=n}return Math.max(0,o-1)}w(P,"Y"),p(P,"spanAt");const re=new Set(["server-request","gateway-request","fetch-done","fetch-error","queue-process"]),N="event-loop-stall";function E(e){let t=-1/0,s=!1;for(const r of e)re.has(r.kind)?t=Math.max(t,r.to):r.kind===N&&(s=!0);if(!s||!Number.isFinite(t))return;let o;for(const r of e)r.kind===N&&r.from>=t&&(o??=new Map).set(r,Math.round(r.from-t));return o}w(E,"_"),p(E,"lateStallsOf");export function stallsAfterResponse(e){const t=new Map;if(!e.some(o=>x(o.raw)&&o.raw.kind===N))return t;const s=new Map;for(const o of e){const r=A(o),n=r.requestId?.startsWith("job:")?r.requestId:O(r);if(n===void 0)continue;const l=s.get(n);l?l.push(r):s.set(n,[r])}for(const o of s.values())for(const[r,n]of E(o)??[])t.set(r.id,n);return t}w(stallsAfterResponse,"stallsAfterResponse"),p(stallsAfterResponse,"stallsAfterResponse");function W(e,t){if(!t)return e;const s=e.filter(o=>!t.has(o));return s.length?s:e}w(W,"T"),p(W,"timedItems");const Q={debug:0,info:1,warning:2,error:3,fatal:4};function F(e,t){const s=[];let o=[];for(const r of e){const n=o[o.length-1];n&&r.ts-n.ts>=t&&(s.push(o),o=[]),o.push(r)}return o.length&&s.push(o),s}w(F,"F"),p(F,"runs");export function segmentFlow(e,t={}){const s={...DEFAULT_SEGMENT_OPTIONS};for(const[i,m]of Object.entries(t))typeof m=="number"&&Number.isFinite(m)&&(s[i]=m);const o=new Set,r=[];for(const i of e)o.has(i.id)||(o.add(i.id),r.push(A(i)));r.sort(K);const n=b(r[0]?.event.context?.flowId)??b(r[0]?.event.raw?.flowId)??"",l=new Map;for(const i of r)i.kind==="queue-enqueued"&&i.queueKey&&i.requestId&&!i.requestId.startsWith("job:")&&!l.has(i.queueKey)&&l.set(i.queueKey,i);const g=new Map,v=new Map,q=[];for(const i of r){const m=z(i),h=O(i);if(m!==void 0){const k=v.get(m);k?k.push(i):v.set(m,[i])}else if(h!==void 0){const k=g.get(h);k?k.push(i):g.set(h,[i])}else q.push(i)}const I=[],$=new Map;for(const[i,m]of g)C(m,s.occurrenceSlackMs).forEach((h,k)=>{const S={id:`${n}~r:${i}${k===0?"":`@${k+1}`}`,kind:"request",items:h,requestId:i};if(I.push(S),l.size)for(const y of h)y.kind==="queue-enqueued"&&$.set(y,S)});for(const[i,m]of v){const h=l.get(i),k=h?$.get(h):void 0;k?k.items.push(...m):I.push({id:`${n}~r:job:${i}`,kind:"request",items:m,requestId:`job:${i}`})}const j=r.filter(i=>i.kind==="fetch-done"&&O(i)!==void 0),a=new Map;for(const i of I)i.requestId&&a.set(i.requestId,[...a.get(i.requestId)??[],i]);const c=p((i,m)=>{const h=a.get(i);if(h)return h.find(k=>k.items.some(S=>S.kind==="fetch-done"&&S.ts===m))??h[h.length-1]},"owningUnit"),d=q.filter(i=>i.browser);for(const i of F(d,s.burstGapMs)){const m=i[0].ts,h=j.filter(y=>y.ts<=m&&m-y.ts<=s.attachWindowMs),k=[...new Set(h.map(y=>O(y)))];if(k.length===1){const y=c(k[0],h[h.length-1].ts);if(y){y.items.push(...i);continue}}const S=i.some(y=>y.kind==="flow-origin");I.push({id:`${n}~${S?"o":"u"}:${i[0].id}`,kind:S?"origin":"ui",items:i,...k.length>1?{after:k.sort()}:{}})}for(const i of F(q.filter(m=>!m.browser),s.phaseGapMs))I.push({id:`${n}~a:${i[0].id}`,kind:"ambient",items:i});const u=H(n,r.length,I,s),f=G(r);return f?{...u,sql:f}:u}w(segmentFlow,"segmentFlow"),p(segmentFlow,"segmentFlow");function H(e,t,s,o){for(const a of s)a.items.sort(K);const r=new Map;for(const a of s){const c=a.kind==="request"?E(a.items):void 0;c&&r.set(a,c)}const n=s.map(a=>{const c=W(a.items,r.get(a));return{unit:a,from:U(c,d=>d.from),to:D(c,d=>d.to)}});n.sort((a,c)=>a.from-c.from||(a.unit.id<c.unit.id?-1:1));const l=new Map;let g=0,v=-1/0;for(const a of n)(g===0||a.from-v>=o.phaseGapMs)&&(g+=1),v=Math.max(v,a.to),l.set(a.unit,g);const q=[];for(const a of n){const c=J(a.unit.items,o.maxSegmentEvents),d=a.unit.kind==="request"?G(a.unit.items):void 0;c.forEach((u,f)=>{const i=V(e,a.unit,u,l.get(a.unit),c.length>1?{index:f+1,total:c.length}:void 0,r.get(a.unit));q.push(d&&f===0?{...i,sql:d}:i)})}const I={};for(const a of q)for(const c of a.eventIds)I[c]=a.id;const $=[];for(const a of q){let c=$[a.phase-1];c||(c={index:a.phase,start:a.start,end:a.end,segmentIds:[]},$[a.phase-1]=c),c.start=Math.min(c.start,a.start),c.end=Math.max(c.end,a.end),c.segmentIds.push(a.id)}const j=q.reduce((a,c)=>a+c.counts.signal,0);return{flowId:e,segments:q,phases:$.filter(Boolean),assignment:I,stats:{events:t,signal:j,bookkeeping:t-j,segments:q.length,phases:$.filter(Boolean).length,largestSegment:q.reduce((a,c)=>Math.max(a,c.counts.total),0)}}}w(H,"J"),p(H,"assemble");function J(e,t){if(e.filter(n=>!n.bookkeeping).length<=t)return[e];const s=[];let o=[],r=0;for(const n of e)!n.bookkeeping&&r===t&&(s.push(o),o=[],r=0),o.push(n),n.bookkeeping||(r+=1);return o.length&&s.push(o),s}w(J,"Z"),p(J,"chunk");function V(e,t,s,o,r,n){const l={total:s.length,signal:0,bookkeeping:0,errors:0,warnings:0},g=new Set;let v="debug";for(const u of s){u.bookkeeping?l.bookkeeping+=1:l.signal+=1;const f=String(u.event.severity);f==="error"||f==="fatal"?l.errors+=1:f==="warning"&&(l.warnings+=1),(Q[f]??1)>(Q[v]??0)&&(v=f),u.project&&g.add(u.project)}const q=t.kind==="ui"||t.kind==="origin"?Y(s):[],I=W(s,n),$=U(I,u=>u.from),j=D(I,u=>u.to),a=n?s.filter(u=>n.has(u)).length:0,c=X(t.items),d=t.id;return{id:r&&r.index>1?`${d}#${r.index}`:d,flowId:e,kind:t.kind,label:Z(t,s,c,r,q),phase:o,start:$,end:j,durationMs:j-$,eventIds:s.map(u=>u.id),counts:l,projects:[...g].sort(),...c.route?{route:c.route}:{},...c.method?{method:c.method}:{},...t.requestId?{requestId:t.requestId}:{},...t.after?{after:t.after}:{},...q.length?{hot:q}:{},...r?{part:r}:{},...a?{stallsAfterResponse:a}:{},worstSeverity:v}}w(V,"ee"),p(V,"toSegment");function X(e){const t=e.find(s=>s.kind==="fetch-start"&&s.route)??e.find(s=>s.kind==="server-request"&&!s.parentRequestId&&s.route)??e.find(s=>s.kind==="gateway-request"&&s.route)??e.find(s=>s.kind==="fetch-done"&&s.route);return{...t?.route?{route:t.route}:{},...t?.method?{method:t.method.toUpperCase()}:{}}}w(X,"te"),p(X,"routeOf");function Y(e){const t=new Map;for(const s of e)s.subject&&!s.bookkeeping&&t.set(s.subject,(t.get(s.subject)??0)+1);return[...t.entries()].sort((s,o)=>o[1]-s[1]||(s[0]<o[0]?-1:1)).slice(0,3).map(([s,o])=>o>1?`${s} \xD7${o}`:s)}w(Y,"ne"),p(Y,"hotOf");function Z(e,t,s,o,r){const n=o?` (part ${o.index}/${o.total})`:"";if(e.kind==="request"){if(s.route)return`${s.method?`${s.method} `:""}${s.route}${n}`;const l=t.find(g=>g.queueKey);return l?`job ${l.queueKey}${n}`:`request ${e.requestId??""}${n}`}return e.kind==="origin"?`${t.find(l=>l.kind==="flow-origin")?.event.title||"start"}${r.length?` \xB7 ${r.join(", ")}`:""}${n}`:e.kind==="ui"?`UI update${r.length?` \xB7 ${r.join(", ")}`:""}${n}`:`background${n}`}w(Z,"se"),p(Z,"labelOf");const ee=50;export function sqlAccountingOf(e){return R(e,!1)}w(sqlAccountingOf,"sqlAccountingOf"),p(sqlAccountingOf,"sqlAccountingOf");function G(e){return R(e.map(t=>t.event),!0)}w(G,"L"),p(G,"accountSqlOfItems");function R(e,t){const s=new Map,o=new Map,r=t?void 0:new Set;for(const d of e){if(r){if(r.has(d.id))continue;r.add(d.id)}const u=x(d.raw)?d.raw:{},f=b(u.kind),i=b(d.context?.requestId);if(!i)continue;const m=b(u.project)??b(d.context?.projectName);if(f==="db-query"&&d.source==="db"){const h=o.get(i)??{count:0,workMs:0,...m?{project:m}:{}};h.count+=1,h.workMs+=M(u.durationMs)??0,o.set(i,h)}else if(f===SQL_ACCOUNT_KIND){const h=b(u.accountId)??d.id,k=M(u.seq)??0,S=s.get(h);if(S&&S.seq>=k)continue;s.set(h,{requestId:i,...m?{project:m}:{},seq:k,basis:u.basis==="end"?"end":"settled",statements:M(u.statements)??0,failed:M(u.failed)??0,workMs:M(u.workMs)??0,recorded:M(u.recorded)??0,suppressed:M(u.suppressed)??0,unwritten:M(u.unwritten)??0})}}const n=new Map;for(const d of s.values()){const u=n.get(d.requestId);if(!u){n.set(d.requestId,{...d});continue}d.basis==="settled"&&(u.basis="settled"),u.statements+=d.statements,u.failed+=d.failed,u.workMs+=d.workMs,u.recorded+=d.recorded,u.suppressed+=d.suppressed,u.unwritten+=d.unwritten}const l=[...new Set([...o.keys(),...n.keys()])].sort();if(l.length===0)return;const g={statements:0,failed:0,workMs:0,recorded:0,suppressed:0,unwritten:0},v={statements:0,workMs:0},q=[];for(const d of l){const u=o.get(d),f=n.get(d),i=u?.count??0;v.statements+=i,v.workMs+=u?.workMs??0;const m=!f||i>f.statements?"unverified":i===f.statements?"complete":"incomplete";f&&m!=="unverified"&&(g.statements+=f.statements,g.failed+=f.failed,g.workMs+=f.workMs,g.recorded+=f.recorded,g.suppressed+=f.suppressed,g.unwritten+=f.unwritten);const h=u?.project??f?.project;q.push({requestId:d,...h?{project:h}:{},status:m,observed:i,observedWorkMs:u?.workMs??0,...f?{basis:f.basis,statements:f.statements,failed:f.failed,workMs:f.workMs,recorded:f.recorded,suppressed:f.suppressed,unwritten:f.unwritten}:{}})}const I=p(d=>q.filter(u=>u.status===d).length,"tally"),$=I("unverified"),j=I("incomplete"),a=p(d=>(d.statements??0)-d.observed,"missing"),c=q.filter(d=>d.status!=="complete").sort((d,u)=>(d.status==="incomplete"?0:1)-(u.status==="incomplete"?0:1)||a(u)-a(d)||(d.requestId<u.requestId?-1:d.requestId>u.requestId?1:0));return{status:$>0?"unverified":j>0?"incomplete":"complete",requests:q.length,complete:I("complete"),incomplete:j,unverified:$,settled:q.filter(d=>d.status!=="unverified"&&d.basis==="settled").length,observed:v,accounted:g,gaps:c.slice(0,ee),gapsTruncated:c.length>ee}}w(R,"D"),p(R,"accountSql");
1
+ "use strict";var ne=Object.defineProperty;var k=(e,t)=>ne(e,"name",{value:t,configurable:!0});var se=Object.defineProperty,w=k((e,t)=>se(e,"name",{value:t,configurable:!0}),"w"),oe=Object.defineProperty,p=w((e,t)=>oe(e,"name",{value:t,configurable:!0}),"p");export const DEFAULT_SEGMENT_OPTIONS={phaseGapMs:1500,burstGapMs:250,attachWindowMs:400,maxSegmentEvents:400,occurrenceSlackMs:10},FLOW_BOOKKEEPING_KINDS=new Set(["subscription-added","subscription-removed","hook-run","store-created","singleton-instance","visual-frame"]),SQL_ACCOUNT_KIND="db-request-account";const re=new Set(["react","valtio","client-runtime","chrome","visual"]),O=p(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObj"),b=p(e=>typeof e=="string"&&e!==""?e:void 0,"str"),$=p(e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,"num"),Y=new WeakMap;function A(e){let t=Y.get(e);return t||(t=T(e),Y.set(e,t)),t}k(A,"A"),w(A,"K"),p(A,"itemOf");function T(e){const t=O(e.raw)?e.raw:{},n=O(t.request)?t.request:{},o=O(t.span)?t.span:{},r=e.context??{},s=b(t.kind)??"",l=s===SQL_ACCOUNT_KIND,g=(l?$(t.lastEndedAt):void 0)??$(e.timestamp)??0,I=$(n.startedAt)??$(o.startTime)??$(t.startedAt)??(l?$(t.firstStartedAt):void 0),q=$(n.endedAt)??$(o.endTime)??(I!==void 0&&$(t.durationMs)!==void 0?I+t.durationMs:void 0),M=Math.min(g,I??g),j=Math.max(g,q??g),y=O(t.render)?t.render:{},c=O(t.update)?t.update:{},a=s==="render"?b(y.componentName):s==="state-update"?b(c.path)?.split(".").slice(0,2).join("."):void 0,d=b(t.queue),u=b(t.jobId),f=String(e.source),i=b(t.project)??b(r.projectName),m=s==="fetch-start"||s==="fetch-done"||s==="gateway-request";return{event:e,id:e.id,ts:g,from:M,to:j,kind:s,source:f,requestId:b(r.requestId),parentRequestId:b(r.parentRequestId),queueKey:d&&u?`${d}#${u}`:void 0,browser:re.has(f)||f==="memory"&&i===void 0,bookkeeping:FLOW_BOOKKEEPING_KINDS.has(s),project:i,subject:a,route:m?G(b(t.url)):s==="server-request"?b(n.route):void 0,method:m?b(t.method):s==="server-request"?b(n.method):void 0}}k(T,"_"),w(T,"C"),p(T,"readItem");function G(e){if(!e)return;const t=e.search(/[?#]/),n=t===-1?e:e.slice(0,t),o=/^[a-z][a-z0-9+.-]*:\/\/[^/]*(\/.*)?$/i.exec(n);return o?o[1]??"/":n}k(G,"B"),w(G,"P"),p(G,"pathOnly");const ie=p(e=>e.split(".")[0],"rootOf"),Z=p((e,t)=>e.reduce((n,o)=>Math.min(n,t(o)),1/0),"minOf"),H=p((e,t)=>e.reduce((n,o)=>Math.max(n,t(o)),-1/0),"maxOf"),_=p((e,t)=>e.ts-t.ts||(e.id<t.id?-1:e.id>t.id?1:0),"compare"),K=p(e=>e.requestId&&!e.requestId.startsWith("job:")?ie(e.requestId):void 0,"directFamilyOf");function B(e){if(e.requestId?.startsWith("job:"))return e.requestId.slice(4);if(e.queueKey&&e.kind!=="queue-enqueued"&&!e.requestId)return e.queueKey}k(B,"z"),w(B,"Q"),p(B,"jobKeyOf");function D(e,t){const n=e.filter(s=>!s.parentRequestId&&(s.kind==="server-request"||s.kind==="gateway-request"||s.kind==="fetch-start"||s.kind==="fetch-done")).sort((s,l)=>s.from-l.from||_(s,l));if(n.length<2)return[e];const o=[];for(const s of n){const l=o[o.length-1];l&&s.from<=l.to+t?l.to=Math.max(l.to,s.to):o.push({from:s.from,to:s.to})}if(o.length<2)return[e];const r=o.map(()=>[]);for(const s of e)r[t>=0?U(o,s.ts,t):P(o,s.ts,t)].push(s);return r.filter(s=>s.length>0)}k(D,"C"),w(D,"V"),p(D,"occurrencesOf");function P(e,t,n){const o=e.findIndex(s=>t>=s.from-n&&t<=s.to+n);if(o!==-1)return o;let r=0;for(let s=0;s<e.length;s+=1)e[s].from<=t&&(r=s);return r}k(P,"L"),w(P,"X"),p(P,"spanScan");function U(e,t,n){let o=0,r=e.length;for(;o<r;){const s=o+r>>1;e[s].to+n<t?o=s+1:r=s}if(o<e.length&&t>=e[o].from-n)return o;for(o=0,r=e.length;o<r;){const s=o+r>>1;e[s].from<=t?o=s+1:r=s}return Math.max(0,o-1)}k(U,"P"),w(U,"Y"),p(U,"spanAt");const ue=new Set(["server-request","gateway-request","fetch-done","fetch-error","queue-process"]),C="event-loop-stall";function N(e){let t=-1/0,n=!1;for(const r of e)ue.has(r.kind)?t=Math.max(t,r.to):r.kind===C&&(n=!0);if(!n||!Number.isFinite(t))return;let o;for(const r of e)r.kind===C&&r.from>=t&&(o??=new Map).set(r,Math.round(r.from-t));return o}k(N,"E"),w(N,"_"),p(N,"lateStallsOf");export function stallsAfterResponse(e){const t=new Map;if(!e.some(o=>O(o.raw)&&o.raw.kind===C))return t;const n=new Map;for(const o of e){const r=A(o),s=r.requestId?.startsWith("job:")?r.requestId:K(r);if(s===void 0)continue;const l=n.get(s);l?l.push(r):n.set(s,[r])}for(const o of n.values())for(const[r,s]of N(o)??[])t.set(r.id,s);return t}k(stallsAfterResponse,"stallsAfterResponse"),w(stallsAfterResponse,"stallsAfterResponse"),p(stallsAfterResponse,"stallsAfterResponse");function E(e,t){if(!t)return e;const n=e.filter(o=>!t.has(o));return n.length?n:e}k(E,"W"),w(E,"T"),p(E,"timedItems");const ee={debug:0,info:1,warning:2,error:3,fatal:4};function F(e,t){const n=[];let o=[];for(const r of e){const s=o[o.length-1];s&&r.ts-s.ts>=t&&(n.push(o),o=[]),o.push(r)}return o.length&&n.push(o),n}k(F,"F"),w(F,"F"),p(F,"runs");export function segmentFlow(e,t={}){const n={...DEFAULT_SEGMENT_OPTIONS};for(const[i,m]of Object.entries(t))typeof m=="number"&&Number.isFinite(m)&&(n[i]=m);const o=new Set,r=[];for(const i of e)o.has(i.id)||(o.add(i.id),r.push(A(i)));r.sort(_);const s=b(r[0]?.event.context?.flowId)??b(r[0]?.event.raw?.flowId)??"",l=new Map;for(const i of r)i.kind==="queue-enqueued"&&i.queueKey&&i.requestId&&!i.requestId.startsWith("job:")&&!l.has(i.queueKey)&&l.set(i.queueKey,i);const g=new Map,I=new Map,q=[];for(const i of r){const m=B(i),h=K(i);if(m!==void 0){const v=I.get(m);v?v.push(i):I.set(m,[i])}else if(h!==void 0){const v=g.get(h);v?v.push(i):g.set(h,[i])}else q.push(i)}const M=[],j=new Map;for(const[i,m]of g)D(m,n.occurrenceSlackMs).forEach((h,v)=>{const S={id:`${s}~r:${i}${v===0?"":`@${v+1}`}`,kind:"request",items:h,requestId:i};if(M.push(S),l.size)for(const x of h)x.kind==="queue-enqueued"&&j.set(x,S)});for(const[i,m]of I){const h=l.get(i),v=h?j.get(h):void 0;v?v.items.push(...m):M.push({id:`${s}~r:job:${i}`,kind:"request",items:m,requestId:`job:${i}`})}const y=r.filter(i=>i.kind==="fetch-done"&&K(i)!==void 0),c=new Map;for(const i of M)i.requestId&&c.set(i.requestId,[...c.get(i.requestId)??[],i]);const a=p((i,m)=>{const h=c.get(i);if(h)return h.find(v=>v.items.some(S=>S.kind==="fetch-done"&&S.ts===m))??h[h.length-1]},"owningUnit"),d=q.filter(i=>i.browser);for(const i of F(d,n.burstGapMs)){const m=i[0].ts,h=y.filter(x=>x.ts<=m&&m-x.ts<=n.attachWindowMs),v=[...new Set(h.map(x=>K(x)))];if(v.length===1){const x=a(v[0],h[h.length-1].ts);if(x){x.items.push(...i);continue}}const S=i.some(x=>x.kind==="flow-origin");M.push({id:`${s}~${S?"o":"u"}:${i[0].id}`,kind:S?"origin":"ui",items:i,...v.length>1?{after:v.sort()}:{}})}for(const i of F(q.filter(m=>!m.browser),n.phaseGapMs))M.push({id:`${s}~a:${i[0].id}`,kind:"ambient",items:i});const u=L(s,r.length,M,n),f=W(r);return f?{...u,sql:f}:u}k(segmentFlow,"segmentFlow"),w(segmentFlow,"segmentFlow"),p(segmentFlow,"segmentFlow");function L(e,t,n,o){for(const c of n)c.items.sort(_);const r=new Map;for(const c of n){const a=c.kind==="request"?N(c.items):void 0;a&&r.set(c,a)}const s=n.map(c=>{const a=E(c.items,r.get(c));return{unit:c,from:Z(a,d=>d.from),to:H(a,d=>d.to)}});s.sort((c,a)=>c.from-a.from||(c.unit.id<a.unit.id?-1:1));const l=new Map;let g=0,I=-1/0;for(const c of s)(g===0||c.from-I>=o.phaseGapMs)&&(g+=1),I=Math.max(I,c.to),l.set(c.unit,g);const q=[];for(const c of s){const a=z(c.unit.items,o.maxSegmentEvents),d=c.unit.kind==="request"?W(c.unit.items):void 0;a.forEach((u,f)=>{const i=Q(e,c.unit,u,l.get(c.unit),a.length>1?{index:f+1,total:a.length}:void 0,r.get(c.unit));q.push(d&&f===0?{...i,sql:d}:i)})}const M={};for(const c of q)for(const a of c.eventIds)M[a]=c.id;const j=[];for(const c of q){let a=j[c.phase-1];a||(a={index:c.phase,start:c.start,end:c.end,segmentIds:[]},j[c.phase-1]=a),a.start=Math.min(a.start,c.start),a.end=Math.max(a.end,c.end),a.segmentIds.push(c.id)}const y=q.reduce((c,a)=>c+a.counts.signal,0);return{flowId:e,segments:q,phases:j.filter(Boolean),assignment:M,stats:{events:t,signal:y,bookkeeping:t-y,segments:q.length,phases:j.filter(Boolean).length,largestSegment:q.reduce((c,a)=>Math.max(c,a.counts.total),0)}}}k(L,"H"),w(L,"J"),p(L,"assemble");function z(e,t){if(e.filter(s=>!s.bookkeeping).length<=t)return[e];const n=[];let o=[],r=0;for(const s of e)!s.bookkeeping&&r===t&&(n.push(o),o=[],r=0),o.push(s),s.bookkeeping||(r+=1);return o.length&&n.push(o),n}k(z,"J"),w(z,"Z"),p(z,"chunk");function Q(e,t,n,o,r,s){const l={total:n.length,signal:0,bookkeeping:0,errors:0,warnings:0},g=new Set;let I="debug";for(const u of n){u.bookkeeping?l.bookkeeping+=1:l.signal+=1;const f=String(u.event.severity);f==="error"||f==="fatal"?l.errors+=1:f==="warning"&&(l.warnings+=1),(ee[f]??1)>(ee[I]??0)&&(I=f),u.project&&g.add(u.project)}const q=t.kind==="ui"||t.kind==="origin"?V(n):[],M=E(n,s),j=Z(M,u=>u.from),y=H(M,u=>u.to),c=s?n.filter(u=>s.has(u)).length:0,a=J(t.items),d=t.id;return{id:r&&r.index>1?`${d}#${r.index}`:d,flowId:e,kind:t.kind,label:X(t,n,a,r,q),phase:o,start:j,end:y,durationMs:y-j,eventIds:n.map(u=>u.id),counts:l,projects:[...g].sort(),...a.route?{route:a.route}:{},...a.method?{method:a.method}:{},...t.requestId?{requestId:t.requestId}:{},...t.after?{after:t.after}:{},...q.length?{hot:q}:{},...r?{part:r}:{},...c?{stallsAfterResponse:c}:{},worstSeverity:I}}k(Q,"V"),w(Q,"ee"),p(Q,"toSegment");function J(e){const t=e.find(n=>n.kind==="fetch-start"&&n.route)??e.find(n=>n.kind==="server-request"&&!n.parentRequestId&&n.route)??e.find(n=>n.kind==="gateway-request"&&n.route)??e.find(n=>n.kind==="fetch-done"&&n.route);return{...t?.route?{route:t.route}:{},...t?.method?{method:t.method.toUpperCase()}:{}}}k(J,"X"),w(J,"te"),p(J,"routeOf");function V(e){const t=new Map;for(const n of e)n.subject&&!n.bookkeeping&&t.set(n.subject,(t.get(n.subject)??0)+1);return[...t.entries()].sort((n,o)=>o[1]-n[1]||(n[0]<o[0]?-1:1)).slice(0,3).map(([n,o])=>o>1?`${n} \xD7${o}`:n)}k(V,"Y"),w(V,"ne"),p(V,"hotOf");function X(e,t,n,o,r){const s=o?` (part ${o.index}/${o.total})`:"";if(e.kind==="request"){if(n.route)return`${n.method?`${n.method} `:""}${n.route}${s}`;const l=t.find(g=>g.queueKey);return l?`job ${l.queueKey}${s}`:`request ${e.requestId??""}${s}`}return e.kind==="origin"?`${t.find(l=>l.kind==="flow-origin")?.event.title||"start"}${r.length?` \xB7 ${r.join(", ")}`:""}${s}`:e.kind==="ui"?`UI update${r.length?` \xB7 ${r.join(", ")}`:""}${s}`:`background${s}`}k(X,"Z"),w(X,"se"),p(X,"labelOf");const te=50;export function sqlAccountingOf(e){return R(e,!1)}k(sqlAccountingOf,"sqlAccountingOf"),w(sqlAccountingOf,"sqlAccountingOf"),p(sqlAccountingOf,"sqlAccountingOf");function W(e){return R(e.map(t=>t.event),!0)}k(W,"G"),w(W,"L"),p(W,"accountSqlOfItems");function R(e,t){const n=new Map,o=new Map,r=t?void 0:new Set;for(const d of e){if(r){if(r.has(d.id))continue;r.add(d.id)}const u=O(d.raw)?d.raw:{},f=b(u.kind),i=b(d.context?.requestId);if(!i)continue;const m=b(u.project)??b(d.context?.projectName);if(f==="db-query"&&d.source==="db"){const h=o.get(i)??{count:0,workMs:0,...m?{project:m}:{}};h.count+=1,h.workMs+=$(u.durationMs)??0,o.set(i,h)}else if(f===SQL_ACCOUNT_KIND){const h=b(u.accountId)??d.id,v=$(u.seq)??0,S=n.get(h);if(S&&S.seq>=v)continue;n.set(h,{requestId:i,...m?{project:m}:{},seq:v,basis:u.basis==="end"?"end":"settled",statements:$(u.statements)??0,failed:$(u.failed)??0,workMs:$(u.workMs)??0,recorded:$(u.recorded)??0,suppressed:$(u.suppressed)??0,unwritten:$(u.unwritten)??0})}}const s=new Map;for(const d of n.values()){const u=s.get(d.requestId);if(!u){s.set(d.requestId,{...d});continue}d.basis==="settled"&&(u.basis="settled"),u.statements+=d.statements,u.failed+=d.failed,u.workMs+=d.workMs,u.recorded+=d.recorded,u.suppressed+=d.suppressed,u.unwritten+=d.unwritten}const l=[...new Set([...o.keys(),...s.keys()])].sort();if(l.length===0)return;const g={statements:0,failed:0,workMs:0,recorded:0,suppressed:0,unwritten:0},I={statements:0,workMs:0},q=[];for(const d of l){const u=o.get(d),f=s.get(d),i=u?.count??0;I.statements+=i,I.workMs+=u?.workMs??0;const m=!f||i>f.statements?"unverified":i===f.statements?"complete":"incomplete";f&&m!=="unverified"&&(g.statements+=f.statements,g.failed+=f.failed,g.workMs+=f.workMs,g.recorded+=f.recorded,g.suppressed+=f.suppressed,g.unwritten+=f.unwritten);const h=u?.project??f?.project;q.push({requestId:d,...h?{project:h}:{},status:m,observed:i,observedWorkMs:u?.workMs??0,...f?{basis:f.basis,statements:f.statements,failed:f.failed,workMs:f.workMs,recorded:f.recorded,suppressed:f.suppressed,unwritten:f.unwritten}:{}})}const M=p(d=>q.filter(u=>u.status===d).length,"tally"),j=M("unverified"),y=M("incomplete"),c=p(d=>(d.statements??0)-d.observed,"missing"),a=q.filter(d=>d.status!=="complete").sort((d,u)=>(d.status==="incomplete"?0:1)-(u.status==="incomplete"?0:1)||c(u)-c(d)||(d.requestId<u.requestId?-1:d.requestId>u.requestId?1:0));return{status:j>0?"unverified":y>0?"incomplete":"complete",requests:q.length,complete:M("complete"),incomplete:y,unverified:j,settled:q.filter(d=>d.status!=="unverified"&&d.basis==="settled").length,observed:I,accounted:g,gaps:a.slice(0,te),gapsTruncated:a.length>te}}k(R,"R"),w(R,"D"),p(R,"accountSql");
@@ -1,3 +1,4 @@
1
+ import { type QueueSignal } from './queue-signals.js';
1
2
  import { type BaseEvent } from '@lensmcp/protocol-types';
2
3
  /**
3
4
  * Architectural area of one flow event — the swimlane it renders in, and a
@@ -71,17 +72,20 @@ export declare function trimFlowEvent(event: BaseEvent, opts?: FlowShapeOptions)
71
72
  role?: string | undefined;
72
73
  captured?: string[] | undefined;
73
74
  error?: string | undefined;
74
- outcome?: "returned" | "threw" | undefined;
75
+ signal?: QueueSignal | undefined;
76
+ outcome?: "returned" | "threw" | "signalled" | undefined;
75
77
  calleeRequestId?: string | undefined;
76
78
  hop?: true | undefined;
77
- source: "nx" | "vite" | "typescript" | "eslint" | "rollup" | "client-runtime" | "chrome" | "react" | "valtio" | "nestjs" | "nextjs" | "db" | "redis" | "queue" | "memory" | "visual" | "perf" | "security" | "gateway" | "external" | "ai" | "lens" | "custom";
78
- category: "db" | "memory" | "visual" | "security" | "ai" | "build" | "lint" | "typecheck" | "test" | "runtime" | "render" | "trace" | "state" | "network" | "backend" | "performance" | "deps" | "cluster" | "agent";
79
- severity: "error" | "debug" | "info" | "warning" | "fatal";
79
+ source: "gateway" | "ai" | "db" | "redis" | "queue" | "external" | "visual" | "react" | "memory" | "lens" | "nx" | "vite" | "typescript" | "eslint" | "rollup" | "client-runtime" | "chrome" | "valtio" | "nestjs" | "nextjs" | "perf" | "security" | "custom";
80
+ category: "ai" | "db" | "visual" | "memory" | "security" | "test" | "typecheck" | "lint" | "build" | "state" | "agent" | "network" | "cluster" | "trace" | "runtime" | "render" | "backend" | "performance" | "deps";
81
+ severity: "error" | "info" | "warning" | "debug" | "fatal";
80
82
  title: string;
81
83
  kind: string | undefined;
82
84
  area: FlowArea;
83
85
  jobId?: string | undefined;
84
86
  queue?: string | undefined;
87
+ broker?: string | undefined;
88
+ db?: string | undefined;
85
89
  valuesId?: string | undefined;
86
90
  method?: string;
87
91
  /** The route template (`/companies/:id`): the framework's own when it says, else the path with its ids folded. */
@@ -145,17 +149,20 @@ export declare function buildFlowDetail(rawEvents: BaseEvent[], opts?: FlowShape
145
149
  role?: string | undefined;
146
150
  captured?: string[] | undefined;
147
151
  error?: string | undefined;
148
- outcome?: "returned" | "threw" | undefined;
152
+ signal?: QueueSignal | undefined;
153
+ outcome?: "returned" | "threw" | "signalled" | undefined;
149
154
  calleeRequestId?: string | undefined;
150
155
  hop?: true | undefined;
151
- source: "nx" | "vite" | "typescript" | "eslint" | "rollup" | "client-runtime" | "chrome" | "react" | "valtio" | "nestjs" | "nextjs" | "db" | "redis" | "queue" | "memory" | "visual" | "perf" | "security" | "gateway" | "external" | "ai" | "lens" | "custom";
152
- category: "db" | "memory" | "visual" | "security" | "ai" | "build" | "lint" | "typecheck" | "test" | "runtime" | "render" | "trace" | "state" | "network" | "backend" | "performance" | "deps" | "cluster" | "agent";
153
- severity: "error" | "debug" | "info" | "warning" | "fatal";
156
+ source: "gateway" | "ai" | "db" | "redis" | "queue" | "external" | "visual" | "react" | "memory" | "lens" | "nx" | "vite" | "typescript" | "eslint" | "rollup" | "client-runtime" | "chrome" | "valtio" | "nestjs" | "nextjs" | "perf" | "security" | "custom";
157
+ category: "ai" | "db" | "visual" | "memory" | "security" | "test" | "typecheck" | "lint" | "build" | "state" | "agent" | "network" | "cluster" | "trace" | "runtime" | "render" | "backend" | "performance" | "deps";
158
+ severity: "error" | "info" | "warning" | "debug" | "fatal";
154
159
  title: string;
155
160
  kind: string | undefined;
156
161
  area: FlowArea;
157
162
  jobId?: string | undefined;
158
163
  queue?: string | undefined;
164
+ broker?: string | undefined;
165
+ db?: string | undefined;
159
166
  valuesId?: string | undefined;
160
167
  method?: string;
161
168
  /** The route template (`/companies/:id`): the framework's own when it says, else the path with its ids folded. */