@@ -20,6 +20,7 @@ import {
20
20
type ProviderMessageContent ,
21
21
type ProviderName ,
22
22
type StopReason ,
23
+ type Usage ,
23
24
} from "../providers/provider.ts" ;
24
25
import { assertUnreachable } from "../utils/assertUnreachable.ts" ;
25
26
import { DEFAULT_OPTIONS , type MagentaOptions } from "../options.ts" ;
@@ -34,6 +35,7 @@ export type ConversationState =
34
35
| {
35
36
state : "stopped" ;
36
37
stopReason : StopReason ;
38
+ usage : Usage ;
37
39
} ;
38
40
39
41
export type Model = {
@@ -115,7 +117,11 @@ export function init({ nvim, lsp }: { nvim: Nvim; lsp: Lsp }) {
115
117
lastUserMessageId : counter . last ( ) as Message . MessageId ,
116
118
options : DEFAULT_OPTIONS ,
117
119
activeProvider : "anthropic" ,
118
- conversation : { state : "stopped" , stopReason : "end_turn" } ,
120
+ conversation : {
121
+ state : "stopped" ,
122
+ stopReason : "end_turn" ,
123
+ usage : { inputTokens : 0 , outputTokens : 0 } ,
124
+ } ,
119
125
messages : [ ] ,
120
126
toolManager : toolManagerModel . initModel ( ) ,
121
127
contextManager : contextManagerModel . initModel ( ) ,
@@ -509,6 +515,7 @@ ${msg.error.stack}`,
509
515
conversation : {
510
516
state : "stopped" ,
511
517
stopReason : res ?. stopReason || "end_turn" ,
518
+ usage : res ?. usage || { inputTokens : 0 , outputTokens : 0 } ,
512
519
} ,
513
520
} ) ;
514
521
}
@@ -549,7 +556,12 @@ ${msg.error.stack}`,
549
556
) % MESSAGE_ANIMATION . length
550
557
]
551
558
} `
552
- : d `Stopped (${ model . conversation . stopReason || "" } )`
559
+ : d `Stopped (${ model . conversation . stopReason } ) [input: ${ model . conversation . usage . inputTokens . toString ( ) } , output: ${ model . conversation . usage . outputTokens . toString ( ) } ${
560
+ model . conversation . usage . cacheHits !== undefined &&
561
+ model . conversation . usage . cacheMisses !== undefined
562
+ ? d `, cache hits: ${ model . conversation . usage . cacheHits . toString ( ) } , cache misses: ${ model . conversation . usage . cacheMisses . toString ( ) } `
563
+ : ""
564
+ } ]`
553
565
} ${
554
566
model . conversation . state == "stopped" &&
555
567
! contextManagerModel . isContextEmpty ( model . contextManager )
0 commit comments