@lensmcp/protocol-types 1.23.8 → 1.23.10
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/index.d.ts +1 -0
- package/index.js +1 -1
- package/lib/bounded-clone.js +1 -1
- package/lib/bounded-map.js +1 -1
- package/lib/bounded-writer.js +1 -1
- package/lib/dashboard.d.ts +23 -1
- package/lib/error-dismissal.d.ts +58 -0
- package/lib/error-dismissal.js +1 -0
- package/lib/event.d.ts +2 -0
- package/lib/event.js +1 -1
- package/lib/flood-guard.js +1 -1
- package/lib/producer-health.js +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";export*from"./lib/schema-version.js";export*from"./lib/source-location.js";export*from"./lib/context.js";export*from"./lib/event.js";export*from"./lib/node.js";export*from"./lib/edge.js";export*from"./lib/attributes.js";export*from"./lib/producer-health.js";export*from"./lib/resources.js";export*from"./lib/tokens.js";export*from"./lib/capture-demand.js";export*from"./lib/bounded-clone.js";export*from"./lib/bounded-map.js";export*from"./lib/flood-guard.js";export*from"./lib/dashboard.js";export*from"./lib/ai-content.js";
|
|
1
|
+
"use strict";export*from"./lib/schema-version.js";export*from"./lib/source-location.js";export*from"./lib/context.js";export*from"./lib/event.js";export*from"./lib/node.js";export*from"./lib/edge.js";export*from"./lib/attributes.js";export*from"./lib/producer-health.js";export*from"./lib/resources.js";export*from"./lib/tokens.js";export*from"./lib/capture-demand.js";export*from"./lib/bounded-clone.js";export*from"./lib/bounded-map.js";export*from"./lib/flood-guard.js";export*from"./lib/dashboard.js";export*from"./lib/error-dismissal.js";export*from"./lib/ai-content.js";
|
package/lib/bounded-clone.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var T=Object.defineProperty;var
|
|
1
|
+
"use strict";var T=Object.defineProperty;var c=(t,e)=>T(t,"name",{value:e,configurable:!0});var h=Object.defineProperty,l=c((t,e)=>h(t,"name",{value:e,configurable:!0}),"i"),_=Object.defineProperty,y=l((t,e)=>_(t,"name",{value:e,configurable:!0}),"_");export const DEFAULT_RAW_BYTE_LIMIT=32768,DEFAULT_MAX_STRING_BYTES=4096,DEFAULT_MAX_ARRAY_ITEMS=64,DEFAULT_MAX_DEPTH=12,CHEAP_ENTRY_BYTES=512,NOMINAL_DEEP_BYTES=32,DEEP_REPORT_DEPTH=64,SKELETON_STRING_BYTES=256,MAX_RECORDED_PATHS=20,TRUNCATION_MARKER_KEY="__lensmcpTruncation",TRUNCATED_VALUE_KEY="__lensmcpTruncated";export function estimateJsonBytes(t,e=Number.POSITIVE_INFINITY,n=12){return g(t,e,n,32)}c(estimateJsonBytes,"estimateJsonBytes"),l(estimateJsonBytes,"estimateJsonBytes"),y(estimateJsonBytes,"estimateJsonBytes");export function exceedsJsonByteBudget(t,e,n=12){return g(t,e,n,Number.POSITIVE_INFINITY)>e}c(exceedsJsonByteBudget,"exceedsJsonByteBudget"),l(exceedsJsonByteBudget,"exceedsJsonByteBudget"),y(exceedsJsonByteBudget,"exceedsJsonByteBudget");function g(t,e,n,a){switch(typeof t){case"undefined":case"function":case"symbol":return 0;case"boolean":return 5;case"number":return Number.isFinite(t)?8:4;case"bigint":return 20;case"string":return t.length+2;default:break}if(t===null)return 4;if(n<=0)return a;if(t instanceof Date)return 26;if(Array.isArray(t)){let r=2;for(let u=0;u<t.length;u++)if(r+=g(t[u],e-r,n-1,a)+1,r>e)return r;return r}let s=2;const o=t;for(const r in o){if(!Object.prototype.hasOwnProperty.call(o,r))continue;const u=g(o[r],e-s,n-1,a);if(u!==0&&(s+=r.length+4+u,s>e))return s}return s}c(g,"y"),l(g,"T"),y(g,"walk");function f(t,e){t.truncatedAnything=!0,t.paths.length<20&&t.paths.push(e||"<root>")}c(f,"g"),l(f,"A"),y(f,"record");function p(t,e,n){return f(t,n),{[TRUNCATED_VALUE_KEY]:!0,originalBytes:estimateJsonBytes(e,Number.POSITIVE_INFINITY,64)}}c(p,"f"),l(p,"I"),y(p,"stub");function m(t){if(t===null)return!0;const e=typeof t;return e==="number"||e==="boolean"||e==="string"||e==="bigint"}c(m,"p"),l(m,"y"),y(m,"isScalar");export function clampValue(t,e,n,a){if(typeof t=="string"){const s=e.budget<=0?256:e.maxStringBytes;if(t.length+2<=s)return e.budget-=t.length+2,t;const o=Math.max(0,s-64);return f(e,a),e.budget-=o,`${t.slice(0,o)}\u2026[lensmcp truncated: ${t.length-o} more chars]`}return t===null||typeof t!="object"?(e.budget-=g(t,Number.POSITIVE_INFINITY,1,32),t):n<=0?p(e,t,a):t instanceof Date?(e.budget-=26,t):Array.isArray(t)?b(t,e,n,a):d(t,e,n,a)}c(clampValue,"clampValue"),l(clampValue,"clampValue"),y(clampValue,"clampValue");function b(t,e,n,a){const s=[],o=Math.min(t.length,e.maxArrayItems);for(let r=0;r<o&&!(e.budget<=0);r++)s.push(clampValue(t[r],e,n-1,`${a}[${r}]`));return s.length<t.length&&f(e,`${a}[] (+${t.length-s.length} items dropped)`),s}c(b,"m"),l(b,"f"),y(b,"clampArray");function d(t,e,n,a){const s={};let o;const r=e.budget<=0;for(const u in t){if(!Object.prototype.hasOwnProperty.call(t,u))continue;const i=t[u],I=g(i,512,n-1,Number.POSITIVE_INFINITY);if(I<=512&&(!r||m(i))){s[u]=i,e.budget-=u.length+4+I;continue}(o??=[]).push({key:u,bytes:I})}if(!o)return s;o.sort((u,i)=>u.bytes===i.bytes?0:u.bytes<i.bytes?-1:1);for(const{key:u}of o){const i=a?`${a}.${u}`:u;s[u]=clampValue(t[u],e,n-1,i)}return s}c(d,"b"),l(d,"m"),y(d,"clampObject");export function boundedClone(t,e={}){const n=e.rawByteLimit??32768,a=e.maxDepth??12;if(n<=0)return{value:void 0,truncated:!1,originalBytes:0,keptBytes:0,paths:[]};if(t==null)return{value:t,truncated:!1,originalBytes:0,keptBytes:0,paths:[]};if(!exceedsJsonByteBudget(t,n,a)){const i=estimateJsonBytes(t,n,a),I={budget:n,maxStringBytes:e.maxStringBytes??4096,maxArrayItems:e.maxArrayItems??64,paths:[],truncatedAnything:!1};return{value:clampValue(t,I,a,""),truncated:!1,originalBytes:i,keptBytes:i,paths:[]}}const s=estimateJsonBytes(t,Number.POSITIVE_INFINITY,64),o={budget:n,maxStringBytes:e.maxStringBytes??4096,maxArrayItems:e.maxArrayItems??64,paths:[],truncatedAnything:!1},r=clampValue(t,o,a,""),u=estimateJsonBytes(r,Number.POSITIVE_INFINITY,a);if(o.truncatedAnything&&r!==null&&typeof r=="object"&&!Array.isArray(r)){const i={truncated:!0,originalBytes:s,keptBytes:u,paths:o.paths};r[TRUNCATION_MARKER_KEY]=i}return{value:r,truncated:o.truncatedAnything,originalBytes:s,keptBytes:u,paths:o.paths}}c(boundedClone,"boundedClone"),l(boundedClone,"boundedClone"),y(boundedClone,"boundedClone");
|
package/lib/bounded-map.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var t=(e,a)=>i(e,"name",{value:a,configurable:!0});var p=Object.defineProperty,o=t((e,a)=>p(e,"name",{value:a,configurable:!0}),"t"),s=Object.defineProperty,u=o((e,a)=>s(e,"name",{value:a,configurable:!0}),"o");export function capMap(e,a){if(e.size<=a)return 0;let r=0;const c=e.keys();for(;e.size>a;){const n=c.next();if(n.done)break;e.delete(n.value)&&(r+=1)}return r}t(capMap,"capMap"),o(capMap,"capMap"),u(capMap,"capMap");export const MAX_PRODUCER_KEYS=256;
|
package/lib/bounded-writer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var r=(t,e)=>m(t,"name",{value:e,configurable:!0});var f=Object.defineProperty,o=r((t,e)=>f(t,"name",{value:e,configurable:!0}),"r"),x=Object.defineProperty,s=o((t,e)=>x(t,"name",{value:e,configurable:!0}),"c");import{renameSync as v,statSync as M,unlinkSync as E}from"node:fs";export function eventMaxBytes(t=process.env){const e=Number(t.LENSMCP_EVENT_MAX_BYTES);return Number.isFinite(e)&&e>0?e:50*1024*1024}r(eventMaxBytes,"eventMaxBytes"),o(eventMaxBytes,"eventMaxBytes"),s(eventMaxBytes,"eventMaxBytes");export function eventMaxFiles(t=process.env){const e=Number(t.LENSMCP_EVENT_MAX_FILES);return Number.isFinite(e)&&e>=1&&e<=20?Math.floor(e):5}r(eventMaxFiles,"eventMaxFiles"),o(eventMaxFiles,"eventMaxFiles"),s(eventMaxFiles,"eventMaxFiles");const b=1024*1024,a=new Map;export function maybeRotateEventFile(t,e,c){const i=(a.get(t)??0)+e,l=c?.maxBytes??eventMaxBytes(),u=c?.maxFiles??eventMaxFiles(),y=Math.min(b,l);if(i<y){a.set(t,i);return}try{const n=M(t).size;if(a.set(t,0),n<=l)return}catch{a.set(t,i);return}try{E(`${t}.${u}`)}catch{}for(let n=u-1;n>=1;n--)try{v(`${t}.${n}`,`${t}.${n+1}`)}catch{}try{v(t,`${t}.1`)}catch{}}r(maybeRotateEventFile,"maybeRotateEventFile"),o(maybeRotateEventFile,"maybeRotateEventFile"),s(maybeRotateEventFile,"maybeRotateEventFile");export function resetRotationThrottle(t){t===void 0?a.clear():a.delete(t)}r(resetRotationThrottle,"resetRotationThrottle"),o(resetRotationThrottle,"resetRotationThrottle"),s(resetRotationThrottle,"resetRotationThrottle");
|
package/lib/dashboard.d.ts
CHANGED
|
@@ -109,6 +109,10 @@ export interface DashService {
|
|
|
109
109
|
lastColdStartMs?: number;
|
|
110
110
|
restarts: number;
|
|
111
111
|
buildFailed: boolean;
|
|
112
|
+
/** It printed a process error (`EADDRINUSE`, an unhandled `'error'` event) — not a build that failed. */
|
|
113
|
+
processError: boolean;
|
|
114
|
+
/** Its type check fails and nothing but the pod's own output says so. The bundle built; it still serves. */
|
|
115
|
+
typeErrors: boolean;
|
|
112
116
|
/** Last build/runtime error lines the gateway saw from this service's pod output. */
|
|
113
117
|
errorLines: string[];
|
|
114
118
|
auth?: {
|
|
@@ -499,8 +503,9 @@ export interface DashDiagnostics {
|
|
|
499
503
|
* queue — a background job failed
|
|
500
504
|
* log — an error-level log line no request explains
|
|
501
505
|
* build / typecheck / service — the code or a service is broken right now (standing, not events)
|
|
506
|
+
* lint — ESLint errors as of its last run (nothing re-lints on save, so dated, not "now")
|
|
502
507
|
*/
|
|
503
|
-
export type DashErrorKind = 'server' | 'exception' | 'request' | 'browser' | 'external' | 'queue' | 'log' | 'build' | 'typecheck' | 'service';
|
|
508
|
+
export type DashErrorKind = 'server' | 'exception' | 'request' | 'browser' | 'external' | 'queue' | 'log' | 'build' | 'typecheck' | 'lint' | 'service';
|
|
504
509
|
export interface DashErrorOccurrence {
|
|
505
510
|
/** The primary event's id. */
|
|
506
511
|
id: string;
|
|
@@ -539,15 +544,32 @@ export interface DashErrorGroup {
|
|
|
539
544
|
ongoing?: boolean;
|
|
540
545
|
/** The resource this came from, for the Raw drawer. */
|
|
541
546
|
resource?: string;
|
|
547
|
+
/** When it was dismissed. Only on the groups in `DashErrors.dismissed`. */
|
|
548
|
+
dismissedAt?: number;
|
|
549
|
+
/** Who dismissed it — a person here, a person at the CLI, or an agent — and the reason they gave. */
|
|
550
|
+
dismissedBy?: 'dashboard' | 'cli' | 'agent';
|
|
551
|
+
dismissedReason?: string;
|
|
542
552
|
}
|
|
543
553
|
export interface DashErrors {
|
|
544
554
|
at: number;
|
|
545
555
|
/** What "recent" means below (ms). */
|
|
546
556
|
recentMs: number;
|
|
557
|
+
/** What is shown. A dismissed group is NOT here until it happens again. */
|
|
547
558
|
groups: DashErrorGroup[];
|
|
548
559
|
/** Groups seen within `recentMs` (plus ongoing ones). */
|
|
549
560
|
recentGroups: number;
|
|
550
561
|
recentOccurrences: number;
|
|
562
|
+
/** Hidden by hand, and still hidden: nothing of them has been seen since. Listed so they can be restored. */
|
|
563
|
+
dismissed: DashErrorGroup[];
|
|
564
|
+
}
|
|
565
|
+
/** `POST /api/errors/dismiss` and `/api/errors/restore` — the body, and the answer. */
|
|
566
|
+
export interface DashErrorIds {
|
|
567
|
+
/** `DashErrorGroup.id`s. Ones the dashboard does not hold are ignored. */
|
|
568
|
+
ids: string[];
|
|
569
|
+
}
|
|
570
|
+
export interface DashErrorIdsResult {
|
|
571
|
+
/** How many of them were written to the bus. */
|
|
572
|
+
count: number;
|
|
551
573
|
}
|
|
552
574
|
export interface DashResourceEntry {
|
|
553
575
|
uri: string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BaseEvent } from './event.js';
|
|
2
|
+
/**
|
|
3
|
+
* A person hid an error by hand — and what that is allowed to mean.
|
|
4
|
+
*
|
|
5
|
+
* The lens had no way to do it: an error left the list when it aged out of the window, or when
|
|
6
|
+
* its pod restarted, and not before. A row that was already understood — the 401 a signed-out
|
|
7
|
+
* capture browser caused, a stderr notice — stayed for as long as it took.
|
|
8
|
+
*
|
|
9
|
+
* A dismissal is an EVENT ON THE BUS, not a list in one process. The dashboard and the MCP server
|
|
10
|
+
* are separate processes that each fold the same file, so this is the one place both read: the
|
|
11
|
+
* dashboard hides the row, `runtime://errors` takes back the entries behind it, and a restart of
|
|
12
|
+
* either replays it in order with the errors it was about. It rotates out with them.
|
|
13
|
+
*
|
|
14
|
+
* Two rules keep it from becoming a way to stop seeing failures:
|
|
15
|
+
*
|
|
16
|
+
* - **It covers the past.** `until` is a moment; an occurrence after it brings the error back.
|
|
17
|
+
* The reader clamps `until` to the dismissal's own timestamp, so no event can dismiss ahead.
|
|
18
|
+
* - **It is undone the same way** (`error-restored`), and what is hidden is still listed.
|
|
19
|
+
*
|
|
20
|
+
* WHO may write one: a person in the dashboard, a person at the CLI, and an agent through
|
|
21
|
+
* `observe.dismiss_errors`. The last two name EVENTS, not a dashboard row, and must say why —
|
|
22
|
+
* `by` and `reason` travel with the dismissal and are shown wherever it is listed, so a status
|
|
23
|
+
* that went quiet because an agent dismissed something says exactly that.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ERROR_DISMISSED = "error-dismissed";
|
|
26
|
+
export declare const ERROR_RESTORED = "error-restored";
|
|
27
|
+
/** The `source` of an event the lens wrote about itself, rather than observed. */
|
|
28
|
+
export declare const LENS_EVENT_SOURCE = "lens";
|
|
29
|
+
/** An event carries at most this many of the group's event ids — the size of the largest list they are matched against. */
|
|
30
|
+
export declare const MAX_DISMISSAL_EVENT_IDS = 200;
|
|
31
|
+
export declare const MAX_DISMISSAL_REASON_CHARS = 500;
|
|
32
|
+
/** Who dismissed: a person in the dashboard, a person at the CLI, or an agent through the MCP tool. */
|
|
33
|
+
export type DismissedBy = 'dashboard' | 'cli' | 'agent';
|
|
34
|
+
export interface ErrorDismissal {
|
|
35
|
+
kind: typeof ERROR_DISMISSED;
|
|
36
|
+
/** `DashErrorGroup.id` — the dashboard's signature for "the same error". */
|
|
37
|
+
groupId: string;
|
|
38
|
+
/** Occurrences up to this moment are dismissed. One seen later brings the error back. */
|
|
39
|
+
until: number;
|
|
40
|
+
/** The bus events behind the occurrences the dashboard held — what a list keyed by event takes back. */
|
|
41
|
+
eventIds: string[];
|
|
42
|
+
by?: DismissedBy;
|
|
43
|
+
/** Why it is not a problem, in the dismisser's words. Required of an agent and of the CLI. */
|
|
44
|
+
reason?: string;
|
|
45
|
+
/** What was dismissed, for a list of dismissals that no longer holds the error itself. */
|
|
46
|
+
title?: string;
|
|
47
|
+
}
|
|
48
|
+
/** A dismissal before it is an event: what a writer hands to `dismissalEvent`. */
|
|
49
|
+
export type ErrorDismissalDraft = Omit<ErrorDismissal, 'kind'>;
|
|
50
|
+
export interface ErrorRestoral {
|
|
51
|
+
kind: typeof ERROR_RESTORED;
|
|
52
|
+
groupId: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read a dismissal or its undo out of a bus event, or nothing. Total: the bus is a file any local
|
|
56
|
+
* process appends to, so every field is checked and a shape that is nearly right is not one.
|
|
57
|
+
*/
|
|
58
|
+
export declare function readErrorDismissal(event: Pick<BaseEvent, 'source' | 'timestamp' | 'raw'>): ErrorDismissal | ErrorRestoral | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var E=Object.defineProperty;var s=(e,r)=>E(e,"name",{value:r,configurable:!0});var m=Object.defineProperty,c=s((e,r)=>m(e,"name",{value:r,configurable:!0}),"s"),p=Object.defineProperty,l=c((e,r)=>p(e,"name",{value:r,configurable:!0}),"s");export const ERROR_DISMISSED="error-dismissed",ERROR_RESTORED="error-restored",LENS_EVENT_SOURCE="lens",MAX_DISMISSAL_EVENT_IDS=200;const y=2048;export const MAX_DISMISSAL_REASON_CHARS=500;const b=300,I=new Set(["dashboard","cli","agent"]);export function readErrorDismissal(e){if(e.source!==LENS_EVENT_SOURCE||!e.raw||typeof e.raw!="object")return;const r=e.raw,i=r.groupId;if(typeof i!="string"||i.length===0||i.length>2048)return;if(r.kind===ERROR_RESTORED)return{kind:ERROR_RESTORED,groupId:i};if(r.kind!==ERROR_DISMISSED)return;const n=r.until;if(typeof n!="number"||!Number.isFinite(n))return;const f=Array.isArray(r.eventIds)?r.eventIds.filter(t=>typeof t=="string"&&t.length>0).slice(0,200):[],o=I.has(r.by)?r.by:void 0,a=l((t,S)=>typeof t=="string"&&t.trim()?t.trim().slice(0,S):void 0,"text"),d=a(r.reason,500),u=a(r.title,300);return{kind:ERROR_DISMISSED,groupId:i,until:Math.min(n,e.timestamp),eventIds:f,...o?{by:o}:{},...d?{reason:d}:{},...u?{title:u}:{}}}s(readErrorDismissal,"readErrorDismissal"),c(readErrorDismissal,"readErrorDismissal"),l(readErrorDismissal,"readErrorDismissal");
|
package/lib/event.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare const EventSourceSchema: z.ZodEnum<{
|
|
|
21
21
|
gateway: "gateway";
|
|
22
22
|
external: "external";
|
|
23
23
|
ai: "ai";
|
|
24
|
+
lens: "lens";
|
|
24
25
|
}>;
|
|
25
26
|
export type EventSource = z.infer<typeof EventSourceSchema>;
|
|
26
27
|
export declare const EventCategorySchema: z.ZodEnum<{
|
|
@@ -78,6 +79,7 @@ export declare const BaseEventSchema: z.ZodObject<{
|
|
|
78
79
|
gateway: "gateway";
|
|
79
80
|
external: "external";
|
|
80
81
|
ai: "ai";
|
|
82
|
+
lens: "lens";
|
|
81
83
|
}>;
|
|
82
84
|
category: z.ZodEnum<{
|
|
83
85
|
db: "db";
|
package/lib/event.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{z as e}from"zod";import{SourceLocationSchema as t}from"./source-location.js";import{TraceContextSchema as r}from"./context.js";export const EventSourceSchema=e.enum(["nx","vite","typescript","eslint","rollup","client-runtime","chrome","react","valtio","nestjs","nextjs","db","redis","queue","memory","visual","perf","security","gateway","external","ai"]),EventCategorySchema=e.enum(["build","lint","typecheck","test","runtime","render","visual","trace","state","network","backend","db","memory","performance","security","deps","cluster","ai"]),SeveritySchema=e.enum(["debug","info","warning","error","fatal"]),BaseEventSchema=e.object({id:e.string(),sessionId:e.string(),timestamp:e.number().int().nonnegative(),source:EventSourceSchema,category:EventCategorySchema,severity:SeveritySchema,context:r,fingerprint:e.string(),title:e.string(),message:e.string().optional(),location:t.optional(),relatedFiles:e.array(e.string()).optional(),relatedUrls:e.array(e.string()).optional(),raw:e.unknown().optional()});
|
|
1
|
+
"use strict";import{z as e}from"zod";import{SourceLocationSchema as t}from"./source-location.js";import{TraceContextSchema as r}from"./context.js";export const EventSourceSchema=e.enum(["nx","vite","typescript","eslint","rollup","client-runtime","chrome","react","valtio","nestjs","nextjs","db","redis","queue","memory","visual","perf","security","gateway","external","ai","lens"]),EventCategorySchema=e.enum(["build","lint","typecheck","test","runtime","render","visual","trace","state","network","backend","db","memory","performance","security","deps","cluster","ai"]),SeveritySchema=e.enum(["debug","info","warning","error","fatal"]),BaseEventSchema=e.object({id:e.string(),sessionId:e.string(),timestamp:e.number().int().nonnegative(),source:EventSourceSchema,category:EventCategorySchema,severity:SeveritySchema,context:r,fingerprint:e.string(),title:e.string(),message:e.string().optional(),location:t.optional(),relatedFiles:e.array(e.string()).optional(),relatedUrls:e.array(e.string()).optional(),raw:e.unknown().optional()});
|
package/lib/flood-guard.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var S=Object.defineProperty;var i=(t,s)=>S(t,"name",{value:s,configurable:!0});var A=Object.defineProperty,f=i((t,s)=>A(t,"name",{value:s,configurable:!0}),"i"),k=Object.defineProperty,u=f((t,s)=>k(t,"name",{value:s,configurable:!0}),"o");function l(){const t=typeof process<"u"?process.env?.LENSMCP_EVENT_MAX_EPS:void 0;if(t===void 0||t==="")return;if(t==="off")return"off";const s=Number(t);if(Number.isFinite(s))return s<=0?"off":s}i(l,"p"),f(l,"S"),u(l,"envPerSec");export function createEventFloodGuard(t){const s=l();if(s==="off")return{admit:u(()=>({ok:!0,suppressed:0}),"admit")};const c=s??t?.perSec??5,d=Math.max(1,t?.burst??Math.max(30,c*4)),p=t?.maxKeys??2048,n=new Map,v=u(o=>{for(const[r,e]of n)o-e.lastSeenAt>6e4&&n.delete(r);if(n.size>p){const r=[...n.entries()].sort((e,a)=>e[1].lastSeenAt-a[1].lastSeenAt);for(let e=0;e<r.length>>1;e++)n.delete(r[e][0])}},"evictStale");return{admit(o){const r=Date.now();let e=n.get(o);e||(n.size>=p&&v(r),e={tokens:d,lastRefillAt:r,suppressed:0,lastSeenAt:r},n.set(o,e)),e.lastSeenAt=r;const a=r-e.lastRefillAt;if(a>0&&(e.tokens=Math.min(d,e.tokens+a/1e3*c),e.lastRefillAt=r),e.tokens>=1){e.tokens-=1;const m=e.suppressed;return e.suppressed=0,{ok:!0,suppressed:m}}return e.suppressed+=1,{ok:!1,suppressed:0}}}}i(createEventFloodGuard,"createEventFloodGuard"),f(createEventFloodGuard,"createEventFloodGuard"),u(createEventFloodGuard,"createEventFloodGuard");
|
package/lib/producer-health.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var R=Object.defineProperty;var i=(e,o)=>R(e,"name",{value:o,configurable:!0});var $=Object.defineProperty,d=i((e,o)=>$(e,"name",{value:o,configurable:!0}),"i"),b=Object.defineProperty,m=d((e,o)=>b(e,"name",{value:o,configurable:!0}),"u");import{z as r}from"zod";export const ProducerStateSchema=r.enum(["none","connected"]),ProducerRunStatusSchema=r.enum(["running","clean","failing","error"]),ProducerReportSchema=r.object({id:r.string(),tool:r.string(),project:r.string().optional(),firstReportedAt:r.number().int().nonnegative(),lastReportedAt:r.number().int().nonnegative(),lastRunStatus:ProducerRunStatusSchema,lastRunDurationMs:r.number().int().nonnegative().optional(),errorCount:r.number().int().nonnegative(),warningCount:r.number().int().nonnegative().optional(),error:r.string().optional()}),ProducerHealthSchema=r.object({producer:ProducerStateSchema,producers:r.array(ProducerReportSchema),lastReportedAt:r.number().int().nonnegative().optional(),ageMs:r.number().int().nonnegative().optional(),stale:r.boolean(),detail:r.string()}),PRODUCER_STALE_AFTER_MS=10*6e4;export function summariseProducers(e){const o=e.now??Date.now(),t=[...e.producers].sort((n,h)=>h.lastReportedAt-n.lastReportedAt);if(t.length===0)return{producer:"none",producers:[],stale:!1,detail:`No ${e.domain} producer has ever reported into this session \u2014 this is NOT a clean result, nothing is watching. ${e.noProducerHint}`};const l=t[0].lastReportedAt,u=Math.max(0,o-l),p=u>PRODUCER_STALE_AFTER_MS,g=t.filter(n=>n.lastRunStatus==="failing"),s=t.filter(n=>n.lastRunStatus==="error"),a=[`${t.length} ${e.domain} producer${t.length===1?"":"s"} reporting (${t.map(n=>n.id).join(", ")}); newest report ${c(u)}.`];return s.length>0&&a.push(`${s.length} produced NO verdict (the tool itself failed): ${s.map(n=>`${n.id} \u2014 ${n.error??"unknown error"}`).join("; ")}.`),g.length>0&&a.push(`${g.length} reporting errors.`),p&&a.push(`Older than ${Math.round(PRODUCER_STALE_AFTER_MS/6e4)}m \u2014 the verdict may predate the current source.`),{producer:"connected",producers:t,lastReportedAt:l,ageMs:u,stale:p,detail:a.join(" ")}}i(summariseProducers,"summariseProducers"),d(summariseProducers,"summariseProducers"),m(summariseProducers,"summariseProducers");function c(e){return e<1e3?"just now":e<6e4?`${Math.round(e/1e3)}s ago`:e<36e5?`${Math.round(e/6e4)}m ago`:`${Math.round(e/36e5)}h ago`}i(c,"g"),d(c,"g"),m(c,"describeAge");
|