@lensmcp/core 1.25.45 → 1.25.46

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.
@@ -11,8 +11,17 @@ export declare const DEFAULT_ANSWER_BUDGET_BYTES: number;
11
11
  export declare const ANSWER_BUDGET_ENV = "LENSMCP_ANSWER_BUDGET_BYTES";
12
12
  /** A budget below this cannot hold the note that says an answer was cut, so it is raised to it. */
13
13
  export declare const MIN_ANSWER_BUDGET_BYTES: number;
14
- /** The key a cut document carries its note under. */
14
+ /** The key a cut document carries its {@link AnswerCut} under. */
15
15
  export declare const ANSWER_CUT_KEY = "cutToFit";
16
+ /**
17
+ * Longest a cut's `note` may be, in UTF-8 bytes. The note used to be a paragraph of about 700 characters that listed
18
+ * every cut list, repeated the tool's hint and ended by telling the agent to start the lens with the budget off. One
19
+ * Codex lead read it 45 times in a run, and the last sentence pushed agents toward larger answers
20
+ * (issues/closed/foodguard-155). Now the details are fields of the cut, and the note is one short sentence that says
21
+ * how to read them. How to turn the budget off is for the person: it is in the docs and on the dashboard, never in an
22
+ * answer to an agent.
23
+ */
24
+ export declare const MAX_CUT_NOTE_BYTES = 120;
16
25
  /** Longest string left whole in an item of a list that is over its budget — a message and about fifteen stack frames. */
17
26
  export declare const FITTED_STRING_CHARS = 1500;
18
27
  /** A string at least this long is stated once per list; a repeat becomes a reference to the first. */
@@ -83,29 +92,45 @@ export interface ListFit<T> {
83
92
  export declare function fitList<T>(items: readonly T[], budgetBytes: number, opts?: ListFitOptions): ListFit<T>;
84
93
  /** Split a budget between several claims: a small one is granted whole, and the large ones share what is left evenly. */
85
94
  export declare function shareBudget(sizes: readonly number[], budgetBytes: number): number[];
86
- /** What a cut answer says about itself, under {@link ANSWER_CUT_KEY}. */
95
+ /** One list that lost items: how many it holds, how many are shown, and which. */
96
+ export interface ListCut {
97
+ list: string;
98
+ total: number;
99
+ returned: number;
100
+ kept: 'newest' | 'first' | 'last';
101
+ }
102
+ /**
103
+ * What a cut answer says about itself, under {@link ANSWER_CUT_KEY}. The details are fields an agent reads, and a
104
+ * field is left out when it has nothing to say, so the whole object is a few hundred bytes. It used to carry a
105
+ * paragraph-long note and every count, zeros included (issues/closed/foodguard-155).
106
+ */
87
107
  export interface AnswerCut {
88
- /** The budget it was fitted to. */
89
- limitBytes: number;
90
- /** What the whole answer weighs. */
91
- originalBytes: number;
92
- /** Each list that lost items: how many it holds, how many are shown, and which. */
93
- lists: Array<{
94
- list: string;
95
- total: number;
96
- returned: number;
97
- kept: 'newest' | 'first' | 'last';
98
- }>;
99
- shortenedStrings: number;
100
- repeatedStrings: number;
101
- /** Cutting lists was not enough: large values elsewhere in the document were shrunk too. */
108
+ /** The budget it was fitted to, in UTF-8 bytes. */
109
+ budget: number;
110
+ /** What the whole answer weighs, in UTF-8 bytes (`null` on the wire for one that cannot be measured). */
111
+ original: number;
112
+ /** Each list that lost items. Absent when no list did. */
113
+ lists?: ListCut[];
114
+ /** How many long texts were cut to their head (`…[lensmcp truncated: N more chars]`). */
115
+ shortened?: number;
116
+ /** How many texts repeated between items are stated once and referenced (`…[lensmcp: same text as …]`). */
117
+ repeated?: number;
118
+ /** Cutting lists was not enough: large values elsewhere in the document were shrunk too (`__lensmcpTruncation`). */
102
119
  clamped?: true;
103
120
  /** The values it holds that were sent whole, whatever the budget ({@link AnswerFitOptions.whole}). */
104
121
  whole?: string[];
122
+ /** Where the rest can be read, when the caller knows ({@link AnswerFitOptions.more}). */
123
+ more?: string;
124
+ /** One sentence on how to read the fields above, at most {@link MAX_CUT_NOTE_BYTES}. */
105
125
  note: string;
106
126
  }
127
+ /** The note for a cut: how to read its fields. It never names a way to turn the budget off (issues/closed/foodguard-155). */
128
+ export declare function cutNote(cut: Pick<AnswerCut, 'lists' | 'more'>): string;
107
129
  export interface AnswerFitOptions {
108
- /** Where the rest can be read — appended to the note (e.g. the tool that pages this list). */
130
+ /**
131
+ * Where the rest can be read, such as the tool that pages this list. It goes in the cut's `more` field: keep it to a
132
+ * line, because every cut answer of that tool carries it.
133
+ */
109
134
  more?: string;
110
135
  /** Per top-level list: the end that holds its newest items, for a ring whose items carry no time. */
111
136
  newest?: Readonly<Record<string, ListEnd>>;
@@ -1,2 +1,2 @@
1
- "use strict";var U=Object.defineProperty;var y=(e,r)=>U(e,"name",{value:r,configurable:!0});var Y=Object.defineProperty,p=y((e,r)=>Y(e,"name",{value:r,configurable:!0}),"u");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",FITTED_STRING_CHARS=1500,REPEATED_STRING_MIN_CHARS=200;const R=900,V=32,H=new Set(["timestamp","startedAt","startTime","at","emittedAt","lastSeenAt","endedAt","endTime","t","ts","time"]),J=p(e=>typeof e=="number"&&e>=1e11&&e<=1e14,"isEpochMs"),K=.95;export function answerBudgetBytes(e=process.env){const r=e[ANSWER_BUDGET_ENV];if(r===void 0||r.trim()==="")return DEFAULT_ANSWER_BUDGET_BYTES;const t=Number(r);return!Number.isFinite(t)||t<0?DEFAULT_ANSWER_BUDGET_BYTES:t===0?Number.POSITIVE_INFINITY:Math.max(MIN_ANSWER_BUDGET_BYTES,Math.floor(t))}y(answerBudgetBytes,"answerBudgetBytes"),p(answerBudgetBytes,"answerBudgetBytes");export function utf8Bytes(e){let r=0;for(let t=0;t<e.length;t++){const s=e.charCodeAt(t);s<128?r+=1:s<2048?r+=2:s>=55296&&s<=56319&&t+1<e.length&&(e.charCodeAt(t+1)&64512)===56320?(r+=4,t+=1):r+=3}return r}y(utf8Bytes,"utf8Bytes"),p(utf8Bytes,"utf8Bytes");export function jsonBytes(e){let r;try{r=JSON.stringify(e)}catch{return Number.POSITIVE_INFINITY}return r===void 0?0:utf8Bytes(r)}y(jsonBytes,"jsonBytes"),p(jsonBytes,"jsonBytes");const C=p(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isRecord");function _(e){if(!C(e))return!1;const r=Object.getPrototypeOf(e);return r===Object.prototype||r===null}y(_,"O"),p(_,"isPlain");export function newestEndOf(e){const r=e[0];if(e.length<2||!C(r))return;let t;for(const s of Object.keys(r)){if(typeof r[s]!="number"||!(H.has(s)||J(r[s])))continue;let i=0,a=0,u=!0,c=r[s];for(let w=1;w<e.length;w++){const S=e[w],m=C(S)?S[s]:void 0;if(typeof m!="number"){u=!1;break}m>c?i+=1:m<c&&(a+=1),c=m}const o=i+a;if(!u||o===0)continue;const f=Math.max(i,a)/o;f>=K&&(!t||f>t.agreement)&&(t={end:i>=a?"end":"start",agreement:f})}return t?.end}y(newestEndOf,"newestEndOf"),p(newestEndOf,"newestEndOf");export function newestFirst(e){return newestEndOf(e)==="end"?[...e].reverse():e.slice()}y(newestFirst,"newestFirst"),p(newestFirst,"newestFirst");export function shortenText(e,r){if(e.length<=r)return e;let t=Math.max(0,r);const s=e.lastIndexOf(`
2
- `,t);return s>=t/2&&(t=s),t>0&&(e.charCodeAt(t-1)&64512)===55296&&(t-=1),`${e.slice(0,t)}\u2026[lensmcp truncated: ${e.length-t} more chars]`}y(shortenText,"shortenText"),p(shortenText,"shortenText");export function fitList(e,r,t={}){const s=e.length,i=e.reduce((l,k)=>l+jsonBytes(k)+1,2);if(i<=r)return{items:e.slice(),total:s,returned:s,kept:"all",shortenedStrings:0,repeatedStrings:0,bytes:i};const a=t.newest??newestEndOf(e),u=a??t.keep??"start",c=t.name??"items",o=t.maxStringChars??FITTED_STRING_CHARS,f=u==="start"?e:[...e].reverse(),w=String(Math.max(0,s-1)).length,S=new Map,m=[],b=[];let $=2,B=0,T=0;for(let l=0;l<f.length;l++){const k=new Map,E=[];let M=0;const n=p((h,I,j,G,L)=>{if(typeof h=="string"){if(h.length>=REPEATED_STRING_MIN_CHARS){const x=S.get(h)??k.get(h);if(x)return E.push({holder:G,key:L,owner:x.owner,path:x.path}),`\u2026[lensmcp: same text as ${c}[${"9".repeat(w)}]${x.path}]`;k.set(h,{owner:l,path:I})}return h.length>o?(M+=1,shortenText(h,o)):h}if(j>=V)return h;if(Array.isArray(h)){const x=[];return h.forEach((N,W)=>x.push(n(N,`${I}[${W}]`,j+1,x,W))),x}if(_(h)){const x={};for(const N of Object.keys(h))x[N]=n(h[N],`${I}.${N}`,j+1,x,N);return x}return h},"slim"),d=[];let g=n(f[l],"",0,d,0),O=jsonBytes(g)+1;if(b.length===0&&$+O>r)g=F(f[l],Math.max(0,r-$-1)),O=jsonBytes(g)+1,E.length=0,k.clear(),M=1;else if($+O>r)break;b.push(g),$+=O,B+=M,T+=E.length;for(const[h,I]of k)S.set(h,I);for(const h of E)m.push(h.holder===d?{...h,holder:b,key:b.length-1}:h)}const A=b.length,v=p(l=>u==="start"?l:A-1-l,"indexOf");if(u==="end"){for(const l of m)l.holder===b&&(l.key=v(l.key));b.reverse()}for(const l of m)l.holder[l.key]=`\u2026[lensmcp: same text as ${c}[${v(l.owner)}]${l.path}]`;return{items:b,total:s,returned:A,kept:A===s?"all":a?"newest":u==="start"?"first":"last",shortenedStrings:B,repeatedStrings:T,bytes:jsonBytes(b)}}y(fitList,"fitList"),p(fitList,"fitList");function F(e,r){let t=Math.max(256,r),s=e;for(let i=0;i<6;i++){if(s=z(e,{rawByteLimit:t,maxStringBytes:Math.min(2e3,Math.max(128,Math.floor(t/4))),maxArrayItems:64}).value,jsonBytes(s)<=r)return s;t=Math.floor(t*.6)}return s}y(F,"W"),p(F,"clampTo");export function shareBudget(e,r){const t=e.map((a,u)=>({size:a,index:u})).sort((a,u)=>a.size-u.size),s=new Array(e.length).fill(0);let i=Math.max(0,r);return t.forEach(({size:a,index:u},c)=>{const o=Math.floor(i/(t.length-c));s[u]=Math.min(a,o),i-=s[u]}),s}y(shareBudget,"shareBudget"),p(shareBudget,"shareBudget");function P(e,r){const t={...e},s=new WeakSet([t]),i=[];let a=0;for(const u of r){const c=u.split("."),o=c[c.length-1];let f=t;for(const w of c.slice(0,-1)){const S=f[w];if(!_(S)){f=void 0;break}const m=s.has(S)?S:{...S};s.add(m),f[w]=m,f=m}!f||f[o]===void 0||f[o]===null||(i.push({keys:c,value:f[o]}),a+=jsonBytes(f[o]),f[o]=null)}return i.length?{body:t,parts:i,bytes:a}:void 0}y(P,"K"),p(P,"holdWhole");function D(e,r){for(const{keys:t,value:s}of r){let i=e;for(const a of t.slice(0,-1)){const u=i[a],c=_(u)?u:{};i[a]=c,i=c}i[t[t.length-1]]=s}return e}y(D,"z"),p(D,"putBack");export function fitAnswer(e,r,t={}){if(!Number.isFinite(r)||e===null||typeof e!="object")return{value:e};const s=jsonBytes(e);if(s<=r)return{value:e};const i=t.whole?.length&&_(e)?P(e,t.whole):void 0,a=i?i.body:e,u=i?jsonBytes(a):s,c=i?Math.max(MIN_ANSWER_BUDGET_BYTES,r-i.bytes):r;if(u<=c)return{value:e};const o={limitBytes:r,originalBytes:s,lists:[],shortenedStrings:0,repeatedStrings:0,...i?{whole:i.parts.map(n=>n.keys.join("."))}:{},note:""},f=p(()=>{const n=o.lists.map(d=>`\`${d.list}\` shows the ${d.kept} ${d.returned} of ${d.total}`);o.note=`Cut to fit one tool result (${r} bytes; the whole answer is ${Number.isFinite(s)?s:"larger"}) \u2014 it is still one valid JSON document.`+(n.length?` ${n.join("; ")}; any other count in this document describes the whole list.`:"")+(o.shortenedStrings?` ${o.shortenedStrings} long text${o.shortenedStrings===1?" was":"s were"} cut to the head.`:"")+(o.repeatedStrings?` ${o.repeatedStrings} repeated text${o.repeatedStrings===1?" is":"s are"} stated once and referenced.`:"")+(o.clamped?" Large values outside the lists were shrunk too (see `__lensmcpTruncation`).":"")+(o.whole?` Never cut: ${o.whole.map(d=>`\`${d}\``).join(", ")} \u2014 sent whole.`:"")+(t.more?` ${t.more}`:"")+` Whole answer: start the lens with ${ANSWER_BUDGET_ENV}=0.`},"describe"),w=p(n=>({value:i?D(n,i.parts):n,cut:o}),"done");if(Array.isArray(a)){const n=fitList(a,c);return n.kept!=="all"&&o.lists.push({list:"items",total:n.total,returned:n.returned,kept:n.kept}),o.shortenedStrings=n.shortenedStrings,o.repeatedStrings=n.repeatedStrings,f(),w(n.items)}if(!_(a))return{value:e};const S=Object.keys(a),m=S.filter(n=>Array.isArray(a[n])&&a[n].length>0),b=m.map(n=>jsonBytes(a[n])),$=u-b.reduce((n,d)=>n+d,0),B=shareBudget(b,c-$-R),T={};m.forEach((n,d)=>{if(b[d]<=B[d])return;const g=fitList(a[n],B[d],{name:n,...t.newest?.[n]?{newest:t.newest[n]}:{}});T[n]=g.items,g.kept!=="all"&&o.lists.push({list:n,total:g.total,returned:g.returned,kept:g.kept}),o.shortenedStrings+=g.shortenedStrings,o.repeatedStrings+=g.repeatedStrings});const A=p(n=>(f(),{[ANSWER_CUT_KEY]:o,...n}),"assemble"),v={};for(const n of S)v[n]=n in T?T[n]:a[n];let l=A(v);if(jsonBytes(l)<=c)return w(l);o.clamped=!0;let k=Math.max(512,c-R);for(let n=0;n<6;n++){if(l=A(F(v,k)),jsonBytes(l)<=c)return w(l);k=Math.floor(k*.6)}const E={};let M=R;for(const n of S){const d=a[n];if(d!==null&&typeof d=="object")continue;const g=jsonBytes(d)+utf8Bytes(n)+4;if(M+g>c)break;E[n]=d,M+=g}return w(A(E))}y(fitAnswer,"fitAnswer"),p(fitAnswer,"fitAnswer");
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");
@@ -74,9 +74,9 @@ export declare function trimFlowEvent(event: BaseEvent, opts?: FlowShapeOptions)
74
74
  outcome?: "returned" | "threw" | undefined;
75
75
  calleeRequestId?: string | undefined;
76
76
  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";
77
+ source: "gateway" | "ai" | "db" | "redis" | "queue" | "external" | "visual" | "react" | "memory" | "nx" | "vite" | "typescript" | "eslint" | "rollup" | "client-runtime" | "chrome" | "valtio" | "nestjs" | "nextjs" | "perf" | "security" | "lens" | "custom";
78
+ category: "ai" | "db" | "visual" | "memory" | "security" | "build" | "test" | "state" | "agent" | "network" | "typecheck" | "lint" | "cluster" | "trace" | "runtime" | "render" | "backend" | "performance" | "deps";
79
+ severity: "error" | "info" | "warning" | "debug" | "fatal";
80
80
  title: string;
81
81
  kind: string | undefined;
82
82
  area: FlowArea;
@@ -148,9 +148,9 @@ export declare function buildFlowDetail(rawEvents: BaseEvent[], opts?: FlowShape
148
148
  outcome?: "returned" | "threw" | undefined;
149
149
  calleeRequestId?: string | undefined;
150
150
  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";
151
+ source: "gateway" | "ai" | "db" | "redis" | "queue" | "external" | "visual" | "react" | "memory" | "nx" | "vite" | "typescript" | "eslint" | "rollup" | "client-runtime" | "chrome" | "valtio" | "nestjs" | "nextjs" | "perf" | "security" | "lens" | "custom";
152
+ category: "ai" | "db" | "visual" | "memory" | "security" | "build" | "test" | "state" | "agent" | "network" | "typecheck" | "lint" | "cluster" | "trace" | "runtime" | "render" | "backend" | "performance" | "deps";
153
+ severity: "error" | "info" | "warning" | "debug" | "fatal";
154
154
  title: string;
155
155
  kind: string | undefined;
156
156
  area: FlowArea;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/core",
3
- "version": "1.25.45",
3
+ "version": "1.25.46",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -84,7 +84,7 @@
84
84
  }
85
85
  },
86
86
  "dependencies": {
87
- "@lensmcp/protocol-types": "1.25.45",
87
+ "@lensmcp/protocol-types": "1.25.46",
88
88
  "tslib": "^2.3.0"
89
89
  },
90
90
  "license": "Apache-2.0",