fix(types): replace all as any with proper type assertions

Eliminate unsafe `as any` casts across 21 non-test source files,
replacing them with specific type annotations:

- Bridge transport: use StdoutMessage type for write/writeBatch calls
- print.ts: type msg.request as Record<string, unknown> for unknown
  SDK control subtypes; use StdoutMessage for output.enqueue()
- API providers (openai/grok/gemini): import ChatCompletion types,
  type streams as AsyncIterable<ChatCompletionChunk>, type request
  bodies as ChatCompletionCreateParamsStreaming
- Computer use executor: use Partial<ResolvePrepareCaptureResult>
  for cross-platform screenshot result
- Components: replace Ink color string casts with proper typing
- Win32 bridge: type stdin as Writable after null check

All 2453 tests pass with 0 failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-09 23:51:33 +08:00
parent a14d3dc8f0
commit 34bbc1d403
19 changed files with 317 additions and 231 deletions

View File

@@ -1,6 +1,6 @@
import OpenAI from 'openai'
import { getProxyFetchOptions } from 'src/utils/proxy.js'
import { isEnvTruthy } from '../../utils/envUtils.js'
import { isEnvTruthy } from 'src/utils/envUtils.js'
/**
* Environment variables:

View File

@@ -7,6 +7,11 @@ import type {
AssistantMessage,
} from '../../../types/message.js'
import type { Tools } from '../../../Tool.js'
import type { Stream } from 'openai/streaming.mjs'
import type {
ChatCompletionChunk,
ChatCompletionCreateParamsStreaming,
} from 'openai/resources/chat/completions/completions.mjs'
import { getOpenAIClient } from './client.js'
import { anthropicMessagesToOpenAI } from './convertMessages.js'
import {
@@ -82,7 +87,7 @@ export function buildOpenAIRequestBody(params: {
toolChoice: any
enableThinking: boolean
temperatureOverride?: number
}): Record<string, any> {
}): ChatCompletionCreateParamsStreaming {
const { model, messages, tools, toolChoice, enableThinking, temperatureOverride } = params
return {
model,
@@ -183,7 +188,7 @@ export async function* queryModelOpenAI(
// 7. Filter out non-standard tools (server tools like advisor)
const standardTools = toolSchemas.filter(
(t): t is BetaToolUnion & { type: string } => {
const anyT = t as Record<string, unknown>
const anyT = t as unknown as Record<string, unknown>
return (
anyT.type !== 'advisor_20260301' && anyT.type !== 'computer_20250124'
)
@@ -349,7 +354,7 @@ export async function* queryModelOpenAI(
yield createAssistantAPIErrorMessage({
content: `API Error: ${errorMessage}`,
apiError: 'api_error',
error: error instanceof Error ? error : new Error(String(error)),
error: (error instanceof Error ? error : new Error(String(error))) as Error,
})
}
}