File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ function TokenRate(props: { api: TuiPluginApi }) {
4141 props . api . event . on ( "message.updated" , ( evt ) => {
4242 const info = evt . properties . info
4343 if ( info . role !== "assistant" ) return
44- const tokens = info . tokens . output + info . tokens . reasoning
44+ const tokens = ( info . tokens ? .output ?? 0 ) + ( info . tokens ? .reasoning ?? 0 )
4545 lastActivityAt = Date . now ( )
4646 if ( info . id !== currentId ) {
4747 currentId = info . id
@@ -67,6 +67,7 @@ function TokenRate(props: { api: TuiPluginApi }) {
6767 tick ( )
6868 const now = Date . now ( )
6969 if ( now - lastActivityAt > ACTIVITY_TIMEOUT ) return
70+ if ( currentTokens <= 0 ) return
7071 return {
7172 rate : meter . rate ( now ) ,
7273 total : currentTokens ,
Original file line number Diff line number Diff line change @@ -34,12 +34,6 @@ export class TokenRateMeter {
3434 return ( last . tokens - first . tokens ) / elapsed
3535 }
3636
37- // True when a sample landed within `timeoutMs` of `at`.
38- isActive ( at = Date . now ( ) , timeoutMs = 2000 ) : boolean {
39- const last = this . samples [ this . samples . length - 1 ]
40- return ! ! last && at - last . at <= timeoutMs
41- }
42-
4337 private prune ( at : number ) {
4438 const windowStart = at - this . windowMs
4539 let drop = 0
Original file line number Diff line number Diff line change @@ -54,14 +54,4 @@ describe("util.token-rate", () => {
5454 meter . add ( 10 , 2000 )
5555 expect ( meter . rate ( 2000 ) ) . toBe ( 0 )
5656 } )
57-
58- test ( "isActive reflects recent sampling within the timeout" , ( ) => {
59- const meter = new TokenRateMeter ( )
60- expect ( meter . isActive ( 1000 , 2000 ) ) . toBe ( false )
61- meter . add ( 10 , 1000 )
62- expect ( meter . isActive ( 1000 , 2000 ) ) . toBe ( true )
63- expect ( meter . isActive ( 2999 , 2000 ) ) . toBe ( true )
64- expect ( meter . isActive ( 3000 , 2000 ) ) . toBe ( true )
65- expect ( meter . isActive ( 3001 , 2000 ) ) . toBe ( false )
66- } )
6757} )
You can’t perform that action at this time.
0 commit comments