Skip to content

Commit 342ecf6

Browse files
committed
chore: remove unused manual logging leftovers
1 parent ec76f93 commit 342ecf6

File tree

8 files changed

+3
-157
lines changed

8 files changed

+3
-157
lines changed

src/api/providers/anthropic.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
6666
reasoning: thinking,
6767
} = this.getModel()
6868

69-
// Accumulators for final response logging
70-
const accumulatedText: string[] = []
71-
const accumulatedReasoning: string[] = []
72-
const toolCalls: Array<{ id?: string; name?: string }> = []
73-
7469
// Filter out non-Anthropic blocks (reasoning, thoughtSignature, etc.) before sending to the API
7570
const sanitizedMessages = filterNonAnthropicBlocks(messages)
7671

@@ -263,30 +258,21 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
263258
// We may receive multiple text blocks, in which
264259
// case just insert a line break between them.
265260
if (chunk.index > 0) {
266-
accumulatedReasoning.push("\n")
267261
yield { type: "reasoning", text: "\n" }
268262
}
269263

270-
accumulatedReasoning.push(chunk.content_block.thinking)
271264
yield { type: "reasoning", text: chunk.content_block.thinking }
272265
break
273266
case "text":
274267
// We may receive multiple text blocks, in which
275268
// case just insert a line break between them.
276269
if (chunk.index > 0) {
277-
accumulatedText.push("\n")
278270
yield { type: "text", text: "\n" }
279271
}
280272

281-
accumulatedText.push(chunk.content_block.text)
282273
yield { type: "text", text: chunk.content_block.text }
283274
break
284275
case "tool_use": {
285-
// Track tool call for logging
286-
toolCalls.push({
287-
id: chunk.content_block.id,
288-
name: chunk.content_block.name,
289-
})
290276
// Emit initial tool call partial with id and name
291277
yield {
292278
type: "tool_call_partial",
@@ -302,11 +288,9 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
302288
case "content_block_delta":
303289
switch (chunk.delta.type) {
304290
case "thinking_delta":
305-
accumulatedReasoning.push(chunk.delta.thinking)
306291
yield { type: "reasoning", text: chunk.delta.thinking }
307292
break
308293
case "text_delta":
309-
accumulatedText.push(chunk.delta.text)
310294
yield { type: "text", text: chunk.delta.text }
311295
break
312296
case "input_json_delta": {

src/api/providers/base-openai-compatible-provider.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,36 +121,6 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
121121
metadata?: ApiHandlerCreateMessageMetadata,
122122
): ApiStream {
123123
const { id: model, info } = this.getModel()
124-
125-
// Build the actual params object that will be passed to the SDK
126-
const max_tokens =
127-
getModelMaxOutputTokens({
128-
modelId: model,
129-
model: info,
130-
settings: this.options,
131-
format: "openai",
132-
}) ?? undefined
133-
134-
const temperature = this.options.modelTemperature ?? this.defaultTemperature
135-
136-
const requestParams: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {
137-
model,
138-
max_tokens,
139-
temperature,
140-
messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
141-
stream: true,
142-
stream_options: { include_usage: true },
143-
...(metadata?.tools && { tools: this.convertToolsForOpenAI(metadata.tools) }),
144-
...(metadata?.tool_choice && { tool_choice: metadata.tool_choice }),
145-
...(metadata?.toolProtocol === "native" && {
146-
parallel_tool_calls: metadata.parallelToolCalls ?? false,
147-
}),
148-
}
149-
150-
// Add thinking parameter if reasoning is enabled and model supports it
151-
if (this.options.enableReasoningEffort && info.supportsReasoningBinary) {
152-
;(requestParams as any).thinking = { type: "enabled" }
153-
}
154124
let lastUsage: OpenAI.CompletionUsage | undefined
155125

156126
const stream = await this.createStream(systemPrompt, messages, metadata)

src/api/providers/base-provider.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { ApiHandler, ApiHandlerCreateMessageMetadata } from "../index"
66
import { ApiStream } from "../transform/stream"
77
import { countTokens } from "../../utils/countTokens"
88
import { isMcpTool } from "../../utils/mcp-name"
9-
import { ApiInferenceLogger } from "../logging/ApiInferenceLogger"
109

1110
/**
1211
* Base class for API providers that implements common functionality.
@@ -18,11 +17,8 @@ export abstract class BaseProvider implements ApiHandler {
1817
protected abstract readonly providerName: string
1918

2019
/**
21-
* Reference to the API inference logger singleton for logging requests/responses.
22-
* Providers can use this to log inference calls when enabled.
20+
* Providers implement inference by streaming chunks from their underlying SDK/transport.
2321
*/
24-
protected readonly inferenceLogger = ApiInferenceLogger
25-
2622
abstract createMessage(
2723
systemPrompt: string,
2824
messages: Anthropic.Messages.MessageParam[],

src/api/providers/mistral.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ export class MistralHandler extends BaseProvider implements SingleCompletionHand
102102
requestOptions.toolChoice = "any"
103103
}
104104

105-
// Temporary debug log for QA
106-
// console.log("[MISTRAL DEBUG] Raw API request body:", requestOptions)
107-
108105
let response
109106
try {
110107
response = await this.client.chat.stream(requestOptions)

src/api/providers/openai-native.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,11 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
181181
metadata,
182182
)
183183

184-
// Accumulators for response logging
185-
const accumulatedText: string[] = []
186-
const accumulatedReasoning: string[] = []
187-
const toolCalls: Array<{ id?: string; name?: string }> = []
188184
let lastUsage: any
189185

190186
// Make the request (pass systemPrompt and messages for potential retry)
191187
for await (const chunk of this.executeRequest(requestBody, model, metadata, systemPrompt, messages)) {
192-
// Accumulate for logging
193-
if (chunk.type === "text") {
194-
accumulatedText.push(chunk.text)
195-
} else if (chunk.type === "reasoning") {
196-
accumulatedReasoning.push(chunk.text)
197-
} else if (chunk.type === "tool_call" || chunk.type === "tool_call_partial") {
198-
if (chunk.id || chunk.name) {
199-
toolCalls.push({ id: chunk.id, name: chunk.name })
200-
}
201-
} else if (chunk.type === "usage") {
188+
if (chunk.type === "usage") {
202189
lastUsage = chunk
203190
}
204191

src/api/providers/openai.ts

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
9999
const deepseekReasoner = modelId.includes("deepseek-reasoner") || enabledR1Format
100100
const ark = modelUrl.includes(".volces.com")
101101

102-
// Accumulators for final response logging
103-
const accumulatedText: string[] = []
104-
const accumulatedReasoning: string[] = []
105-
const toolCalls: Array<{ id?: string; name?: string }> = []
106102
let lastUsage: any
107103

108104
// Handle O3 family models separately with their own logging
@@ -213,31 +209,18 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
213209

214210
if (delta.content) {
215211
for (const matchedChunk of matcher.update(delta.content)) {
216-
if (matchedChunk.type === "text") {
217-
accumulatedText.push(matchedChunk.text)
218-
} else if (matchedChunk.type === "reasoning") {
219-
accumulatedReasoning.push(matchedChunk.text)
220-
}
221212
yield matchedChunk
222213
}
223214
}
224215

225216
if ("reasoning_content" in delta && delta.reasoning_content) {
226-
accumulatedReasoning.push((delta.reasoning_content as string | undefined) || "")
227217
yield {
228218
type: "reasoning",
229219
text: (delta.reasoning_content as string | undefined) || "",
230220
}
231221
}
232222

233-
// Track tool calls for logging and use processToolCalls for proper tool_call_end events
234-
if (delta.tool_calls) {
235-
for (const toolCall of delta.tool_calls) {
236-
if (toolCall.id || toolCall.function?.name) {
237-
toolCalls.push({ id: toolCall.id, name: toolCall.function?.name })
238-
}
239-
}
240-
}
223+
// Use processToolCalls for proper tool_call_end events
241224
yield* this.processToolCalls(delta, finishReason, activeToolCallIds)
242225

243226
if (chunk.usage) {
@@ -246,11 +229,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
246229
}
247230

248231
for (const matchedChunk of matcher.final()) {
249-
if (matchedChunk.type === "text") {
250-
accumulatedText.push(matchedChunk.text)
251-
} else if (matchedChunk.type === "reasoning") {
252-
accumulatedReasoning.push(matchedChunk.text)
253-
}
254232
yield matchedChunk
255233
}
256234

@@ -291,7 +269,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
291269
if (message?.tool_calls) {
292270
for (const toolCall of message.tool_calls) {
293271
if (toolCall.type === "function") {
294-
toolCalls.push({ id: toolCall.id, name: toolCall.function.name })
295272
yield {
296273
type: "tool_call",
297274
id: toolCall.id,
@@ -302,7 +279,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
302279
}
303280
}
304281

305-
accumulatedText.push(message?.content || "")
306282
yield {
307283
type: "text",
308284
text: message?.content || "",
@@ -373,9 +349,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
373349
const modelInfo = this.getModel().info
374350
const methodIsAzureAiInference = this._isAzureAiInference(this.options.openAiBaseUrl)
375351

376-
// Accumulators for response logging
377-
const accumulatedText: string[] = []
378-
const toolCalls: Array<{ id?: string; name?: string }> = []
379352
let lastUsage: any
380353

381354
if (this.options.openAiStreamingEnabled ?? true) {
@@ -424,21 +397,12 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
424397

425398
if (delta) {
426399
if (delta.content) {
427-
accumulatedText.push(delta.content)
428400
yield {
429401
type: "text",
430402
text: delta.content,
431403
}
432404
}
433405

434-
// Track tool calls for logging and use processToolCalls for proper tool_call_end events
435-
if (delta.tool_calls) {
436-
for (const toolCall of delta.tool_calls) {
437-
if (toolCall.id || toolCall.function?.name) {
438-
toolCalls.push({ id: toolCall.id, name: toolCall.function?.name })
439-
}
440-
}
441-
}
442406
yield* this.processToolCalls(delta, finishReason, activeToolCallIds)
443407
}
444408

@@ -489,7 +453,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
489453
if (message?.tool_calls) {
490454
for (const toolCall of message.tool_calls) {
491455
if (toolCall.type === "function") {
492-
toolCalls.push({ id: toolCall.id, name: toolCall.function.name })
493456
yield {
494457
type: "tool_call",
495458
id: toolCall.id,
@@ -500,7 +463,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
500463
}
501464
}
502465

503-
accumulatedText.push(message?.content || "")
504466
yield {
505467
type: "text",
506468
text: message?.content || "",
@@ -511,34 +473,6 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
511473
}
512474
}
513475

514-
private async *handleStreamResponse(stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>): ApiStream {
515-
const activeToolCallIds = new Set<string>()
516-
517-
for await (const chunk of stream) {
518-
const delta = chunk.choices?.[0]?.delta
519-
const finishReason = chunk.choices?.[0]?.finish_reason
520-
521-
if (delta) {
522-
if (delta.content) {
523-
yield {
524-
type: "text",
525-
text: delta.content,
526-
}
527-
}
528-
529-
yield* this.processToolCalls(delta, finishReason, activeToolCallIds)
530-
}
531-
532-
if (chunk.usage) {
533-
yield {
534-
type: "usage",
535-
inputTokens: chunk.usage.prompt_tokens || 0,
536-
outputTokens: chunk.usage.completion_tokens || 0,
537-
}
538-
}
539-
}
540-
}
541-
542476
/**
543477
* Helper generator to process tool calls from a stream chunk.
544478
* Tracks active tool call IDs and yields tool_call_partial and tool_call_end events.

src/api/providers/openrouter.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,6 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
329329
? { headers: { "x-anthropic-beta": "fine-grained-tool-streaming-2025-05-14" } }
330330
: undefined
331331

332-
// Accumulators for response logging
333-
const accumulatedText: string[] = []
334-
const accumulatedReasoning: string[] = []
335-
const toolCalls: Array<{ id?: string; name?: string }> = []
336-
337332
let stream
338333
try {
339334
stream = await this.client.chat.completions.create(completionParams, requestOptions)
@@ -459,23 +454,18 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
459454
// Note: reasoning.encrypted types are intentionally skipped as they contain redacted content
460455

461456
if (reasoningText) {
462-
accumulatedReasoning.push(reasoningText)
463457
yield { type: "reasoning", text: reasoningText }
464458
}
465459
}
466460
} else if ("reasoning" in delta && delta.reasoning && typeof delta.reasoning === "string") {
467461
// Handle legacy reasoning format - only if reasoning_details is not present
468462
// See: https://openrouter.ai/docs/use-cases/reasoning-tokens
469-
accumulatedReasoning.push(delta.reasoning)
470463
yield { type: "reasoning", text: delta.reasoning }
471464
}
472465

473466
// Emit raw tool call chunks - NativeToolCallParser handles state management
474467
if ("tool_calls" in delta && Array.isArray(delta.tool_calls)) {
475468
for (const toolCall of delta.tool_calls) {
476-
if (toolCall.id || toolCall.function?.name) {
477-
toolCalls.push({ id: toolCall.id, name: toolCall.function?.name })
478-
}
479469
yield {
480470
type: "tool_call_partial",
481471
index: toolCall.index,
@@ -487,7 +477,6 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
487477
}
488478

489479
if (delta.content) {
490-
accumulatedText.push(delta.content)
491480
yield { type: "text", text: delta.content }
492481
}
493482
}

src/api/providers/roo.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
128128
const { id: model } = this.getModel()
129129

130130
// Accumulators for final response logging
131-
const accumulatedText: string[] = []
132-
const accumulatedReasoning: string[] = []
133-
const toolCalls: Array<{ id?: string; name?: string }> = []
134131

135132
try {
136133
// Reset reasoning_details accumulator for this request
@@ -228,20 +225,17 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
228225
// Note: reasoning.encrypted types are intentionally skipped as they contain redacted content
229226

230227
if (reasoningText) {
231-
accumulatedReasoning.push(reasoningText)
232228
yield { type: "reasoning", text: reasoningText }
233229
}
234230
}
235231
} else if ("reasoning" in delta && delta.reasoning && typeof delta.reasoning === "string") {
236232
// Handle legacy reasoning format - only if reasoning_details is not present
237-
accumulatedReasoning.push(delta.reasoning)
238233
yield {
239234
type: "reasoning",
240235
text: delta.reasoning,
241236
}
242237
} else if ("reasoning_content" in delta && typeof delta.reasoning_content === "string") {
243238
// Also check for reasoning_content for backward compatibility
244-
accumulatedReasoning.push(delta.reasoning_content)
245239
yield {
246240
type: "reasoning",
247241
text: delta.reasoning_content,
@@ -251,10 +245,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
251245
// Emit raw tool call chunks - NativeToolCallParser handles state management
252246
if ("tool_calls" in delta && Array.isArray(delta.tool_calls)) {
253247
for (const toolCall of delta.tool_calls) {
254-
// Track tool calls for logging
255-
if (toolCall.id || toolCall.function?.name) {
256-
toolCalls.push({ id: toolCall.id, name: toolCall.function?.name })
257-
}
258248
yield {
259249
type: "tool_call_partial",
260250
index: toolCall.index,
@@ -266,7 +256,6 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
266256
}
267257

268258
if (delta.content) {
269-
accumulatedText.push(delta.content)
270259
yield {
271260
type: "text",
272261
text: delta.content,

0 commit comments

Comments
 (0)