@lensmcp/core 1.26.6 → 1.26.8
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/flow-categories.d.ts +1 -1
- package/lib/flow-categories.js +1 -1
- package/lib/lens-events.d.ts +6 -1
- package/lib/lens-events.js +2 -2
- package/package.json +2 -2
package/lib/flow-categories.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* Pure. Takes the flow's events and its `segmentFlow` result; never reads anything else.
|
|
18
18
|
*/
|
|
19
|
-
import type
|
|
19
|
+
import { type BaseEvent } from '@lensmcp/protocol-types';
|
|
20
20
|
import type { FlowSegment, FlowSegmentation } from './flow-segments.js';
|
|
21
21
|
export type BuiltinCategory = 'page-load' | 'user-action' | 'navigation' | 'api' | 'background' | 'ai' | 'system' | 'test' | 'other';
|
|
22
22
|
/** The order groups are shown in: what a person is most likely looking for first. */
|
package/lib/flow-categories.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var T=Object.defineProperty;var c=(e,t)=>T(e,"name",{value:t,configurable:!0});var M=Object.defineProperty,s=c((e,t)=>M(e,"name",{value:t,configurable:!0}),"s");import{TEST_FLOW_ID as F}from"@lensmcp/protocol-types";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 S=s(e=>/^[A-Z]+ /.test(e),"hasMethod");function w(e,t){return t.some(o=>o.route?S(e)?globMatch(e,`${o.method??"GET"} ${o.route}`):globMatch(e,o.route):!1)}c(w,"O"),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 I(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(I,"j"),s(I,"originOf");const E=s((e,t)=>F.test(e)||t!==void 0&&/^(ui:)?(tools|scripts?|e2e)\//.test(t),"isTestFlow"),$={"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"},_=new Set(["page-load","user-action","navigation"]),z=/^[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=>z.test(t)||/^[0-9a-f]{16,}$/i.test(t)||/^\d{2,}$/.test(t)?":id":t).join("/")}c(templatePath,"templatePath"),s(templatePath,"templatePath");function x(e){const t=/^ui:(?:.*\/)?([^/:]+?)(?:\.[a-z]+)?:\d+:([A-Za-z]+)$/.exec(e);return t?`${t[1]} \xB7 ${t[2]}`:e}c(x,"q"),s(x,"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&&$[t.type]==="user-action"&&r)return x(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 A=10,B=1e3,N=3,R=500,C=1e3;function O(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>=A&&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(O,"G"),s(O,"tagsOf");export function classifyFlow(e,t,o=[]){const n=I(e),r={flowId:t.flowId,origin:n,segments:t.segments},i=O(e,t),u=s((d,q,b)=>{const h=j(d,n,t,e);return{category:d,decidedBy:q,...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(E(t.flowId,n.nodeId))return u("test","test");const l=n.type?$[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"&&_.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");
|
package/lib/lens-events.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BaseEvent, type ContainerOomEvent, type DockerEngineLostEvent, type ErrorDismissalDraft, type ExpectedFailureRule, type ExpectedRuleAuthor, type MetricsChange } from '@lensmcp/protocol-types';
|
|
1
|
+
import { type BaseEvent, type ContainerOomEvent, type DockerEngineLostEvent, type ErrorDismissalDraft, type ExpectedFailureRule, type ExpectedRuleAuthor, type MetricsChange, type TestRunRecord, type VerdictOverride } from '@lensmcp/protocol-types';
|
|
2
2
|
/**
|
|
3
3
|
* Events the lens writes about itself — a dismissed error and its undo, a standing rule that expects a failure and its
|
|
4
4
|
* removal, a reset of a catalog's numbers and its undo — and about the Docker work it runs (a container killed for
|
|
@@ -44,6 +44,11 @@ export declare function containerOomEvent(kill: Omit<ContainerOomEvent, 'kind'>,
|
|
|
44
44
|
* The fingerprint is the VM: the context — and, for a worker's engine told on this Mac's bus (slice D16), the worker.
|
|
45
45
|
*/
|
|
46
46
|
export declare function dockerEngineLostEvent(lost: Omit<DockerEngineLostEvent, 'kind'>, sessionId: string, at: number): BaseEvent;
|
|
47
|
+
/** «This is a bug» over the lens's verdict on one group (overseer-105) — its cause and its events, so every list finds it. */
|
|
48
|
+
export declare function verdictOverrideEvent(o: Omit<VerdictOverride, 'kind'>, sessionId: string): BaseEvent;
|
|
49
|
+
export declare function verdictClearedEvent(groupId: string, causeId: string | undefined, sessionId: string, at: number): BaseEvent;
|
|
50
|
+
/** A test or e2e run's state (overseer-105): the flow scope its requests carry, and whether it passed. One bucket per run. */
|
|
51
|
+
export declare function testRunEvent(run: Omit<TestRunRecord, 'at'>, sessionId: string, at: number): BaseEvent;
|
|
47
52
|
/**
|
|
48
53
|
* Append events to the bus file. Throws when the write fails: the caller is answering a person or
|
|
49
54
|
* an agent, and "dismissed" must not be a guess.
|
package/lib/lens-events.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var
|
|
2
|
-
`).join("")))}
|
|
1
|
+
"use strict";var f=Object.defineProperty;var n=(e,t)=>f(e,"name",{value:t,configurable:!0});var y=Object.defineProperty,s=n((e,t)=>y(e,"name",{value:t,configurable:!0}),"r");import{appendFileSync as g,closeSync as _,mkdirSync as k,openSync as b,renameSync as O,statSync as T,unlinkSync as N}from"node:fs";import{dirname as C,join as h}from"node:path";import{CONTAINER_OOM as c,DOCKER_ENGINE_LOST as E,ERROR_DISMISSED as u,ERROR_RESTORED as p,ERROR_VERDICT_CLEARED as v,ERROR_VERDICT_SET as l,EXPECTED_RULE_REMOVED as m,EXPECTED_RULE_SET as R,LENS_EVENT_SOURCE as I,METRICS_RESET as L,TEST_RUN as $,describeExpectedMatch as M,dockerErrorWords as D,metricsIdBatches as A,readDockerError as B}from"@lensmcp/protocol-types";import{rotateBusFile as F}from"./bus-rotation.js";import{ulid as x}from"./ulid.js";export function lensEventFile(e=process.env,t=process.cwd()){return e.LENSMCP_EVENT_FILE??h(t,".lensmcp","events.jsonl")}n(lensEventFile,"lensEventFile"),s(lensEventFile,"lensEventFile");const a=s((e,t,r,o,i)=>({id:x(),sessionId:e,timestamp:t,source:I,category:"runtime",severity:"info",context:{sessionId:e},fingerprint:r,title:o,raw:i}),"lensEvent");export function dismissalEvent(e,t){return a(t,e.until,`${u}:${e.groupId}`,`error dismissed: ${e.title??e.groupId}`,{kind:u,groupId:e.groupId,until:e.until,eventIds:e.eventIds,...e.by?{by:e.by}:{},...e.reason?{reason:e.reason}:{},...e.title?{title:e.title}:{}})}n(dismissalEvent,"dismissalEvent"),s(dismissalEvent,"dismissalEvent");export function restoralEvent(e,t,r){return a(t,r,`${p}:${e}`,"error restored",{kind:p,groupId:e})}n(restoralEvent,"restoralEvent"),s(restoralEvent,"restoralEvent");export function expectedRuleEvent(e,t){return a(t,e.createdAt,`${R}:${e.id}`,`failure expected: ${e.title??M(e.match)}`,{kind:R,id:e.id,match:e.match,reason:e.reason,by:e.by,createdAt:e.createdAt,...e.expiresAt!==void 0?{expiresAt:e.expiresAt}:{},...e.title?{title:e.title}:{}})}n(expectedRuleEvent,"expectedRuleEvent"),s(expectedRuleEvent,"expectedRuleEvent");export function expectedRuleRemovedEvent(e,t,r,o){return a(r,o,`${m}:${e}`,"failure no longer expected",{kind:m,id:e,by:t})}n(expectedRuleRemovedEvent,"expectedRuleRemovedEvent"),s(expectedRuleRemovedEvent,"expectedRuleRemovedEvent");export function metricsChangeEvents(e,t,r){const o=e.kind===L;return(e.ids?A(e.ids):[void 0]).map(i=>a(t,r,`${e.kind}:${e.scope}`,`${o?"numbers reset":"numbers counted whole again"}: ${e.scope}${i?` \xB7 ${i.length}`:" \xB7 all"}`,{kind:e.kind,scope:e.scope,...o?{at:r}:{},...i?{ids:i}:{}}))}n(metricsChangeEvents,"metricsChangeEvents"),s(metricsChangeEvents,"metricsChangeEvents");function d(e,t,r,o){const i=D(B(e));return{id:x(),sessionId:r,timestamp:Math.max(0,Math.floor(o)),source:I,category:"cluster",severity:"error",context:{sessionId:r},fingerprint:t,title:i.title,message:i.facts,raw:e}}n(d,"_"),s(d,"dockerErrorEvent");export function containerOomEvent(e,t,r){return d({kind:c,...e},`${c}:${e.job}:${e.service}`,t,r)}n(containerOomEvent,"containerOomEvent"),s(containerOomEvent,"containerOomEvent");export function dockerEngineLostEvent(e,t,r){return d({kind:E,...e},`${E}:${e.context??""}${e.host?`@${e.host.peer}`:""}`,t,r)}n(dockerEngineLostEvent,"dockerEngineLostEvent"),s(dockerEngineLostEvent,"dockerEngineLostEvent");export function verdictOverrideEvent(e,t){return a(t,e.at,`${l}:${e.groupId}`,"error marked a bug",{kind:l,verdict:"bug",groupId:e.groupId,...e.causeId?{causeId:e.causeId}:{},eventIds:e.eventIds,...e.by?{by:e.by}:{}})}n(verdictOverrideEvent,"verdictOverrideEvent"),s(verdictOverrideEvent,"verdictOverrideEvent");export function verdictClearedEvent(e,t,r,o){return a(r,o,`${v}:${e}`,"error verdict back to the lens",{kind:v,groupId:e,...t?{causeId:t}:{}})}n(verdictClearedEvent,"verdictClearedEvent"),s(verdictClearedEvent,"verdictClearedEvent");export function testRunEvent(e,t,r){return a(t,r,`${$}:${e.runId}`,`test run ${e.runId} ${e.state}`,{kind:$,...e})}n(testRunEvent,"testRunEvent"),s(testRunEvent,"testRunEvent");const S=s((e,t,r)=>{const o=Number(process.env[e]);return Number.isFinite(o)&&r(o)?o:t},"envNumber");export function appendBusEvents(e,t){t.length!==0&&(k(C(e),{recursive:!0}),F(e,{maxBytes:S("LENSMCP_EVENT_MAX_BYTES",50*1024*1024,r=>r>0),maxFiles:S("LENSMCP_EVENT_MAX_FILES",5,r=>r>=1&&r<=20),fs:{statSync:T,renameSync:O,unlinkSync:N,openSync:b,closeSync:_}}),g(e,t.map(r=>JSON.stringify(r)+`
|
|
2
|
+
`).join("")))}n(appendBusEvents,"appendBusEvents"),s(appendBusEvents,"appendBusEvents");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/core",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
}
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"@lensmcp/protocol-types": "1.26.
|
|
112
|
+
"@lensmcp/protocol-types": "1.26.8",
|
|
113
113
|
"tslib": "^2.3.0"
|
|
114
114
|
},
|
|
115
115
|
"license": "Apache-2.0",
|