(raw: unknown)
| 61 | } |
| 62 | |
| 63 | export function parseConfigFile(raw: unknown): ConfigFile { |
| 64 | if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return {}; |
| 65 | const obj = raw as Record<string, unknown>; |
| 66 | const out: ConfigFile = {}; |
| 67 | |
| 68 | if (typeof obj.api_key === 'string') out.api_key = obj.api_key; |
| 69 | if (typeof obj.region === 'string' && VALID_REGIONS.has(obj.region)) out.region = obj.region as Region; |
| 70 | if (typeof obj.base_url === 'string' && obj.base_url.startsWith('http')) out.base_url = obj.base_url; |
| 71 | if (typeof obj.output === 'string' && VALID_OUTPUTS.has(obj.output)) out.output = obj.output as ConfigFile['output']; |
| 72 | if (typeof obj.timeout === 'number' && obj.timeout > 0) out.timeout = obj.timeout; |
| 73 | if (typeof obj.proxy === 'string' && obj.proxy.startsWith('http')) out.proxy = obj.proxy; |
| 74 | const oauth = parseOAuth(obj.oauth); |
| 75 | if (oauth) out.oauth = oauth; |
| 76 | if (typeof obj.default_text_model === 'string' && obj.default_text_model.length > 0) out.default_text_model = obj.default_text_model; |
| 77 | if (typeof obj.default_speech_model === 'string' && obj.default_speech_model.length > 0) out.default_speech_model = obj.default_speech_model; |
| 78 | if (typeof obj.default_video_model === 'string' && obj.default_video_model.length > 0) out.default_video_model = obj.default_video_model; |
| 79 | if (typeof obj.default_music_model === 'string' && obj.default_music_model.length > 0) out.default_music_model = obj.default_music_model; |
| 80 | |
| 81 | return out; |
| 82 | } |
| 83 | |
| 84 | export interface Config { |
| 85 | apiKey?: string; |
no test coverage detected