Fix : Codex on cursor
This commit is contained in:
@@ -12,3 +12,20 @@ export const FORMATS = {
|
|||||||
CURSOR: "cursor"
|
CURSOR: "cursor"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Map endpoint suffix → source format (takes priority over body-based detection)
|
||||||
|
const ENDPOINT_FORMAT_MAP = {
|
||||||
|
"/v1/responses": FORMATS.OPENAI_RESPONSES,
|
||||||
|
"/v1/chat/completions": FORMATS.OPENAI,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect source format from request URL pathname.
|
||||||
|
* Returns null if no matching endpoint found.
|
||||||
|
*/
|
||||||
|
export function detectFormatByEndpoint(pathname) {
|
||||||
|
for (const [segment, format] of Object.entries(ENDPOINT_FORMAT_MAP)) {
|
||||||
|
if (pathname.includes(segment)) return format;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,9 @@ export function openaiResponsesToOpenAIRequest(model, body, stream, credentials)
|
|||||||
* Convert OpenAI Chat Completions to OpenAI Responses API format
|
* Convert OpenAI Chat Completions to OpenAI Responses API format
|
||||||
*/
|
*/
|
||||||
export function openaiToOpenAIResponsesRequest(model, body, stream, credentials) {
|
export function openaiToOpenAIResponsesRequest(model, body, stream, credentials) {
|
||||||
|
// Body already in Responses API format (e.g. Cursor CLI calling /chat/completions with input[])
|
||||||
|
if (body.input) return { ...body, model, stream: true };
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
model,
|
model,
|
||||||
input: [],
|
input: [],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "9router-app",
|
"name": "9router-app",
|
||||||
"version": "0.3.18",
|
"version": "0.3.19",
|
||||||
"description": "9Router web dashboard",
|
"description": "9Router web dashboard",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { handleChatCore } from "open-sse/handlers/chatCore.js";
|
|||||||
import { errorResponse, unavailableResponse } from "open-sse/utils/error.js";
|
import { errorResponse, unavailableResponse } from "open-sse/utils/error.js";
|
||||||
import { handleComboChat } from "open-sse/services/combo.js";
|
import { handleComboChat } from "open-sse/services/combo.js";
|
||||||
import { HTTP_STATUS } from "open-sse/config/constants.js";
|
import { HTTP_STATUS } from "open-sse/config/constants.js";
|
||||||
|
import { detectFormatByEndpoint } from "open-sse/translator/formats.js";
|
||||||
import * as log from "../utils/logger.js";
|
import * as log from "../utils/logger.js";
|
||||||
import { updateProviderCredentials, checkAndRefreshToken } from "../services/tokenRefresh.js";
|
import { updateProviderCredentials, checkAndRefreshToken } from "../services/tokenRefresh.js";
|
||||||
import { getProjectIdForConnection } from "open-sse/services/projectId.js";
|
import { getProjectIdForConnection } from "open-sse/services/projectId.js";
|
||||||
@@ -180,6 +181,8 @@ async function handleSingleModelChat(body, modelStr, clientRawRequest = null, re
|
|||||||
connectionId: credentials.connectionId,
|
connectionId: credentials.connectionId,
|
||||||
userAgent,
|
userAgent,
|
||||||
apiKey,
|
apiKey,
|
||||||
|
// Detect source format by endpoint — /chat/completions is always openai, /responses is always openai-responses
|
||||||
|
sourceFormatOverride: request?.url ? detectFormatByEndpoint(new URL(request.url).pathname) : null,
|
||||||
onCredentialsRefreshed: async (newCreds) => {
|
onCredentialsRefreshed: async (newCreds) => {
|
||||||
await updateProviderCredentials(credentials.connectionId, {
|
await updateProviderCredentials(credentials.connectionId, {
|
||||||
accessToken: newCreds.accessToken,
|
accessToken: newCreds.accessToken,
|
||||||
|
|||||||
Reference in New Issue
Block a user