@@ -45,12 +45,15 @@ import {
4545} from "@trigger.dev/core/v3/workers" ;
4646
4747export class CliApiClient {
48+ private engineURL : string ;
49+
4850 constructor (
4951 public readonly apiURL : string ,
5052 // TODO: consider making this required
5153 public readonly accessToken ?: string
5254 ) {
5355 this . apiURL = apiURL . replace ( / \/ $ / , "" ) ;
56+ this . engineURL = this . apiURL ;
5457 }
5558
5659 async createAuthorizationCode ( ) {
@@ -418,6 +421,7 @@ export class CliApiClient {
418421 heartbeatRun : this . devHeartbeatRun . bind ( this ) ,
419422 startRunAttempt : this . devStartRunAttempt . bind ( this ) ,
420423 completeRunAttempt : this . devCompleteRunAttempt . bind ( this ) ,
424+ setEngineURL : this . setEngineURL . bind ( this ) ,
421425 } as const ;
422426 }
423427
@@ -486,7 +490,7 @@ export class CliApiClient {
486490 throw new Error ( "devConfig: No access token" ) ;
487491 }
488492
489- return wrapZodFetch ( DevConfigResponseBody , `${ this . apiURL } /engine/v1/dev/config` , {
493+ return wrapZodFetch ( DevConfigResponseBody , `${ this . engineURL } /engine/v1/dev/config` , {
490494 headers : {
491495 Authorization : `Bearer ${ this . accessToken } ` ,
492496 Accept : "application/json" ,
@@ -503,7 +507,7 @@ export class CliApiClient {
503507 const maxRetries = 5 ;
504508 const retryDelay = 1000 ; // Start with 1 second delay
505509
506- const eventSource = new EventSource ( `${ this . apiURL } /engine/v1/dev/presence` , {
510+ const eventSource = new EventSource ( `${ this . engineURL } /engine/v1/dev/presence` , {
507511 fetch : ( input , init ) =>
508512 fetch ( input , {
509513 ...init ,
@@ -557,7 +561,7 @@ export class CliApiClient {
557561 throw new Error ( "devConfig: No access token" ) ;
558562 }
559563
560- return wrapZodFetch ( DevDequeueResponseBody , `${ this . apiURL } /engine/v1/dev/dequeue` , {
564+ return wrapZodFetch ( DevDequeueResponseBody , `${ this . engineURL } /engine/v1/dev/dequeue` , {
561565 method : "POST" ,
562566 headers : {
563567 Authorization : `Bearer ${ this . accessToken } ` ,
@@ -575,7 +579,7 @@ export class CliApiClient {
575579 throw new Error ( "devConfig: No access token" ) ;
576580 }
577581
578- return wrapZodFetch ( z . unknown ( ) , `${ this . apiURL } /engine/v1/dev/runs/${ runId } /logs/debug` , {
582+ return wrapZodFetch ( z . unknown ( ) , `${ this . engineURL } /engine/v1/dev/runs/${ runId } /logs/debug` , {
579583 method : "POST" ,
580584 headers : {
581585 Authorization : `Bearer ${ this . accessToken } ` ,
@@ -591,7 +595,7 @@ export class CliApiClient {
591595 ) : Promise < ApiResult < WorkloadRunLatestSnapshotResponseBody > > {
592596 return wrapZodFetch (
593597 WorkloadRunLatestSnapshotResponseBody ,
594- `${ this . apiURL } /engine/v1/dev/runs/${ runId } /snapshots/latest` ,
598+ `${ this . engineURL } /engine/v1/dev/runs/${ runId } /snapshots/latest` ,
595599 {
596600 method : "GET" ,
597601 headers : {
@@ -609,7 +613,7 @@ export class CliApiClient {
609613 ) : Promise < ApiResult < WorkloadHeartbeatResponseBody > > {
610614 return wrapZodFetch (
611615 WorkloadHeartbeatResponseBody ,
612- `${ this . apiURL } /engine/v1/dev/runs/${ runId } /snapshots/${ snapshotId } /heartbeat` ,
616+ `${ this . engineURL } /engine/v1/dev/runs/${ runId } /snapshots/${ snapshotId } /heartbeat` ,
613617 {
614618 method : "POST" ,
615619 headers : {
@@ -628,7 +632,7 @@ export class CliApiClient {
628632 ) : Promise < ApiResult < WorkloadRunAttemptStartResponseBody > > {
629633 return wrapZodFetch (
630634 WorkloadRunAttemptStartResponseBody ,
631- `${ this . apiURL } /engine/v1/dev/runs/${ runId } /snapshots/${ snapshotId } /attempts/start` ,
635+ `${ this . engineURL } /engine/v1/dev/runs/${ runId } /snapshots/${ snapshotId } /attempts/start` ,
632636 {
633637 method : "POST" ,
634638 headers : {
@@ -648,7 +652,7 @@ export class CliApiClient {
648652 ) : Promise < ApiResult < WorkloadRunAttemptCompleteResponseBody > > {
649653 return wrapZodFetch (
650654 WorkloadRunAttemptCompleteResponseBody ,
651- `${ this . apiURL } /engine/v1/dev/runs/${ runId } /snapshots/${ snapshotId } /attempts/complete` ,
655+ `${ this . engineURL } /engine/v1/dev/runs/${ runId } /snapshots/${ snapshotId } /attempts/complete` ,
652656 {
653657 method : "POST" ,
654658 headers : {
@@ -659,4 +663,8 @@ export class CliApiClient {
659663 }
660664 ) ;
661665 }
666+
667+ private setEngineURL ( engineURL : string ) {
668+ this . engineURL = engineURL . replace ( / \/ $ / , "" ) ;
669+ }
662670}
0 commit comments