@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
364 lines (363 loc) • 13.8 kB
TypeScript
/**
* Provider Configuration Utility
* Consolidated configuration helpers for all AI providers
* Eliminates duplicate error messages and configuration logic
* Enhanced with format validation and advanced error classification
* Extended with Claude subscription OAuth support
*/
import type { APIValidationResult, ProviderConfigOptions, AnthropicAuthMethod, ClaudeSubscriptionTier, AnthropicAuthConfig, AnthropicAuthConfigResult } from "../types/index.js";
/**
* API key format validation patterns (extracted from advanced validation system)
* Exported for use across the codebase to replace scattered regex patterns
*/
export declare const API_KEY_FORMATS: Record<string, RegExp>;
/**
* OAuth token format validation patterns
* These patterns are more flexible as OAuth tokens can vary by provider
*/
export declare const OAUTH_TOKEN_FORMATS: Record<string, RegExp>;
/**
* API key length constants to replace scattered magic numbers
*/
export declare const API_KEY_LENGTHS: {
readonly OPENAI_MIN: 48;
readonly ANTHROPIC_MIN: 95;
readonly HUGGINGFACE_EXACT: 37;
readonly AZURE_MIN: 32;
readonly MISTRAL_EXACT: 32;
readonly AWS_ACCESS_KEY: 20;
readonly GOOGLE_AI_EXACT: 39;
};
/**
* Project ID format validation (for Google Cloud)
*/
export declare const PROJECT_ID_FORMAT: {
readonly MIN_LENGTH: 6;
readonly MAX_LENGTH: 30;
readonly PATTERN: RegExp;
};
/**
* Validates API key format for a specific provider
* @param providerKey Provider identifier (e.g., 'openai', 'anthropic')
* @param apiKey The API key to validate
* @returns True if format is valid
*/
export declare function validateApiKeyFormat(providerKey: string, apiKey: string): boolean;
/**
* Enhanced validation with format checking
* @param config Provider configuration options
* @param enableFormatValidation Whether to validate API key format
* @returns Validation result with detailed information
*/
export declare function validateApiKeyEnhanced(config: ProviderConfigOptions, enableFormatValidation?: boolean): APIValidationResult;
/**
* Validates an API key for a provider and returns it (BACKWARD COMPATIBLE)
* Throws detailed error message if validation fails
* @param config Provider configuration options
* @returns The validated API key
*/
export declare function validateApiKey(config: ProviderConfigOptions): string;
/**
* Gets a provider model with fallback to default
* @param envVar Environment variable name for the model
* @param defaultModel Default model to use if env var not set
* @returns The model name to use
*/
export declare function getProviderModel(envVar: string, defaultModel: string): string;
/**
* Checks if provider credentials are available
* @param envVars Array of environment variable names to check
* @returns True if one of the credentials is available
*/
export declare function hasProviderCredentials(envVars: string[]): boolean;
/**
* Creates Anthropic provider configuration
* Supports both API key and OAuth authentication methods
*/
export declare function createAnthropicConfig(): ProviderConfigOptions;
/**
* Creates OpenAI provider configuration
*/
export declare function createOpenAIConfig(): ProviderConfigOptions;
/**
* Creates HuggingFace provider configuration
*/
export declare function createHuggingFaceConfig(): ProviderConfigOptions;
/**
* Creates Mistral provider configuration
*/
export declare function createMistralConfig(): ProviderConfigOptions;
/**
* Creates AWS Access Key configuration for Bedrock
*/
export declare function createAWSAccessKeyConfig(): ProviderConfigOptions;
/**
* Creates AWS Secret Key configuration for Bedrock
*/
export declare function createAWSSecretConfig(): ProviderConfigOptions;
/**
* Creates Azure OpenAI API Key configuration
*/
export declare function createAzureAPIKeyConfig(): ProviderConfigOptions;
/**
* Creates Azure OpenAI Endpoint configuration
*/
export declare function createAzureEndpointConfig(): ProviderConfigOptions;
/**
* Creates OpenAI Compatible provider configuration
*/
export declare function createOpenAICompatibleConfig(): ProviderConfigOptions;
/**
* Creates DeepSeek provider configuration
*/
export declare function createDeepSeekConfig(): ProviderConfigOptions;
/**
* Creates NVIDIA NIM provider configuration
*/
export declare function createNvidiaNimConfig(): ProviderConfigOptions;
/**
* Creates LM Studio provider configuration (local server)
*/
export declare function createLmStudioConfig(): ProviderConfigOptions;
/**
* Creates llama.cpp provider configuration (local server)
*/
export declare function createLlamaCppConfig(): ProviderConfigOptions;
/**
* Creates xAI Grok provider configuration.
*/
export declare function createXaiConfig(): ProviderConfigOptions;
/**
* Creates Groq provider configuration.
*/
export declare function createGroqConfig(): ProviderConfigOptions;
/**
* Creates Cohere provider configuration.
*/
export declare function createCohereConfig(): ProviderConfigOptions;
/**
* Creates Replicate provider configuration.
*/
export declare function createReplicateConfig(): ProviderConfigOptions;
/**
* Creates Together AI provider configuration.
*/
export declare function createTogetherAIConfig(): ProviderConfigOptions;
/**
* Creates Fireworks AI provider configuration.
*/
export declare function createFireworksConfig(): ProviderConfigOptions;
/**
* Creates Perplexity provider configuration.
*/
export declare function createPerplexityConfig(): ProviderConfigOptions;
/**
* Creates Voyage AI provider configuration (embedding-only).
*/
export declare function createVoyageConfig(): ProviderConfigOptions;
/**
* Creates Jina AI provider configuration (embeddings + reranking).
*/
export declare function createJinaConfig(): ProviderConfigOptions;
/**
* Creates Stability AI provider configuration (image generation).
*/
export declare function createStabilityConfig(): ProviderConfigOptions;
/**
* Creates Ideogram provider configuration (image generation).
*/
export declare function createIdeogramConfig(): ProviderConfigOptions;
/**
* Creates Recraft provider configuration (image generation, vector focus).
*/
export declare function createRecraftConfig(): ProviderConfigOptions;
/**
* Creates Cloudflare Workers AI provider configuration.
*
* Cloudflare requires both `CLOUDFLARE_API_KEY` (workers-AI-scoped token)
* AND `CLOUDFLARE_ACCOUNT_ID` since the endpoint is per-account.
*/
export declare function createCloudflareConfig(): ProviderConfigOptions;
/**
* Creates Google Vertex Project ID configuration
*/
export declare function createVertexProjectConfig(): ProviderConfigOptions;
/**
* Creates Google Cloud Authentication configuration
*/
export declare function createGoogleAuthConfig(): ProviderConfigOptions;
/**
* Creates Anthropic Base Provider configuration
*/
export declare function createAnthropicBaseConfig(): ProviderConfigOptions;
/**
* Gets AWS Region with default fallback
* Supports both AWS_REGION and AWS_DEFAULT_REGION for broader compatibility
*/
export declare function getAWSRegion(): string;
/**
* Gets AWS Session Token if available
*/
export declare function getAWSSessionToken(): string | undefined;
/**
* Checks if HuggingFace credentials are available
*/
export declare function hasHuggingFaceCredentials(): boolean;
/**
* Gets the configured Anthropic authentication method
* Defaults to "api_key" for backward compatibility
* @returns The configured authentication method
*/
export declare function getAnthropicAuthMethod(): AnthropicAuthMethod;
/**
* Gets the configured Claude subscription tier
* Defaults to "api" for backward compatibility (API key users)
* @returns The configured subscription tier
*/
export declare function getAnthropicSubscriptionTier(): ClaudeSubscriptionTier;
/**
* Validates OAuth access token format
* @param token The token to validate
* @returns True if the token format is valid
*/
export declare function validateOAuthAccessToken(token: string): boolean;
/**
* Validates OAuth refresh token format
* @param token The token to validate
* @returns True if the token format is valid
*/
export declare function validateOAuthRefreshToken(token: string): boolean;
/**
* Detects the best available authentication method for Anthropic
* Checks environment variables and returns the most appropriate auth configuration
* @returns Complete authentication configuration
*/
export declare function detectAnthropicAuth(): AnthropicAuthConfigResult;
/**
* Checks if Anthropic credentials are available (either API key or OAuth)
* @returns True if any valid authentication is configured
*/
export declare function hasAnthropicCredentials(): boolean;
/**
* Gets the authentication token or key for Anthropic API calls
* Returns the appropriate credential based on configured auth method
* @returns The API key or OAuth access token, or undefined if not configured
*/
export declare function getAnthropicCredential(): string | undefined;
/**
* Checks if OAuth refresh is needed based on token state
* This is a placeholder for actual token expiration checking
* @returns True if refresh is needed
*/
export declare function needsOAuthRefresh(): boolean;
/**
* Gets subscription tier limits for informational purposes
* These are approximate limits and may change
* @param tier The subscription tier
* @returns Object with tier limit information
*/
export declare function getSubscriptionTierLimits(tier: ClaudeSubscriptionTier): {
messagesPerDay: number | "unlimited";
contextWindow: number;
priorityAccess: boolean;
description: string;
};
/**
* Environment variables for Anthropic/Claude subscription configuration
* These control authentication method, subscription tier, and feature flags
*/
export declare const ANTHROPIC_ENV_VARS: {
/** Authentication method: "api_key" or "oauth" */
readonly AUTH_METHOD: "ANTHROPIC_AUTH_METHOD";
/** Subscription tier: "free", "pro", "max", "max_5", "max_20", or "api" */
readonly SUBSCRIPTION_TIER: "ANTHROPIC_SUBSCRIPTION_TIER";
/** Enable beta features: "true" or "false" */
readonly ENABLE_BETA_FEATURES: "ANTHROPIC_ENABLE_BETA_FEATURES";
/** API key for api_key authentication */
readonly API_KEY: "ANTHROPIC_API_KEY";
/** OAuth access token for oauth authentication (canonical, with BC fallbacks) */
readonly OAUTH_ACCESS_TOKEN: "ANTHROPIC_OAUTH_TOKEN";
/** OAuth refresh token for oauth authentication */
readonly OAUTH_REFRESH_TOKEN: "ANTHROPIC_OAUTH_REFRESH_TOKEN";
/** OAuth token expiry timestamp (Unix epoch in seconds) */
readonly OAUTH_TOKEN_EXPIRY: "ANTHROPIC_OAUTH_TOKEN_EXPIRY";
};
/**
* Valid subscription tier values for validation
*/
export declare const VALID_SUBSCRIPTION_TIERS: readonly ClaudeSubscriptionTier[];
/**
* Valid authentication method values for validation
*/
export declare const VALID_AUTH_METHODS: readonly AnthropicAuthMethod[];
/**
* Validates a subscription tier value
* @param tier The tier value to validate
* @returns True if the tier is valid, false otherwise
*/
export declare function isValidSubscriptionTier(tier: string | undefined): tier is ClaudeSubscriptionTier;
/**
* Validates an authentication method value
* @param method The method value to validate
* @returns True if the method is valid, false otherwise
*/
export declare function isValidAuthMethod(method: string | undefined): method is AnthropicAuthMethod;
/**
* Validates subscription tier and returns a detailed result
* @param tier The tier value to validate
* @returns Validation result with error details if invalid
*/
export declare function validateSubscriptionTier(tier: string | undefined): {
isValid: boolean;
tier?: ClaudeSubscriptionTier;
error?: string;
};
/**
* Gets the complete Anthropic authentication configuration
* Detects auth method from environment or config and loads appropriate credentials
*
* @returns Complete AnthropicAuthConfig with method, credentials, and tier
*/
export declare function getAnthropicAuthConfig(): AnthropicAuthConfig;
/**
* Detects the subscription tier from environment variables or config
* Checks environment variable first, then config, defaults to "api" if using API key
*
* @returns The detected subscription tier
*/
export declare function detectSubscriptionTier(): ClaudeSubscriptionTier;
/**
* Determines whether beta features should be enabled
* Checks environment/config and defaults based on authentication method
*
* @returns True if beta features should be enabled
*/
export declare function shouldEnableBetaFeatures(): boolean;
/**
* Gets complete subscription configuration including auth, tier, and features
* Combines all configuration sources into a unified config object
*
* @returns Complete subscription configuration
*/
export declare function getAnthropicSubscriptionConfig(): {
auth: AnthropicAuthConfig;
tier: ClaudeSubscriptionTier;
betaFeaturesEnabled: boolean;
limits: ReturnType<typeof getSubscriptionTierLimits>;
isConfigured: boolean;
error?: string;
};
/**
* Checks if the current subscription tier has access to a specific feature
* @param feature The feature to check
* @param currentTier The current subscription tier (optional, auto-detects if not provided)
* @returns True if the tier has access to the feature
*/
export declare function hasSubscriptionFeature(feature: "extended_thinking" | "priority_access" | "vision" | "file_analysis" | "mcp_tools" | "computer_use" | "web_search", currentTier?: ClaudeSubscriptionTier): boolean;
/**
* Gets a human-readable description of the current authentication configuration
* Useful for debugging and user feedback
*
* @returns Human-readable configuration description
*/
export declare function describeAnthropicConfig(): string;