@decartai/sdk 0.0.47 → 0.0.49
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/index.d.ts +9 -2
- package/dist/index.js +7 -2
- package/dist/queue/polling.js +9 -4
- package/dist/queue/types.d.ts +2 -0
- package/dist/realtime/client.d.ts +7 -8
- package/dist/realtime/client.js +128 -27
- package/dist/realtime/diagnostics.d.ts +78 -0
- package/dist/realtime/subscribe-client.d.ts +2 -0
- package/dist/realtime/telemetry-reporter.js +120 -0
- package/dist/realtime/webrtc-connection.js +156 -22
- package/dist/realtime/webrtc-manager.js +39 -5
- package/dist/realtime/webrtc-stats.d.ts +59 -0
- package/dist/realtime/webrtc-stats.js +154 -0
- package/dist/shared/types.d.ts +1 -0
- package/dist/shared/types.js +11 -4
- package/dist/utils/errors.d.ts +5 -1
- package/dist/utils/errors.js +39 -5
- package/dist/utils/logger.d.ts +18 -0
- package/dist/utils/logger.js +37 -0
- package/package.json +5 -2
package/dist/utils/errors.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const ERROR_CODES = {
|
|
3
3
|
INVALID_API_KEY: "INVALID_API_KEY",
|
|
4
4
|
INVALID_BASE_URL: "INVALID_BASE_URL",
|
|
5
|
-
WEB_RTC_ERROR: "WEB_RTC_ERROR",
|
|
6
5
|
PROCESSING_ERROR: "PROCESSING_ERROR",
|
|
7
6
|
INVALID_INPUT: "INVALID_INPUT",
|
|
8
7
|
INVALID_OPTIONS: "INVALID_OPTIONS",
|
|
@@ -11,7 +10,12 @@ const ERROR_CODES = {
|
|
|
11
10
|
QUEUE_STATUS_ERROR: "QUEUE_STATUS_ERROR",
|
|
12
11
|
QUEUE_RESULT_ERROR: "QUEUE_RESULT_ERROR",
|
|
13
12
|
JOB_NOT_COMPLETED: "JOB_NOT_COMPLETED",
|
|
14
|
-
TOKEN_CREATE_ERROR: "TOKEN_CREATE_ERROR"
|
|
13
|
+
TOKEN_CREATE_ERROR: "TOKEN_CREATE_ERROR",
|
|
14
|
+
WEBRTC_WEBSOCKET_ERROR: "WEBRTC_WEBSOCKET_ERROR",
|
|
15
|
+
WEBRTC_ICE_ERROR: "WEBRTC_ICE_ERROR",
|
|
16
|
+
WEBRTC_TIMEOUT_ERROR: "WEBRTC_TIMEOUT_ERROR",
|
|
17
|
+
WEBRTC_SERVER_ERROR: "WEBRTC_SERVER_ERROR",
|
|
18
|
+
WEBRTC_SIGNALING_ERROR: "WEBRTC_SIGNALING_ERROR"
|
|
15
19
|
};
|
|
16
20
|
function createSDKError(code, message, data, cause) {
|
|
17
21
|
return {
|
|
@@ -27,8 +31,38 @@ function createInvalidApiKeyError() {
|
|
|
27
31
|
function createInvalidBaseUrlError(url) {
|
|
28
32
|
return createSDKError(ERROR_CODES.INVALID_BASE_URL, `Invalid base URL${url ? `: ${url}` : ""}`);
|
|
29
33
|
}
|
|
30
|
-
function
|
|
31
|
-
return createSDKError(ERROR_CODES.
|
|
34
|
+
function createWebrtcWebsocketError(error) {
|
|
35
|
+
return createSDKError(ERROR_CODES.WEBRTC_WEBSOCKET_ERROR, "WebSocket connection failed", void 0, error);
|
|
36
|
+
}
|
|
37
|
+
function createWebrtcIceError(error) {
|
|
38
|
+
return createSDKError(ERROR_CODES.WEBRTC_ICE_ERROR, "ICE connection failed", void 0, error);
|
|
39
|
+
}
|
|
40
|
+
function createWebrtcTimeoutError(phase, timeoutMs, cause) {
|
|
41
|
+
const hasTimeout = typeof timeoutMs === "number" && Number.isFinite(timeoutMs);
|
|
42
|
+
return createSDKError(ERROR_CODES.WEBRTC_TIMEOUT_ERROR, hasTimeout ? `${phase} timed out after ${timeoutMs}ms` : `${phase} timed out`, hasTimeout ? {
|
|
43
|
+
phase,
|
|
44
|
+
timeoutMs
|
|
45
|
+
} : { phase }, cause);
|
|
46
|
+
}
|
|
47
|
+
function createWebrtcServerError(message) {
|
|
48
|
+
return createSDKError(ERROR_CODES.WEBRTC_SERVER_ERROR, message);
|
|
49
|
+
}
|
|
50
|
+
function createWebrtcSignalingError(error) {
|
|
51
|
+
return createSDKError(ERROR_CODES.WEBRTC_SIGNALING_ERROR, "Signaling error", void 0, error);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Classify a raw WebRTC error into a specific SDK error based on its message.
|
|
55
|
+
*/
|
|
56
|
+
function classifyWebrtcError(error) {
|
|
57
|
+
const msg = error.message.toLowerCase();
|
|
58
|
+
if (error.source === "server") return createWebrtcServerError(error.message);
|
|
59
|
+
if (msg.includes("websocket")) return createWebrtcWebsocketError(error);
|
|
60
|
+
if (msg.includes("ice connection failed")) return createWebrtcIceError(error);
|
|
61
|
+
if (msg.includes("timeout") || msg.includes("timed out")) {
|
|
62
|
+
const timeoutMatch = msg.match(/(\d+)\s*ms/);
|
|
63
|
+
return createWebrtcTimeoutError("connection", timeoutMatch ? Number.parseInt(timeoutMatch[1], 10) : void 0, error);
|
|
64
|
+
}
|
|
65
|
+
return createWebrtcSignalingError(error);
|
|
32
66
|
}
|
|
33
67
|
function createInvalidInputError(message) {
|
|
34
68
|
return createSDKError(ERROR_CODES.INVALID_INPUT, message);
|
|
@@ -47,4 +81,4 @@ function createQueueResultError(message, status) {
|
|
|
47
81
|
}
|
|
48
82
|
|
|
49
83
|
//#endregion
|
|
50
|
-
export { ERROR_CODES, createInvalidApiKeyError, createInvalidBaseUrlError, createInvalidInputError, createModelNotFoundError, createQueueResultError, createQueueStatusError, createQueueSubmitError, createSDKError
|
|
84
|
+
export { ERROR_CODES, classifyWebrtcError, createInvalidApiKeyError, createInvalidBaseUrlError, createInvalidInputError, createModelNotFoundError, createQueueResultError, createQueueStatusError, createQueueSubmitError, createSDKError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/utils/logger.d.ts
|
|
2
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
3
|
+
type Logger = {
|
|
4
|
+
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
5
|
+
info: (message: string, data?: Record<string, unknown>) => void;
|
|
6
|
+
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
7
|
+
error: (message: string, data?: Record<string, unknown>) => void;
|
|
8
|
+
};
|
|
9
|
+
/** A logger that discards all messages. Zero overhead. */
|
|
10
|
+
declare const noopLogger: Logger;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a console-based logger that only logs messages at or above the given level.
|
|
13
|
+
*
|
|
14
|
+
* @param minLevel - Minimum log level to output. Default: "warn".
|
|
15
|
+
*/
|
|
16
|
+
declare function createConsoleLogger(minLevel?: LogLevel): Logger;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { LogLevel, Logger, createConsoleLogger, noopLogger };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/utils/logger.ts
|
|
2
|
+
/** A logger that discards all messages. Zero overhead. */
|
|
3
|
+
const noopLogger = {
|
|
4
|
+
debug() {},
|
|
5
|
+
info() {},
|
|
6
|
+
warn() {},
|
|
7
|
+
error() {}
|
|
8
|
+
};
|
|
9
|
+
const LOG_LEVELS = {
|
|
10
|
+
debug: 0,
|
|
11
|
+
info: 1,
|
|
12
|
+
warn: 2,
|
|
13
|
+
error: 3
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates a console-based logger that only logs messages at or above the given level.
|
|
17
|
+
*
|
|
18
|
+
* @param minLevel - Minimum log level to output. Default: "warn".
|
|
19
|
+
*/
|
|
20
|
+
function createConsoleLogger(minLevel = "warn") {
|
|
21
|
+
const threshold = LOG_LEVELS[minLevel];
|
|
22
|
+
const log = (level, message, data) => {
|
|
23
|
+
if (LOG_LEVELS[level] < threshold) return;
|
|
24
|
+
const prefix = "[DecartSDK]";
|
|
25
|
+
if (data) console[level](prefix, message, data);
|
|
26
|
+
else console[level](prefix, message);
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
debug: (msg, data) => log("debug", msg, data),
|
|
30
|
+
info: (msg, data) => log("info", msg, data),
|
|
31
|
+
warn: (msg, data) => log("warn", msg, data),
|
|
32
|
+
error: (msg, data) => log("error", msg, data)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { createConsoleLogger, noopLogger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decartai/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.49",
|
|
4
4
|
"description": "Decart's JavaScript SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,13 +32,15 @@
|
|
|
32
32
|
"@biomejs/biome": "2.3.8",
|
|
33
33
|
"@types/bun": "^1.3.3",
|
|
34
34
|
"@types/node": "^22.15.17",
|
|
35
|
+
"@vitest/browser-playwright": "^4",
|
|
35
36
|
"bumpp": "^10.1.0",
|
|
36
37
|
"msw": "^2.11.3",
|
|
37
38
|
"pkg-pr-new": "^0.0.56",
|
|
39
|
+
"playwright": "^1.58.2",
|
|
38
40
|
"tsdown": "^0.14.1",
|
|
39
41
|
"typescript": "^5.8.3",
|
|
40
42
|
"vite": "^7.1.2",
|
|
41
|
-
"vitest": "^
|
|
43
|
+
"vitest": "^4.0.18"
|
|
42
44
|
},
|
|
43
45
|
"dependencies": {
|
|
44
46
|
"mitt": "^3.0.1",
|
|
@@ -51,6 +53,7 @@
|
|
|
51
53
|
"dev:example": "vite dev --port 3000",
|
|
52
54
|
"test": "vitest unit",
|
|
53
55
|
"test:e2e": "vitest e2e",
|
|
56
|
+
"test:e2e:realtime": "vitest --config vitest.config.e2e-realtime.ts",
|
|
54
57
|
"typecheck": "tsc --noEmit",
|
|
55
58
|
"format": "biome format --write",
|
|
56
59
|
"format:check": "biome check",
|