Skip to content

Commit e335ced

Browse files
committed
Fix connecting to off workspaces
We made a change to always include the agent in the host name so the session is stable, however for workspaces that are off there is no agent included in the response, and we were silently returning in these cases. So for these cases, fetch the first agent through a different API that still returns agents when the workspace is off. Workspace picker is broken out into a separate function, logic is unchanged. Instead of a possibly-undefined agent on a tree item, I switch on the tree item type. I feel the intent this way is easier to follow. To extract agents from both APIs, make extractAgents accept an array of resources instead of a workspace.
1 parent cb2a4ec commit e335ced

File tree

4 files changed

+195
-176
lines changed

4 files changed

+195
-176
lines changed

src/api-helper.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { isApiError, isApiErrorResponse } from "coder/site/src/api/errors";
2-
import { Workspace, WorkspaceAgent } from "coder/site/src/api/typesGenerated";
2+
import {
3+
Workspace,
4+
WorkspaceAgent,
5+
WorkspaceResource,
6+
} from "coder/site/src/api/typesGenerated";
37
import { ErrorEvent } from "eventsource";
48
import { z } from "zod";
59

@@ -24,12 +28,14 @@ export function extractAllAgents(
2428
workspaces: readonly Workspace[],
2529
): WorkspaceAgent[] {
2630
return workspaces.reduce((acc, workspace) => {
27-
return acc.concat(extractAgents(workspace));
31+
return acc.concat(extractAgents(workspace.latest_build.resources));
2832
}, [] as WorkspaceAgent[]);
2933
}
3034

31-
export function extractAgents(workspace: Workspace): WorkspaceAgent[] {
32-
return workspace.latest_build.resources.reduce((acc, resource) => {
35+
export function extractAgents(
36+
resources: readonly WorkspaceResource[],
37+
): WorkspaceAgent[] {
38+
return resources.reduce((acc, resource) => {
3339
return acc.concat(resource.agents || []);
3440
}, [] as WorkspaceAgent[]);
3541
}

0 commit comments

Comments
 (0)