mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
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:
@@ -56,7 +56,7 @@ export async function* queryModelGemini(
|
||||
|
||||
const standardTools = toolSchemas.filter(
|
||||
(t): t is BetaToolUnion & { type: string } => {
|
||||
const anyTool = t as Record<string, unknown>
|
||||
const anyTool = t as unknown as Record<string, unknown>
|
||||
return (
|
||||
anyTool.type !== 'advisor_20260301' &&
|
||||
anyTool.type !== 'computer_20250124'
|
||||
@@ -186,7 +186,7 @@ export async function* queryModelGemini(
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ import type { BetaToolUnion } from '@anthropic-ai/sdk/resources/beta/messages/me
|
||||
import type { SystemPrompt } from '../../../utils/systemPromptType.js'
|
||||
import type { Message, StreamEvent, SystemAPIErrorMessage, AssistantMessage } from '../../../types/message.js'
|
||||
import type { Tools } from '../../../Tool.js'
|
||||
import type {
|
||||
ChatCompletionChunk,
|
||||
ChatCompletionCreateParamsStreaming,
|
||||
} from 'openai/resources/chat/completions/completions.mjs'
|
||||
import { getGrokClient } from './client.js'
|
||||
import { anthropicMessagesToOpenAI } from '../openai/convertMessages.js'
|
||||
import { anthropicToolsToOpenAI, anthropicToolChoiceToOpenAI } from '../openai/convertTools.js'
|
||||
@@ -51,7 +55,7 @@ export async function* queryModelGrok(
|
||||
)
|
||||
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'
|
||||
},
|
||||
)
|
||||
@@ -62,7 +66,7 @@ export async function* queryModelGrok(
|
||||
|
||||
const client = getGrokClient({
|
||||
maxRetries: 0,
|
||||
fetchOverride: options.fetchOverride,
|
||||
fetchOverride: options.fetchOverride as typeof fetch | undefined,
|
||||
source: options.querySource,
|
||||
})
|
||||
|
||||
@@ -81,13 +85,13 @@ export async function* queryModelGrok(
|
||||
...(options.temperatureOverride !== undefined && {
|
||||
temperature: options.temperatureOverride,
|
||||
}),
|
||||
},
|
||||
} as ChatCompletionCreateParamsStreaming,
|
||||
{
|
||||
signal,
|
||||
},
|
||||
)
|
||||
|
||||
const adaptedStream = adaptOpenAIStreamToAnthropic(stream, grokModel)
|
||||
const adaptedStream = adaptOpenAIStreamToAnthropic(stream as AsyncIterable<ChatCompletionChunk>, grokModel)
|
||||
|
||||
const contentBlocks: Record<number, any> = {}
|
||||
let partialMessage: any = undefined
|
||||
@@ -186,7 +190,7 @@ export async function* queryModelGrok(
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user