mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 05:39:05 +08:00
refactor(providers): 重构基础 providers 定义和类型导出
将基础 provider IDs 和 schema 定义移到文件顶部 移除从 baseProviders 动态生成 IDs 的逻辑 使用 satisfies 约束 baseProviders 类型
This commit is contained in:
parent
3d131dc213
commit
005cd730b0
@ -11,6 +11,39 @@ import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
|
|||||||
import { createXai } from '@ai-sdk/xai'
|
import { createXai } from '@ai-sdk/xai'
|
||||||
import * as z from 'zod'
|
import * as z from 'zod'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基础 Provider IDs
|
||||||
|
*/
|
||||||
|
export const baseProviderIds = [
|
||||||
|
'openai',
|
||||||
|
'openai-responses',
|
||||||
|
'openai-compatible',
|
||||||
|
'anthropic',
|
||||||
|
'google',
|
||||||
|
'xai',
|
||||||
|
'azure',
|
||||||
|
'deepseek'
|
||||||
|
] as const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基础 Provider ID Schema
|
||||||
|
*/
|
||||||
|
export const baseProviderIdSchema = z.enum(baseProviderIds)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基础 Provider ID
|
||||||
|
*/
|
||||||
|
export type BaseProviderId = z.infer<typeof baseProviderIdSchema>
|
||||||
|
|
||||||
|
export const baseProviderSchema = z.object({
|
||||||
|
id: baseProviderIdSchema,
|
||||||
|
name: z.string(),
|
||||||
|
creator: z.function().args(z.any()).returns(z.any()),
|
||||||
|
supportsImageGeneration: z.boolean()
|
||||||
|
})
|
||||||
|
|
||||||
|
export type BaseProvider = z.infer<typeof baseProviderSchema>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础 Providers 定义
|
* 基础 Providers 定义
|
||||||
* 作为唯一数据源,避免重复维护
|
* 作为唯一数据源,避免重复维护
|
||||||
@ -64,18 +97,7 @@ export const baseProviders = [
|
|||||||
creator: createDeepSeek,
|
creator: createDeepSeek,
|
||||||
supportsImageGeneration: false
|
supportsImageGeneration: false
|
||||||
}
|
}
|
||||||
] as const
|
] as const satisfies BaseProvider[]
|
||||||
|
|
||||||
/**
|
|
||||||
* 基础 Provider IDs
|
|
||||||
* 从 baseProviders 动态生成
|
|
||||||
*/
|
|
||||||
export const baseProviderIds = baseProviders.map((p) => p.id) as unknown as readonly [string, ...string[]]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 基础 Provider ID Schema
|
|
||||||
*/
|
|
||||||
export const baseProviderIdSchema = z.enum(baseProviderIds)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户自定义 Provider ID Schema
|
* 用户自定义 Provider ID Schema
|
||||||
@ -117,7 +139,6 @@ export const providerConfigSchema = z
|
|||||||
* Provider ID 类型 - 基于 zod schema 推导
|
* Provider ID 类型 - 基于 zod schema 推导
|
||||||
*/
|
*/
|
||||||
export type ProviderId = z.infer<typeof providerIdSchema>
|
export type ProviderId = z.infer<typeof providerIdSchema>
|
||||||
export type BaseProviderId = z.infer<typeof baseProviderIdSchema>
|
|
||||||
export type CustomProviderId = z.infer<typeof customProviderIdSchema>
|
export type CustomProviderId = z.infer<typeof customProviderIdSchema>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user