Repository navigation
feat(codex): add fast tier settings toggle #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegosouzapw
merged 2 commits into
diegosouzapw:main
from
kfiramar:feat-codex-fast-toggle
Mar 14, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/app/(dashboard)/dashboard/settings/components/CodexServiceTierTab.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useState } from "react"; | ||
| import { Card } from "@/shared/components"; | ||
|
|
||
| export default function CodexServiceTierTab() { | ||
| const [enabled, setEnabled] = useState(false); | ||
| const [loading, setLoading] = useState(true); | ||
| const [saving, setSaving] = useState(false); | ||
| const [status, setStatus] = useState<"" | "saved" | "error">(""); | ||
|
|
||
| useEffect(() => { | ||
| fetch("/api/settings/codex-service-tier") | ||
| .then((res) => res.json()) | ||
| .then((data) => { | ||
| setEnabled(Boolean(data.enabled)); | ||
| setLoading(false); | ||
| }) | ||
| .catch(() => setLoading(false)); | ||
| }, []); | ||
|
|
||
| const save = async (nextEnabled: boolean) => { | ||
| setEnabled(nextEnabled); | ||
| setSaving(true); | ||
| setStatus(""); | ||
|
|
||
| try { | ||
| const res = await fetch("/api/settings/codex-service-tier", { | ||
| method: "PUT", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ enabled: nextEnabled }), | ||
| }); | ||
|
|
||
| if (res.ok) { | ||
| setStatus("saved"); | ||
| setTimeout(() => setStatus(""), 2000); | ||
| } else { | ||
| setStatus("error"); | ||
| setEnabled(!nextEnabled); | ||
| } | ||
| } catch { | ||
| setStatus("error"); | ||
| setEnabled(!nextEnabled); | ||
| } finally { | ||
| setSaving(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Card> | ||
| <div className="flex items-center gap-3 mb-5"> | ||
| <div className="p-2 rounded-lg bg-sky-500/10 text-sky-500"> | ||
| <span className="material-symbols-outlined text-[20px]" aria-hidden="true"> | ||
| bolt | ||
| </span> | ||
| </div> | ||
| <div className="flex-1"> | ||
| <h3 className="text-lg font-semibold">Codex Fast Service Tier</h3> | ||
| <p className="text-sm text-text-muted"> | ||
| Inject `service_tier=fast` into Codex requests when the client leaves it unset. | ||
| </p> | ||
| </div> | ||
| {status === "saved" && ( | ||
| <span className="text-xs font-medium text-emerald-500 flex items-center gap-1"> | ||
| <span className="material-symbols-outlined text-[14px]">check_circle</span> | ||
| Saved | ||
| </span> | ||
| )} | ||
| {status === "error" && ( | ||
| <span className="text-xs font-medium text-rose-500 flex items-center gap-1"> | ||
| <span className="material-symbols-outlined text-[14px]">error</span> | ||
| Failed to save | ||
| </span> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="flex items-center justify-between p-4 rounded-lg bg-surface/30 border border-border/30"> | ||
| <div> | ||
| <p className="text-sm font-medium">Force fast tier for Codex</p> | ||
| <p className="text-xs text-text-muted mt-0.5"> | ||
| Off by default. Applies only to Codex requests and does not override an explicit tier. | ||
| </p> | ||
| </div> | ||
| <button | ||
| onClick={() => save(!enabled)} | ||
| disabled={loading || saving} | ||
| className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${ | ||
| enabled ? "bg-sky-500" : "bg-white/10" | ||
| }`} | ||
| > | ||
| <span | ||
| className={`inline-block h-4 w-4 rounded-full bg-white transition-transform ${ | ||
| enabled ? "translate-x-6" : "translate-x-1" | ||
| }`} | ||
| /> | ||
| </button> | ||
| </div> | ||
| </Card> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { NextResponse, type Request } from "next/server"; | ||
| import { getSettings, updateSettings } from "@/lib/localDb"; | ||
| import { setDefaultFastServiceTierEnabled } from "@omniroute/open-sse/executors/codex.ts"; | ||
| import { updateCodexServiceTierSchema } from "@/shared/validation/schemas"; | ||
| import { isValidationFailure, validateBody } from "@/shared/validation/helpers"; | ||
|
|
||
| export async function GET() { | ||
| try { | ||
| const settings = await getSettings(); | ||
| const persisted = | ||
| typeof settings.codexServiceTier === "string" | ||
| ? JSON.parse(settings.codexServiceTier) | ||
| : settings.codexServiceTier; | ||
|
|
||
| return NextResponse.json({ | ||
| enabled: typeof persisted?.enabled === "boolean" ? persisted.enabled : false, | ||
| }); | ||
| } catch (error) { | ||
| console.error("[API ERROR] /api/settings/codex-service-tier GET:", error); | ||
| return NextResponse.json({ error: "Failed to get config" }, { status: 500 }); | ||
| } | ||
| } | ||
|
|
||
| export async function PUT(request: Request) { | ||
| let rawBody; | ||
| try { | ||
| rawBody = await request.json(); | ||
| } catch { | ||
| return NextResponse.json( | ||
| { | ||
| error: { | ||
| message: "Invalid request", | ||
| details: [{ field: "body", message: "Invalid JSON body" }], | ||
| }, | ||
| }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const validation = validateBody(updateCodexServiceTierSchema, rawBody); | ||
| if (isValidationFailure(validation)) { | ||
| return NextResponse.json({ error: validation.error }, { status: 400 }); | ||
| } | ||
|
|
||
| const config = validation.data; | ||
| await updateSettings({ codexServiceTier: config }); | ||
| setDefaultFastServiceTierEnabled(config.enabled); | ||
|
|
||
| return NextResponse.json(config); | ||
| } catch (error) { | ||
| console.error("[API ERROR] /api/settings/codex-service-tier PUT:", error); | ||
| return NextResponse.json({ error: "Failed to update config" }, { status: 500 }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling in the
savefunction can be improved:statusis set to"error"on failure, but there is no corresponding UI element to display this error. This means the save operation fails silently for the user.To fix the inconsistent state, you can revert the
enabledstate on failure. For the silent failure, you should add a UI element to display whenstatus === 'error'. Here is a suggestion to fix the state inconsistency: