Files
openclaw/src/commands/openai-codex-model-default.ts
Gustavo Madeira Santana 4629054403 chore: apply local workspace updates (#9911)
* chore: apply local workspace updates

* fix: resolve prep findings after rebase (#9898) (thanks @gumadeiras)

* refactor: centralize model allowlist normalization (#9898) (thanks @gumadeiras)

* fix: guard model allowlist initialization (#9911)

* docs: update changelog scope for #9911

* docs: remove model names from changelog entry (#9911)

* fix: satisfy type-aware lint in model allowlist (#9911)
2026-02-05 16:54:44 -05:00

59 lines
1.6 KiB
TypeScript

import type { OpenClawConfig } from "../config/config.js";
import type { AgentModelListConfig } from "../config/types.js";
export const OPENAI_CODEX_DEFAULT_MODEL = "openai-codex/gpt-5.3-codex";
function shouldSetOpenAICodexModel(model?: string): boolean {
const trimmed = model?.trim();
if (!trimmed) {
return true;
}
const normalized = trimmed.toLowerCase();
if (normalized.startsWith("openai-codex/")) {
return false;
}
if (normalized.startsWith("openai/")) {
return true;
}
return normalized === "gpt" || normalized === "gpt-mini";
}
function resolvePrimaryModel(model?: AgentModelListConfig | string): string | undefined {
if (typeof model === "string") {
return model;
}
if (model && typeof model === "object" && typeof model.primary === "string") {
return model.primary;
}
return undefined;
}
export function applyOpenAICodexModelDefault(cfg: OpenClawConfig): {
next: OpenClawConfig;
changed: boolean;
} {
const current = resolvePrimaryModel(cfg.agents?.defaults?.model);
if (!shouldSetOpenAICodexModel(current)) {
return { next: cfg, changed: false };
}
return {
next: {
...cfg,
agents: {
...cfg.agents,
defaults: {
...cfg.agents?.defaults,
model:
cfg.agents?.defaults?.model && typeof cfg.agents.defaults.model === "object"
? {
...cfg.agents.defaults.model,
primary: OPENAI_CODEX_DEFAULT_MODEL,
}
: { primary: OPENAI_CODEX_DEFAULT_MODEL },
},
},
},
changed: true,
};
}