mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
Merge pull request #1441 from kaitranntt/codex/propose-fix-for-provider-alias-crash
fix: harden provider alias normalization
This commit is contained in:
@@ -18,19 +18,19 @@ export interface ModelsDevPricingLookupOptions {
|
||||
provider?: string;
|
||||
}
|
||||
|
||||
const PROVIDER_ALIASES: Record<string, string> = {
|
||||
agy: 'google',
|
||||
antigravity: 'google',
|
||||
claude: 'anthropic',
|
||||
codex: 'openai',
|
||||
copilot: 'github-copilot',
|
||||
gemini: 'google',
|
||||
ghcp: 'github-copilot',
|
||||
github: 'github-copilot',
|
||||
kimi: 'moonshotai',
|
||||
moonshot: 'moonshotai',
|
||||
qwen: 'alibaba',
|
||||
};
|
||||
const PROVIDER_ALIASES = new Map<string, string>([
|
||||
['agy', 'google'],
|
||||
['antigravity', 'google'],
|
||||
['claude', 'anthropic'],
|
||||
['codex', 'openai'],
|
||||
['copilot', 'github-copilot'],
|
||||
['gemini', 'google'],
|
||||
['ghcp', 'github-copilot'],
|
||||
['github', 'github-copilot'],
|
||||
['kimi', 'moonshotai'],
|
||||
['moonshot', 'moonshotai'],
|
||||
['qwen', 'alibaba'],
|
||||
]);
|
||||
|
||||
function normalizeId(value: string): string {
|
||||
return value.trim().toLowerCase();
|
||||
@@ -45,7 +45,7 @@ export function normalizeModelsDevProviderId(
|
||||
): string | undefined {
|
||||
if (!provider) return undefined;
|
||||
const normalized = normalizeId(provider);
|
||||
return PROVIDER_ALIASES[normalized] ?? normalized;
|
||||
return PROVIDER_ALIASES.get(normalized) ?? normalized;
|
||||
}
|
||||
|
||||
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].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