| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { ProxyAgent } from 'undici'; |
| import { getConfig } from './config.js'; |
|
|
| let cachedAgent: ProxyAgent | undefined; |
| let cachedVisionAgent: ProxyAgent | undefined; |
|
|
| |
| |
| |
| |
| export function getProxyDispatcher(): ProxyAgent | undefined { |
| const config = getConfig(); |
| const proxyUrl = config.proxy; |
|
|
| if (!proxyUrl) return undefined; |
|
|
| if (!cachedAgent) { |
| console.log(`[Proxy] 使用全局代理: ${proxyUrl}`); |
| cachedAgent = new ProxyAgent(proxyUrl); |
| } |
|
|
| return cachedAgent; |
| } |
|
|
| |
| |
| |
| |
| export function getProxyFetchOptions(): Record<string, unknown> { |
| const dispatcher = getProxyDispatcher(); |
| return dispatcher ? { dispatcher } : {}; |
| } |
|
|
| |
| |
| |
| |
| export function getVisionProxyFetchOptions(): Record<string, unknown> { |
| const config = getConfig(); |
| const visionProxy = config.vision?.proxy; |
|
|
| if (visionProxy) { |
| if (!cachedVisionAgent) { |
| console.log(`[Proxy] Vision 独立代理: ${visionProxy}`); |
| cachedVisionAgent = new ProxyAgent(visionProxy); |
| } |
| return { dispatcher: cachedVisionAgent }; |
| } |
|
|
| |
| return getProxyFetchOptions(); |
| } |
|
|