@redonvn/event-ws-cliproxyapi-sdk 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/ws/client.d.ts +3 -0
- package/dist/ws/client.js +25 -1
- package/dist/ws/types.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -259,7 +259,8 @@ import { CliproxyWSProvider } from 'event-ws-cliproxyapi-sdk';
|
|
|
259
259
|
const provider = new CliproxyWSProvider({
|
|
260
260
|
baseUrl: 'http://127.0.0.1:8317',
|
|
261
261
|
accessKey: 'andev',
|
|
262
|
-
managementKey: 'mgmt_xxx'
|
|
262
|
+
managementKey: 'mgmt_xxx',
|
|
263
|
+
authViaQuery: false
|
|
263
264
|
});
|
|
264
265
|
|
|
265
266
|
await provider.connect({
|
|
@@ -429,5 +430,8 @@ await openai.postChatCompletions({
|
|
|
429
430
|
- `Authorization: Bearer <accessKey>` (backward compatible)
|
|
430
431
|
- `X-Access-Key: <accessKey>`
|
|
431
432
|
- `X-Management-Key: <managementKey>` (if provided)
|
|
433
|
+
- Optional query fallback (`authViaQuery: true`):
|
|
434
|
+
- `key=<accessKey>` + `auth_token=<accessKey>`
|
|
435
|
+
- `management_key=<managementKey>` + `mgmt_key=<managementKey>`
|
|
432
436
|
- Management APIs require `managementKey` (or local password for `/keep-alive` if enabled).
|
|
433
437
|
- HTTP client returns `Response` for streaming endpoints; parse SSE or chunks based on your client.
|
package/dist/ws/client.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export declare class CliproxyWSProvider {
|
|
|
10
10
|
constructor(options: ProviderOptions);
|
|
11
11
|
connect(handlers: ProviderHandlers): Promise<void>;
|
|
12
12
|
close(): void;
|
|
13
|
+
setAccessKey(accessKey?: string): void;
|
|
14
|
+
setManagementKey(managementKey?: string): void;
|
|
15
|
+
setCredentials(accessKey?: string, managementKey?: string): void;
|
|
13
16
|
private handleMessage;
|
|
14
17
|
private handleClose;
|
|
15
18
|
private emitError;
|
package/dist/ws/client.js
CHANGED
|
@@ -13,7 +13,21 @@ export class CliproxyWSProvider {
|
|
|
13
13
|
if (this.ws && this.ws.readyState === WebSocket.OPEN)
|
|
14
14
|
return Promise.resolve();
|
|
15
15
|
const base = this.options.baseUrl.replace(/\/+$/, '');
|
|
16
|
-
const
|
|
16
|
+
const wsPath = (this.options.wsPath || '/v1/ws').startsWith('/')
|
|
17
|
+
? (this.options.wsPath || '/v1/ws')
|
|
18
|
+
: `/${this.options.wsPath || '/v1/ws'}`;
|
|
19
|
+
const urlObj = new URL(`${base.replace(/^http/, 'ws')}${wsPath}`);
|
|
20
|
+
if (this.options.authViaQuery) {
|
|
21
|
+
if (this.options.accessKey) {
|
|
22
|
+
urlObj.searchParams.set('key', this.options.accessKey);
|
|
23
|
+
urlObj.searchParams.set('auth_token', this.options.accessKey);
|
|
24
|
+
}
|
|
25
|
+
if (this.options.managementKey) {
|
|
26
|
+
urlObj.searchParams.set('management_key', this.options.managementKey);
|
|
27
|
+
urlObj.searchParams.set('mgmt_key', this.options.managementKey);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const url = urlObj.toString();
|
|
17
31
|
const headers = {};
|
|
18
32
|
if (this.options.accessKey) {
|
|
19
33
|
headers['Authorization'] = `Bearer ${this.options.accessKey}`;
|
|
@@ -43,6 +57,16 @@ export class CliproxyWSProvider {
|
|
|
43
57
|
close() {
|
|
44
58
|
this.ws?.close();
|
|
45
59
|
}
|
|
60
|
+
setAccessKey(accessKey) {
|
|
61
|
+
this.options.accessKey = accessKey;
|
|
62
|
+
}
|
|
63
|
+
setManagementKey(managementKey) {
|
|
64
|
+
this.options.managementKey = managementKey;
|
|
65
|
+
}
|
|
66
|
+
setCredentials(accessKey, managementKey) {
|
|
67
|
+
this.options.accessKey = accessKey;
|
|
68
|
+
this.options.managementKey = managementKey;
|
|
69
|
+
}
|
|
46
70
|
handleMessage(raw) {
|
|
47
71
|
let msg;
|
|
48
72
|
try {
|
package/dist/ws/types.d.ts
CHANGED