Skip to content

Commit 57a376f

Browse files
committed
fix(provider): skip grok-4.7 insert when vendor already lists it
1 parent f8f7e4d commit 57a376f

2 files changed

Lines changed: 49 additions & 11 deletions

File tree

‎src/auth/xai/constants.ts‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,30 @@ import {
88

99
export { XAI_BASE_URL, XAI_REDIRECT_URI, XAI_REFRESH_SKEW_MS };
1010

11+
const GROK_47 = "grok-4.7";
12+
1113
// Local extension over the vendor fallback list (CL-5691): grok-4.7 rides the
1214
// same OAuth proxy as the older Grok generations but the vendored catalog has
13-
// not caught up yet. The default stays the first vendor entry; drop this shim
14-
// once the vendor fallback lists grok-4.7 itself.
15-
const [firstVendorModel, secondVendorModel, ...restVendorModels] =
16-
VENDOR_XAI_DEFAULT_MODELS;
17-
export const XAI_DEFAULT_MODELS = [
18-
firstVendorModel,
19-
secondVendorModel,
20-
"grok-4.7",
21-
...restVendorModels,
22-
] as const;
15+
// not caught up yet. Insert after the second vendor entry and skip when the
16+
// vendor list already includes it so a vendor bump cannot duplicate. The
17+
// default stays the first vendor entry.
18+
export function extendVendorXaiDefaultModels(
19+
vendorModels: readonly string[],
20+
): readonly [string, ...string[]] {
21+
if (vendorModels.some((id) => id === GROK_47)) {
22+
const [first, ...rest] = vendorModels;
23+
if (first === undefined) return [GROK_47];
24+
return [first, ...rest];
25+
}
26+
const [first, second, ...rest] = vendorModels;
27+
if (first === undefined) return [GROK_47];
28+
if (second === undefined) return [first, GROK_47];
29+
return [first, second, GROK_47, ...rest];
30+
}
31+
32+
export const XAI_DEFAULT_MODELS = extendVendorXaiDefaultModels(
33+
VENDOR_XAI_DEFAULT_MODELS,
34+
);
2335

2436
const xaiRedirect = new URL(XAI_REDIRECT_URI);
2537
export const XAI_CALLBACK_PORT = Number(xaiRedirect.port);

‎src/config/xai-providers.test.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, expect, test } from "bun:test";
22

3-
import { XAI_BASE_URL, XAI_DEFAULT_MODELS } from "../auth/xai/constants.js";
3+
import {
4+
extendVendorXaiDefaultModels,
5+
XAI_BASE_URL,
6+
XAI_DEFAULT_MODELS,
7+
} from "../auth/xai/constants.js";
48
import type { XaiProfile } from "../auth/xai/store.js";
59
import { providerCatalogToSettings } from "./index.js";
610
import {
@@ -24,6 +28,28 @@ describe("xAI OAuth provider projection", () => {
2428
expect(models[0]).toBe("grok-4.5");
2529
});
2630

31+
test("skips grok-4.7 insert when the vendor list already includes it", () => {
32+
const vendor = [
33+
"grok-4.5",
34+
"grok-4.6",
35+
"grok-4.7",
36+
"grok-composer-2.5-fast",
37+
] as const;
38+
const models = extendVendorXaiDefaultModels(vendor);
39+
expect(models).toEqual(vendor);
40+
expect(models.filter((m) => m === "grok-4.7")).toHaveLength(1);
41+
});
42+
43+
test("inserts grok-4.7 after the second vendor model when absent", () => {
44+
expect(
45+
extendVendorXaiDefaultModels([
46+
"grok-4.5",
47+
"grok-4.6",
48+
"grok-composer-2.5-fast",
49+
]),
50+
).toEqual(["grok-4.5", "grok-4.6", "grok-4.7", "grok-composer-2.5-fast"]);
51+
});
52+
2753
const profile: XaiProfile = {
2854
name: "work",
2955
tokens: {

0 commit comments

Comments
 (0)