Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/api/providers/fetchers/roo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RooModelsResponseSchema } from "@roo-code/types"

import type { ModelRecord } from "../../../shared/api"
import { parseApiPrice } from "../../../shared/cost"

import { DEFAULT_HEADERS } from "../constants"

Expand Down Expand Up @@ -71,10 +72,10 @@ export async function getRooModels(baseUrl: string, apiKey?: string): Promise<Mo
const supportsImages = tags.includes("vision")

// Parse pricing (API returns strings, convert to numbers)
const inputPrice = parseFloat(pricing.input)
const outputPrice = parseFloat(pricing.output)
const cacheReadPrice = pricing.input_cache_read ? parseFloat(pricing.input_cache_read) : undefined
const cacheWritePrice = pricing.input_cache_write ? parseFloat(pricing.input_cache_write) : undefined
const inputPrice = parseApiPrice(pricing.input)
const outputPrice = parseApiPrice(pricing.output)
const cacheReadPrice = pricing.input_cache_read ? parseApiPrice(pricing.input_cache_read) : undefined
const cacheWritePrice = pricing.input_cache_write ? parseApiPrice(pricing.input_cache_write) : undefined

models[modelId] = {
maxTokens,
Expand Down
14 changes: 12 additions & 2 deletions src/api/providers/roo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { DEFAULT_HEADERS } from "./constants"
import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
import { getModels, flushModels, getModelsFromCache } from "../providers/fetchers/modelCache"

// Extend OpenAI's CompletionUsage to include Roo specific fields
interface RooUsage extends OpenAI.CompletionUsage {
cache_creation_input_tokens?: number
cost?: number
}

export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
private authStateListener?: (state: { state: AuthState }) => void
private fetcherBaseURL: string
Expand Down Expand Up @@ -124,10 +130,14 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
}

if (chunk.usage) {
const usage = chunk.usage as RooUsage
yield {
type: "usage",
inputTokens: chunk.usage.prompt_tokens || 0,
outputTokens: chunk.usage.completion_tokens || 0,
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,
}
}
}
Expand Down