fix(openai): proxy websocket connections under bun (#29832)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user