Skip to content

Commit 1b042dd

Browse files
committed
set and use engine url from dev config reply
1 parent ca8c39c commit 1b042dd

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

packages/cli-v3/src/apiClient.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ import {
4545
} from "@trigger.dev/core/v3/workers";
4646

4747
export 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
}

packages/cli-v3/src/dev/devSupervisor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class DevSupervisor implements WorkerRuntime {
8484
logger.debug("[DevSupervisor] Got dev settings", { settings: settings.data });
8585
this.config = settings.data;
8686

87+
this.options.client.dev.setEngineURL(this.config.engineUrl);
88+
8789
const maxConcurrentRuns = Math.min(
8890
this.config.maxConcurrentRuns,
8991
this.options.args.maxConcurrentRuns ?? this.config.maxConcurrentRuns

0 commit comments

Comments
 (0)