mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 06:15:03 +00:00
fix: harden provider alias normalization
This commit is contained in:
1 parent
c21f589247
commit
480f3ba469
4 files changed
+54
-23
No files matched your search
@@ -483,9 +483,8 @@ export async function reconcileExhaustedRotationAccounts(
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const { pauseAccountForQuotaCooldown, restoreExpiredQuotaPauses } = await import(
|
const { pauseAccountForQuotaCooldown, restoreExpiredQuotaPauses } =
|
||||||
'../accounts/account-safety'
|
await import('../accounts/account-safety');
|
||||||
);
|
|
||||||
restoreExpiredQuotaPauses();
|
restoreExpiredQuotaPauses();
|
||||||
|
|
||||||
const config = loadOrCreateUnifiedConfig();
|
const config = loadOrCreateUnifiedConfig();
|
||||||
@@ -593,9 +592,8 @@ export async function preflightCheck(provider: CLIProxyProvider): Promise<Prefli
|
|||||||
return { proceed: true, accountId: defaultAccount?.id || '' };
|
return { proceed: true, accountId: defaultAccount?.id || '' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const { pauseAccountForQuotaCooldown, restoreExpiredQuotaPauses } = await import(
|
const { pauseAccountForQuotaCooldown, restoreExpiredQuotaPauses } =
|
||||||
'../accounts/account-safety'
|
await import('../accounts/account-safety');
|
||||||
);
|
|
||||||
restoreExpiredQuotaPauses();
|
restoreExpiredQuotaPauses();
|
||||||
|
|
||||||
const config = loadOrCreateUnifiedConfig();
|
const config = loadOrCreateUnifiedConfig();
|
||||||
|
|||||||
@@ -112,9 +112,8 @@ export async function runImageAnalysisCheck(results: HealthCheck): Promise<void>
|
|||||||
* Fix image analysis configuration issues
|
* Fix image analysis configuration issues
|
||||||
*/
|
*/
|
||||||
export async function fixImageAnalysisConfig(): Promise<boolean> {
|
export async function fixImageAnalysisConfig(): Promise<boolean> {
|
||||||
const { updateConfig, loadOrCreateUnifiedConfig } = await import(
|
const { updateConfig, loadOrCreateUnifiedConfig } =
|
||||||
'../../config/config-loader-facade'
|
await import('../../config/config-loader-facade');
|
||||||
);
|
|
||||||
|
|
||||||
const config = loadOrCreateUnifiedConfig();
|
const config = loadOrCreateUnifiedConfig();
|
||||||
let fixed = false;
|
let fixed = false;
|
||||||
|
|||||||
@@ -18,19 +18,19 @@ export interface ModelsDevPricingLookupOptions {
|
|||||||
provider?: string;
|
provider?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PROVIDER_ALIASES: Record<string, string> = {
|
const PROVIDER_ALIASES = new Map<string, string>([
|
||||||
agy: 'google',
|
['agy', 'google'],
|
||||||
antigravity: 'google',
|
['antigravity', 'google'],
|
||||||
claude: 'anthropic',
|
['claude', 'anthropic'],
|
||||||
codex: 'openai',
|
['codex', 'openai'],
|
||||||
copilot: 'github-copilot',
|
['copilot', 'github-copilot'],
|
||||||
gemini: 'google',
|
['gemini', 'google'],
|
||||||
ghcp: 'github-copilot',
|
['ghcp', 'github-copilot'],
|
||||||
github: 'github-copilot',
|
['github', 'github-copilot'],
|
||||||
kimi: 'moonshotai',
|
['kimi', 'moonshotai'],
|
||||||
moonshot: 'moonshotai',
|
['moonshot', 'moonshotai'],
|
||||||
qwen: 'alibaba',
|
['qwen', 'alibaba'],
|
||||||
};
|
]);
|
||||||
|
|
||||||
function normalizeId(value: string): string {
|
function normalizeId(value: string): string {
|
||||||
return value.trim().toLowerCase();
|
return value.trim().toLowerCase();
|
||||||
@@ -45,7 +45,7 @@ export function normalizeModelsDevProviderId(
|
|||||||
): string | undefined {
|
): string | undefined {
|
||||||
if (!provider) return undefined;
|
if (!provider) return undefined;
|
||||||
const normalized = normalizeId(provider);
|
const normalized = normalizeId(provider);
|
||||||
return PROVIDER_ALIASES[normalized] ?? normalized;
|
return PROVIDER_ALIASES.get(normalized) ?? normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
function splitProviderPrefix(model: string): { provider?: string; model: string } {
|
function splitProviderPrefix(model: string): { provider?: string; model: string } {
|
||||||
|
|||||||
@@ -150,6 +150,40 @@ describe('aggregateDailyUsage', () => {
|
|||||||
expect(result[0].modelBreakdowns[0].provider).toBe('github-copilot');
|
expect(result[0].modelBreakdowns[0].provider).toBe('github-copilot');
|
||||||
expect(result[0].modelBreakdowns[0].inputTokens).toBe(3000);
|
expect(result[0].modelBreakdowns[0].inputTokens).toBe(3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('handles provider names inherited from Object.prototype', () => {
|
||||||
|
const entries: RawUsageEntry[] = [
|
||||||
|
createEntry({ model: 'model-a', target: '__proto__' }),
|
||||||
|
createEntry({ model: 'model-b', target: 'constructor' }),
|
||||||
|
createEntry({ model: 'model-c', target: 'toString' }),
|
||||||
|
];
|
||||||
|
|
||||||
|
const daily = aggregateDailyUsage(entries);
|
||||||
|
const hourly = aggregateHourlyUsage(entries);
|
||||||
|
const monthly = aggregateMonthlyUsage(entries);
|
||||||
|
const session = aggregateSessionUsage(entries);
|
||||||
|
|
||||||
|
expect(daily[0].modelBreakdowns.map((item) => item.provider)).toEqual([
|
||||||
|
'__proto__',
|
||||||
|
'constructor',
|
||||||
|
'tostring',
|
||||||
|
]);
|
||||||
|
expect(hourly[0].modelBreakdowns.map((item) => item.provider)).toEqual([
|
||||||
|
'__proto__',
|
||||||
|
'constructor',
|
||||||
|
'tostring',
|
||||||
|
]);
|
||||||
|
expect(monthly[0].modelBreakdowns.map((item) => item.provider)).toEqual([
|
||||||
|
'__proto__',
|
||||||
|
'constructor',
|
||||||
|
'tostring',
|
||||||
|
]);
|
||||||
|
expect(session[0].modelBreakdowns.map((item) => item.provider)).toEqual([
|
||||||
|
'__proto__',
|
||||||
|
'constructor',
|
||||||
|
'tostring',
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
Reference in new issue
Block a user