refactor(server): move the config.json provider-key copy out of VaultStore (P1.2)

VaultStore.migrateFromConfig had two callers, both in the server. It is now
copyProviderKeysToVault in provider-env.ts, next to
migrateLegacyProviderKeysToVault, with the same rules: copy keys that have a
value, keep keys the vault already holds, store models and baseUrl as metadata.
Its tests moved from core to provider-env.test.ts.
This commit is contained in:
shumeiko.it
2026-10-24 16:40:39 +02:00
parent 3528a242f6
commit 2226ec1bd7
5 changed files with 65 additions and 61 deletions

View File

@@ -327,20 +327,4 @@ export class VaultStore implements SecretStore {
const vault = this.readVault();
return name in vault;
}
/** Migrate plaintext providers from config.json to vault. Returns count migrated. */
migrateFromConfig(config: { providers?: Record<string, { apiKey: string; models?: string[]; baseUrl?: string }> }): number {
if (!config.providers) return 0;
let migrated = 0;
for (const [name, provider] of Object.entries(config.providers)) {
if (provider.apiKey && !this.has(name)) {
this.set(name, provider.apiKey, {
models: provider.models,
baseUrl: provider.baseUrl,
});
migrated++;
}
}
return migrated;
}
}