fix(openai): proxy websocket connections under bun (#29832)

This commit is contained in:
Aiden Cline
2026-05-28 23:53:07 -05:00
committed by GitHub
parent 43f110a6cb
commit a15d4f9f04
2 changed files with 80 additions and 1 deletions

View File

@@ -4,6 +4,7 @@
import WebSocket from "ws"
import { ProviderError } from "@/provider/error"
import { errorMessage } from "@/util/error"
import { ProxyEnv } from "@/util/proxy-env"
export const PROTOCOL_HEADER = "responses_websockets=2026-02-06"
@@ -72,7 +73,13 @@ export function connectResponsesWebSocket(options: ConnectResponsesWebSocketOpti
}
delete headers["content-length"]
const socket = new WebSocket(options.url, { headers })
// Bun does not apply HTTP(S)_PROXY to WebSockets unless the proxy is supplied explicitly.
const proxy =
typeof Bun === "undefined"
? undefined
: ProxyEnv.getProxyForUrl(options.url.replace(/^wss:/, "https:").replace(/^ws:/, "http:"))
const connect = { headers, ...(proxy ? { proxy } : {}) }
const socket = new WebSocket(options.url, connect)
const timeout = options.timeout
? setTimeout(() => {
cleanup()