All files / tavus/client/src tavus.ts

0% Statements 0/15
0% Branches 0/5
0% Functions 0/3
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                                                                                                 
/**
 * Centralized Tavus configuration
 *
 * This module now uses the secure API key management system.
 * API keys are managed through environment variables and the ApiKeyManager.
 */
 
import type { BuzzTrailGlobal } from '@buzztrail/shared-types';
import { getApiKeyManager, getTavusApiKey as getSecureApiKey } from '@buzztrail/shared-config';
 
// Legacy fallback for backward compatibility
const LEGACY_TAVUS_API_KEY = '8ff39906dd5840a9bca8c6ce4e15135c';
 
/**
 * Returns the Tavus API key.
 *
 * Uses the secure API key management system first,
 * then falls back to global override, then legacy key.
 */
export function getTavusApiKey(): string {
  try {
    // Try secure API key management first
    const secureKey = getSecureApiKey();
    Iif (secureKey) {
      return secureKey;
    }
    
    // Fall back to global override
    const override = (globalThis as BuzzTrailGlobal).__BT_TAVUS_API_KEY__;
    Iif (override && typeof override === 'string' && override.trim().length > 0) {
      return override.trim();
    }
  } catch {
    // Ignore errors when accessing global properties or secure system
  }
  
  // Final fallback to legacy key
  return LEGACY_TAVUS_API_KEY;
}
 
/**
 * Sets a runtime override for the Tavus API key in the current JS context.
 * Note: extension contexts are isolated; set per-context if needed.
 */
export function setTavusApiKey(key: string): void {
  (globalThis as BuzzTrailGlobal).__BT_TAVUS_API_KEY__ = key;
}
 
/**
 * Get API key manager for advanced operations
 */
export function getTavusApiKeyManager() {
  return getApiKeyManager();
}