termcode
Version:
Superior terminal AI coding agent with enterprise-grade security, intelligent error recovery, performance monitoring, and plugin system - Advanced Claude Code alternative
45 lines (44 loc) • 1.52 kB
JavaScript
import keytar from "keytar";
const SERVICE_NAME = "termcode";
export class KeyStore {
static async setProviderKey(provider, key) {
await keytar.setPassword(SERVICE_NAME, `provider:${provider}`, key);
}
static async getProviderKey(provider) {
return await keytar.getPassword(SERVICE_NAME, `provider:${provider}`);
}
static async deleteProviderKey(provider) {
return await keytar.deletePassword(SERVICE_NAME, `provider:${provider}`);
}
static async listProviderKeys() {
try {
const credentials = await keytar.findCredentials(SERVICE_NAME);
const providers = [];
for (const cred of credentials) {
if (cred.account.startsWith("provider:")) {
const provider = cred.account.replace("provider:", "");
providers.push(provider);
}
}
return providers;
}
catch (error) {
return [];
}
}
static async hasProviderKey(provider) {
const key = await KeyStore.getProviderKey(provider);
return key !== null && key.trim() !== "";
}
static async clearAllKeys() {
try {
const credentials = await keytar.findCredentials(SERVICE_NAME);
for (const cred of credentials) {
await keytar.deletePassword(SERVICE_NAME, cred.account);
}
}
catch (error) {
// Ignore errors during cleanup
}
}
}