- Updated `generateUUID` function for improved readability and performance. - Deleted `logger.ts`, `other.ts`, `request.ts`, `storage.ts`, `tansParams.ts`, and `validate.ts` as they were no longer needed. - Simplified TypeScript configuration by removing unnecessary paths and aliases. - Enhanced Vite configuration for better project structure and maintainability.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { BaseProvider } from "./BaseProvider";
|
|
import { OpenAIProvider } from "./OpenAIProvider";
|
|
import { providerApiService } from '@electron/service/provider-api-service';
|
|
import { getProviderTypeInfo } from '@runtime/lib/providers';
|
|
|
|
export function createProvider(accountId: string): BaseProvider {
|
|
const account = providerApiService.getAccounts().find((a) => a.id === accountId);
|
|
if (!account) {
|
|
throw new Error(`Provider account ${accountId} not found`);
|
|
}
|
|
|
|
const apiKeyResult = providerApiService.getApiKey(accountId);
|
|
const apiKey = apiKeyResult.apiKey;
|
|
if (!apiKey) {
|
|
throw new Error(`API key for account ${accountId} not found`);
|
|
}
|
|
|
|
const baseURL = account.baseUrl || getProviderTypeInfo(account.vendorId)?.defaultBaseUrl;
|
|
if (!baseURL) {
|
|
throw new Error(`Base URL for account ${accountId} not found`);
|
|
}
|
|
|
|
switch (account.apiProtocol) {
|
|
case 'anthropic-messages':
|
|
throw new Error('Anthropic provider not yet implemented');
|
|
case 'openai-completions':
|
|
case 'openai-responses':
|
|
default:
|
|
return new OpenAIProvider(apiKey, baseURL, account.headers);
|
|
}
|
|
}
|
|
|
|
export * from './BaseProvider';
|
|
export { OpenAIProvider };
|