@chinchillaenterprises/mcp-ai-assistant
Version:
MCP server for AI assistant with ElevenLabs text-to-speech integration
64 lines • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountState = void 0;
const credential_manager_js_1 = require("./credential-manager.js");
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
class AccountState {
credentialManager;
activeAccount = null;
constructor() {
this.credentialManager = new credential_manager_js_1.CredentialManager();
}
async initialize() {
const accounts = await this.credentialManager.getAllAccounts();
// Find default account or first account
const defaultAccount = accounts.find(acc => acc.isDefault);
this.activeAccount = defaultAccount || accounts[0] || null;
// Try to load from environment if no accounts
if (!this.activeAccount && process.env.ELEVENLABS_API_KEY) {
const envAccount = {
id: 'env-account',
name: 'Environment Account',
apiKey: process.env.ELEVENLABS_API_KEY,
isDefault: true,
createdAt: new Date().toISOString()
};
await this.credentialManager.saveAccount(envAccount);
this.activeAccount = envAccount;
}
}
getActiveAccount() {
return this.activeAccount;
}
async addAccount(account) {
await this.credentialManager.saveAccount(account);
if (!this.activeAccount || account.isDefault) {
this.activeAccount = account;
}
}
async switchAccount(name) {
const accounts = await this.credentialManager.getAllAccounts();
const account = accounts.find(acc => acc.name === name);
if (!account) {
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `Account "${name}" not found`);
}
this.activeAccount = account;
}
async removeAccount(name) {
const accounts = await this.credentialManager.getAllAccounts();
const account = accounts.find(acc => acc.name === name);
if (!account) {
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `Account "${name}" not found`);
}
await this.credentialManager.removeAccount(account.id);
if (this.activeAccount?.id === account.id) {
const remainingAccounts = await this.credentialManager.getAllAccounts();
this.activeAccount = remainingAccounts[0] || null;
}
}
async getAllAccounts() {
return this.credentialManager.getAllAccounts();
}
}
exports.AccountState = AccountState;
//# sourceMappingURL=account-state.js.map