@xmaxai/sdk 1.0.1 → 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.
Files changed (38) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/README.md +9 -5
  3. package/dist/{chunk-V4NR6CPP.js → chunk-F567ONBH.js} +7 -184
  4. package/dist/chunk-F567ONBH.js.map +1 -0
  5. package/dist/{chunk-LCPC56BK.js → chunk-TFGYBN3Q.js} +493 -136
  6. package/dist/chunk-TFGYBN3Q.js.map +1 -0
  7. package/dist/index.cjs +30 -272
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +369 -8
  10. package/dist/index.d.ts +369 -8
  11. package/dist/index.js +1003 -9
  12. package/dist/index.js.map +1 -1
  13. package/dist/react/index.cjs +9 -271
  14. package/dist/react/index.cjs.map +1 -1
  15. package/dist/react/index.d.cts +1 -3
  16. package/dist/react/index.d.ts +1 -3
  17. package/dist/react/index.js +6 -26
  18. package/dist/react/index.js.map +1 -1
  19. package/dist/{rtc-manager-gYDkADGw.d.ts → rtc-manager-DnQoznIg.d.cts} +2 -17
  20. package/dist/{rtc-manager-gYDkADGw.d.cts → rtc-manager-DnQoznIg.d.ts} +2 -17
  21. package/dist/video-file-stream-4TAGKL2Q.js +3 -0
  22. package/dist/{video-file-stream-K7GQMIJ5.js.map → video-file-stream-4TAGKL2Q.js.map} +1 -1
  23. package/package.json +1 -6
  24. package/dist/chunk-4YHBCQ2C.js +0 -432
  25. package/dist/chunk-4YHBCQ2C.js.map +0 -1
  26. package/dist/chunk-LCPC56BK.js.map +0 -1
  27. package/dist/chunk-V4NR6CPP.js.map +0 -1
  28. package/dist/chunk-VLJZ56PT.js +0 -997
  29. package/dist/chunk-VLJZ56PT.js.map +0 -1
  30. package/dist/experimental/index.cjs +0 -3897
  31. package/dist/experimental/index.cjs.map +0 -1
  32. package/dist/experimental/index.d.cts +0 -2
  33. package/dist/experimental/index.d.ts +0 -2
  34. package/dist/experimental/index.js +0 -5
  35. package/dist/experimental/index.js.map +0 -1
  36. package/dist/index-Cw8C8LbO.d.ts +0 -367
  37. package/dist/index-Dg1ElHAj.d.cts +0 -367
  38. package/dist/video-file-stream-K7GQMIJ5.js +0 -4
package/CHANGELOG.md CHANGED
@@ -13,12 +13,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
  - 构建时区域开关 `XMAX_SDK_REGION`(`cn` | `global`),经 tsup 内联注入默认 `baseUrl`。
14
14
  - `XMAX_OPEN_API_BASE_URLS` 常量与 `XmaxSdkRegion` 类型。
15
15
  - `build:cn` / `build:global` / `publish:cn` / `publish:global` / `publish:all` 脚本及 `scripts/publish-sdk.mjs`。
16
+ - `connect` 支持可选的 `onError` / `onDisconnect`(与 Decart Overview 对齐;不传则行为与原先一致)。
16
17
 
17
18
  ### Changed
18
19
 
19
20
  - `XMAX_OPEN_API_PRODUCTION_BASE_URL` 现按构建区域解析(默认 `cn`),不再硬编码单一地址。
21
+ - **根入口正式对外**:`createXmaxClient` / `models` 等从 `@xmaxai/sdk`(或 `@xmaxai/sdk-global`)直接导入,不再标 `@deprecated`。
22
+ - 移除 `@xmaxai/sdk/experimental` 子路径(发版前无外部依赖);Realtime API 仅通过根入口导出。
23
+ - 错误通过 `onError` 通知调用方处理。
20
24
 
21
- ## [1.0.1 ] - 2026-07-01
25
+ ### Removed
26
+
27
+ - Package export `./experimental` and `src/experimental` barrel.
28
+ - Deprecated aliases and no-ops: `mirrorInput`, `setMode` / `RealtimeSetModeOptions`, `preserveLocalInput`, `getContentRect`, `RTC_PUBLISH_FPS`, `waitForRtcOutboundBeforeStart`, `waitForPublishedInputFramesBeforeStart`, React `changeModel`.
29
+
30
+ ## [1.0.2 ] - 2026-07-01
22
31
 
23
32
  ### Added
24
33
 
@@ -26,7 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
26
35
  - `XMAX_OPEN_API_PRODUCTION_BASE_URL` constant for explicit production API endpoint configuration.
27
36
  - `@xmaxai/sdk/experimental` subpath for `createXmaxClient`, drag, and related APIs.
28
37
  - Unit tests for RTC event builders, video size utilities, and HTTP client request handling.
29
- - Inline SVG icons for built-in error toasts (no host static assets required).
30
38
 
31
39
  ### Changed
32
40
 
package/README.md CHANGED
@@ -28,8 +28,8 @@ npm install @xmaxai/sdk-global
28
28
 
29
29
  | 入口 | 说明 |
30
30
  |------|------|
31
- | `@xmaxai/sdk/experimental` | **推荐** — `createXmaxClient`、`models` |
32
- | `@xmaxai/sdk` | HTTP Client、`RtcManager`、房间事件等底层 API |
31
+ | `@xmaxai/sdk` | **推荐** — `createXmaxClient`、`models`,以及 HTTP Client / RTC 底层 API |
32
+ | `@xmaxai/sdk/react` | React bindings(可选) |
33
33
 
34
34
  ## 快速开始
35
35
 
@@ -38,7 +38,7 @@ npm install @xmaxai/sdk-global
38
38
  `baseUrl` 已内置生产环境默认值,一般无需传入;仅在 staging / 私有部署时覆盖。
39
39
 
40
40
  ```ts
41
- import { createXmaxClient, models } from "@xmaxai/sdk/experimental";
41
+ import { createXmaxClient, models } from "@xmaxai/sdk";
42
42
 
43
43
  const model = models.realtime("x2.0");
44
44
 
@@ -84,7 +84,8 @@ await realtimeClient.disconnect();
84
84
  - `connect()` 自动完成:createSession → heartbeat → join RTC → 推流 →(`autoStart: true` 时)发送 start。
85
85
  - `initialState.prompt` 传 `{ text: string }`;`initialState.image` 传参考图 URL。
86
86
  - 宿主自行提供 `#video-input` / `#video-output` 容器元素。
87
- - 未传 `onError` 时,API/RTC 错误会弹出内置 toast;传入 `onError` 则完全覆盖。
87
+ - API/RTC 错误通过 `onError` 回调交给调用方处理。在 `createXmaxClient` `connect` 任一处传入即可(`connect` 优先)。
88
+ - `onDisconnect` 仅在 session 成功建立后断开时触发;`connect()` 失败不会回调。
88
89
 
89
90
  ### 自定义 baseUrl(可选)
90
91
 
@@ -92,7 +93,7 @@ await realtimeClient.disconnect();
92
93
  import {
93
94
  createXmaxClient,
94
95
  XMAX_OPEN_API_PRODUCTION_BASE_URL,
95
- } from "@xmaxai/sdk/experimental";
96
+ } from "@xmaxai/sdk";
96
97
 
97
98
  const client = createXmaxClient({
98
99
  apiKey: "<YOUR_XMAX_API_KEY>",
@@ -124,6 +125,9 @@ client.realtime.connect(stream, {
124
125
  model: RealtimeModel, // models.realtime("x2.0")
125
126
  localElement?: HTMLElement,
126
127
  remoteElement?: HTMLElement,
128
+ onRemoteStream?: (stream: MediaStream) => void,
129
+ onError?: (message, error?) => void, // optional; overrides createXmaxClient.onError
130
+ onDisconnect?: (reason) => void, // "client" | "session_inactive" | "heartbeat_error"
127
131
  mirror?: "auto" | boolean,
128
132
  initialState?: {
129
133
  prompt?: string | { text: string },
@@ -1,149 +1,14 @@
1
- import { createSDKI18n, resolveApiErrorMessage, resolvePlaybackDrivenEncoderFps, mountCaptureVideo } from './chunk-LCPC56BK.js';
1
+ import { createSDKI18n, resolveApiErrorMessage, resolvePlaybackDrivenEncoderFps, mountCaptureVideo } from './chunk-TFGYBN3Q.js';
2
2
  import COS from 'cos-js-sdk-v5';
3
3
  import VERTC, { VideoSourceType, MediaType, StreamIndex, RoomProfileType, MirrorType, VideoCodecType, VideoRenderMode } from '@volcengine/rtc';
4
4
 
5
- // src/shared/browser-toast.ts
6
- var TOAST_ROOT_ID = "Xmax-sdk-toast-root";
7
- var TOAST_DURATION_MS = 3e3;
8
- var toastSeed = 0;
9
- var timeoutMap = /* @__PURE__ */ new Map();
10
- var elementMap = /* @__PURE__ */ new Map();
11
- function ensureToastRoot() {
12
- if (typeof document === "undefined") {
13
- return null;
14
- }
15
- let root = document.getElementById(TOAST_ROOT_ID);
16
- if (root) {
17
- return root;
18
- }
19
- root = document.createElement("div");
20
- root.id = TOAST_ROOT_ID;
21
- root.setAttribute("aria-live", "polite");
22
- Object.assign(root.style, {
23
- position: "fixed",
24
- left: "50%",
25
- top: "24px",
26
- transform: "translateX(-50%)",
27
- zIndex: "3000",
28
- display: "flex",
29
- flexDirection: "column",
30
- alignItems: "center",
31
- gap: "12px",
32
- pointerEvents: "none"
33
- });
34
- document.body.appendChild(root);
35
- return root;
36
- }
37
- function createIcon(type) {
38
- const icon = document.createElement("span");
39
- icon.setAttribute("aria-hidden", "true");
40
- icon.innerHTML = type === "success" ? '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M10 3L4.5 8.5 2 6" stroke="#4ade80" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>' : '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none"><circle cx="6" cy="6" r="5" stroke="#f87171" stroke-width="1.5"/><path d="M4 4l4 4M8 4L4 8" stroke="#f87171" stroke-width="1.5" stroke-linecap="round"/></svg>';
41
- Object.assign(icon.style, {
42
- display: "inline-flex",
43
- width: "12px",
44
- height: "12px",
45
- flexShrink: "0"
46
- });
47
- return icon;
48
- }
49
- function clearToastTimer(id) {
50
- const timer = timeoutMap.get(id);
51
- if (timer) {
52
- window.clearTimeout(timer);
53
- timeoutMap.delete(id);
54
- }
55
- }
56
- function destroyToast(id) {
57
- if (!id) {
58
- timeoutMap.forEach((timer) => window.clearTimeout(timer));
59
- timeoutMap.clear();
60
- elementMap.forEach((element2) => element2.remove());
61
- elementMap.clear();
62
- const root2 = typeof document !== "undefined" ? document.getElementById(TOAST_ROOT_ID) : null;
63
- root2?.remove();
64
- return;
65
- }
66
- clearToastTimer(id);
67
- const element = elementMap.get(id);
68
- element?.remove();
69
- elementMap.delete(id);
70
- const root = typeof document !== "undefined" ? document.getElementById(TOAST_ROOT_ID) : null;
71
- if (root && !root.childElementCount) {
72
- root.remove();
73
- }
74
- }
75
- function showToast(type, message, options) {
76
- const root = ensureToastRoot();
77
- if (!root) {
78
- return "";
79
- }
80
- const id = options?.key || `toast-${Date.now()}-${++toastSeed}`;
81
- clearToastTimer(id);
82
- elementMap.get(id)?.remove();
83
- const isMobile = typeof window !== "undefined" && window.matchMedia("(max-width: 768px)").matches;
84
- const textSize = isMobile ? "12px" : "14px";
85
- const toast = document.createElement("div");
86
- toast.setAttribute("role", "status");
87
- Object.assign(toast.style, {
88
- pointerEvents: "auto",
89
- display: "flex",
90
- alignItems: "center",
91
- gap: "12px",
92
- minWidth: "240px",
93
- padding: "16px",
94
- borderRadius: "12px",
95
- border: "1px solid rgba(255, 255, 255, 0.20)",
96
- background: "rgba(0, 0, 0, 0.80)",
97
- boxShadow: "0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)",
98
- fontFamily: "Rubik, ui-sans-serif, system-ui, sans-serif",
99
- fontSize: textSize,
100
- fontWeight: "400",
101
- lineHeight: "14px"
102
- });
103
- const content = document.createElement("span");
104
- content.textContent = message;
105
- Object.assign(content.style, {
106
- paddingRight: "0px",
107
- textAlign: "center",
108
- color: "#ffffff",
109
- fontFamily: "Rubik, ui-sans-serif, system-ui, sans-serif",
110
- fontSize: textSize,
111
- fontWeight: "400",
112
- lineHeight: "14px"
113
- });
114
- toast.appendChild(createIcon(type));
115
- toast.appendChild(content);
116
- root.appendChild(toast);
117
- elementMap.set(id, toast);
118
- const timer = window.setTimeout(() => {
119
- destroyToast(id);
120
- }, options?.duration ?? TOAST_DURATION_MS);
121
- timeoutMap.set(id, timer);
122
- return id;
123
- }
124
- var browserToast = {
125
- success(message, options) {
126
- return showToast("success", message, options);
127
- },
128
- error(message, options) {
129
- return showToast("error", message, options);
130
- },
131
- destroy(id) {
132
- destroyToast(id);
133
- }
134
- };
135
-
136
5
  // src/shared/error-utils.ts
137
6
  function notifyError(error, notifier, fallbackMessage) {
138
7
  const resolved = error instanceof Error ? error : Object.assign(new Error(fallbackMessage), { cause: error });
139
- if (!resolved.__XmaxNotified) {
8
+ if (!resolved.__XmaxNotified && notifier) {
140
9
  resolved.__XmaxNotified = true;
141
10
  const message = resolved.message || fallbackMessage;
142
- if (notifier) {
143
- notifier(message, error);
144
- } else if (typeof window !== "undefined" && typeof document !== "undefined") {
145
- browserToast.error(message);
146
- }
11
+ notifier(message, error);
147
12
  }
148
13
  return resolved;
149
14
  }
@@ -215,7 +80,7 @@ var XmaxOpenClient = class {
215
80
  }
216
81
  throw notifyError(error, this.onError, message);
217
82
  }
218
- /** Stop heartbeat, abort in-flight API requests, and suppress error toasts during teardown. */
83
+ /** Stop heartbeat, abort in-flight API requests, and suppress error notifications during teardown. */
219
84
  beginTeardown() {
220
85
  this.suppressErrorNotification = true;
221
86
  this.stopHeartbeat();
@@ -1066,45 +931,6 @@ var _RtcManager = class _RtcManager {
1066
931
  sentFrameRate: this.lastObservedSentFrameRate
1067
932
  });
1068
933
  }
1069
- /** @deprecated Use {@link ensurePublishedInputBeforeStart}. */
1070
- async waitForRtcOutboundBeforeStart(options) {
1071
- const timeoutMs = options?.timeoutMs ?? PUBLISH_READY_TIMEOUT_MS;
1072
- const publishAgeMs = this.publishStartedAtMs > 0 ? performance.now() - this.publishStartedAtMs : 0;
1073
- const localFramesPromise = publishAgeMs >= PUBLISH_WARM_SKIP_MS ? Promise.resolve({ ready: true, frameCount: 0, elapsedMs: 0 }) : this.waitForPublishedInputFrames({
1074
- minFrames: PUBLISH_START_MIN_FRAMES,
1075
- timeoutMs: PUBLISH_START_FRAME_TIMEOUT_MS
1076
- });
1077
- const [, rtcReady] = await Promise.all([
1078
- localFramesPromise,
1079
- this.waitForLocalPublishReady({ timeoutMs })
1080
- ]);
1081
- return rtcReady;
1082
- }
1083
- /** @deprecated Use {@link waitForRtcOutboundBeforeStart}. */
1084
- async waitForPublishedInputFramesBeforeStart() {
1085
- const waitOptions = this.resolveInputFrameWaitOptions();
1086
- const waitTasks = [
1087
- this.waitForLocalPublishReady({ timeoutMs: PUBLISH_READY_TIMEOUT_MS })
1088
- ];
1089
- if (waitOptions) {
1090
- waitTasks.push(
1091
- this.waitForMinPublishDuration(waitOptions.minPublishMs),
1092
- this.waitForPublishedInputFrames({
1093
- minFrames: waitOptions.minFrames,
1094
- timeoutMs: waitOptions.timeoutMs
1095
- })
1096
- );
1097
- }
1098
- const [rtcResult, ...rest] = await Promise.all(waitTasks);
1099
- const rtcSend = rtcResult;
1100
- const frameResult = waitOptions ? rest[1] : { ready: true, frameCount: 0, elapsedMs: 0 };
1101
- return {
1102
- ...frameResult,
1103
- rtcSendReady: rtcSend.ready,
1104
- rtcSendReason: rtcSend.reason,
1105
- rtcSendElapsedMs: rtcSend.elapsedSincePublishMs
1106
- };
1107
- }
1108
934
  async waitForMinPublishDuration(minMs) {
1109
935
  if (minMs <= 0 || this.publishStartedAtMs <= 0) {
1110
936
  return;
@@ -2206,9 +2032,6 @@ function getFitContentRect(rect, targetSize, fitMode = "contain") {
2206
2032
  height
2207
2033
  };
2208
2034
  }
2209
- function getContentRect(rect, targetSize) {
2210
- return getFitContentRect(rect, targetSize, "contain");
2211
- }
2212
2035
  function findDragMediaElement(dragSurface) {
2213
2036
  const root = dragSurface.parentElement ?? dragSurface;
2214
2037
  if (typeof root.querySelector !== "function") {
@@ -2663,6 +2486,6 @@ var models = {
2663
2486
  }
2664
2487
  };
2665
2488
 
2666
- export { ACTIVE_STATUS, PREVIEW_CONTAIN_ATTR, PREVIEW_COVER_ATTR, PREVIEW_OUTPUT_LAYOUT_ATTR, PREVIEW_UPLOAD_FIT_ATTR, PREVIEW_UPLOAD_LAYOUT_ATTR, PUBLISH_COLD_FRAME_TIMEOUT_MS, PUBLISH_COLD_MIN_FRAMES, PUBLISH_COLD_WARMUP_MS, PUBLISH_START_FRAME_TIMEOUT_MS, PUBLISH_START_MIN_FRAMES, PUBLISH_WARM_SKIP_MS, RtcManager, XMAX_OPEN_API_BASE_URLS, XMAX_OPEN_API_PRODUCTION_BASE_URL, XmaxOpenClient, applyUploadPreviewMediaLayout, browserToast, classifyCameraAccessError, createDragTrackController, createNativeCameraStream, createStartRtcRoomEvent, createStopRtcRoomEvent, createTaskUid, createTracksRtcRoomEvent, getCameraEnvironmentIssue, getContentRect, getFitContentRect, isCameraAccessError, mapTargetPointToCanvas, mapViewportPointToCoordinateSpace, models, notifyError, observeUploadPreviewMediaLayout, openNativeCameraStream, requestCameraMediaStream, stabilizeCameraVideoTrack };
2667
- //# sourceMappingURL=chunk-V4NR6CPP.js.map
2668
- //# sourceMappingURL=chunk-V4NR6CPP.js.map
2489
+ export { ACTIVE_STATUS, PREVIEW_CONTAIN_ATTR, PREVIEW_COVER_ATTR, PREVIEW_OUTPUT_LAYOUT_ATTR, PREVIEW_UPLOAD_FIT_ATTR, PREVIEW_UPLOAD_LAYOUT_ATTR, PUBLISH_COLD_FRAME_TIMEOUT_MS, PUBLISH_COLD_MIN_FRAMES, PUBLISH_COLD_WARMUP_MS, PUBLISH_START_FRAME_TIMEOUT_MS, PUBLISH_START_MIN_FRAMES, PUBLISH_WARM_SKIP_MS, RtcManager, XMAX_OPEN_API_BASE_URLS, XMAX_OPEN_API_PRODUCTION_BASE_URL, XmaxOpenClient, applyUploadPreviewMediaLayout, classifyCameraAccessError, createDragTrackController, createNativeCameraStream, createStartRtcRoomEvent, createStopRtcRoomEvent, createTaskUid, createTracksRtcRoomEvent, getCameraEnvironmentIssue, getFitContentRect, isCameraAccessError, mapTargetPointToCanvas, mapViewportPointToCoordinateSpace, models, notifyError, observeUploadPreviewMediaLayout, openNativeCameraStream, requestCameraMediaStream, stabilizeCameraVideoTrack };
2490
+ //# sourceMappingURL=chunk-F567ONBH.js.map
2491
+ //# sourceMappingURL=chunk-F567ONBH.js.map