豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit e0aba70

Browse files
feat(client): add support for path parameters in websockets clients
1 parent 7673137 commit e0aba70

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/resources/responses/internal-base.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff 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

src/resources/responses/ws.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)