From 95c0030c6a7b8132d875e62fd5f504c85a68ae47 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Mon, 29 Dec 2025 18:08:26 -0700 Subject: [PATCH] chore: remove unused manual logging leftovers --- src/api/providers/anthropic.ts | 16 ----- .../base-openai-compatible-provider.ts | 31 --------- src/api/providers/base-provider.ts | 6 +- src/api/providers/mistral.ts | 3 - src/api/providers/openai-native.ts | 15 +--- src/api/providers/openai.ts | 68 +------------------ src/api/providers/roo.ts | 11 --- 7 files changed, 3 insertions(+), 147 deletions(-) diff --git a/src/api/providers/anthropic.ts b/src/api/providers/anthropic.ts index 163bc2da26..59c239ac78 100644 --- a/src/api/providers/anthropic.ts +++ b/src/api/providers/anthropic.ts @@ -66,11 +66,6 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa reasoning: thinking, } = this.getModel() - // Accumulators for final response logging - const accumulatedText: string[] = [] - const accumulatedReasoning: string[] = [] - const toolCalls: Array<{ id?: string; name?: string }> = [] - // Filter out non-Anthropic blocks (reasoning, thoughtSignature, etc.) before sending to the API const sanitizedMessages = filterNonAnthropicBlocks(messages) @@ -263,30 +258,21 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa // We may receive multiple text blocks, in which // case just insert a line break between them. if (chunk.index > 0) { - accumulatedReasoning.push("\n") yield { type: "reasoning", text: "\n" } } - accumulatedReasoning.push(chunk.content_block.thinking) yield { type: "reasoning", text: chunk.content_block.thinking } break case "text": // We may receive multiple text blocks, in which // case just insert a line break between them. if (chunk.index > 0) { - accumulatedText.push("\n") yield { type: "text", text: "\n" } } - accumulatedText.push(chunk.content_block.text) yield { type: "text", text: chunk.content_block.text } break case "tool_use": { - // Track tool call for logging - toolCalls.push({ - id: chunk.content_block.id, - name: chunk.content_block.name, - }) // Emit initial tool call partial with id and name yield { type: "tool_call_partial", @@ -302,11 +288,9 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa case "content_block_delta": switch (chunk.delta.type) { case "thinking_delta": - accumulatedReasoning.push(chunk.delta.thinking) yield { type: "reasoning", text: chunk.delta.thinking } break case "text_delta": - accumulatedText.push(chunk.delta.text) yield { type: "text", text: chunk.delta.text } break case "input_json_delta": { diff --git a/src/api/providers/base-openai-compatible-provider.ts b/src/api/providers/base-openai-compatible-provider.ts index 2a343242a1..d402cb975b 100644 --- a/src/api/providers/base-openai-compatible-provider.ts +++ b/src/api/providers/base-openai-compatible-provider.ts @@ -121,37 +121,6 @@ export abstract class BaseOpenAiCompatibleProvider metadata?: ApiHandlerCreateMessageMetadata, ): ApiStream { const { id: model, info } = this.getModel() - - // Build the actual params object that will be passed to the SDK - const max_tokens = - getModelMaxOutputTokens({ - modelId: model, - model: info, - settings: this.options, - format: "openai", - }) ?? undefined - - const temperature = this.options.modelTemperature ?? this.defaultTemperature - - const requestParams: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = { - model, - max_tokens, - temperature, - messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)], - stream: true, - stream_options: { include_usage: true }, - ...(metadata?.tools && { tools: this.convertToolsForOpenAI(metadata.tools) }), - ...(metadata?.tool_choice && { tool_choice: metadata.tool_choice }), - ...(metadata?.toolProtocol === "native" && { - parallel_tool_calls: metadata.parallelToolCalls ?? false, - }), - } - - // Add thinking parameter if reasoning is enabled and model supports it - if (this.options.enableReasoningEffort && info.supportsReasoningBinary) { - ;(requestParams as any).thinking = { type: "enabled" } - } - let lastUsage: OpenAI.CompletionUsage | undefined const activeToolCallIds = new Set() diff --git a/src/api/providers/base-provider.ts b/src/api/providers/base-provider.ts index 80599e2c80..a19857466a 100644 --- a/src/api/providers/base-provider.ts +++ b/src/api/providers/base-provider.ts @@ -6,7 +6,6 @@ import type { ApiHandler, ApiHandlerCreateMessageMetadata } from "../index" import { ApiStream } from "../transform/stream" import { countTokens } from "../../utils/countTokens" import { isMcpTool } from "../../utils/mcp-name" -import { ApiInferenceLogger } from "../logging/ApiInferenceLogger" /** * Base class for API providers that implements common functionality. @@ -18,11 +17,8 @@ export abstract class BaseProvider implements ApiHandler { protected abstract readonly providerName: string /** - * Reference to the API inference logger singleton for logging requests/responses. - * Providers can use this to log inference calls when enabled. + * Providers implement inference by streaming chunks from their underlying SDK/transport. */ - protected readonly inferenceLogger = ApiInferenceLogger - abstract createMessage( systemPrompt: string, messages: Anthropic.Messages.MessageParam[], diff --git a/src/api/providers/mistral.ts b/src/api/providers/mistral.ts index c06083a505..10b3fa1f3b 100644 --- a/src/api/providers/mistral.ts +++ b/src/api/providers/mistral.ts @@ -102,9 +102,6 @@ export class MistralHandler extends BaseProvider implements SingleCompletionHand requestOptions.toolChoice = "any" } - // Temporary debug log for QA - // console.log("[MISTRAL DEBUG] Raw API request body:", requestOptions) - let response try { response = await this.client.chat.stream(requestOptions) diff --git a/src/api/providers/openai-native.ts b/src/api/providers/openai-native.ts index 8cb212f1fb..a99542ede3 100644 --- a/src/api/providers/openai-native.ts +++ b/src/api/providers/openai-native.ts @@ -181,24 +181,11 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio metadata, ) - // Accumulators for response logging - const accumulatedText: string[] = [] - const accumulatedReasoning: string[] = [] - const toolCalls: Array<{ id?: string; name?: string }> = [] let lastUsage: any // Make the request (pass systemPrompt and messages for potential retry) for await (const chunk of this.executeRequest(requestBody, model, metadata, systemPrompt, messages)) { - // Accumulate for logging - if (chunk.type === "text") { - accumulatedText.push(chunk.text) - } else if (chunk.type === "reasoning") { - accumulatedReasoning.push(chunk.text) - } else if (chunk.type === "tool_call" || chunk.type === "tool_call_partial") { - if (chunk.id || chunk.name) { - toolCalls.push({ id: chunk.id, name: chunk.name }) - } - } else if (chunk.type === "usage") { + if (chunk.type === "usage") { lastUsage = chunk } diff --git a/src/api/providers/openai.ts b/src/api/providers/openai.ts index f20d2e030c..35759f1e0d 100644 --- a/src/api/providers/openai.ts +++ b/src/api/providers/openai.ts @@ -100,10 +100,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl const deepseekReasoner = modelId.includes("deepseek-reasoner") || enabledR1Format const ark = modelUrl.includes(".volces.com") - // Accumulators for final response logging - const accumulatedText: string[] = [] - const accumulatedReasoning: string[] = [] - const toolCalls: Array<{ id?: string; name?: string }> = [] let lastUsage: any // Handle O3 family models separately with their own logging @@ -214,31 +210,18 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl if (delta.content) { for (const matchedChunk of matcher.update(delta.content)) { - if (matchedChunk.type === "text") { - accumulatedText.push(matchedChunk.text) - } else if (matchedChunk.type === "reasoning") { - accumulatedReasoning.push(matchedChunk.text) - } yield matchedChunk } } if ("reasoning_content" in delta && delta.reasoning_content) { - accumulatedReasoning.push((delta.reasoning_content as string | undefined) || "") yield { type: "reasoning", text: (delta.reasoning_content as string | undefined) || "", } } - // Track tool calls for logging and use processToolCalls for proper tool_call_end events - if (delta.tool_calls) { - for (const toolCall of delta.tool_calls) { - if (toolCall.id || toolCall.function?.name) { - toolCalls.push({ id: toolCall.id, name: toolCall.function?.name }) - } - } - } + // Use processToolCalls for proper tool_call_end events yield* this.processToolCalls(delta, finishReason, activeToolCallIds) if (chunk.usage) { @@ -247,11 +230,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl } for (const matchedChunk of matcher.final()) { - if (matchedChunk.type === "text") { - accumulatedText.push(matchedChunk.text) - } else if (matchedChunk.type === "reasoning") { - accumulatedReasoning.push(matchedChunk.text) - } yield matchedChunk } @@ -292,7 +270,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl if (message?.tool_calls) { for (const toolCall of message.tool_calls) { if (toolCall.type === "function") { - toolCalls.push({ id: toolCall.id, name: toolCall.function.name }) yield { type: "tool_call", id: toolCall.id, @@ -303,7 +280,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl } } - accumulatedText.push(message?.content || "") yield { type: "text", text: message?.content || "", @@ -380,9 +356,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl const modelInfo = this.getModel().info const methodIsAzureAiInference = this._isAzureAiInference(this.options.openAiBaseUrl) - // Accumulators for response logging - const accumulatedText: string[] = [] - const toolCalls: Array<{ id?: string; name?: string }> = [] let lastUsage: any if (this.options.openAiStreamingEnabled ?? true) { @@ -431,21 +404,12 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl if (delta) { if (delta.content) { - accumulatedText.push(delta.content) yield { type: "text", text: delta.content, } } - // Track tool calls for logging and use processToolCalls for proper tool_call_end events - if (delta.tool_calls) { - for (const toolCall of delta.tool_calls) { - if (toolCall.id || toolCall.function?.name) { - toolCalls.push({ id: toolCall.id, name: toolCall.function?.name }) - } - } - } yield* this.processToolCalls(delta, finishReason, activeToolCallIds) } @@ -496,7 +460,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl if (message?.tool_calls) { for (const toolCall of message.tool_calls) { if (toolCall.type === "function") { - toolCalls.push({ id: toolCall.id, name: toolCall.function.name }) yield { type: "tool_call", id: toolCall.id, @@ -507,7 +470,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl } } - accumulatedText.push(message?.content || "") yield { type: "text", text: message?.content || "", @@ -518,34 +480,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl } } - private async *handleStreamResponse(stream: AsyncIterable): ApiStream { - const activeToolCallIds = new Set() - - for await (const chunk of stream) { - const delta = chunk.choices?.[0]?.delta - const finishReason = chunk.choices?.[0]?.finish_reason - - if (delta) { - if (delta.content) { - yield { - type: "text", - text: delta.content, - } - } - - yield* this.processToolCalls(delta, finishReason, activeToolCallIds) - } - - if (chunk.usage) { - yield { - type: "usage", - inputTokens: chunk.usage.prompt_tokens || 0, - outputTokens: chunk.usage.completion_tokens || 0, - } - } - } - } - /** * Helper generator to process tool calls from a stream chunk. * Tracks active tool call IDs and yields tool_call_partial and tool_call_end events. diff --git a/src/api/providers/roo.ts b/src/api/providers/roo.ts index ff04258564..d0c2343a7b 100644 --- a/src/api/providers/roo.ts +++ b/src/api/providers/roo.ts @@ -128,9 +128,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider { const { id: model } = this.getModel() // Accumulators for final response logging - const accumulatedText: string[] = [] - const accumulatedReasoning: string[] = [] - const toolCalls: Array<{ id?: string; name?: string }> = [] try { // Reset reasoning_details accumulator for this request @@ -241,7 +238,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider { if (reasoningText) { hasYieldedReasoningFromDetails = true - accumulatedReasoning.push(reasoningText) yield { type: "reasoning", text: reasoningText } } } @@ -251,13 +247,11 @@ export class RooHandler extends BaseOpenAiCompatibleProvider { // Skip if we've already yielded from reasoning_details to avoid duplicate display. if ("reasoning" in delta && delta.reasoning && typeof delta.reasoning === "string") { if (!hasYieldedReasoningFromDetails) { - accumulatedReasoning.push(delta.reasoning) yield { type: "reasoning", text: delta.reasoning } } } else if ("reasoning_content" in delta && typeof delta.reasoning_content === "string") { // Also check for reasoning_content for backward compatibility if (!hasYieldedReasoningFromDetails) { - accumulatedReasoning.push(delta.reasoning_content) yield { type: "reasoning", text: delta.reasoning_content } } } @@ -265,10 +259,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider { // Emit raw tool call chunks - NativeToolCallParser handles state management if ("tool_calls" in delta && Array.isArray(delta.tool_calls)) { for (const toolCall of delta.tool_calls) { - // Track tool calls for logging - if (toolCall.id || toolCall.function?.name) { - toolCalls.push({ id: toolCall.id, name: toolCall.function?.name }) - } yield { type: "tool_call_partial", index: toolCall.index, @@ -280,7 +270,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider { } if (delta.content) { - accumulatedText.push(delta.content) yield { type: "text", text: delta.content,