mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 22:05:50 +00:00
- 新建 workspace 包 packages/@anthropic-ai/model-provider - 定义 ModelProviderHooks 接口(依赖注入:分析、成本、日志等) - 定义 ClientFactories 接口(Anthropic/OpenAI/Gemini/Grok 客户端工厂) - 搬入核心类型:Message 体系、NonNullableUsage、EMPTY_USAGE、SystemPrompt、错误常量 - 主项目 src/types/message.ts 等改为 re-export,保持向后兼容 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
// @anthropic-ai/model-provider
|
|
// Model provider abstraction layer for Claude Code
|
|
//
|
|
// This package owns the model calling logic and provides:
|
|
// - Core query functions (queryModelWithStreaming, etc.)
|
|
// - Provider implementations (Anthropic, OpenAI, Gemini, Grok)
|
|
// - Type definitions (Message, Tool, Usage, etc.)
|
|
// - Dependency injection hooks (analytics, cost tracking, etc.)
|
|
//
|
|
// Initialization:
|
|
// registerClientFactories({ ... }) // inject auth clients
|
|
// registerHooks({ ... }) // inject analytics/cost/logging
|
|
|
|
// Hooks (dependency injection)
|
|
export { registerHooks, getHooks } from './hooks/index.js'
|
|
export type { ModelProviderHooks } from './hooks/types.js'
|
|
|
|
// Client factories
|
|
export { registerClientFactories, getClientFactories } from './client/index.js'
|
|
export type { ClientFactories } from './client/types.js'
|
|
|
|
// Types
|
|
export * from './types/index.js'
|
|
|
|
// Provider model mappings
|
|
export { resolveOpenAIModel } from './providers/openai/modelMapping.js'
|
|
export { resolveGrokModel } from './providers/grok/modelMapping.js'
|
|
export { resolveGeminiModel } from './providers/gemini/modelMapping.js'
|
|
|
|
// Gemini provider utilities
|
|
export { anthropicMessagesToGemini } from './providers/gemini/convertMessages.js'
|
|
export { anthropicToolsToGemini, anthropicToolChoiceToGemini } from './providers/gemini/convertTools.js'
|
|
export { adaptGeminiStreamToAnthropic } from './providers/gemini/streamAdapter.js'
|
|
export {
|
|
GEMINI_THOUGHT_SIGNATURE_FIELD,
|
|
type GeminiContent,
|
|
type GeminiGenerateContentRequest,
|
|
type GeminiPart,
|
|
type GeminiStreamChunk,
|
|
type GeminiTool,
|
|
type GeminiFunctionCallingConfig,
|
|
type GeminiFunctionDeclaration,
|
|
type GeminiFunctionCall,
|
|
type GeminiFunctionResponse,
|
|
type GeminiInlineData,
|
|
type GeminiUsageMetadata,
|
|
type GeminiCandidate,
|
|
} from './providers/gemini/types.js'
|
|
|
|
// Error utilities
|
|
export {
|
|
formatAPIError,
|
|
extractConnectionErrorDetails,
|
|
sanitizeAPIError,
|
|
getSSLErrorHint,
|
|
type ConnectionErrorDetails,
|
|
} from './errorUtils.js'
|
|
|
|
// Shared OpenAI conversion utilities
|
|
export { anthropicMessagesToOpenAI } from './shared/openaiConvertMessages.js'
|
|
export type { ConvertMessagesOptions } from './shared/openaiConvertMessages.js'
|
|
export { anthropicToolsToOpenAI, anthropicToolChoiceToOpenAI } from './shared/openaiConvertTools.js'
|
|
export { adaptOpenAIStreamToAnthropic } from './shared/openaiStreamAdapter.js'
|