fix(cliproxy): harden xAI provider contracts

This commit is contained in:
Tam Nhu Tran committed 2026-07-18 19:04:07 -04:00
1 parent 90c0409aac
commit 4e4c949967
8 files changed
+110 -15

No files matched your search

+7 -6
View File
@@ -407,25 +407,21 @@ export const MODEL_CATALOGS: Record<string, ProviderCatalog> = {
id: 'grok-4.3',
name: 'Grok 4.3',
description: 'General-purpose Grok model with a one-million-token context window',
extendedContext: true,
},
{
id: 'grok-4.20-0309-reasoning',
name: 'Grok 4.20 0309 Reasoning',
description: 'Reasoning model with a two-million-token context window',
extendedContext: true,
},
{
id: 'grok-4.20-0309-non-reasoning',
name: 'Grok 4.20 0309 Non Reasoning',
description: 'Non-reasoning model with a two-million-token context window',
extendedContext: true,
},
{
id: 'grok-4.20-multi-agent-0309',
name: 'Grok 4.20 Multi Agent 0309',
description: 'Multi-agent model with a two-million-token context window',
extendedContext: true,
},
{
id: 'grok-3-mini',
@@ -1124,7 +1120,8 @@ export function buildUiCatalog(
provider: string,
liveCatalog: ProviderCatalog | undefined
): ProviderCatalog | undefined {
const staticCatalog = MODEL_CATALOGS[provider.toLowerCase()];
const normalizedProvider = provider.toLowerCase();
const staticCatalog = MODEL_CATALOGS[normalizedProvider];
if (!liveCatalog || liveCatalog.models.length === 0) {
return staticCatalog;
}
@@ -1145,7 +1142,10 @@ export function buildUiCatalog(
issueUrl: staticModel?.issueUrl,
deprecated: staticModel?.deprecated,
deprecationReason: staticModel?.deprecationReason,
extendedContext: model.extendedContext ?? staticModel?.extendedContext,
extendedContext:
normalizedProvider === 'xai'
? undefined
: (model.extendedContext ?? staticModel?.extendedContext),
presetMapping: staticModel?.presetMapping,
};
});
@@ -1344,5 +1344,6 @@ export function supportsExtendedContext(
modelId: string,
catalogOverride?: ProviderCatalog
): boolean {
if (provider.toLowerCase() === 'xai') return false;
return findCatalogModel(provider, modelId, catalogOverride)?.extendedContext === true;
}
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { MODEL_CATALOGS } from '@/lib/model-catalogs';
import { buildUiCatalog, MODEL_CATALOGS, supportsExtendedContext } from '@/lib/model-catalogs';
describe('xAI model catalog defaults', () => {
it('mirrors the CLIProxyAPI text catalog and default tier routing', () => {
@@ -27,4 +27,31 @@ describe('xAI model catalog defaults', () => {
haiku: 'grok-composer-2.5-fast',
});
});
it('does not expose Claude [1m] suffix support for xAI model IDs', () => {
const catalog = MODEL_CATALOGS.xai;
for (const model of catalog.models) {
expect(model.extendedContext).not.toBe(true);
expect(supportsExtendedContext('xai', model.id)).toBe(false);
}
});
it('strips generic extended-context metadata from live xAI catalogs', () => {
const catalog = buildUiCatalog('xai', {
provider: 'xai',
displayName: 'xAI (Grok)',
defaultModel: 'grok-4.3',
models: [
{
id: 'grok-4.3',
name: 'Grok 4.3',
extendedContext: true,
},
],
});
expect(catalog?.models[0]?.extendedContext).toBeUndefined();
expect(supportsExtendedContext('xai', 'grok-4.3', catalog)).toBe(false);
});
});