fix: isolate model transport and stop replaying unknown requests
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { Agent,EnvHttpProxyAgent,fetch } from 'undici';
|
||||
|
||||
export class ModelTransport {
|
||||
constructor({environment=process.env,lookup,connectTimeoutMs=10000}={}){
|
||||
const setting=(lower,upper)=>environment[lower]??environment[upper]??'';
|
||||
this.proxy={httpProxy:setting('http_proxy','HTTP_PROXY'),httpsProxy:setting('https_proxy','HTTPS_PROXY'),noProxy:setting('no_proxy','NO_PROXY')};
|
||||
this.connect={autoSelectFamily:true,autoSelectFamilyAttemptTimeout:250,timeout:connectTimeoutMs,...(lookup?{lookup}:{})};
|
||||
this.profile={schemaVersion:1,implementation:'undici-7.30.1',autoSelectFamily:true,familyAttemptTimeoutMs:250,connectTimeoutMs,
|
||||
httpProxyConfigured:!!this.proxy.httpProxy,httpsProxyConfigured:!!this.proxy.httpsProxy,noProxyConfigured:!!this.proxy.noProxy};
|
||||
}
|
||||
fetch(url,options){
|
||||
this.dispatcher??=this.profile.httpProxyConfigured||this.profile.httpsProxyConfigured
|
||||
?new EnvHttpProxyAgent({...this.proxy,connect:this.connect,proxyTls:this.connect,requestTls:this.connect}):new Agent({connect:this.connect});
|
||||
return fetch(url,{...options,dispatcher:this.dispatcher});
|
||||
}
|
||||
async close(){const dispatcher=this.dispatcher;this.dispatcher=null;await dispatcher?.close();}
|
||||
}
|
||||
Reference in New Issue
Block a user