export class RetryTransportAdapter{inner;maxRetries;baseDelayMs;maxJitterMs;constructor(e,t={}){this.inner=e,this.maxRetries=t.maxRetries??3,this.baseDelayMs=t.baseDelayMs??1e3,this.maxJitterMs=t.maxJitterMs??200}async send(e,t){let s;for(let r=0;r<=this.maxRetries;r++){const i=await this.inner.send(e,t);if(i.ok)return i;if(s=i.error,r<this.maxRetries){const e=Math.pow(2,r)*this.baseDelayMs,t=new Uint32Array(1);crypto.getRandomValues(t);const s=t[0]/4294967295*this.maxJitterMs*2-this.maxJitterMs;await this.sleep(e+s)}}throw new Error(`Failed after ${this.maxRetries} retries: ${s??"unknown error"}`)}onReceive(e){this.inner.onReceive(e)}dispose(){this.inner.dispose()}sleep(e){return new Promise(t=>setTimeout(t,e))}}