File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { EventEmitter , on } from "node:events" ;
22
33export class TypedEventEmitter < TEvents > extends EventEmitter {
4+ constructor ( ) {
5+ super ( ) ;
6+ this . setMaxListeners ( 0 ) ;
7+ }
8+
49 emit < K extends keyof TEvents & string > (
510 event : K ,
611 payload : TEvents [ K ] ,
Original file line number Diff line number Diff line change @@ -100,6 +100,9 @@ export class Agent {
100100 }
101101
102102 async cleanup ( ) : Promise < void > {
103+ if ( this . sessionLogWriter && this . taskRunId ) {
104+ await this . sessionLogWriter . flush ( this . taskRunId ) ;
105+ }
103106 await this . acpConnection ?. cleanup ( ) ;
104107 }
105108}
Original file line number Diff line number Diff line change @@ -18,25 +18,14 @@ export class SessionLogWriter {
1818 this . posthogAPI = posthogAPI ;
1919 this . logger =
2020 logger ?? new Logger ( { debug : false , prefix : "[SessionLogWriter]" } ) ;
21+ }
2122
22- const flushAllAndExit = async ( ) => {
23- const flushPromises : Promise < void > [ ] = [ ] ;
24- for ( const sessionId of this . configs . keys ( ) ) {
25- flushPromises . push ( this . flush ( sessionId ) ) ;
26- }
27- await Promise . all ( flushPromises ) ;
28- process . exit ( 0 ) ;
29- } ;
30-
31- process . on ( "beforeExit" , ( ) => {
32- flushAllAndExit ( ) . catch ( ( e ) => this . logger . error ( "Flush failed:" , e ) ) ;
33- } ) ;
34- process . on ( "SIGINT" , ( ) => {
35- flushAllAndExit ( ) . catch ( ( e ) => this . logger . error ( "Flush failed:" , e ) ) ;
36- } ) ;
37- process . on ( "SIGTERM" , ( ) => {
38- flushAllAndExit ( ) . catch ( ( e ) => this . logger . error ( "Flush failed:" , e ) ) ;
39- } ) ;
23+ async flushAll ( ) : Promise < void > {
24+ const flushPromises : Promise < void > [ ] = [ ] ;
25+ for ( const sessionId of this . configs . keys ( ) ) {
26+ flushPromises . push ( this . flush ( sessionId ) ) ;
27+ }
28+ await Promise . all ( flushPromises ) ;
4029 }
4130
4231 register ( sessionId : string , config : SessionLogConfig ) : void {
You can’t perform that action at this time.
0 commit comments