@@ -67,7 +67,7 @@ export class CoderApi extends Api {
6767 return client ;
6868 }
6969
70- watchInboxNotifications = (
70+ watchInboxNotifications = async (
7171 watchTemplates : string [ ] ,
7272 watchTargets : string [ ] ,
7373 options ?: ClientOptions ,
@@ -83,14 +83,14 @@ export class CoderApi extends Api {
8383 } ) ;
8484 } ;
8585
86- watchWorkspace = ( workspace : Workspace , options ?: ClientOptions ) => {
86+ watchWorkspace = async ( workspace : Workspace , options ?: ClientOptions ) => {
8787 return this . createWebSocket < ServerSentEvent > ( {
8888 apiRoute : `/api/v2/workspaces/${ workspace . id } /watch-ws` ,
8989 options,
9090 } ) ;
9191 } ;
9292
93- watchAgentMetadata = (
93+ watchAgentMetadata = async (
9494 agentId : WorkspaceAgent [ "id" ] ,
9595 options ?: ClientOptions ,
9696 ) => {
@@ -100,21 +100,22 @@ export class CoderApi extends Api {
100100 } ) ;
101101 } ;
102102
103- watchBuildLogsByBuildId = ( buildId : string , logs : ProvisionerJobLog [ ] ) => {
103+ watchBuildLogsByBuildId = async (
104+ buildId : string ,
105+ logs : ProvisionerJobLog [ ] ,
106+ ) => {
104107 const searchParams = new URLSearchParams ( { follow : "true" } ) ;
105108 if ( logs . length ) {
106109 searchParams . append ( "after" , logs [ logs . length - 1 ] . id . toString ( ) ) ;
107110 }
108111
109- const socket = this . createWebSocket < ProvisionerJobLog > ( {
112+ return this . createWebSocket < ProvisionerJobLog > ( {
110113 apiRoute : `/api/v2/workspacebuilds/${ buildId } /logs` ,
111114 searchParams,
112115 } ) ;
113-
114- return socket ;
115116 } ;
116117
117- private createWebSocket < TData = unknown > (
118+ private async createWebSocket < TData = unknown > (
118119 configs : Omit < OneWayWebSocketInit , "location" > ,
119120 ) {
120121 const baseUrlRaw = this . getAxiosInstance ( ) . defaults . baseURL ;
@@ -127,7 +128,15 @@ export class CoderApi extends Api {
127128 coderSessionTokenHeader
128129 ] as string | undefined ;
129130
130- const httpAgent = createHttpAgent ( vscode . workspace . getConfiguration ( ) ) ;
131+ const headers = await getHeaders (
132+ baseUrlRaw ,
133+ getHeaderCommand ( vscode . workspace . getConfiguration ( ) ) ,
134+ this . output ,
135+ ) ;
136+
137+ const httpAgent = await createHttpAgent (
138+ vscode . workspace . getConfiguration ( ) ,
139+ ) ;
131140 const webSocket = new OneWayWebSocket < TData > ( {
132141 location : baseUrl ,
133142 ...configs ,
@@ -137,6 +146,7 @@ export class CoderApi extends Api {
137146 headers : {
138147 ...( token ? { [ coderSessionTokenHeader ] : token } : { } ) ,
139148 ...configs . options ?. headers ,
149+ ...headers ,
140150 } ,
141151 ...configs . options ,
142152 } ,
@@ -191,7 +201,7 @@ function setupInterceptors(
191201 // Configure proxy and TLS.
192202 // Note that by default VS Code overrides the agent. To prevent this, set
193203 // `http.proxySupport` to `on` or `off`.
194- const agent = createHttpAgent ( vscode . workspace . getConfiguration ( ) ) ;
204+ const agent = await createHttpAgent ( vscode . workspace . getConfiguration ( ) ) ;
195205 config . httpsAgent = agent ;
196206 config . httpAgent = agent ;
197207 config . proxy = false ;
0 commit comments