File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -84,14 +84,24 @@ export abstract class ResponsesEmitter extends EventEmitter<WebSocketEvents> {
8484 }
8585}
8686
87- export function buildURL ( client : OpenAI , query ?: object | null ) : URL {
88- const path = '/responses' ;
87+ export function buildURL ( client : OpenAI , parameters : Record < string , unknown > ) : URL {
88+ const { ...query } = parameters ;
89+ const endpoint = '/responses' ;
8990 const baseURL = client . baseURL ;
90- const url = new URL ( baseURL + ( baseURL . endsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
91- if ( query ) {
91+ const url = new URL ( baseURL ) ;
92+ url . pathname +=
93+ url . pathname . endsWith ( '/' ) ?
94+ endpoint . startsWith ( '/' ) ?
95+ endpoint . slice ( 1 )
96+ : endpoint
97+ : endpoint . startsWith ( '/' ) ? endpoint
98+ : `/${ endpoint } ` ;
99+ if ( url . search ) {
100+ url . search += `&${ stringifyQuery ( query ) } ` ;
101+ } else {
92102 url . search = stringifyQuery ( query ) ;
93103 }
94- url . protocol = url . protocol === 'http:' ? 'ws:' : 'wss:' ;
104+ url . protocol = url . protocol === 'http:' || url . protocol === 'ws:' ? 'ws:' : 'wss:' ;
95105 return url ;
96106}
97107
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ export class ResponsesWS extends ResponsesEmitter {
4747 socket : WS . WebSocket ;
4848
4949 private _client : OpenAI ;
50- private _parameters : Record < string , unknown > | undefined ;
50+ private _parameters : Record < string , unknown > | null | undefined ;
5151 private _wsOptions : WS . ClientOptions | null | undefined ;
5252 private _reconnectOptions : ResponsesWSReconnectOptions | null ;
5353 private _sendQueue : string [ ] = [ ] ;
@@ -265,7 +265,7 @@ export class ResponsesWS extends ResponsesEmitter {
265265 }
266266
267267 private _connect ( ) : WS . WebSocket {
268- this . url = buildURL ( this . _client , this . _parameters ) ;
268+ this . url = buildURL ( this . _client , { } ) ;
269269
270270 const socket = new WS . WebSocket ( this . url , {
271271 ...this . _wsOptions ,
You can’t perform that action at this time.
0 commit comments