mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
fix issue with costs resetting once chat is completed
This commit is contained in:
parent
ca48a4f0fb
commit
248325925f
1 changed files with 2 additions and 11 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue