feat(opencode): Handle Venice cache creation tokens (#10735)
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
This commit is contained in:
@@ -426,11 +426,20 @@ export namespace Session {
|
|||||||
metadata: z.custom<ProviderMetadata>().optional(),
|
metadata: z.custom<ProviderMetadata>().optional(),
|
||||||
}),
|
}),
|
||||||
(input) => {
|
(input) => {
|
||||||
const cachedInputTokens = input.usage.cachedInputTokens ?? 0
|
const cacheReadInputTokens = input.usage.cachedInputTokens ?? 0
|
||||||
|
const cacheWriteInputTokens = (
|
||||||
|
input.metadata?.["anthropic"]?.["cacheCreationInputTokens"] ??
|
||||||
|
// @ts-expect-error
|
||||||
|
input.metadata?.["bedrock"]?.["usage"]?.["cacheWriteInputTokens"] ??
|
||||||
|
// @ts-expect-error
|
||||||
|
input.metadata?.["venice"]?.["usage"]?.["cacheCreationInputTokens"] ??
|
||||||
|
0
|
||||||
|
) as number
|
||||||
|
|
||||||
const excludesCachedTokens = !!(input.metadata?.["anthropic"] || input.metadata?.["bedrock"])
|
const excludesCachedTokens = !!(input.metadata?.["anthropic"] || input.metadata?.["bedrock"])
|
||||||
const adjustedInputTokens = excludesCachedTokens
|
const adjustedInputTokens = excludesCachedTokens
|
||||||
? (input.usage.inputTokens ?? 0)
|
? (input.usage.inputTokens ?? 0)
|
||||||
: (input.usage.inputTokens ?? 0) - cachedInputTokens
|
: (input.usage.inputTokens ?? 0) - cacheReadInputTokens - cacheWriteInputTokens
|
||||||
const safe = (value: number) => {
|
const safe = (value: number) => {
|
||||||
if (!Number.isFinite(value)) return 0
|
if (!Number.isFinite(value)) return 0
|
||||||
return value
|
return value
|
||||||
@@ -441,13 +450,8 @@ export namespace Session {
|
|||||||
output: safe(input.usage.outputTokens ?? 0),
|
output: safe(input.usage.outputTokens ?? 0),
|
||||||
reasoning: safe(input.usage?.reasoningTokens ?? 0),
|
reasoning: safe(input.usage?.reasoningTokens ?? 0),
|
||||||
cache: {
|
cache: {
|
||||||
write: safe(
|
write: safe(cacheWriteInputTokens),
|
||||||
(input.metadata?.["anthropic"]?.["cacheCreationInputTokens"] ??
|
read: safe(cacheReadInputTokens),
|
||||||
// @ts-expect-error
|
|
||||||
input.metadata?.["bedrock"]?.["usage"]?.["cacheWriteInputTokens"] ??
|
|
||||||
0) as number,
|
|
||||||
),
|
|
||||||
read: safe(cachedInputTokens),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user