@redonvn/event-ws-cliproxyapi-sdk 0.2.2 → 1.0.0

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 CHANGED
@@ -256,12 +256,10 @@ import {
256
256
  ```ts
257
257
  import { CliproxyWSProvider } from 'event-ws-cliproxyapi-sdk';
258
258
 
259
- const provider = new CliproxyWSProvider({
260
- baseUrl: 'http://127.0.0.1:8317',
261
- accessKey: 'andev',
262
- managementKey: 'mgmt_xxx',
263
- authViaQuery: false
264
- });
259
+ const provider = new CliproxyWSProvider({
260
+ baseUrl: 'http://127.0.0.1:8317',
261
+ accessKey: 'andev'
262
+ });
265
263
 
266
264
  await provider.connect({
267
265
  onEvent: (ev) => {
@@ -425,13 +423,6 @@ await openai.postChatCompletions({
425
423
 
426
424
  ## Notes
427
425
 
428
- - For WS relay, if `ws-auth: true`, provide `accessKey`.
429
- - SDK handshake sends:
430
- - `Authorization: Bearer <accessKey>` (backward compatible)
431
- - `X-Access-Key: <accessKey>`
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>`
426
+ - For WS relay, if `ws-auth: true`, pass `accessKey` as `Authorization: Bearer ...`.
436
427
  - Management APIs require `managementKey` (or local password for `/keep-alive` if enabled).
437
428
  - HTTP client returns `Response` for streaming endpoints; parse SSE or chunks based on your client.
@@ -7,12 +7,15 @@ export declare class CliproxyWSProvider {
7
7
  private ws?;
8
8
  private options;
9
9
  private handlers?;
10
+ private lastHandlers?;
10
11
  constructor(options: ProviderOptions);
11
12
  connect(handlers: ProviderHandlers): Promise<void>;
12
13
  close(): void;
14
+ reconnect(): Promise<void>;
13
15
  setAccessKey(accessKey?: string): void;
14
16
  setManagementKey(managementKey?: string): void;
15
17
  setCredentials(accessKey?: string, managementKey?: string): void;
18
+ setCredentialsAndReconnect(accessKey?: string, managementKey?: string): Promise<void>;
16
19
  private handleMessage;
17
20
  private handleClose;
18
21
  private emitError;
package/dist/ws/client.js CHANGED
@@ -10,6 +10,7 @@ export class CliproxyWSProvider {
10
10
  // It resolves once the socket is open.
11
11
  connect(handlers) {
12
12
  this.handlers = handlers;
13
+ this.lastHandlers = handlers;
13
14
  if (this.ws && this.ws.readyState === WebSocket.OPEN)
14
15
  return Promise.resolve();
15
16
  const base = this.options.baseUrl.replace(/\/+$/, '');
@@ -57,6 +58,13 @@ export class CliproxyWSProvider {
57
58
  close() {
58
59
  this.ws?.close();
59
60
  }
61
+ async reconnect() {
62
+ this.close();
63
+ if (!this.lastHandlers) {
64
+ throw new Error('wsrelay: reconnect requires handlers (call connect at least once)');
65
+ }
66
+ await this.connect(this.lastHandlers);
67
+ }
60
68
  setAccessKey(accessKey) {
61
69
  this.options.accessKey = accessKey;
62
70
  }
@@ -67,6 +75,10 @@ export class CliproxyWSProvider {
67
75
  this.options.accessKey = accessKey;
68
76
  this.options.managementKey = managementKey;
69
77
  }
78
+ async setCredentialsAndReconnect(accessKey, managementKey) {
79
+ this.setCredentials(accessKey, managementKey);
80
+ await this.reconnect();
81
+ }
70
82
  handleMessage(raw) {
71
83
  let msg;
72
84
  try {
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "@redonvn/event-ws-cliproxyapi-sdk",
3
- "version": "0.2.2",
3
+ "version": "1.0.0",
4
4
  "description": "TypeScript SDK for CLIProxyAPI WebSocket relay (provider-side).",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
- "files": [
10
- "dist"
11
- ],
9
+ "files": ["dist"],
12
10
  "scripts": {
13
11
  "build": "tsc -p tsconfig.json",
14
12
  "dev": "tsc -p tsconfig.json --watch",
@@ -22,4 +20,4 @@
22
20
  "typescript": "^5.7.3",
23
21
  "@types/ws": "^8.5.12"
24
22
  }
25
- }
23
+ }