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 <[email protected]>
This commit is contained in:
1 parent
d58ff5de26
commit
40fcb6bdf8
11 files changed
+399
-21
No files matched your search
@@ -13,6 +13,8 @@ import {
|
||||
classifyCodexStderrLine,
|
||||
isRecoverableThreadResumeError,
|
||||
normalizeCodexModelSlug,
|
||||
readCodexAccountSnapshot,
|
||||
resolveCodexModelForAccount,
|
||||
} from "./codexAppServerManager";
|
||||
|
||||
const asThreadId = (value: string): ThreadId => ThreadId.makeUnsafe(value);
|
||||
@@ -21,14 +23,20 @@ function createSendTurnHarness() {
|
||||
const manager = new CodexAppServerManager();
|
||||
const context = {
|
||||
session: {
|
||||
sessionId: "sess_1",
|
||||
provider: "codex",
|
||||
status: "ready",
|
||||
threadId: "thread_1",
|
||||
runtimeMode: "full-access",
|
||||
model: "gpt-5.3-codex",
|
||||
resumeCursor: { threadId: "thread_1" },
|
||||
createdAt: "2026-02-10T00:00:00.000Z",
|
||||
updatedAt: "2026-02-10T00:00:00.000Z",
|
||||
},
|
||||
account: {
|
||||
type: "unknown",
|
||||
planType: null,
|
||||
sparkEnabled: true,
|
||||
},
|
||||
};
|
||||
|
||||
const requireSession = vi
|
||||
@@ -58,10 +66,11 @@ function createThreadControlHarness() {
|
||||
const manager = new CodexAppServerManager();
|
||||
const context = {
|
||||
session: {
|
||||
sessionId: "sess_1",
|
||||
provider: "codex",
|
||||
status: "ready",
|
||||
threadId: "thread_1",
|
||||
runtimeMode: "full-access",
|
||||
model: "gpt-5.3-codex",
|
||||
resumeCursor: { threadId: "thread_1" },
|
||||
createdAt: "2026-02-10T00:00:00.000Z",
|
||||
updatedAt: "2026-02-10T00:00:00.000Z",
|
||||
@@ -89,10 +98,11 @@ function createPendingUserInputHarness() {
|
||||
const manager = new CodexAppServerManager();
|
||||
const context = {
|
||||
session: {
|
||||
sessionId: "sess_1",
|
||||
provider: "codex",
|
||||
status: "ready",
|
||||
threadId: "thread_1",
|
||||
runtimeMode: "full-access",
|
||||
model: "gpt-5.3-codex",
|
||||
resumeCursor: { threadId: "thread_1" },
|
||||
createdAt: "2026-02-10T00:00:00.000Z",
|
||||
updatedAt: "2026-02-10T00:00:00.000Z",
|
||||
@@ -195,6 +205,70 @@ describe("isRecoverableThreadResumeError", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("readCodexAccountSnapshot", () => {
|
||||
it("disables spark for chatgpt plus accounts", () => {
|
||||
expect(
|
||||
readCodexAccountSnapshot({
|
||||
type: "chatgpt",
|
||||
email: "[email protected]",
|
||||
planType: "plus",
|
||||
}),
|
||||
).toEqual({
|
||||
type: "chatgpt",
|
||||
planType: "plus",
|
||||
sparkEnabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps spark enabled for chatgpt pro accounts", () => {
|
||||
expect(
|
||||
readCodexAccountSnapshot({
|
||||
type: "chatgpt",
|
||||
email: "[email protected]",
|
||||
planType: "pro",
|
||||
}),
|
||||
).toEqual({
|
||||
type: "chatgpt",
|
||||
planType: "pro",
|
||||
sparkEnabled: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps spark enabled for api key accounts", () => {
|
||||
expect(
|
||||
readCodexAccountSnapshot({
|
||||
type: "apiKey",
|
||||
}),
|
||||
).toEqual({
|
||||
type: "apiKey",
|
||||
planType: null,
|
||||
sparkEnabled: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveCodexModelForAccount", () => {
|
||||
it("falls back from spark to default for unsupported chatgpt plans", () => {
|
||||
expect(
|
||||
resolveCodexModelForAccount("gpt-5.3-codex-spark", {
|
||||
type: "chatgpt",
|
||||
planType: "plus",
|
||||
sparkEnabled: false,
|
||||
}),
|
||||
).toBe("gpt-5.3-codex");
|
||||
});
|
||||
|
||||
it("keeps spark for supported plans", () => {
|
||||
expect(
|
||||
resolveCodexModelForAccount("gpt-5.3-codex-spark", {
|
||||
type: "chatgpt",
|
||||
planType: "pro",
|
||||
sparkEnabled: true,
|
||||
}),
|
||||
).toBe("gpt-5.3-codex-spark");
|
||||
});
|
||||
});
|
||||
|
||||
describe("startSession", () => {
|
||||
it("enables Codex experimental api capabilities during initialize", () => {
|
||||
expect(buildCodexInitializeParams()).toEqual({
|
||||
@@ -259,8 +333,8 @@ describe("sendTurn", () => {
|
||||
},
|
||||
],
|
||||
model: "gpt-5.3",
|
||||
effort: "high",
|
||||
serviceTier: "fast",
|
||||
effort: "high",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
@@ -283,8 +357,8 @@ describe("sendTurn", () => {
|
||||
},
|
||||
],
|
||||
model: "gpt-5.3-codex",
|
||||
effort: "high",
|
||||
serviceTier: "fast",
|
||||
effort: "high",
|
||||
});
|
||||
expect(updateSession).toHaveBeenCalledWith(context, {
|
||||
status: "running",
|
||||
@@ -314,6 +388,7 @@ describe("sendTurn", () => {
|
||||
url: "data:image/png;base64,BBBB",
|
||||
},
|
||||
],
|
||||
model: "gpt-5.3-codex",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -377,6 +452,37 @@ describe("sendTurn", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the session model when interaction mode is set without an explicit model", async () => {
|
||||
const { manager, context, sendRequest } = createSendTurnHarness();
|
||||
context.session.model = "gpt-5.2-codex";
|
||||
|
||||
await manager.sendTurn({
|
||||
threadId: asThreadId("thread_1"),
|
||||
input: "Plan this with my current session model",
|
||||
interactionMode: "plan",
|
||||
});
|
||||
|
||||
expect(sendRequest).toHaveBeenCalledWith(context, "turn/start", {
|
||||
threadId: "thread_1",
|
||||
input: [
|
||||
{
|
||||
type: "text",
|
||||
text: "Plan this with my current session model",
|
||||
text_elements: [],
|
||||
},
|
||||
],
|
||||
model: "gpt-5.2-codex",
|
||||
collaborationMode: {
|
||||
mode: "plan",
|
||||
settings: {
|
||||
model: "gpt-5.2-codex",
|
||||
reasoning_effort: "medium",
|
||||
developer_instructions: CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects empty turn input", async () => {
|
||||
const { manager } = createSendTurnHarness();
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ interface CodexUserInputAnswer {
|
||||
|
||||
interface CodexSessionContext {
|
||||
session: ProviderSession;
|
||||
account: CodexAccountSnapshot;
|
||||
child: ChildProcessWithoutNullStreams;
|
||||
output: readline.Interface;
|
||||
pending: Map<PendingRequestKey, PendingRequest>;
|
||||
@@ -89,13 +90,30 @@ interface JsonRpcNotification {
|
||||
params?: unknown;
|
||||
}
|
||||
|
||||
type CodexPlanType =
|
||||
| "free"
|
||||
| "go"
|
||||
| "plus"
|
||||
| "pro"
|
||||
| "team"
|
||||
| "business"
|
||||
| "enterprise"
|
||||
| "edu"
|
||||
| "unknown";
|
||||
|
||||
interface CodexAccountSnapshot {
|
||||
readonly type: "apiKey" | "chatgpt" | "unknown";
|
||||
readonly planType: CodexPlanType | null;
|
||||
readonly sparkEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface CodexAppServerSendTurnInput {
|
||||
readonly threadId: ThreadId;
|
||||
readonly input?: string;
|
||||
readonly attachments?: ReadonlyArray<{ type: "image"; url: string }>;
|
||||
readonly model?: string;
|
||||
readonly serviceTier?: string | null;
|
||||
readonly effort?: string;
|
||||
readonly serviceTier?: string;
|
||||
readonly interactionMode?: ProviderInteractionMode;
|
||||
}
|
||||
|
||||
@@ -135,6 +153,50 @@ const RECOVERABLE_THREAD_RESUME_ERROR_SNIPPETS = [
|
||||
"unknown thread",
|
||||
"does not exist",
|
||||
];
|
||||
const CODEX_DEFAULT_MODEL = "gpt-5.3-codex";
|
||||
const CODEX_SPARK_MODEL = "gpt-5.3-codex-spark";
|
||||
const CODEX_SPARK_DISABLED_PLAN_TYPES = new Set<CodexPlanType>(["free", "go", "plus"]);
|
||||
|
||||
function asObject(value: unknown): Record<string, unknown> | undefined {
|
||||
if (!value || typeof value !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function asString(value: unknown): string | undefined {
|
||||
return typeof value === "string" ? value : undefined;
|
||||
}
|
||||
|
||||
export function readCodexAccountSnapshot(response: unknown): CodexAccountSnapshot {
|
||||
const record = asObject(response);
|
||||
const account = asObject(record?.account) ?? record;
|
||||
const accountType = asString(account?.type);
|
||||
|
||||
if (accountType === "apiKey") {
|
||||
return {
|
||||
type: "apiKey",
|
||||
planType: null,
|
||||
sparkEnabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (accountType === "chatgpt") {
|
||||
const planType = (account?.planType as CodexPlanType | null) ?? "unknown";
|
||||
return {
|
||||
type: "chatgpt",
|
||||
planType,
|
||||
sparkEnabled: !CODEX_SPARK_DISABLED_PLAN_TYPES.has(planType),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: "unknown",
|
||||
planType: null,
|
||||
sparkEnabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
export const CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS = `<collaboration_mode># Plan Mode (Conversational)
|
||||
|
||||
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): {
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveCodexModelForAccount(
|
||||
model: string | undefined,
|
||||
account: CodexAccountSnapshot,
|
||||
): string | undefined {
|
||||
if (model !== CODEX_SPARK_MODEL || account.sparkEnabled) {
|
||||
return model;
|
||||
}
|
||||
|
||||
return CODEX_DEFAULT_MODEL;
|
||||
}
|
||||
|
||||
/**
|
||||
* On Windows with `shell: true`, `child.kill()` only terminates the `cmd.exe`
|
||||
* wrapper, leaving the actual command running. Use `taskkill /T` to kill the
|
||||
@@ -475,6 +548,11 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
|
||||
context = {
|
||||
session,
|
||||
account: {
|
||||
type: "unknown",
|
||||
planType: null,
|
||||
sparkEnabled: true,
|
||||
},
|
||||
child,
|
||||
output,
|
||||
pending: new Map(),
|
||||
@@ -492,12 +570,33 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
await this.sendRequest(context, "initialize", buildCodexInitializeParams());
|
||||
|
||||
this.writeMessage(context, { method: "initialized" });
|
||||
try {
|
||||
const modelListResponse = await this.sendRequest(context, "model/list", {});
|
||||
console.log("codex model/list response", modelListResponse);
|
||||
} catch (error) {
|
||||
console.log("codex model/list failed", error);
|
||||
}
|
||||
try {
|
||||
const accountReadResponse = await this.sendRequest(context, "account/read", {});
|
||||
console.log("codex account/read response", accountReadResponse);
|
||||
context.account = readCodexAccountSnapshot(accountReadResponse);
|
||||
console.log("codex subscription status", {
|
||||
type: context.account.type,
|
||||
planType: context.account.planType,
|
||||
sparkEnabled: context.account.sparkEnabled,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("codex account/read failed", error);
|
||||
}
|
||||
|
||||
const normalizedModel = normalizeCodexModelSlug(input.model);
|
||||
const normalizedModel = resolveCodexModelForAccount(
|
||||
normalizeCodexModelSlug(input.model),
|
||||
context.account,
|
||||
);
|
||||
const sessionOverrides = {
|
||||
model: normalizedModel ?? null,
|
||||
cwd: input.cwd ?? null,
|
||||
...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
|
||||
cwd: input.cwd ?? null,
|
||||
...mapCodexRuntimeMode(input.runtimeMode ?? "full-access"),
|
||||
};
|
||||
|
||||
@@ -657,8 +756,8 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
{ type: "text"; text: string; text_elements: [] } | { type: "image"; url: string }
|
||||
>;
|
||||
model?: string;
|
||||
serviceTier?: string | null;
|
||||
effort?: string;
|
||||
serviceTier?: string;
|
||||
collaborationMode?: {
|
||||
mode: "default" | "plan";
|
||||
settings: {
|
||||
@@ -671,16 +770,19 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
|
||||
threadId: providerThreadId,
|
||||
input: turnInput,
|
||||
};
|
||||
const normalizedModel = normalizeCodexModelSlug(input.model ?? context.session.model);
|
||||
const normalizedModel = resolveCodexModelForAccount(
|
||||
normalizeCodexModelSlug(input.model ?? context.session.model),
|
||||
context.account,
|
||||
);
|
||||
if (normalizedModel) {
|
||||
turnStartParams.model = normalizedModel;
|
||||
}
|
||||
if (input.serviceTier !== undefined) {
|
||||
turnStartParams.serviceTier = input.serviceTier;
|
||||
}
|
||||
if (input.effort) {
|
||||
turnStartParams.effort = input.effort;
|
||||
}
|
||||
if (input.serviceTier) {
|
||||
turnStartParams.serviceTier = input.serviceTier;
|
||||
}
|
||||
const collaborationMode = buildCodexCollaborationMode({
|
||||
...(input.interactionMode !== undefined ? { interactionMode: input.interactionMode } : {}),
|
||||
...(normalizedModel !== undefined ? { model: normalizedModel } : {}),
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
type OrchestrationEvent,
|
||||
type ProviderModelOptions,
|
||||
type ProviderKind,
|
||||
type ProviderServiceTier,
|
||||
type OrchestrationSession,
|
||||
ThreadId,
|
||||
type ProviderSession,
|
||||
@@ -201,6 +202,7 @@ const make = Effect.gen(function* () {
|
||||
readonly provider?: ProviderKind;
|
||||
readonly model?: string;
|
||||
readonly modelOptions?: ProviderModelOptions;
|
||||
readonly serviceTier?: ProviderServiceTier | null;
|
||||
},
|
||||
) {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
@@ -235,6 +237,7 @@ const make = Effect.gen(function* () {
|
||||
: {}),
|
||||
...(effectiveCwd ? { cwd: effectiveCwd } : {}),
|
||||
...(desiredModel ? { model: desiredModel } : {}),
|
||||
...(options?.serviceTier !== undefined ? { serviceTier: options.serviceTier } : {}),
|
||||
...(options?.modelOptions !== undefined ? { modelOptions: options.modelOptions } : {}),
|
||||
...(input?.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),
|
||||
runtimeMode: desiredRuntimeMode,
|
||||
@@ -320,6 +323,7 @@ const make = Effect.gen(function* () {
|
||||
readonly attachments?: ReadonlyArray<ChatAttachment>;
|
||||
readonly provider?: ProviderKind;
|
||||
readonly model?: string;
|
||||
readonly serviceTier?: ProviderServiceTier | null;
|
||||
readonly modelOptions?: ProviderModelOptions;
|
||||
readonly interactionMode?: "default" | "plan";
|
||||
readonly createdAt: string;
|
||||
@@ -331,6 +335,7 @@ const make = Effect.gen(function* () {
|
||||
yield* ensureSessionForThread(input.threadId, input.createdAt, {
|
||||
...(input.provider !== undefined ? { provider: input.provider } : {}),
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
|
||||
...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
|
||||
});
|
||||
const normalizedInput = toNonEmptyProviderInput(input.messageText);
|
||||
@@ -350,6 +355,7 @@ const make = Effect.gen(function* () {
|
||||
...(normalizedInput ? { input: normalizedInput } : {}),
|
||||
...(normalizedAttachments.length > 0 ? { attachments: normalizedAttachments } : {}),
|
||||
...(modelForTurn !== undefined ? { model: modelForTurn } : {}),
|
||||
...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
|
||||
...(input.modelOptions !== undefined ? { modelOptions: input.modelOptions } : {}),
|
||||
...(input.interactionMode !== undefined ? { interactionMode: input.interactionMode } : {}),
|
||||
});
|
||||
@@ -464,6 +470,7 @@ const make = Effect.gen(function* () {
|
||||
...(message.attachments !== undefined ? { attachments: message.attachments } : {}),
|
||||
...(event.payload.provider !== undefined ? { provider: event.payload.provider } : {}),
|
||||
...(event.payload.model !== undefined ? { model: event.payload.model } : {}),
|
||||
...(event.payload.serviceTier !== undefined ? { serviceTier: event.payload.serviceTier } : {}),
|
||||
...(event.payload.modelOptions !== undefined ? { modelOptions: event.payload.modelOptions } : {}),
|
||||
interactionMode: event.payload.interactionMode,
|
||||
createdAt: event.payload.createdAt,
|
||||
|
||||
@@ -301,6 +301,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
messageId: command.message.messageId,
|
||||
...(command.provider !== undefined ? { provider: command.provider } : {}),
|
||||
...(command.model !== undefined ? { model: command.model } : {}),
|
||||
...(command.serviceTier !== undefined ? { serviceTier: command.serviceTier } : {}),
|
||||
...(command.modelOptions !== undefined ? { modelOptions: command.modelOptions } : {}),
|
||||
assistantDeliveryMode: command.assistantDeliveryMode ?? DEFAULT_ASSISTANT_DELIVERY_MODE,
|
||||
runtimeMode:
|
||||
|
||||
@@ -1354,6 +1354,7 @@ const makeCodexAdapter = (options?: CodexAdapterLiveOptions) =>
|
||||
threadId: input.threadId,
|
||||
...(input.input !== undefined ? { input: input.input } : {}),
|
||||
...(input.model !== undefined ? { model: input.model } : {}),
|
||||
...(input.serviceTier !== undefined ? { serviceTier: input.serviceTier } : {}),
|
||||
...(input.modelOptions?.codex?.reasoningEffort !== undefined
|
||||
? { effort: input.modelOptions.codex.reasoningEffort }
|
||||
: {}),
|
||||
|
||||
@@ -4,6 +4,8 @@ import {
|
||||
getAppModelOptions,
|
||||
getSlashModelOptions,
|
||||
normalizeCustomModelSlugs,
|
||||
resolveAppServiceTier,
|
||||
shouldShowFastTierIcon,
|
||||
resolveAppModelSelection,
|
||||
} from "./appSettings";
|
||||
|
||||
@@ -82,3 +84,22 @@ describe("getSlashModelOptions", () => {
|
||||
expect(options.map((option) => option.slug)).toEqual(["openai/gpt-oss-120b"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveAppServiceTier", () => {
|
||||
it("maps automatic to no override", () => {
|
||||
expect(resolveAppServiceTier("auto")).toBeNull();
|
||||
});
|
||||
|
||||
it("preserves explicit service tier overrides", () => {
|
||||
expect(resolveAppServiceTier("fast")).toBe("fast");
|
||||
expect(resolveAppServiceTier("flex")).toBe("flex");
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldShowFastTierIcon", () => {
|
||||
it("shows the fast-tier icon only for gpt-5.4 on fast tier", () => {
|
||||
expect(shouldShowFastTierIcon("gpt-5.4", "fast")).toBe(true);
|
||||
expect(shouldShowFastTierIcon("gpt-5.4", "auto")).toBe(false);
|
||||
expect(shouldShowFastTierIcon("gpt-5.3-codex", "fast")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,31 @@
|
||||
import { useCallback, useSyncExternalStore } from "react";
|
||||
import { Option, Schema } from "effect";
|
||||
import { type ProviderKind } from "@t3tools/contracts";
|
||||
import { type ProviderKind, type ProviderServiceTier } from "@t3tools/contracts";
|
||||
import { getDefaultModel, getModelOptions, normalizeModelSlug } from "@t3tools/shared/model";
|
||||
|
||||
const APP_SETTINGS_STORAGE_KEY = "t3code:app-settings:v1";
|
||||
const MAX_CUSTOM_MODEL_COUNT = 32;
|
||||
export const MAX_CUSTOM_MODEL_LENGTH = 256;
|
||||
export const APP_SERVICE_TIER_OPTIONS = [
|
||||
{
|
||||
value: "auto",
|
||||
label: "Automatic",
|
||||
description: "Use Codex defaults without forcing a service tier.",
|
||||
},
|
||||
{
|
||||
value: "fast",
|
||||
label: "Fast",
|
||||
description: "Request the fast service tier when the model supports it.",
|
||||
},
|
||||
{
|
||||
value: "flex",
|
||||
label: "Flex",
|
||||
description: "Request the flex service tier when the model supports it.",
|
||||
},
|
||||
] as const;
|
||||
export type AppServiceTier = (typeof APP_SERVICE_TIER_OPTIONS)[number]["value"];
|
||||
const AppServiceTierSchema = Schema.Literals(["auto", "fast", "flex"]);
|
||||
const MODELS_WITH_FAST_SUPPORT = new Set(["gpt-5.4"]);
|
||||
const BUILT_IN_MODEL_SLUGS_BY_PROVIDER: Record<ProviderKind, ReadonlySet<string>> = {
|
||||
codex: new Set(getModelOptions("codex").map((option) => option.slug)),
|
||||
};
|
||||
@@ -21,6 +41,7 @@ const AppSettingsSchema = Schema.Struct({
|
||||
enableAssistantStreaming: Schema.Boolean.pipe(
|
||||
Schema.withConstructorDefault(() => Option.some(false)),
|
||||
),
|
||||
codexServiceTier: AppServiceTierSchema.pipe(Schema.withConstructorDefault(() => Option.some("auto"))),
|
||||
customCodexModels: Schema.Array(Schema.String).pipe(
|
||||
Schema.withConstructorDefault(() => Option.some([])),
|
||||
),
|
||||
@@ -32,6 +53,22 @@ export interface AppModelOption {
|
||||
isCustom: boolean;
|
||||
}
|
||||
|
||||
export function resolveAppServiceTier(serviceTier: AppServiceTier): ProviderServiceTier | null {
|
||||
return serviceTier === "auto" ? null : serviceTier;
|
||||
}
|
||||
|
||||
export function shouldShowFastTierIcon(
|
||||
model: string | null | undefined,
|
||||
serviceTier: AppServiceTier,
|
||||
): boolean {
|
||||
const normalizedModel = normalizeModelSlug(model);
|
||||
return (
|
||||
resolveAppServiceTier(serviceTier) === "fast" &&
|
||||
normalizedModel !== null &&
|
||||
MODELS_WITH_FAST_SUPPORT.has(normalizedModel)
|
||||
);
|
||||
}
|
||||
|
||||
const DEFAULT_APP_SETTINGS = AppSettingsSchema.makeUnsafe({});
|
||||
|
||||
let listeners: Array<() => void> = [];
|
||||
|
||||
@@ -140,6 +140,7 @@ import {
|
||||
XIcon,
|
||||
CopyIcon,
|
||||
CheckIcon,
|
||||
ZapIcon,
|
||||
} from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { Input } from "./ui/input";
|
||||
@@ -196,7 +197,14 @@ import { Toggle } from "./ui/toggle";
|
||||
import { SidebarTrigger } from "./ui/sidebar";
|
||||
import { newCommandId, newMessageId, newThreadId } from "~/lib/utils";
|
||||
import { readNativeApi } from "~/nativeApi";
|
||||
import { getAppModelOptions, resolveAppModelSelection, useAppSettings } from "../appSettings";
|
||||
import {
|
||||
getAppModelOptions,
|
||||
resolveAppModelSelection,
|
||||
resolveAppServiceTier,
|
||||
shouldShowFastTierIcon,
|
||||
type AppServiceTier,
|
||||
useAppSettings,
|
||||
} from "../appSettings";
|
||||
import {
|
||||
type ComposerImageAttachment,
|
||||
type DraftThreadEnvMode,
|
||||
@@ -388,6 +396,7 @@ type ComposerCommandItem =
|
||||
model: ModelSlug;
|
||||
label: string;
|
||||
description: string;
|
||||
showFastBadge: boolean;
|
||||
};
|
||||
|
||||
type SendPhase = "idle" | "preparing-worktree" | "sending-turn";
|
||||
@@ -497,7 +506,12 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
|
||||
model
|
||||
</Badge>
|
||||
) : null}
|
||||
<span className="truncate">{props.item.label}</span>
|
||||
<span className="flex min-w-0 items-center gap-1.5 truncate">
|
||||
{props.item.type === "model" && props.item.showFastBadge ? (
|
||||
<ZapIcon className="size-3.5 shrink-0 text-amber-500" />
|
||||
) : null}
|
||||
<span className="truncate">{props.item.label}</span>
|
||||
</span>
|
||||
<span className="truncate text-muted-foreground/70 text-xs">{props.item.description}</span>
|
||||
</CommandItem>
|
||||
);
|
||||
@@ -754,6 +768,8 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
activeThread.messages.length > 0 ||
|
||||
activeThread.session !== null),
|
||||
);
|
||||
const selectedServiceTierSetting = settings.codexServiceTier;
|
||||
const selectedServiceTier = resolveAppServiceTier(selectedServiceTierSetting);
|
||||
const lockedProvider: ProviderKind | null = hasThreadStarted
|
||||
? (sessionProvider ?? selectedProviderByThreadId ?? null)
|
||||
: null;
|
||||
@@ -1205,8 +1221,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
model: slug,
|
||||
label: name,
|
||||
description: `${providerLabel} · ${slug}`,
|
||||
showFastBadge:
|
||||
provider === "codex" && shouldShowFastTierIcon(slug, selectedServiceTierSetting),
|
||||
}));
|
||||
}, [composerTrigger, searchableModelOptions, workspaceEntries]);
|
||||
}, [composerTrigger, searchableModelOptions, selectedServiceTierSetting, workspaceEntries]);
|
||||
const composerMenuOpen = Boolean(composerTrigger);
|
||||
const activeComposerMenuItem = useMemo(
|
||||
() =>
|
||||
@@ -2539,6 +2557,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
attachments: turnAttachments,
|
||||
},
|
||||
model: selectedModel || undefined,
|
||||
serviceTier: selectedServiceTier,
|
||||
...(selectedModelOptionsForDispatch
|
||||
? { modelOptions: selectedModelOptionsForDispatch }
|
||||
: {}),
|
||||
@@ -3534,6 +3553,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
model={selectedModelForPickerWithCustomFallback}
|
||||
lockedProvider={lockedProvider}
|
||||
modelOptionsByProvider={modelOptionsByProvider}
|
||||
serviceTierSetting={selectedServiceTierSetting}
|
||||
onProviderModelChange={onProviderModelSelect}
|
||||
/>
|
||||
|
||||
@@ -5220,6 +5240,7 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
model: ModelSlug;
|
||||
lockedProvider: ProviderKind | null;
|
||||
modelOptionsByProvider: Record<ProviderKind, ReadonlyArray<{ slug: string; name: string }>>;
|
||||
serviceTierSetting: AppServiceTier;
|
||||
disabled?: boolean;
|
||||
onProviderModelChange: (provider: ProviderKind, model: ModelSlug) => void;
|
||||
}) {
|
||||
@@ -5252,6 +5273,9 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<ProviderIcon aria-hidden="true" className="size-4 shrink-0 text-muted-foreground/70" />
|
||||
{props.provider === "codex" && shouldShowFastTierIcon(props.model, props.serviceTierSetting) ? (
|
||||
<ZapIcon className="size-3.5 shrink-0 text-amber-500" />
|
||||
) : null}
|
||||
<span className="truncate">{selectedModelLabel}</span>
|
||||
<ChevronDownIcon aria-hidden="true" className="size-3 opacity-60" />
|
||||
</span>
|
||||
@@ -5294,6 +5318,10 @@ const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
value={modelOption.slug}
|
||||
onClick={() => setIsMenuOpen(false)}
|
||||
>
|
||||
{option.value === "codex" &&
|
||||
shouldShowFastTierIcon(modelOption.slug, props.serviceTierSetting) ? (
|
||||
<ZapIcon className="size-3.5 shrink-0 text-amber-500" />
|
||||
) : null}
|
||||
{modelOption.name}
|
||||
</MenuRadioItem>
|
||||
))}
|
||||
|
||||
@@ -3,8 +3,14 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { useCallback, useState } from "react";
|
||||
import { type ProviderKind } from "@t3tools/contracts";
|
||||
import { getModelOptions, normalizeModelSlug } from "@t3tools/shared/model";
|
||||
import { ZapIcon } from "lucide-react";
|
||||
|
||||
import { MAX_CUSTOM_MODEL_LENGTH, useAppSettings } from "../appSettings";
|
||||
import {
|
||||
APP_SERVICE_TIER_OPTIONS,
|
||||
MAX_CUSTOM_MODEL_LENGTH,
|
||||
shouldShowFastTierIcon,
|
||||
useAppSettings,
|
||||
} from "../appSettings";
|
||||
import { isElectron } from "../env";
|
||||
import { useTheme } from "../hooks/useTheme";
|
||||
import { serverConfigQueryOptions } from "../lib/serverReactQuery";
|
||||
@@ -12,6 +18,7 @@ import { ensureNativeApi } from "../nativeApi";
|
||||
import { preferredTerminalEditor } from "../terminal-links";
|
||||
import { Button } from "../components/ui/button";
|
||||
import { Input } from "../components/ui/input";
|
||||
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../components/ui/select";
|
||||
import { Switch } from "../components/ui/switch";
|
||||
import { SidebarInset } from "~/components/ui/sidebar";
|
||||
|
||||
@@ -96,6 +103,7 @@ function SettingsRouteView() {
|
||||
|
||||
const codexBinaryPath = settings.codexBinaryPath;
|
||||
const codexHomePath = settings.codexHomePath;
|
||||
const codexServiceTier = settings.codexServiceTier;
|
||||
const keybindingsConfigPath = serverConfigQuery.data?.keybindingsConfigPath ?? null;
|
||||
|
||||
const openKeybindingsFile = useCallback(() => {
|
||||
@@ -302,6 +310,43 @@ function SettingsRouteView() {
|
||||
</div>
|
||||
|
||||
<div className="space-y-5">
|
||||
<label className="block space-y-1">
|
||||
<span className="text-xs font-medium text-foreground">Default service tier</span>
|
||||
<Select
|
||||
items={APP_SERVICE_TIER_OPTIONS.map((option) => ({
|
||||
label: option.label,
|
||||
value: option.value,
|
||||
}))}
|
||||
value={codexServiceTier}
|
||||
onValueChange={(value) => {
|
||||
if (!value) return;
|
||||
updateSettings({ codexServiceTier: value });
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectPopup alignItemWithTrigger={false}>
|
||||
{APP_SERVICE_TIER_OPTIONS.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
{option.value === "fast" ? (
|
||||
<ZapIcon className="size-3.5 text-amber-500" />
|
||||
) : (
|
||||
<span className="size-3.5 shrink-0" aria-hidden="true" />
|
||||
)}
|
||||
<span className="truncate">{option.label}</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectPopup>
|
||||
</Select>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{APP_SERVICE_TIER_OPTIONS.find((option) => option.value === codexServiceTier)
|
||||
?.description ?? "Use Codex defaults without forcing a service tier."}
|
||||
</span>
|
||||
</label>
|
||||
|
||||
{MODEL_PROVIDER_SETTINGS.map((providerSettings) => {
|
||||
const provider = providerSettings.provider;
|
||||
const customModels = getCustomModelsForProvider(settings, provider);
|
||||
@@ -400,9 +445,14 @@ function SettingsRouteView() {
|
||||
key={`${provider}:${slug}`}
|
||||
className="flex items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2"
|
||||
>
|
||||
<code className="min-w-0 flex-1 truncate text-xs text-foreground">
|
||||
{slug}
|
||||
</code>
|
||||
<div className="flex min-w-0 flex-1 items-center gap-2">
|
||||
{provider === "codex" && shouldShowFastTierIcon(slug, codexServiceTier) ? (
|
||||
<ZapIcon className="size-3.5 shrink-0 text-amber-500" />
|
||||
) : null}
|
||||
<code className="min-w-0 flex-1 truncate text-xs text-foreground">
|
||||
{slug}
|
||||
</code>
|
||||
</div>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
|
||||
@@ -29,6 +29,21 @@ export const ORCHESTRATION_WS_CHANNELS = {
|
||||
|
||||
export const ProviderKind = Schema.Literal("codex");
|
||||
export type ProviderKind = typeof ProviderKind.Type;
|
||||
export const ProviderApprovalPolicy = Schema.Literals([
|
||||
"untrusted",
|
||||
"on-failure",
|
||||
"on-request",
|
||||
"never",
|
||||
]);
|
||||
export type ProviderApprovalPolicy = typeof ProviderApprovalPolicy.Type;
|
||||
export const ProviderSandboxMode = Schema.Literals([
|
||||
"read-only",
|
||||
"workspace-write",
|
||||
"danger-full-access",
|
||||
]);
|
||||
export type ProviderSandboxMode = typeof ProviderSandboxMode.Type;
|
||||
export const ProviderServiceTier = Schema.Literals(["fast", "flex"]);
|
||||
export type ProviderServiceTier = typeof ProviderServiceTier.Type;
|
||||
export const DEFAULT_PROVIDER_KIND: ProviderKind = "codex";
|
||||
export const RuntimeMode = Schema.Literals(["approval-required", "full-access"]);
|
||||
export type RuntimeMode = typeof RuntimeMode.Type;
|
||||
@@ -349,6 +364,7 @@ export const ThreadTurnStartCommand = Schema.Struct({
|
||||
}),
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
@@ -370,6 +386,7 @@ const ClientThreadTurnStartCommand = Schema.Struct({
|
||||
}),
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode,
|
||||
@@ -649,6 +666,7 @@ export const ThreadTurnStartRequestedPayload = Schema.Struct({
|
||||
messageId: MessageId,
|
||||
provider: Schema.optional(ProviderKind),
|
||||
model: Schema.optional(TrimmedNonEmptyString),
|
||||
serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
assistantDeliveryMode: Schema.optional(AssistantDeliveryMode),
|
||||
runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(() => DEFAULT_RUNTIME_MODE)),
|
||||
|
||||
@@ -14,9 +14,12 @@ import {
|
||||
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
|
||||
PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
|
||||
ProviderApprovalDecision,
|
||||
ProviderApprovalPolicy,
|
||||
ProviderInteractionMode,
|
||||
ProviderKind,
|
||||
ProviderRequestKind,
|
||||
ProviderSandboxMode,
|
||||
ProviderServiceTier,
|
||||
ProviderUserInputAnswers,
|
||||
RuntimeMode,
|
||||
} from "./orchestration";
|
||||
@@ -61,6 +64,9 @@ export const ProviderSessionStartInput = Schema.Struct({
|
||||
model: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
resumeCursor: Schema.optional(Schema.Unknown),
|
||||
serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
|
||||
approvalPolicy: Schema.optional(ProviderApprovalPolicy),
|
||||
sandboxMode: Schema.optional(ProviderSandboxMode),
|
||||
providerOptions: Schema.optional(ProviderStartOptions),
|
||||
runtimeMode: RuntimeMode,
|
||||
});
|
||||
@@ -75,6 +81,7 @@ export const ProviderSendTurnInput = Schema.Struct({
|
||||
Schema.Array(ChatAttachment).check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_ATTACHMENTS)),
|
||||
),
|
||||
model: Schema.optional(TrimmedNonEmptyStringSchema),
|
||||
serviceTier: Schema.optional(Schema.NullOr(ProviderServiceTier)),
|
||||
modelOptions: Schema.optional(ProviderModelOptions),
|
||||
interactionMode: Schema.optional(ProviderInteractionMode),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user