@@ -6,12 +6,15 @@ import { setTimeout as sleep } from "node:timers/promises"
66import { createServer } from "http"
77import { OpenAIWebSocketPool } from "./ws-pool"
88import { OauthCallbackPage } from "@opencode-ai/core/oauth/page"
9+ import { isRecord } from "@/util/record"
910
1011const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann"
1112const ISSUER = "https://auth.openai.com"
1213const CODEX_API_ENDPOINT = "https://chatgpt.com/backend-api/codex/responses"
1314const OAUTH_PORT = 1455
1415const OAUTH_POLLING_SAFETY_MARGIN_MS = 3000
16+ const CODEX_COMPATIBILITY_VERSION = "0.144.0"
17+ const RESPONSES_LITE_MODEL = "gpt-5.6-luna"
1518const ALLOWED_MODELS = new Set ( [ "gpt-5.5" , "gpt-5.3-codex-spark" , "gpt-5.4" , "gpt-5.4-mini" ] )
1619const DISALLOWED_MODELS = new Set ( [ "gpt-5.5-pro" ] )
1720
@@ -417,6 +420,9 @@ export async function CodexAuthPlugin(input: PluginInput, options: CodexAuthPlug
417420
418421 const requestInit = {
419422 ...init ,
423+ body : parsed . pathname . endsWith ( "/responses" )
424+ ? prepareResponsesLiteRequest ( init ?. body , headers )
425+ : init ?. body ,
420426 headers,
421427 }
422428 if ( websocketFetch && parsed . pathname . endsWith ( "/responses" ) ) return websocketFetch ( url , requestInit )
@@ -561,3 +567,61 @@ export async function CodexAuthPlugin(input: PluginInput, options: CodexAuthPlug
561567 } ,
562568 }
563569}
570+
571+ function prepareResponsesLiteRequest ( body : BodyInit | null | undefined , headers : Headers ) {
572+ if ( typeof body !== "string" ) return body
573+ const request : unknown = JSON . parse ( body )
574+ if ( ! isRecord ( request ) ) return body
575+ if ( request . model !== RESPONSES_LITE_MODEL ) return body
576+ if ( ! Array . isArray ( request . input ) ) throw new Error ( "Responses Lite requires an input array" )
577+ if ( request . tools !== undefined && ! Array . isArray ( request . tools ) ) {
578+ throw new Error ( "Responses Lite requires a tools array" )
579+ }
580+ if ( request . instructions !== undefined && typeof request . instructions !== "string" ) {
581+ throw new Error ( "Responses Lite requires string instructions" )
582+ }
583+
584+ const sessionID = headers . get ( "session-id" )
585+ if ( ! sessionID ) throw new Error ( "Responses Lite requires a session-id header" )
586+
587+ function stripImageDetail ( value : unknown ) {
588+ if ( Array . isArray ( value ) ) {
589+ value . forEach ( stripImageDetail )
590+ return
591+ }
592+ if ( ! isRecord ( value ) ) return
593+ if ( value . type === "input_image" ) delete value . detail
594+ Object . values ( value ) . forEach ( stripImageDetail )
595+ }
596+
597+ stripImageDetail ( request . input )
598+ request . input = [
599+ { type : "additional_tools" , role : "developer" , tools : request . tools ?? [ ] } ,
600+ ...( request . instructions
601+ ? [
602+ {
603+ type : "message" ,
604+ role : "developer" ,
605+ content : [ { type : "input_text" , text : request . instructions } ] ,
606+ } ,
607+ ]
608+ : [ ] ) ,
609+ ...request . input ,
610+ ]
611+ delete request . tools
612+ delete request . instructions
613+ request . tool_choice = "auto"
614+ request . parallel_tool_calls = false
615+ request . prompt_cache_key = sessionID
616+ request . reasoning = {
617+ ...( isRecord ( request . reasoning ) ? request . reasoning : { } ) ,
618+ context : "all_turns" ,
619+ }
620+
621+ headers . set ( "session-id" , sessionID )
622+ headers . set ( "x-session-affinity" , sessionID )
623+ headers . set ( "version" , CODEX_COMPATIBILITY_VERSION )
624+ headers . set ( OpenAIWebSocketPool . RESPONSES_LITE_HEADER , "true" )
625+ headers . delete ( "content-length" )
626+ return JSON . stringify ( request )
627+ }
0 commit comments