mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-21 12:11:28 -07:00
feat(ai): split shared provider config from Anki runtime
This commit is contained in:
27
src/ai/config.ts
Normal file
27
src/ai/config.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { AiConfig, AiFeatureConfig } from '../types';
|
||||
|
||||
function trimToOverride(value: string | undefined): string | undefined {
|
||||
if (typeof value !== 'string') return undefined;
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : undefined;
|
||||
}
|
||||
|
||||
export function mergeAiConfig(
|
||||
sharedConfig: AiConfig | undefined,
|
||||
featureConfig?: AiFeatureConfig | boolean | null,
|
||||
): AiConfig {
|
||||
const overrides =
|
||||
featureConfig && typeof featureConfig === 'object' ? featureConfig : undefined;
|
||||
const modelOverride = trimToOverride(overrides?.model);
|
||||
const systemPromptOverride = trimToOverride(overrides?.systemPrompt);
|
||||
|
||||
return {
|
||||
enabled: sharedConfig?.enabled,
|
||||
apiKey: sharedConfig?.apiKey,
|
||||
apiKeyCommand: sharedConfig?.apiKeyCommand,
|
||||
baseUrl: sharedConfig?.baseUrl,
|
||||
model: modelOverride ?? sharedConfig?.model,
|
||||
systemPrompt: systemPromptOverride ?? sharedConfig?.systemPrompt,
|
||||
requestTimeoutMs: sharedConfig?.requestTimeoutMs,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user