mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 02:34:21 +01:00
fix issue with costs resetting once chat is completed
This commit is contained in:
@@ -502,15 +502,6 @@ export namespace Session {
|
|||||||
}
|
}
|
||||||
text = undefined
|
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) {
|
onError(err) {
|
||||||
log.error("callback error", err)
|
log.error("callback error", err)
|
||||||
switch (true) {
|
switch (true) {
|
||||||
@@ -681,7 +672,7 @@ export namespace Session {
|
|||||||
value.usage,
|
value.usage,
|
||||||
value.providerMetadata,
|
value.providerMetadata,
|
||||||
)
|
)
|
||||||
assistant.cost = usage.cost
|
assistant.cost += usage.cost
|
||||||
await updateMessage(next)
|
await updateMessage(next)
|
||||||
if (value.finishReason === "length")
|
if (value.finishReason === "length")
|
||||||
throw new Message.OutputLengthError({})
|
throw new Message.OutputLengthError({})
|
||||||
@@ -830,7 +821,7 @@ export namespace Session {
|
|||||||
async onFinish(input) {
|
async onFinish(input) {
|
||||||
const assistant = next.metadata!.assistant!
|
const assistant = next.metadata!.assistant!
|
||||||
const usage = getUsage(model.info, input.usage, input.providerMetadata)
|
const usage = getUsage(model.info, input.usage, input.providerMetadata)
|
||||||
assistant.cost = usage.cost
|
assistant.cost += usage.cost
|
||||||
assistant.tokens = usage.tokens
|
assistant.tokens = usage.tokens
|
||||||
next.metadata!.time.completed = Date.now()
|
next.metadata!.time.completed = Date.now()
|
||||||
await updateMessage(next)
|
await updateMessage(next)
|
||||||
|
|||||||
Reference in New Issue
Block a user