Skip to content

The open source coding agent.

TypeScript

fix cost

Dax Raadf3e31130ba47
diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts
index 13496a7758f..d77da209ede 100644
--- a/packages/opencode/src/session/index.ts
+++ b/packages/opencode/src/session/index.ts
@@ -379,9 +379,12 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se
let text: Message.TextPart | undefined
const result = streamText({
onStepFinish: async (step) => {
+ log.info("step finish", {
+ finishReason: step.finishReason,
+ })
const assistant = next.metadata!.assistant!
const usage = getUsage(step.usage, model.info)
- assistant.cost = usage.cost
+ assistant.cost += usage.cost
assistant.tokens = usage.tokens
await updateMessage(next)
if (text) {
@@ -465,6 +468,12 @@ ${app.git ? await ListTool.execute({ path: app.path.cwd }, { sessionID: input.se
}
await updateMessage(next)
},
+ async onFinish(input) {
+ const assistant = next.metadata!.assistant!
+ const usage = getUsage(input.totalUsage, model.info)
+ assistant.cost = usage.cost
+ await updateMessage(next)
+ },
onError(input) {
if (input.error instanceof Error) {
next.metadata.error = input.error.toString()