@aixnn/aixautots 0.5.3 → 0.6.0

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 (57) hide show
  1. package/README.md +40 -23
  2. package/dist/ScriptStudio-DaCqOF5H.d.ts +43 -0
  3. package/dist/agent-runner-V60B0is1.d.ts +57 -0
  4. package/dist/automation-queue-BxrSIkG3.d.ts +72 -0
  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-SVK2AY3J.js → chunk-HPKXW5IC.js} +2 -2
  8. package/dist/{chunk-XNKC6HU3.js → chunk-IZMWCTAP.js} +3 -3
  9. package/dist/{chunk-OXIM6EYO.js → chunk-JTFZSFFA.js} +1 -1
  10. package/dist/{chunk-O34SNDQB.js → chunk-JY7O77ML.js} +4 -4
  11. package/dist/{chunk-IJVNII5N.js → chunk-LAZ3RQ7X.js} +1 -1
  12. package/dist/{chunk-YOT7HZBU.js → chunk-QPNH7B7P.js} +6 -6
  13. package/dist/{chunk-UINEPEIE.js → chunk-SSE4IYA4.js} +12 -5
  14. package/dist/{chunk-BSHHYM72.js → chunk-XB4MS2A4.js} +2 -2
  15. package/dist/config-CLi5IhmO.d.ts +1380 -0
  16. package/dist/coords-LPR_MPyp.d.ts +22 -0
  17. package/dist/core/index.d.ts +135 -0
  18. package/dist/core/index.js +4 -4
  19. package/dist/device-normalize-BaThgnH7.d.ts +43 -0
  20. package/dist/device-session-CVT7OY4H.js +2 -0
  21. package/dist/i18n/index.d.ts +30 -0
  22. package/dist/mirror-session-7hrjaLnF.d.ts +108 -0
  23. package/dist/nav/index.d.ts +19 -0
  24. package/dist/react/index.d.ts +488 -0
  25. package/dist/react/index.js +6 -6
  26. package/dist/script-debugger-DtUGxK9i.d.ts +114 -0
  27. package/dist/task-agent-runner-DzV_OUZ7.d.ts +160 -0
  28. package/dist/types-C2WXVcam.d.ts +1005 -0
  29. package/dist/ui/billing.d.ts +48 -0
  30. package/dist/ui/billing.js +6 -6
  31. package/dist/ui/device-create.d.ts +55 -0
  32. package/dist/ui/device-create.js +7 -7
  33. package/dist/ui/device-mirror.d.ts +42 -0
  34. package/dist/ui/device-mirror.js +7 -7
  35. package/dist/ui/devices.d.ts +223 -0
  36. package/dist/ui/devices.js +9 -9
  37. package/dist/ui/editor.d.ts +64 -0
  38. package/dist/ui/editor.js +7 -7
  39. package/dist/ui/index.d.ts +108 -0
  40. package/dist/ui/index.js +83 -90
  41. package/dist/ui/inspector.d.ts +5 -0
  42. package/dist/ui/inspector.js +6 -6
  43. package/dist/ui/market.d.ts +10 -0
  44. package/dist/ui/market.js +6 -6
  45. package/dist/ui/mirror.d.ts +52 -0
  46. package/dist/ui/primitives/index.d.ts +101 -0
  47. package/dist/ui/script-studio.d.ts +85 -0
  48. package/dist/ui/script-studio.js +7 -7
  49. package/dist/ui/scripts.d.ts +18 -0
  50. package/dist/ui/scripts.js +6 -6
  51. package/dist/ui/tasks.d.ts +10 -0
  52. package/dist/ui/tasks.js +9 -9
  53. package/dist/use-script-run-Diay7ibY.d.ts +50 -0
  54. package/package.json +112 -40
  55. package/styles.css +1 -1
  56. package/tailwind-preset.cjs +3 -3
  57. 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]
@@ -0,0 +1,43 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /** Context handed to host-injected slots (agent / inspector). */
5
+ interface ScriptStudioSlotContext {
6
+ /** Persisted script id (undefined until first save). */
7
+ scriptId?: string;
8
+ /** Currently selected run device id. */
9
+ deviceId: string | null;
10
+ /** Resolved platform of the selected device ('android' | 'ios' | …). */
11
+ platform: 'android' | 'ios';
12
+ /** Current editor source. */
13
+ code: string;
14
+ /** Replace the entire editor source. */
15
+ setCode: (code: string) => void;
16
+ /** Append a snippet to the editor source (newline-separated). */
17
+ insertSnippet: (snippet: string) => void;
18
+ /** Open the host-injected device inspector (same as the header button). */
19
+ openInspector: () => void;
20
+ }
21
+ interface ScriptStudioProps {
22
+ /** Route param: the script to open. Undefined ⇒ a fresh "New Script". */
23
+ scriptId?: string;
24
+ /** Called after the first create assigns an id, so the host can switch the
25
+ * URL to `/editor/:id` (the SDK does not depend on a router). */
26
+ onScriptIdChange?: (id: string) => void;
27
+ /** Host-injected LLM agent panel (right column). Not rendered if omitted. */
28
+ renderAgentPanel?: (ctx: ScriptStudioSlotContext) => ReactNode;
29
+ /** Host-injected device inspector (modal/overlay). Not rendered if omitted.
30
+ * `open`/`onClose` are driven by the studio's "设备/Inspector" button. */
31
+ renderInspector?: (ctx: ScriptStudioSlotContext & {
32
+ open: boolean;
33
+ onClose: () => void;
34
+ }) => ReactNode;
35
+ /** localStorage key for the resizable console height. */
36
+ consoleHeightStorageKey?: string;
37
+ /** Extra controls rendered at the right end of the header (e.g. a language
38
+ * toggle). The studio itself stays app-chrome-agnostic. */
39
+ headerExtra?: ReactNode;
40
+ }
41
+ declare function ScriptStudio({ scriptId, onScriptIdChange, renderAgentPanel, renderInspector, consoleHeightStorageKey, headerExtra, }: ScriptStudioProps): react.JSX.Element;
42
+
43
+ export { type ScriptStudioProps as S, type ScriptStudioSlotContext as a, ScriptStudio as b };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * LLM agent 传输的注入接口。`AgentPanel` 的 UI 与可移植逻辑在 aixautots 内,但「如何
3
+ * 真正跑一个本地 agent」是宿主特有的(桌面端经 Tauri IPC spawn claude/codex CLI,
4
+ * 经事件流式回传)——所以这部分由宿主实现 `AgentRunner` 注入,aixautots 不依赖 Tauri。
5
+ *
6
+ * 非桌面/无本地 agent 的宿主可传 `available: false`,面板会显示「需在桌面应用中使用」。
7
+ *
8
+ * ── 实现是可替换的:Tauri 只是其中一种 ──
9
+ * 本接口刻意与传输解耦,`AgentPanel` 不知底层是本机还是服务端。已有/可有的实现:
10
+ * 1) 本机 CLI(现状):桌面端 `frontend/src/lib/agentRunner.ts` 用 Tauri `invoke`/`listen`
11
+ * spawn 本机 claude/codex CLI(密钥/算力在用户机器)。
12
+ * 2) 服务端 agent:服务器跑 claude/codex CLI(密钥/算力在后端),HTTP 起停 + SSE 流式
13
+ * 回传。**SDK 已内置实现** `createBackendAgentRunner(client)`(见 `backend-agent-runner.ts`);
14
+ * editor 薄壳按环境切换即可,aixautots 与 AgentPanel 零改动:
15
+ * agentRunner={isTauri() ? tauriAgentRunner : createBackendAgentRunner(client)}
16
+ * (仅待后端落地 `/api/agent/*` 端点;客户端侧已就绪。)
17
+ *
18
+ * 后端端点契约(详见 `backend-agent-runner.ts`):`POST /api/agent/{start,send,stop}` +
19
+ * `GET /api/agent/stream`(SSE);事件载荷映射到本文件的 `AgentStreamEvent`
20
+ * (`stream: 'stdout'|'stderr'|'done'`,done 带最终 `script` 全文)。鉴权复用 user JWT。
21
+ * 失败可经 `stream:'stderr'` 文本上报,或 `done` 不带 `script` 表示无产出。
22
+ */
23
+ type AgentKind = 'claude' | 'codex';
24
+ interface AgentStreamEvent {
25
+ /** 该事件所属脚本 id(面板按当前 scriptId 过滤)。 */
26
+ scriptId: string;
27
+ stream: 'stdout' | 'stderr' | 'done';
28
+ /** stdout/stderr 增量文本。 */
29
+ chunk?: string;
30
+ /** done 时回带的最终 script.ts 全文(非空且有变化则替换编辑器)。 */
31
+ script?: string;
32
+ }
33
+ interface AgentSendRequest {
34
+ agent: AgentKind;
35
+ scriptId: string;
36
+ code: string;
37
+ deviceId: string;
38
+ userMsg: string;
39
+ /** 本轮是否是会话首轮(决定 start vs send 语义,由实现自行处理)。 */
40
+ isFirst: boolean;
41
+ }
42
+ interface AgentRunner {
43
+ /** 本机 agent 后端是否可用(如桌面/Tauri 环境)。false 时面板显示提示而不渲染交互。 */
44
+ available: boolean;
45
+ /** 可选:从宿主设置读默认 agent / 权限模式(面板挂载时调用)。 */
46
+ defaults?: () => Promise<{
47
+ agent?: AgentKind;
48
+ }>;
49
+ /** 启动或继续一轮 agent。权限模式等宿主细节由实现内部处理。 */
50
+ send: (req: AgentSendRequest) => Promise<void>;
51
+ /** 停止进行中的一轮。 */
52
+ stop: (scriptId: string) => Promise<void>;
53
+ /** 订阅流式输出;返回取消订阅函数。面板内部按 scriptId 过滤事件。 */
54
+ subscribe: (on: (ev: AgentStreamEvent) => void) => () => void;
55
+ }
56
+
57
+ export type { AgentKind as A, AgentRunner as a, AgentSendRequest as b, AgentStreamEvent as c };
@@ -0,0 +1,72 @@
1
+ import { a as RunEventKind, A as AixConfig, R as ResolvedConfig } from './config-CLi5IhmO.js';
2
+ import { S as Script } from './types-C2WXVcam.js';
3
+
4
+ interface FlowSubmit {
5
+ /** Inline flow JSON (XOR scriptId). */
6
+ flow?: unknown;
7
+ /** Reference a stored script by id (XOR flow). */
8
+ scriptId?: string;
9
+ /** Internal device UUIDs (non-empty). */
10
+ deviceIds: string[];
11
+ params?: unknown;
12
+ mode?: unknown;
13
+ expiresIn?: number;
14
+ }
15
+ /** A normalized per-device execution event. */
16
+ interface FlowEvent {
17
+ deviceId: string;
18
+ event: RunEventKind;
19
+ }
20
+ declare class FlowRun {
21
+ readonly taskId: string;
22
+ readonly targets: string[];
23
+ private readonly socket;
24
+ private readonly eventListeners;
25
+ private readonly doneListeners;
26
+ private readonly finished;
27
+ private doneFired;
28
+ private cursor;
29
+ private constructor();
30
+ static submit(cfg: AixConfig | ResolvedConfig, body: FlowSubmit): Promise<FlowRun>;
31
+ on(event: 'event', cb: (e: FlowEvent) => void): () => void;
32
+ on(event: 'done', cb: () => void): () => void;
33
+ /** Called (via microtask) when submit() returns targets:[]. */
34
+ fireDoneIfEmpty(): void;
35
+ private onMessage;
36
+ close(): void;
37
+ }
38
+
39
+ /** 批次派发模式。`'round-robin'` 为默认(行分摊到设备);`'broadcast'` 每行全量。 */
40
+ type QueueMode = 'round-robin' | 'broadcast';
41
+ /** 一个批次的输入。`script` 与 `flow` 二选一(与 `FlowRun`/后端的 flow XOR
42
+ * script 约束一致)。`rows` 每项是一组动态参数值(覆写 `flow.variables`);空
43
+ * 数组等价于「无参数」单组(提交一次,沿用脚本自带 variables)。 */
44
+ interface BatchConfig {
45
+ /** 引用已存库脚本(XOR flow)。 */
46
+ script?: Pick<Script, 'id'> & {
47
+ id: string;
48
+ };
49
+ /** 内联 flow JSON(XOR script)。 */
50
+ flow?: unknown;
51
+ /** 每行 = 一组动态参数(如不同账户)。空 ⇒ 视作单组空参数,提交一次。 */
52
+ rows: Array<Record<string, unknown>>;
53
+ /** 目标设备内部 UUID(非空)。 */
54
+ deviceIds: string[];
55
+ /** 派发模式,默认 `'round-robin'`。 */
56
+ mode?: QueueMode;
57
+ /** 透传给 `FlowRun.submit` 的任务过期秒数(可选)。 */
58
+ expiresIn?: number;
59
+ }
60
+ /** 把 rows×mode 展开为多次 `FlowRun.submit`,返回每次提交得到的 task id 顺序数组。
61
+ * 逐行顺序提交(保留行序);任一行失败即抛出(已提交的行不回滚——它们是独立任务)。 */
62
+ declare function submitBatch(cfg: AixConfig | ResolvedConfig, config: BatchConfig): Promise<string[]>;
63
+ /** 自动化队列的薄封装:绑定一份 config,`submit(batch)` 即提交。无状态——
64
+ * 追踪/暂停/恢复由 `TasksApi`(`useAutomationQueue`)负责。 */
65
+ declare class AutomationQueue {
66
+ private readonly cfg;
67
+ constructor(cfg: AixConfig | ResolvedConfig);
68
+ /** 展开并提交一个批次,返回 task id 数组。见 [`submitBatch`]。 */
69
+ submit(config: BatchConfig): Promise<string[]>;
70
+ }
71
+
72
+ export { AutomationQueue as A, type BatchConfig as B, type FlowEvent as F, type QueueMode as Q, FlowRun as a, type FlowSubmit as b, submitBatch as s };
@@ -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) {
@@ -1,6 +1,6 @@
1
1
  import { MirrorView, ControlBar } from './chunk-CVV7FOMQ.js';
2
- import { useMirror, useDevices } from './chunk-O34SNDQB.js';
3
- import { useClient } from './chunk-UINEPEIE.js';
2
+ import { useMirror, useDevices } from './chunk-JY7O77ML.js';
3
+ import { useClient } from './chunk-SSE4IYA4.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';
@@ -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-JY7O77ML.js';
4
+ import { variablesToSchema, normalizeDevices, schemaToVariables } from './chunk-BUW45GM2.js';
5
+ import { useClient } from './chunk-SSE4IYA4.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,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,7 +1,7 @@
1
- import { MirrorSession, normalizeDevices, submitBatch } from './chunk-V4MXFPDX.js';
2
- import { useDevice, useAixConfig, useClient, useQuery } from './chunk-UINEPEIE.js';
3
- import { FlowRun } from './chunk-OXIM6EYO.js';
4
- import { isFleetRunTerminal, resolveConfig, joinUrl, AixAuthError, AixError, detectEnvOs, EnvRun, summarizeEnv, ReconnectingSocket, executionWsTicketUrl } from './chunk-TATL3HTE.js';
1
+ import { MirrorSession, normalizeDevices, submitBatch } from './chunk-BUW45GM2.js';
2
+ import { useDevice, useAixConfig, useClient, useQuery } from './chunk-SSE4IYA4.js';
3
+ import { FlowRun } from './chunk-JTFZSFFA.js';
4
+ import { isFleetRunTerminal, resolveConfig, joinUrl, AixAuthError, AixError, detectEnvOs, EnvRun, summarizeEnv, ReconnectingSocket, executionWsTicketUrl } from './chunk-B2BOVLI6.js';
5
5
  import { createContext, useState, useRef, useEffect, useCallback, useMemo, createElement, useContext } from 'react';
6
6
 
7
7
  function useCommands(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,12 +1,12 @@
1
1
  import { useAixT } from './chunk-64Q7BBIQ.js';
2
2
  import { LogConsole } from './chunk-FW23FLAF.js';
3
- import { MirrorSurface, DeviceMirror } from './chunk-SVK2AY3J.js';
3
+ import { MirrorSurface, DeviceMirror } from './chunk-HPKXW5IC.js';
4
4
  import { ControlBar, MirrorView } from './chunk-CVV7FOMQ.js';
5
- import { createProxyProbeGuard, proxySummaryFromDevice, isProxyApplyStatus, proxyCapabilityReason, proxyProbeExitIp, proxyProbeMessage, DeviceCreate, isProxyProbeUnsupported, isRedactedProxyUrl, isSupportedProxyUrl, redactProxyUrl } from './chunk-BSHHYM72.js';
5
+ import { createProxyProbeGuard, proxySummaryFromDevice, isProxyApplyStatus, proxyCapabilityReason, proxyProbeExitIp, proxyProbeMessage, DeviceCreate, isProxyProbeUnsupported, isRedactedProxyUrl, isSupportedProxyUrl, redactProxyUrl } from './chunk-XB4MS2A4.js';
6
6
  import { cn, Badge, Button, Dialog, Input, Popover, Select, useToast, ToastViewport, Drawer } from './chunk-EVHTAXQG.js';
7
- import { useDevicesView, useShortcutsView, GROUP_MIRROR_MAX, useGroupMirror, useScripts, useFleetRun, useTaskAgentRun, preflightTaskAgentDevice, createAgentTaskRunner, useNodesView } from './chunk-O34SNDQB.js';
8
- import { DeviceSession, pushFile, pullFile } from './chunk-IJVNII5N.js';
9
- import { useClient } from './chunk-UINEPEIE.js';
7
+ import { useDevicesView, useShortcutsView, GROUP_MIRROR_MAX, useGroupMirror, useScripts, useFleetRun, useTaskAgentRun, preflightTaskAgentDevice, createAgentTaskRunner, useNodesView } from './chunk-JY7O77ML.js';
8
+ import { DeviceSession, pushFile, pullFile } from './chunk-LAZ3RQ7X.js';
9
+ import { useClient } from './chunk-SSE4IYA4.js';
10
10
  import { useState, useRef, useCallback, useEffect, useMemo, useLayoutEffect } from 'react';
11
11
  import * as Icons from 'lucide-react';
12
12
  import { Monitor, Eye, Play, Power, RefreshCw, Server, Pencil, Trash2, FolderPlus, Upload, ArrowUp, Folder, File, Download, Dices, ShieldCheck, AlertTriangle, X, Crown, RotateCcw, Square, Plus, Search, LayoutGrid, List, ChevronLeft, Link, Link2Off, Terminal as Terminal$1, PackagePlus, MonitorPlay, ChevronRight, ChevronDown, PlusSquare, Maximize2, Info, ChevronsLeft, ChevronsRight, Check, Copy, Tablet, Smartphone } from 'lucide-react';
@@ -5674,7 +5674,7 @@ function NodeRegister({ open, onClose }) {
5674
5674
  setBusy(false);
5675
5675
  }
5676
5676
  };
5677
- const instructions = token ? `export AIXAUTOSDK_BACKEND_WS=wss://aixautobot.com
5677
+ const instructions = token ? `export AIXAUTOSDK_BACKEND_URL=${client.cfg.baseUrl.replace(/\/+$/, "")}
5678
5678
  export AIXAUTOSDK_NODE_TOKEN=${token}
5679
5679
  aixautobot node` : "";
5680
5680
  return /* @__PURE__ */ jsx(