mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
feat(providers): add authIndex to API key entries and connectivity tests
This commit is contained in:
@@ -123,6 +123,7 @@ function buildInitialForm(
|
||||
apiKey: entry.apiKey,
|
||||
proxyUrl: entry.proxyUrl ?? '',
|
||||
headersText: headersObjectToText(entry.headers),
|
||||
authIndex: entry.authIndex,
|
||||
}))
|
||||
: [emptyApiKeyEntry()],
|
||||
};
|
||||
|
||||
@@ -126,7 +126,12 @@ export function useConnectivityTest(
|
||||
() =>
|
||||
(apiKeyEntries ?? []).map(
|
||||
(entry) =>
|
||||
`${entry.apiKey ?? ''}||${entry.proxyUrl ?? ''}||${entry.headersText ?? ''}`
|
||||
[
|
||||
entry.apiKey ?? '',
|
||||
entry.authIndex ?? '',
|
||||
entry.proxyUrl ?? '',
|
||||
entry.headersText ?? '',
|
||||
].join('||')
|
||||
),
|
||||
[apiKeyEntries]
|
||||
);
|
||||
@@ -199,7 +204,8 @@ export function useConnectivityTest(
|
||||
}
|
||||
const entry = apiKeyEntries?.[idx];
|
||||
const entryKey = (entry?.apiKey ?? '').trim();
|
||||
const resolvedAuthIndex = (authIndex ?? '').trim() || undefined;
|
||||
const resolvedAuthIndex =
|
||||
(entry?.authIndex ?? '').trim() || (authIndex ?? '').trim() || undefined;
|
||||
if (!entryKey && !resolvedAuthIndex) {
|
||||
updateOpenaiStatus(idx, {
|
||||
state: 'error',
|
||||
|
||||
@@ -110,9 +110,11 @@ export function useModelDiscovery(
|
||||
);
|
||||
} else if (brand === 'openaiCompatibility') {
|
||||
const firstEntry = (apiKeyEntries ?? []).find((e) =>
|
||||
(e.apiKey ?? '').trim()
|
||||
(e.apiKey ?? '').trim() || (e.authIndex ?? '').trim()
|
||||
);
|
||||
const entryKey = (firstEntry?.apiKey ?? '').trim();
|
||||
const entryAuthIndex =
|
||||
(firstEntry?.authIndex ?? '').trim() || resolvedAuthIndex;
|
||||
const entryHeaders = parseHeadersText(firstEntry?.headersText ?? '');
|
||||
const headers = { ...baseHeaders, ...entryHeaders };
|
||||
try {
|
||||
@@ -120,7 +122,7 @@ export function useModelDiscovery(
|
||||
baseUrl,
|
||||
entryKey,
|
||||
headers,
|
||||
resolvedAuthIndex
|
||||
entryAuthIndex
|
||||
);
|
||||
} catch (firstErr) {
|
||||
// Some OpenAI-compatible endpoints expose /models without auth, or
|
||||
@@ -165,9 +167,16 @@ export function useModelDiscovery(
|
||||
.map((h) => `${h.key}:${h.value}`)
|
||||
.join('|');
|
||||
const entriesSig = (apiKeyEntries ?? [])
|
||||
.map((e) => `${e.apiKey ?? ''}::${e.headersText ?? ''}`)
|
||||
.map((e) => `${e.apiKey ?? ''}::${e.authIndex ?? ''}::${e.headersText ?? ''}`)
|
||||
.join('|');
|
||||
return `${baseUrl}||${apiKey ?? ''}||${fallbackApiKey ?? ''}||${authIndex ?? ''}||${headerSig}||${entriesSig}`;
|
||||
return [
|
||||
baseUrl,
|
||||
apiKey ?? '',
|
||||
fallbackApiKey ?? '',
|
||||
authIndex ?? '',
|
||||
headerSig,
|
||||
entriesSig,
|
||||
].join('||');
|
||||
}, [apiKey, apiKeyEntries, authIndex, baseUrl, fallbackApiKey, formHeaders]);
|
||||
|
||||
const lastSignatureRef = useRef(inputSignature);
|
||||
|
||||
@@ -78,7 +78,8 @@ export interface ProviderSnapshot {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用 Sheet 表单值(Gemini/Codex/Claude/Vertex/OpenAI 共用基础字段,各自启用 advanced 区)
|
||||
* 通用 Sheet 表单值。
|
||||
* Gemini/Codex/Claude/Vertex/OpenAI 共用基础字段,各自启用 advanced 区。
|
||||
*/
|
||||
export interface ModelEntryInput {
|
||||
name: string;
|
||||
@@ -91,6 +92,7 @@ export interface ApiKeyEntryInput {
|
||||
apiKey: string;
|
||||
proxyUrl: string;
|
||||
headersText: string;
|
||||
authIndex?: string;
|
||||
}
|
||||
|
||||
export interface CloakInput {
|
||||
|
||||
@@ -180,6 +180,7 @@ const buildOpenAIConfig = (
|
||||
headers: Object.keys(parseHeadersText(entry.headersText)).length
|
||||
? parseHeadersText(entry.headersText)
|
||||
: undefined,
|
||||
authIndex: entry.authIndex?.trim() || undefined,
|
||||
}))
|
||||
.filter((entry) => entry.apiKey) ?? [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user