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
19 changes: 19 additions & 0 deletions open-sse/config/imageRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ export const IMAGE_PROVIDERS: Record<string, ImageProviderConfig> = {
supportedSizes: ["1024x1024", "1024x1792", "1792x1024", "256x256", "512x512"],
},

// Codex exposes image generation only as a Responses-API hosted tool under
// ChatGPT OAuth. Incoming DALL-E-style `/v1/images/generations` requests are
// translated to /responses calls with `tools: [{ type: "image_generation" }]`
// by handleCodexImageGeneration.
codex: {
id: "codex",
alias: "cx",
baseUrl: "https://chatgpt.com/backend-api/codex/responses",
authType: "oauth",
authHeader: "bearer",
format: "codex-responses",
models: [
{ id: "gpt-5.4", name: "GPT 5.4 (Codex Image)" },
{ id: "gpt-5.3-codex", name: "GPT 5.3 Codex (Image)" },
{ id: "gpt-5.1-codex-max", name: "GPT 5.1 Codex Max (Image)" },
],
supportedSizes: ["512x512", "1024x1024", "1024x1536", "1536x1024"],
},

xai: {
id: "xai",
baseUrl: "https://api.x.ai/v1/images/generations",
Expand Down
19 changes: 19 additions & 0 deletions open-sse/config/petals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const PETALS_DEFAULT_BASE_URL = "https://chat.petals.dev/api/v1/generate";
export const PETALS_DEFAULT_MODEL = "stabilityai/StableBeluga2";

export function normalizePetalsBaseUrl(baseUrl: string | null | undefined): string {
const normalized = String(baseUrl || PETALS_DEFAULT_BASE_URL)
.trim()
.replace(/\/+$/, "");

if (normalized.endsWith("/api/v1/generate")) {
return normalized;
}
if (normalized.endsWith("/api/v1")) {
return `${normalized}/generate`;
}
if (normalized.endsWith("/api")) {
return `${normalized}/v1/generate`;
}
return `${normalized}/api/v1/generate`;
}
45 changes: 45 additions & 0 deletions open-sse/config/providerRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { BEDROCK_DEFAULT_BASE_URL } from "./bedrock.ts";
import { WATSONX_DEFAULT_BASE_URL } from "./watsonx.ts";
import { OCI_DEFAULT_BASE_URL } from "./oci.ts";
import { SAP_DEFAULT_BASE_URL } from "./sap.ts";
import { PETALS_DEFAULT_BASE_URL } from "./petals.ts";
import {
CURSOR_REGISTRY_VERSION,
getAntigravityProviderHeaders,
Expand Down Expand Up @@ -205,6 +206,26 @@ const CHAT_OPENAI_COMPAT_MODELS: Record<string, RegistryModel[]> = {
"meta-llama/Meta-Llama-3-8B-Instruct",
"meta-llama/Meta-Llama-3-70B-Instruct",
]),
"nous-research": [
{ id: "nousresearch/hermes-4-70b", name: "Nous: Hermes 4 70B", contextLength: 131072 },
{ id: "nousresearch/hermes-4-405b", name: "Nous: Hermes 4 405B", contextLength: 131072 },
{
id: "nousresearch/hermes-3-llama-3.1-70b",
name: "Nous: Hermes 3 70B Instruct",
contextLength: 131072,
},
{
id: "nousresearch/hermes-3-llama-3.1-405b",
name: "Nous: Hermes 3 405B Instruct",
contextLength: 131072,
},
{
id: "nousresearch/hermes-2-pro-llama-3-8b",
name: "NousResearch: Hermes 2 Pro - Llama-3 8B",
contextLength: 8192,
},
],
petals: [{ id: "stabilityai/StableBeluga2", name: "Stable Beluga 2 (70B)", contextLength: 8192 }],
poe: buildModels(["Claude-Sonnet-4.5", "GPT-5-Pro", "GPT-5-Codex", "Gemini-2.5-Pro"]),
gitlab: [{ id: "gitlab-duo-code-suggestions", name: "GitLab Duo Code Suggestions" }],
"gitlab-duo": [{ id: "gitlab-duo-code-suggestions", name: "GitLab Duo Code Suggestions" }],
Expand Down Expand Up @@ -2075,6 +2096,30 @@ export const REGISTRY: Record<string, RegistryEntry> = {
passthroughModels: true,
},

"nous-research": {
id: "nous-research",
alias: "nous",
format: "openai",
executor: "default",
baseUrl: "https://inference-api.nousresearch.com/v1",
modelsUrl: "https://inference-api.nousresearch.com/v1/models",
authType: "apikey",
authHeader: "bearer",
models: CHAT_OPENAI_COMPAT_MODELS["nous-research"],
passthroughModels: true,
},

petals: {
id: "petals",
alias: "petals",
format: "openai",
executor: "petals",
baseUrl: PETALS_DEFAULT_BASE_URL,
authType: "apikey",
authHeader: "bearer",
models: CHAT_OPENAI_COMPAT_MODELS.petals,
},

poe: {
id: "poe",
alias: "poe",
Expand Down
43 changes: 40 additions & 3 deletions open-sse/executors/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,31 @@ function stripStoredItemReferences(body: Record<string, unknown>): void {
}
}

function hasImageGenerationTool(body: Record<string, unknown>): boolean {
if (!Array.isArray(body.tools)) return false;
return body.tools.some((tool) => {
if (!tool || typeof tool !== "object" || Array.isArray(tool)) return false;
return (tool as Record<string, unknown>).type === "image_generation";
});
}

// Responses-API hosted tool types that OpenAI executes server-side (e.g.
// `image_generation` backed by gpt-image-1 under ChatGPT auth). These arrive shaped as
// `{ type, ...params }` with no `function` object and no `name` — Codex CLI injects
// `{ type: "image_generation", output_format: "png" }` when [features] image_generation = true.
// Keep them through `normalizeCodexTools` so upstream can execute them.
const CODEX_HOSTED_TOOL_TYPES: ReadonlySet<string> = new Set([
"image_generation",
"web_search",
"web_search_preview",
"file_search",
"computer",
"computer_use_preview",
"code_interpreter",
"mcp",
"local_shell",
]);

function normalizeCodexTools(body: Record<string, unknown>): void {
if (!Array.isArray(body.tools)) return;

Expand All @@ -336,10 +361,11 @@ function normalizeCodexTools(body: Record<string, unknown>): void {
}

const tool = toolValue as Record<string, unknown>;
const toolType = typeof tool.type === "string" ? tool.type : "";

// Preserve namespace tools (MCP tool groups used by Codex/OpenAI Responses API).
// Codex API supports them natively; register sub-tool names for tool_choice validation.
if (tool.type === "namespace") {
if (toolType === "namespace") {
if (Array.isArray(tool.tools)) {
for (const st of tool.tools as unknown[]) {
if (st && typeof st === "object" && !Array.isArray(st)) {
Expand All @@ -352,7 +378,16 @@ function normalizeCodexTools(body: Record<string, unknown>): void {
return true;
}

if (tool.type !== "function") {
if (toolType !== "function") {
const hasFunctionObject = tool.function && typeof tool.function === "object";
const hasName = typeof tool.name === "string";
if (!toolType || hasFunctionObject || hasName) {
return false;
}
if (CODEX_HOSTED_TOOL_TYPES.has(toolType)) {
return true;
}
console.debug(`[Codex] dropping unknown hosted tool type: ${toolType}`);
return false;
}

Expand Down Expand Up @@ -613,6 +648,8 @@ export class CodexExecutor extends BaseExecutor {
// Proxy clients (e.g. OpenClaw) rely on response chaining via previous_response_id,
// which requires store=true so that response items are persisted.
// If the client explicitly sets store, respect it. Otherwise default to true.
// Exception: when the request uses the image_generation hosted tool, the Codex
// backend rejects store=true ("Store must be set to false"), so default to false.
const explicitStoreSetting =
credentials?.providerSpecificData &&
typeof credentials.providerSpecificData === "object" &&
Expand All @@ -622,7 +659,7 @@ export class CodexExecutor extends BaseExecutor {
if (explicitStoreSetting === false) {
body.store = false;
} else if (body.store === undefined) {
body.store = true;
body.store = hasImageGenerationTool(body) ? false : true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compute store default after Codex tool normalization

store is defaulted from hasImageGenerationTool(body) before normalizeCodexTools(body) removes invalid hosted tools. If an image_generation entry is later filtered out (for example because it also has a name or function field), store remains forced to false even though no image tool is sent upstream, which can unexpectedly disable response persistence and break previous_response_id chaining for the remaining valid tools. Derive this default from the normalized tool list instead.

Useful? React with 👍 / 👎.

}

// Codex Responses only supports function tools with non-empty names.
Expand Down
3 changes: 3 additions & 0 deletions open-sse/executors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { MuseSparkWebExecutor } from "./muse-spark-web.ts";
import { AzureOpenAIExecutor } from "./azure-openai.ts";
import { GitlabExecutor } from "./gitlab.ts";
import { NlpCloudExecutor } from "./nlpcloud.ts";
import { PetalsExecutor } from "./petals.ts";

const executors = {
antigravity: new AntigravityExecutor(),
Expand All @@ -34,6 +35,7 @@ const executors = {
gitlab: new GitlabExecutor(),
"gitlab-duo": new GitlabExecutor("gitlab-duo"),
nlpcloud: new NlpCloudExecutor(),
petals: new PetalsExecutor(),
pollinations: new PollinationsExecutor(),
pol: new PollinationsExecutor(), // Alias
"cloudflare-ai": new CloudflareAIExecutor(),
Expand Down Expand Up @@ -89,3 +91,4 @@ export { MuseSparkWebExecutor } from "./muse-spark-web.ts";
export { AzureOpenAIExecutor } from "./azure-openai.ts";
export { GitlabExecutor } from "./gitlab.ts";
export { NlpCloudExecutor } from "./nlpcloud.ts";
export { PetalsExecutor } from "./petals.ts";
Loading