mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 21:30:17 +08:00
db44484726
API-key preset pointing at https://api.x.ai/v1 with wire_api = "responses": xAI serves the Responses API natively, so no route takeover conversion is needed. Ships a grok-4.5 catalog entry (500K context, parallel tools, text+image) so the model shows up under Codex's strict catalog parsing. This is deliberately not a managed-account preset: providerType stays absent, pinned by a regression test alongside the Claude-side xAI OAuth presets.
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { claudeDesktopProviderPresets } from "@/config/claudeDesktopProviderPresets";
|
|
import { providerPresets } from "@/config/claudeProviderPresets";
|
|
import { codexProviderPresets } from "@/config/codexProviderPresets";
|
|
import {
|
|
extractCodexBaseUrl,
|
|
extractCodexModelName,
|
|
extractCodexWireApi,
|
|
} from "@/utils/providerConfigUtils";
|
|
|
|
describe("xAI OAuth provider presets", () => {
|
|
it("pins the Claude Code preset to managed Responses auth", () => {
|
|
const preset = providerPresets.find((entry) => entry.name === "xAI (Grok)");
|
|
expect(preset).toBeDefined();
|
|
expect(preset).toMatchObject({
|
|
category: "third_party",
|
|
apiFormat: "openai_responses",
|
|
providerType: "xai_oauth",
|
|
requiresOAuth: true,
|
|
icon: "xai",
|
|
});
|
|
expect((preset!.settingsConfig as any).env).toMatchObject({
|
|
ANTHROPIC_BASE_URL: "https://api.x.ai/v1",
|
|
ANTHROPIC_MODEL: "grok-4.5",
|
|
ANTHROPIC_DEFAULT_HAIKU_MODEL: "grok-4.5",
|
|
ANTHROPIC_DEFAULT_SONNET_MODEL: "grok-4.5",
|
|
ANTHROPIC_DEFAULT_OPUS_MODEL: "grok-4.5",
|
|
});
|
|
expect((preset!.settingsConfig as any).env).not.toHaveProperty(
|
|
"ANTHROPIC_API_KEY",
|
|
);
|
|
expect((preset!.settingsConfig as any).env).not.toHaveProperty(
|
|
"ANTHROPIC_AUTH_TOKEN",
|
|
);
|
|
});
|
|
|
|
it("pins the Claude Desktop preset to proxy Responses mode without 1M", () => {
|
|
const preset = claudeDesktopProviderPresets.find(
|
|
(entry) => entry.name === "xAI (Grok)",
|
|
);
|
|
expect(preset).toMatchObject({
|
|
category: "third_party",
|
|
baseUrl: "https://api.x.ai/v1",
|
|
mode: "proxy",
|
|
apiFormat: "openai_responses",
|
|
providerType: "xai_oauth",
|
|
requiresOAuth: true,
|
|
icon: "xai",
|
|
});
|
|
expect(preset!.modelRoutes).toEqual([
|
|
expect.objectContaining({
|
|
upstreamModel: "grok-4.5",
|
|
supports1m: false,
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it("pins the Codex preset to native Responses via API key (no managed OAuth)", () => {
|
|
const preset = codexProviderPresets.find(
|
|
(entry) => entry.name === "xAI (Grok)",
|
|
);
|
|
expect(preset).toBeDefined();
|
|
expect(preset).toMatchObject({
|
|
category: "third_party",
|
|
apiFormat: "openai_responses",
|
|
icon: "xai",
|
|
});
|
|
// API-key preset: managed-account OAuth is Claude-side only for now.
|
|
expect(preset).not.toHaveProperty("providerType");
|
|
expect(preset!.auth).toEqual({ OPENAI_API_KEY: "" });
|
|
expect(extractCodexBaseUrl(preset!.config)).toBe("https://api.x.ai/v1");
|
|
expect(extractCodexWireApi(preset!.config)).toBe("responses");
|
|
expect(extractCodexModelName(preset!.config)).toBe("grok-4.5");
|
|
expect(preset!.modelCatalog).toEqual([
|
|
expect.objectContaining({
|
|
model: "grok-4.5",
|
|
contextWindow: 500000,
|
|
supportsParallelToolCalls: true,
|
|
inputModalities: ["text", "image"],
|
|
}),
|
|
]);
|
|
});
|
|
});
|