@@ -6,15 +6,20 @@ import { matchFilters } from '../../../model/filters/filter-matching';
66import { SelectableSearchFilterClasses } from '../../../model/filters/search-filters' ;
77import { EventsStore } from '../../../model/events/events-store' ;
88
9+ // Free-tier body exports are capped to support exploration but not
10+ // arbitrary export (paid feature).
11+ const FREE_TIER_MAX_BODY_CHARS = 100_000 ;
12+
913export function registerEventOperations (
1014 registry : OperationRegistry ,
1115 eventsStore : EventsStore ,
12- getEvents : ( ) => ReadonlyArray < CollectedEvent >
16+ getEvents : ( ) => ReadonlyArray < CollectedEvent > ,
17+ isPaidUser : ( ) => boolean
1318) : void {
1419 registry . register ( eventsListOperation ( getEvents ) ) ;
1520 registry . register ( eventsGetOutlineOperation ( getEvents ) ) ;
16- registry . register ( eventsGetRequestBodyOperation ( getEvents ) ) ;
17- registry . register ( eventsGetResponseBodyOperation ( getEvents ) ) ;
21+ registry . register ( eventsGetRequestBodyOperation ( getEvents , isPaidUser ) ) ;
22+ registry . register ( eventsGetResponseBodyOperation ( getEvents , isPaidUser ) ) ;
1823 registry . register ( eventsClearOperation ( eventsStore ) ) ;
1924}
2025
@@ -171,6 +176,10 @@ function eventsGetOutlineOperation(
171176 'Use events.get-request-body or events.get-response-body to retrieve bodies.' ,
172177 category : 'events' ,
173178 tiers : [ 'free' , 'pro' ] ,
179+ sessionLimit : 500 ,
180+ freeTierNote : 'This operation is limited to 500 calls per session for free users, so ' +
181+ 'ensure only the necessary events are queried. Upgrade to Pro (account.upgrade) ' +
182+ 'for unlimited access to all features.' ,
174183 annotations : { readOnlyHint : true } ,
175184 inputSchema : {
176185 type : 'object' ,
@@ -218,8 +227,15 @@ function eventsGetOutlineOperation(
218227 } ;
219228}
220229
230+ function effectiveMaxLength ( requested : number | undefined , isPaid : boolean ) : number | undefined {
231+ if ( isPaid ) return requested ;
232+ if ( requested === undefined ) return FREE_TIER_MAX_BODY_CHARS ;
233+ return Math . min ( requested , FREE_TIER_MAX_BODY_CHARS ) ;
234+ }
235+
221236function eventsGetRequestBodyOperation (
222- getEvents : ( ) => ReadonlyArray < CollectedEvent >
237+ getEvents : ( ) => ReadonlyArray < CollectedEvent > ,
238+ isPaidUser : ( ) => boolean
223239) : Operation {
224240 return {
225241 definition : {
@@ -228,7 +244,10 @@ function eventsGetRequestBodyOperation(
228244 'Use offset and maxLength to retrieve specific ranges of large bodies.' ,
229245 category : 'events' ,
230246 tiers : [ 'free' , 'pro' ] ,
231- sessionLimit : 50 ,
247+ sessionLimit : 100 ,
248+ freeTierNote : `Response bodies are capped at ${ FREE_TIER_MAX_BODY_CHARS } ` +
249+ 'characters per call. Page through larger bodies with offset, or upgrade ' +
250+ 'to Pro (account.upgrade) for full bodies.' ,
232251 annotations : { readOnlyHint : true } ,
233252 inputSchema : {
234253 type : 'object' ,
@@ -243,15 +262,16 @@ function eventsGetRequestBodyOperation(
243262
244263 const body = await serializeBody ( lookup . exchange , 'request' , {
245264 offset : params . offset as number | undefined ,
246- maxLength : params . maxLength as number | undefined
265+ maxLength : effectiveMaxLength ( params . maxLength as number | undefined , isPaidUser ( ) )
247266 } ) ;
248267 return { success : true , data : body } ;
249268 }
250269 } ;
251270}
252271
253272function eventsGetResponseBodyOperation (
254- getEvents : ( ) => ReadonlyArray < CollectedEvent >
273+ getEvents : ( ) => ReadonlyArray < CollectedEvent > ,
274+ isPaidUser : ( ) => boolean
255275) : Operation {
256276 return {
257277 definition : {
@@ -260,7 +280,10 @@ function eventsGetResponseBodyOperation(
260280 'Use offset and maxLength to retrieve specific ranges of large bodies.' ,
261281 category : 'events' ,
262282 tiers : [ 'free' , 'pro' ] ,
263- sessionLimit : 50 ,
283+ sessionLimit : 100 ,
284+ freeTierNote : `Response bodies are capped at ${ FREE_TIER_MAX_BODY_CHARS } ` +
285+ 'characters per call. Page through larger bodies with offset, or upgrade ' +
286+ 'to Pro (account.upgrade) for full bodies.' ,
264287 annotations : { readOnlyHint : true } ,
265288 inputSchema : {
266289 type : 'object' ,
@@ -275,7 +298,7 @@ function eventsGetResponseBodyOperation(
275298
276299 const body = await serializeBody ( lookup . exchange , 'response' , {
277300 offset : params . offset as number | undefined ,
278- maxLength : params . maxLength as number | undefined
301+ maxLength : effectiveMaxLength ( params . maxLength as number | undefined , isPaidUser ( ) )
279302 } ) ;
280303 return { success : true , data : body } ;
281304 }
0 commit comments