fix(openai): narrow timeout fetch contract

This commit is contained in:
Aiden Cline 2026-06-03 23:03:20 -05:00
parent e4a9538289
commit 423b1cb41b
3 changed files with 5 additions and 4 deletions

View file

@ -21,7 +21,7 @@ const HEADER_TIMEOUT = Symbol.for("opencode.provider.header-timeout")
const ALLOWED_MODELS = new Set(["gpt-5.5", "gpt-5.3-codex-spark", "gpt-5.4", "gpt-5.4-mini"])
export function fetchWithHeaderTimeout(
fetch: typeof globalThis.fetch,
fetch: OpenAIWebSocketPool.Fetch,
input: RequestInfo | URL,
init: RequestInit | undefined,
timeout: number | false,
@ -374,7 +374,7 @@ export async function CodexAuthPlugin(input: PluginInput, options: CodexAuthPlug
let httpHeaderTimeout: number | false = DEFAULT_HTTP_HEADER_TIMEOUT
let websocketFetchInstalled = false
const websocketFetches: Array<ReturnType<typeof OpenAIWebSocketPool.createWebSocketFetch>> = []
const httpFetch: typeof globalThis.fetch = (requestInput, init) =>
const httpFetch: OpenAIWebSocketPool.Fetch = (requestInput, init) =>
fetchWithHeaderTimeout(fetch, requestInput, init, httpHeaderTimeout)
return {

View file

@ -5,11 +5,12 @@ import { isRecord } from "@/util/record"
import { OpenAIWebSocket } from "./ws"
export const TITLE_HEADER = "x-opencode-title"
export type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
const log = Log.create({ service: "plugin.openai.ws" })
export interface CreateWebSocketFetchOptions {
httpFetch?: typeof globalThis.fetch
httpFetch?: Fetch
url?: string
connectTimeout?: number
idleTimeout?: number

View file

@ -38,7 +38,7 @@ const HEADER_TIMEOUT = Symbol.for("opencode.provider.header-timeout")
export function headerTimeoutForFetch(fetch: unknown, timeout: number | false | undefined) {
if (timeout === false) return undefined
if (typeof fetch === "function" && fetch[HEADER_TIMEOUT] === false) return undefined
if (typeof fetch === "function" && (fetch as { [HEADER_TIMEOUT]?: false })[HEADER_TIMEOUT] === false) return undefined
return timeout
}