@@ -502,15 +502,6 @@ export namespace Session {
502502 }
503503 text = undefined
504504 } ,
505- async onFinish ( input ) {
506- log . info ( "message finish" , {
507- reason : input . finishReason ,
508- } )
509- const assistant = next . metadata ! . assistant !
510- const usage = getUsage ( model . info , input . usage , input . providerMetadata )
511- assistant . cost = usage . cost
512- await updateMessage ( next )
513- } ,
514505 onError ( err ) {
515506 log . error ( "callback error" , err )
516507 switch ( true ) {
@@ -681,7 +672,7 @@ export namespace Session {
681672 value . usage ,
682673 value . providerMetadata ,
683674 )
684- assistant . cost = usage . cost
675+ assistant . cost + = usage . cost
685676 await updateMessage ( next )
686677 if ( value . finishReason === "length" )
687678 throw new Message . OutputLengthError ( { } )
@@ -830,7 +821,7 @@ export namespace Session {
830821 async onFinish ( input ) {
831822 const assistant = next . metadata ! . assistant !
832823 const usage = getUsage ( model . info , input . usage , input . providerMetadata )
833- assistant . cost = usage . cost
824+ assistant . cost + = usage . cost
834825 assistant . tokens = usage . tokens
835826 next . metadata ! . time . completed = Date . now ( )
836827 await updateMessage ( next )
0 commit comments