Repository navigation
Pin fetch to bundled undici for undici higher versions compatibility #4238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
df387e6
bd6c84a
632e0b0
fa5f896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||||||||
| */ | ||||||||||||
|
|
||||||||||||
| import { ProxyAgent, type Dispatcher } from 'undici'; | ||||||||||||
| import { ProxyAgent, fetch as undiciFetch, type Dispatcher } from 'undici'; | ||||||||||||
|
|
||||||||||||
| import { createDebugLogger } from './debugLogger.js'; | ||||||||||||
|
|
||||||||||||
|
|
@@ -37,6 +37,13 @@ export type OpenAIRuntimeFetchOptions = | |||||||||||
| dispatcher?: Dispatcher; | ||||||||||||
| timeout?: false; | ||||||||||||
| }; | ||||||||||||
| // Optional fetch override. When a custom dispatcher is being passed, | ||||||||||||
| // we pin this to the bundled undici's fetch so the dispatcher and | ||||||||||||
| // fetch share a single undici version — otherwise Node's built-in | ||||||||||||
| // fetch (newer undici) rejects a ProxyAgent from the bundled undici | ||||||||||||
| // (e.g. v6) with `invalid onError method`. | ||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||
| fetch?: any; | ||||||||||||
| } | ||||||||||||
| | undefined; | ||||||||||||
|
|
||||||||||||
|
|
@@ -596,7 +603,13 @@ function buildFetchOptionsWithDispatcher( | |||||||||||
| // 300s bodyTimeout. This is sufficient for all current model streaming responses. | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Anthropic SDK 静默丢弃
这不是此 PR 引入的问题(PR 之前 dispatcher 就已经被返回了),但
Suggested change
— DeepSeek/deepseek-v4-pro via Qwen Code /review |
||||||||||||
| try { | ||||||||||||
| const dispatcher = getOrCreateSharedDispatcher(proxyUrl); | ||||||||||||
| return { fetchOptions: { dispatcher } }; | ||||||||||||
| // Pin fetch to undici's own implementation so the dispatcher and fetch | ||||||||||||
| // come from the same undici version. Node's bundled undici may differ in | ||||||||||||
| // major version from the project's bundled one (e.g. v8 vs v6), which | ||||||||||||
| // breaks dispatcher handler-interface checks (`invalid onError method`). | ||||||||||||
| // The no-proxy branch above intentionally skips this so the runtime's | ||||||||||||
| // built-in fetch continues to be used when no dispatcher is involved. | ||||||||||||
| return { fetchOptions: { dispatcher }, fetch: undiciFetch }; | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Missing success-path debug log. Consider adding a debug log before the return:
Suggested change
— qwen-latest-series-invite-beta-v34 via Qwen Code /review |
||||||||||||
| } catch (error) { | ||||||||||||
| // Log dispatcher creation failure - requests will fallback to direct connection | ||||||||||||
| // bypassing the configured proxy. This is important for environments requiring | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.