fix issue with costs resetting once chat is completed

This commit is contained in:
Dax Raad 2025-06-29 19:43:03 -04:00
parent ca48a4f0fb
commit 248325925f

View file

@ -502,15 +502,6 @@ export namespace Session {
}
text = undefined
},
async onFinish(input) {
log.info("message finish", {
reason: input.finishReason,
})
const assistant = next.metadata!.assistant!
const usage = getUsage(model.info, input.usage, input.providerMetadata)
assistant.cost = usage.cost
await updateMessage(next)
},
onError(err) {
log.error("callback error", err)
switch (true) {
@ -681,7 +672,7 @@ export namespace Session {
value.usage,
value.providerMetadata,
)
assistant.cost = usage.cost
assistant.cost += usage.cost
await updateMessage(next)
if (value.finishReason === "length")
throw new Message.OutputLengthError({})
@ -830,7 +821,7 @@ export namespace Session {
async onFinish(input) {
const assistant = next.metadata!.assistant!
const usage = getUsage(model.info, input.usage, input.providerMetadata)
assistant.cost = usage.cost
assistant.cost += usage.cost
assistant.tokens = usage.tokens
next.metadata!.time.completed = Date.now()
await updateMessage(next)