@devries-cameron20 / t3code-1 / commits / 40fcb6bdf8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix: restrict spark to non-plus users & fast mode gpt5.4 (#180)

* fix: restrict spark to non-plus users & fast mode gpt5.4 * nit * tests * tests --------- Co-authored-by: Theo Browne <me@t3.gg>

Yash Singh committed Mar 6, 2026 at 15:48 UTC 40fcb6bdf8d726f35c6d3aec82d0cce6345c9dcd
11 files changed +400 -22
apps/server/src/codexAppServerManager.test.ts
+111 -5
@@ -13,6 +13,8 @@ import {
13 classifyCodexStderrLine,
14 isRecoverableThreadResumeError,
15 normalizeCodexModelSlug,
16 + readCodexAccountSnapshot,
17 + resolveCodexModelForAccount,
18 } from "./codexAppServerManager";
19
20 const asThreadId = (value: string): ThreadId => ThreadId.makeUnsafe(value);
@@ -21,14 +23,20 @@ function createSendTurnHarness() {
23 const manager = new CodexAppServerManager();
24 const context = {
25 session: {
24 - sessionId: "sess_1",
26 provider: "codex",
27 status: "ready",
28 threadId: "thread_1",
29 + runtimeMode: "full-access",
30 + model: "gpt-5.3-codex",
31 resumeCursor: { threadId: "thread_1" },
32 createdAt: "2026-02-10T00:00:00.000Z",
33 updatedAt: "2026-02-10T00:00:00.000Z",
34 },
35 + account: {
36 + type: "unknown",
37 + planType: null,
38 + sparkEnabled: true,
39 + },
40 };
41
42 const requireSession = vi
@@ -58,10 +66,11 @@ function createThreadControlHarness() {
66 const manager = new CodexAppServerManager();
67 const context = {
68 session: {
61 - sessionId: "sess_1",
69 provider: "codex",
70 status: "ready",
71 threadId: "thread_1",
72 + runtimeMode: "full-access",
73 + model: "gpt-5.3-codex",
74 resumeCursor: { threadId: "thread_1" },
75 createdAt: "2026-02-10T00:00:00.000Z",
76 updatedAt: "2026-02-10T00:00:00.000Z",
@@ -89,10 +98,11 @@ function createPendingUserInputHarness() {
98 const manager = new CodexAppServerManager();
99 const context = {
100 session: {
92 - sessionId: "sess_1",
101 provider: "codex",
102 status: "ready",
103 threadId: "thread_1",
104 + runtimeMode: "full-access",
105 + model: "gpt-5.3-codex",
106 resumeCursor: { threadId: "thread_1" },
107 createdAt: "2026-02-10T00:00:00.000Z",
108 updatedAt: "2026-02-10T00:00:00.000Z",
@@ -195,6 +205,70 @@ describe("isRecoverableThreadResumeError", () => {
205 });
206 });
207
208 +describe("readCodexAccountSnapshot", () => {
209 + it("disables spark for chatgpt plus accounts", () => {
210 + expect(
211 + readCodexAccountSnapshot({
212 + type: "chatgpt",
213 + email: "plus@example.com",
214 + planType: "plus",
215 + }),
216 + ).toEqual({
217 + type: "chatgpt",
218 + planType: "plus",
219 + sparkEnabled: false,
220 + });
221 + });
222 +
223 + it("keeps spark enabled for chatgpt pro accounts", () => {
224 + expect(
225 + readCodexAccountSnapshot({
226 + type: "chatgpt",
227 + email: "pro@example.com",
228 + planType: "pro",
229 + }),
230 + ).toEqual({
231 + type: "chatgpt",
232 + planType: "pro",
233 + sparkEnabled: true,
234 + });
235 + });
236 +
237 + it("keeps spark enabled for api key accounts", () => {
238 + expect(
239 + readCodexAccountSnapshot({
240 + type: "apiKey",
241 + }),
242 + ).toEqual({
243 + type: "apiKey",
244 + planType: null,
245 + sparkEnabled: true,
246 + });
247 + });
248 +});
249 +
250 +describe("resolveCodexModelForAccount", () => {
251 + it("falls back from spark to default for unsupported chatgpt plans", () => {
252 + expect(
253 + resolveCodexModelForAccount("gpt-5.3-codex-spark", {
254 + type: "chatgpt",
255 + planType: "plus",
256 + sparkEnabled: false,
257 + }),
258 + ).toBe("gpt-5.3-codex");
259 + });
260 +
261 + it("keeps spark for supported plans", () => {
262 + expect(
263 + resolveCodexModelForAccount("gpt-5.3-codex-spark", {
264 + type: "chatgpt",
265 + planType: "pro",
266 + sparkEnabled: true,
267 + }),
268 + ).toBe("gpt-5.3-codex-spark");
269 + });
270 +});
271 +
272 describe("startSession", () => {
273 it("enables Codex experimental api capabilities during initialize", () => {
274 expect(buildCodexInitializeParams()).toEqual({
@@ -259,8 +333,8 @@ describe("sendTurn", () => {
333 },
334 ],
335 model: "gpt-5.3",
262 - effort: "high",
336 serviceTier: "fast",
337 + effort: "high",
338 });
339
340 expect(result).toEqual({
@@ -283,8 +357,8 @@ describe("sendTurn", () => {
357 },
358 ],
359 model: "gpt-5.3-codex",
286 - effort: "high",
360 serviceTier: "fast",
361 + effort: "high",
362 });
363 expect(updateSession).toHaveBeenCalledWith(context, {
364 status: "running",
@@ -314,6 +388,7 @@ describe("sendTurn", () => {
388 url: "data:image/png;base64,BBBB",
389 },
390 ],
391 + model: "gpt-5.3-codex",
392 });
393 });
394
@@ -377,6 +452,37 @@ describe("sendTurn", () => {
452 });
453 });
454
455 + it("keeps the session model when interaction mode is set without an explicit model", async () => {
456 + const { manager, context, sendRequest } = createSendTurnHarness();
457 + context.session.model = "gpt-5.2-codex";
458 +
459 + await manager.sendTurn({
460 + threadId: asThreadId("thread_1"),
461 + input: "Plan this with my current session model",
462 + interactionMode: "plan",
463 + });
464 +
465 + expect(sendRequest).toHaveBeenCalledWith(context, "turn/start", {
466 + threadId: "thread_1",
467 + input: [
468 + {
469 + type: "text",
470 + text: "Plan this with my current session model",
471 + text_elements: [],
472 + },
473 + ],
474 + model: "gpt-5.2-codex",
475 + collaborationMode: {
476 + mode: "plan",
477 + settings: {
478 + model: "gpt-5.2-codex",
479 + reasoning_effort: "medium",
480 + developer_instructions: CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS,
481 + },
482 + },
483 + });
484 + });
485 +
486 it("rejects empty turn input", async () => {
487 const { manager } = createSendTurnHarness();
488
apps/server/src/codexAppServerManager.ts
+110 -8
@@ -58,6 +58,7 @@ interface CodexUserInputAnswer {
58
59 interface CodexSessionContext {
60 session: ProviderSession;
61 + account: CodexAccountSnapshot;
62 child: ChildProcessWithoutNullStreams;
63 output: readline.Interface;
64 pending: Map<PendingRequestKey, PendingRequest>;
@@ -89,13 +90,30 @@ interface JsonRpcNotification {
90 params?: unknown;
91 }
92
93 +type CodexPlanType =
94 + | "free"
95 + | "go"
96 + | "plus"
97 + | "pro"
98 + | "team"
99 + | "business"
100 + | "enterprise"
101 + | "edu"
102 + | "unknown";
103 +
104 +interface CodexAccountSnapshot {
105 + readonly type: "apiKey" | "chatgpt" | "unknown";
106 + readonly planType: CodexPlanType | null;
107 + readonly sparkEnabled: boolean;
108 +}
109 +
110 export interface CodexAppServerSendTurnInput {
111 readonly threadId: ThreadId;
112 readonly input?: string;
113 readonly attachments?: ReadonlyArray<{ type: "image"; url: string }>;
114 readonly model?: string;
115 + readonly serviceTier?: string | null;
116 readonly effort?: string;
98 - readonly serviceTier?: string;
117 readonly interactionMode?: ProviderInteractionMode;
118 }
119
@@ -135,6 +153,50 @@ const RECOVERABLE_THREAD_RESUME_ERROR_SNIPPETS = [
153 "unknown thread",
154 "does not exist",
155 ];
156 +const CODEX_DEFAULT_MODEL = "gpt-5.3-codex";
157 +const CODEX_SPARK_MODEL = "gpt-5.3-codex-spark";
158 +const CODEX_SPARK_DISABLED_PLAN_TYPES = new Set<CodexPlanType>(["free", "go", "plus"]);
159 +
160 +function asObject(value: unknown): Record<string, unknown> | undefined {
161 + if (!value || typeof value !== "object") {
162 + return undefined;
163 + }
164 + return value as Record<string, unknown>;
165 +}
166 +
167 +function asString(value: unknown): string | undefined {
168 + return typeof value === "string" ? value : undefined;
169 +}
170 +
171 +export function readCodexAccountSnapshot(response: unknown): CodexAccountSnapshot {
172 + const record = asObject(response);
173 + const account = asObject(record?.account) ?? record;
174 + const accountType = asString(account?.type);
175 +
176 + if (accountType === "apiKey") {
177 + return {
178 + type: "apiKey",
179 + planType: null,
180 + sparkEnabled: true,
181 + };
182 + }
183 +
184 + if (accountType === "chatgpt") {
185 + const planType = (account?.planType as CodexPlanType | null) ?? "unknown";
186 + return {
187 + type: "chatgpt",
188 + planType,
189 + sparkEnabled: !CODEX_SPARK_DISABLED_PLAN_TYPES.has(planType),
190 + };
191 + }
192 +
193 + return {
194 + type: "unknown",
195 + planType: null,
196 + sparkEnabled: true,
197 + };
198 +}
199 +
200 export const CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS = `<collaboration_mode># Plan Mode (Conversational)
201
202 You work in 3 phases, and you should *chat your way* to a great plan before finalizing it. A great plan is very detailed-intent- and implementation-wise-so that it can be handed to another engineer or agent to be implemented right away. It must be **decision complete**, where the implementer does not need to make any decisions.
@@ -287,6 +349,17 @@ function mapCodexRuntimeMode(runtimeMode: RuntimeMode): {
349 };
350 }
351
352 +export function resolveCodexModelForAccount(
353 + model: string | undefined,
354 + account: CodexAccountSnapshot,
355 +): string | undefined {
356 + if (model !== CODEX_SPARK_MODEL || account.sparkEnabled) {
357 + return model;
358 + }
359 +
360 + return CODEX_DEFAULT_MODEL;
361 +}
362 +
363 /**
364 * On Windows with `shell: true`, `child.kill()` only terminates the `cmd.exe`
365 * wrapper, leaving the actual command running. Use `taskkill /T` to kill the
@@ -475,6 +548,11 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
548
549 context = {
550 session,
551 + account: {
552 + type: "unknown",
553 + planType: null,
554 + sparkEnabled: true,
555 + },
556 child,
557 output,
558 pending: new Map(),
@@ -492,12 +570,33 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
570 await this.sendRequest(context, "initialize", buildCodexInitializeParams());
571
572 this.writeMessage(context, { method: "initialized" });
573 + try {
574 + const modelListResponse = await this.sendRequest(context, "model/list", {});
575 + console.log("codex model/list response", modelListResponse);
576 + } catch (error) {
577 + console.log("codex model/list failed", error);
578 + }
579 + try {
580 + const accountReadResponse = await this.sendRequest(context, "account/read", {});
581 + console.log("codex account/read response", accountReadResponse);
582 + context.account = readCodexAccountSnapshot(accountReadResponse);
583 + console.log("codex subscription status", {
584 + type: context.account.type,
585 + planType: context.account.planType,
586 + sparkEnabled: context.account.sparkEnabled,
587 + });
588 + } catch (error) {
589 + console.log("codex account/read failed", error);
590 + }
591
496 - const normalizedModel = normalizeCodexModelSlug(input.model);
592 + const normalizedModel = resolveCodexModelForAccount(
593 + normalizeCodexModelSlug(input.model),
594 + context.account,
595 + );
596 const sessionOverrides = {
597 model: normalizedModel ?? null,
499 - cwd: input.cwd ?? null,
598 ...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
599 + cwd: input.cwd ?? null,
600 ...mapCodexRuntimeMode(input.runtimeMode ?? "full-access"),
601 };
602
@@ -657,8 +756,8 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
756 { type: "text"; text: string; text_elements: [] } | { type: "image"; url: string }
757 >;
758 model?: string;
759 + serviceTier?: string | null;
760 effort?: string;
661 - serviceTier?: string;
761 collaborationMode?: {
762 mode: "default" | "plan";
763 settings: {
@@ -671,16 +770,19 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
770 threadId: providerThreadId,
771 input: turnInput,
772 };
674 - const normalizedModel = normalizeCodexModelSlug(input.model ?? context.session.model);
773 + const normalizedModel = resolveCodexModelForAccount(
774 + normalizeCodexModelSlug(input.model ?? context.session.model),
775 + context.account,
776 + );
777 if (normalizedModel) {
778 turnStartParams.model = normalizedModel;
779 }
780 + if (input.serviceTier !== undefined) {
781 + turnStartParams.serviceTier = input.serviceTier;
782 + }
783 if (input.effort) {
784 turnStartParams.effort = input.effort;
785 }
681 - if (input.serviceTier) {
682 - turnStartParams.serviceTier = input.serviceTier;
683 - }
786 const collaborationMode = buildCodexCollaborationMode({
787 ...(input.interactionMode !== undefined ? { interactionMode: input.interactionMode } : {}),
788 ...(normalizedModel !== undefined ? { model: normalizedModel } : {}),
apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
+7
@@ -5,6 +5,7 @@ import {
5 type OrchestrationEvent,
6 type ProviderModelOptions,
7 type ProviderKind,
8 + type ProviderServiceTier,
9 type OrchestrationSession,
10 ThreadId,
11 type ProviderSession,
@@ -201,6 +202,7 @@ const make = Effect.gen(function* () {
202 readonly provider?: ProviderKind;
203 readonly model?: string;
204 readonly modelOptions?: ProviderModelOptions;
205 + readonly serviceTier?: ProviderServiceTier | null;
206 },
207 ) {
208 const readModel = yield* orchestrationEngine.getReadModel();
@@ -235,6 +237,7 @@ const make = Effect.gen(function* () {
237 : {}),
238 ...(effectiveCwd ? { cwd: effectiveCwd } : {}),
239 ...(desiredModel ? { model: desiredModel } : {}),
240 + ...(options?.serviceTier !== undefined ? { serviceTier: options.serviceTier } : {}),
241 ...(options?.modelOptions !== undefined ? { modelOptions: options.modelOptions } : {}),
242 ...(input?.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),
243 runtimeMode: desiredRuntimeMode,
@@ -320,6 +323,7 @@ const make = Effect.gen(function* () {
323 readonly attachments?: ReadonlyArray<ChatAttachment>;
324 readonly provider?: ProviderKind;
325 readonly model?: string;
326 + readonly serviceTier?: ProviderServiceTier | null;
327 readonly modelOptions?: ProviderModelOptions;
328 readonly interactionMode?: "default" | "plan";
329 readonly createdAt: string;
@@ -331,6 +335,7 @@ const make = Effect.gen(function* () {
335 yield* ensureSessionForThread(input.threadId, input.createdAt, {
336 ...(input.provider !== undefined ? { provider: input.provider } : {}),
337 ...(input.model !== undefined ? { model: input.model } : {}),
338 + ...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
339 ...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
340 });
341 const normalizedInput = toNonEmptyProviderInput(input.messageText);
@@ -350,6 +355,7 @@ const make = Effect.gen(function* () {
355 ...(normalizedInput ? { input: normalizedInput } : {}),
356 ...(normalizedAttachments.length > 0 ? { attachments: normalizedAttachments } : {}),
357 ...(modelForTurn !== undefined ? { model: modelForTurn } : {}),
358 + ...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
359 ...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
360 ...(input.interactionMode !== undefined ? { interactionMode: input.interactionMode } : {}),
361 });
@@ -464,6 +470,7 @@ const make = Effect.gen(function* () {
470 ...(message.attachments !== undefined ? { attachments: message.attachments } : {}),
471 ...(event.payload.provider !== undefined ? { provider: event.payload.provider } : {}),
472 ...(event.payload.model !== undefined ? { model: event.payload.model } : {}),
473 + ...(event.payload.serviceTier !== undefined ? { serviceTier: event.payload.serviceTier } : {}),
474 ...(event.payload.modelOptions !== undefined ? { modelOptions: event.payload.modelOptions } : {}),
475 interactionMode: event.payload.interactionMode,
476 createdAt: event.payload.createdAt,
apps/server/src/orchestration/decider.ts
+1
@@ -301,6 +301,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
301 messageId: command.message.messageId,
302 ...(command.provider !== undefined ? { provider: command.provider } : {}),
303 ...(command.model !== undefined ? { model: command.model } : {}),
304 + ...(command.serviceTier !== undefined ? { serviceTier: command.serviceTier } : {}),
305 ...(command.modelOptions !== undefined ? { modelOptions: command.modelOptions } : {}),
306 assistantDeliveryMode: command.assistantDeliveryMode ?? DEFAULT_ASSISTANT_DELIVERY_MODE,
307 runtimeMode:
apps/server/src/provider/Layers/CodexAdapter.ts
+1
@@ -1354,6 +1354,7 @@ const makeCodexAdapter = (options?: CodexAdapterLiveOptions) =>
1354 threadId: input.threadId,
1355 ...(input.input !== undefined ? { input: input.input } : {}),
1356 ...(input.model !== undefined ? { model: input.model } : {}),
1357 + ...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
1358 ...(input.modelOptions?.codex?.reasoningEffort !== undefined
1359 ? { effort: input.modelOptions.codex.reasoningEffort }
1360 : {}),
apps/web/src/appSettings.test.ts
+21
@@ -4,6 +4,8 @@ import {
4 getAppModelOptions,
5 getSlashModelOptions,
6 normalizeCustomModelSlugs,
7 + resolveAppServiceTier,
8 + shouldShowFastTierIcon,
9 resolveAppModelSelection,
10 } from "./appSettings";
11
@@ -82,3 +84,22 @@ describe("getSlashModelOptions", () => {
84 expect(options.map((option) => option.slug)).toEqual(["openai/gpt-oss-120b"]);
85 });
86 });
87 +
88 +describe("resolveAppServiceTier", () => {
89 + it("maps automatic to no override", () => {
90 + expect(resolveAppServiceTier("auto")).toBeNull();
91 + });
92 +
93 + it("preserves explicit service tier overrides", () => {
94 + expect(resolveAppServiceTier("fast")).toBe("fast");
95 + expect(resolveAppServiceTier("flex")).toBe("flex");
96 + });
97 +});
98 +
99 +describe("shouldShowFastTierIcon", () => {
100 + it("shows the fast-tier icon only for gpt-5.4 on fast tier", () => {
101 + expect(shouldShowFastTierIcon("gpt-5.4", "fast")).toBe(true);
102 + expect(shouldShowFastTierIcon("gpt-5.4", "auto")).toBe(false);
103 + expect(shouldShowFastTierIcon("gpt-5.3-codex", "fast")).toBe(false);
104 + });
105 +});
apps/web/src/appSettings.ts
+38 -1
@@ -1,11 +1,31 @@
1 import { useCallback, useSyncExternalStore } from "react";
2 import { Option, Schema } from "effect";
3 -import { type ProviderKind } from "@t3tools/contracts";
3 +import { type ProviderKind, type ProviderServiceTier } from "@t3tools/contracts";
4 import { getDefaultModel, getModelOptions, normalizeModelSlug } from "@t3tools/shared/model";
5
6 const APP_SETTINGS_STORAGE_KEY = "t3code:app-settings:v1";
7 const MAX_CUSTOM_MODEL_COUNT = 32;
8 export const MAX_CUSTOM_MODEL_LENGTH = 256;
9 +export const APP_SERVICE_TIER_OPTIONS = [
10 + {
11 + value: "auto",
12 + label: "Automatic",
13 + description: "Use Codex defaults without forcing a service tier.",
14 + },
15 + {
16 + value: "fast",
17 + label: "Fast",
18 + description: "Request the fast service tier when the model supports it.",
19 + },
20 + {
21 + value: "flex",
22 + label: "Flex",
23 + description: "Request the flex service tier when the model supports it.",
24 + },
25 +] as const;
26 +export type AppServiceTier = (typeof APP_SERVICE_TIER_OPTIONS)[number]["value"];
27 +const AppServiceTierSchema = Schema.Literals(["auto", "fast", "flex"]);
28 +const MODELS_WITH_FAST_SUPPORT = new Set(["gpt-5.4"]);
29 const BUILT_IN_MODEL_SLUGS_BY_PROVIDER: Record<ProviderKind, ReadonlySet<string>> = {
30 codex: new Set(getModelOptions("codex").map((option) => option.slug)),
31 };
@@ -21,6 +41,7 @@ const AppSettingsSchema = Schema.Struct({
41 enableAssistantStreaming: Schema.Boolean.pipe(
42 Schema.withConstructorDefault(() => Option.some(false)),
43 ),
44 + codexServiceTier: AppServiceTierSchema.pipe(Schema.withConstructorDefault(() => Option.some("auto"))),
45 customCodexModels: Schema.Array(Schema.String).pipe(
46 Schema.withConstructorDefault(() => Option.some([])),
47 ),
@@ -32,6 +53,22 @@ export interface AppModelOption {
53 isCustom: boolean;
54 }
55
56 +export function resolveAppServiceTier(serviceTier: AppServiceTier): ProviderServiceTier | null {
57 + return serviceTier === "auto" ? null : serviceTier;
58 +}
59 +
60 +export function shouldShowFastTierIcon(
61 + model: string | null | undefined,
62 + serviceTier: AppServiceTier,
63 +): boolean {
64 + const normalizedModel = normalizeModelSlug(model);
65 + return (
66 + resolveAppServiceTier(serviceTier) === "fast" &&
67 + normalizedModel !== null &&
68 + MODELS_WITH_FAST_SUPPORT.has(normalizedModel)
69 + );
70 +}
71 +
72 const DEFAULT_APP_SETTINGS = AppSettingsSchema.makeUnsafe({});
73
74 let listeners: Array<() => void> = [];
apps/web/src/components/ChatView.tsx
+31 -3
@@ -140,6 +140,7 @@ import {
140 XIcon,
141 CopyIcon,
142 CheckIcon,
143 + ZapIcon,
144 } from "lucide-react";
145 import { Button } from "./ui/button";
146 import { Input } from "./ui/input";
@@ -196,7 +197,14 @@ import { Toggle } from "./ui/toggle";
197 import { SidebarTrigger } from "./ui/sidebar";
198 import { newCommandId, newMessageId, newThreadId } from "~/lib/utils";
199 import { readNativeApi } from "~/nativeApi";
199 -import { getAppModelOptions, resolveAppModelSelection, useAppSettings } from "../appSettings";
200 +import {
201 + getAppModelOptions,
202 + resolveAppModelSelection,
203 + resolveAppServiceTier,
204 + shouldShowFastTierIcon,
205 + type AppServiceTier,
206 + useAppSettings,
207 +} from "../appSettings";
208 import {
209 type ComposerImageAttachment,
210 type DraftThreadEnvMode,
@@ -388,6 +396,7 @@ type ComposerCommandItem =
396 model: ModelSlug;
397 label: string;
398 description: string;
399 + showFastBadge: boolean;
400 };
401
402 type SendPhase = "idle" | "preparing-worktree" | "sending-turn";
@@ -497,7 +506,12 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
506 model
507 </Badge>
508 ) : null}
500 - <span className="truncate">{props.item.label}</span>
509 + <span className="flex min-w-0 items-center gap-1.5 truncate">
510 + {props.item.type === "model" && props.item.showFastBadge ? (
511 + <ZapIcon className="size-3.5 shrink-0 text-amber-500" />
512 + ) : null}
513 + <span className="truncate">{props.item.label}</span>
514 + </span>
515 <span className="truncate text-muted-foreground/70 text-xs">{props.item.description}</span>
516 </CommandItem>
517 );
@@ -754,6 +768,8 @@ export default function ChatView({ threadId }: ChatViewProps) {
768 activeThread.messages.length > 0 ||
769 activeThread.session !== null),
770 );
771 + const selectedServiceTierSetting = settings.codexServiceTier;
772 + const selectedServiceTier = resolveAppServiceTier(selectedServiceTierSetting);
773 const lockedProvider: ProviderKind | null = hasThreadStarted
774 ? (sessionProvider ?? selectedProviderByThreadId ?? null)
775 : null;
@@ -1205,8 +1221,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
1221 model: slug,
1222 label: name,
1223 description: `${providerLabel} · ${slug}`,
1224 + showFastBadge:
1225 + provider === "codex" && shouldShowFastTierIcon(slug, selectedServiceTierSetting),
1226 }));
1209 - }, [composerTrigger, searchableModelOptions, workspaceEntries]);
1227 + }, [composerTrigger, searchableModelOptions, selectedServiceTierSetting, workspaceEntries]);
1228 const composerMenuOpen = Boolean(composerTrigger);
1229 const activeComposerMenuItem = useMemo(
1230 () =>
@@ -2539,6 +2557,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
2557 attachments: turnAttachments,
2558 },
2559 model: selectedModel || undefined,
2560 + serviceTier: selectedServiceTier,
2561 ...(selectedModelOptionsForDispatch
2562 ? { modelOptions: selectedModelOptionsForDispatch }
2563 : {}),
@@ -3534,6 +3553,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
3553 model={selectedModelForPickerWithCustomFallback}
3554 lockedProvider={lockedProvider}
3555 modelOptionsByProvider={modelOptionsByProvider}
3556 + serviceTierSetting={selectedServiceTierSetting}
3557 onProviderModelChange={onProviderModelSelect}
3558 />
3559
@@ -5220,6 +5240,7 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
5240 model: ModelSlug;
5241 lockedProvider: ProviderKind | null;
5242 modelOptionsByProvider: Record<ProviderKind, ReadonlyArray<{ slug: string; name: string }>>;
5243 + serviceTierSetting: AppServiceTier;
5244 disabled?: boolean;
5245 onProviderModelChange: (provider: ProviderKind, model: ModelSlug) => void;
5246 }) {
@@ -5252,6 +5273,9 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
5273 >
5274 <span className="flex min-w-0 items-center gap-2">
5275 <ProviderIcon aria-hidden="true" className="size-4 shrink-0 text-muted-foreground/70" />
5276 + {props.provider === "codex" && shouldShowFastTierIcon(props.model, props.serviceTierSetting) ? (
5277 + <ZapIcon className="size-3.5 shrink-0 text-amber-500" />
5278 + ) : null}
5279 <span className="truncate">{selectedModelLabel}</span>
5280 <ChevronDownIcon aria-hidden="true" className="size-3 opacity-60" />
5281 </span>
@@ -5294,6 +5318,10 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
5318 value={modelOption.slug}
5319 onClick={() => setIsMenuOpen(false)}
5320 >
5321 + {option.value === "codex" &&
5322 + shouldShowFastTierIcon(modelOption.slug, props.serviceTierSetting) ? (
5323 + <ZapIcon className="size-3.5 shrink-0 text-amber-500" />
5324 + ) : null}
5325 {modelOption.name}
5326 </MenuRadioItem>
5327 ))}
apps/web/src/routes/_chat.settings.tsx
+55 -5
@@ -3,8 +3,14 @@ import { useQuery } from "@tanstack/react-query";
3 import { useCallback, useState } from "react";
4 import { type ProviderKind } from "@t3tools/contracts";
5 import { getModelOptions, normalizeModelSlug } from "@t3tools/shared/model";
6 -
7 -import { MAX_CUSTOM_MODEL_LENGTH, useAppSettings } from "../appSettings";
6 +import { ZapIcon } from "lucide-react";
7 +
8 +import {
9 + APP_SERVICE_TIER_OPTIONS,
10 + MAX_CUSTOM_MODEL_LENGTH,
11 + shouldShowFastTierIcon,
12 + useAppSettings,
13 +} from "../appSettings";
14 import { isElectron } from "../env";
15 import { useTheme } from "../hooks/useTheme";
16 import { serverConfigQueryOptions } from "../lib/serverReactQuery";
@@ -12,6 +18,7 @@ import { ensureNativeApi } from "../nativeApi";
18 import { preferredTerminalEditor } from "../terminal-links";
19 import { Button } from "../components/ui/button";
20 import { Input } from "../components/ui/input";
21 +import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../components/ui/select";
22 import { Switch } from "../components/ui/switch";
23 import { SidebarInset } from "~/components/ui/sidebar";
24
@@ -96,6 +103,7 @@ function SettingsRouteView() {
103
104 const codexBinaryPath = settings.codexBinaryPath;
105 const codexHomePath = settings.codexHomePath;
106 + const codexServiceTier = settings.codexServiceTier;
107 const keybindingsConfigPath = serverConfigQuery.data?.keybindingsConfigPath ?? null;
108
109 const openKeybindingsFile = useCallback(() => {
@@ -302,6 +310,43 @@ function SettingsRouteView() {
310 </div>
311
312 <div className="space-y-5">
313 + <label className="block space-y-1">
314 + <span className="text-xs font-medium text-foreground">Default service tier</span>
315 + <Select
316 + items={APP_SERVICE_TIER_OPTIONS.map((option) => ({
317 + label: option.label,
318 + value: option.value,
319 + }))}
320 + value={codexServiceTier}
321 + onValueChange={(value) => {
322 + if (!value) return;
323 + updateSettings({ codexServiceTier: value });
324 + }}
325 + >
326 + <SelectTrigger>
327 + <SelectValue />
328 + </SelectTrigger>
329 + <SelectPopup alignItemWithTrigger={false}>
330 + {APP_SERVICE_TIER_OPTIONS.map((option) => (
331 + <SelectItem key={option.value} value={option.value}>
332 + <div className="flex min-w-0 items-center gap-2">
333 + {option.value === "fast" ? (
334 + <ZapIcon className="size-3.5 text-amber-500" />
335 + ) : (
336 + <span className="size-3.5 shrink-0" aria-hidden="true" />
337 + )}
338 + <span className="truncate">{option.label}</span>
339 + </div>
340 + </SelectItem>
341 + ))}
342 + </SelectPopup>
343 + </Select>
344 + <span className="text-xs text-muted-foreground">
345 + {APP_SERVICE_TIER_OPTIONS.find((option) => option.value === codexServiceTier)
346 + ?.description ?? "Use Codex defaults without forcing a service tier."}
347 + </span>
348 + </label>
349 +
350 {MODEL_PROVIDER_SETTINGS.map((providerSettings) => {
351 const provider = providerSettings.provider;
352 const customModels = getCustomModelsForProvider(settings, provider);
@@ -400,9 +445,14 @@ function SettingsRouteView() {
445 key={`${provider}:${slug}`}
446 className="flex items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2"
447 >
403 - <code className="min-w-0 flex-1 truncate text-xs text-foreground">
404 - {slug}
405 - </code>
448 + <div className="flex min-w-0 flex-1 items-center gap-2">
449 + {provider === "codex" && shouldShowFastTierIcon(slug, codexServiceTier) ? (
450 + <ZapIcon className="size-3.5 shrink-0 text-amber-500" />
451 + ) : null}
452 + <code className="min-w-0 flex-1 truncate text-xs text-foreground">
453 + {slug}
454 + </code>
455 + </div>
456 <Button
457 size="xs"
458 variant="ghost"
packages/contracts/src/orchestration.ts
+18
@@ -29,6 +29,21 @@ export const ORCHESTRATION_WS_CHANNELS = {
29
30 export const ProviderKind = Schema.Literal("codex");
31 export type ProviderKind = typeof ProviderKind.Type;
32 +export const ProviderApprovalPolicy = Schema.Literals([
33 + "untrusted",
34 + "on-failure",
35 + "on-request",
36 + "never",
37 +]);
38 +export type ProviderApprovalPolicy = typeof ProviderApprovalPolicy.Type;
39 +export const ProviderSandboxMode = Schema.Literals([
40 + "read-only",
41 + "workspace-write",
42 + "danger-full-access",
43 +]);
44 +export type ProviderSandboxMode = typeof ProviderSandboxMode.Type;
45 +export const ProviderServiceTier = Schema.Literals(["fast", "flex"]);
46 +export type ProviderServiceTier = typeof ProviderServiceTier.Type;
47 export const DEFAULT_PROVIDER_KIND: ProviderKind = "codex";
48 export const RuntimeMode = Schema.Literals(["approval-required", "full-access"]);
49 export type RuntimeMode = typeof RuntimeMode.Type;
@@ -349,6 +364,7 @@ export const ThreadTurnStartCommand = Schema.Struct({
364 }),
365 provider: Schema.optional(ProviderKind),
366 model: Schema.optional(TrimmedNonEmptyString),
367 + serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
368 modelOptions: Schema.optional(ProviderModelOptions),
369 assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
370 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
@@ -370,6 +386,7 @@ const ClientThreadTurnStartCommand = Schema.Struct({
386 }),
387 provider: Schema.optional(ProviderKind),
388 model: Schema.optional(TrimmedNonEmptyString),
389 + serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
390 modelOptions: Schema.optional(ProviderModelOptions),
391 assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
392 runtimeMode: RuntimeMode,
@@ -649,6 +666,7 @@ export const ThreadTurnStartRequestedPayload = Schema.Struct({
666 messageId: MessageId,
667 provider: Schema.optional(ProviderKind),
668 model: Schema.optional(TrimmedNonEmptyString),
669 + serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
670 modelOptions: Schema.optional(ProviderModelOptions),
671 assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
672 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
packages/contracts/src/provider.ts
+7
@@ -14,9 +14,12 @@ import {
14 PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
15 PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
16 ProviderApprovalDecision,
17 + ProviderApprovalPolicy,
18 ProviderInteractionMode,
19 ProviderKind,
20 ProviderRequestKind,
21 + ProviderSandboxMode,
22 + ProviderServiceTier,
23 ProviderUserInputAnswers,
24 RuntimeMode,
25 } from "./orchestration";
@@ -61,6 +64,9 @@ export const ProviderSessionStartInput = Schema.Struct({
64 model: Schema.optional(TrimmedNonEmptyStringSchema),
65 modelOptions: Schema.optional(ProviderModelOptions),
66 resumeCursor: Schema.optional(Schema.Unknown),
67 + serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
68 + approvalPolicy: Schema.optional(ProviderApprovalPolicy),
69 + sandboxMode: Schema.optional(ProviderSandboxMode),
70 providerOptions: Schema.optional(ProviderStartOptions),
71 runtimeMode: RuntimeMode,
72 });
@@ -75,6 +81,7 @@ export const ProviderSendTurnInput = Schema.Struct({
81 Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
82 ),
83 model: Schema.optional(TrimmedNonEmptyStringSchema),
84 + serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
85 modelOptions: Schema.optional(ProviderModelOptions),
86 interactionMode: Schema.optional(ProviderInteractionMode),
87 });