mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-16 16:15:19 +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:
2 files changed
+48
-14
No files matched your search
@@ -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