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" ;
@@ -9,6 +9,12 @@ import * as path from "path";
9
9
import prettyBytes from "pretty-bytes" ;
10
10
import * as semver from "semver" ;
11
11
import * as vscode from "vscode" ;
12
+ import {
13
+ createAgentMetadataWatcher ,
14
+ getEventValue ,
15
+ formatEventLabel ,
16
+ formatMetadataError ,
17
+ } from "./agentMetadataHelper" ;
12
18
import {
13
19
createHttpAgent ,
14
20
makeCoderSdk ,
@@ -68,6 +74,7 @@ export class Remote {
68
74
workspace : Workspace ,
69
75
label : string ,
70
76
binPath : string ,
77
+ featureSet : FeatureSet ,
71
78
) : Promise < Workspace | undefined > {
72
79
const workspaceName = `${ workspace . owner_name } /${ workspace . name } ` ;
73
80
@@ -136,6 +143,7 @@ export class Remote {
136
143
binPath ,
137
144
workspace ,
138
145
writeEmitter ,
146
+ featureSet ,
139
147
) ;
140
148
break ;
141
149
case "failed" :
@@ -153,6 +161,7 @@ export class Remote {
153
161
binPath ,
154
162
workspace ,
155
163
writeEmitter ,
164
+ featureSet ,
156
165
) ;
157
166
break ;
158
167
}
@@ -383,6 +392,7 @@ export class Remote {
383
392
workspace ,
384
393
parts . label ,
385
394
binaryPath ,
395
+ featureSet ,
386
396
) ;
387
397
if ( ! updatedWorkspace ) {
388
398
// User declined to start the workspace.
@@ -620,6 +630,10 @@ export class Remote {
620
630
} ) ,
621
631
) ;
622
632
633
+ disposables . push (
634
+ ...this . createAgentMetadataStatusBar ( agent , workspaceRestClient ) ,
635
+ ) ;
636
+
623
637
this . storage . output . info ( "Remote setup complete" ) ;
624
638
625
639
// Returning the URL and token allows the plugin to authenticate its own
@@ -962,6 +976,56 @@ export class Remote {
962
976
return loop ( ) ;
963
977
}
964
978
979
+ /**
980
+ * Creates and manages a status bar item that displays metadata information for a given workspace agent.
981
+ * The status bar item updates dynamically based on changes to the agent's metadata,
982
+ * and hides itself if no metadata is available or an error occurs.
983
+ */
984
+ private createAgentMetadataStatusBar (
985
+ agent : WorkspaceAgent ,
986
+ restClient : Api ,
987
+ ) : vscode . Disposable [ ] {
988
+ const statusBarItem = vscode . window . createStatusBarItem (
989
+ "agentMetadata" ,
990
+ vscode . StatusBarAlignment . Left ,
991
+ ) ;
992
+
993
+ const agentWatcher = createAgentMetadataWatcher ( agent . id , restClient ) ;
994
+
995
+ const onChangeDisposable = agentWatcher . onChange ( ( ) => {
996
+ if ( agentWatcher . error ) {
997
+ const errMessage = formatMetadataError ( agentWatcher . error ) ;
998
+ this . storage . output . warn ( errMessage ) ;
999
+
1000
+ statusBarItem . text = "$(warning) Agent Status Unavailable" ;
1001
+ statusBarItem . tooltip = errMessage ;
1002
+ statusBarItem . color = new vscode . ThemeColor (
1003
+ "statusBarItem.warningForeground" ,
1004
+ ) ;
1005
+ statusBarItem . backgroundColor = new vscode . ThemeColor (
1006
+ "statusBarItem.warningBackground" ,
1007
+ ) ;
1008
+ statusBarItem . show ( ) ;
1009
+ return ;
1010
+ }
1011
+
1012
+ if ( agentWatcher . metadata && agentWatcher . metadata . length > 0 ) {
1013
+ statusBarItem . text =
1014
+ "$(dashboard) " + getEventValue ( agentWatcher . metadata [ 0 ] ) ;
1015
+ statusBarItem . tooltip = agentWatcher . metadata
1016
+ . map ( ( metadata ) => formatEventLabel ( metadata ) )
1017
+ . join ( "\n" ) ;
1018
+ statusBarItem . color = undefined ;
1019
+ statusBarItem . backgroundColor = undefined ;
1020
+ statusBarItem . show ( ) ;
1021
+ } else {
1022
+ statusBarItem . hide ( ) ;
1023
+ }
1024
+ } ) ;
1025
+
1026
+ return [ statusBarItem , agentWatcher , onChangeDisposable ] ;
1027
+ }
1028
+
965
1029
// closeRemote ends the current remote session.
966
1030
public async closeRemote ( ) {
967
1031
await vscode . commands . executeCommand ( "workbench.action.remote.close" ) ;
0 commit comments