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" ;
@@ -9,6 +9,12 @@ import * as path from "path";
99import prettyBytes from "pretty-bytes" ;
1010import * as semver from "semver" ;
1111import * as vscode from "vscode" ;
12+ import {
13+ createAgentMetadataWatcher ,
14+ getEventValue ,
15+ formatEventLabel ,
16+ formatMetadataError ,
17+ } from "./agentMetadataHelper" ;
1218import {
1319 createHttpAgent ,
1420 makeCoderSdk ,
@@ -68,6 +74,7 @@ export class Remote {
6874 workspace : Workspace ,
6975 label : string ,
7076 binPath : string ,
77+ featureSet : FeatureSet ,
7178 ) : Promise < Workspace | undefined > {
7279 const workspaceName = `${ workspace . owner_name } /${ workspace . name } ` ;
7380
@@ -136,6 +143,7 @@ export class Remote {
136143 binPath ,
137144 workspace ,
138145 writeEmitter ,
146+ featureSet ,
139147 ) ;
140148 break ;
141149 case "failed" :
@@ -153,6 +161,7 @@ export class Remote {
153161 binPath ,
154162 workspace ,
155163 writeEmitter ,
164+ featureSet ,
156165 ) ;
157166 break ;
158167 }
@@ -383,6 +392,7 @@ export class Remote {
383392 workspace ,
384393 parts . label ,
385394 binaryPath ,
395+ featureSet ,
386396 ) ;
387397 if ( ! updatedWorkspace ) {
388398 // User declined to start the workspace.
@@ -620,6 +630,10 @@ export class Remote {
620630 } ) ,
621631 ) ;
622632
633+ disposables . push (
634+ ...this . createAgentMetadataStatusBar ( agent , workspaceRestClient ) ,
635+ ) ;
636+
623637 this . storage . output . info ( "Remote setup complete" ) ;
624638
625639 // Returning the URL and token allows the plugin to authenticate its own
@@ -962,6 +976,56 @@ export class Remote {
962976 return loop ( ) ;
963977 }
964978
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+
9651029 // closeRemote ends the current remote session.
9661030 public async closeRemote ( ) {
9671031 await vscode . commands . executeCommand ( "workbench.action.remote.close" ) ;
0 commit comments