1
1
import { isAxiosError } from "axios" ;
2
2
import { 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" ;
4
4
import find from "find-process" ;
5
5
import * as fs from "fs/promises" ;
6
6
import * as jsonc from "jsonc-parser" ;
@@ -19,7 +19,7 @@ import {
19
19
import { extractAgents } from "./api-helper" ;
20
20
import * as cli from "./cliManager" ;
21
21
import { Commands } from "./commands" ;
22
- import { featureSetForVersion , FeatureSet } from "./featureSet" ;
22
+ import { FeatureSet , featureSetForVersion } from "./featureSet" ;
23
23
import { getHeaderArgs } from "./headers" ;
24
24
import { Inbox } from "./inbox" ;
25
25
import { SSHConfig , SSHValues , mergeSSHConfigValues } from "./sshConfig" ;
@@ -162,7 +162,7 @@ export class Remote {
162
162
protected async validateServerVersion (
163
163
workspaceRestClient : Api ,
164
164
binaryPath : string ,
165
- ) : Promise < { process : ChildProcess ; logPath : string } | undefined > {
165
+ ) : Promise < FeatureSet | undefined > {
166
166
// First thing is to check the version.
167
167
const buildInfo = await workspaceRestClient . getBuildInfo ( ) ;
168
168
@@ -275,34 +275,32 @@ export class Remote {
275
275
* Extracted for testability.
276
276
*/
277
277
protected async waitForAgentConnection (
278
- agent : { id : string ; status : string ; name ?: string } ,
278
+ agent : WorkspaceAgent ,
279
279
monitor : WorkspaceMonitor ,
280
- ) : Promise < { id : string ; status : string ; name ?: string } > {
280
+ ) : Promise < WorkspaceAgent > {
281
281
return await vscode . window . withProgress (
282
282
{
283
283
title : "Waiting for the agent to connect..." ,
284
284
location : vscode . ProgressLocation . Notification ,
285
285
} ,
286
286
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 ;
303
292
} ) ;
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
+ } ) ;
306
304
} ,
307
305
) ;
308
306
}
@@ -584,7 +582,7 @@ export class Remote {
584
582
}
585
583
586
584
// Find the workspace from the URI scheme provided
587
- const workspace = await this . fetchWorkspace (
585
+ let workspace = await this . fetchWorkspace (
588
586
workspaceRestClient ,
589
587
parts ,
590
588
baseUrlRaw ,
@@ -1014,13 +1012,11 @@ export class Remote {
1014
1012
protected updateNetworkStatus (
1015
1013
networkStatus : vscode . StatusBarItem ,
1016
1014
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 ;
1024
1020
} ,
1025
1021
) : void {
1026
1022
let statusText = "$(globe) " ;
@@ -1037,40 +1033,26 @@ export class Remote {
1037
1033
statusText += "Direct " ;
1038
1034
networkStatus . tooltip = "You're connected peer-to-peer ✨." ;
1039
1035
} else {
1040
- statusText += network . preferred_derp + " ";
1036
+ statusText += "Relay ";
1041
1037
networkStatus . tooltip =
1042
1038
"You're connected through a relay 🕵.\nWe'll switch over to peer-to-peer when available." ;
1043
1039
}
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" ;
1071
1051
}
1072
1052
1073
- statusText += "(" + network . latency . toFixed ( 2 ) + "ms)" ;
1053
+ if ( network . latency ) {
1054
+ statusText += "(" + network . latency . toFixed ( 2 ) + "ms)" ;
1055
+ }
1074
1056
networkStatus . text = statusText ;
1075
1057
networkStatus . show ( ) ;
1076
1058
}
0 commit comments