@lensmcp/client-runtime 1.23.12 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/auto.d.ts +1 -1
- package/auto.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/auto.d.ts +4 -0
- package/lib/auto.js +1 -1
- package/lib/install.d.ts +5 -0
- package/lib/install.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,12 +34,24 @@ Run the bridge alongside your dev server:
|
|
|
34
34
|
lensmcp bridge # ws://127.0.0.1:5747, forwards to .lensmcp/events.jsonl
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
The bridge admits pages by **origin**: loopback dev servers (`localhost`,
|
|
38
|
+
`127.0.0.1`, `*.localhost`) work as-is; a page served from any other host — a
|
|
39
|
+
custom `/etc/hosts` name, a LAN address — needs its origin in
|
|
40
|
+
`LENSMCP_BRIDGE_ALLOWED_ORIGINS` where the bridge runs. If the bridge was
|
|
41
|
+
started with `LENSMCP_BRIDGE_TOKEN`, give the page the same value:
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<meta name="lensmcp-ws-token" content="…">
|
|
45
|
+
<!-- or: <script>window.__LENSMCP_WS_TOKEN__ = '…'</script> before the runtime loads -->
|
|
46
|
+
```
|
|
47
|
+
|
|
37
48
|
For explicit control, call the installer yourself instead of importing `/auto`:
|
|
38
49
|
|
|
39
50
|
```ts
|
|
40
51
|
import { installLensmcp } from '@lensmcp/client-runtime';
|
|
41
52
|
|
|
42
53
|
installLensmcp({ wsUrl: 'ws://127.0.0.1:5747' });
|
|
54
|
+
// against a bridge started with LENSMCP_BRIDGE_TOKEN: installLensmcp({ wsUrl: '…', wsToken: '…' })
|
|
43
55
|
```
|
|
44
56
|
|
|
45
57
|
## With a build plugin
|
package/auto.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { installLensmcp, resolveLensmcpWsUrl, type AutoInstallOptions } from './lib/auto.js';
|
|
1
|
+
export { installLensmcp, resolveLensmcpWsUrl, resolveLensmcpWsToken, type AutoInstallOptions } from './lib/auto.js';
|
package/auto.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{installLensmcp as s}from"./lib/auto.js";s();export{installLensmcp,resolveLensmcpWsUrl}from"./lib/auto.js";
|
|
1
|
+
"use strict";import{installLensmcp as s}from"./lib/auto.js";s();export{installLensmcp,resolveLensmcpWsUrl,resolveLensmcpWsToken}from"./lib/auto.js";
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { installClientRuntime, type InstallOptions } from './lib/install.js';
|
|
2
|
-
export { installLensmcp, resolveLensmcpWsUrl, type AutoInstallOptions, } from './lib/auto.js';
|
|
2
|
+
export { installLensmcp, resolveLensmcpWsUrl, resolveLensmcpWsToken, type AutoInstallOptions, } from './lib/auto.js';
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";export{installClientRuntime}from"./lib/install.js";export{installLensmcp,resolveLensmcpWsUrl}from"./lib/auto.js";
|
|
1
|
+
"use strict";export{installClientRuntime}from"./lib/install.js";export{installLensmcp,resolveLensmcpWsUrl,resolveLensmcpWsToken}from"./lib/auto.js";
|
package/lib/auto.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export interface AutoInstallOptions {
|
|
2
2
|
/** Full WS URL override. Wins over every other resolution source. */
|
|
3
3
|
wsUrl?: string;
|
|
4
|
+
/** Bridge token override. Wins over `__LENSMCP_WS_TOKEN__` and `<meta name="lensmcp-ws-token">`. */
|
|
5
|
+
wsToken?: string;
|
|
4
6
|
/** Reconnect interval after a previously-good connection drops. */
|
|
5
7
|
reconnectIntervalMs?: number;
|
|
6
8
|
}
|
|
7
9
|
/** Resolve the bridge WebSocket URL from the runtime environment. */
|
|
8
10
|
export declare function resolveLensmcpWsUrl(override?: string): string;
|
|
11
|
+
/** Resolve the bridge token, if the page was given one: argument → global → `<meta>`. */
|
|
12
|
+
export declare function resolveLensmcpWsToken(override?: string): string | undefined;
|
|
9
13
|
/**
|
|
10
14
|
* Resolve the bridge WS endpoint and install the capture layer. The no-build
|
|
11
15
|
* seam: any app can call this (or `import '@lensmcp/client-runtime/auto'`)
|
package/lib/auto.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var o=(t,e)=>a(t,"name",{value:e,configurable:!0});var _=Object.defineProperty,s=o((t,e)=>_(t,"name",{value:e,configurable:!0}),"o");import{installClientRuntime as p}from"./install.js";const f=5747,m="127.0.0.1";export function resolveLensmcpWsUrl(t){if(t)return t;const e=globalThis,n=e.__LENSMCP_WS_URL__;if(typeof n=="string"&&n.length>0)return n;const i=r("lensmcp-ws");if(i)return i;const c=e.__LENSMCP_WS_PORT__,u=typeof c=="number"||typeof c=="string"?String(c):r("lensmcp-ws-port")??String(f),l=e.__LENSMCP_WS_HOST__;return`ws://${typeof l=="string"&&l.length>0?l:r("lensmcp-ws-host")??(typeof location<"u"&&location.hostname?location.hostname:m)}:${u}`}o(resolveLensmcpWsUrl,"resolveLensmcpWsUrl"),s(resolveLensmcpWsUrl,"resolveLensmcpWsUrl");export function resolveLensmcpWsToken(t){if(t)return t;const e=globalThis.__LENSMCP_WS_TOKEN__;return typeof e=="string"&&e.length>0?e:r("lensmcp-ws-token")}o(resolveLensmcpWsToken,"resolveLensmcpWsToken"),s(resolveLensmcpWsToken,"resolveLensmcpWsToken");export function installLensmcp(t={}){if(typeof window>"u")return;const e={wsUrl:resolveLensmcpWsUrl(t.wsUrl)},n=resolveLensmcpWsToken(t.wsToken);n!==void 0&&(e.wsToken=n),t.reconnectIntervalMs!==void 0&&(e.reconnectIntervalMs=t.reconnectIntervalMs),p(e)}o(installLensmcp,"installLensmcp"),s(installLensmcp,"installLensmcp");function r(t){if(!(typeof document>"u"))try{const e=document.querySelector(`meta[name="${t}"]`)?.getAttribute("content");return e&&e.length>0?e:void 0}catch{return}}o(r,"r"),s(r,"readMeta");
|
package/lib/install.d.ts
CHANGED
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
export interface InstallOptions {
|
|
22
22
|
/** WebSocket URL the plugin opened on the dev server. */
|
|
23
23
|
wsUrl: string;
|
|
24
|
+
/**
|
|
25
|
+
* The bridge's token, when it requires one (`LENSMCP_BRIDGE_TOKEN` on a standalone bridge). Sent as
|
|
26
|
+
* `?token=` on the upgrade unless `wsUrl` already carries one.
|
|
27
|
+
*/
|
|
28
|
+
wsToken?: string;
|
|
24
29
|
/** Reconnect interval after a previously-good connection drops. */
|
|
25
30
|
reconnectIntervalMs?: number;
|
|
26
31
|
}
|
package/lib/install.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var O=Object.defineProperty;var u=(
|
|
1
|
+
"use strict";var O=Object.defineProperty;var u=(e,o)=>O(e,"name",{value:o,configurable:!0});var J=Object.defineProperty,a=u((e,o)=>J(e,"name",{value:o,configurable:!0}),"i");const L="__LENSMCP_CLIENT__";export function installClientRuntime(e){if(typeof window>"u"||window[L])return;window[L]=!0;const o=N(e.wsUrl,e.wsToken),d=e.reconnectIntervalMs??1e3;let c=null,S=!1;const w=[];let f=[],m=!1;const v=a(()=>{if(m=!1,!f.length)return;const n=f;if(f=[],c&&c.readyState===1)try{let t=0;for(;t<n.length;){const r=[];let h=0;for(;t<n.length&&r.length<200;){let i=JSON.stringify(n[t]);if(i.length>3e5&&(i=JSON.stringify({kind:"console",level:"warn",at:Date.now(),truncated:!0,args:[`[lensmcp] dropped an oversized ${String(n[t]?.kind)} event (${i.length} chars)`]})),r.length&&h+i.length>3e5)break;r.push(i),h+=i.length+1,t+=1}c.send(r.length===1?r[0]:`{"kind":"batch","at":${Date.now()},"events":[${r.join(",")}]}`)}return}catch{}for(const t of n)w.push(t)},"flushBatch"),s=a(n=>{n.at=Date.now(),f.push(n),m||(m=!0,setTimeout(v,0))},"send");window.addEventListener("pagehide",v);const p=a(()=>{try{c=new WebSocket(o)}catch{setTimeout(p,d);return}c.addEventListener("open",()=>{for(S=!0;w.length;){const n=w.splice(0,200);try{c.send(JSON.stringify(n.length===1?n[0]:{kind:"batch",at:Date.now(),events:n}))}catch{}}s({kind:"ready",userAgent:navigator.userAgent,url:location.href})}),c.addEventListener("close",()=>{S&&setTimeout(p,d)}),c.addEventListener("error",()=>{})},"open");p(),window.__LENSMCP_PUBLISH__=n=>{s({...n,kind:"publish"})},window.addEventListener("error",n=>{const t=n.target;if(t&&t!==window&&t.tagName&&!n.message){s({kind:"resource-error",tagName:t.tagName.toLowerCase(),url:t.currentSrc||t.src||t.href||void 0});return}const r=n.error;s({kind:"error",message:n.message,name:r?.name,stack:g(r?.stack),source:n.filename,lineno:n.lineno,colno:n.colno})},!0),window.addEventListener("unhandledrejection",n=>{const t=n.reason;s({kind:"unhandledrejection",reason:g(E(t)),name:typeof t=="object"&&t?t.name:void 0,stack:typeof t=="object"&&t?g(t.stack):void 0})});const T=["log","info","warn","error","debug"];for(const n of T){const t=console[n];console[n]=function(...r){try{s({kind:"console",level:n,args:r.map(_)})}catch{}t.apply(console,r)}}const j=window.fetch.bind(window);window.fetch=async function(n,t){const r=t?.method??(typeof n=="object"&&n&&"method"in n?n.method:"GET"),h=typeof n=="string"?n:n instanceof URL?n.toString():n.url,i=Date.now();try{const l=await j(n,t);return s({kind:"fetch",method:r,url:h,status:l.status,statusText:l.statusText,ok:l.ok,durationMs:Date.now()-i}),l}catch(l){const b=l;throw s({kind:"fetch",method:r,url:h,error:b.message??String(b),durationMs:Date.now()-i}),l}};const C=history.pushState.bind(history),D=history.replaceState.bind(history),y=a(n=>s({kind:"route",url:location.href,from:n}),"notify");history.pushState=function(...n){const t=location.href,r=C(...n);return y(t),r},history.replaceState=function(...n){const t=location.href,r=D(...n);return y(t),r},window.addEventListener("popstate",()=>y())}u(installClientRuntime,"installClientRuntime"),a(installClientRuntime,"installClientRuntime");function N(e,o){if(!o)return e;try{const d=new URL(e);return d.searchParams.has("token")||d.searchParams.set("token",o),d.toString()}catch{return e}}u(N,"T"),a(N,"withToken");const k=4096;function g(e){return e===void 0||e.length<=k?e:`${e.slice(0,k)}\u2026[lensmcp truncated: ${e.length-k} more chars]`}u(g,"k"),a(g,"clipStack");function E(e){if(e==null)return String(e);if(typeof e=="string")return e;if(typeof e.message=="string"&&e.message)return e.message;try{const o=JSON.stringify(e);if(o&&o!=="{}"&&o!=="null")return o}catch{}return String(e)}u(E,"M"),a(E,"describeReason");function _(e){if(e===null)return null;const o=typeof e;if(o==="string"||o==="number"||o==="boolean")return e;try{return JSON.parse(JSON.stringify(e))}catch{return String(e)}}u(_,"C"),a(_,"safe");
|