@redonvn/event-ws-cliproxyapi-sdk 1.0.0 → 1.0.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/dist/management/client.d.ts +3 -1
- package/dist/management/client.js +21 -0
- package/dist/management/index.d.ts +1 -1
- package/dist/shared/types.d.ts +14 -0
- package/dist/ws/client.d.ts +0 -6
- package/dist/ws/client.js +2 -43
- package/dist/ws/types.d.ts +0 -3
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { AmpModelMapping, AmpModelMappingsPatch, AmpUpstreamAPIKeyEntry, AmpUpstreamAPIKeysPatch, ApiCallRequest, ApiCallResponse, AuthFileDeleteResponse, AuthFileListQuery, AuthFileListResponse, AuthFileModelsQuery, AuthFileModelsResponse, AuthFileStatusRequest, AuthFileStatusResponse, AuthStatusResponse, ClaudeKey, ClaudeKeyPatch, CodexKey, CodexKeyPatch, Config, DeleteLogsResponse, ErrorLogFilesResponse, GeminiKey, GeminiKeyPatch, KeyedValueResponse, LogLinesResponse, OAuthCallbackRequest, OAuthCallbackResponse, OAuthExcludedModelsPatch, OAuthModelAlias, OAuthModelAliasPatch, OAuthStartResponse, OpenAICompatibility, OpenAICompatPatch, PatchByIndexOrMatch, PatchStringListRequest, UsageExportResponse, UsageGetResponse, UsageImportRequest, UsageImportResponse, VertexCompatKey, VertexCompatPatch } from '../shared/types.js';
|
|
1
|
+
import type { AmpModelMapping, AmpModelMappingsPatch, AmpUpstreamAPIKeyEntry, AmpUpstreamAPIKeysPatch, ApiCallRequest, ApiCallResponse, AuthFileDeleteResponse, AuthFileListQuery, AuthFileListResponse, AuthFileModelsQuery, AuthFileModelsResponse, AuthFileStatusRequest, AuthFileStatusResponse, AuthStatusResponse, DesktopKeysResponse, ManagementApiKeysResponse, ClaudeKey, ClaudeKeyPatch, CodexKey, CodexKeyPatch, Config, DeleteLogsResponse, ErrorLogFilesResponse, GeminiKey, GeminiKeyPatch, KeyedValueResponse, LogLinesResponse, OAuthCallbackRequest, OAuthCallbackResponse, OAuthExcludedModelsPatch, OAuthModelAlias, OAuthModelAliasPatch, OAuthStartResponse, OpenAICompatibility, OpenAICompatPatch, PatchByIndexOrMatch, PatchStringListRequest, UsageExportResponse, UsageGetResponse, UsageImportRequest, UsageImportResponse, VertexCompatKey, VertexCompatPatch } from '../shared/types.js';
|
|
2
2
|
import { BaseHttpClient } from '../shared/http.js';
|
|
3
3
|
export declare class ManagementClient extends BaseHttpClient {
|
|
4
|
+
getDesktopKeys(): Promise<DesktopKeysResponse>;
|
|
5
|
+
getManagementApiKeys(): Promise<ManagementApiKeysResponse>;
|
|
4
6
|
getUsage(): Promise<UsageGetResponse>;
|
|
5
7
|
exportUsage(): Promise<UsageExportResponse>;
|
|
6
8
|
importUsage(body: UsageImportRequest): Promise<UsageImportResponse>;
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { BaseHttpClient } from '../shared/http.js';
|
|
2
2
|
export class ManagementClient extends BaseHttpClient {
|
|
3
|
+
getDesktopKeys() {
|
|
4
|
+
return this.requestJson('GET', '/desktop/keys');
|
|
5
|
+
}
|
|
6
|
+
async getManagementApiKeys() {
|
|
7
|
+
try {
|
|
8
|
+
const data = await this.getDesktopKeys();
|
|
9
|
+
return {
|
|
10
|
+
'api-keys': Array.isArray(data?.apiKeys) ? data.apiKeys : [],
|
|
11
|
+
'management-key': data?.managementKey ?? this.managementKey ?? '',
|
|
12
|
+
'base-url': data?.baseUrl,
|
|
13
|
+
'bridge-url': data?.bridgeUrl,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
const data = await this.getApiKeys();
|
|
18
|
+
return {
|
|
19
|
+
'api-keys': Array.isArray(data?.['api-keys']) ? data['api-keys'] : [],
|
|
20
|
+
'management-key': this.managementKey ?? '',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
3
24
|
getUsage() {
|
|
4
25
|
return this.requestJson('GET', '/v0/management/usage', undefined, undefined, 'management');
|
|
5
26
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ManagementClient } from './client.js';
|
|
2
|
-
export type { SDKConfig, StreamingConfig, AccessConfig, AccessProvider, TLSConfig, PprofConfig, RemoteManagementConfig, QuotaExceededConfig, RoutingConfig, OAuthModelAlias, AmpModelMapping, AmpUpstreamAPIKeyEntry, AmpCodeConfig, PayloadConfig, PayloadFilterRule, PayloadRule, PayloadModelRule, CloakConfig, ClaudeModel, ClaudeKey, CodexModel, CodexKey, GeminiModel, GeminiKey, OpenAICompatibilityAPIKey, OpenAICompatibilityModel, OpenAICompatibility, VertexCompatModel, VertexCompatKey, Config, UsageTokenStats, UsageRequestDetail, UsageModelSnapshot, UsageApiSnapshot, UsageStatisticsSnapshot, UsageGetResponse, UsageExportResponse, UsageImportRequest, UsageImportResponse, ApiCallRequest, ApiCallResponse, ErrorResponse, StatusResponse, LogLinesResponse, DeleteLogsResponse, ErrorLogFileInfo, ErrorLogFilesResponse, AuthFileEntry, AuthFileListResponse, AuthFileModelsResponse, AuthFileUploadResponse, AuthFileDeleteResponse, AuthFileStatusRequest, AuthFileStatusResponse, OAuthCallbackRequest, OAuthCallbackResponse, OAuthStartResponse, AuthStatusResponse, AuthFileDownloadRequest, AuthFileListQuery, AuthFileModelsQuery, PatchStringListRequest, PatchByIndexOrMatch, GeminiKeyPatch, ClaudeKeyPatch, CodexKeyPatch, OpenAICompatPatch, VertexCompatPatch, OAuthExcludedModelsPatch, OAuthModelAliasPatch, AmpModelMappingsPatch, AmpUpstreamAPIKeysPatch, AmpStringListPatch, AuthFileUploadRequest, VertexImportRequest, RootResponse, KeepAliveResponse, ModelThinkingSupport, ModelInfo, ModelListResponse } from '../shared/types.js';
|
|
2
|
+
export type { SDKConfig, StreamingConfig, AccessConfig, AccessProvider, TLSConfig, PprofConfig, RemoteManagementConfig, QuotaExceededConfig, RoutingConfig, OAuthModelAlias, AmpModelMapping, AmpUpstreamAPIKeyEntry, AmpCodeConfig, PayloadConfig, PayloadFilterRule, PayloadRule, PayloadModelRule, CloakConfig, ClaudeModel, ClaudeKey, CodexModel, CodexKey, GeminiModel, GeminiKey, OpenAICompatibilityAPIKey, OpenAICompatibilityModel, OpenAICompatibility, VertexCompatModel, VertexCompatKey, Config, UsageTokenStats, UsageRequestDetail, UsageModelSnapshot, UsageApiSnapshot, UsageStatisticsSnapshot, UsageGetResponse, UsageExportResponse, UsageImportRequest, UsageImportResponse, ApiCallRequest, ApiCallResponse, ErrorResponse, StatusResponse, LogLinesResponse, DeleteLogsResponse, ErrorLogFileInfo, ErrorLogFilesResponse, AuthFileEntry, AuthFileListResponse, AuthFileModelsResponse, AuthFileUploadResponse, AuthFileDeleteResponse, AuthFileStatusRequest, AuthFileStatusResponse, OAuthCallbackRequest, OAuthCallbackResponse, OAuthStartResponse, AuthStatusResponse, AuthFileDownloadRequest, AuthFileListQuery, AuthFileModelsQuery, PatchStringListRequest, PatchByIndexOrMatch, GeminiKeyPatch, ClaudeKeyPatch, CodexKeyPatch, OpenAICompatPatch, VertexCompatPatch, OAuthExcludedModelsPatch, OAuthModelAliasPatch, AmpModelMappingsPatch, AmpUpstreamAPIKeysPatch, AmpStringListPatch, AuthFileUploadRequest, VertexImportRequest, RootResponse, KeepAliveResponse, DesktopKeysResponse, ManagementApiKeysResponse, ModelThinkingSupport, ModelInfo, ModelListResponse } from '../shared/types.js';
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -22,6 +22,20 @@ export interface RootResponse {
|
|
|
22
22
|
export interface KeepAliveResponse {
|
|
23
23
|
status: 'ok';
|
|
24
24
|
}
|
|
25
|
+
export interface DesktopKeysResponse {
|
|
26
|
+
configPath: string;
|
|
27
|
+
backendPath: string;
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
bridgeUrl: string;
|
|
30
|
+
apiKeys: string[];
|
|
31
|
+
managementKey: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ManagementApiKeysResponse {
|
|
34
|
+
'api-keys': string[];
|
|
35
|
+
'management-key': string;
|
|
36
|
+
'base-url'?: string;
|
|
37
|
+
'bridge-url'?: string;
|
|
38
|
+
}
|
|
25
39
|
export interface ModelThinkingSupport {
|
|
26
40
|
min?: number;
|
|
27
41
|
max?: number;
|
package/dist/ws/client.d.ts
CHANGED
|
@@ -7,15 +7,9 @@ export declare class CliproxyWSProvider {
|
|
|
7
7
|
private ws?;
|
|
8
8
|
private options;
|
|
9
9
|
private handlers?;
|
|
10
|
-
private lastHandlers?;
|
|
11
10
|
constructor(options: ProviderOptions);
|
|
12
11
|
connect(handlers: ProviderHandlers): Promise<void>;
|
|
13
12
|
close(): void;
|
|
14
|
-
reconnect(): Promise<void>;
|
|
15
|
-
setAccessKey(accessKey?: string): void;
|
|
16
|
-
setManagementKey(managementKey?: string): void;
|
|
17
|
-
setCredentials(accessKey?: string, managementKey?: string): void;
|
|
18
|
-
setCredentialsAndReconnect(accessKey?: string, managementKey?: string): Promise<void>;
|
|
19
13
|
private handleMessage;
|
|
20
14
|
private handleClose;
|
|
21
15
|
private emitError;
|
package/dist/ws/client.js
CHANGED
|
@@ -10,33 +10,13 @@ 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;
|
|
14
13
|
if (this.ws && this.ws.readyState === WebSocket.OPEN)
|
|
15
14
|
return Promise.resolve();
|
|
16
15
|
const base = this.options.baseUrl.replace(/\/+$/, '');
|
|
17
|
-
const
|
|
18
|
-
? (this.options.wsPath || '/v1/ws')
|
|
19
|
-
: `/${this.options.wsPath || '/v1/ws'}`;
|
|
20
|
-
const urlObj = new URL(`${base.replace(/^http/, 'ws')}${wsPath}`);
|
|
21
|
-
if (this.options.authViaQuery) {
|
|
22
|
-
if (this.options.accessKey) {
|
|
23
|
-
urlObj.searchParams.set('key', this.options.accessKey);
|
|
24
|
-
urlObj.searchParams.set('auth_token', this.options.accessKey);
|
|
25
|
-
}
|
|
26
|
-
if (this.options.managementKey) {
|
|
27
|
-
urlObj.searchParams.set('management_key', this.options.managementKey);
|
|
28
|
-
urlObj.searchParams.set('mgmt_key', this.options.managementKey);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const url = urlObj.toString();
|
|
16
|
+
const url = `${base.replace(/^http/, 'ws')}/v1/ws`;
|
|
32
17
|
const headers = {};
|
|
33
|
-
if (this.options.accessKey)
|
|
18
|
+
if (this.options.accessKey)
|
|
34
19
|
headers['Authorization'] = `Bearer ${this.options.accessKey}`;
|
|
35
|
-
headers['X-Access-Key'] = this.options.accessKey;
|
|
36
|
-
}
|
|
37
|
-
if (this.options.managementKey) {
|
|
38
|
-
headers['X-Management-Key'] = this.options.managementKey;
|
|
39
|
-
}
|
|
40
20
|
this.ws = new WebSocket(url, { headers });
|
|
41
21
|
return new Promise((resolve, reject) => {
|
|
42
22
|
const ws = this.ws;
|
|
@@ -58,27 +38,6 @@ export class CliproxyWSProvider {
|
|
|
58
38
|
close() {
|
|
59
39
|
this.ws?.close();
|
|
60
40
|
}
|
|
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
|
-
}
|
|
68
|
-
setAccessKey(accessKey) {
|
|
69
|
-
this.options.accessKey = accessKey;
|
|
70
|
-
}
|
|
71
|
-
setManagementKey(managementKey) {
|
|
72
|
-
this.options.managementKey = managementKey;
|
|
73
|
-
}
|
|
74
|
-
setCredentials(accessKey, managementKey) {
|
|
75
|
-
this.options.accessKey = accessKey;
|
|
76
|
-
this.options.managementKey = managementKey;
|
|
77
|
-
}
|
|
78
|
-
async setCredentialsAndReconnect(accessKey, managementKey) {
|
|
79
|
-
this.setCredentials(accessKey, managementKey);
|
|
80
|
-
await this.reconnect();
|
|
81
|
-
}
|
|
82
41
|
handleMessage(raw) {
|
|
83
42
|
let msg;
|
|
84
43
|
try {
|
package/dist/ws/types.d.ts
CHANGED
|
@@ -75,9 +75,6 @@ export type WSMessage = WSHttpRequestMessage | WSHttpResponseMessage | WSStreamS
|
|
|
75
75
|
export interface ProviderOptions {
|
|
76
76
|
baseUrl: string;
|
|
77
77
|
accessKey?: string;
|
|
78
|
-
managementKey?: string;
|
|
79
|
-
wsPath?: string;
|
|
80
|
-
authViaQuery?: boolean;
|
|
81
78
|
}
|
|
82
79
|
export type ProviderEvent = {
|
|
83
80
|
type: 'error';
|