@@ -67,7 +67,7 @@ export class CoderApi extends Api {
6767return client ;
6868}
6969
70- watchInboxNotifications = (
70+ watchInboxNotifications = async (
7171watchTemplates :string [ ] ,
7272watchTargets :string [ ] ,
7373options ?: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 ) => {
8787return this . createWebSocket < ServerSentEvent > ( {
8888apiRoute :`/api/v2/workspaces/${ workspace . id } /watch-ws` ,
8989options,
9090} ) ;
9191} ;
9292
93- watchAgentMetadata = (
93+ watchAgentMetadata = async (
9494agentId :WorkspaceAgent [ "id" ] ,
9595options ?: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+ ) => {
104107const searchParams = new URLSearchParams ( { follow :"true" } ) ;
105108if ( logs . length ) {
106109searchParams . append ( "after" , logs [ logs . length - 1 ] . id . toString ( ) ) ;
107110}
108111
109- const socket = this . createWebSocket < ProvisionerJobLog > ( {
112+ return this . createWebSocket < ProvisionerJobLog > ( {
110113apiRoute :`/api/v2/workspacebuilds/${ buildId } /logs` ,
111114searchParams,
112115} ) ;
113-
114- return socket ;
115116} ;
116117
117- private createWebSocket < TData = unknown > (
118+ private async createWebSocket < TData = unknown > (
118119configs :Omit < OneWayWebSocketInit , "location" > ,
119120) {
120121const baseUrlRaw = this . getAxiosInstance ( ) . defaults . baseURL ;
@@ -127,7 +128,15 @@ export class CoderApi extends Api {
127128coderSessionTokenHeader
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+ ) ;
131140const webSocket = new OneWayWebSocket < TData > ( {
132141location :baseUrl ,
133142...configs ,
@@ -137,6 +146,7 @@ export class CoderApi extends Api {
137146headers :{
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 ( ) ) ;
195205config . httpsAgent = agent ;
196206config . httpAgent = agent ;
197207config . proxy = false ;