Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/codex-role-model/src/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function buildLoginFreeCatalog(
);
}
const allModels = discovery.discovery.models.filter(
(model) => model.type === "alias" || model.type === "model",
(model) => model.type === "alias" || model.type === "model" || model.type === "endpoint",
);
const firstModel = allModels[0];
if (!firstModel) {
Expand Down Expand Up @@ -226,7 +226,7 @@ function buildSignedInMergedCatalog(
}

const allModels = discovery.discovery.models.filter(
(model) => model.type === "alias" || model.type === "model",
(model) => model.type === "alias" || model.type === "model" || model.type === "endpoint",
);
const firstModel = allModels[0];
if (!firstModel) {
Expand Down
43 changes: 38 additions & 5 deletions packages/codex-role-model/src/downstream-openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
DownstreamOpenAIDiscovery,
DownstreamOpenAIModelRecord,
PiModelSelection,
PiProviderModelConfig,
ProviderRegistration,
RoleModelModelDiagnostic,
} from "./types.js";
Expand All @@ -21,7 +22,7 @@ function isModelRecord(value: unknown): value is DownstreamOpenAIModelRecord {
hasString(record.id) &&
record.object === "model" &&
record.owned_by === "role-model" &&
(record.type === "model" || record.type === "alias") &&
(record.type === "model" || record.type === "alias" || record.type === "endpoint") &&
typeof record.piMapping === "object" &&
record.piMapping !== null
);
Expand Down Expand Up @@ -82,6 +83,38 @@ function isReasoningSupported(model: DownstreamOpenAIModelRecord): boolean {
return false;
}

function readEffortToken(model: DownstreamOpenAIModelRecord): string | null {
const value =
model.reasoningEffort ??
model.reasoning_effort ??
model.fixedEffort ??
model.fixed_effort ??
null;
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
}

function modelDisplayName(model: DownstreamOpenAIModelRecord): string {
const base = model.displayName ?? model.upstreamModelId ?? model.upstream_model_id ?? model.id;
const effort = readEffortToken(model);
if (!effort) return base;
const label = effort
.replace(/[_-]+/g, " ")
.split(/\s+/)
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join(" ");
return base.endsWith(` (${label})`) ? base : `${base} (${label})`;
}

function readModelCost(model: DownstreamOpenAIModelRecord): PiProviderModelConfig["cost"] {
const pricing = model.pricing;
return {
input: pricing?.inputPer1M ?? pricing?.input ?? 0,
output: pricing?.outputPer1M ?? pricing?.output ?? 0,
cacheRead: pricing?.cacheReadPer1M ?? pricing?.cacheRead ?? 0,
cacheWrite: pricing?.cacheWritePer1M ?? pricing?.cacheWrite ?? 0,
};
}

function readPiCompat(
model: DownstreamOpenAIModelRecord,
): Required<NonNullable<PiModelSelection["compat"]>> {
Expand Down Expand Up @@ -134,9 +167,9 @@ export function createPiModelSelection(
return {
provider: "role-model",
id: model.id,
name: model.id,
name: modelDisplayName(model),
input: mapInput(model),
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
cost: readModelCost(model),
contextWindow,
maxTokens,
reasoning: isReasoningSupported(model),
Expand Down Expand Up @@ -169,9 +202,9 @@ export function mapDiscoveryToProviderConfig(
});
return {
id: model.id,
name: model.id,
name: modelDisplayName(model),
input: mapInput(model),
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
cost: readModelCost(model),
contextWindow: contextWindow.value,
maxTokens: maxTokens.value,
reasoning: isReasoningSupported(model),
Expand Down
2 changes: 1 addition & 1 deletion packages/codex-role-model/src/native-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function buildPickerExternalModels(

push(selected);
for (const model of discovery.models) {
if (model.type === "model") push(model);
if (model.type === "model" || model.type === "endpoint") push(model);
}
return out;
}
Expand Down
20 changes: 19 additions & 1 deletion packages/codex-role-model/src/runtime-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,30 @@ function createFallbackModelRecord(
const endpointIds = Array.isArray(record.endpoint_ids)
? record.endpoint_ids.filter((item): item is string => typeof item === "string")
: [];
const effort =
typeof record.reasoning_effort === "string"
? record.reasoning_effort
: typeof roleModel.reasoning_effort === "string"
? roleModel.reasoning_effort
: typeof roleModel.fixed_effort === "string"
? roleModel.fixed_effort
: null;
const upstreamModelId =
typeof record.upstream_model_id === "string"
? record.upstream_model_id
: typeof roleModel.upstream_model_id === "string"
? roleModel.upstream_model_id
: null;
return {
id: normalizedModelId,
object: "model",
owned_by: "role-model",
endpoint_ids: endpointIds,
type: roleModel.type === "model" ? "model" : "alias",
type:
roleModel.type === "endpoint" ? "endpoint" : roleModel.type === "model" ? "model" : "alias",
...(typeof roleModel.display_name === "string" ? { displayName: roleModel.display_name } : {}),
...(upstreamModelId ? { upstreamModelId } : {}),
...(effort ? { reasoningEffort: effort, fixedEffort: effort } : {}),
targetModelIds: [normalizedModelId],
canonicalModelIds: [normalizedModelId],
providerIds: ["role-model"],
Expand Down
39 changes: 37 additions & 2 deletions packages/codex-role-model/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ export interface DownstreamOpenAIModelRecord {
object: "model";
owned_by: "role-model";
endpoint_ids?: string[];
type: "model" | "alias";
type: "model" | "alias" | "endpoint";
displayName?: string;
upstreamModelId?: string;
upstream_model_id?: string;
reasoningEffort?: string | null;
reasoning_effort?: string | null;
fixedEffort?: string | null;
fixed_effort?: string | null;
effortSource?: string | null;
effort_source?: string | null;
reasoningEffortLevels?: string[];
reasoning_effort_levels?: string[];
endpoint_id?: string;
routingMode?: "basic" | "difficulty" | "intelligent" | "hybrid";
targetModelIds?: string[];
canonicalModelIds?: string[];
Expand All @@ -27,7 +39,14 @@ export interface DownstreamOpenAIModelRecord {
available?: string[];
conditional?: unknown;
tools?: { functionCalling?: boolean } | boolean;
reasoning?: { supported?: boolean; effortControl?: boolean } | boolean;
reasoning?:
| {
supported?: boolean;
effortControl?: boolean;
effortLevels?: string[];
effort_levels?: string[];
}
| boolean;
structuredOutput?: { supported?: boolean } | boolean;
caching?: unknown;
} & Record<string, unknown>);
Expand All @@ -43,6 +62,16 @@ export interface DownstreamOpenAIModelRecord {
};
};
sources?: string[];
pricing?: {
inputPer1M?: number;
outputPer1M?: number;
cacheReadPer1M?: number;
cacheWritePer1M?: number;
input?: number;
output?: number;
cacheRead?: number;
cacheWrite?: number;
} | null;
}

export interface DownstreamOpenAIDiscovery {
Expand Down Expand Up @@ -80,6 +109,9 @@ export interface PiProviderModelConfig {
contextWindow?: number;
maxTokens?: number;
reasoning?: boolean;
thinkingLevelMap?: PiThinkingLevelMap;
upstreamModelId?: string;
reasoningEffort?: string | null;
provider?: string;
api?: "openai-completions";
compat?: {
Expand All @@ -97,6 +129,9 @@ export interface PiProviderConfig {
models: PiProviderModelConfig[];
}

export type PiThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
export type PiThinkingLevelMap = Partial<Record<PiThinkingLevel, string | null>>;

export interface ProviderRegistration {
providerId: "role-model";
config: PiProviderConfig;
Expand Down
37 changes: 37 additions & 0 deletions packages/codex-role-model/test/effort-identity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, expect, test } from "vitest";

import { mapDiscoveryToProviderConfig } from "../src/downstream-openai.js";
import { createDiscovery, createModelRecord } from "./fixtures.js";

describe("Codex endpoint-instance compatibility", () => {
test("keeps endpoint rows distinct instead of collapsing upstream effort siblings", () => {
const discovery = createDiscovery({
models: [
createModelRecord({
id: "deepseek.personal.global.deepseek-v4-pro:low",
type: "endpoint" as never,
endpoint_ids: ["deepseek.personal.global.deepseek-v4-pro:low"],
upstreamModelId: "deepseek/deepseek-v4-pro" as never,
fixedEffort: "low" as never,
}),
createModelRecord({
id: "deepseek.personal.global.deepseek-v4-pro:medium",
type: "endpoint" as never,
endpoint_ids: ["deepseek.personal.global.deepseek-v4-pro:medium"],
upstreamModelId: "deepseek/deepseek-v4-pro" as never,
fixedEffort: "medium" as never,
}),
],
});

const registration = mapDiscoveryToProviderConfig(discovery);
expect(registration.config.models.map((entry) => entry.id)).toEqual([
"deepseek.personal.global.deepseek-v4-pro:low",
"deepseek.personal.global.deepseek-v4-pro:medium",
]);
expect(registration.config.models.map((entry) => entry.name)).toEqual([
"deepseek/deepseek-v4-pro (Low)",
"deepseek/deepseek-v4-pro (Medium)",
]);
});
});
Loading
Loading