Fix caching logic in Roo provider (#8860)

This commit is contained in:
Matt Rubens 2025-10-27 10:12:28 -04:00 committed by GitHub
parent bd1f890589
commit b92a22b0c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 10 deletions

View file

@ -598,7 +598,12 @@ export const getApiProtocol = (provider: ProviderName | undefined, modelId?: str
}
// Vercel AI Gateway uses anthropic protocol for anthropic models.
if (provider && provider === "vercel-ai-gateway" && modelId && modelId.toLowerCase().startsWith("anthropic/")) {
if (
provider &&
["vercel-ai-gateway", "roo"].includes(provider) &&
modelId &&
modelId.toLowerCase().startsWith("anthropic/")
) {
return "anthropic"
}

View file

@ -90,6 +90,8 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
metadata?.taskId ? { headers: { "X-Roo-Task-ID": metadata.taskId } } : undefined,
)
let lastUsage: RooUsage | undefined = undefined
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta
@ -110,15 +112,18 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
}
if (chunk.usage) {
const usage = chunk.usage as RooUsage
yield {
type: "usage",
inputTokens: usage.prompt_tokens || 0,
outputTokens: usage.completion_tokens || 0,
cacheWriteTokens: usage.cache_creation_input_tokens,
cacheReadTokens: usage.prompt_tokens_details?.cached_tokens,
totalCost: usage.cost ?? 0,
}
lastUsage = chunk.usage as RooUsage
}
}
if (lastUsage) {
yield {
type: "usage",
inputTokens: lastUsage.prompt_tokens || 0,
outputTokens: lastUsage.completion_tokens || 0,
cacheWriteTokens: lastUsage.cache_creation_input_tokens,
cacheReadTokens: lastUsage.prompt_tokens_details?.cached_tokens,
totalCost: lastUsage.cost ?? 0,
}
}
}