fix: force direct global dispatcher; Anthropic uses own proxy dispatcher

This commit is contained in:
aedes
2026-04-21 17:20:04 +03:00
parent 720469dfc8
commit 99b4b58f89

View File

@@ -2,10 +2,13 @@ const express = require('express');
const path = require('path');
const fs = require('fs');
const os = require('os');
const { ProxyAgent } = require('undici');
const { ProxyAgent, Agent, setGlobalDispatcher } = require('undici');
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
const anthropicAgent = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;
const directAgent = new Agent();
const anthropicAgent = proxyUrl ? new ProxyAgent(proxyUrl) : directAgent;
// Force global default = DIRECT. Anthropic calls override with their own dispatcher.
setGlobalDispatcher(directAgent);
if (proxyUrl) console.log(`✓ Anthropic proxy: ${proxyUrl} (sechenov: direct)`);
const app = express();