mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 05:45:51 +00:00
Compare commits
5 Commits
v2.4.4
...
revert-122
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bd8622d84 | ||
|
|
d66a6f6124 | ||
|
|
48a19b8a0d | ||
|
|
5157b09743 | ||
|
|
ecd3f9d791 |
@@ -16,6 +16,7 @@ export async function* adaptGeminiStreamToAnthropic(
|
||||
let finishReason: string | undefined
|
||||
let inputTokens = 0
|
||||
let outputTokens = 0
|
||||
let cachedReadTokens = 0
|
||||
|
||||
for await (const chunk of stream) {
|
||||
const usage = chunk.usageMetadata
|
||||
@@ -23,6 +24,7 @@ export async function* adaptGeminiStreamToAnthropic(
|
||||
inputTokens = usage.promptTokenCount ?? inputTokens
|
||||
outputTokens =
|
||||
(usage.candidatesTokenCount ?? 0) + (usage.thoughtsTokenCount ?? 0)
|
||||
cachedReadTokens = usage.cachedContentTokenCount ?? cachedReadTokens
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
@@ -41,7 +43,7 @@ export async function* adaptGeminiStreamToAnthropic(
|
||||
input_tokens: inputTokens,
|
||||
output_tokens: 0,
|
||||
cache_creation_input_tokens: 0,
|
||||
cache_read_input_tokens: 0,
|
||||
cache_read_input_tokens: cachedReadTokens,
|
||||
},
|
||||
},
|
||||
} as unknown as BetaRawMessageStreamEvent
|
||||
@@ -204,7 +206,10 @@ export async function* adaptGeminiStreamToAnthropic(
|
||||
stop_sequence: null,
|
||||
},
|
||||
usage: {
|
||||
input_tokens: inputTokens,
|
||||
output_tokens: outputTokens,
|
||||
cache_creation_input_tokens: 0,
|
||||
cache_read_input_tokens: cachedReadTokens,
|
||||
},
|
||||
} as BetaRawMessageStreamEvent
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ export type GeminiUsageMetadata = {
|
||||
candidatesTokenCount?: number
|
||||
thoughtsTokenCount?: number
|
||||
totalTokenCount?: number
|
||||
cachedContentTokenCount?: number
|
||||
}
|
||||
|
||||
export type GeminiCandidate = {
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
ChatCompletionCreateParamsStreaming,
|
||||
} from 'openai/resources/chat/completions/completions.mjs'
|
||||
import { getGrokClient } from './client.js'
|
||||
import { updateOpenAIUsage } from '../openai/openaiShared.js'
|
||||
import {
|
||||
anthropicMessagesToOpenAI,
|
||||
anthropicToolsToOpenAI,
|
||||
@@ -136,7 +137,7 @@ export async function* queryModelGrok(
|
||||
partialMessage = (event as any).message
|
||||
ttftMs = Date.now() - start
|
||||
if ((event as any).message?.usage) {
|
||||
usage = { ...usage, ...(event as any).message.usage }
|
||||
usage = updateOpenAIUsage(usage, (event as any).message.usage)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -192,7 +193,7 @@ export async function* queryModelGrok(
|
||||
case 'message_delta': {
|
||||
const deltaUsage = (event as any).usage
|
||||
if (deltaUsage) {
|
||||
usage = { ...usage, ...deltaUsage }
|
||||
usage = updateOpenAIUsage(usage, deltaUsage)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
import type { AgentId } from '../../../types/ids.js'
|
||||
import type { Tools } from '../../../Tool.js'
|
||||
import { getOpenAIClient } from './client.js'
|
||||
import { updateOpenAIUsage } from './openaiShared.js'
|
||||
import {
|
||||
anthropicMessagesToOpenAI,
|
||||
resolveOpenAIModel,
|
||||
@@ -449,7 +450,7 @@ export async function* queryModelOpenAI(
|
||||
case 'message_delta': {
|
||||
const deltaUsage = (event as any).usage
|
||||
if (deltaUsage) {
|
||||
usage = { ...usage, ...deltaUsage }
|
||||
usage = updateOpenAIUsage(usage, deltaUsage)
|
||||
}
|
||||
if ((event as any).delta?.stop_reason != null) {
|
||||
stopReason = (event as any).delta.stop_reason
|
||||
|
||||
46
src/services/api/openai/openaiShared.ts
Normal file
46
src/services/api/openai/openaiShared.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Shared utilities for OpenAI-compatible API paths.
|
||||
*
|
||||
* Both the OpenAI path (queryModelOpenAI) and Grok path (queryModelGrok) use
|
||||
* the same adapters (openaiStreamAdapter, openaiConvertMessages), so the event
|
||||
* processing logic should be shared rather than duplicated.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Merge a delta usage into the accumulated usage, preserving cache-related
|
||||
* fields from previous values when the delta carries explicit zeroes or
|
||||
* undefined values.
|
||||
*
|
||||
* Mirrors updateUsage() in claude.ts: a future adapter change that omits
|
||||
* cache fields from certain streaming events should not silently zero the
|
||||
* accumulated counters.
|
||||
*/
|
||||
export function updateOpenAIUsage(
|
||||
current: {
|
||||
input_tokens: number
|
||||
output_tokens: number
|
||||
cache_creation_input_tokens: number
|
||||
cache_read_input_tokens: number
|
||||
},
|
||||
delta: {
|
||||
input_tokens?: number
|
||||
output_tokens?: number
|
||||
cache_creation_input_tokens?: number
|
||||
cache_read_input_tokens?: number
|
||||
},
|
||||
): typeof current {
|
||||
return {
|
||||
input_tokens: delta.input_tokens ?? current.input_tokens,
|
||||
output_tokens: delta.output_tokens ?? current.output_tokens,
|
||||
cache_creation_input_tokens:
|
||||
delta.cache_creation_input_tokens !== undefined &&
|
||||
delta.cache_creation_input_tokens > 0
|
||||
? delta.cache_creation_input_tokens
|
||||
: current.cache_creation_input_tokens,
|
||||
cache_read_input_tokens:
|
||||
delta.cache_read_input_tokens !== undefined &&
|
||||
delta.cache_read_input_tokens > 0
|
||||
? delta.cache_read_input_tokens
|
||||
: current.cache_read_input_tokens,
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,9 @@ export function isOpenAIThinkingEnabled(model: string): boolean {
|
||||
if (isEnvDefinedFalsy(process.env.OPENAI_ENABLE_THINKING)) return false
|
||||
// Explicit enable
|
||||
if (isEnvTruthy(process.env.OPENAI_ENABLE_THINKING)) return true
|
||||
// Auto-detect from model name (DeepSeek and MiMo models support thinking mode)
|
||||
// Auto-detect from model name (DeepSeek and MiMo models support thinking mode).
|
||||
// Grok is intentionally excluded — Grok reasoning models reason automatically
|
||||
// and do NOT require thinking/enable_thinking request body parameters.
|
||||
const modelLower = model.toLowerCase()
|
||||
return modelLower.includes('deepseek') || modelLower.includes('mimo')
|
||||
}
|
||||
|
||||
@@ -1724,12 +1724,29 @@ export function getSubscriptionName(): string {
|
||||
}
|
||||
}
|
||||
|
||||
/** Check if using third-party services (Bedrock or Vertex or Foundry) */
|
||||
/**
|
||||
* Check if using third-party services (non-Anthropic providers).
|
||||
*
|
||||
* This function gates several behaviours that should only apply when the user
|
||||
* is NOT calling the first-party Anthropic API directly:
|
||||
* - auth status display (authStatus handler)
|
||||
* - command visibility (login/logout shown for non-3P)
|
||||
* - command availability checks (meetsAvailabilityRequirement)
|
||||
*
|
||||
* KEEP IN SYNC with providers.ts — when a new CLAUDE_CODE_USE_* env var is
|
||||
* added to getAPIProvider(), the corresponding check MUST be added here.
|
||||
* Providers whose selection is controlled purely via settings.modelType
|
||||
* (rather than env vars) are NOT covered by this function and may need
|
||||
* separate handling in the call sites above.
|
||||
*/
|
||||
export function isUsing3PServices(): boolean {
|
||||
return !!(
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK) ||
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_VERTEX) ||
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_FOUNDRY)
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_FOUNDRY) ||
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_OPENAI) ||
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_GEMINI) ||
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_GROK)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user