فهرست منبع

fix(openai): narrow timeout fetch contract

Aiden Cline 2 ماه پیش
والد
کامیت
423b1cb41b

+ 2 - 2
packages/opencode/src/plugin/openai/codex.ts

@@ -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 {

+ 2 - 1
packages/opencode/src/plugin/openai/ws-pool.ts

@@ -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

+ 1 - 1
packages/opencode/src/provider/provider.ts

@@ -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
 }