mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
chore(providers): remove dead exports left over from refactor
- Drop empty barrel src/components/providers/index.ts (no external importers) - Drop src/components/providers/types.ts (only referenced in a stale comment) - Trim src/components/providers/utils.ts to the 10 exports actually used externally; remaining helpers (ampcode mappers, key builders, base URL normalizers, redundant recent-stats wrappers) were dead after the ProvidersWorkbench rewrite
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
export { ProviderStatusBar } from './ProviderStatusBar';
|
||||
export * from './hooks/useProviderRecentRequests';
|
||||
export * from './types';
|
||||
export * from './utils';
|
||||
@@ -1,49 +0,0 @@
|
||||
import type { ApiKeyEntry, GeminiKeyConfig, ProviderKeyConfig } from '@/types';
|
||||
import type { HeaderEntry } from '@/utils/headers';
|
||||
|
||||
export interface ModelEntry {
|
||||
name: string;
|
||||
alias: string;
|
||||
}
|
||||
|
||||
export interface OpenAIFormState {
|
||||
name: string;
|
||||
priority?: number;
|
||||
prefix: string;
|
||||
baseUrl: string;
|
||||
headers: HeaderEntry[];
|
||||
testModel?: string;
|
||||
modelEntries: ModelEntry[];
|
||||
apiKeyEntries: ApiKeyEntry[];
|
||||
}
|
||||
|
||||
export interface AmpcodeUpstreamApiKeyEntry {
|
||||
upstreamApiKey: string;
|
||||
clientApiKeysText: string;
|
||||
}
|
||||
|
||||
export interface AmpcodeFormState {
|
||||
upstreamUrl: string;
|
||||
upstreamApiKey: string;
|
||||
forceModelMappings: boolean;
|
||||
mappingEntries: ModelEntry[];
|
||||
upstreamApiKeyEntries: AmpcodeUpstreamApiKeyEntry[];
|
||||
}
|
||||
|
||||
export type GeminiFormState = Omit<GeminiKeyConfig, 'headers' | 'models'> & {
|
||||
headers: HeaderEntry[];
|
||||
modelEntries: ModelEntry[];
|
||||
excludedText: string;
|
||||
};
|
||||
|
||||
export type ProviderFormState = Omit<ProviderKeyConfig, 'headers'> & {
|
||||
headers: HeaderEntry[];
|
||||
modelEntries: ModelEntry[];
|
||||
excludedText: string;
|
||||
};
|
||||
|
||||
export type VertexFormState = Omit<ProviderKeyConfig, 'headers'> & {
|
||||
headers: HeaderEntry[];
|
||||
modelEntries: ModelEntry[];
|
||||
excludedText: string;
|
||||
};
|
||||
@@ -1,23 +1,15 @@
|
||||
import type {
|
||||
AmpcodeConfig,
|
||||
AmpcodeModelMapping,
|
||||
AmpcodeUpstreamApiKeyMapping,
|
||||
ApiKeyEntry,
|
||||
OpenAIProviderConfig,
|
||||
} from '@/types';
|
||||
import type { OpenAIProviderConfig } from '@/types';
|
||||
import {
|
||||
buildRecentRequestCompositeKey,
|
||||
mergeRecentRequestBucketGroups,
|
||||
normalizeRecentRequestAuthIndex,
|
||||
statusBarDataFromRecentRequests,
|
||||
sumRecentRequests,
|
||||
type RecentRequestBucket,
|
||||
type RecentRequestUsageEntry,
|
||||
type StatusBarData,
|
||||
} from '@/utils/recentRequests';
|
||||
import type { AmpcodeFormState, AmpcodeUpstreamApiKeyEntry, ModelEntry } from './types';
|
||||
|
||||
export const DISABLE_ALL_MODELS_RULE = '*';
|
||||
const DISABLE_ALL_MODELS_RULE = '*';
|
||||
|
||||
export const hasDisableAllModelsRule = (models?: string[]) =>
|
||||
Array.isArray(models) &&
|
||||
@@ -33,23 +25,10 @@ export const withDisableAllModelsRule = (models?: string[]) => {
|
||||
return [...base, DISABLE_ALL_MODELS_RULE];
|
||||
};
|
||||
|
||||
export const withoutDisableAllModelsRule = (models?: string[]) => {
|
||||
const base = stripDisableAllModelsRule(models);
|
||||
return base;
|
||||
};
|
||||
export const withoutDisableAllModelsRule = (models?: string[]) =>
|
||||
stripDisableAllModelsRule(models);
|
||||
|
||||
export const parseTextList = (text: string): string[] =>
|
||||
text
|
||||
.split(/[\n,]+/)
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
export const parseExcludedModels = parseTextList;
|
||||
|
||||
export const excludedModelsToText = (models?: string[]) =>
|
||||
Array.isArray(models) ? models.join('\n') : '';
|
||||
|
||||
export const normalizeOpenAIBaseUrl = (baseUrl: string): string => {
|
||||
const normalizeOpenAIBaseUrl = (baseUrl: string): string => {
|
||||
let trimmed = String(baseUrl || '').trim();
|
||||
if (!trimmed) return '';
|
||||
trimmed = trimmed.replace(/\/?v0\/management\/?$/i, '');
|
||||
@@ -60,7 +39,7 @@ export const normalizeOpenAIBaseUrl = (baseUrl: string): string => {
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
export const normalizeClaudeBaseUrl = (baseUrl: string): string => {
|
||||
const normalizeClaudeBaseUrl = (baseUrl: string): string => {
|
||||
let trimmed = String(baseUrl || '').trim();
|
||||
if (!trimmed) {
|
||||
return 'https://api.anthropic.com';
|
||||
@@ -73,12 +52,6 @@ export const normalizeClaudeBaseUrl = (baseUrl: string): string => {
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
export const buildOpenAIModelsEndpoint = (baseUrl: string): string => {
|
||||
const trimmed = normalizeOpenAIBaseUrl(baseUrl);
|
||||
if (!trimmed) return '';
|
||||
return `${trimmed}/models`;
|
||||
};
|
||||
|
||||
export const buildOpenAIChatCompletionsEndpoint = (baseUrl: string): string => {
|
||||
const trimmed = normalizeOpenAIBaseUrl(baseUrl);
|
||||
if (!trimmed) return '';
|
||||
@@ -111,12 +84,12 @@ const EMPTY_RECENT_USAGE_ENTRY: RecentRequestUsageEntry = {
|
||||
const normalizeProviderRecentKey = (value: unknown): string =>
|
||||
String(value ?? '').trim().toLowerCase();
|
||||
|
||||
export function getProviderRecentUsageEntry(
|
||||
const getProviderRecentUsageEntry = (
|
||||
usageByProvider: ProviderRecentUsageMap,
|
||||
provider: string,
|
||||
apiKey?: string,
|
||||
baseUrl?: string
|
||||
): RecentRequestUsageEntry {
|
||||
): RecentRequestUsageEntry => {
|
||||
if (!String(apiKey ?? '').trim()) {
|
||||
return EMPTY_RECENT_USAGE_ENTRY;
|
||||
}
|
||||
@@ -124,49 +97,15 @@ export function getProviderRecentUsageEntry(
|
||||
const providerKey = normalizeProviderRecentKey(provider);
|
||||
const compositeKey = buildRecentRequestCompositeKey(baseUrl, apiKey);
|
||||
return usageByProvider.get(providerKey)?.get(compositeKey) ?? EMPTY_RECENT_USAGE_ENTRY;
|
||||
}
|
||||
};
|
||||
|
||||
export function getProviderRecentBuckets(
|
||||
const getProviderRecentBuckets = (
|
||||
usageByProvider: ProviderRecentUsageMap,
|
||||
provider: string,
|
||||
apiKey?: string,
|
||||
baseUrl?: string
|
||||
): RecentRequestBucket[] {
|
||||
return getProviderRecentUsageEntry(
|
||||
usageByProvider,
|
||||
provider,
|
||||
apiKey,
|
||||
baseUrl
|
||||
).recentRequests;
|
||||
}
|
||||
|
||||
export function getProviderTotalStats(
|
||||
usageByProvider: ProviderRecentUsageMap,
|
||||
provider: string,
|
||||
apiKey?: string,
|
||||
baseUrl?: string
|
||||
): { success: number; failure: number } {
|
||||
const entry = getProviderRecentUsageEntry(usageByProvider, provider, apiKey, baseUrl);
|
||||
return { success: entry.success, failure: entry.failed };
|
||||
}
|
||||
|
||||
export function getProviderRecentWindowStats(
|
||||
usageByProvider: ProviderRecentUsageMap,
|
||||
provider: string,
|
||||
apiKey?: string,
|
||||
baseUrl?: string
|
||||
): { success: number; failure: number } {
|
||||
return sumRecentRequests(getProviderRecentBuckets(usageByProvider, provider, apiKey, baseUrl));
|
||||
}
|
||||
|
||||
export function getProviderRecentStats(
|
||||
usageByProvider: ProviderRecentUsageMap,
|
||||
provider: string,
|
||||
apiKey?: string,
|
||||
baseUrl?: string
|
||||
): { success: number; failure: number } {
|
||||
return getProviderTotalStats(usageByProvider, provider, apiKey, baseUrl);
|
||||
}
|
||||
): RecentRequestBucket[] =>
|
||||
getProviderRecentUsageEntry(usageByProvider, provider, apiKey, baseUrl).recentRequests;
|
||||
|
||||
export function getProviderRecentStatusData(
|
||||
usageByProvider: ProviderRecentUsageMap,
|
||||
@@ -179,10 +118,10 @@ export function getProviderRecentStatusData(
|
||||
);
|
||||
}
|
||||
|
||||
export function collectOpenAIProviderRecentBuckets(
|
||||
const collectOpenAIProviderRecentBuckets = (
|
||||
provider: OpenAIProviderConfig,
|
||||
usageByProvider: ProviderRecentUsageMap
|
||||
): RecentRequestBucket[] {
|
||||
): RecentRequestBucket[] => {
|
||||
if (!provider.apiKeyEntries?.length) {
|
||||
return [];
|
||||
}
|
||||
@@ -192,36 +131,7 @@ export function collectOpenAIProviderRecentBuckets(
|
||||
);
|
||||
|
||||
return mergeRecentRequestBucketGroups(groups);
|
||||
}
|
||||
|
||||
export function getOpenAIProviderRecentStats(
|
||||
provider: OpenAIProviderConfig,
|
||||
usageByProvider: ProviderRecentUsageMap
|
||||
): { success: number; failure: number } {
|
||||
return getOpenAIProviderTotalStats(provider, usageByProvider);
|
||||
}
|
||||
|
||||
export function getOpenAIProviderTotalStats(
|
||||
provider: OpenAIProviderConfig,
|
||||
usageByProvider: ProviderRecentUsageMap
|
||||
): { success: number; failure: number } {
|
||||
return (provider.apiKeyEntries || []).reduce(
|
||||
(total, entry) => {
|
||||
const usageEntry = getProviderRecentUsageEntry(
|
||||
usageByProvider,
|
||||
provider.name,
|
||||
entry.apiKey,
|
||||
provider.baseUrl
|
||||
);
|
||||
|
||||
return {
|
||||
success: total.success + usageEntry.success,
|
||||
failure: total.failure + usageEntry.failed,
|
||||
};
|
||||
},
|
||||
{ success: 0, failure: 0 }
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export function getOpenAIProviderRecentWindowStats(
|
||||
provider: OpenAIProviderConfig,
|
||||
@@ -238,109 +148,3 @@ export function getOpenAIProviderRecentStatusData(
|
||||
collectOpenAIProviderRecentBuckets(provider, usageByProvider)
|
||||
);
|
||||
}
|
||||
|
||||
export const getProviderConfigKey = (
|
||||
config: {
|
||||
authIndex?: unknown;
|
||||
apiKey?: string;
|
||||
baseUrl?: string;
|
||||
proxyUrl?: string;
|
||||
},
|
||||
index: number
|
||||
): string => {
|
||||
const authIndexKey = normalizeRecentRequestAuthIndex(config.authIndex);
|
||||
if (authIndexKey) {
|
||||
return authIndexKey;
|
||||
}
|
||||
return `${config.apiKey ?? ''}::${config.baseUrl ?? ''}::${config.proxyUrl ?? ''}::${index}`;
|
||||
};
|
||||
|
||||
export const getOpenAIProviderKey = (provider: OpenAIProviderConfig, index: number): string => {
|
||||
const authIndexKey = normalizeRecentRequestAuthIndex(provider.authIndex);
|
||||
if (authIndexKey) {
|
||||
return authIndexKey;
|
||||
}
|
||||
return `${provider.name}::${provider.baseUrl}::${provider.prefix ?? ''}::${index}`;
|
||||
};
|
||||
|
||||
export const getOpenAIEntryKey = (entry: ApiKeyEntry, index: number): string => {
|
||||
const authIndexKey = normalizeRecentRequestAuthIndex(entry.authIndex);
|
||||
if (authIndexKey) {
|
||||
return authIndexKey;
|
||||
}
|
||||
return `${entry.apiKey}::${entry.proxyUrl ?? ''}::${index}`;
|
||||
};
|
||||
|
||||
export const buildApiKeyEntry = (input?: Partial<ApiKeyEntry>): ApiKeyEntry => ({
|
||||
apiKey: input?.apiKey ?? '',
|
||||
proxyUrl: input?.proxyUrl ?? '',
|
||||
headers: input?.headers ?? {},
|
||||
});
|
||||
|
||||
export const ampcodeMappingsToEntries = (mappings?: AmpcodeModelMapping[]): ModelEntry[] => {
|
||||
if (!Array.isArray(mappings) || mappings.length === 0) {
|
||||
return [{ name: '', alias: '' }];
|
||||
}
|
||||
return mappings.map((mapping) => ({
|
||||
name: mapping.from ?? '',
|
||||
alias: mapping.to ?? '',
|
||||
}));
|
||||
};
|
||||
|
||||
export const entriesToAmpcodeMappings = (entries: ModelEntry[]): AmpcodeModelMapping[] => {
|
||||
const seen = new Set<string>();
|
||||
const mappings: AmpcodeModelMapping[] = [];
|
||||
|
||||
entries.forEach((entry) => {
|
||||
const from = entry.name.trim();
|
||||
const to = entry.alias.trim();
|
||||
if (!from || !to) return;
|
||||
const key = from.toLowerCase();
|
||||
if (seen.has(key)) return;
|
||||
seen.add(key);
|
||||
mappings.push({ from, to });
|
||||
});
|
||||
|
||||
return mappings;
|
||||
};
|
||||
|
||||
export const ampcodeUpstreamApiKeysToEntries = (
|
||||
mappings?: AmpcodeUpstreamApiKeyMapping[]
|
||||
): AmpcodeUpstreamApiKeyEntry[] => {
|
||||
if (!Array.isArray(mappings) || mappings.length === 0) {
|
||||
return [{ upstreamApiKey: '', clientApiKeysText: '' }];
|
||||
}
|
||||
|
||||
return mappings.map((mapping) => ({
|
||||
upstreamApiKey: mapping.upstreamApiKey ?? '',
|
||||
clientApiKeysText: Array.isArray(mapping.apiKeys) ? mapping.apiKeys.join('\n') : '',
|
||||
}));
|
||||
};
|
||||
|
||||
export const entriesToAmpcodeUpstreamApiKeys = (
|
||||
entries: AmpcodeUpstreamApiKeyEntry[]
|
||||
): AmpcodeUpstreamApiKeyMapping[] => {
|
||||
const seen = new Set<string>();
|
||||
const mappings: AmpcodeUpstreamApiKeyMapping[] = [];
|
||||
|
||||
entries.forEach((entry) => {
|
||||
const upstreamApiKey = String(entry?.upstreamApiKey ?? '').trim();
|
||||
if (!upstreamApiKey || seen.has(upstreamApiKey)) return;
|
||||
|
||||
const apiKeys = Array.from(new Set(parseTextList(String(entry?.clientApiKeysText ?? ''))));
|
||||
if (!apiKeys.length) return;
|
||||
|
||||
seen.add(upstreamApiKey);
|
||||
mappings.push({ upstreamApiKey, apiKeys });
|
||||
});
|
||||
|
||||
return mappings;
|
||||
};
|
||||
|
||||
export const buildAmpcodeFormState = (ampcode?: AmpcodeConfig | null): AmpcodeFormState => ({
|
||||
upstreamUrl: ampcode?.upstreamUrl ?? '',
|
||||
upstreamApiKey: '',
|
||||
forceModelMappings: ampcode?.forceModelMappings ?? false,
|
||||
mappingEntries: ampcodeMappingsToEntries(ampcode?.modelMappings),
|
||||
upstreamApiKeyEntries: ampcodeUpstreamApiKeysToEntries(ampcode?.upstreamApiKeys),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user