@aixnn/aixautots 0.5.4 → 0.6.1

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 (44) hide show
  1. package/README.md +40 -23
  2. package/dist/{automation-queue-CKsueO9z.d.ts → automation-queue-BxrSIkG3.d.ts} +1 -1
  3. package/dist/{chunk-XNKC6HU3.js → chunk-6S3XLY5O.js} +3 -3
  4. package/dist/{chunk-UINEPEIE.js → chunk-A5VNENHD.js} +18 -6
  5. package/dist/{chunk-TATL3HTE.js → chunk-B2BOVLI6.js} +82 -21
  6. package/dist/{chunk-V4MXFPDX.js → chunk-BUW45GM2.js} +3 -3
  7. package/dist/{chunk-CVV7FOMQ.js → chunk-E7WMHM63.js} +10 -1
  8. package/dist/{chunk-OXIM6EYO.js → chunk-JTFZSFFA.js} +1 -1
  9. package/dist/{chunk-IJVNII5N.js → chunk-LAZ3RQ7X.js} +1 -1
  10. package/dist/{chunk-SVK2AY3J.js → chunk-M7CKUC4U.js} +49 -12
  11. package/dist/{chunk-BSHHYM72.js → chunk-P2Y655SL.js} +19 -8
  12. package/dist/{chunk-O34SNDQB.js → chunk-Q63FQ7B5.js} +4 -4
  13. package/dist/{chunk-64Q7BBIQ.js → chunk-T3QVYTOT.js} +10 -0
  14. package/dist/{chunk-YOT7HZBU.js → chunk-VKPKHUHU.js} +59 -16
  15. package/dist/{config-fsx4jlLK.d.ts → config-CLi5IhmO.d.ts} +6 -4
  16. package/dist/core/index.d.ts +6 -6
  17. package/dist/core/index.js +4 -4
  18. package/dist/device-session-CVT7OY4H.js +2 -0
  19. package/dist/i18n/index.js +1 -1
  20. package/dist/{mirror-session-DM-trg1F.d.ts → mirror-session-BP7Rd3Jk.d.ts} +4 -1
  21. package/dist/react/index.d.ts +8 -7
  22. package/dist/react/index.js +6 -6
  23. package/dist/{script-debugger-Cu_coj-h.d.ts → script-debugger-DtUGxK9i.d.ts} +1 -1
  24. package/dist/{task-agent-runner-CMq9Cir1.d.ts → task-agent-runner-DzV_OUZ7.d.ts} +1 -1
  25. package/dist/ui/billing.js +7 -7
  26. package/dist/ui/device-create.js +7 -7
  27. package/dist/ui/device-mirror.js +8 -8
  28. package/dist/ui/devices.d.ts +3 -3
  29. package/dist/ui/devices.js +11 -11
  30. package/dist/ui/editor.d.ts +1 -1
  31. package/dist/ui/editor.js +8 -8
  32. package/dist/ui/index.d.ts +12 -6
  33. package/dist/ui/index.js +118 -100
  34. package/dist/ui/inspector.js +7 -7
  35. package/dist/ui/market.js +7 -7
  36. package/dist/ui/mirror.d.ts +5 -3
  37. package/dist/ui/mirror.js +1 -1
  38. package/dist/ui/script-studio.js +7 -7
  39. package/dist/ui/scripts.js +7 -7
  40. package/dist/ui/tasks.js +11 -11
  41. package/package.json +112 -40
  42. package/styles.css +1 -1
  43. package/tailwind-preset.cjs +3 -3
  44. package/dist/device-session-W7I3WQXF.js +0 -2
package/README.md CHANGED
@@ -1,4 +1,21 @@
1
- # aixautots
1
+ # @aixnn/aixautots
2
+
3
+ 发布包已迁移到 npm 用户 `aixnn` 的 scope,完整包名为 `@aixnn/aixautots`。本仓库目录仍为 `aixautots/`,各子包入口保持不变,例如 `@aixnn/aixautots/core`。
4
+
5
+ ```sh
6
+ npm install @aixnn/aixautots
7
+ ```
8
+
9
+ 发布(在 `aixautots/` 目录,使用有权限的 npm 账号):
10
+
11
+ ```sh
12
+ npm run typecheck
13
+ npm test
14
+ npm run build
15
+ python3 ../scripts/npm-with-access-key.py publish --access public
16
+ ```
17
+
18
+ 发布脚本读取 `~/.aixenv` 的 `NPM_ACCESS_KEY`,通过临时 npm 配置使用令牌,结束后删除临时配置,不修改全局登录配置。令牌需拥有 `@aixnn/aixautots` 的发布权限;第三方项目也可使用自身 npm 凭据执行 `npm publish --access public`。发布后应运行 `npm view @aixnn/aixautots version dist-tags --json --prefer-online` 确认远端版本;若 registry 仍显示 `0.0.0-stage` 占位版本,正式版本尚不可安装,需检查 npm 的待审批发布状态。若令牌未允许绕过双重验证,npm 仍可能要求一次性验证码。
2
19
 
3
20
  aixautobot 的 TypeScript 客户端 SDK。core/react 是 headless 的数据/传输/鉴权层;ui 既提供细粒度
4
21
  部件,也提供**开箱即用的成品页面**(设备/任务/市场/脚本/编辑器/检查器)+ 一套可换肤主题,
@@ -8,47 +25,47 @@ aixautobot 的 TypeScript 客户端 SDK。core/react 是 headless 的数据/传
8
25
 
9
26
  | 子包 | 职责 |
10
27
  |---|---|
11
- | `aixautots/core` | 资源 REST 客户端(`AixClient`)+ 会话层(设备通道 / Flow / 镜像)+ 类型 + 错误 |
12
- | `aixautots/react` | 上述能力的 React hooks(`AixProvider` + 资源/会话 hooks) |
13
- | `aixautots/ui` | 设备向细粒度部件(`MirrorView`/`ControlBar`/`ScriptEditor`/`DebugConsole`/`ScriptPanel`) |
14
- | `aixautots/ui/primitives` | 基础件(`Button`/`Input`/`Select`/`Badge`/`Dialog`/`Popover`) |
15
- | `aixautots/ui/{devices,tasks,market,scripts,editor,inspector}` | 成品页面组件 |
16
- | `aixautots/nav` | 路由无关导航注入(`AixNavProvider`/`useAixNav`) |
17
- | `aixautots/i18n` | 内置 i18n(`AixI18nProvider`/`useAixT`,en/zh,无 i18next 依赖) |
18
- | `aixautots/tailwind-preset` · `aixautots/styles.css` | Tailwind 预设 + 主题 token |
28
+ | `@aixnn/aixautots/core` | 资源 REST 客户端(`AixClient`)+ 会话层(设备通道 / Flow / 镜像)+ 类型 + 错误 |
29
+ | `@aixnn/aixautots/react` | 上述能力的 React hooks(`AixProvider` + 资源/会话 hooks) |
30
+ | `@aixnn/aixautots/ui` | 设备向细粒度部件(`MirrorView`/`ControlBar`/`ScriptEditor`/`DebugConsole`/`ScriptPanel`) |
31
+ | `@aixnn/aixautots/ui/primitives` | 基础件(`Button`/`Input`/`Select`/`Badge`/`Dialog`/`Popover`) |
32
+ | `@aixnn/aixautots/ui/{devices,tasks,market,scripts,editor,inspector}` | 成品页面组件 |
33
+ | `@aixnn/aixautots/nav` | 路由无关导航注入(`AixNavProvider`/`useAixNav`) |
34
+ | `@aixnn/aixautots/i18n` | 内置 i18n(`AixI18nProvider`/`useAixT`,en/zh,无 i18next 依赖) |
35
+ | `@aixnn/aixautots/tailwind-preset` · `@aixnn/aixautots/styles.css` | Tailwind 预设 + 主题 token |
19
36
 
20
37
  ```bash
21
- npm i aixautots # peer: react(react 子包用);ui 子包另需 @uiw/react-codemirror
38
+ npm i @aixnn/aixautots # peer: react(react 子包用);ui 子包另需 @uiw/react-codemirror
22
39
  ```
23
40
 
24
41
  ## 接入(三步)
25
42
 
26
- 用到 `aixautots/ui` 的成品页面/部件时,按以下三步接入样式与运行时上下文:
43
+ 用到 `@aixnn/aixautots/ui` 的成品页面/部件时,按以下三步接入样式与运行时上下文:
27
44
 
28
45
  **1) 样式** —— Tailwind 预设 + 主题 token + content 扫描:
29
46
 
30
47
  ```js
31
48
  // tailwind.config.js
32
49
  module.exports = {
33
- presets: [require('aixautots/tailwind-preset')],
50
+ presets: [require('@aixnn/aixautots/tailwind-preset')],
34
51
  content: [
35
52
  './src/**/*.{ts,tsx}',
36
- './node_modules/aixautots/dist/**/*.js', // 关键:否则 aixautots 组件的类名不会被生成
53
+ './node_modules/@aixnn/aixautots/dist/**/*.js', // 关键:否则 aixautots 组件的类名不会被生成
37
54
  ],
38
55
  }
39
56
  ```
40
57
 
41
58
  ```css
42
59
  /* 入口 CSS */
43
- @import "aixautots/styles.css"; /* :root 浅色 + .dark 深色 token,可覆盖换肤 */
60
+ @import "@aixnn/aixautots/styles.css"; /* :root 浅色 + .dark 深色 token,可覆盖换肤 */
44
61
  ```
45
62
 
46
63
  **2) Provider** —— 在 `AixProvider` 内注入导航与语言:
47
64
 
48
65
  ```tsx
49
- import { AixProvider } from 'aixautots/react'
50
- import { AixNavProvider } from 'aixautots/nav'
51
- import { AixI18nProvider } from 'aixautots/i18n'
66
+ import { AixProvider } from '@aixnn/aixautots/react'
67
+ import { AixNavProvider } from '@aixnn/aixautots/nav'
68
+ import { AixI18nProvider } from '@aixnn/aixautots/i18n'
52
69
  import { useNavigate } from 'react-router-dom' // 任意路由库都行
53
70
 
54
71
  function Providers({ children }) {
@@ -66,8 +83,8 @@ function Providers({ children }) {
66
83
  **3) 用页面** —— 直接挂成品页面,路由参数以 props 传入:
67
84
 
68
85
  ```tsx
69
- import { DevicesPage } from 'aixautots/ui/devices'
70
- import { ScriptEditorPage } from 'aixautots/ui/editor'
86
+ import { DevicesPage } from '@aixnn/aixautots/ui/devices'
87
+ import { ScriptEditorPage } from '@aixnn/aixautots/ui/editor'
71
88
 
72
89
  <DevicesPage />
73
90
  <ScriptEditorPage scriptId={params.id} />
@@ -76,7 +93,7 @@ import { ScriptEditorPage } from 'aixautots/ui/editor'
76
93
  ## Quickstart
77
94
 
78
95
  ```ts
79
- import { AixClient } from 'aixautots/core'
96
+ import { AixClient } from '@aixnn/aixautots/core'
80
97
 
81
98
  const client = new AixClient({
82
99
  baseUrl: 'https://aixautobot.com',
@@ -90,7 +107,7 @@ const { run_id } = await client.fleet.start({ flow, device_ids: [devices[0].id]
90
107
  React:
91
108
 
92
109
  ```tsx
93
- import { AixProvider, useDevices } from 'aixautots/react'
110
+ import { AixProvider, useDevices } from '@aixnn/aixautots/react'
94
111
 
95
112
  function App() {
96
113
  return (
@@ -136,7 +153,7 @@ auth: [
136
153
  第三方前端(浏览器不持 project secret):后端铸 user JWT,前端用 `createCachedUserCredential` 自动缓存/刷新(按 `expiresIn` 或 JWT `exp`,并发去重):
137
154
 
138
155
  ```ts
139
- import { createCachedUserCredential } from 'aixautots/core'
156
+ import { createCachedUserCredential } from '@aixnn/aixautots/core'
140
157
 
141
158
  const auth = createCachedUserCredential({
142
159
  mint: () => fetch('/mint-token').then((r) => r.json()), // 你的后端 → { token, expiresIn? } 或 token 字符串
@@ -204,7 +221,7 @@ React:`useLlm()` → `{ generate, refine, explain, test }`(参考实现见 f
204
221
  ## 镜像
205
222
 
206
223
  ```ts
207
- import { MirrorSession } from 'aixautots/core'
224
+ import { MirrorSession } from '@aixnn/aixautots/core'
208
225
  const s = await MirrorSession.join(cfg, deviceId)
209
226
  s.onStream((stream) => { videoEl.srcObject = stream })
210
227
  s.sendInput({ t: 'tap', x, y }) // 归一坐标 [0,1]
@@ -1,4 +1,4 @@
1
- import { a as RunEventKind, A as AixConfig, R as ResolvedConfig } from './config-fsx4jlLK.js';
1
+ import { a as RunEventKind, A as AixConfig, R as ResolvedConfig } from './config-CLi5IhmO.js';
2
2
  import { S as Script } from './types-C2WXVcam.js';
3
3
 
4
4
  interface FlowSubmit {
@@ -1,8 +1,8 @@
1
1
  import { LogConsole } from './chunk-FW23FLAF.js';
2
2
  import { cn, Button, Select } from './chunk-EVHTAXQG.js';
3
- import { useDevices, useScripts, useScriptRun } from './chunk-O34SNDQB.js';
4
- import { variablesToSchema, normalizeDevices, schemaToVariables } from './chunk-V4MXFPDX.js';
5
- import { useClient } from './chunk-UINEPEIE.js';
3
+ import { useDevices, useScripts, useScriptRun } from './chunk-Q63FQ7B5.js';
4
+ import { variablesToSchema, normalizeDevices, schemaToVariables } from './chunk-BUW45GM2.js';
5
+ import { useClient } from './chunk-A5VNENHD.js';
6
6
  import { useMemo, useState, useEffect, useRef, useCallback } from 'react';
7
7
  import { Trash2, Plus, Play, Pause, Square, ArrowDownToLine, WrapText, ChevronRight, Save, XCircle, CheckCircle2, Loader2, Circle } from 'lucide-react';
8
8
  import CodeMirror, { EditorView } from '@uiw/react-codemirror';
@@ -1,5 +1,5 @@
1
- import { DeviceChannel, ScriptDebugger } from './chunk-OXIM6EYO.js';
2
- import { resolveConfig, AixClient, EnvRun } from './chunk-TATL3HTE.js';
1
+ import { DeviceChannel, ScriptDebugger } from './chunk-JTFZSFFA.js';
2
+ import { resolveConfig, AixClient, EnvRun } from './chunk-B2BOVLI6.js';
3
3
  import React, { createContext, useContext, useState, useRef, useEffect, useMemo, useCallback } from 'react';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
@@ -155,13 +155,14 @@ function useQuery(loader, deps) {
155
155
  }, []);
156
156
  return { data, loading, error, refetch: run, setData: patch };
157
157
  }
158
- function useEnvRun() {
158
+ function useEnvRun(beforeSetup) {
159
159
  const cfg = useAixConfig();
160
160
  const [reqId, setReqId] = useState(null);
161
161
  const [events, setEvents] = useState([]);
162
162
  const [finished, setFinished] = useState(null);
163
163
  const [done, setDone] = useState(false);
164
164
  const [error, setError] = useState(null);
165
+ const [preparing, setPreparing] = useState(false);
165
166
  const runRef = useRef(null);
166
167
  const mountedRef = useRef(true);
167
168
  useEffect(() => {
@@ -176,6 +177,7 @@ function useEnvRun() {
176
177
  async (start) => {
177
178
  runRef.current?.close();
178
179
  if (mountedRef.current) {
180
+ setPreparing(true);
179
181
  setError(null);
180
182
  setEvents([]);
181
183
  setFinished(null);
@@ -186,7 +188,12 @@ function useEnvRun() {
186
188
  const r = await start();
187
189
  runRef.current = r;
188
190
  r.on("event", (e) => {
189
- if (mountedRef.current) setEvents((prev) => [...prev, e]);
191
+ if (!mountedRef.current) return;
192
+ setEvents((prev) => [...prev, e]);
193
+ if (e.kind === "finished") {
194
+ setFinished(e);
195
+ setDone(true);
196
+ }
190
197
  });
191
198
  r.on("done", (f) => {
192
199
  if (mountedRef.current) {
@@ -200,18 +207,23 @@ function useEnvRun() {
200
207
  const err = e instanceof Error ? e : new Error(String(e));
201
208
  if (mountedRef.current) setError(err);
202
209
  throw err;
210
+ } finally {
211
+ if (mountedRef.current) setPreparing(false);
203
212
  }
204
213
  },
205
214
  []
206
215
  );
207
- const setup = useCallback((nodeId, input) => run(() => EnvRun.start(cfg, nodeId, "setup", input)), [cfg, run]);
216
+ const setup = useCallback((nodeId, input) => run(async () => {
217
+ await beforeSetup?.(nodeId);
218
+ return EnvRun.start(cfg, nodeId, "setup", input);
219
+ }), [cfg, run, beforeSetup]);
208
220
  const status = useCallback((nodeId, input) => run(() => EnvRun.start(cfg, nodeId, "status", input)), [cfg, run]);
209
221
  const teardown = useCallback((nodeId, input) => run(() => EnvRun.start(cfg, nodeId, "teardown", input)), [cfg, run]);
210
222
  const close = useCallback(() => {
211
223
  runRef.current?.close();
212
224
  runRef.current = null;
213
225
  }, []);
214
- return { reqId, events, finished, done, error, setup, status, teardown, close };
226
+ return { reqId, events, finished, done, error, preparing, setup, status, teardown, close };
215
227
  }
216
228
 
217
229
  export { AixProvider, useAixConfig, useClient, useDevice, useEnvRun, useQuery, useScript };
@@ -286,7 +286,9 @@ var ReconnectingSocket = class {
286
286
  this.attempt++;
287
287
  this.reconnectTimer = setTimeout(() => {
288
288
  this.reconnectTimer = null;
289
- void this.connect();
289
+ void this.connect().catch(() => {
290
+ if (!this.closed) this.scheduleReconnect();
291
+ });
290
292
  }, exp + jitter);
291
293
  }
292
294
  send(text) {
@@ -325,6 +327,8 @@ var EnvRun = class _EnvRun {
325
327
  this.doneFired = false;
326
328
  this.last = null;
327
329
  this.cursor = 0;
330
+ this.pollTimer = null;
331
+ this.closed = false;
328
332
  // `start()` opens the socket before callers can register listeners. Keep
329
333
  // frames received in that small window so the first Started/Step events do
330
334
  // not disappear and leave progress UIs stuck at 0%.
@@ -349,17 +353,26 @@ var EnvRun = class _EnvRun {
349
353
  let run = null;
350
354
  let cursor = 0;
351
355
  let processing = Promise.resolve();
352
- let processFrame;
356
+ const applyFrame = (frame) => {
357
+ if (frame.run_id !== data.req_id) return;
358
+ if (typeof frame.cursor !== "number") {
359
+ run?.onMessage(JSON.stringify(frame.event));
360
+ return;
361
+ }
362
+ if (frame.cursor <= cursor) return;
363
+ cursor = frame.cursor;
364
+ run?.onMessage(JSON.stringify({ cursor: frame.cursor, ...frame.event }));
365
+ };
353
366
  const fetchCatchup = async (after) => {
354
367
  let nextAfter = after;
355
368
  do {
356
369
  const page = await executionStreamEventsAfter(resolved, data.req_id, nextAfter);
357
- for (const event of page.events) await processFrame(event);
370
+ for (const event of page.events) applyFrame(event);
358
371
  nextAfter = page.next_cursor ?? cursor;
359
372
  if (!page.has_more) break;
360
373
  } while (true);
361
374
  };
362
- processFrame = async (frame) => {
375
+ const processFrame = async (frame) => {
363
376
  if (frame.run_id !== data.req_id) return;
364
377
  if (typeof frame.cursor !== "number") {
365
378
  run?.onMessage(JSON.stringify(frame.event));
@@ -368,10 +381,8 @@ var EnvRun = class _EnvRun {
368
381
  if (frame.cursor <= cursor) return;
369
382
  if (frame.cursor > cursor + 1) {
370
383
  await fetchCatchup(cursor);
371
- return processFrame(frame);
372
384
  }
373
- cursor = frame.cursor;
374
- run?.onMessage(JSON.stringify({ cursor: frame.cursor, ...frame.event }));
385
+ applyFrame(frame);
375
386
  };
376
387
  const socket = new ReconnectingSocket({
377
388
  // Fetch a new one-time ticket after every stream reconnect and resume
@@ -393,7 +404,34 @@ var EnvRun = class _EnvRun {
393
404
  }
394
405
  });
395
406
  run = new _EnvRun(data.req_id, data.stream ?? `/ws/execution/${data.req_id}`, socket);
396
- await socket.start();
407
+ const currentRun = run;
408
+ let failures = 0;
409
+ const poll = async () => {
410
+ if (currentRun.closed) return;
411
+ try {
412
+ await (processing = processing.catch(() => void 0).then(() => fetchCatchup(cursor)));
413
+ failures = 0;
414
+ } catch (error) {
415
+ if (++failures >= 3 && !currentRun.closed) {
416
+ currentRun.onMessage(JSON.stringify({
417
+ kind: "finished",
418
+ ok: false,
419
+ error: `Environment progress connection failed: ${String(error)}`,
420
+ hint: "The node may still be installing. Check its status before starting setup again."
421
+ }));
422
+ }
423
+ }
424
+ if (!currentRun.closed) currentRun.pollTimer = setTimeout(() => {
425
+ void poll();
426
+ }, 3e3);
427
+ };
428
+ currentRun.pollTimer = setTimeout(() => {
429
+ void poll();
430
+ }, 3e3);
431
+ try {
432
+ await socket.start();
433
+ } catch {
434
+ }
397
435
  return run;
398
436
  }
399
437
  on(event, cb) {
@@ -435,10 +473,15 @@ var EnvRun = class _EnvRun {
435
473
  this.doneFired = true;
436
474
  this.last = ev;
437
475
  for (const cb of this.doneListeners) cb(this.last);
438
- this.socket.close();
476
+ this.close();
439
477
  }
440
478
  }
441
479
  close() {
480
+ this.closed = true;
481
+ if (this.pollTimer !== null) {
482
+ clearTimeout(this.pollTimer);
483
+ this.pollTimer = null;
484
+ }
442
485
  this.socket.close();
443
486
  }
444
487
  };
@@ -453,7 +496,17 @@ function summarizeEnv(events) {
453
496
  for (const e of events) {
454
497
  if (e.kind === "started") {
455
498
  total = e.total;
456
- e.steps.forEach((s, i) => meta.set(i, s));
499
+ e.steps.forEach((s, i) => {
500
+ meta.set(i, s);
501
+ const existing = steps.get(i);
502
+ steps.set(i, existing ? { ...existing, label: s.label } : {
503
+ index: i,
504
+ id: s.id,
505
+ label: s.label,
506
+ state: "pending",
507
+ pct: 0
508
+ });
509
+ });
457
510
  } else if (e.kind === "step") {
458
511
  const m = meta.get(e.index);
459
512
  steps.set(e.index, {
@@ -1307,8 +1360,15 @@ var ApiTokensApi = class {
1307
1360
  };
1308
1361
 
1309
1362
  // src/core/local-node.ts
1310
- function toWs(httpBase) {
1311
- return httpBase.replace(/^http/, "ws");
1363
+ function validatedBackendUrl(base) {
1364
+ base = base.trim();
1365
+ const url = new URL(base);
1366
+ const hostname = url.hostname.replace(/^\[|\]$/g, "");
1367
+ const loopback = hostname === "localhost" || hostname === "::1" || /^127(?:\.\d{1,3}){3}$/.test(hostname);
1368
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback) || url.username || url.password || url.href.includes("?") || url.href.includes("#")) {
1369
+ throw new Error("backendUrl must be an HTTPS base URL (HTTP is allowed only for loopback development) without credentials, query or fragment");
1370
+ }
1371
+ return base.replace(/\/+$/, "");
1312
1372
  }
1313
1373
  var LocalNodeController = class {
1314
1374
  constructor(client, opts) {
@@ -1319,16 +1379,17 @@ var LocalNodeController = class {
1319
1379
  /** Last best-effort failure captured by `ensure()`, for host UIs that want to surface it. */
1320
1380
  this.lastError = null;
1321
1381
  }
1322
- async startHost(token, backendWs) {
1323
- const opts = { token, backendWs };
1382
+ async startHost(token, backendUrl) {
1383
+ const opts = { token, backendUrl };
1324
1384
  if (this.opts.requireSdkUpdate !== void 0) opts.requireSdkUpdate = this.opts.requireSdkUpdate;
1325
1385
  await this.opts.host.start(opts);
1326
1386
  }
1327
1387
  get scope() {
1328
1388
  return this.opts.scope ?? "personal";
1329
1389
  }
1330
- get backendWs() {
1331
- return this.opts.backendWs ?? toWs(this.client.cfg.baseUrl);
1390
+ get backendUrl() {
1391
+ if ("backendWs" in this.opts) throw new Error("backendWs is no longer supported; use backendUrl with an HTTPS base URL");
1392
+ return validatedBackendUrl(this.opts.backendUrl ?? this.client.cfg.baseUrl);
1332
1393
  }
1333
1394
  /** Ensure THIS machine runs as its OWN node owned by the signed-in caller,
1334
1395
  * starting it via the host. The node is keyed by machine name (`nameHint`), so
@@ -1340,8 +1401,8 @@ var LocalNodeController = class {
1340
1401
  const { host } = this.opts;
1341
1402
  this.lastError = null;
1342
1403
  try {
1404
+ const backendUrl = this.backendUrl;
1343
1405
  const status = await host.status();
1344
- const ws = this.backendWs;
1345
1406
  const nodes = await this.client.nodes.list();
1346
1407
  const mine = nodes.filter((n) => n.is_owner && n.scope === this.scope);
1347
1408
  const machine = this.opts.nameHint ?? "desktop-node";
@@ -1353,16 +1414,16 @@ var LocalNodeController = class {
1353
1414
  await host.stop();
1354
1415
  }
1355
1416
  if (status.hasToken && status.nodeId && ours && status.nodeId === ours.id) {
1356
- await this.startHost(null, ws);
1417
+ await this.startHost(null, backendUrl);
1357
1418
  return await this.bind(status.nodeId);
1358
1419
  }
1359
1420
  if (ours) {
1360
1421
  const r2 = await this.client.nodes.rotateToken(ours.id);
1361
- await this.startHost(r2.token, ws);
1422
+ await this.startHost(r2.token, backendUrl);
1362
1423
  return await this.bind(ours.id);
1363
1424
  }
1364
1425
  const r = await this.client.nodes.register({ name: machine, scope: this.scope });
1365
- await this.startHost(r.token, ws);
1426
+ await this.startHost(r.token, backendUrl);
1366
1427
  return await this.bind(r.id);
1367
1428
  } catch (e) {
1368
1429
  this.lastError = e;
@@ -1500,7 +1561,7 @@ var AixClient = class {
1500
1561
  * 即可,不必回依赖 client 实例)。
1501
1562
  */
1502
1563
  async deviceSession(deviceId, opts = {}) {
1503
- const { DeviceSession } = await import('./device-session-W7I3WQXF.js');
1564
+ const { DeviceSession } = await import('./device-session-CVT7OY4H.js');
1504
1565
  return DeviceSession.open(this.cfg, deviceId, opts);
1505
1566
  }
1506
1567
  };
@@ -1,6 +1,6 @@
1
- import { getIceServers, mintViewerToken } from './chunk-IJVNII5N.js';
2
- import { FlowRun } from './chunk-OXIM6EYO.js';
3
- import { resolveConfig, ReconnectingSocket, joinUrl } from './chunk-TATL3HTE.js';
1
+ import { getIceServers, mintViewerToken } from './chunk-LAZ3RQ7X.js';
2
+ import { FlowRun } from './chunk-JTFZSFFA.js';
3
+ import { resolveConfig, ReconnectingSocket, joinUrl } from './chunk-B2BOVLI6.js';
4
4
 
5
5
  // src/core/automation-queue.ts
6
6
  async function submitBatch(cfg, config) {
@@ -12,6 +12,7 @@ function MirrorView({
12
12
  onFirstFrame,
13
13
  onResize,
14
14
  continuousTouch = false,
15
+ volume = 0,
15
16
  className
16
17
  }) {
17
18
  const videoRef = useRef(null);
@@ -24,6 +25,14 @@ function MirrorView({
24
25
  if (v) v.srcObject = stream;
25
26
  firstFrameRef.current = false;
26
27
  }, [stream]);
28
+ useEffect(() => {
29
+ const v = videoRef.current;
30
+ if (!v) return;
31
+ v.volume = Math.max(0, Math.min(1, volume));
32
+ v.muted = volume === 0;
33
+ void v.play()?.catch(() => {
34
+ });
35
+ }, [volume, stream]);
27
36
  const handleFrameReady = useCallback(() => {
28
37
  if (firstFrameRef.current) return;
29
38
  const v = videoRef.current;
@@ -112,7 +121,7 @@ function MirrorView({
112
121
  ref: videoRef,
113
122
  autoPlay: true,
114
123
  playsInline: true,
115
- muted: true,
124
+ muted: volume === 0,
116
125
  tabIndex: keyboard ? 0 : -1,
117
126
  className,
118
127
  onPointerDown: handlePointerDown,
@@ -1,4 +1,4 @@
1
- import { joinUrl, AixAuthError, AixLocked, AixError, resolveConfig, ReconnectingSocket, AixTimeout, parseIncoming, isRetFrame, errorFromRet, isFridaEventFrame, isScriptletEventFrame, isStatusFrame, executionWsTicketUrl, isExecutionFrame, executionStreamEventsAfter } from './chunk-TATL3HTE.js';
1
+ import { joinUrl, AixAuthError, AixLocked, AixError, resolveConfig, ReconnectingSocket, AixTimeout, parseIncoming, isRetFrame, errorFromRet, isFridaEventFrame, isScriptletEventFrame, isStatusFrame, executionWsTicketUrl, isExecutionFrame, executionStreamEventsAfter } from './chunk-B2BOVLI6.js';
2
2
 
3
3
  // src/core/ws-access.ts
4
4
  async function mintDeviceAccess(cfg, deviceId) {
@@ -1,4 +1,4 @@
1
- import { joinUrl, AixAuthError, AixError, AixClient, resolveConfig, DevicesApi, RestClient, ReconnectingSocket } from './chunk-TATL3HTE.js';
1
+ import { joinUrl, AixAuthError, AixError, AixClient, resolveConfig, DevicesApi, RestClient, ReconnectingSocket } from './chunk-B2BOVLI6.js';
2
2
 
3
3
  // src/core/webrtc-rest.ts
4
4
  async function getIceServers(cfg) {
@@ -1,6 +1,6 @@
1
- import { MirrorView, ControlBar } from './chunk-CVV7FOMQ.js';
2
- import { useMirror, useDevices } from './chunk-O34SNDQB.js';
3
- import { useClient } from './chunk-UINEPEIE.js';
1
+ import { MirrorView, ControlBar } from './chunk-E7WMHM63.js';
2
+ import { useMirror, useDevices } from './chunk-Q63FQ7B5.js';
3
+ import { useClient } from './chunk-A5VNENHD.js';
4
4
  import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
5
5
  import { RotateCw, Minimize2, Maximize2, X } from 'lucide-react';
6
6
  import { jsxs, jsx } from 'react/jsx-runtime';
@@ -128,6 +128,7 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
128
128
  const [hasFrame, setHasFrame] = useState(false);
129
129
  useEffect(() => {
130
130
  setHasFrame(false);
131
+ setVolume(0);
131
132
  }, [deviceId, stream]);
132
133
  useEffect(() => {
133
134
  setSize(DEFAULT_SIZE);
@@ -143,18 +144,31 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
143
144
  },
144
145
  [setQuality]
145
146
  );
146
- const [landscape, setLandscape] = useState(false);
147
+ const landscape = size.width > size.height;
148
+ const [volume, setVolume] = useState(0);
149
+ const audioEnabledRef = useRef(false);
150
+ useEffect(() => () => {
151
+ if (audioEnabledRef.current) sendInput({ t: "audio", enabled: false });
152
+ audioEnabledRef.current = false;
153
+ }, [stream, sendInput]);
154
+ const [hasAudio, setHasAudio] = useState(false);
155
+ useEffect(() => {
156
+ const update = () => setHasAudio(!!stream?.getAudioTracks().some((t) => t.readyState === "live"));
157
+ update();
158
+ stream?.addEventListener("addtrack", update);
159
+ stream?.addEventListener("removetrack", update);
160
+ return () => {
161
+ stream?.removeEventListener("addtrack", update);
162
+ stream?.removeEventListener("removetrack", update);
163
+ };
164
+ }, [stream]);
147
165
  const toggleOrientation = useCallback(() => {
148
- setLandscape((prev) => {
149
- const next = !prev;
150
- sendInput({ t: "rotate", orientation: next ? "landscape" : "portrait" });
151
- return next;
152
- });
153
- }, [sendInput]);
166
+ sendInput({ t: "rotate", orientation: landscape ? "portrait" : "landscape" });
167
+ }, [sendInput, landscape]);
154
168
  useEffect(() => {
155
169
  manualRef.current = false;
156
170
  setProfile("balanced");
157
- setLandscape(false);
171
+ setVolume(0);
158
172
  }, [deviceId]);
159
173
  const profileRef = useRef(profile);
160
174
  useEffect(() => {
@@ -212,6 +226,7 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
212
226
  MirrorView,
213
227
  {
214
228
  stream,
229
+ volume: volume / 100,
215
230
  deviceSize: size,
216
231
  onInput: sendInput,
217
232
  onFirstFrame: handleFirstFrame,
@@ -232,7 +247,7 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
232
247
  }
233
248
  )
234
249
  ] }),
235
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
250
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-center gap-2", children: [
236
251
  /* @__PURE__ */ jsx(
237
252
  ControlBar,
238
253
  {
@@ -252,6 +267,28 @@ function MirrorSurface({ deviceId, platform = "android", onSize, videoAspect, sh
252
267
  children: Object.keys(PROFILE_LABELS).map((p) => /* @__PURE__ */ jsx("option", { value: p, children: PROFILE_LABELS[p] }, p))
253
268
  }
254
269
  ),
270
+ /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-1 text-xs text-foreground", children: [
271
+ "\u97F3\u91CF",
272
+ /* @__PURE__ */ jsx(
273
+ "input",
274
+ {
275
+ type: "range",
276
+ "aria-label": "\u64AD\u653E\u97F3\u91CF",
277
+ min: 0,
278
+ max: 100,
279
+ value: volume,
280
+ disabled: !hasAudio,
281
+ onChange: (e) => {
282
+ const next = Number(e.target.value);
283
+ if (audioEnabledRef.current !== next > 0) sendInput({ t: "audio", enabled: next > 0 });
284
+ audioEnabledRef.current = next > 0;
285
+ setVolume(next);
286
+ },
287
+ className: "w-20"
288
+ }
289
+ ),
290
+ /* @__PURE__ */ jsx("span", { children: hasAudio ? `${volume}%` : "\u65E0\u97F3\u9891\u6D41" })
291
+ ] }),
255
292
  platform === "android" && /* @__PURE__ */ jsxs(
256
293
  "button",
257
294
  {