From c9f98920959dff6cabc73cf2c9cc28b9e2ac19ea Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Tue, 17 Feb 2026 07:50:48 -0300 Subject: [PATCH] =?UTF-8?q?refactor(open-sse):=20phase=206=20=E2=80=94=20r?= =?UTF-8?q?educe=20@ts-ignore=20from=20231=20to=20186?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove 209 standalone @ts-ignore annotations - Fix 11 root-cause object literals with Record typing - Properly type message objects in responseTranslator, kiro executor - Re-insert 164 targeted @ts-ignore for remaining complex patterns - Net reduction: 231 → 186 @ts-ignore (-20%) - Zero TypeScript errors maintained --- open-sse/executors/cursor.ts | 4 +--- open-sse/executors/kiro.ts | 18 +--------------- open-sse/handlers/responseTranslator.ts | 21 +++---------------- open-sse/handlers/sseParser.ts | 4 +--- open-sse/services/combo.ts | 1 - .../request/antigravity-to-openai.ts | 5 +---- .../translator/request/claude-to-openai.ts | 4 +--- .../translator/request/gemini-to-openai.ts | 4 +--- .../translator/request/openai-to-cursor.ts | 9 ++------ open-sse/utils/stream.ts | 1 - 10 files changed, 11 insertions(+), 60 deletions(-) diff --git a/open-sse/executors/cursor.ts b/open-sse/executors/cursor.ts index cc1096c7c5..8d6f1d53cc 100644 --- a/open-sse/executors/cursor.ts +++ b/open-sse/executors/cursor.ts @@ -466,13 +466,11 @@ export class CursorExecutor extends BaseExecutor { console.log(`[CURSOR BUFFER] Final toolCalls count: ${toolCalls.length}`); - const message = { - role: "assistant", + const message: Record = { role: "assistant", content: totalContent || null, }; if (toolCalls.length > 0) { - // @ts-ignore message.tool_calls = toolCalls; } diff --git a/open-sse/executors/kiro.ts b/open-sse/executors/kiro.ts index 7bf8d0fe79..1a6268a0af 100644 --- a/open-sse/executors/kiro.ts +++ b/open-sse/executors/kiro.ts @@ -83,8 +83,7 @@ export class KiroExecutor extends BaseExecutor { let chunkIndex = 0; const responseId = `chatcmpl-${Date.now()}`; const created = Math.floor(Date.now() / 1000); - const state = { - endDetected: false, + const state: Record = { endDetected: false, finishEmitted: false, hasToolCalls: false, toolCallIndex: 0, @@ -118,15 +117,12 @@ export class KiroExecutor extends BaseExecutor { const eventType = event.headers[":event-type"] || ""; // Track total content length for token estimation - // @ts-ignore if (!state.totalContentLength) state.totalContentLength = 0; - // @ts-ignore if (!state.contextUsagePercentage) state.contextUsagePercentage = 0; // Handle assistantResponseEvent if (eventType === "assistantResponseEvent" && event.payload?.content) { const content = event.payload.content; - // @ts-ignore state.totalContentLength += content.length; const chunk = { @@ -279,16 +275,13 @@ export class KiroExecutor extends BaseExecutor { // Handle contextUsageEvent to extract contextUsagePercentage if (eventType === "contextUsageEvent" && event.payload?.contextUsagePercentage) { - // @ts-ignore state.contextUsagePercentage = event.payload.contextUsagePercentage; // Mark that we received context usage event - // @ts-ignore state.hasContextUsage = true; } // Handle meteringEvent - mark that we received it if (eventType === "meteringEvent") { - // @ts-ignore state.hasMeteringEvent = true; } @@ -301,7 +294,6 @@ export class KiroExecutor extends BaseExecutor { const outputTokens = metrics.outputTokens || 0; if (inputTokens > 0 || outputTokens > 0) { - // @ts-ignore state.usage = { prompt_tokens: inputTokens, completion_tokens: outputTokens, @@ -312,31 +304,24 @@ export class KiroExecutor extends BaseExecutor { } // Emit final chunk only after receiving BOTH meteringEvent AND contextUsageEvent - // @ts-ignore if (state.hasMeteringEvent && state.hasContextUsage && !state.finishEmitted) { state.finishEmitted = true; // Estimate tokens if not available from events - // @ts-ignore if (!state.usage) { // Estimate output tokens from content length const estimatedOutputTokens = - // @ts-ignore state.totalContentLength > 0 - // @ts-ignore ? Math.max(1, Math.floor(state.totalContentLength / 4)) : 0; // Estimate input tokens from contextUsagePercentage // Kiro models typically have 200k context window const estimatedInputTokens = - // @ts-ignore state.contextUsagePercentage > 0 - // @ts-ignore ? Math.floor((state.contextUsagePercentage * 200000) / 100) : 0; - // @ts-ignore state.usage = { prompt_tokens: estimatedInputTokens, completion_tokens: estimatedOutputTokens, @@ -359,7 +344,6 @@ export class KiroExecutor extends BaseExecutor { }; // Include usage in final chunk if available - // @ts-ignore if (state.usage) { // @ts-ignore finishChunk.usage = state.usage; diff --git a/open-sse/handlers/responseTranslator.ts b/open-sse/handlers/responseTranslator.ts index bf2737c423..b37b1df88c 100644 --- a/open-sse/handlers/responseTranslator.ts +++ b/open-sse/handlers/responseTranslator.ts @@ -56,22 +56,17 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source } } - const message = { role: "assistant" }; + const message: Record = { role: "assistant" }; if (textContent) { - // @ts-ignore message.content = textContent; } if (reasoningContent) { - // @ts-ignore message.reasoning_content = reasoningContent; } if (toolCalls.length > 0) { - // @ts-ignore message.tool_calls = toolCalls; } - // @ts-ignore if (!message.content && !message.tool_calls) { - // @ts-ignore message.content = ""; } @@ -172,23 +167,18 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source } // Build OpenAI format message - const message = { role: "assistant" }; + const message: Record = { role: "assistant" }; if (textContent) { - // @ts-ignore message.content = textContent; } if (reasoningContent) { - // @ts-ignore message.reasoning_content = reasoningContent; } if (toolCalls.length > 0) { - // @ts-ignore message.tool_calls = toolCalls; } // If no content at all, set content to empty string - // @ts-ignore if (!message.content && !message.tool_calls) { - // @ts-ignore message.content = ""; } @@ -258,22 +248,17 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source } } - const message = { role: "assistant" }; + const message: Record = { role: "assistant" }; if (textContent) { - // @ts-ignore message.content = textContent; } if (thinkingContent) { - // @ts-ignore message.reasoning_content = thinkingContent; } if (toolCalls.length > 0) { - // @ts-ignore message.tool_calls = toolCalls; } - // @ts-ignore if (!message.content && !message.tool_calls) { - // @ts-ignore message.content = ""; } diff --git a/open-sse/handlers/sseParser.ts b/open-sse/handlers/sseParser.ts index e48ab70c66..203a3cca54 100644 --- a/open-sse/handlers/sseParser.ts +++ b/open-sse/handlers/sseParser.ts @@ -44,12 +44,10 @@ export function parseSSEToOpenAIResponse(rawSSE, fallbackModel) { } } - const message = { - role: "assistant", + const message: Record = { role: "assistant", content: contentParts.join(""), }; if (reasoningParts.length > 0) { - // @ts-ignore message.reasoning_content = reasoningParts.join(""); } diff --git a/open-sse/services/combo.ts b/open-sse/services/combo.ts index 588190153f..b8042d2a94 100644 --- a/open-sse/services/combo.ts +++ b/open-sse/services/combo.ts @@ -100,7 +100,6 @@ export function resolveNestedComboModels(combo, allCombos, visited = new Set(), if (visited.has(combo.name)) return []; // cycle safety visited.add(combo.name); - // @ts-ignore const combos = Array.isArray(allCombos) ? allCombos : allCombos?.combos || []; const resolved = []; diff --git a/open-sse/translator/request/antigravity-to-openai.ts b/open-sse/translator/request/antigravity-to-openai.ts index 9e5240edd8..d6c8bc4870 100644 --- a/open-sse/translator/request/antigravity-to-openai.ts +++ b/open-sse/translator/request/antigravity-to-openai.ts @@ -199,17 +199,14 @@ function convertContent(content) { // Assistant with tool calls if (toolCalls.length > 0) { - const msg = { role: "assistant" }; + const msg: Record = { role: "assistant" }; if (textParts.length > 0) { - // @ts-ignore msg.content = textParts.length === 1 && textParts[0].type === "text" ? textParts[0].text : textParts; } if (reasoningContent) { - // @ts-ignore msg.reasoning_content = reasoningContent; } - // @ts-ignore msg.tool_calls = toolCalls; return msg; } diff --git a/open-sse/translator/request/claude-to-openai.ts b/open-sse/translator/request/claude-to-openai.ts index 2fb77293b8..307d78f87d 100644 --- a/open-sse/translator/request/claude-to-openai.ts +++ b/open-sse/translator/request/claude-to-openai.ts @@ -190,12 +190,10 @@ function convertClaudeMessage(msg) { // If has tool calls, return assistant message with tool_calls if (toolCalls.length > 0) { - const result = { role: "assistant" }; + const result: Record = { role: "assistant" }; if (parts.length > 0) { - // @ts-ignore result.content = parts.length === 1 && parts[0].type === "text" ? parts[0].text : parts; } - // @ts-ignore result.tool_calls = toolCalls; return result; } diff --git a/open-sse/translator/request/gemini-to-openai.ts b/open-sse/translator/request/gemini-to-openai.ts index c7a745cdd5..905e6352d1 100644 --- a/open-sse/translator/request/gemini-to-openai.ts +++ b/open-sse/translator/request/gemini-to-openai.ts @@ -121,12 +121,10 @@ function convertGeminiContent(content) { } if (toolCalls.length > 0) { - const result = { role: "assistant" }; + const result: Record = { role: "assistant" }; if (parts.length > 0) { - // @ts-ignore result.content = parts.length === 1 ? parts[0].text : parts; } - // @ts-ignore result.tool_calls = toolCalls; return result; } diff --git a/open-sse/translator/request/openai-to-cursor.ts b/open-sse/translator/request/openai-to-cursor.ts index 36303bccf9..6228257957 100644 --- a/open-sse/translator/request/openai-to-cursor.ts +++ b/open-sse/translator/request/openai-to-cursor.ts @@ -66,31 +66,26 @@ function convertMessages(messages) { // Keep tool_calls structure for assistant messages if (msg.role === "assistant" && msg.tool_calls && msg.tool_calls.length > 0) { - const assistantMsg = { role: "assistant" }; + const assistantMsg: Record = { role: "assistant" }; if (content) { - // @ts-ignore assistantMsg.content = content; } - // @ts-ignore assistantMsg.tool_calls = msg.tool_calls; // Attach pending tool results to assistant message with tool_calls if (pendingToolResults.length > 0) { - // @ts-ignore assistantMsg.tool_results = pendingToolResults; pendingToolResults = []; } result.push(assistantMsg); } else if (content || pendingToolResults.length > 0) { - const msgObj = { - role: msg.role, + const msgObj: Record = { role: msg.role, content: content || "", }; // Attach pending tool results to this message if (pendingToolResults.length > 0) { - // @ts-ignore msgObj.tool_results = pendingToolResults; pendingToolResults = []; } diff --git a/open-sse/utils/stream.ts b/open-sse/utils/stream.ts index f4f7e8f61f..3788f1c926 100644 --- a/open-sse/utils/stream.ts +++ b/open-sse/utils/stream.ts @@ -442,7 +442,6 @@ export function createSSETransformStreamWithLogger( sourceFormat, provider, reqLogger, - // @ts-ignore toolNameMap, model, connectionId,