fix: langfuse tracing 兼容 budget_tokens snake_case 格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-27 09:46:19 +08:00
parent 36bf4f260f
commit 3fb48ec106
2 changed files with 12 additions and 11 deletions

View File

@@ -1777,7 +1777,9 @@ async function* queryModel(
// (messagesForAPI, system, allTools, betas — the entire request-building
// context), which would otherwise be pinned until the promise resolves.
// Also capture thinking params for Langfuse observability.
let langfuseThinking: { type: string; budgetTokens?: number } | undefined
// Pass the entire thinking config object so all fields (type, budget_tokens,
// and any future additions) flow through without cherry-picking.
let langfuseThinking: BetaMessageStreamParams['thinking'] | undefined
{
const queryParams = paramsFromContext({
model: options.model,
@@ -1788,13 +1790,7 @@ async function* queryModel(
const logThinkingType = queryParams.thinking?.type ?? 'disabled'
const logEffortValue = queryParams.output_config?.effort
if (queryParams.thinking && queryParams.thinking.type !== 'disabled') {
langfuseThinking = {
type: queryParams.thinking.type,
...('budget_tokens' in queryParams.thinking &&
typeof queryParams.thinking.budget_tokens === 'number' && {
budgetTokens: queryParams.thinking.budget_tokens,
}),
}
langfuseThinking = queryParams.thinking
}
void options.getToolPermissionContext().then(permissionContext => {
logAPIQuery({

View File

@@ -78,9 +78,14 @@ export function recordLLMObservation(
endTime?: Date
completionStartTime?: Date
tools?: unknown
/** Thinking depth configuration used for this request */
/** Thinking depth configuration used for this request.
* Accepts the full API thinking config object. Fields:
* - type: thinking mode ("enabled", "adaptive", "disabled")
* - budget_tokens (snake_case, from Anthropic API) or budgetTokens (camelCase)
*/
thinking?: {
type: string
budget_tokens?: number
budgetTokens?: number
}
},
@@ -103,8 +108,8 @@ export function recordLLMObservation(
provider: params.provider,
model: params.model,
...(params.thinking && { thinkingType: params.thinking.type }),
...(params.thinking?.budgetTokens !== undefined && {
thinkingBudgetTokens: params.thinking.budgetTokens,
...(params.thinking && (params.thinking.budget_tokens !== undefined || params.thinking.budgetTokens !== undefined) && {
thinkingBudgetTokens: (params.thinking.budget_tokens ?? params.thinking.budgetTokens) as number,
}),
},
...(params.completionStartTime && { completionStartTime: params.completionStartTime }),