模块路径:
src/types/+src/config/schema.ts生成时间: 2026-05-11
数据模型模块定义了系统核心的 TypeScript 类型和 Zod Schema,是配置验证和类型安全的基础。使用 Zod Schema 作为唯一数据来源,TypeScript 类型通过 z.infer 自动推断。
ConfigSchema 包含所有配置字段.min(1) 等验证规则.int().positive() 验证BackendConfigSchema 包含后端配置字段name 和 prefix 为必填非空字符串base_url 为必填且格式为合法 URLdefault、require_api_key 默认为 falserole_rewrites 默认为空对象 {}unsupported_params 默认为空数组 []z.infer<typeof ConfigSchema> 自动推断 Config 类型z.infer<typeof BackendConfigSchema> 自动推断 BackendConfig 类型llmrouterApiKey、useGeneratedKey、logger)使用接口扩展ZodError 的详细错误信息transform 处理字段名映射// 从 Zod Schema 推断的基础类型
type BaseConfig = z.infer<typeof ConfigSchema>;
// 运行时扩展
interface Config extends BaseConfig {
llmrouterApiKey: string;
useGeneratedKey: boolean;
logger: Logger;
}
type BackendConfig = z.infer<typeof BackendConfigSchema>;
interface ChatMessage {
role: 'system' | 'user' | 'assistant' | 'developer' | string;
content: string | null;
}
interface ChatCompletionRequest {
model: string;
messages: ChatMessage[];
stream?: boolean;
temperature?: number;
max_tokens?: number;
[key: string]: unknown;
}
| Go 类型 | TypeScript 类型 | 说明 |
|---|---|---|
Config struct |
Config interface (Zod 推断 + 扩展) |
新增运行时字段 |
BackendConfig struct |
BackendConfig type (Zod 推断) |
Zod Schema 驱动 |
struct tags |
Zod Schema | 运行时验证 + 类型推断 |
json.Unmarshal |
jsonc-parser / yaml | 多格式解析 |
| 无 | Zod Schema 验证 | 新增:运行时安全保障 |