@redonvn/event-ws-cliproxyapi-sdk 1.0.3 → 1.0.4

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.
@@ -1,6 +1,6 @@
1
- import type { ClaudeMessagesRequest, ModelListResponse } from '../shared/types.js';
2
1
  import type { RequestOptions } from '../shared/http.js';
3
2
  import { BaseHttpClient } from '../shared/http.js';
3
+ import type { ClaudeMessagesRequest, ModelListResponse } from '../shared/types.js';
4
4
  export declare class ClaudeClient extends BaseHttpClient {
5
5
  getModels(options?: RequestOptions): Promise<ModelListResponse>;
6
6
  postMessages(body: ClaudeMessagesRequest, options?: RequestOptions): Promise<Response>;
@@ -1,2 +1,2 @@
1
+ export type { ClaudeCompatibleRequest, ClaudeCompatibleResponse, ClaudeContentBlock, ClaudeContentImage, ClaudeContentText, ClaudeMessage, ClaudeMessageRole, ClaudeMessagesRequest, ClaudeMessagesResponse, ClaudeStreamEvent, ClaudeStreamEventType, ClaudeUsage } from '../shared/types.js';
1
2
  export { ClaudeClient } from './client.js';
2
- export type { ClaudeMessageRole, ClaudeContentText, ClaudeContentImage, ClaudeContentBlock, ClaudeMessage, ClaudeMessagesRequest, ClaudeUsage, ClaudeMessagesResponse, ClaudeStreamEventType, ClaudeStreamEvent, ClaudeCompatibleRequest, ClaudeCompatibleResponse } from '../shared/types.js';
@@ -1,6 +1,6 @@
1
- import type { CliproxyAuthsQuery, CliproxyAuthsResponse, CliproxyChatRequest, CliproxyModelsQuery, CliproxyModelsResponse, KeepAliveResponse, RootResponse } from '../shared/types.js';
2
1
  import type { RequestOptions } from '../shared/http.js';
3
2
  import { BaseHttpClient } from '../shared/http.js';
3
+ import type { CliproxyAuthsQuery, CliproxyAuthsResponse, CliproxyChatRequest, CliproxyModelsQuery, CliproxyModelsResponse, KeepAliveResponse, RootResponse } from '../shared/types.js';
4
4
  export declare class CliproxyClient extends BaseHttpClient {
5
5
  getRoot(): Promise<RootResponse>;
6
6
  getManagementHtml(): Promise<Response>;
@@ -1,2 +1,2 @@
1
+ export type { CliproxyAuthEntry, CliproxyAuthModelEntry, CliproxyAuthsQuery, CliproxyAuthsResponse, CliproxyChatRequest, CliproxyModelsQuery, CliproxyModelsResponse } from '../shared/types.js';
1
2
  export { CliproxyClient } from './client.js';
2
- export type { CliproxyChatRequest, CliproxyAuthModelEntry, CliproxyAuthEntry, CliproxyAuthsResponse, CliproxyModelsResponse, CliproxyAuthsQuery, CliproxyModelsQuery } from '../shared/types.js';
@@ -1,6 +1,6 @@
1
- import type { GeminiCompatibleRequest } from '../shared/types.js';
2
1
  import type { RequestOptions } from '../shared/http.js';
3
2
  import { BaseHttpClient } from '../shared/http.js';
3
+ import type { GeminiCompatibleRequest } from '../shared/types.js';
4
4
  export declare class GeminiClient extends BaseHttpClient {
5
5
  getModels(options?: RequestOptions): Promise<Response>;
6
6
  postModelsAction(action: string, body: GeminiCompatibleRequest, options?: RequestOptions): Promise<Response>;
@@ -1,2 +1,2 @@
1
+ export type { GeminiCandidate, GeminiCompatibleRequest, GeminiCompatibleResponse, GeminiContent, GeminiFunctionCall, GeminiFunctionResponse, GeminiGenerateContentRequest, GeminiGenerateContentResponse, GeminiGenerationConfig, GeminiInlineData, GeminiPart, GeminiPromptFeedback, GeminiStreamChunk, GeminiToolDeclaration } from '../shared/types.js';
1
2
  export { GeminiClient } from './client.js';
2
- export type { GeminiInlineData, GeminiFunctionCall, GeminiFunctionResponse, GeminiPart, GeminiContent, GeminiGenerationConfig, GeminiToolDeclaration, GeminiGenerateContentRequest, GeminiCandidate, GeminiPromptFeedback, GeminiGenerateContentResponse, GeminiStreamChunk, GeminiCompatibleRequest, GeminiCompatibleResponse } from '../shared/types.js';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './ws/index.js';
2
- export * from './cliproxy/index.js';
3
- export * from './openai/index.js';
4
1
  export * from './claude/index.js';
2
+ export * from './cliproxy/index.js';
5
3
  export * from './gemini/index.js';
6
4
  export * from './management/index.js';
5
+ export * from './openai/index.js';
7
6
  export * from './shared/index.js';
7
+ export * from './ws/index.js';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export * from './ws/index.js';
2
- export * from './cliproxy/index.js';
3
- export * from './openai/index.js';
4
1
  export * from './claude/index.js';
2
+ export * from './cliproxy/index.js';
5
3
  export * from './gemini/index.js';
6
4
  export * from './management/index.js';
5
+ export * from './openai/index.js';
7
6
  export * from './shared/index.js';
7
+ export * from './ws/index.js';
@@ -1,5 +1,5 @@
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, UpdateConnectionSettingsRequest, VertexCompatKey, VertexCompatPatch } from '../shared/types.js';
2
1
  import { BaseHttpClient } from '../shared/http.js';
2
+ import type { AmpModelMapping, AmpModelMappingsPatch, AmpUpstreamAPIKeyEntry, AmpUpstreamAPIKeysPatch, ApiCallRequest, ApiCallResponse, AuthFileDeleteResponse, AuthFileListQuery, AuthFileListResponse, AuthFileModelsQuery, AuthFileModelsResponse, AuthFileStatusRequest, AuthFileStatusResponse, AuthStatusResponse, ClaudeKey, ClaudeKeyPatch, CodexKey, CodexKeyPatch, Config, DeleteLogsResponse, DesktopKeysResponse, ErrorLogFilesResponse, GeminiKey, GeminiKeyPatch, KeyedValueResponse, LogLinesResponse, ManagementApiKeysResponse, OAuthCallbackRequest, OAuthCallbackResponse, OAuthExcludedModelsPatch, OAuthModelAlias, OAuthModelAliasPatch, OAuthStartResponse, OpenAICompatibility, OpenAICompatPatch, PatchByIndexOrMatch, PatchStringListRequest, UpdateConnectionSettingsRequest, UsageExportResponse, UsageGetResponse, UsageImportRequest, UsageImportResponse, VertexCompatKey, VertexCompatPatch } from '../shared/types.js';
3
3
  export declare class ManagementClient extends BaseHttpClient {
4
4
  getDesktopKeys(): Promise<DesktopKeysResponse>;
5
5
  getManagementApiKeys(): Promise<ManagementApiKeysResponse>;
@@ -364,7 +364,7 @@ export class ManagementClient extends BaseHttpClient {
364
364
  return this.requestJson('GET', '/v0/management/auth-files', undefined, { query: query }, 'management');
365
365
  }
366
366
  getAuthFileModels(query) {
367
- return this.requestJson('GET', '/v0/management/auth-files/models', undefined, { query: query }, 'management');
367
+ return this.requestJson('GET', '/v0/management/auth-files/models', undefined, { query: { name: query.name } }, 'management');
368
368
  }
369
369
  getStaticModelDefinitions(channel) {
370
370
  return this.requestRaw('GET', `/v0/management/model-definitions/${encodeURIComponent(channel)}`, undefined, undefined, 'management');
@@ -1,2 +1,2 @@
1
+ export type { AccessConfig, AccessProvider, AmpCodeConfig, AmpModelMapping, AmpModelMappingsPatch, AmpStringListPatch, AmpUpstreamAPIKeyEntry, AmpUpstreamAPIKeysPatch, ApiCallRequest, ApiCallResponse, AuthFileDeleteResponse, AuthFileDownloadRequest, AuthFileEntry, AuthFileListQuery, AuthFileListResponse, AuthFileModelsQuery, AuthFileModelsResponse, AuthFileStatusRequest, AuthFileStatusResponse, AuthFileUploadRequest, AuthFileUploadResponse, AuthStatusResponse, ClaudeKey, ClaudeKeyPatch, ClaudeModel, CloakConfig, CodexKey, CodexKeyPatch, CodexModel, Config, DeleteLogsResponse, DesktopKeysResponse, ErrorLogFileInfo, ErrorLogFilesResponse, ErrorResponse, GeminiKey, GeminiKeyPatch, GeminiModel, KeepAliveResponse, LogLinesResponse, ManagementApiKeysResponse, ModelInfo, ModelListResponse, ModelThinkingSupport, OAuthCallbackRequest, OAuthCallbackResponse, OAuthExcludedModelsPatch, OAuthModelAlias, OAuthModelAliasPatch, OAuthStartResponse, OpenAICompatibility, OpenAICompatibilityAPIKey, OpenAICompatibilityModel, OpenAICompatPatch, PatchByIndexOrMatch, PatchStringListRequest, PayloadConfig, PayloadFilterRule, PayloadModelRule, PayloadRule, PprofConfig, QuotaExceededConfig, RemoteManagementConfig, RootResponse, RoutingConfig, SDKConfig, StatusResponse, StreamingConfig, TLSConfig, UpdateConnectionSettingsRequest, UsageApiSnapshot, UsageExportResponse, UsageGetResponse, UsageImportRequest, UsageImportResponse, UsageModelSnapshot, UsageRequestDetail, UsageStatisticsSnapshot, UsageTokenStats, VertexCompatKey, VertexCompatModel, VertexCompatPatch, VertexImportRequest } from '../shared/types.js';
1
2
  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, UpdateConnectionSettingsRequest, 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';
@@ -1,6 +1,6 @@
1
- import type { ModelListResponse, OpenAIChatCompletionRequest, OpenAICompletionRequest, OpenAIResponsesRequest } from '../shared/types.js';
2
1
  import type { RequestOptions } from '../shared/http.js';
3
2
  import { BaseHttpClient } from '../shared/http.js';
3
+ import type { ModelListResponse, OpenAIChatCompletionRequest, OpenAICompletionRequest, OpenAIResponsesRequest } from '../shared/types.js';
4
4
  export declare class OpenAIClient extends BaseHttpClient {
5
5
  getModels(options?: RequestOptions): Promise<ModelListResponse>;
6
6
  postChatCompletions(body: OpenAIChatCompletionRequest, options?: RequestOptions): Promise<Response>;
@@ -1,2 +1,2 @@
1
+ export type { OpenAIChatCompletionChoice, OpenAIChatCompletionChunk, OpenAIChatCompletionChunkChoice, OpenAIChatCompletionRequest, OpenAIChatCompletionResponse, OpenAIChatMessage, OpenAIChatMessageContentImageUrl, OpenAIChatMessageContentPart, OpenAIChatMessageContentText, OpenAIChatRole, OpenAICompatibleRequest, OpenAICompatibleResponse, OpenAICompletionChoice, OpenAICompletionChunk, OpenAICompletionRequest, OpenAICompletionResponse, OpenAIErrorDetail, OpenAIErrorResponse, OpenAIResponsesChunk, OpenAIResponsesInputContent, OpenAIResponsesInputImage, OpenAIResponsesInputMessage, OpenAIResponsesInputText, OpenAIResponsesOutput, OpenAIResponsesRequest, OpenAIResponsesResponse } from '../shared/types.js';
1
2
  export { OpenAIClient } from './client.js';
2
- export type { OpenAIChatRole, OpenAIChatMessageContentText, OpenAIChatMessageContentImageUrl, OpenAIChatMessageContentPart, OpenAIChatMessage, OpenAIChatCompletionRequest, OpenAICompletionRequest, OpenAIResponsesInputText, OpenAIResponsesInputImage, OpenAIResponsesInputContent, OpenAIResponsesInputMessage, OpenAIResponsesRequest, OpenAIChatCompletionChoice, OpenAIChatCompletionResponse, OpenAIChatCompletionChunkChoice, OpenAIChatCompletionChunk, OpenAICompletionChoice, OpenAICompletionResponse, OpenAICompletionChunk, OpenAIResponsesOutput, OpenAIResponsesResponse, OpenAIResponsesChunk, OpenAICompatibleRequest, OpenAICompatibleResponse, OpenAIErrorDetail, OpenAIErrorResponse } from '../shared/types.js';
@@ -1,4 +1,4 @@
1
- import type { OpenAIErrorResponse, ErrorResponse, StatusResponse, JsonObject } from './types.js';
1
+ import type { ErrorResponse, JsonObject, JsonValue, OpenAIErrorResponse, StatusResponse } from './types.js';
2
2
  export type ManagementErrorResponse = ErrorResponse;
3
3
  export type ApiErrorPayload = OpenAIErrorResponse | ManagementErrorResponse | StatusResponse | JsonObject | {
4
4
  error: string;
@@ -8,6 +8,6 @@ export declare class APIError extends Error {
8
8
  readonly payload?: ApiErrorPayload;
9
9
  constructor(message: string, status: number, payload?: ApiErrorPayload);
10
10
  }
11
- export declare function isOpenAIError(payload: unknown): payload is OpenAIErrorResponse;
12
- export declare function isStatusError(payload: unknown): payload is StatusResponse;
13
- export declare function isManagementError(payload: unknown): payload is ManagementErrorResponse;
11
+ export declare function isOpenAIError(payload: JsonValue | undefined): payload is OpenAIErrorResponse;
12
+ export declare function isStatusError(payload: JsonValue | undefined): payload is StatusResponse;
13
+ export declare function isManagementError(payload: JsonValue | undefined): payload is ManagementErrorResponse;
@@ -6,21 +6,27 @@ export class APIError extends Error {
6
6
  this.payload = payload;
7
7
  }
8
8
  }
9
+ function isJsonObject(payload) {
10
+ return !!payload && typeof payload === 'object' && !Array.isArray(payload);
11
+ }
9
12
  export function isOpenAIError(payload) {
10
- if (!payload || typeof payload !== 'object')
13
+ if (!isJsonObject(payload))
14
+ return false;
15
+ const error = payload.error;
16
+ if (!error || typeof error !== 'object' || Array.isArray(error))
11
17
  return false;
12
- const obj = payload;
13
- return !!obj.error && typeof obj.error.message === 'string' && typeof obj.error.type === 'string';
18
+ const message = error.message;
19
+ const type = error.type;
20
+ return typeof message === 'string' && typeof type === 'string';
14
21
  }
15
22
  export function isStatusError(payload) {
16
- if (!payload || typeof payload !== 'object')
23
+ if (!isJsonObject(payload))
17
24
  return false;
18
- const obj = payload;
19
- return typeof obj.status === 'string' && (obj.status === 'error' || obj.status === 'wait' || obj.status === 'ok');
25
+ const status = payload.status;
26
+ return typeof status === 'string' && (status === 'error' || status === 'wait' || status === 'ok');
20
27
  }
21
28
  export function isManagementError(payload) {
22
- if (!payload || typeof payload !== 'object')
29
+ if (!isJsonObject(payload))
23
30
  return false;
24
- const obj = payload;
25
- return typeof obj.error === 'string';
31
+ return typeof payload.error === 'string';
26
32
  }
@@ -1,3 +1,4 @@
1
+ import type { JsonValue } from './types.js';
1
2
  export interface HttpClientOptions {
2
3
  baseUrl: string;
3
4
  accessKey?: string;
@@ -21,9 +22,10 @@ export declare class BaseHttpClient {
21
22
  setLocalPassword(value?: string): void;
22
23
  getWebsocketUrl(path?: string): string;
23
24
  protected buildUrl(path: string, query?: Record<string, string | number | boolean | undefined>): string;
24
- protected requestJson<T>(method: string, path: string, body?: unknown, options?: RequestOptions, auth?: 'access' | 'management' | 'local'): Promise<T>;
25
+ protected requestJson<T>(method: string, path: string, body?: JsonValue, options?: RequestOptions, auth?: 'access' | 'management' | 'local'): Promise<T>;
25
26
  protected requestText(method: string, path: string, body?: string, options?: RequestOptions, auth?: 'access' | 'management' | 'local'): Promise<string>;
26
27
  protected requestRaw(method: string, path: string, body?: BodyInit, options?: RequestOptions, auth?: 'access' | 'management' | 'local'): Promise<Response>;
27
28
  protected applyAuth(headers: Record<string, string>, auth?: 'access' | 'management' | 'local'): void;
28
29
  protected throwApiError(res: Response): Promise<never>;
30
+ private extractErrorMessage;
29
31
  }
@@ -108,18 +108,24 @@ export class BaseHttpClient {
108
108
  catch {
109
109
  payload = { error: text };
110
110
  }
111
- if (payload && typeof payload === 'object') {
112
- const obj = payload;
113
- if (typeof obj.error === 'string')
114
- message = obj.error;
115
- else if (obj.error && typeof obj.error === 'object' && typeof obj.error.message === 'string') {
116
- message = obj.error.message;
117
- }
118
- else if (typeof obj.message === 'string') {
119
- message = obj.message;
120
- }
121
- }
111
+ message = this.extractErrorMessage(payload, message);
112
+ }
113
+ throw new APIError(message, res.status, payload ?? { error: message });
114
+ }
115
+ extractErrorMessage(payload, fallback) {
116
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload))
117
+ return fallback;
118
+ const obj = payload;
119
+ const error = obj.error;
120
+ if (typeof error === 'string')
121
+ return error;
122
+ if (error && typeof error === 'object' && !Array.isArray(error)) {
123
+ const nestedMessage = error.message;
124
+ if (typeof nestedMessage === 'string')
125
+ return nestedMessage;
122
126
  }
123
- throw new APIError(message, res.status, (payload ?? { error: message }));
127
+ if (typeof obj.message === 'string')
128
+ return obj.message;
129
+ return fallback;
124
130
  }
125
131
  }
@@ -1,2 +1,2 @@
1
- export * from './types.js';
2
1
  export * from './errors.js';
2
+ export * from './types.js';
@@ -1,2 +1,2 @@
1
- export * from './types.js';
2
1
  export * from './errors.js';
2
+ export * from './types.js';
@@ -1,6 +1,7 @@
1
- export type JsonValue = unknown;
2
- export type JsonObject = Record<string, unknown>;
3
- export type JsonArray = unknown[];
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+ export type JsonValue = JsonPrimitive | object | JsonArray | undefined;
3
+ export type JsonObject = Record<string, JsonValue>;
4
+ export type JsonArray = JsonValue[];
4
5
  export type PrimaryOpenAIChatRequest = OpenAIChatCompletionRequest;
5
6
  export type PrimaryOpenAICompletionRequest = OpenAICompletionRequest;
6
7
  export type PrimaryOpenAIResponsesRequest = OpenAIResponsesRequest;
@@ -110,7 +111,7 @@ export interface AccessProvider {
110
111
  type: string;
111
112
  sdk?: string;
112
113
  'api-keys'?: string[];
113
- config?: Record<string, unknown>;
114
+ config?: JsonObject;
114
115
  }
115
116
  export interface TLSConfig {
116
117
  enable: boolean;
@@ -169,7 +170,7 @@ export interface PayloadFilterRule {
169
170
  }
170
171
  export interface PayloadRule {
171
172
  models: PayloadModelRule[];
172
- params: Record<string, unknown>;
173
+ params: JsonObject;
173
174
  }
174
175
  export interface PayloadModelRule {
175
176
  name: string;
@@ -411,7 +412,7 @@ export interface AuthFileEntry {
411
412
  updated_at?: string;
412
413
  last_refresh?: string;
413
414
  path?: string;
414
- id_token?: Record<string, unknown>;
415
+ id_token?: JsonObject;
415
416
  }
416
417
  export interface AuthFileListResponse {
417
418
  files: AuthFileEntry[];
@@ -755,12 +756,12 @@ export interface GeminiInlineData {
755
756
  export interface GeminiFunctionCall {
756
757
  id?: string;
757
758
  name: string;
758
- args: Record<string, unknown>;
759
+ args: JsonObject;
759
760
  }
760
761
  export interface GeminiFunctionResponse {
761
762
  id?: string;
762
763
  name: string;
763
- response: Record<string, unknown>;
764
+ response: JsonObject;
764
765
  }
765
766
  export interface GeminiPart {
766
767
  thought?: boolean;
@@ -11,6 +11,7 @@ export declare class CliproxyWSProvider {
11
11
  connect(handlers: ProviderHandlers): Promise<void>;
12
12
  close(): void;
13
13
  private handleMessage;
14
+ private errorMessage;
14
15
  private handleClose;
15
16
  private emitError;
16
17
  private buildContext;
package/dist/ws/client.js CHANGED
@@ -60,21 +60,23 @@ export class CliproxyWSProvider {
60
60
  const req = decodeRequest(msg.payload);
61
61
  const ctx = this.buildContext(msg.id);
62
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';
63
+ Promise.resolve()
64
+ .then(() => this.handlers?.onRequest(req, ctx))
65
+ .catch((err) => {
66
+ const message = this.errorMessage(err);
75
67
  ctx.error(message);
76
- this.emitError(message, msg?.id);
68
+ this.emitError(message, msg.id);
69
+ });
70
+ }
71
+ errorMessage(err) {
72
+ if (typeof err === 'string' && err)
73
+ return err;
74
+ if (err && typeof err === 'object' && 'message' in err && typeof err.message === 'string' && err.message) {
75
+ return err.message;
77
76
  }
77
+ if (err instanceof Error && err.message)
78
+ return err.message;
79
+ return 'provider error';
78
80
  }
79
81
  handleClose(code, reason) {
80
82
  this.handlers?.onEvent?.({ type: 'ws:close', code, reason });
package/dist/ws/codec.js CHANGED
@@ -89,7 +89,7 @@ export function encodeError(message, status) {
89
89
  // CLIProxyAPI always formats as "message (status=...)".
90
90
  export function decodeError(payload) {
91
91
  if (!payload)
92
- return 'wsrelay: unknown error';
92
+ return 'wsrelay: upstream error';
93
93
  const message = typeof payload.error === 'string' ? payload.error : 'wsrelay: upstream error';
94
94
  const status = typeof payload.status === 'number'
95
95
  ? payload.status
@@ -1,3 +1,3 @@
1
- export * from './types.js';
2
1
  export * from './client.js';
3
2
  export * from './codec.js';
3
+ export * from './types.js';
package/dist/ws/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './types.js';
2
1
  export * from './client.js';
3
2
  export * from './codec.js';
3
+ export * from './types.js';
@@ -15,13 +15,13 @@ export interface HTTPResponse {
15
15
  export interface WSHttpRequestPayload {
16
16
  method: string;
17
17
  url: string;
18
- headers?: WSHeaders;
18
+ headers?: Record<string, string | string[]>;
19
19
  body?: string;
20
20
  sent_at?: string;
21
21
  }
22
22
  export interface WSHttpResponsePayload {
23
- status: number;
24
- headers?: WSHeaders;
23
+ status: number | string;
24
+ headers?: Record<string, string | string[]>;
25
25
  body?: string;
26
26
  }
27
27
  export interface WSStreamChunkPayload {
@@ -29,7 +29,7 @@ export interface WSStreamChunkPayload {
29
29
  }
30
30
  export interface WSErrorPayload {
31
31
  error: string;
32
- status?: number;
32
+ status?: number | string;
33
33
  }
34
34
  export interface WSHttpRequestMessage {
35
35
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redonvn/event-ws-cliproxyapi-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "TypeScript SDK for CLIProxyAPI WebSocket relay (provider-side).",
5
5
  "license": "MIT",
6
6
  "type": "module",