Expose Codex service tier options
Map the app-server service tier catalog to a select capability and forward selected tier IDs without translating them through fast mode. Preserve legacy persisted fast-mode selections. Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
ddae737d6f
commit
d0e9e37a34
8 files changed
+168
-49
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
|
||||
import { ProviderInstanceId } from "@t3tools/contracts";
|
||||
import { createModelSelection } from "@t3tools/shared/model";
|
||||
|
||||
import { getCodexServiceTierOptionValue } from "./codexModelOptions.ts";
|
||||
|
||||
it("returns the selected Codex service tier id", () => {
|
||||
const selection = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.5", [
|
||||
{ id: "serviceTier", value: "flex" },
|
||||
]);
|
||||
|
||||
assert.equal(getCodexServiceTierOptionValue(selection), "flex");
|
||||
});
|
||||
|
||||
it("keeps legacy persisted fast mode selections working", () => {
|
||||
const selection = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
|
||||
{ id: "fastMode", value: true },
|
||||
]);
|
||||
|
||||
assert.equal(getCodexServiceTierOptionValue(selection), "fast");
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { ModelSelection } from "@t3tools/contracts";
|
||||
import {
|
||||
getModelSelectionBooleanOptionValue,
|
||||
getModelSelectionStringOptionValue,
|
||||
} from "@t3tools/shared/model";
|
||||
|
||||
export function getCodexServiceTierOptionValue(
|
||||
modelSelection: ModelSelection | null | undefined,
|
||||
): string | undefined {
|
||||
return (
|
||||
getModelSelectionStringOptionValue(modelSelection, "serviceTier") ??
|
||||
(getModelSelectionBooleanOptionValue(modelSelection, "fastMode") === true ? "fast" : undefined)
|
||||
);
|
||||
}
|
||||
@@ -271,7 +271,7 @@ validationLayer("CodexAdapterLive validation", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
threadId: asThreadId("thread-1"),
|
||||
modelSelection: createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.3-codex", [
|
||||
{ id: "fastMode", value: true },
|
||||
{ id: "serviceTier", value: "priority" },
|
||||
]),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
@@ -281,7 +281,7 @@ validationLayer("CodexAdapterLive validation", (it) => {
|
||||
cwd: process.cwd(),
|
||||
model: "gpt-5.3-codex",
|
||||
providerInstanceId: ProviderInstanceId.make("codex"),
|
||||
serviceTier: "fast",
|
||||
serviceTier: "priority",
|
||||
threadId: asThreadId("thread-1"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
@@ -344,7 +344,7 @@ sessionErrorLayer("CodexAdapterLive session errors", (it) => {
|
||||
input: "hello",
|
||||
modelSelection: createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.3-codex", [
|
||||
{ id: "reasoningEffort", value: "high" },
|
||||
{ id: "fastMode", value: true },
|
||||
{ id: "serviceTier", value: "priority" },
|
||||
]),
|
||||
attachments: [],
|
||||
}),
|
||||
@@ -354,7 +354,7 @@ sessionErrorLayer("CodexAdapterLive session errors", (it) => {
|
||||
input: "hello",
|
||||
model: "gpt-5.3-codex",
|
||||
effort: "high",
|
||||
serviceTier: "fast",
|
||||
serviceTier: "priority",
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -398,7 +398,7 @@ sessionErrorLayer("CodexAdapterLive session errors", (it) => {
|
||||
"gpt-5.3-codex",
|
||||
[
|
||||
{ id: "reasoningEffort", value: "high" },
|
||||
{ id: "fastMode", value: true },
|
||||
{ id: "serviceTier", value: "flex" },
|
||||
],
|
||||
),
|
||||
attachments: [],
|
||||
@@ -409,7 +409,7 @@ sessionErrorLayer("CodexAdapterLive session errors", (it) => {
|
||||
input: "hello",
|
||||
model: "gpt-5.3-codex",
|
||||
effort: "high",
|
||||
serviceTier: "fast",
|
||||
serviceTier: "flex",
|
||||
});
|
||||
}).pipe(Effect.provide(customLayer));
|
||||
});
|
||||
|
||||
@@ -37,10 +37,8 @@ import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
import * as CodexErrors from "effect-codex-app-server/errors";
|
||||
import * as EffectCodexSchema from "effect-codex-app-server/schema";
|
||||
|
||||
import {
|
||||
getModelSelectionBooleanOptionValue,
|
||||
getModelSelectionStringOptionValue,
|
||||
} from "@t3tools/shared/model";
|
||||
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
|
||||
import { getCodexServiceTierOptionValue } from "../../codexModelOptions.ts";
|
||||
|
||||
import {
|
||||
ProviderAdapterRequestError,
|
||||
@@ -1380,6 +1378,10 @@ export const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (
|
||||
yield* Effect.suspend(() => stopSessionInternal(existing));
|
||||
}
|
||||
|
||||
const serviceTier =
|
||||
input.modelSelection?.instanceId === boundInstanceId
|
||||
? getCodexServiceTierOptionValue(input.modelSelection)
|
||||
: undefined;
|
||||
const runtimeInput: CodexSessionRuntimeOptions = {
|
||||
threadId: input.threadId,
|
||||
providerInstanceId: boundInstanceId,
|
||||
@@ -1394,10 +1396,7 @@ export const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (
|
||||
...(input.modelSelection?.instanceId === boundInstanceId
|
||||
? { model: input.modelSelection.model }
|
||||
: {}),
|
||||
...(input.modelSelection?.instanceId === boundInstanceId &&
|
||||
getModelSelectionBooleanOptionValue(input.modelSelection, "fastMode") === true
|
||||
? { serviceTier: "fast" }
|
||||
: {}),
|
||||
...(serviceTier ? { serviceTier } : {}),
|
||||
};
|
||||
const sessionScope = yield* Scope.make("sequential");
|
||||
let sessionScopeTransferred = false;
|
||||
@@ -1513,9 +1512,9 @@ export const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (
|
||||
input.modelSelection?.instanceId === boundInstanceId
|
||||
? getModelSelectionStringOptionValue(input.modelSelection, "reasoningEffort")
|
||||
: undefined;
|
||||
const fastMode =
|
||||
const serviceTier =
|
||||
input.modelSelection?.instanceId === boundInstanceId
|
||||
? getModelSelectionBooleanOptionValue(input.modelSelection, "fastMode")
|
||||
? getCodexServiceTierOptionValue(input.modelSelection)
|
||||
: undefined;
|
||||
return yield* session.runtime
|
||||
.sendTurn({
|
||||
@@ -1528,7 +1527,7 @@ export const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (
|
||||
effort: reasoningEffort as EffectCodexSchema.V2TurnStartParams__ReasoningEffort,
|
||||
}
|
||||
: {}),
|
||||
...(fastMode === true ? { serviceTier: "fast" } : {}),
|
||||
...(serviceTier ? { serviceTier } : {}),
|
||||
...(input.interactionMode !== undefined ? { interactionMode: input.interactionMode } : {}),
|
||||
...(codexAttachments.length > 0 ? { attachments: codexAttachments } : {}),
|
||||
})
|
||||
|
||||
@@ -12,12 +12,18 @@ it("maps current Codex model capability fields", () => {
|
||||
id: "gpt-test",
|
||||
isDefault: true,
|
||||
model: "gpt-test",
|
||||
defaultServiceTier: "flex",
|
||||
serviceTiers: [
|
||||
{
|
||||
id: "fast",
|
||||
id: "priority",
|
||||
name: "Fast",
|
||||
description: "Lower latency responses.",
|
||||
},
|
||||
{
|
||||
id: "flex",
|
||||
name: "Flex",
|
||||
description: "Lower-cost asynchronous routing.",
|
||||
},
|
||||
],
|
||||
supportedReasoningEfforts: [
|
||||
{
|
||||
@@ -36,10 +42,63 @@ it("maps current Codex model capability fields", () => {
|
||||
currentValue: "super-high",
|
||||
},
|
||||
{
|
||||
id: "fastMode",
|
||||
label: "Fast",
|
||||
description: "Lower latency responses.",
|
||||
type: "boolean",
|
||||
id: "serviceTier",
|
||||
label: "Service Tier",
|
||||
type: "select",
|
||||
options: [
|
||||
{ id: "default", label: "Standard" },
|
||||
{
|
||||
id: "priority",
|
||||
label: "Fast",
|
||||
description: "Lower latency responses.",
|
||||
},
|
||||
{
|
||||
id: "flex",
|
||||
label: "Flex",
|
||||
description: "Lower-cost asynchronous routing.",
|
||||
isDefault: true,
|
||||
},
|
||||
],
|
||||
currentValue: "flex",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses standard routing when the catalog has no default service tier", () => {
|
||||
const capabilities = mapCodexModelCapabilities({
|
||||
additionalSpeedTiers: ["fast"],
|
||||
defaultReasoningEffort: "medium",
|
||||
defaultServiceTier: null,
|
||||
description: "Test model",
|
||||
displayName: "GPT Test",
|
||||
hidden: false,
|
||||
id: "gpt-test",
|
||||
isDefault: true,
|
||||
model: "gpt-test",
|
||||
serviceTiers: [
|
||||
{
|
||||
id: "priority",
|
||||
name: "Fast",
|
||||
description: "1.5x speed, increased usage",
|
||||
},
|
||||
],
|
||||
supportedReasoningEfforts: [],
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(capabilities.optionDescriptors, [
|
||||
{
|
||||
id: "serviceTier",
|
||||
label: "Service Tier",
|
||||
type: "select",
|
||||
options: [
|
||||
{ id: "default", label: "Standard", isDefault: true },
|
||||
{
|
||||
id: "priority",
|
||||
label: "Fast",
|
||||
description: "1.5x speed, increased usage",
|
||||
},
|
||||
],
|
||||
currentValue: "default",
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -54,6 +54,8 @@ const REASONING_EFFORT_LABELS: Readonly<Record<string, string>> = {
|
||||
xhigh: "Extra High",
|
||||
};
|
||||
|
||||
const DEFAULT_SERVICE_TIER_ID = "default";
|
||||
|
||||
function reasoningEffortLabel(reasoningEffort: string): string {
|
||||
return REASONING_EFFORT_LABELS[reasoningEffort] ?? reasoningEffort;
|
||||
}
|
||||
@@ -114,9 +116,20 @@ export function mapCodexModelCapabilities(
|
||||
},
|
||||
);
|
||||
const defaultReasoning = reasoningOptions.find((option) => option.isDefault)?.id;
|
||||
const fastServiceTier = model.serviceTiers?.find((tier) => tier.id === "fast");
|
||||
const supportsFastMode =
|
||||
fastServiceTier !== undefined || (model.additionalSpeedTiers ?? []).includes("fast");
|
||||
const serviceTiers =
|
||||
model.serviceTiers && model.serviceTiers.length > 0
|
||||
? model.serviceTiers
|
||||
: (model.additionalSpeedTiers ?? []).map((id) => ({
|
||||
id,
|
||||
name: id === "fast" ? "Fast" : id,
|
||||
description: "",
|
||||
}));
|
||||
const catalogDefaultServiceTier = serviceTiers.some(
|
||||
(tier) => tier.id === model.defaultServiceTier,
|
||||
)
|
||||
? model.defaultServiceTier
|
||||
: null;
|
||||
const defaultServiceTier = catalogDefaultServiceTier ?? DEFAULT_SERVICE_TIER_ID;
|
||||
const optionDescriptors: ProviderOptionDescriptor[] = [];
|
||||
|
||||
if (reasoningOptions.length > 0) {
|
||||
@@ -128,12 +141,25 @@ export function mapCodexModelCapabilities(
|
||||
...(defaultReasoning ? { currentValue: defaultReasoning } : {}),
|
||||
});
|
||||
}
|
||||
if (supportsFastMode) {
|
||||
if (serviceTiers.length > 0) {
|
||||
optionDescriptors.push({
|
||||
id: "fastMode",
|
||||
label: fastServiceTier?.name ?? "Fast Mode",
|
||||
...(fastServiceTier?.description ? { description: fastServiceTier.description } : {}),
|
||||
type: "boolean",
|
||||
id: "serviceTier",
|
||||
label: "Service Tier",
|
||||
type: "select",
|
||||
options: [
|
||||
{
|
||||
id: DEFAULT_SERVICE_TIER_ID,
|
||||
label: "Standard",
|
||||
...(defaultServiceTier === DEFAULT_SERVICE_TIER_ID ? { isDefault: true } : {}),
|
||||
},
|
||||
...serviceTiers.map((tier) => ({
|
||||
id: tier.id,
|
||||
label: tier.name,
|
||||
...(tier.description ? { description: tier.description } : {}),
|
||||
...(defaultServiceTier === tier.id ? { isDefault: true } : {}),
|
||||
})),
|
||||
],
|
||||
currentValue: defaultServiceTier,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ function makeFakeCodexBinary(
|
||||
exitCode?: number;
|
||||
stderr?: string;
|
||||
requireImage?: boolean;
|
||||
requireFastServiceTier?: boolean;
|
||||
requireServiceTier?: string;
|
||||
requireReasoningEffort?: string;
|
||||
forbidReasoningEffort?: boolean;
|
||||
stdinMustContain?: string;
|
||||
@@ -52,7 +52,7 @@ function makeFakeCodexBinary(
|
||||
"#!/bin/sh",
|
||||
'output_path=""',
|
||||
'seen_image="0"',
|
||||
'seen_fast_service_tier="0"',
|
||||
'seen_service_tier=""',
|
||||
'seen_reasoning_effort=""',
|
||||
"while [ $# -gt 0 ]; do",
|
||||
' if [ "$1" = "--image" ]; then',
|
||||
@@ -65,9 +65,11 @@ function makeFakeCodexBinary(
|
||||
" fi",
|
||||
' if [ "$1" = "--config" ]; then',
|
||||
" shift",
|
||||
' if [ "$1" = "service_tier=\\"fast\\"" ]; then',
|
||||
' seen_fast_service_tier="1"',
|
||||
" fi",
|
||||
' case "$1" in',
|
||||
" service_tier=*)",
|
||||
' seen_service_tier="$1"',
|
||||
" ;;",
|
||||
" esac",
|
||||
' case "$1" in',
|
||||
" model_reasoning_effort=*)",
|
||||
' seen_reasoning_effort="$1"',
|
||||
@@ -93,10 +95,10 @@ function makeFakeCodexBinary(
|
||||
"fi",
|
||||
]
|
||||
: []),
|
||||
...(input.requireFastServiceTier
|
||||
...(input.requireServiceTier
|
||||
? [
|
||||
'if [ "$seen_fast_service_tier" != "1" ]; then',
|
||||
' printf "%s\\n" "missing fast service tier config" >&2',
|
||||
`if [ "$seen_service_tier" != "service_tier=\\"${input.requireServiceTier}\\"" ]; then`,
|
||||
' printf "%s\\n" "unexpected service tier config: $seen_service_tier" >&2',
|
||||
` exit 5`,
|
||||
"fi",
|
||||
]
|
||||
@@ -161,7 +163,7 @@ function withFakeCodexEnv<A, E, R>(
|
||||
exitCode?: number;
|
||||
stderr?: string;
|
||||
requireImage?: boolean;
|
||||
requireFastServiceTier?: boolean;
|
||||
requireServiceTier?: string;
|
||||
requireReasoningEffort?: string;
|
||||
forbidReasoningEffort?: boolean;
|
||||
stdinMustContain?: string;
|
||||
@@ -209,7 +211,7 @@ it.layer(CodexTextGenerationTestLayer)("CodexTextGeneration", (it) => {
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"forwards codex fast mode and non-default reasoning effort into codex exec config",
|
||||
"forwards codex service tier and non-default reasoning effort into codex exec config",
|
||||
() =>
|
||||
withFakeCodexEnv(
|
||||
{
|
||||
@@ -217,7 +219,7 @@ it.layer(CodexTextGenerationTestLayer)("CodexTextGeneration", (it) => {
|
||||
subject: "Add important change",
|
||||
body: "",
|
||||
}),
|
||||
requireFastServiceTier: true,
|
||||
requireServiceTier: "priority",
|
||||
requireReasoningEffort: "xhigh",
|
||||
stdinMustNotContain: "branch must be a short semantic git branch fragment",
|
||||
},
|
||||
@@ -229,7 +231,7 @@ it.layer(CodexTextGenerationTestLayer)("CodexTextGeneration", (it) => {
|
||||
stagedPatch: "diff --git a/README.md b/README.md",
|
||||
modelSelection: createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
|
||||
{ id: "reasoningEffort", value: "xhigh" },
|
||||
{ id: "fastMode", value: true },
|
||||
{ id: "serviceTier", value: "priority" },
|
||||
]),
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -32,10 +32,8 @@ import {
|
||||
sanitizeThreadTitle,
|
||||
toJsonSchemaObject,
|
||||
} from "./TextGenerationUtils.ts";
|
||||
import {
|
||||
getModelSelectionBooleanOptionValue,
|
||||
getModelSelectionStringOptionValue,
|
||||
} from "@t3tools/shared/model";
|
||||
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
|
||||
import { getCodexServiceTierOptionValue } from "../codexModelOptions.ts";
|
||||
|
||||
const CODEX_GIT_TEXT_GENERATION_REASONING_EFFORT = "low";
|
||||
const CODEX_TIMEOUT_MS = 180_000;
|
||||
@@ -181,6 +179,7 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func
|
||||
const reasoningEffort =
|
||||
getModelSelectionStringOptionValue(modelSelection, "reasoningEffort") ??
|
||||
CODEX_GIT_TEXT_GENERATION_REASONING_EFFORT;
|
||||
const serviceTier = getCodexServiceTierOptionValue(modelSelection);
|
||||
const command = ChildProcess.make(
|
||||
codexConfig.binaryPath || "codex",
|
||||
[
|
||||
@@ -193,9 +192,7 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func
|
||||
modelSelection.model,
|
||||
"--config",
|
||||
`model_reasoning_effort="${reasoningEffort}"`,
|
||||
...(getModelSelectionBooleanOptionValue(modelSelection, "fastMode") === true
|
||||
? ["--config", `service_tier="fast"`]
|
||||
: []),
|
||||
...(serviceTier ? ["--config", `service_tier="${serviceTier}"`] : []),
|
||||
"--output-schema",
|
||||
schemaPath,
|
||||
"--output-last-message",
|
||||
|
||||
Reference in new issue
Block a user