@redonvn/event-ws-cliproxyapi-sdk 0.1.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 +428 -0
- package/dist/claude/client.d.ts +8 -0
- package/dist/claude/client.js +16 -0
- package/dist/claude/index.d.ts +2 -0
- package/dist/claude/index.js +1 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +96 -0
- package/dist/cliproxy/client.d.ts +41 -0
- package/dist/cliproxy/client.js +43 -0
- package/dist/cliproxy/index.d.ts +2 -0
- package/dist/cliproxy/index.js +1 -0
- package/dist/codec.d.ts +8 -0
- package/dist/codec.js +79 -0
- package/dist/errors/index.d.ts +13 -0
- package/dist/errors/index.js +26 -0
- package/dist/gemini/client.d.ts +9 -0
- package/dist/gemini/client.js +19 -0
- package/dist/gemini/index.d.ts +2 -0
- package/dist/gemini/index.js +1 -0
- package/dist/http/client.d.ts +260 -0
- package/dist/http/client.js +591 -0
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +2 -0
- package/dist/http/types.d.ts +783 -0
- package/dist/http/types.js +1 -0
- package/dist/http-client.d.ts +259 -0
- package/dist/http-client.js +557 -0
- package/dist/http-types.d.ts +677 -0
- package/dist/http-types.js +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/management/client.d.ts +187 -0
- package/dist/management/client.js +399 -0
- package/dist/management/index.d.ts +2 -0
- package/dist/management/index.js +1 -0
- package/dist/openai/client.d.ts +10 -0
- package/dist/openai/client.js +23 -0
- package/dist/openai/index.d.ts +2 -0
- package/dist/openai/index.js +1 -0
- package/dist/shared/errors.d.ts +13 -0
- package/dist/shared/errors.js +26 -0
- package/dist/shared/http.d.ts +29 -0
- package/dist/shared/http.js +125 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/types.d.ts +789 -0
- package/dist/shared/types.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types.d.ts +101 -0
- package/dist/types.js +1 -0
- package/dist/utils/index.d.ts +0 -0
- package/dist/utils/index.js +2 -0
- package/dist/ws/client.d.ts +20 -0
- package/dist/ws/client.js +114 -0
- package/dist/ws/codec.d.ts +8 -0
- package/dist/ws/codec.js +100 -0
- package/dist/ws/index.d.ts +3 -0
- package/dist/ws/index.js +3 -0
- package/dist/ws/types.d.ts +101 -0
- package/dist/ws/types.js +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export type HTTPHeaders = Record<string, string | string[]>;
|
|
2
|
+
export type WSHeaders = Record<string, string[]>;
|
|
3
|
+
export interface HTTPRequest {
|
|
4
|
+
method: string;
|
|
5
|
+
url: string;
|
|
6
|
+
headers?: WSHeaders;
|
|
7
|
+
body?: string;
|
|
8
|
+
sent_at?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface HTTPResponse {
|
|
11
|
+
status: number;
|
|
12
|
+
headers?: HTTPHeaders;
|
|
13
|
+
body?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface WSHttpRequestPayload {
|
|
16
|
+
method: string;
|
|
17
|
+
url: string;
|
|
18
|
+
headers?: WSHeaders;
|
|
19
|
+
body?: string;
|
|
20
|
+
sent_at?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WSHttpResponsePayload {
|
|
23
|
+
status: number;
|
|
24
|
+
headers?: WSHeaders;
|
|
25
|
+
body?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface WSStreamChunkPayload {
|
|
28
|
+
data: string;
|
|
29
|
+
}
|
|
30
|
+
export interface WSErrorPayload {
|
|
31
|
+
error: string;
|
|
32
|
+
status?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface WSHttpRequestMessage {
|
|
35
|
+
id: string;
|
|
36
|
+
type: 'http_request';
|
|
37
|
+
payload: WSHttpRequestPayload;
|
|
38
|
+
}
|
|
39
|
+
export interface WSHttpResponseMessage {
|
|
40
|
+
id: string;
|
|
41
|
+
type: 'http_response';
|
|
42
|
+
payload: WSHttpResponsePayload;
|
|
43
|
+
}
|
|
44
|
+
export interface WSStreamStartMessage {
|
|
45
|
+
id: string;
|
|
46
|
+
type: 'stream_start';
|
|
47
|
+
payload: WSHttpResponsePayload;
|
|
48
|
+
}
|
|
49
|
+
export interface WSStreamChunkMessage {
|
|
50
|
+
id: string;
|
|
51
|
+
type: 'stream_chunk';
|
|
52
|
+
payload: WSStreamChunkPayload;
|
|
53
|
+
}
|
|
54
|
+
export interface WSStreamEndMessage {
|
|
55
|
+
id: string;
|
|
56
|
+
type: 'stream_end';
|
|
57
|
+
payload?: undefined;
|
|
58
|
+
}
|
|
59
|
+
export interface WSErrorMessage {
|
|
60
|
+
id: string;
|
|
61
|
+
type: 'error';
|
|
62
|
+
payload: WSErrorPayload;
|
|
63
|
+
}
|
|
64
|
+
export interface WSPingMessage {
|
|
65
|
+
id: string;
|
|
66
|
+
type: 'ping';
|
|
67
|
+
payload?: undefined;
|
|
68
|
+
}
|
|
69
|
+
export interface WSPongMessage {
|
|
70
|
+
id: string;
|
|
71
|
+
type: 'pong';
|
|
72
|
+
payload?: undefined;
|
|
73
|
+
}
|
|
74
|
+
export type WSMessage = WSHttpRequestMessage | WSHttpResponseMessage | WSStreamStartMessage | WSStreamChunkMessage | WSStreamEndMessage | WSErrorMessage | WSPingMessage | WSPongMessage;
|
|
75
|
+
export interface ProviderOptions {
|
|
76
|
+
baseUrl: string;
|
|
77
|
+
accessKey?: string;
|
|
78
|
+
}
|
|
79
|
+
export type ProviderEvent = {
|
|
80
|
+
type: 'error';
|
|
81
|
+
requestId?: string;
|
|
82
|
+
error: string;
|
|
83
|
+
} | {
|
|
84
|
+
type: 'ws:open';
|
|
85
|
+
} | {
|
|
86
|
+
type: 'ws:close';
|
|
87
|
+
code?: number;
|
|
88
|
+
reason?: string;
|
|
89
|
+
} | {
|
|
90
|
+
type: 'request';
|
|
91
|
+
requestId: string;
|
|
92
|
+
request: HTTPRequest;
|
|
93
|
+
};
|
|
94
|
+
export interface WSRequestContext {
|
|
95
|
+
requestId: string;
|
|
96
|
+
respond: (resp: HTTPResponse) => void;
|
|
97
|
+
streamStart: (status?: number, headers?: HTTPHeaders) => void;
|
|
98
|
+
streamChunk: (chunk: string) => void;
|
|
99
|
+
streamEnd: () => void;
|
|
100
|
+
error: (message: string, status?: number) => void;
|
|
101
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HTTPRequest, ProviderEvent, ProviderOptions, WSRequestContext } from './types.js';
|
|
2
|
+
export interface ProviderHandlers {
|
|
3
|
+
onRequest: (req: HTTPRequest, ctx: WSRequestContext) => void | Promise<void>;
|
|
4
|
+
onEvent?: (ev: ProviderEvent) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare class CliproxyWSProvider {
|
|
7
|
+
private ws?;
|
|
8
|
+
private options;
|
|
9
|
+
private handlers?;
|
|
10
|
+
constructor(options: ProviderOptions);
|
|
11
|
+
connect(handlers: ProviderHandlers): Promise<void>;
|
|
12
|
+
close(): void;
|
|
13
|
+
private handleMessage;
|
|
14
|
+
private handleClose;
|
|
15
|
+
private emitError;
|
|
16
|
+
private buildContext;
|
|
17
|
+
private sendMessage;
|
|
18
|
+
}
|
|
19
|
+
export declare class CliproxyWSClient extends CliproxyWSProvider {
|
|
20
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { decodeRequest, encodeChunk, encodeError, encodeResponse } from './codec.js';
|
|
3
|
+
// CliproxyWSProvider connects to CLIProxyAPI /v1/ws and handles server->provider requests.
|
|
4
|
+
// The websocket message shapes match CLIProxyAPI internal/wsrelay Message definitions.
|
|
5
|
+
export class CliproxyWSProvider {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
// connect opens the websocket and starts processing incoming requests.
|
|
10
|
+
// It resolves once the socket is open.
|
|
11
|
+
connect(handlers) {
|
|
12
|
+
this.handlers = handlers;
|
|
13
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN)
|
|
14
|
+
return Promise.resolve();
|
|
15
|
+
const base = this.options.baseUrl.replace(/\/+$/, '');
|
|
16
|
+
const url = `${base.replace(/^http/, 'ws')}/v1/ws`;
|
|
17
|
+
const headers = {};
|
|
18
|
+
if (this.options.accessKey)
|
|
19
|
+
headers['Authorization'] = `Bearer ${this.options.accessKey}`;
|
|
20
|
+
this.ws = new WebSocket(url, { headers });
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const ws = this.ws;
|
|
23
|
+
const onOpen = () => {
|
|
24
|
+
this.handlers?.onEvent?.({ type: 'ws:open' });
|
|
25
|
+
resolve();
|
|
26
|
+
};
|
|
27
|
+
const onErr = (err) => {
|
|
28
|
+
this.emitError(err?.message ?? 'wsrelay: connect error');
|
|
29
|
+
reject(err);
|
|
30
|
+
};
|
|
31
|
+
ws.once('open', onOpen);
|
|
32
|
+
ws.once('error', onErr);
|
|
33
|
+
ws.on('message', (raw) => this.handleMessage(raw.toString()));
|
|
34
|
+
ws.on('error', (err) => this.emitError(err?.message ?? 'wsrelay: socket error'));
|
|
35
|
+
ws.on('close', (code, reason) => this.handleClose(code, reason.toString()));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
close() {
|
|
39
|
+
this.ws?.close();
|
|
40
|
+
}
|
|
41
|
+
handleMessage(raw) {
|
|
42
|
+
let msg;
|
|
43
|
+
try {
|
|
44
|
+
msg = JSON.parse(raw);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
this.emitError('wsrelay: invalid message (json parse failed)');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!msg || !msg.id || !msg.type) {
|
|
51
|
+
this.emitError('wsrelay: invalid message (missing id/type)');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (msg.type === 'ping') {
|
|
55
|
+
this.sendMessage('pong', msg.id);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (msg.type !== 'http_request')
|
|
59
|
+
return;
|
|
60
|
+
const req = decodeRequest(msg.payload);
|
|
61
|
+
const ctx = this.buildContext(msg.id);
|
|
62
|
+
this.handlers?.onEvent?.({ type: 'request', requestId: msg.id, request: req });
|
|
63
|
+
try {
|
|
64
|
+
const result = this.handlers?.onRequest(req, ctx);
|
|
65
|
+
if (result && typeof result.then === 'function') {
|
|
66
|
+
result.catch((err) => {
|
|
67
|
+
const message = err?.message ?? 'provider error';
|
|
68
|
+
ctx.error(message);
|
|
69
|
+
this.emitError(message, msg?.id);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
const message = err instanceof Error ? err.message : 'provider error';
|
|
75
|
+
ctx.error(message);
|
|
76
|
+
this.emitError(message, msg?.id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
handleClose(code, reason) {
|
|
80
|
+
this.handlers?.onEvent?.({ type: 'ws:close', code, reason });
|
|
81
|
+
}
|
|
82
|
+
emitError(error, requestId) {
|
|
83
|
+
this.handlers?.onEvent?.({ type: 'error', requestId, error });
|
|
84
|
+
}
|
|
85
|
+
buildContext(requestId) {
|
|
86
|
+
return {
|
|
87
|
+
requestId,
|
|
88
|
+
respond: (resp) => {
|
|
89
|
+
this.sendMessage('http_response', requestId, encodeResponse(resp));
|
|
90
|
+
},
|
|
91
|
+
streamStart: (status, headers) => {
|
|
92
|
+
const payload = encodeResponse({ status: status ?? 200, headers, body: '' });
|
|
93
|
+
this.sendMessage('stream_start', requestId, payload);
|
|
94
|
+
},
|
|
95
|
+
streamChunk: (chunk) => {
|
|
96
|
+
this.sendMessage('stream_chunk', requestId, encodeChunk(chunk));
|
|
97
|
+
},
|
|
98
|
+
streamEnd: () => {
|
|
99
|
+
this.sendMessage('stream_end', requestId);
|
|
100
|
+
},
|
|
101
|
+
error: (message, status) => {
|
|
102
|
+
this.sendMessage('error', requestId, encodeError(message, status));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
sendMessage(type, id, payload) {
|
|
107
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN)
|
|
108
|
+
return;
|
|
109
|
+
const msg = (payload === undefined ? { id, type } : { id, type, payload });
|
|
110
|
+
this.ws.send(JSON.stringify(msg));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export class CliproxyWSClient extends CliproxyWSProvider {
|
|
114
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HTTPRequest, HTTPResponse, WSErrorPayload, WSHttpRequestPayload, WSHttpResponsePayload, WSStreamChunkPayload } from './types.js';
|
|
2
|
+
export declare function decodeRequest(payload?: WSHttpRequestPayload): HTTPRequest;
|
|
3
|
+
export declare function encodeResponse(resp: HTTPResponse): WSHttpResponsePayload;
|
|
4
|
+
export declare function decodeResponse(payload?: WSHttpResponsePayload): HTTPResponse;
|
|
5
|
+
export declare function encodeChunk(chunk: string): WSStreamChunkPayload;
|
|
6
|
+
export declare function decodeChunk(payload?: WSStreamChunkPayload): string;
|
|
7
|
+
export declare function encodeError(message: string, status?: number): WSErrorPayload;
|
|
8
|
+
export declare function decodeError(payload?: WSErrorPayload): string;
|
package/dist/ws/codec.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Decode a server->provider request payload into an HTTPRequest.
|
|
2
|
+
// Mirrors CLIProxyAPI wsrelay encodeRequest behavior.
|
|
3
|
+
export function decodeRequest(payload) {
|
|
4
|
+
const method = typeof payload?.method === 'string' ? payload.method : 'GET';
|
|
5
|
+
const url = typeof payload?.url === 'string' ? payload.url : '';
|
|
6
|
+
const rawHeaders = payload?.headers;
|
|
7
|
+
const headers = {};
|
|
8
|
+
if (rawHeaders) {
|
|
9
|
+
for (const [key, raw] of Object.entries(rawHeaders)) {
|
|
10
|
+
if (Array.isArray(raw)) {
|
|
11
|
+
headers[key] = raw.map(String);
|
|
12
|
+
}
|
|
13
|
+
else if (typeof raw === 'string') {
|
|
14
|
+
headers[key] = [raw];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const body = typeof payload?.body === 'string' ? payload.body : '';
|
|
19
|
+
const sent_at = typeof payload?.sent_at === 'string' ? payload.sent_at : undefined;
|
|
20
|
+
return { method, url, headers, body, sent_at };
|
|
21
|
+
}
|
|
22
|
+
// Encode a provider response into the wsrelay HTTP response payload.
|
|
23
|
+
export function encodeResponse(resp) {
|
|
24
|
+
const headers = {};
|
|
25
|
+
if (resp.headers) {
|
|
26
|
+
for (const [key, value] of Object.entries(resp.headers)) {
|
|
27
|
+
if (Array.isArray(value))
|
|
28
|
+
headers[key] = value.map(String);
|
|
29
|
+
else
|
|
30
|
+
headers[key] = [String(value)];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
status: resp.status ?? 200,
|
|
35
|
+
headers,
|
|
36
|
+
body: resp.body ?? ''
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Decode a wsrelay HTTP response payload into HTTPResponse.
|
|
40
|
+
// CLIProxyAPI defaults to 502 when payload is missing.
|
|
41
|
+
export function decodeResponse(payload) {
|
|
42
|
+
let status;
|
|
43
|
+
if (!payload) {
|
|
44
|
+
status = 502;
|
|
45
|
+
}
|
|
46
|
+
else if (typeof payload.status === 'number') {
|
|
47
|
+
status = payload.status;
|
|
48
|
+
}
|
|
49
|
+
else if (typeof payload.status === 'string') {
|
|
50
|
+
const parsed = Number(payload.status);
|
|
51
|
+
status = Number.isFinite(parsed) ? parsed : 200;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
status = 200;
|
|
55
|
+
}
|
|
56
|
+
const headers = {};
|
|
57
|
+
const rawHeaders = payload?.headers;
|
|
58
|
+
if (rawHeaders) {
|
|
59
|
+
for (const [key, raw] of Object.entries(rawHeaders)) {
|
|
60
|
+
if (Array.isArray(raw)) {
|
|
61
|
+
headers[key] = raw.map(String);
|
|
62
|
+
}
|
|
63
|
+
else if (typeof raw === 'string') {
|
|
64
|
+
headers[key] = raw;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const body = typeof payload?.body === 'string' ? payload.body : '';
|
|
69
|
+
return { status, headers, body };
|
|
70
|
+
}
|
|
71
|
+
// Encode a streaming chunk message payload.
|
|
72
|
+
export function encodeChunk(chunk) {
|
|
73
|
+
return { data: chunk ?? '' };
|
|
74
|
+
}
|
|
75
|
+
// Decode a streaming chunk message payload.
|
|
76
|
+
export function decodeChunk(payload) {
|
|
77
|
+
const data = payload?.data;
|
|
78
|
+
return typeof data === 'string' ? data : '';
|
|
79
|
+
}
|
|
80
|
+
// Encode an error payload. Status is optional but preferred when known.
|
|
81
|
+
export function encodeError(message, status) {
|
|
82
|
+
const payload = { error: message || 'wsrelay: upstream error' };
|
|
83
|
+
if (typeof status === 'number' && !Number.isNaN(status)) {
|
|
84
|
+
payload.status = status;
|
|
85
|
+
}
|
|
86
|
+
return payload;
|
|
87
|
+
}
|
|
88
|
+
// Decode an error payload into a human-readable message.
|
|
89
|
+
// CLIProxyAPI always formats as "message (status=...)".
|
|
90
|
+
export function decodeError(payload) {
|
|
91
|
+
if (!payload)
|
|
92
|
+
return 'wsrelay: unknown error';
|
|
93
|
+
const message = typeof payload.error === 'string' ? payload.error : 'wsrelay: upstream error';
|
|
94
|
+
const status = typeof payload.status === 'number'
|
|
95
|
+
? payload.status
|
|
96
|
+
: typeof payload.status === 'string'
|
|
97
|
+
? Number(payload.status)
|
|
98
|
+
: 0;
|
|
99
|
+
return `${message} (status=${Number.isFinite(status) ? status : 0})`;
|
|
100
|
+
}
|
package/dist/ws/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export type HTTPHeaders = Record<string, string | string[]>;
|
|
2
|
+
export type WSHeaders = Record<string, string[]>;
|
|
3
|
+
export interface HTTPRequest {
|
|
4
|
+
method: string;
|
|
5
|
+
url: string;
|
|
6
|
+
headers?: WSHeaders;
|
|
7
|
+
body?: string;
|
|
8
|
+
sent_at?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface HTTPResponse {
|
|
11
|
+
status: number;
|
|
12
|
+
headers?: HTTPHeaders;
|
|
13
|
+
body?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface WSHttpRequestPayload {
|
|
16
|
+
method: string;
|
|
17
|
+
url: string;
|
|
18
|
+
headers?: WSHeaders;
|
|
19
|
+
body?: string;
|
|
20
|
+
sent_at?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WSHttpResponsePayload {
|
|
23
|
+
status: number;
|
|
24
|
+
headers?: WSHeaders;
|
|
25
|
+
body?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface WSStreamChunkPayload {
|
|
28
|
+
data: string;
|
|
29
|
+
}
|
|
30
|
+
export interface WSErrorPayload {
|
|
31
|
+
error: string;
|
|
32
|
+
status?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface WSHttpRequestMessage {
|
|
35
|
+
id: string;
|
|
36
|
+
type: 'http_request';
|
|
37
|
+
payload: WSHttpRequestPayload;
|
|
38
|
+
}
|
|
39
|
+
export interface WSHttpResponseMessage {
|
|
40
|
+
id: string;
|
|
41
|
+
type: 'http_response';
|
|
42
|
+
payload: WSHttpResponsePayload;
|
|
43
|
+
}
|
|
44
|
+
export interface WSStreamStartMessage {
|
|
45
|
+
id: string;
|
|
46
|
+
type: 'stream_start';
|
|
47
|
+
payload: WSHttpResponsePayload;
|
|
48
|
+
}
|
|
49
|
+
export interface WSStreamChunkMessage {
|
|
50
|
+
id: string;
|
|
51
|
+
type: 'stream_chunk';
|
|
52
|
+
payload: WSStreamChunkPayload;
|
|
53
|
+
}
|
|
54
|
+
export interface WSStreamEndMessage {
|
|
55
|
+
id: string;
|
|
56
|
+
type: 'stream_end';
|
|
57
|
+
payload?: undefined;
|
|
58
|
+
}
|
|
59
|
+
export interface WSErrorMessage {
|
|
60
|
+
id: string;
|
|
61
|
+
type: 'error';
|
|
62
|
+
payload: WSErrorPayload;
|
|
63
|
+
}
|
|
64
|
+
export interface WSPingMessage {
|
|
65
|
+
id: string;
|
|
66
|
+
type: 'ping';
|
|
67
|
+
payload?: undefined;
|
|
68
|
+
}
|
|
69
|
+
export interface WSPongMessage {
|
|
70
|
+
id: string;
|
|
71
|
+
type: 'pong';
|
|
72
|
+
payload?: undefined;
|
|
73
|
+
}
|
|
74
|
+
export type WSMessage = WSHttpRequestMessage | WSHttpResponseMessage | WSStreamStartMessage | WSStreamChunkMessage | WSStreamEndMessage | WSErrorMessage | WSPingMessage | WSPongMessage;
|
|
75
|
+
export interface ProviderOptions {
|
|
76
|
+
baseUrl: string;
|
|
77
|
+
accessKey?: string;
|
|
78
|
+
}
|
|
79
|
+
export type ProviderEvent = {
|
|
80
|
+
type: 'error';
|
|
81
|
+
requestId?: string;
|
|
82
|
+
error: string;
|
|
83
|
+
} | {
|
|
84
|
+
type: 'ws:open';
|
|
85
|
+
} | {
|
|
86
|
+
type: 'ws:close';
|
|
87
|
+
code?: number;
|
|
88
|
+
reason?: string;
|
|
89
|
+
} | {
|
|
90
|
+
type: 'request';
|
|
91
|
+
requestId: string;
|
|
92
|
+
request: HTTPRequest;
|
|
93
|
+
};
|
|
94
|
+
export interface WSRequestContext {
|
|
95
|
+
requestId: string;
|
|
96
|
+
respond: (resp: HTTPResponse) => void;
|
|
97
|
+
streamStart: (status?: number, headers?: HTTPHeaders) => void;
|
|
98
|
+
streamChunk: (chunk: string) => void;
|
|
99
|
+
streamEnd: () => void;
|
|
100
|
+
error: (message: string, status?: number) => void;
|
|
101
|
+
}
|
package/dist/ws/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@redonvn/event-ws-cliproxyapi-sdk",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public",
|
|
5
|
+
"registry": "https://registry.npmjs.org/"
|
|
6
|
+
},
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"description": "TypeScript SDK for CLIProxyAPI WebSocket relay (provider-side).",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
19
|
+
"example": "node examples/run.js"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"ws": "^8.18.0",
|
|
23
|
+
"uuid": "^11.0.3"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.7.3",
|
|
27
|
+
"@types/ws": "^8.5.12"
|
|
28
|
+
}
|
|
29
|
+
}
|