@@ -110,36 +110,42 @@ export class CoderApi extends Api {
110110 logs : ProvisionerJobLog [ ] ,
111111 options ?: ClientOptions ,
112112 ) => {
113- const searchParams = new URLSearchParams ( { follow : "true" } ) ;
114- const lastLog = logs . at ( - 1 ) ;
115- if ( lastLog ) {
116- searchParams . append ( "after" , lastLog . id . toString ( ) ) ;
117- }
118-
119- return this . createWebSocket < ProvisionerJobLog > ( {
120- apiRoute : `/api/v2/workspacebuilds/${ buildId } /logs` ,
121- searchParams,
113+ return this . watchLogs < ProvisionerJobLog > (
114+ `/api/v2/workspacebuilds/${ buildId } /logs` ,
115+ logs ,
122116 options ,
123- } ) ;
117+ ) ;
124118 } ;
125119
126120 watchWorkspaceAgentLogs = async (
127121 agentId : string ,
128122 logs : WorkspaceAgentLog [ ] ,
129123 options ?: ClientOptions ,
130124 ) => {
125+ return this . watchLogs < WorkspaceAgentLog [ ] > (
126+ `/api/v2/workspaceagents/${ agentId } /logs` ,
127+ logs ,
128+ options ,
129+ ) ;
130+ } ;
131+
132+ private async watchLogs < TData > (
133+ apiRoute : string ,
134+ logs : { id : number } [ ] ,
135+ options ?: ClientOptions ,
136+ ) {
131137 const searchParams = new URLSearchParams ( { follow : "true" } ) ;
132138 const lastLog = logs . at ( - 1 ) ;
133139 if ( lastLog ) {
134140 searchParams . append ( "after" , lastLog . id . toString ( ) ) ;
135141 }
136142
137- return this . createWebSocket < WorkspaceAgentLog [ ] > ( {
138- apiRoute : `/api/v2/workspaceagents/ ${ agentId } /logs` ,
143+ return this . createWebSocket < TData > ( {
144+ apiRoute,
139145 searchParams,
140146 options,
141147 } ) ;
142- } ;
148+ }
143149
144150 private async createWebSocket < TData = unknown > (
145151 configs : Omit < OneWayWebSocketInit , "location" > ,
0 commit comments