fix: 修复类型问题

This commit is contained in:
claude-code-best
2026-04-10 17:34:01 +08:00
parent e70319e8f5
commit ff03fe7fcb
18 changed files with 70 additions and 56 deletions

View File

@@ -14,6 +14,7 @@ import {
normalizeContentFromAPI,
normalizeMessagesForAPI,
} from '../../../utils/messages.js'
import type { SDKAssistantMessageError } from '../../../entrypoints/agentSdkTypes.js'
import type { SystemPrompt } from '../../../utils/systemPromptType.js'
import type { ThinkingConfig } from '../../../utils/thinking.js'
import type { Options } from '../claude.js'
@@ -186,7 +187,7 @@ export async function* queryModelGemini(
yield createAssistantAPIErrorMessage({
content: `API Error: ${errorMessage}`,
apiError: 'api_error',
error: (error instanceof Error ? error : new Error(String(error))) as Error,
error: (error instanceof Error ? error : new Error(String(error))) as unknown as SDKAssistantMessageError,
})
}
}

View File

@@ -28,7 +28,7 @@ export function getGrokClient(options?: {
maxRetries: options?.maxRetries ?? 0,
timeout: parseInt(process.env.API_TIMEOUT_MS || String(600 * 1000), 10),
dangerouslyAllowBrowser: true,
fetchOptions: getProxyFetchOptions({ forAnthropicAPI: false }) as RequestInit,
fetchOptions: getProxyFetchOptions({ forAnthropicAPI: false }),
...(options?.fetchOverride && { fetch: options.fetchOverride }),
})

View File

@@ -12,6 +12,7 @@ import { anthropicToolsToOpenAI, anthropicToolChoiceToOpenAI } from '../openai/c
import { adaptOpenAIStreamToAnthropic } from '../openai/streamAdapter.js'
import { resolveGrokModel } from './modelMapping.js'
import { normalizeMessagesForAPI } from '../../../utils/messages.js'
import type { SDKAssistantMessageError } from '../../../entrypoints/agentSdkTypes.js'
import { toolToAPISchema } from '../../../utils/api.js'
import { logForDebugging } from '../../../utils/debug.js'
import { addToTotalSessionCost } from '../../../cost-tracker.js'
@@ -190,7 +191,7 @@ export async function* queryModelGrok(
yield createAssistantAPIErrorMessage({
content: `API Error: ${errorMessage}`,
apiError: 'api_error',
error: (error instanceof Error ? error : new Error(String(error))) as Error,
error: (error instanceof Error ? error : new Error(String(error))) as unknown as SDKAssistantMessageError,
})
}
}

View File

@@ -151,7 +151,7 @@ describe('buildOpenAIRequestBody — thinking params', () => {
messages: [{ role: 'user', content: 'hello' }],
tools: [] as any[],
toolChoice: undefined as any,
}
} as any
test('includes official DeepSeek API thinking format when enabled', () => {
const body = buildOpenAIRequestBody({ ...baseParams, enableThinking: true })

View File

@@ -31,7 +31,7 @@ export function getOpenAIClient(options?: {
dangerouslyAllowBrowser: true,
...(process.env.OPENAI_ORG_ID && { organization: process.env.OPENAI_ORG_ID }),
...(process.env.OPENAI_PROJECT_ID && { project: process.env.OPENAI_PROJECT_ID }),
fetchOptions: getProxyFetchOptions({ forAnthropicAPI: false }) as RequestInit,
fetchOptions: getProxyFetchOptions({ forAnthropicAPI: false }),
...(options?.fetchOverride && { fetch: options.fetchOverride }),
})

View File

@@ -36,6 +36,7 @@ import {
createAssistantAPIErrorMessage,
normalizeContentFromAPI,
} from '../../../utils/messages.js'
import type { SDKAssistantMessageError } from '../../../entrypoints/agentSdkTypes.js'
import {
isToolSearchEnabled,
extractDiscoveredToolNames,
@@ -87,7 +88,11 @@ export function buildOpenAIRequestBody(params: {
toolChoice: any
enableThinking: boolean
temperatureOverride?: number
}): ChatCompletionCreateParamsStreaming {
}): ChatCompletionCreateParamsStreaming & {
thinking?: { type: string }
enable_thinking?: boolean
chat_template_kwargs?: { thinking: boolean }
} {
const { model, messages, tools, toolChoice, enableThinking, temperatureOverride } = params
return {
model,
@@ -220,7 +225,7 @@ export async function* queryModelOpenAI(
// 10. Get client and make streaming request
const client = getOpenAIClient({
maxRetries: 0,
fetchOverride: options.fetchOverride,
fetchOverride: options.fetchOverride as unknown as typeof fetch,
source: options.querySource,
})
@@ -354,7 +359,7 @@ export async function* queryModelOpenAI(
yield createAssistantAPIErrorMessage({
content: `API Error: ${errorMessage}`,
apiError: 'api_error',
error: (error instanceof Error ? error : new Error(String(error))) as Error,
error: (error instanceof Error ? error : new Error(String(error))) as unknown as SDKAssistantMessageError,
})
}
}