Skip to content

Commit 2483259

Browse files
committed
fix issue with costs resetting once chat is completed
1 parent ca48a4f commit 2483259

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

packages/opencode/src/session/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)