@@ -5,9 +5,11 @@ import type {
55 ProcessProgressEvent ,
66 ProcessSettings ,
77 ProcessStatus ,
8- CustomServiceConfig
8+ CustomServiceConfig ,
9+ ServiceId
910} from "../../shared/types" ;
1011import { maskKey , sanitizeErrorMessage } from "../../shared/mask" ;
12+ import { decodeProxyKey } from "../../shared/proxy" ;
1113import type { ServiceAdapter } from "../services/types" ;
1214import { RateLimiter } from "./rateLimiter" ;
1315import { randomBetween , sleep } from "./utils" ;
@@ -21,6 +23,7 @@ interface ProcessEvents {
2123export interface ProcessRunOptions {
2224 id : string ;
2325 name : string ;
26+ serviceId : ServiceId ;
2427 keys : string [ ] ;
2528 method : CheckMethod ;
2629 settings : ProcessSettings ;
@@ -40,6 +43,7 @@ export class ProcessRun {
4043 private customConfig ?: CustomServiceConfig ;
4144 private rateLimiter : RateLimiter ;
4245 private events : ProcessEvents ;
46+ private isProxyService : boolean ;
4347 private status : ProcessStatus = "Running" ;
4448 private queueIndex = 0 ;
4549 private activeCount = 0 ;
@@ -52,6 +56,7 @@ export class ProcessRun {
5256 constructor ( options : ProcessRunOptions ) {
5357 this . id = options . id ;
5458 this . name = options . name ;
59+ this . isProxyService = options . serviceId === "proxy" ;
5560 this . keys = options . keys ;
5661 this . method = options . method ;
5762 this . settings = options . settings ;
@@ -61,6 +66,20 @@ export class ProcessRun {
6166 this . events = options . events ;
6267 }
6368
69+ private buildProxyMeta (
70+ proxyType : CheckResult [ "proxyType" ] | undefined ,
71+ overrides ?: { checkMode ?: CheckResult [ "checkMode" ] ; targetUrl ?: CheckResult [ "targetUrl" ] }
72+ ) {
73+ if ( ! this . isProxyService ) {
74+ return { proxyType } ;
75+ }
76+ return {
77+ proxyType,
78+ checkMode : overrides ?. checkMode ?? this . settings . proxy ?. checkMode ,
79+ targetUrl : overrides ?. targetUrl ?? this . settings . proxy ?. targetUrl
80+ } ;
81+ }
82+
6483 start ( ) {
6584 this . status = "Running" ;
6685 this . emitProgress ( ) ;
@@ -151,7 +170,9 @@ export class ProcessRun {
151170 this . abortControllers . set ( keyIndex , controller ) ;
152171 this . activeCount += 1 ;
153172
154- const maskedKey = maskKey ( key ) ;
173+ const proxyInfo = decodeProxyKey ( key ) ;
174+ const displayKey = proxyInfo ?. proxy ?? key ;
175+ const maskedKey = this . isProxyService ? displayKey : maskKey ( displayKey ) ;
155176 let result : CheckResult ;
156177
157178 try {
@@ -162,14 +183,15 @@ export class ProcessRun {
162183 await sleep ( delayMs ) ;
163184 }
164185
165- result = await this . runWithRetries ( key , controller . signal ) ;
186+ result = await this . runWithRetries ( key , controller . signal , proxyInfo ?? undefined ) ;
166187 } catch ( error ) {
167188 const message = error instanceof Error ? error . message : "Unexpected error" ;
168189 result = {
169190 status : "UNKNOWN_ERROR" ,
170191 latencyMs : 0 ,
171192 errorMessage : sanitizeErrorMessage ( message ) ,
172- checkedAt : new Date ( ) . toISOString ( )
193+ checkedAt : new Date ( ) . toISOString ( ) ,
194+ ...this . buildProxyMeta ( proxyInfo ?. proxyType )
173195 } ;
174196 } finally {
175197 this . activeCount -= 1 ;
@@ -180,7 +202,7 @@ export class ProcessRun {
180202 this . events . onLog ( {
181203 processId : this . id ,
182204 keyIndex,
183- keyFull : key ,
205+ keyFull : displayKey ,
184206 keyMasked : maskedKey ,
185207 method : this . method ,
186208 result
@@ -190,13 +212,18 @@ export class ProcessRun {
190212 this . schedule ( ) ;
191213 }
192214
193- private async runWithRetries ( key : string , signal : AbortSignal ) : Promise < CheckResult > {
215+ private async runWithRetries (
216+ key : string ,
217+ signal : AbortSignal ,
218+ proxyInfo ?: { proxyType : CheckResult [ "proxyType" ] }
219+ ) : Promise < CheckResult > {
194220 let attempt = 0 ;
195221 let lastResult : CheckResult = {
196222 status : "UNKNOWN_ERROR" ,
197223 latencyMs : 0 ,
198224 checkedAt : new Date ( ) . toISOString ( ) ,
199- errorMessage : "No response"
225+ errorMessage : "No response" ,
226+ ...this . buildProxyMeta ( proxyInfo ?. proxyType )
200227 } ;
201228
202229 while ( attempt <= this . settings . retries ) {
@@ -206,7 +233,8 @@ export class ProcessRun {
206233 latencyMs : 0 ,
207234 checkedAt : new Date ( ) . toISOString ( ) ,
208235 errorCode : "cancelled" ,
209- errorMessage : "Cancelled by user"
236+ errorMessage : "Cancelled by user" ,
237+ ...this . buildProxyMeta ( proxyInfo ?. proxyType )
210238 } ;
211239 }
212240
@@ -217,7 +245,8 @@ export class ProcessRun {
217245 timeoutMs : this . settings . timeoutMs ,
218246 signal,
219247 customConfig : this . customConfig ,
220- openAiOrgId : this . settings . openAiOrgId
248+ openAiOrgId : this . settings . openAiOrgId ,
249+ proxySettings : this . settings . proxy
221250 } ) ;
222251
223252 if ( this . stopped || signal . aborted ) {
@@ -226,7 +255,8 @@ export class ProcessRun {
226255 latencyMs : 0 ,
227256 checkedAt : new Date ( ) . toISOString ( ) ,
228257 errorCode : "cancelled" ,
229- errorMessage : "Cancelled by user"
258+ errorMessage : "Cancelled by user" ,
259+ ...this . buildProxyMeta ( proxyInfo ?. proxyType )
230260 } ;
231261 }
232262
@@ -236,7 +266,11 @@ export class ProcessRun {
236266 latencyMs : adapterResult . latencyMs ,
237267 errorCode : adapterResult . errorCode ,
238268 errorMessage : adapterResult . errorMessage ,
239- checkedAt : new Date ( ) . toISOString ( )
269+ checkedAt : new Date ( ) . toISOString ( ) ,
270+ ...this . buildProxyMeta ( adapterResult . proxyType ?? proxyInfo ?. proxyType , {
271+ checkMode : adapterResult . checkMode ,
272+ targetUrl : adapterResult . targetUrl
273+ } )
240274 } ;
241275
242276 if ( ! adapterResult . retryable || attempt === this . settings . retries ) {
0 commit comments