fix: include output tokens in context window usage calculation
Include output tokens from last response in getContextWindowUsage calculation. Output tokens become part of next request's input (conversation history), so they must be counted to avoid overestimating remainingTokens. This aligns with preemptive-compaction's calculation which already includes output tokens correctly. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -112,7 +112,10 @@ export async function getContextWindowUsage(
|
|||||||
|
|
||||||
const lastAssistant = assistantMessages[assistantMessages.length - 1]
|
const lastAssistant = assistantMessages[assistantMessages.length - 1]
|
||||||
const lastTokens = lastAssistant.tokens
|
const lastTokens = lastAssistant.tokens
|
||||||
const usedTokens = (lastTokens?.input ?? 0) + (lastTokens?.cache?.read ?? 0)
|
const usedTokens =
|
||||||
|
(lastTokens?.input ?? 0) +
|
||||||
|
(lastTokens?.cache?.read ?? 0) +
|
||||||
|
(lastTokens?.output ?? 0)
|
||||||
const remainingTokens = ANTHROPIC_ACTUAL_LIMIT - usedTokens
|
const remainingTokens = ANTHROPIC_ACTUAL_LIMIT - usedTokens
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user