♻️ refactor: enhance logging and provider handling for Anthropic integration

This commit is contained in:
Vaayne
2025-09-29 14:38:41 +08:00
parent 5b98ef5b3d
commit cc871b7a72
7 changed files with 59 additions and 168 deletions
+1 -1
View File
@@ -2618,7 +2618,7 @@ const migrateConfig = {
provider.anthropicApiHost = 'https://api-inference.modelscope.cn'
break
case 'aihubmix':
provider.anthropicApiHost = 'https://aihubmix.com/anthropic'
provider.anthropicApiHost = "https://aihubmix.com";
provider.isAnthropicModel = (m: Model) => m.id.includes('claude')
break
}
-157
View File
@@ -13,7 +13,6 @@ import type { FileMetadata } from './file'
import { KnowledgeBase, KnowledgeReference } from './knowledge'
import { MCPConfigSample, McpServerType } from './mcp'
import type { Message } from './newMessage'
import type { ServiceTier } from './provider'
import type { BaseTool, MCPTool } from './tool'
export * from './agent'
@@ -224,162 +223,6 @@ export type User = {
email: string
}
// undefined 视为支持,默认支持
export type ProviderApiOptions = {
/** 是否不支持 message 的 content 为数组类型 */
isNotSupportArrayContent?: boolean
/** 是否不支持 stream_options 参数 */
isNotSupportStreamOptions?: boolean
/**
* @deprecated
* 是否不支持 message 的 role 为 developer */
isNotSupportDeveloperRole?: boolean
/* 是否支持 message 的 role 为 developer */
isSupportDeveloperRole?: boolean
/**
* @deprecated
* 是否不支持 service_tier 参数. Only for OpenAI Models. */
isNotSupportServiceTier?: boolean
/* 是否支持 service_tier 参数. Only for OpenAI Models. */
isSupportServiceTier?: boolean
/** 是否不支持 enable_thinking 参数 */
isNotSupportEnableThinking?: boolean
}
export type Provider = {
id: string
type: ProviderType
name: string
apiKey: string
apiHost: string
anthropicApiHost?: string
isAnthropicModel?: (m: Model) => boolean
apiVersion?: string
models: Model[]
enabled?: boolean
isSystem?: boolean
isAuthed?: boolean
rateLimit?: number
// API options
apiOptions?: ProviderApiOptions
serviceTier?: ServiceTier
/** @deprecated */
isNotSupportArrayContent?: boolean
/** @deprecated */
isNotSupportStreamOptions?: boolean
/** @deprecated */
isNotSupportDeveloperRole?: boolean
/** @deprecated */
isNotSupportServiceTier?: boolean
authType?: 'apiKey' | 'oauth'
isVertex?: boolean
notes?: string
extra_headers?: Record<string, string>
}
export const SystemProviderIds = {
// cherryin: 'cherryin',
silicon: 'silicon',
aihubmix: 'aihubmix',
ocoolai: 'ocoolai',
deepseek: 'deepseek',
ppio: 'ppio',
alayanew: 'alayanew',
qiniu: 'qiniu',
dmxapi: 'dmxapi',
burncloud: 'burncloud',
tokenflux: 'tokenflux',
'302ai': '302ai',
cephalon: 'cephalon',
lanyun: 'lanyun',
ph8: 'ph8',
openrouter: 'openrouter',
ollama: 'ollama',
'new-api': 'new-api',
lmstudio: 'lmstudio',
anthropic: 'anthropic',
openai: 'openai',
'azure-openai': 'azure-openai',
gemini: 'gemini',
vertexai: 'vertexai',
github: 'github',
copilot: 'copilot',
zhipu: 'zhipu',
yi: 'yi',
moonshot: 'moonshot',
baichuan: 'baichuan',
dashscope: 'dashscope',
stepfun: 'stepfun',
doubao: 'doubao',
infini: 'infini',
minimax: 'minimax',
groq: 'groq',
together: 'together',
fireworks: 'fireworks',
nvidia: 'nvidia',
grok: 'grok',
hyperbolic: 'hyperbolic',
mistral: 'mistral',
jina: 'jina',
perplexity: 'perplexity',
modelscope: 'modelscope',
xirang: 'xirang',
hunyuan: 'hunyuan',
'tencent-cloud-ti': 'tencent-cloud-ti',
'baidu-cloud': 'baidu-cloud',
gpustack: 'gpustack',
voyageai: 'voyageai',
'aws-bedrock': 'aws-bedrock',
poe: 'poe',
aionly: 'aionly',
longcat: 'longcat'
} as const
export type SystemProviderId = keyof typeof SystemProviderIds
export const isSystemProviderId = (id: string): id is SystemProviderId => {
return Object.hasOwn(SystemProviderIds, id)
}
export type SystemProvider = Provider & {
id: SystemProviderId
isSystem: true
apiOptions?: never
}
export type VertexProvider = Provider & {
googleCredentials: {
privateKey: string
clientEmail: string
}
project: string
location: string
}
/**
* 判断是否为系统内置的提供商。比直接使用`provider.isSystem`更好,因为该数据字段不会随着版本更新而变化。
* @param provider - Provider对象,包含提供商的信息
* @returns 是否为系统内置提供商
*/
export const isSystemProvider = (provider: Provider): provider is SystemProvider => {
return isSystemProviderId(provider.id) && !!provider.isSystem
}
export type ProviderType =
| 'openai'
| 'openai-response'
| 'anthropic'
| 'gemini'
| 'qwenlm'
| 'azure-openai'
| 'vertexai'
| 'mistral'
| 'aws-bedrock'
| 'vertex-anthropic'
export type ModelType = 'text' | 'vision' | 'embedding' | 'reasoning' | 'function_calling' | 'web_search' | 'rerank'
export type ModelTag = Exclude<ModelType, 'text'> | 'free'
+5 -2
View File
@@ -77,6 +77,8 @@ export type Provider = {
name: string
apiKey: string
apiHost: string
anthropicApiHost?: string
isAnthropicModel?: (m: Model) => boolean
apiVersion?: string
models: Model[]
enabled?: boolean
@@ -104,7 +106,7 @@ export type Provider = {
}
export const SystemProviderIds = {
cherryin: 'cherryin',
// cherryin: 'cherryin',
silicon: 'silicon',
aihubmix: 'aihubmix',
ocoolai: 'ocoolai',
@@ -157,7 +159,8 @@ export const SystemProviderIds = {
voyageai: 'voyageai',
'aws-bedrock': 'aws-bedrock',
poe: 'poe',
aionly: 'aionly'
aionly: 'aionly',
longcat: 'longcat'
} as const
export type SystemProviderId = keyof typeof SystemProviderIds