@@ -10,10 +10,7 @@ import {
1010 SessionStoreNotFoundError ,
1111 TurnNotFoundError ,
1212} from '@truefoundry/trueforge-core/agent-session' ;
13- import {
14- buildSessionMetricsCharts ,
15- MAX_SESSION_METRICS_WINDOW_MS ,
16- } from '@truefoundry/trueforge-core/agent-session/store/sessionMetrics' ;
13+ import { buildSessionMetricsCharts } from '@truefoundry/trueforge-core/agent-session/store/sessionMetrics' ;
1714import { extractErrorLogFields } from '@truefoundry/trueforge-core/core' ;
1815import {
1916 redisRequest ,
@@ -358,33 +355,22 @@ export function createSessionsRouter(deps: SessionsRouterDeps) {
358355 }
359356 } ;
360357
361- const validateSessionMetricsQuery = async (
362- query : {
363- agent_id : string ;
364- start_timestamp : Date ;
365- end_timestamp : Date ;
366- } ,
358+ const requireNamedAgentForSessionMetrics = async (
359+ agent_id : string ,
367360 c : Parameters < RouteHandler < typeof getSessionMetricsMetersRoute > > [ 0 ] ,
368361 ) => {
369- const windowMs = query . end_timestamp . getTime ( ) - query . start_timestamp . getTime ( ) ;
370- if ( windowMs < 0 ) {
371- return c . json ( { error : { message : 'end_timestamp must be on or after start_timestamp' } } , 400 ) ;
372- }
373- if ( windowMs > MAX_SESSION_METRICS_WINDOW_MS ) {
374- return c . json ( { error : { message : 'metrics window must not exceed 30 days' } } , 400 ) ;
375- }
376- const agent = await deps . agentStore . getAgent ( { tenant_id : TENANT_ID , id : query . agent_id } ) ;
362+ const agent = await deps . agentStore . getAgent ( { tenant_id : TENANT_ID , id : agent_id } ) ;
377363 if ( agent === undefined ) {
378- return c . json ( { error : { message : `Agent not found: ${ query . agent_id } ` } } , 404 ) ;
364+ return c . json ( { error : { message : `Agent not found: ${ agent_id } ` } } , 404 ) ;
379365 }
380366 return null ;
381367 } ;
382368
383369 const getSessionMetricsMetersHandler : RouteHandler < typeof getSessionMetricsMetersRoute > = async c => {
384370 const query = c . req . valid ( 'query' ) ;
385- const validationError = await validateSessionMetricsQuery ( query , c ) ;
386- if ( validationError !== null ) {
387- return validationError ;
371+ const missingAgent = await requireNamedAgentForSessionMetrics ( query . agent_id , c ) ;
372+ if ( missingAgent !== null ) {
373+ return missingAgent ;
388374 }
389375 const user = deps . resolveUserContext ( c ) ;
390376 const metrics = await deps . sessionStore . getSessionMetricsMeters ( {
@@ -403,9 +389,9 @@ export function createSessionsRouter(deps: SessionsRouterDeps) {
403389
404390 const getSessionMetricsChartsDataHandler : RouteHandler < typeof getSessionMetricsChartsDataRoute > = async c => {
405391 const query = c . req . valid ( 'query' ) ;
406- const validationError = await validateSessionMetricsQuery ( query , c ) ;
407- if ( validationError !== null ) {
408- return validationError ;
392+ const missingAgent = await requireNamedAgentForSessionMetrics ( query . agent_id , c ) ;
393+ if ( missingAgent !== null ) {
394+ return missingAgent ;
409395 }
410396 const user = deps . resolveUserContext ( c ) ;
411397 const chartData = await deps . sessionStore . getSessionMetricsChartData ( {
0 commit comments