Skip to content

Commit d9afdaa

Browse files
author
mux
committed
refactor: extract shared ServiceTier type from ServiceTierSchema
The OpenAI service-tier literal union ('auto' | 'default' | 'flex' | 'priority') was duplicated in three places: the CLI options interface (src/cli/run.ts), the providerModelFactory cast at the providers.jsonc boundary, and a local OpenAIServiceTier alias in ProvidersSection.tsx. ServiceTierSchema (src/common/config/schemas/providersConfig.ts) already defines this enum as the runtime source of truth, so derive a TypeScript ServiceTier alias via z.infer once and import it at each site. Pure type-only refactor; the emitted JS and the schema remain unchanged.
1 parent 43b5711 commit d9afdaa

4 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/browser/features/Settings/Sections/ProvidersSection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ import type {
7878
AddCustomOpenAICompatibleProviderInput,
7979
ProviderConfigInfo,
8080
} from "@/common/orpc/types";
81+
import type { ServiceTier } from "@/common/config/schemas/providersConfig";
8182

8283
type MuxGatewayLoginStatus = "idle" | "starting" | "waiting" | "success" | "error";
8384
type CodexOauthFlowStatus = "idle" | "starting" | "waiting" | "error";
8485
type CopilotLoginStatus = "idle" | "starting" | "waiting" | "success" | "error";
8586

8687
const OPENAI_SERVICE_TIER_UNSET = "unset";
8788

88-
type OpenAIServiceTier = "auto" | "default" | "flex" | "priority";
89+
type OpenAIServiceTier = ServiceTier;
8990
type OpenAIServiceTierSelectValue = typeof OPENAI_SERVICE_TIER_UNSET | OpenAIServiceTier;
9091

9192
function isOpenAIServiceTier(value: string): value is OpenAIServiceTier {

src/cli/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
type SendMessageOptions,
3636
type WorkspaceChatMessage,
3737
} from "../common/orpc/types";
38+
import type { ServiceTier } from "../common/config/schemas/providersConfig";
3839
import { createDisplayUsage } from "../common/utils/tokens/displayUsage";
3940
import {
4041
getTotalCost,
@@ -298,7 +299,7 @@ interface CLIOptions {
298299
mcpConfig: boolean;
299300
experiment: string[];
300301
budget?: number;
301-
serviceTier?: "auto" | "default" | "flex" | "priority";
302+
serviceTier?: ServiceTier;
302303
use1m?: boolean;
303304
keepBackgroundProcesses?: boolean;
304305
}

src/common/config/schemas/providersConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ProviderModelEntrySchema } from "./providerModelEntry";
55

66
export const CacheTtlSchema = z.enum(["5m", "1h"]);
77
export const ServiceTierSchema = z.enum(["auto", "default", "flex", "priority"]);
8+
export type ServiceTier = z.infer<typeof ServiceTierSchema>;
89
export const CodexOauthDefaultAuthSchema = z.enum(["oauth", "apiKey"]);
910

1011
export const BaseProviderConfigSchema = z

src/node/services/providerModelFactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { parseCodexOauthAuth } from "@/node/utils/codexOauthAuth";
2121
import type { Config, ProviderConfig, ProvidersConfig } from "@/node/config";
2222
import type { MuxProviderOptions } from "@/common/types/providerOptions";
23+
import type { ServiceTier } from "@/common/config/schemas/providersConfig";
2324
import type { ExternalSecretResolver } from "@/common/types/secrets";
2425
import { isOpReference } from "@/common/utils/opRef";
2526
import { isProviderDisabledInConfig } from "@/common/utils/providers/isProviderDisabled";
@@ -1279,7 +1280,7 @@ export class ProviderModelFactory {
12791280
if (configServiceTier && muxProviderOptions.openai?.serviceTier == null) {
12801281
muxProviderOptions.openai = {
12811282
...muxProviderOptions.openai,
1282-
serviceTier: configServiceTier as "auto" | "default" | "flex" | "priority",
1283+
serviceTier: configServiceTier as ServiceTier,
12831284
};
12841285
}
12851286
if (configWireFormat === "responses" || configWireFormat === "chatCompletions") {

0 commit comments

Comments
 (0)