@@ -13,15 +13,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
1313 const requestId = crypto . randomUUID ( )
1414 const stream = new SSEStream ( )
1515 const run = await findRun ( Number ( id ) )
16- if ( ! run ) {
17- return new Response ( `Run ${ id } not found` , { status : 404 } )
18- }
19-
2016 const redis = await redisClient ( )
21- if ( ! redis ) {
22- console . error ( `[stream#${ requestId } ] Redis client not available` ) ;
23- return new Response ( "Internal server error" , { status : 500 } )
24- }
2517
2618 let isStreamClosed = false
2719 const channelName = `evals:${ run . id } `
@@ -32,22 +24,19 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
3224 }
3325
3426 try {
35- const parsedData = JSON . parse ( data )
36- const taskEvent = taskEventSchema . parse ( parsedData )
27+ const taskEvent = taskEventSchema . parse ( JSON . parse ( data ) )
3728 console . log ( `[stream#${ requestId } ] task event -> ${ taskEvent . eventName } ` )
3829 const writeSuccess = await stream . write ( JSON . stringify ( taskEvent ) )
3930
4031 if ( ! writeSuccess ) {
41- console . error ( `[stream#${ requestId } ] failed to write to stream, disconnecting` ) ;
4232 await disconnect ( )
4333 }
44- } catch ( error ) {
45- console . error ( `[stream#${ requestId } ] invalid task event:` , data , 'Error:' , error ) ;
34+ } catch ( _error ) {
35+ console . error ( `[stream#${ requestId } ] invalid task event:` , data )
4636 }
4737 }
4838
4939 const disconnect = async ( ) => {
50- console . log ( `YO YO YO - [stream#${ requestId } ] disconnecting from channel ${ channelName } ` ) ;
5140 if ( isStreamClosed ) {
5241 return
5342 }
@@ -56,24 +45,19 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
5645
5746 try {
5847 await redis . unsubscribe ( channelName )
59- console . log ( `YO YO YO - [stream#${ requestId } ] unsubscribed from ${ channelName } ` ) ;
48+ console . log ( `[stream#${ requestId } ] unsubscribed from ${ channelName } ` )
6049 } catch ( error ) {
61- console . error ( `YO YO YO - [stream#${ requestId } ] error unsubscribing:` , error ) ;
50+ console . error ( `[stream#${ requestId } ] error unsubscribing:` , error )
6251 }
6352
6453 try {
6554 await stream . close ( )
6655 } catch ( error ) {
67- console . error ( `Error closing stream:` , error ) ;
56+ console . error ( `[stream# ${ requestId } ] error closing stream:` , error )
6857 }
6958 }
7059
71- try {
72- await redis . subscribe ( channelName , onMessage )
73- } catch ( error ) {
74- console . error ( `Error subscribing to Redis:` , error ) ;
75- return new Response ( "Internal server error" , { status : 500 } )
76- }
60+ await redis . subscribe ( channelName , onMessage )
7761
7862 // Add a timeout to close the stream after a period of inactivity or errors
7963 const timeoutDuration = 300000 ; // 5 minutes
0 commit comments