chore: remove unused manual logging leftovers

This commit is contained in:
Hannes Rudolph 2025-12-29 18:08:26 -07:00
parent 099cf851f9
commit 95c0030c6a
7 changed files with 3 additions and 147 deletions

View file

@ -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": {

View file

@ -121,37 +121,6 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
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<string>()

View file

@ -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[],

View file

@ -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)

View file

@ -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
}

View file

@ -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<OpenAI.Chat.Completions.ChatCompletionChunk>): ApiStream {
const activeToolCallIds = new Set<string>()
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.

View file

@ -128,9 +128,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
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<string> {
if (reasoningText) {
hasYieldedReasoningFromDetails = true
accumulatedReasoning.push(reasoningText)
yield { type: "reasoning", text: reasoningText }
}
}
@ -251,13 +247,11 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
// 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<string> {
// 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<string> {
}
if (delta.content) {
accumulatedText.push(delta.content)
yield {
type: "text",
text: delta.content,