File size: 5,346 Bytes
c0a9bce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import type { ProviderName, ProviderConfig, StatusCheckResult } from './types';
import { BaseProviderChecker } from './base-provider';

import { AmazonBedrockStatusChecker } from './providers/amazon-bedrock';
import { CohereStatusChecker } from './providers/cohere';
import { DeepseekStatusChecker } from './providers/deepseek';
import { GoogleStatusChecker } from './providers/google';
import { GroqStatusChecker } from './providers/groq';
import { HuggingFaceStatusChecker } from './providers/huggingface';
import { HyperbolicStatusChecker } from './providers/hyperbolic';
import { MistralStatusChecker } from './providers/mistral';
import { OpenRouterStatusChecker } from './providers/openrouter';
import { PerplexityStatusChecker } from './providers/perplexity';
import { TogetherStatusChecker } from './providers/together';
import { XAIStatusChecker } from './providers/xai';

export class ProviderStatusCheckerFactory {
  private static _providerConfigs: Record<ProviderName, ProviderConfig> = {
    AmazonBedrock: {
      statusUrl: 'https://health.aws.amazon.com/health/status',
      apiUrl: 'https://bedrock.us-east-1.amazonaws.com/models',
      headers: {},
      testModel: 'anthropic.claude-3-sonnet-20240229-v1:0',
    },
    Cohere: {
      statusUrl: 'https://status.cohere.com/',
      apiUrl: 'https://api.cohere.ai/v1/models',
      headers: {},
      testModel: 'command',
    },
    Deepseek: {
      statusUrl: 'https://status.deepseek.com/',
      apiUrl: 'https://api.deepseek.com/v1/models',
      headers: {},
      testModel: 'deepseek-chat',
    },
    Google: {
      statusUrl: 'https://status.cloud.google.com/',
      apiUrl: 'https://generativelanguage.googleapis.com/v1/models',
      headers: {},
      testModel: 'gemini-pro',
    },
    Groq: {
      statusUrl: 'https://groqstatus.com/',
      apiUrl: 'https://api.groq.com/v1/models',
      headers: {},
      testModel: 'mixtral-8x7b-32768',
    },
    HuggingFace: {
      statusUrl: 'https://status.huggingface.co/',
      apiUrl: 'https://api-inference.huggingface.co/models',
      headers: {},
      testModel: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
    },
    Hyperbolic: {
      statusUrl: 'https://status.hyperbolic.ai/',
      apiUrl: 'https://api.hyperbolic.ai/v1/models',
      headers: {},
      testModel: 'hyperbolic-1',
    },
    Mistral: {
      statusUrl: 'https://status.mistral.ai/',
      apiUrl: 'https://api.mistral.ai/v1/models',
      headers: {},
      testModel: 'mistral-tiny',
    },
    OpenRouter: {
      statusUrl: 'https://status.openrouter.ai/',
      apiUrl: 'https://openrouter.ai/api/v1/models',
      headers: {},
      testModel: 'anthropic/claude-3-sonnet',
    },
    Perplexity: {
      statusUrl: 'https://status.perplexity.com/',
      apiUrl: 'https://api.perplexity.ai/v1/models',
      headers: {},
      testModel: 'pplx-7b-chat',
    },
    Together: {
      statusUrl: 'https://status.together.ai/',
      apiUrl: 'https://api.together.xyz/v1/models',
      headers: {},
      testModel: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
    },
    XAI: {
      statusUrl: 'https://status.x.ai/',
      apiUrl: 'https://api.x.ai/v1/models',
      headers: {},
      testModel: 'grok-1',
    },
  };

  static getChecker(provider: ProviderName): BaseProviderChecker {
    const config = this._providerConfigs[provider];

    if (!config) {
      throw new Error(`No configuration found for provider: ${provider}`);
    }

    switch (provider) {
      case 'AmazonBedrock':
        return new AmazonBedrockStatusChecker(config);
      case 'Cohere':
        return new CohereStatusChecker(config);
      case 'Deepseek':
        return new DeepseekStatusChecker(config);
      case 'Google':
        return new GoogleStatusChecker(config);
      case 'Groq':
        return new GroqStatusChecker(config);
      case 'HuggingFace':
        return new HuggingFaceStatusChecker(config);
      case 'Hyperbolic':
        return new HyperbolicStatusChecker(config);
      case 'Mistral':
        return new MistralStatusChecker(config);
      case 'OpenRouter':
        return new OpenRouterStatusChecker(config);
      case 'Perplexity':
        return new PerplexityStatusChecker(config);
      case 'Together':
        return new TogetherStatusChecker(config);
      case 'XAI':
        return new XAIStatusChecker(config);
      default:
        return new (class extends BaseProviderChecker {
          async checkStatus(): Promise<StatusCheckResult> {
            const endpointStatus = await this.checkEndpoint(this.config.statusUrl);
            const apiStatus = await this.checkEndpoint(this.config.apiUrl);

            return {
              status: endpointStatus === 'reachable' && apiStatus === 'reachable' ? 'operational' : 'degraded',
              message: `Status page: ${endpointStatus}, API: ${apiStatus}`,
              incidents: ['Note: Limited status information due to CORS restrictions'],
            };
          }
        })(config);
    }
  }

  static getProviderNames(): ProviderName[] {
    return Object.keys(this._providerConfigs) as ProviderName[];
  }

  static getProviderConfig(provider: ProviderName): ProviderConfig {
    const config = this._providerConfigs[provider];

    if (!config) {
      throw new Error(`Unknown provider: ${provider}`);
    }

    return config;
  }
}