@lensmcp/bridge 1.21.3 → 1.21.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/event-mappers.js +3 -3
- package/lib/types.d.ts +34 -0
- package/package.json +3 -3
package/lib/event-mappers.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)[0]??e.reason;return{id:
|
|
3
|
-
`).slice(0,2);for(const s of n){const r=s.match(/at\s+(\S+)/);if(r&&r[1])return r[1]}return"unknown"}
|
|
1
|
+
"use strict";var w=Object.defineProperty;var l=(e,n)=>w(e,"name",{value:n,configurable:!0});var I=Object.defineProperty,m=l((e,n)=>I(e,"name",{value:n,configurable:!0}),"l");import{fingerprint as a,ulid as o}from"@lensmcp/core";import{redactDeep as y,redactText as d,redactUrl as g,safeText as u,safeTitle as c}from"./redact.js";const x="pending";export function envelopeToEvent(e,n=x){const s=e.tabId?{tabId:e.tabId}:{};switch(e.kind){case"error":{const r=!e.stack&&!e.source&&(!e.message||e.message==="Script error."),i=e.name&&e.name!=="Error"?`${e.name}: `:"",t=r?"Uncaught cross-origin script error (no detail available \u2014 add crossorigin to the script tag)":e.message?`${i}${e.message}`:`Uncaught ${e.name??"error"}`;return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"error",context:{sessionId:n,...s},fingerprint:a({kind:"runtime",identity:`error:${k(e.stack)}`,file:e.source,detail:e.message??e.name}),title:c(t),message:u(e.stack??e.message),location:e.source?{file:g(e.source),line:e.lineno,column:e.colno}:void 0,raw:{...e,...e.message?{message:d(e.message)}:{},...e.stack?{stack:u(e.stack)}:{},...e.source?{source:g(e.source)}:{}}}}case"resource-error":{const r=e.url?g(e.url):void 0;return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"error",context:{sessionId:n,...s},fingerprint:a({kind:"runtime",identity:`resource-error:${e.tagName}:${v(e.url??"")}`}),title:c(`Failed to load <${e.tagName}>${r?` ${r}`:""}`),...r?{relatedUrls:[r]}:{},raw:{...e,...r?{url:r}:{}}}}case"unhandledrejection":{const r=e.name&&e.name!=="Error"?`${e.name}: `:"",i=e.reason.split(`
|
|
2
|
+
`)[0]??e.reason;return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"error",context:{sessionId:n,...s},fingerprint:a({kind:"runtime",identity:`unhandledrejection:${e.reason.slice(0,80)}`}),title:c(`Unhandled promise rejection: ${r}${i}`),message:u(e.stack??e.reason),raw:{...e,reason:d(e.reason),...e.stack?{stack:u(e.stack)}:{}}}}case"console":{const r=e.level==="error"?"error":e.level==="warn"?"warning":"info",i=y(e.args),t=i.map(h).join(" ");return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"runtime",severity:r,context:{sessionId:n,...s},fingerprint:a({kind:"runtime",identity:`console:${e.level}:${t.slice(0,80)}`}),title:`console.${e.level}`,message:u(t),raw:{...e,args:i}}}case"fetch":{const r=e.error!==void 0||e.status!==void 0&&e.status>=400,i=g(e.url),t=e.status!==void 0?` \u2192 ${e.status}${e.statusText?` ${e.statusText}`:""}`:"";return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"network",severity:r?"error":"info",context:{sessionId:n,...s},fingerprint:a({kind:"network",identity:`${e.method}:${v(e.url)}:${e.status??"err"}`}),title:c(`${e.method} ${i}${t}`),message:u(e.error),relatedUrls:[i],raw:{...e,url:i}}}case"route":return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"info",context:{sessionId:n,url:e.url,...s},fingerprint:a({kind:"runtime",identity:`route:${e.url}`}),title:`Route \u2192 ${e.url}`,raw:e};case"ready":return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"info",context:{sessionId:n,url:e.url,...s},fingerprint:a({kind:"runtime",identity:"client-ready"}),title:"Client runtime ready",message:e.reloadCause?`${e.userAgent} \u2014 after a Vite full reload${e.reloadCause.triggeredBy?` triggered by ${u(d(e.reloadCause.triggeredBy))}`:""}`:e.userAgent,raw:e};case"hmr":{const r=e.triggeredBy?d(e.triggeredBy):void 0,i=e.path?d(e.path):void 0,t=e.event==="full-reload"?`full-reload:${r??i??"?"}`:e.event==="invalidate"?`invalidate:${i??"?"}`:e.event,p=e.event==="full-reload"?`Vite full reload${r?` \u2014 ${c(r)} could not hot-update`:i?` \u2014 ${c(i)}`:""}`:e.event==="update"?`Vite HMR update (${e.count??e.updates?.length??0} module${(e.count??e.updates?.length??0)===1?"":"s"})`:e.event==="invalidate"?`Vite HMR invalidate \u2014 ${c(i??"?")}`:e.event==="ws-disconnect"?"Vite HMR socket lost \u2014 the page will poll and reload":"Vite HMR socket connected";return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"build",severity:e.event==="full-reload"||e.event==="ws-disconnect"?"warning":"info",context:{sessionId:n,...s},fingerprint:a({kind:"hmr",identity:t}),title:p,...e.message?{message:u(d(e.message))}:{},...r||i?{location:{file:r??i??""}}:{},...e.updates?.length?{relatedFiles:e.updates.map(f=>d(f))}:{},raw:{...e,...r?{triggeredBy:r}:{},...i?{path:i}:{}}}}case"gone":return{id:o(),sessionId:n,timestamp:e.at,source:"client-runtime",category:"runtime",severity:"info",context:{sessionId:n,...s},fingerprint:a({kind:"runtime",identity:"client-gone"}),title:"Client runtime gone",raw:e};case"publish":{const r=$(e.category,e.raw),i=r&&r.status!==void 0&&r.status>=400?"error":e.severity??"info",t=m(f=>r&&r.url!==r.redactedUrl?f.split(r.url).join(r.redactedUrl):f,"scrub"),p=t(e.title);return{id:o(),sessionId:n,timestamp:e.at,source:e.source,category:e.category,severity:i,context:{sessionId:n,...s,...e.context??{}},fingerprint:e.fingerprint?t(e.fingerprint):a({kind:"publish",identity:p}),title:c(p),message:u(e.message),...r?{relatedUrls:[r.redactedUrl]}:{},raw:r?{...y(e.raw),url:r.redactedUrl}:y(e.raw)}}}}l(envelopeToEvent,"envelopeToEvent"),m(envelopeToEvent,"envelopeToEvent");function $(e,n){if(e!=="network"||!n||typeof n!="object")return;const s=n;if(!(typeof s.url!="string"||s.url.length===0))return{url:s.url,redactedUrl:g(s.url),...typeof s.status=="number"?{status:s.status}:{}}}l($,"h"),m($,"networkDetails");function k(e){if(!e)return"unknown";const n=e.split(`
|
|
3
|
+
`).slice(0,2);for(const s of n){const r=s.match(/at\s+(\S+)/);if(r&&r[1])return r[1]}return"unknown"}l(k,"w"),m(k,"normaliseStackTopFrame");function v(e){try{return`${new URL(e,"http://x").pathname}`}catch{return e}}l(v,"y"),m(v,"normaliseUrl");function h(e){if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}l(h,"x"),m(h,"stringify");
|
package/lib/types.d.ts
CHANGED
|
@@ -79,6 +79,40 @@ export type ClientEnvelope = (
|
|
|
79
79
|
at: number;
|
|
80
80
|
userAgent: string;
|
|
81
81
|
url: string;
|
|
82
|
+
/**
|
|
83
|
+
* Why THIS document exists, when the previous one in the tab was thrown away by Vite: the
|
|
84
|
+
* `vite:beforeFullReload` the runtime saw just before the reload, parked in `sessionStorage`
|
|
85
|
+
* because the socket that saw it died with the page. Absent on a fresh navigation.
|
|
86
|
+
*/
|
|
87
|
+
reloadCause?: {
|
|
88
|
+
path?: string;
|
|
89
|
+
triggeredBy?: string;
|
|
90
|
+
at: number;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Vite's HMR channel as the PAGE sees it — the client-side events Vite emits on `import.meta.hot`.
|
|
95
|
+
* This is what lets the lens answer "why did the page reload instead of hot-updating?" and "why
|
|
96
|
+
* did the tab lose its dev server?": `full-reload` names the file Vite could not hot-update
|
|
97
|
+
* (`triggeredBy`) and the path it reloaded for; `update` lists the modules that DID hot-update;
|
|
98
|
+
* `invalidate` is a module giving up on self-acceptance; `ws-disconnect` / `ws-connect` are the
|
|
99
|
+
* HMR socket itself — the "[vite] server connection lost" console line, as data. Without these the
|
|
100
|
+
* lens was blind to ~320 full reloads a day on one workspace (issues/dev-gateway/08).
|
|
101
|
+
*/
|
|
102
|
+
| {
|
|
103
|
+
kind: 'hmr';
|
|
104
|
+
at: number;
|
|
105
|
+
event: 'full-reload' | 'update' | 'invalidate' | 'ws-disconnect' | 'ws-connect';
|
|
106
|
+
/** `full-reload`: the reload path; `invalidate`: the invalidated module. */
|
|
107
|
+
path?: string;
|
|
108
|
+
/** `full-reload`: the changed file Vite could not hot-update (Vite ≥ 5.1). */
|
|
109
|
+
triggeredBy?: string;
|
|
110
|
+
/** `update`: the hot-updated module paths (bounded). */
|
|
111
|
+
updates?: string[];
|
|
112
|
+
/** `update`: how many updates the payload carried (before bounding). */
|
|
113
|
+
count?: number;
|
|
114
|
+
/** `invalidate`: Vite's reason. */
|
|
115
|
+
message?: string;
|
|
82
116
|
}
|
|
83
117
|
/**
|
|
84
118
|
* The tab's transport closed — its document is GONE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/bridge",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@lensmcp/core": "1.21.
|
|
23
|
-
"@lensmcp/protocol-types": "1.21.
|
|
22
|
+
"@lensmcp/core": "1.21.5",
|
|
23
|
+
"@lensmcp/protocol-types": "1.21.5",
|
|
24
24
|
"tslib": "^2.3.0",
|
|
25
25
|
"ws": "^8.21.0"
|
|
26
26
|
},
|