11import { isAxiosError } from "axios" ;
22import { Api } from "coder/site/src/api/api" ;
3- import { Workspace } from "coder/site/src/api/typesGenerated" ;
3+ import { Workspace , WorkspaceAgent } from "coder/site/src/api/typesGenerated" ;
44import find from "find-process" ;
55import * as fs from "fs/promises" ;
66import * as jsonc from "jsonc-parser" ;
@@ -19,7 +19,7 @@ import {
1919import { extractAgents } from "./api-helper" ;
2020import * as cli from "./cliManager" ;
2121import { Commands } from "./commands" ;
22- import { featureSetForVersion , FeatureSet } from "./featureSet" ;
22+ import { FeatureSet , featureSetForVersion } from "./featureSet" ;
2323import { getHeaderArgs } from "./headers" ;
2424import { Inbox } from "./inbox" ;
2525import { SSHConfig , SSHValues , mergeSSHConfigValues } from "./sshConfig" ;
@@ -162,7 +162,7 @@ export class Remote {
162162 protected async validateServerVersion (
163163 workspaceRestClient : Api ,
164164 binaryPath : string ,
165- ) : Promise < { process : ChildProcess ; logPath : string } | undefined > {
165+ ) : Promise < FeatureSet | undefined > {
166166 // First thing is to check the version.
167167 const buildInfo = await workspaceRestClient . getBuildInfo ( ) ;
168168
@@ -275,34 +275,32 @@ export class Remote {
275275 * Extracted for testability.
276276 */
277277 protected async waitForAgentConnection (
278- agent : { id : string ; status : string ; name ?: string } ,
278+ agent : WorkspaceAgent ,
279279 monitor : WorkspaceMonitor ,
280- ) : Promise < { id : string ; status : string ; name ?: string } > {
280+ ) : Promise < WorkspaceAgent > {
281281 return await vscode . window . withProgress (
282282 {
283283 title : "Waiting for the agent to connect..." ,
284284 location : vscode . ProgressLocation . Notification ,
285285 } ,
286286 async ( ) => {
287- return await new Promise < { id : string ; status : string ; name ?: string } > (
288- ( resolve ) => {
289- const updateEvent = monitor . onChange . event ( ( workspace ) => {
290- const agents = extractAgents ( workspace ) ;
291- const found = agents . find ( ( newAgent ) => {
292- return newAgent . id === agent . id ;
293- } ) ;
294- if ( ! found ) {
295- return ;
296- }
297- agent = found ;
298- if ( agent . status === "connecting" ) {
299- return ;
300- }
301- updateEvent . dispose ( ) ;
302- resolve ( agent ) ;
287+ return await new Promise < WorkspaceAgent > ( ( resolve ) => {
288+ const updateEvent = monitor . onChange . event ( ( workspace ) => {
289+ const agents = extractAgents ( workspace ) ;
290+ const found = agents . find ( ( newAgent ) => {
291+ return newAgent . id === agent . id ;
303292 } ) ;
304- } ,
305- ) ;
293+ if ( ! found ) {
294+ return ;
295+ }
296+ agent = found ;
297+ if ( agent . status === "connecting" ) {
298+ return ;
299+ }
300+ updateEvent . dispose ( ) ;
301+ resolve ( agent ) ;
302+ } ) ;
303+ } ) ;
306304 } ,
307305 ) ;
308306 }
@@ -584,7 +582,7 @@ export class Remote {
584582 }
585583
586584 // Find the workspace from the URI scheme provided
587- const workspace = await this . fetchWorkspace (
585+ let workspace = await this . fetchWorkspace (
588586 workspaceRestClient ,
589587 parts ,
590588 baseUrlRaw ,
@@ -1014,13 +1012,11 @@ export class Remote {
10141012 protected updateNetworkStatus (
10151013 networkStatus : vscode . StatusBarItem ,
10161014 network : {
1017- p2p : boolean ;
1018- latency : number ;
1019- preferred_derp : string ;
1020- derp_latency : { [ key : string ] : number } ;
1021- upload_bytes_sec : number ;
1022- download_bytes_sec : number ;
1023- using_coder_connect : boolean ;
1015+ using_coder_connect ?: boolean ;
1016+ p2p ?: boolean ;
1017+ latency ?: number ;
1018+ download_bytes_sec ?: number ;
1019+ upload_bytes_sec ?: number ;
10241020 } ,
10251021 ) : void {
10261022 let statusText = "$(globe) " ;
@@ -1037,40 +1033,26 @@ export class Remote {
10371033 statusText += "Direct " ;
10381034 networkStatus . tooltip = "You're connected peer-to-peer ✨." ;
10391035 } else {
1040- statusText += network . preferred_derp + " ";
1036+ statusText += "Relay ";
10411037 networkStatus . tooltip =
10421038 "You're connected through a relay 🕵.\nWe'll switch over to peer-to-peer when available." ;
10431039 }
1044- networkStatus . tooltip +=
1045- "\n\nDownload ↓ " +
1046- prettyBytes ( network . download_bytes_sec , {
1047- bits : true ,
1048- } ) +
1049- "/s • Upload ↑ " +
1050- prettyBytes ( network . upload_bytes_sec , {
1051- bits : true ,
1052- } ) +
1053- "/s\n" ;
1054-
1055- if ( ! network . p2p ) {
1056- const derpLatency = network . derp_latency [ network . preferred_derp ] ;
1057-
1058- networkStatus . tooltip += `You ↔ ${ derpLatency . toFixed ( 2 ) } ms ↔ ${ network . preferred_derp } ↔ ${ ( network . latency - derpLatency ) . toFixed ( 2 ) } ms ↔ Workspace` ;
1059-
1060- let first = true ;
1061- Object . keys ( network . derp_latency ) . forEach ( ( region ) => {
1062- if ( region === network . preferred_derp ) {
1063- return ;
1064- }
1065- if ( first ) {
1066- networkStatus . tooltip += `\n\nOther regions:` ;
1067- first = false ;
1068- }
1069- networkStatus . tooltip += `\n${ region } : ${ Math . round ( network . derp_latency [ region ] * 100 ) / 100 } ms` ;
1070- } ) ;
1040+ if ( network . download_bytes_sec && network . upload_bytes_sec ) {
1041+ networkStatus . tooltip +=
1042+ "\n\nDownload ↓ " +
1043+ prettyBytes ( network . download_bytes_sec , {
1044+ bits : true ,
1045+ } ) +
1046+ "/s • Upload ↑ " +
1047+ prettyBytes ( network . upload_bytes_sec , {
1048+ bits : true ,
1049+ } ) +
1050+ "/s\n" ;
10711051 }
10721052
1073- statusText += "(" + network . latency . toFixed ( 2 ) + "ms)" ;
1053+ if ( network . latency ) {
1054+ statusText += "(" + network . latency . toFixed ( 2 ) + "ms)" ;
1055+ }
10741056 networkStatus . text = statusText ;
10751057 networkStatus . show ( ) ;
10761058 }
0 commit comments