mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-17 23:51:08 +00:00
fix: resolve review issues - remove duplicate OpenRouter fallback utils, preserve Bedrock opt-in caching default
- openrouter.ts: Remove inline firstNumber/toFiniteNumber fallback chains that duplicated the profile-based resolution in usage-profiles.ts. Now uses simple totalUsage ?? usage preference and delegates all further extraction to normalizeProviderUsage. - bedrock.ts: Preserve historical opt-in caching default. Previously controlled by awsUsePromptCache (defaulting to off), the migration to unified promptCachingEnabled (defaulting to true) silently enabled caching for existing Bedrock users. Now explicitly defaults to false for Bedrock when no global setting exists.
This commit is contained in:
parent
844f43c8b6
commit
ba08cc7420
2 changed files with 15 additions and 19 deletions
|
|
@ -252,6 +252,15 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
|
|||
}
|
||||
}
|
||||
|
||||
// Bedrock caching was historically opt-in (awsUsePromptCache).
|
||||
// Preserve that default: when no explicit global or provider-level
|
||||
// setting exists, default to disabled so existing users are not
|
||||
// silently enrolled.
|
||||
const bedrockCacheSettings = {
|
||||
...this.options,
|
||||
promptCachingEnabled: this.options.promptCachingEnabled ?? false,
|
||||
}
|
||||
|
||||
const promptCache = applyPromptCacheToMessages({
|
||||
adapter: "bedrock",
|
||||
overrideKey: "bedrock",
|
||||
|
|
@ -260,7 +269,7 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
|
|||
supportsPromptCache: modelConfig.info.supportsPromptCache,
|
||||
promptCacheRetention: modelConfig.info.promptCacheRetention,
|
||||
},
|
||||
settings: this.options,
|
||||
settings: bedrockCacheSettings,
|
||||
})
|
||||
|
||||
// Build streamText request
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import { getModelEndpoints } from "./fetchers/modelEndpointCache"
|
|||
import { applyRouterToolPreferences } from "./utils/router-tool-preferences"
|
||||
import { generateImageWithProvider, ImageGenerationResult } from "./utils/image-generation"
|
||||
import { normalizeProviderUsage } from "./utils/normalize-provider-usage"
|
||||
import { toFiniteNumber, firstNumber } from "./utils/usage-metrics"
|
||||
|
||||
import type { ApiHandlerCreateMessageMetadata, SingleCompletionHandler } from "../index"
|
||||
import type { ApiStreamChunk } from "../transform/stream"
|
||||
|
|
@ -180,26 +179,14 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
|
|||
|
||||
const usage = await result.usage
|
||||
const totalUsage = await result.totalUsage
|
||||
const rawUsage = (usage as any)?.raw as Record<string, unknown> | undefined
|
||||
|
||||
// Prefer totalUsage (multi-step accumulation) over per-step usage;
|
||||
// all further fallback extraction is handled by the openrouter profile
|
||||
// in usage-profiles.ts via normalizeProviderUsage.
|
||||
const usageRecord = {
|
||||
...(usage as any),
|
||||
inputTokens: firstNumber([
|
||||
totalUsage.inputTokens,
|
||||
(usage as any).inputTokens,
|
||||
(usage as any).promptTokens,
|
||||
(usage as any).prompt_tokens,
|
||||
rawUsage?.prompt_tokens as number | undefined,
|
||||
rawUsage?.input_tokens as number | undefined,
|
||||
]),
|
||||
outputTokens: firstNumber([
|
||||
totalUsage.outputTokens,
|
||||
(usage as any).outputTokens,
|
||||
(usage as any).completionTokens,
|
||||
(usage as any).completion_tokens,
|
||||
rawUsage?.completion_tokens as number | undefined,
|
||||
rawUsage?.output_tokens as number | undefined,
|
||||
]),
|
||||
inputTokens: totalUsage.inputTokens ?? (usage as any).inputTokens,
|
||||
outputTokens: totalUsage.outputTokens ?? (usage as any).outputTokens,
|
||||
}
|
||||
const { chunk } = normalizeProviderUsage({
|
||||
provider: "openrouter",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue