@@ -28,19 +28,25 @@ export class Service extends Context.Service<Service, {
2828 readonly fetch : ( url : string , opts : { timeoutMs : number } ) => Effect . Effect < FetchResult , Error >
2929} > ( ) ( "@browser-use/FetchUse" ) { }
3030
31- export const makeLayer = ( options : { endpoint : string ; apiKey : string ; proxyToken : string } ) =>
31+ export const makeLayer = ( options : { proxyUrl : string ; apiKey : string ; proxyToken : string } ) =>
3232 Layer . effect (
3333 Service ,
3434 Effect . gen ( function * ( ) {
3535 const http = yield * HttpClient . HttpClient
36+ const hasProxySetting = options . proxyUrl . length > 0 || options . proxyToken . length > 0
37+ const proxyEnabled = options . proxyUrl . length > 0 && options . proxyToken . length > 0
38+ const directEnabled = ! hasProxySetting && options . apiKey . length > 0
3639 return Service . of ( {
37- enabled : options . proxyToken . length > 0 || options . apiKey . length > 0 ,
40+ enabled : proxyEnabled || directEnabled ,
3841 fetch : ( url , { timeoutMs } ) =>
3942 Effect . gen ( function * ( ) {
40- const auth = options . proxyToken
43+ if ( ! proxyEnabled && ! directEnabled ) {
44+ return yield * Effect . fail ( new Error ( "fetch-use credentials are missing or partially configured" ) )
45+ }
46+ const auth = proxyEnabled
4147 ? { Authorization : `Bearer ${ options . proxyToken } ` }
4248 : { "X-Browser-Use-API-Key" : options . apiKey }
43- const request = yield * HttpClientRequest . post ( options . endpoint ) . pipe (
49+ const request = yield * HttpClientRequest . post ( proxyEnabled ? options . proxyUrl : DEFAULT_ENDPOINT ) . pipe (
4450 HttpClientRequest . setHeaders ( { "Content-Type" : "application/json" , ...auth } ) ,
4551 HttpClientRequest . bodyJson ( { url, timeout_ms : timeoutMs } ) ,
4652 )
@@ -62,7 +68,7 @@ export const makeLayer = (options: { endpoint: string; apiKey: string; proxyToke
6268 )
6369
6470export const layer = makeLayer ( {
65- endpoint : process . env . BROWSER_USE_FETCH_URL ?? DEFAULT_ENDPOINT ,
71+ proxyUrl : process . env . BROWSER_USE_FETCH_URL ?? "" ,
6672 apiKey : process . env . BROWSER_USE_API_KEY ?? "" ,
6773 proxyToken : process . env . BROWSER_USE_FETCH_TOKEN ?? "" ,
6874} )
0 commit comments