@aixnn/aixautots 0.6.13 → 0.6.20

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 (55) hide show
  1. package/dist/{automation-queue-BFWqw32O.d.ts → automation-queue-GhfQtZLm.d.ts} +2 -2
  2. package/dist/{chunk-S5N4EOCP.js → chunk-3OBCSW2J.js} +1 -1
  3. package/dist/{chunk-SKI7TINK.js → chunk-4NRIEM5Z.js} +269 -53
  4. package/dist/{chunk-VMA3QOYR.js → chunk-7RQTSTR6.js} +1 -1
  5. package/dist/{chunk-HMDUSVQ3.js → chunk-DAU3FVCV.js} +4 -4
  6. package/dist/chunk-DTXXQPOU.js +693 -0
  7. package/dist/{chunk-7BJPVSEZ.js → chunk-ED6CB3B4.js} +222 -12
  8. package/dist/{chunk-Q5I63UYT.js → chunk-FJKMRWYC.js} +97 -75
  9. package/dist/{chunk-U4QW45MB.js → chunk-H7KZUU67.js} +14 -7
  10. package/dist/{chunk-QRIWTPN3.js → chunk-HQ2L4NQ2.js} +270 -12
  11. package/dist/{chunk-QFGMQLRB.js → chunk-JQBSGFAR.js} +31 -14
  12. package/dist/{chunk-2KPZSPV6.js → chunk-OJK35AQD.js} +105 -17
  13. package/dist/chunk-QISBQ532.js +1665 -0
  14. package/dist/{chunk-T6X6TWHK.js → chunk-RFOJSDYI.js} +3 -3
  15. package/dist/{chunk-QEK25NUA.js → chunk-UEZVXYGP.js} +12 -5
  16. package/dist/{config-UmU2_q5M.d.ts → config-C79rcedl.d.ts} +53 -11
  17. package/dist/core/index.d.ts +13 -9
  18. package/dist/core/index.js +2 -2
  19. package/dist/core/network-adb-node.d.ts +23 -0
  20. package/dist/core/network-adb-node.js +171 -0
  21. package/dist/{script-debugger-F5UGUq5t.d.ts → device-channel-OiZwAqNQ.d.ts} +41 -55
  22. package/dist/{device-normalize-CWJFr_sf.d.ts → device-normalize-ODrxJb-a.d.ts} +1 -1
  23. package/dist/device-session-PVHD6PNR.js +1 -0
  24. package/dist/i18n/index.js +1 -1
  25. package/dist/{mirror-session-Cy20lIHP.d.ts → mirror-session-DifANocH.d.ts} +2 -2
  26. package/dist/react/index.d.ts +19 -12
  27. package/dist/react/index.js +3 -3
  28. package/dist/script-debugger-DjxpvdaN.d.ts +56 -0
  29. package/dist/{task-agent-runner-Cj_u-3DS.d.ts → task-agent-runner-CAt-z8gr.d.ts} +3 -3
  30. package/dist/{types-BvrppNIZ.d.ts → types-CBI5SIH5.d.ts} +103 -5
  31. package/dist/ui/billing.d.ts +43 -6
  32. package/dist/ui/billing.js +190 -309
  33. package/dist/ui/device-create.d.ts +5 -2
  34. package/dist/ui/device-create.js +8 -8
  35. package/dist/ui/device-mirror.js +6 -6
  36. package/dist/ui/devices.d.ts +5 -5
  37. package/dist/ui/devices.js +11 -11
  38. package/dist/ui/editor.d.ts +2 -2
  39. package/dist/ui/editor.js +7 -7
  40. package/dist/ui/index.d.ts +6 -4
  41. package/dist/ui/index.js +13 -492
  42. package/dist/ui/inspector.js +5 -5
  43. package/dist/ui/ip-commerce.d.ts +4 -2
  44. package/dist/ui/ip-commerce.js +6 -6
  45. package/dist/ui/market.js +4 -4
  46. package/dist/ui/mirror.d.ts +3 -3
  47. package/dist/ui/primitives/index.js +1 -1
  48. package/dist/ui/script-studio.js +6 -6
  49. package/dist/ui/scripts.d.ts +1 -1
  50. package/dist/ui/scripts.js +5 -5
  51. package/dist/ui/settings.d.ts +164 -0
  52. package/dist/ui/settings.js +10 -0
  53. package/dist/ui/tasks.js +11 -11
  54. package/package.json +9 -1
  55. package/dist/device-session-3XK2SZDF.js +0 -1
@@ -0,0 +1,1665 @@
1
+ import { BillingPage, RechargeDrawer } from './chunk-DTXXQPOU.js';
2
+ import { IosDeviceDiagnostics } from './chunk-RFOJSDYI.js';
3
+ import { iosPhysicalUnavailableReason } from './chunk-ZB5ET67B.js';
4
+ import { cn, Button, Input, Drawer, Select } from './chunk-7RQTSTR6.js';
5
+ import { useAixT } from './chunk-HQ2L4NQ2.js';
6
+ import { useEnvRun, useClient, useOptionalAixConfig, AixResolvedProvider } from './chunk-UEZVXYGP.js';
7
+ import { summarizeEnv, envBlocker, detectEnvOs } from './chunk-OJK35AQD.js';
8
+ import React, { useState, useRef, useEffect, useMemo, useCallback } from 'react';
9
+ import { Info, Loader2, Wallet, Receipt, RefreshCw } from 'lucide-react';
10
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
11
+
12
+ // src/ui/settings/types.ts
13
+ function errorMessage(error) {
14
+ if (error && typeof error === "object") {
15
+ if ("message" in error && typeof error.message === "string") return error.message;
16
+ if ("code" in error && typeof error.code === "string") return error.code;
17
+ }
18
+ return String(error);
19
+ }
20
+ function isSessionActive(session) {
21
+ if (!session) return true;
22
+ if (session.authenticated === false) return false;
23
+ return session.isCurrent ? session.isCurrent() : true;
24
+ }
25
+ function helperPhaseKey(phase) {
26
+ return `sdkSettings.helperPhase${phase.charAt(0).toUpperCase()}${phase.slice(1)}`;
27
+ }
28
+ function SdkLocalNodeSection({
29
+ runtime,
30
+ session,
31
+ appName,
32
+ className
33
+ }) {
34
+ const t = useAixT();
35
+ const resolvedAppName = appName?.trim() || t("sdkSettings.defaultAppName");
36
+ const [running, setRunning] = useState(null);
37
+ const [health, setHealth] = useState(null);
38
+ const [busy, setBusy] = useState(false);
39
+ const [err, setErr] = useState(null);
40
+ const [autoStartNode, setAutoStartNode] = useState(() => runtime.getAutoStart?.() ?? false);
41
+ const [actionStarting, setActionStarting] = useState(true);
42
+ const runtimeRef = useRef(runtime);
43
+ runtimeRef.current = runtime;
44
+ const sessionRef = useRef(session);
45
+ sessionRef.current = session;
46
+ const viewRef = useRef(null);
47
+ const current = (view) => view.active && viewRef.current === view && view.isCurrent();
48
+ async function observe(view, field, load, commit, fresh) {
49
+ if (!load || !current(view)) return;
50
+ const prior = view[field];
51
+ if (prior) {
52
+ if (!fresh) return prior;
53
+ await prior;
54
+ if (!current(view)) return;
55
+ }
56
+ if (view[field]) return view[field];
57
+ const pending = load().then(
58
+ (value) => {
59
+ if (current(view)) commit(value);
60
+ },
61
+ () => {
62
+ if (current(view)) commit(null);
63
+ }
64
+ ).finally(() => {
65
+ view[field] = null;
66
+ });
67
+ view[field] = pending;
68
+ return pending;
69
+ }
70
+ const refreshStatus = async (view, fresh = false) => {
71
+ await Promise.all([
72
+ observe(view, "statusRequest", runtimeRef.current.getNodeRunning, (value) => setRunning(value), fresh),
73
+ observe(view, "healthRequest", runtimeRef.current.getRuntimeHealth, (value) => setHealth(value), fresh)
74
+ ]);
75
+ };
76
+ const sessionKey = session?.id ?? "default";
77
+ const authenticated = session?.authenticated !== false;
78
+ useEffect(() => {
79
+ const capturedSession = sessionRef.current;
80
+ const view = {
81
+ isCurrent: () => isSessionActive(capturedSession),
82
+ active: true,
83
+ pending: false,
84
+ statusRequest: null,
85
+ healthRequest: null
86
+ };
87
+ viewRef.current = view;
88
+ setRunning(null);
89
+ setHealth(null);
90
+ setBusy(false);
91
+ setErr(null);
92
+ setAutoStartNode(runtimeRef.current.getAutoStart?.() ?? false);
93
+ if (!runtimeRef.current.available) {
94
+ return () => {
95
+ view.active = false;
96
+ };
97
+ }
98
+ void refreshStatus(view);
99
+ const onStatus = () => {
100
+ if (!view.pending) void refreshStatus(view);
101
+ };
102
+ const unsub = runtimeRef.current.subscribeStatus?.(onStatus);
103
+ const timer = setInterval(onStatus, 3e3);
104
+ return () => {
105
+ view.active = false;
106
+ clearInterval(timer);
107
+ unsub?.();
108
+ };
109
+ }, [runtime.available, sessionKey]);
110
+ const changeRunning = async (start) => {
111
+ const view = viewRef.current;
112
+ const rt = runtimeRef.current;
113
+ if (!view || !current(view) || view.pending) return;
114
+ if (start ? !rt.startNode : !rt.stopNode) return;
115
+ view.pending = true;
116
+ setActionStarting(start);
117
+ setBusy(true);
118
+ setErr(null);
119
+ try {
120
+ if (start) await rt.startNode();
121
+ else await rt.stopNode();
122
+ if (!current(view)) return;
123
+ rt.notifyStatusChanged?.();
124
+ await refreshStatus(view, true);
125
+ } catch (e) {
126
+ if (current(view)) setErr(errorMessage(e));
127
+ } finally {
128
+ view.pending = false;
129
+ if (current(view)) setBusy(false);
130
+ }
131
+ };
132
+ const observedNode = health && (health.node.owner_epoch === null || session?.id === void 0 || String(health.node.owner_epoch) === String(session.id)) ? health.node : null;
133
+ const nodeEnabled = observedNode?.desired ? observedNode.desired === "running" : running;
134
+ const nodeLabel = observedNode ? t(helperPhaseKey(observedNode.phase)) : running === null ? t("sdkSettings.unknown") : t(running ? "sdkSettings.running" : "sdkSettings.stopped");
135
+ const bridgeLabel = health ? t(health.mcp.busy ? "sdkSettings.helperBusy" : helperPhaseKey(health.mcp.phase)) : t("sdkSettings.unknown");
136
+ const showAutoStart = runtime.getAutoStart !== void 0 && runtime.setAutoStart !== void 0;
137
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col", className), children: [
138
+ /* @__PURE__ */ jsxs("div", { className: "mb-4", children: [
139
+ /* @__PURE__ */ jsx("h2", { className: "text-sm font-semibold text-foreground", children: t("sdkSettings.startupTitle") }),
140
+ /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("sdkSettings.startupDesc") })
141
+ ] }),
142
+ !runtime.available && /* @__PURE__ */ jsxs("div", { className: "mb-4 flex items-center gap-2 rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-muted-foreground", children: [
143
+ /* @__PURE__ */ jsx(Info, { className: "h-3.5 w-3.5 shrink-0 text-warning" }),
144
+ t("sdkSettings.desktopNotice")
145
+ ] }),
146
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-border bg-card px-5 py-1", children: [
147
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 border-b border-border/60 py-3 last:border-0", children: [
148
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.localNode") }),
149
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-3", children: [
150
+ /* @__PURE__ */ jsxs("span", { className: cn("inline-flex items-center gap-1 text-xs", running ? "text-success" : "text-muted-foreground"), children: [
151
+ busy && /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" }),
152
+ busy ? t(actionStarting ? "sdkSettings.starting" : "sdkSettings.stopping") : nodeLabel
153
+ ] }),
154
+ /* @__PURE__ */ jsx(
155
+ "button",
156
+ {
157
+ type: "button",
158
+ role: "switch",
159
+ "aria-checked": Boolean(nodeEnabled),
160
+ disabled: !runtime.available || !authenticated || busy || nodeEnabled == null,
161
+ "aria-label": t("sdkSettings.localNode"),
162
+ onClick: () => void changeRunning(!nodeEnabled),
163
+ className: cn(
164
+ "relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-50",
165
+ nodeEnabled ? "bg-primary" : "bg-muted-foreground/30"
166
+ ),
167
+ children: /* @__PURE__ */ jsx(
168
+ "span",
169
+ {
170
+ className: cn(
171
+ "inline-block h-3.5 w-3.5 transform rounded-full bg-white shadow-sm transition-transform",
172
+ nodeEnabled ? "translate-x-[1.125rem]" : "translate-x-0.5"
173
+ )
174
+ }
175
+ )
176
+ }
177
+ )
178
+ ] })
179
+ ] }),
180
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 border-b border-border/60 py-3 last:border-0", children: [
181
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.desktopBridge") }),
182
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: bridgeLabel })
183
+ ] }),
184
+ /* @__PURE__ */ jsx("p", { className: "py-2 text-xs text-muted-foreground", children: t("sdkSettings.localProcessHint") }),
185
+ showAutoStart && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 border-t border-border/60 py-3", children: [
186
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.autoStartNode", { appName: resolvedAppName }) }),
187
+ /* @__PURE__ */ jsx(
188
+ "input",
189
+ {
190
+ type: "checkbox",
191
+ disabled: !runtime.available,
192
+ checked: autoStartNode,
193
+ onChange: (e) => {
194
+ runtimeRef.current.setAutoStart?.(e.target.checked);
195
+ setAutoStartNode(e.target.checked);
196
+ },
197
+ className: "h-4 w-4 accent-primary"
198
+ }
199
+ )
200
+ ] }),
201
+ err && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 border-t border-border/60 py-3", children: [
202
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.error") }),
203
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-destructive", children: err })
204
+ ] })
205
+ ] })
206
+ ] });
207
+ }
208
+ var STATE_ICON = {
209
+ ok: "\u2713",
210
+ done: "\u2713",
211
+ skipped: "\u2298",
212
+ present: "\u2713",
213
+ running: "\u23F3",
214
+ missing: "\xB7",
215
+ pending: "\xB7",
216
+ failed: "\u2715",
217
+ error: "\u2715"
218
+ };
219
+ var stateColor = (s) => s === "failed" || s === "error" ? "var(--aix-danger, #e5484d)" : s === "ok" || s === "done" || s === "present" ? "var(--aix-accent, #2d6cdf)" : s === "running" ? "var(--aix-fg, #e6e6e6)" : "var(--aix-muted, #8a8a8a)";
220
+ var overlay = {
221
+ position: "fixed",
222
+ inset: 0,
223
+ background: "rgba(0,0,0,0.55)",
224
+ display: "flex",
225
+ alignItems: "center",
226
+ justifyContent: "center",
227
+ zIndex: 1e3
228
+ };
229
+ var card = {
230
+ width: "min(560px, 92vw)",
231
+ maxHeight: "86vh",
232
+ overflow: "auto",
233
+ background: "var(--aix-bg, #14161a)",
234
+ color: "var(--aix-fg, #e6e6e6)",
235
+ border: "1px solid var(--aix-border, #2a2e35)",
236
+ borderRadius: "var(--aix-radius, 10px)",
237
+ padding: "20px 22px",
238
+ font: "var(--aix-font, 14px/1.5 system-ui, sans-serif)",
239
+ boxShadow: "0 12px 40px rgba(0,0,0,0.5)"
240
+ };
241
+ var btn = (primary) => ({
242
+ background: primary ? "var(--aix-accent, #2d6cdf)" : "transparent",
243
+ color: primary ? "#fff" : "var(--aix-fg, #e6e6e6)",
244
+ border: primary ? "none" : "1px solid var(--aix-border, #2a2e35)",
245
+ borderRadius: "var(--aix-radius, 8px)",
246
+ padding: "7px 16px",
247
+ cursor: "pointer",
248
+ fontSize: 13
249
+ });
250
+ function EnvInitDialog(props) {
251
+ const { open, onClose, nodeId, os, route, mode = "prompt", seedEvents, onReady, onInstallWsl, title } = props;
252
+ const { reqId, events, finished: streamFinished, error, setup } = useEnvRun(props.beforeSetup);
253
+ const confirmation = useEnvRun();
254
+ const confirmationStarted = useRef(false);
255
+ const [minimized, setMinimized] = useState(false);
256
+ const [started, setStarted] = useState(false);
257
+ const [showLogs, setShowLogs] = useState(false);
258
+ const [installing, setInstalling] = useState(false);
259
+ const [wslFailed, setWslFailed] = useState(false);
260
+ const readyFired = useRef(false);
261
+ const wslTried = useRef(false);
262
+ const summary = useMemo(
263
+ () => summarizeEnv(started ? events : seedEvents ?? []),
264
+ [started, events, seedEvents]
265
+ );
266
+ const checked = summarizeEnv(confirmation.events);
267
+ const confirmed = confirmationStarted.current && confirmation.finished ? checked.ready ? confirmation.finished : { ...confirmation.finished, ok: false, error: confirmation.finished.error ?? "\u73AF\u5883\u68C0\u67E5\u672A\u901A\u8FC7\uFF0C\u8BF7\u91CD\u8BD5\u521D\u59CB\u5316\u3002" } : null;
268
+ const finished = streamFinished ?? (started ? summary.finished : null) ?? confirmed;
269
+ const done = !!finished;
270
+ useEffect(() => {
271
+ if (!open || !started || finished || confirmationStarted.current) return;
272
+ const verified = summary.steps.some((s) => s.id === "verify" && ["ok", "done", "skipped", "present"].includes(s.state));
273
+ if (!verified) return;
274
+ const timer = setTimeout(() => {
275
+ confirmationStarted.current = true;
276
+ void confirmation.status(nodeId, { os }).catch(() => {
277
+ });
278
+ }, 1500);
279
+ return () => clearTimeout(timer);
280
+ }, [open, started, finished, summary.steps, confirmation.status, nodeId, os]);
281
+ useEffect(() => {
282
+ if (open) {
283
+ setMinimized(false);
284
+ setStarted(false);
285
+ setShowLogs(false);
286
+ setInstalling(false);
287
+ setWslFailed(false);
288
+ readyFired.current = false;
289
+ wslTried.current = false;
290
+ confirmationStarted.current = false;
291
+ }
292
+ }, [open, nodeId]);
293
+ const wslBlocked = done && envBlocker(finished) === "wsl-missing" && !!onInstallWsl;
294
+ const installWsl = React.useCallback(async () => {
295
+ if (!onInstallWsl) return;
296
+ setInstalling(true);
297
+ setWslFailed(false);
298
+ try {
299
+ await onInstallWsl();
300
+ } catch {
301
+ setInstalling(false);
302
+ setWslFailed(true);
303
+ }
304
+ }, [onInstallWsl]);
305
+ useEffect(() => {
306
+ if (wslBlocked && !installing && !wslFailed && !wslTried.current) {
307
+ wslTried.current = true;
308
+ void installWsl();
309
+ }
310
+ }, [wslBlocked, installing, wslFailed, installWsl]);
311
+ const begin = React.useCallback(() => {
312
+ confirmation.close();
313
+ confirmationStarted.current = false;
314
+ setStarted(true);
315
+ void setup(nodeId, { os, route }).catch(() => {
316
+ });
317
+ }, [setup, nodeId, os, route, confirmation.close]);
318
+ useEffect(() => {
319
+ if (open && mode === "auto" && !started) begin();
320
+ }, [open, mode, started, begin]);
321
+ useEffect(() => {
322
+ if (open && started && done && finished?.ok && !readyFired.current) {
323
+ readyFired.current = true;
324
+ onReady?.();
325
+ }
326
+ }, [open, started, done, finished, onReady]);
327
+ if (!open) return null;
328
+ const pct = summary.steps.length ? Math.round(summary.steps.reduce((a, s) => a + (s.state === "ok" || s.state === "done" || s.state === "skipped" || s.state === "present" ? 100 : s.pct), 0) / summary.steps.length) : 0;
329
+ const failed = !!error || confirmationStarted.current && !!confirmation.error || done && !!finished && !finished.ok;
330
+ const success = done && finished?.ok;
331
+ if (minimized) return /* @__PURE__ */ jsxs("div", { role: "status", style: {
332
+ position: "fixed",
333
+ bottom: 16,
334
+ left: 16,
335
+ right: 16,
336
+ zIndex: 1e3,
337
+ background: "var(--aix-bg, #14161a)",
338
+ color: "var(--aix-fg, #e6e6e6)",
339
+ border: "1px solid var(--aix-border, #2a2e35)",
340
+ borderRadius: 10,
341
+ padding: "12px 16px",
342
+ boxShadow: "0 4px 20px rgba(0,0,0,.2)",
343
+ display: "flex",
344
+ alignItems: "center",
345
+ gap: 16
346
+ }, children: [
347
+ /* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
348
+ /* @__PURE__ */ jsxs("div", { style: { fontSize: 13, marginBottom: 6 }, children: [
349
+ title ?? "Android \u73AF\u5883\u521D\u59CB\u5316",
350
+ " \xB7 ",
351
+ success ? "\u5DF2\u5B8C\u6210" : failed ? "\u521D\u59CB\u5316\u5931\u8D25" : !reqId ? "\u6B63\u5728\u8FDE\u63A5\u8282\u70B9\u2026" : "\u6B63\u5728\u521D\u59CB\u5316\u2026",
352
+ " ",
353
+ pct,
354
+ "%"
355
+ ] }),
356
+ /* @__PURE__ */ jsx(
357
+ "div",
358
+ {
359
+ role: "progressbar",
360
+ "aria-valuemin": 0,
361
+ "aria-valuemax": 100,
362
+ "aria-valuenow": pct,
363
+ "aria-label": "\u521D\u59CB\u5316\u8FDB\u5EA6",
364
+ style: { height: 5, background: "var(--aix-border, #2a2e35)", borderRadius: 999, overflow: "hidden" },
365
+ children: /* @__PURE__ */ jsx("div", { style: { width: `${pct}%`, height: "100%", background: failed ? "var(--aix-danger, #e5484d)" : "var(--aix-accent, #2d6cdf)" } })
366
+ }
367
+ )
368
+ ] }),
369
+ /* @__PURE__ */ jsx("button", { style: btn(), onClick: () => setMinimized(false), children: "\u5C55\u5F00" }),
370
+ (success || failed) && /* @__PURE__ */ jsx("button", { style: btn(), onClick: onClose, children: "\u5173\u95ED" })
371
+ ] });
372
+ return /* @__PURE__ */ jsx("div", { style: overlay, role: "dialog", "aria-modal": "true", onClick: (e) => {
373
+ if (e.target === e.currentTarget && !started) onClose();
374
+ }, children: /* @__PURE__ */ jsxs("div", { style: card, children: [
375
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", gap: 16, alignItems: "center", marginBottom: 8 }, children: [
376
+ /* @__PURE__ */ jsx("span", { style: { fontSize: 16, fontWeight: 600 }, children: title ?? "\u521D\u59CB\u5316 Android \u73AF\u5883\u5E95\u5EA7" }),
377
+ /* @__PURE__ */ jsx("button", { style: btn(), onClick: () => setMinimized(true), children: "\u6700\u5C0F\u5316" })
378
+ ] }),
379
+ /* @__PURE__ */ jsx("div", { style: { color: "var(--aix-muted, #8a8a8a)", fontSize: 13, marginBottom: 16 }, children: success ? "\u521D\u59CB\u5316\u6210\u529F\uFF0C\u73AF\u5883\u548C\u955C\u50CF\u5DF2\u5C31\u7EEA\uFF0C\u53EF\u4EE5\u4F7F\u7528\u4E91\u624B\u673A\u3002" : wslBlocked && wslFailed ? "\u81EA\u52A8\u5B89\u88C5 WSL \u8FD0\u884C\u65F6\u5931\u8D25\uFF08\u53EF\u80FD\u5185\u7F51\u65E0\u6CD5\u4E0B\u8F7D\uFF09\u3002\u8BF7\u6309\u4E0B\u65B9\u6B65\u9AA4\u624B\u52A8\u4E0B\u8F7D\u5B89\u88C5\u540E\u91CD\u8BD5\u3002" : wslBlocked ? '\u9700\u8981\u5148\u5B89\u88C5 WSL \u8FD0\u884C\u65F6\uFF1A\u6B63\u5728\u81EA\u52A8\u4E0B\u8F7D\u5E76\u5B89\u88C5\uFF08\u9700\u5728 UAC \u5F39\u7A97\u70B9"\u662F"\uFF0C\u7EA6 250MB\uFF09\uFF0C\u5B8C\u6210\u540E\u4F1A\u81EA\u52A8\u91CD\u542F\u5E76\u7EE7\u7EED\u3002' : failed ? "Setup failed. Review the steps below and retry." : started && !reqId ? "\u6B63\u5728\u542F\u52A8\u5E76\u8FDE\u63A5\u8282\u70B9\uFF0C\u9996\u6B21\u542F\u52A8\u4F1A\u81EA\u52A8\u68C0\u67E5\u3001\u4E0B\u8F7D\u6240\u9700\u7EC4\u4EF6\uFF0C\u53EF\u80FD\u9700\u8981\u51E0\u5206\u949F\u3002\u8FDE\u63A5\u6210\u529F\u540E\u81EA\u52A8\u5F00\u59CB\u521D\u59CB\u5316\u3002" : started ? "Installing the redroid base. This downloads ~1\u20132 GB and may take several minutes." : "This machine needs a one-time base (kernel + container runtime + image) to host cloud phones." }),
380
+ (started || summary.steps.length > 0) && /* @__PURE__ */ jsxs(Fragment, { children: [
381
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: 10, marginBottom: 14 }, children: [
382
+ /* @__PURE__ */ jsx("div", { style: { flex: 1, height: 6, background: "var(--aix-border, #2a2e35)", borderRadius: 999, overflow: "hidden" }, children: /* @__PURE__ */ jsx("div", { style: { width: `${pct}%`, height: "100%", background: failed ? "var(--aix-danger, #e5484d)" : "var(--aix-accent, #2d6cdf)", transition: "width .3s" } }) }),
383
+ /* @__PURE__ */ jsxs("span", { style: { fontSize: 12, color: "var(--aix-muted, #8a8a8a)", minWidth: 36, textAlign: "right", fontVariantNumeric: "tabular-nums" }, children: [
384
+ pct,
385
+ "%"
386
+ ] })
387
+ ] }),
388
+ started && events.length === 0 && !failed && /* @__PURE__ */ jsx("div", { role: "status", style: { color: "var(--aix-muted, #8a8a8a)", fontSize: 13, marginBottom: 12 }, children: "\u6B63\u5728\u8FDE\u63A5\u8282\u70B9\u5E76\u7B49\u5F85\u521D\u59CB\u5316\u6B65\u9AA4\u2026" }),
389
+ /* @__PURE__ */ jsx("ul", { style: { listStyle: "none", margin: 0, padding: 0, display: "grid", gap: 8 }, children: summary.steps.map((s) => /* @__PURE__ */ jsxs("li", { style: { display: "flex", alignItems: "baseline", gap: 10, fontSize: 13 }, children: [
390
+ /* @__PURE__ */ jsx("span", { style: { color: stateColor(s.state), width: 16, textAlign: "center" }, children: STATE_ICON[s.state] ?? "\xB7" }),
391
+ /* @__PURE__ */ jsxs("span", { style: { flex: 1 }, children: [
392
+ s.label,
393
+ s.detail ? /* @__PURE__ */ jsxs("span", { style: { color: "var(--aix-muted, #8a8a8a)" }, children: [
394
+ " \u2014 ",
395
+ s.detail
396
+ ] }) : null
397
+ ] }),
398
+ s.state === "running" && /* @__PURE__ */ jsxs("span", { style: { color: "var(--aix-muted, #8a8a8a)" }, children: [
399
+ s.pct,
400
+ "%"
401
+ ] })
402
+ ] }, s.index)) })
403
+ ] }),
404
+ failed && finished?.error && /* @__PURE__ */ jsxs("div", { style: { marginTop: 12, padding: 10, background: "rgba(229,72,77,0.1)", border: "1px solid var(--aix-danger, #e5484d)", borderRadius: 8, fontSize: 13 }, children: [
405
+ finished.error,
406
+ finished.hint ? /* @__PURE__ */ jsxs("div", { style: { color: "var(--aix-muted, #8a8a8a)", marginTop: 4 }, children: [
407
+ "Hint: ",
408
+ finished.hint
409
+ ] }) : null
410
+ ] }),
411
+ confirmationStarted.current && confirmation.error && !finished && /* @__PURE__ */ jsxs("div", { role: "alert", style: { marginTop: 12, color: "var(--aix-danger, #e5484d)" }, children: [
412
+ "\u65E0\u6CD5\u786E\u8BA4\u521D\u59CB\u5316\u7ED3\u679C\uFF1A",
413
+ confirmation.error.message,
414
+ "\u3002\u8BF7\u91CD\u65B0\u68C0\u67E5\u8282\u70B9\u72B6\u6001\u3002"
415
+ ] }),
416
+ error && !finished && /* @__PURE__ */ jsxs("div", { style: { marginTop: 12, color: "var(--aix-danger, #e5484d)", fontSize: 13 }, children: [
417
+ "Could not start setup: ",
418
+ error.message
419
+ ] }),
420
+ wslBlocked && wslFailed && /* @__PURE__ */ jsxs("div", { style: { marginTop: 12, padding: 12, background: "var(--aix-editor-bg, #0e0f12)", border: "1px solid var(--aix-border, #2a2e35)", borderRadius: 8, fontSize: 12.5, lineHeight: 1.6 }, children: [
421
+ /* @__PURE__ */ jsx("div", { style: { fontWeight: 600, marginBottom: 6 }, children: "\u624B\u52A8\u5B89\u88C5 WSL \u8FD0\u884C\u65F6\uFF08\u9700 Win10 21H2/19044+\uFF09" }),
422
+ /* @__PURE__ */ jsxs("ol", { style: { margin: 0, paddingLeft: 18 }, children: [
423
+ /* @__PURE__ */ jsxs("li", { children: [
424
+ "\u4E0B\u8F7D\uFF08\u7EA6 250MB\uFF09\uFF1A",
425
+ /* @__PURE__ */ jsx("br", {}),
426
+ /* @__PURE__ */ jsx("code", { style: { fontFamily: "var(--aix-mono, ui-monospace, Menlo, monospace)", wordBreak: "break-all" }, children: "https://github.com/microsoft/WSL/releases/latest" }),
427
+ /* @__PURE__ */ jsx("br", {}),
428
+ "\u9009 ",
429
+ /* @__PURE__ */ jsx("code", { children: "wsl.<\u7248\u672C>.x64.msi" }),
430
+ "\uFF08\u5185\u7F51\u673A\u53EF\u5728\u80FD\u8054\u7F51\u7684\u7535\u8111\u4E0B\u597D\u518D\u62F7\u8FC7\u6765\uFF09\u3002"
431
+ ] }),
432
+ /* @__PURE__ */ jsxs("li", { style: { marginTop: 4 }, children: [
433
+ "\u7BA1\u7406\u5458\u8FD0\u884C\uFF1A",
434
+ /* @__PURE__ */ jsx("br", {}),
435
+ /* @__PURE__ */ jsx("code", { style: { fontFamily: "var(--aix-mono, ui-monospace, Menlo, monospace)" }, children: "msiexec /i wsl.<\u7248\u672C>.x64.msi /quiet" }),
436
+ "\uFF08\u6216\u53CC\u51FB\u5B89\u88C5\uFF09\u3002"
437
+ ] }),
438
+ /* @__PURE__ */ jsxs("li", { style: { marginTop: 4 }, children: [
439
+ "\u91CD\u542F\u540E ",
440
+ /* @__PURE__ */ jsx("code", { children: "wsl --version" }),
441
+ " \u80FD\u663E\u793A\u7248\u672C\u5373\u6210\u529F\uFF0C\u518D\u70B9\u4E0B\u65B9\u300C\u91CD\u8BD5\u300D\u3002"
442
+ ] })
443
+ ] })
444
+ ] }),
445
+ started && summary.logs.length > 0 && /* @__PURE__ */ jsxs("div", { style: { marginTop: 12 }, children: [
446
+ /* @__PURE__ */ jsxs("button", { style: { ...btn(), padding: "2px 0", border: "none", color: "var(--aix-muted, #8a8a8a)", fontSize: 12 }, onClick: () => setShowLogs((v) => !v), children: [
447
+ showLogs ? "\u25BE Hide logs" : "\u25B8 Show logs",
448
+ " (",
449
+ summary.logs.length,
450
+ ")"
451
+ ] }),
452
+ showLogs && /* @__PURE__ */ jsx("pre", { style: { marginTop: 6, maxHeight: 160, overflow: "auto", background: "var(--aix-editor-bg, #0e0f12)", color: "var(--aix-editor-fg, #cfcfcf)", padding: 10, borderRadius: 8, fontSize: 12, fontFamily: "var(--aix-mono, ui-monospace, Menlo, monospace)" }, children: summary.logs.slice(-200).join("\n") })
453
+ ] }),
454
+ /* @__PURE__ */ jsx("div", { style: { display: "flex", justifyContent: "flex-end", gap: 10, marginTop: 18 }, children: success ? /* @__PURE__ */ jsx("button", { style: btn(true), onClick: onClose, children: "\u5B8C\u6210" }) : wslBlocked && wslFailed ? /* @__PURE__ */ jsxs(Fragment, { children: [
455
+ /* @__PURE__ */ jsx("button", { style: btn(), onClick: onClose, children: "\u5173\u95ED" }),
456
+ /* @__PURE__ */ jsx("button", { style: btn(true), onClick: begin, children: "\u91CD\u8BD5\uFF08\u5DF2\u624B\u52A8\u88C5\u597D\uFF09" })
457
+ ] }) : wslBlocked ? /* @__PURE__ */ jsx("button", { style: btn(), disabled: true, onClick: () => {
458
+ }, children: installing ? "\u6B63\u5728\u4E0B\u8F7D\u5B89\u88C5 WSL \u8FD0\u884C\u65F6\u2026" : "\u51C6\u5907\u5B89\u88C5\u2026" }) : failed ? /* @__PURE__ */ jsxs(Fragment, { children: [
459
+ /* @__PURE__ */ jsx("button", { style: btn(), onClick: onClose, children: "Close" }),
460
+ /* @__PURE__ */ jsx("button", { style: btn(true), onClick: begin, children: "Retry" })
461
+ ] }) : started ? /* @__PURE__ */ jsx("button", { style: btn(), disabled: true, onClick: () => {
462
+ }, children: "Installing\u2026" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
463
+ /* @__PURE__ */ jsx("button", { style: btn(), onClick: onClose, children: "Not now" }),
464
+ /* @__PURE__ */ jsx("button", { style: btn(true), onClick: begin, children: "Start setup" })
465
+ ] }) })
466
+ ] }) });
467
+ }
468
+ function installedTags(node) {
469
+ const v = node.reported_caps?.installed_images;
470
+ return Array.isArray(v) ? v.filter((x) => typeof x === "string") : [];
471
+ }
472
+ var str = (v) => typeof v === "string" && v ? v : "\u2014";
473
+ var sys = (node, k) => node.reported_caps?.system?.[k];
474
+ var capBool = (node, k) => node.reported_caps?.[k] === true;
475
+ function supportsRuntimeDataRoot(node) {
476
+ const capability = node.reported_caps?.runtime_data_root;
477
+ return capability?.supported === true;
478
+ }
479
+ function envOsOf(node) {
480
+ const os = str(sys(node, "os"));
481
+ return os === "macos" ? "mac" : os === "windows" ? "win" : null;
482
+ }
483
+ function withLocalEnvOs(node, os) {
484
+ if (!node.is_owner || !os || envOsOf(node) || sys(node, "os")) return node;
485
+ return {
486
+ ...node,
487
+ reported_caps: {
488
+ ...node.reported_caps,
489
+ system: {
490
+ ...node.reported_caps?.system,
491
+ os: os === "win" ? "windows" : "macos"
492
+ }
493
+ }
494
+ };
495
+ }
496
+ function vmPlan(node) {
497
+ const eff = node.effective_caps;
498
+ const os = str(sys(node, "os"));
499
+ const out = [];
500
+ if (sys(node, "runtime_preparing") === true) {
501
+ out.push({ key: "android", label: "Android \u4E91\u624B\u673A", state: "checking", reason: "\u8282\u70B9\u6B63\u5728\u68C0\u6D4B\u5DF2\u914D\u7F6E\u7684\u8FD0\u884C\u73AF\u5883\uFF0C\u8BF7\u7A0D\u5019" });
502
+ } else if (!eff?.android && (capBool(node, "redroid_runtime_ready") || capBool(node, "redroid_capable"))) {
503
+ out.push({ key: "android", label: "Android \u4E91\u624B\u673A", state: "unavailable", reason: "\u8FD0\u884C\u73AF\u5883\u5DF2\u5C31\u7EEA\uFF0C\u8282\u70B9\u672A\u542F\u7528 Android \u4E91\u624B\u673A\u6743\u9650" });
504
+ } else if (eff?.android) {
505
+ const imageReady = node.reported_caps?.android_image_ready !== false;
506
+ if (imageReady) {
507
+ out.push({ key: "android", label: "Android \u4E91\u624B\u673A", state: "available" });
508
+ } else {
509
+ out.push({
510
+ key: "android",
511
+ label: "Android \u4E91\u624B\u673A",
512
+ state: "needs-image",
513
+ reason: "\u8FD0\u884C\u73AF\u5883\u5DF2\u5C31\u7EEA\uFF0CAndroid \u955C\u50CF\u5C1A\u672A\u4E0B\u8F7D\uFF08\u8282\u70B9\u542F\u52A8\u65F6\u81EA\u52A8\u62C9\u53D6\uFF0C\u4E5F\u53EF\u624B\u52A8\u89E6\u53D1\uFF09"
514
+ });
515
+ }
516
+ } else if (os === "windows" || os === "macos") {
517
+ out.push({
518
+ key: "android",
519
+ label: "Android \u4E91\u624B\u673A",
520
+ state: "needs-init",
521
+ reason: `\u9700\u5B89\u88C5 redroid \u73AF\u5883\u5E95\u5EA7\uFF08${os === "windows" ? "WSL2" : "lima"}\uFF09\u540E\u53EF\u7528`
522
+ });
523
+ } else if (os === "linux") {
524
+ const feature = node.reported_caps?.redroid_feature_enabled;
525
+ const setupSupported = feature !== false && !capBool(node, "redroid_capable") && capBool(node, "redroid_setup_supported");
526
+ out.push({
527
+ key: "android",
528
+ label: "Android \u4E91\u624B\u673A",
529
+ state: setupSupported ? "needs-init" : "unavailable",
530
+ reason: setupSupported ? "\u9700\u521D\u59CB\u5316\u8FD0\u884C\u73AF\u5883\u5E76\u5728\u7EBF\u4E0B\u8F7D Android \u955C\u50CF" : feature === false ? "\u8BE5 Linux \u8282\u70B9\u7248\u672C\u672A\u5305\u542B Redroid provider\uFF0C\u8BF7\u5347\u7EA7\u8282\u70B9" : capBool(node, "redroid_capable") ? "\u8282\u70B9\u672A\u542F\u7528 Android \u4E91\u624B\u673A\u6743\u9650" : feature === true ? "Linux \u8FD0\u884C\u73AF\u5883\u5C1A\u672A\u5C31\u7EEA\uFF0C\u6B64\u8282\u70B9\u4E0D\u652F\u6301\u81EA\u52A8\u521D\u59CB\u5316" : "\u8282\u70B9\u5C1A\u672A\u4E0A\u62A5 Linux \u521D\u59CB\u5316\u80FD\u529B\uFF0C\u8BF7\u68C0\u67E5\u8282\u70B9\u7248\u672C\u4E0E\u8FD0\u884C\u73AF\u5883"
531
+ });
532
+ } else {
533
+ out.push({ key: "android", label: "Android \u4E91\u624B\u673A", state: "unavailable", reason: "\u672C\u673A\u4E0D\u652F\u6301" });
534
+ }
535
+ if (capBool(node, "vphone_capable") && eff?.ios) {
536
+ out.push({ key: "ios", label: "iOS \u865A\u62DF\u673A", state: "available" });
537
+ } else {
538
+ const arch = str(sys(node, "arch"));
539
+ const reason = os === "macos" ? arch === "aarch64" ? "\u672A\u68C0\u6D4B\u5230 vphone \u80FD\u529B\uFF08\u9700\u5728\u6B64 Mac \u4E0A\u542F\u7528\uFF09" : "iOS \u865A\u62DF\u673A\u4EC5 Apple Silicon Mac \u652F\u6301\uFF08\u6B64 Mac \u4E3A Intel\uFF09" : "iOS \u865A\u62DF\u673A\u4EC5 Apple Silicon Mac \u652F\u6301\uFF0C\u672C\u673A\u4E0D\u53EF\u7528";
540
+ out.push({ key: "ios", label: "iOS \u865A\u62DF\u673A", state: "unavailable", reason });
541
+ }
542
+ const iosReason = iosPhysicalUnavailableReason(node);
543
+ out.push({ key: "ios-real", label: "iOS \u771F\u673A", state: iosReason ? "unavailable" : "available", ...iosReason ? { reason: iosReason } : {} });
544
+ out.push(
545
+ eff?.real_devices ? { key: "android-real", label: "Android \u771F\u673A", state: "available" } : { key: "android-real", label: "Android \u771F\u673A", state: "unavailable", reason: "\u8282\u70B9\u672A\u542F\u7528\u771F\u673A\u63A5\u5165" }
546
+ );
547
+ return out;
548
+ }
549
+ function VmCapRow({
550
+ node,
551
+ vm,
552
+ onInit,
553
+ onDownload,
554
+ downloading
555
+ }) {
556
+ const canInit = vm.state === "needs-init" && node.is_owner && (envOsOf(node) !== null || sys(node, "os") === "linux" && capBool(node, "redroid_setup_supported"));
557
+ const canDownload = vm.state === "needs-image" && node.is_owner;
558
+ const dot = vm.state === "available" ? "bg-success" : vm.state === "needs-init" ? "bg-warning" : vm.state === "needs-image" ? "bg-warning" : "bg-muted-foreground/40";
559
+ const badge = vm.state === "checking" ? "\u68C0\u6D4B\u4E2D" : vm.state === "available" ? "\u53EF\u7528" : vm.state === "needs-init" ? "\u9700\u521D\u59CB\u5316" : vm.state === "needs-image" ? "\u955C\u50CF\u672A\u5C31\u7EEA" : "\u672C\u673A\u4E0D\u53EF\u7528";
560
+ const badgeClass = vm.state === "available" ? "text-success" : vm.state === "needs-init" ? "text-warning" : vm.state === "needs-image" ? "text-warning" : "text-muted-foreground";
561
+ return /* @__PURE__ */ jsxs("div", { className: "rounded border border-border px-3 py-2", children: [
562
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
563
+ /* @__PURE__ */ jsx("span", { className: `h-1.5 w-1.5 shrink-0 rounded-full ${dot}` }),
564
+ /* @__PURE__ */ jsx("span", { className: "flex-1 text-xs text-foreground", children: vm.label }),
565
+ /* @__PURE__ */ jsx("span", { className: `text-[11px] ${badgeClass}`, children: badge }),
566
+ canInit && /* @__PURE__ */ jsx(Button, { size: "sm", variant: "primary", onClick: onInit, disabled: downloading, className: "ml-2", children: downloading ? "\u521D\u59CB\u5316\u4E2D\u2026" : "\u521D\u59CB\u5316" }),
567
+ canDownload && /* @__PURE__ */ jsx(Button, { size: "sm", variant: "primary", onClick: onDownload, disabled: downloading, className: "ml-2", children: downloading ? "\u4E0B\u8F7D\u4E2D\u2026" : "\u4E0B\u8F7D\u955C\u50CF" })
568
+ ] }),
569
+ vm.reason && /* @__PURE__ */ jsx("p", { className: "mt-1 pl-3.5 text-[11px] text-muted-foreground", children: vm.reason })
570
+ ] });
571
+ }
572
+ function DataRootConfig({ node }) {
573
+ const client = useClient();
574
+ const [dataRoot, setDataRoot] = useState("");
575
+ const [saving, setSaving] = useState(false);
576
+ const [message, setMessage] = useState(null);
577
+ if (!supportsRuntimeDataRoot(node)) {
578
+ return /* @__PURE__ */ jsx("p", { className: "mt-3 text-[11px] text-muted-foreground", children: "\u6570\u636E\u6839\u76EE\u5F55\u914D\u7F6E\u9700\u8981\u652F\u6301\u6B64\u529F\u80FD\u7684\u65B0\u7248 Linux \u8282\u70B9\u3002" });
579
+ }
580
+ const save = async () => {
581
+ if (!dataRoot.trim() || saving) return;
582
+ setSaving(true);
583
+ setMessage(null);
584
+ try {
585
+ const receipt = await client.nodes.setDataRoot(node.id, dataRoot);
586
+ setMessage(
587
+ receipt.restart_required ? `\u5DF2\u4FDD\u5B58 ${receipt.data_root}\u3002\u8BF7\u91CD\u542F\u8282\u70B9\u540E\uFF0C\u65B0\u5EFA Redroid \u5BB9\u5668\u624D\u4F1A\u4F7F\u7528\u6B64\u76EE\u5F55\u3002` : `\u5DF2\u4FDD\u5B58 ${receipt.data_root}\u3002`
588
+ );
589
+ } catch (error) {
590
+ setMessage(error instanceof Error ? error.message : String(error));
591
+ } finally {
592
+ setSaving(false);
593
+ }
594
+ };
595
+ return /* @__PURE__ */ jsxs("div", { className: "mt-3 rounded border border-border p-3 space-y-2", children: [
596
+ /* @__PURE__ */ jsxs("div", { children: [
597
+ /* @__PURE__ */ jsx("h4", { className: "text-xs font-medium text-foreground", children: "Redroid \u6570\u636E\u6839\u76EE\u5F55" }),
598
+ /* @__PURE__ */ jsx("p", { className: "mt-1 text-[11px] text-muted-foreground", children: "\u4EC5\u63A5\u53D7\u8282\u70B9\u539F\u751F\u6587\u4EF6\u7CFB\u7EDF\u7684\u7EDD\u5BF9\u8DEF\u5F84\u3002\u4E0D\u4F1A\u8FC1\u79FB\u6216\u5220\u9664\u73B0\u6709\u6570\u636E\uFF0C\u4FDD\u5B58\u540E\u9700\u624B\u52A8\u91CD\u542F\u8282\u70B9\u3002" })
599
+ ] }),
600
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
601
+ /* @__PURE__ */ jsx(
602
+ Input,
603
+ {
604
+ value: dataRoot,
605
+ onChange: (event) => setDataRoot(event.target.value),
606
+ placeholder: "/var/lib/aixautobot/instances",
607
+ "aria-label": "Redroid \u6570\u636E\u6839\u76EE\u5F55"
608
+ }
609
+ ),
610
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "primary", disabled: saving || !dataRoot.trim(), onClick: () => void save(), children: saving ? "\u4FDD\u5B58\u4E2D\u2026" : "\u4FDD\u5B58" })
611
+ ] }),
612
+ message && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: message })
613
+ ] });
614
+ }
615
+ function AndroidImageRows({ images, installed }) {
616
+ return /* @__PURE__ */ jsx("div", { className: "mt-1.5 ml-3.5 space-y-1 border-l border-border/60 pl-3", children: images.map((img) => {
617
+ const has = installed.includes(img.image_tag);
618
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
619
+ /* @__PURE__ */ jsx("span", { className: `h-1 w-1 shrink-0 rounded-full ${has ? "bg-success" : "bg-muted-foreground/40"}` }),
620
+ /* @__PURE__ */ jsx("span", { className: "flex-1 text-[11px] text-muted-foreground", children: img.label }),
621
+ /* @__PURE__ */ jsx("span", { className: `text-[10px] ${has ? "text-success" : "text-muted-foreground"}`, children: has ? "\u5DF2\u5B89\u88C5" : "\u672A\u5B89\u88C5" })
622
+ ] }, img.id);
623
+ }) });
624
+ }
625
+ function NodeCapabilityPanel({ node: reportedNode, isTauri, onInstallWsl, localEnvOs, beforeSetup }) {
626
+ const client = useClient();
627
+ const localOs = localEnvOs ?? (client.localNode?.nodeId === reportedNode.id ? client.localNode.envOs ?? detectEnvOs() : null);
628
+ const node = withLocalEnvOs(reportedNode, localOs);
629
+ const [init, setInit] = useState(null);
630
+ const initOs = sys(node, "os") === "linux" ? "linux" : envOsOf(node);
631
+ const [androidImages, setAndroidImages] = useState([]);
632
+ useEffect(() => {
633
+ let cancelled = false;
634
+ client.images.options("android").then((imgs) => {
635
+ if (!cancelled) setAndroidImages(imgs);
636
+ }).catch(() => {
637
+ });
638
+ return () => {
639
+ cancelled = true;
640
+ };
641
+ }, [client]);
642
+ const installed = installedTags(node);
643
+ const usbDiagnostic = node.reported_caps?.ios_usb_diagnostic;
644
+ return /* @__PURE__ */ jsxs("section", { children: [
645
+ /* @__PURE__ */ jsx("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: "\u865A\u62DF\u673A\u4E0E\u8BBE\u5907\u80FD\u529B" }),
646
+ usbDiagnostic && typeof usbDiagnostic.message === "string" && /* @__PURE__ */ jsxs("div", { role: "alert", className: "mb-3 rounded border border-destructive/50 p-3 text-sm", children: [
647
+ /* @__PURE__ */ jsx("p", { children: usbDiagnostic.message }),
648
+ Array.isArray(usbDiagnostic.instance_ids) && usbDiagnostic.instance_ids.filter((id) => typeof id === "string").map((id) => /* @__PURE__ */ jsx("p", { className: "mt-2 break-all font-mono text-xs", children: id }, id)),
649
+ typeof usbDiagnostic.hint === "string" && /* @__PURE__ */ jsx("p", { className: "mt-2 whitespace-pre-wrap", children: usbDiagnostic.hint })
650
+ ] }),
651
+ !node.reported_caps ? /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: "\u80FD\u529B\u672A\u77E5\uFF1A\u8282\u70B9\u5C1A\u672A\u8FDE\u63A5\u6216\u4E3A\u65E7\u7248\u672C\uFF08\u9700\u5347\u7EA7\u4EE5\u4E0A\u62A5\u80FD\u529B\uFF09\u3002" }) : /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
652
+ !reportedNode.reported_caps && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: "\u5DF2\u8BC6\u522B\u672C\u673A\u7CFB\u7EDF\uFF0C\u53EF\u521D\u59CB\u5316\u73AF\u5883\uFF1B\u8282\u70B9\u80FD\u529B\u5C1A\u672A\u4E0A\u62A5\uFF0C\u8BF7\u786E\u4FDD\u8282\u70B9\u5DF2\u8FDE\u63A5\u8BBE\u5907\u7F51\u5173\u3002" }),
653
+ vmPlan(node).map((vm) => /* @__PURE__ */ jsxs("div", { children: [
654
+ /* @__PURE__ */ jsx(
655
+ VmCapRow,
656
+ {
657
+ node,
658
+ vm,
659
+ onInit: () => setInit(vm),
660
+ onDownload: () => setInit(vm)
661
+ }
662
+ ),
663
+ vm.key === "android" && vm.state !== "unavailable" && androidImages.length > 0 && /* @__PURE__ */ jsx(AndroidImageRows, { images: androidImages, installed })
664
+ ] }, vm.key))
665
+ ] }),
666
+ node.is_owner && node.status === "online" && node.reported_caps?.ios_control?.diagnostics === true && /* @__PURE__ */ jsx(IosDeviceDiagnostics, { nodeId: node.id }, node.id),
667
+ node.is_owner && (supportsRuntimeDataRoot(node) || sys(node, "os") === "linux") && /* @__PURE__ */ jsx(DataRootConfig, { node }),
668
+ init && initOs && /* @__PURE__ */ jsx(
669
+ EnvInitDialog,
670
+ {
671
+ open: true,
672
+ nodeId: node.id,
673
+ os: initOs,
674
+ mode: "prompt",
675
+ beforeSetup,
676
+ title: `\u521D\u59CB\u5316 ${init.label} \u73AF\u5883\u5E95\u5EA7`,
677
+ onInstallWsl: isTauri ? onInstallWsl : void 0,
678
+ onClose: () => setInit(null),
679
+ onReady: async () => {
680
+ try {
681
+ await client.nodes.restart(node.id);
682
+ } catch {
683
+ }
684
+ }
685
+ }
686
+ )
687
+ ] });
688
+ }
689
+ function useLocalNodeList(client, runtime, session, nodeId, nodeName) {
690
+ const [state, setState] = useState({
691
+ data: null,
692
+ loading: true,
693
+ error: null
694
+ });
695
+ const identity = useRef({ nodeId, nodeName });
696
+ identity.current = { nodeId, nodeName };
697
+ const sessionRef = useRef(session);
698
+ sessionRef.current = session;
699
+ const runtimeRef = useRef(runtime);
700
+ runtimeRef.current = runtime;
701
+ const refreshRef = useRef(async () => {
702
+ });
703
+ const sessionKey = session?.id ?? "default";
704
+ const authenticated = session?.authenticated !== false;
705
+ useEffect(() => {
706
+ const capturedSession = sessionRef.current;
707
+ let active = true;
708
+ let pending = null;
709
+ let timer = null;
710
+ let attempts = 0;
711
+ const current = () => active && isSessionActive(capturedSession);
712
+ const clearRetry = () => {
713
+ if (timer !== null) {
714
+ clearTimeout(timer);
715
+ timer = null;
716
+ }
717
+ };
718
+ const load = () => {
719
+ if (!current()) return Promise.resolve();
720
+ if (pending) return pending;
721
+ clearRetry();
722
+ attempts += 1;
723
+ setState((previous) => ({ ...previous, loading: true, error: null }));
724
+ pending = (async () => {
725
+ let found = false;
726
+ try {
727
+ const data = await client.nodes.list();
728
+ if (!current()) return;
729
+ const target = identity.current;
730
+ found = data.some(
731
+ (node) => node.status === "online" && (target.nodeId ? node.id === target.nodeId : Boolean(target.nodeName) && node.name === target.nodeName)
732
+ );
733
+ setState({ data, loading: false, error: null });
734
+ } catch (error) {
735
+ if (current()) setState((previous) => ({ ...previous, loading: false, error: errorMessage(error) }));
736
+ } finally {
737
+ pending = null;
738
+ if (current() && !found && attempts < 6) {
739
+ timer = setTimeout(() => {
740
+ timer = null;
741
+ void load();
742
+ }, Math.min(8e3, 500 * 2 ** (attempts - 1)));
743
+ }
744
+ }
745
+ })();
746
+ return pending;
747
+ };
748
+ const refresh = () => {
749
+ attempts = pending ? 1 : 0;
750
+ return load();
751
+ };
752
+ refreshRef.current = refresh;
753
+ setState({ data: null, loading: true, error: null });
754
+ void load();
755
+ const unsub = runtimeRef.current.subscribeStatus?.(() => {
756
+ void refresh();
757
+ });
758
+ return () => {
759
+ active = false;
760
+ clearRetry();
761
+ unsub?.();
762
+ if (refreshRef.current === refresh) refreshRef.current = async () => {
763
+ };
764
+ };
765
+ }, [client, sessionKey, authenticated]);
766
+ useEffect(() => {
767
+ if (nodeId || nodeName) void refreshRef.current();
768
+ }, [nodeId, nodeName]);
769
+ return { ...state, refetch: () => refreshRef.current() };
770
+ }
771
+ function DesktopNodeDetailsView({
772
+ client,
773
+ runtime,
774
+ session,
775
+ renderNodeCapability,
776
+ className
777
+ }) {
778
+ const t = useAixT();
779
+ const optionalConfig = useOptionalAixConfig();
780
+ const [nodeName, setNodeName] = useState(null);
781
+ const [boundNodeId, setBoundNodeId] = useState(null);
782
+ const runtimeRef = useRef(runtime);
783
+ runtimeRef.current = runtime;
784
+ const sessionRef = useRef(session);
785
+ sessionRef.current = session;
786
+ const viewRef = useRef(null);
787
+ const sessionKey = session?.id ?? "default";
788
+ const authenticated = session?.authenticated !== false;
789
+ useEffect(() => {
790
+ const capturedSession = sessionRef.current;
791
+ const view = {
792
+ isCurrent: () => isSessionActive(capturedSession),
793
+ active: true,
794
+ name: null,
795
+ namePending: false,
796
+ idPending: false
797
+ };
798
+ viewRef.current = view;
799
+ setNodeName(null);
800
+ setBoundNodeId(null);
801
+ if (!runtimeRef.current.available || !authenticated) {
802
+ return () => {
803
+ view.active = false;
804
+ };
805
+ }
806
+ const current = () => view.active && viewRef.current === view && view.isCurrent();
807
+ const refreshIdentity = () => {
808
+ const rt = runtimeRef.current;
809
+ if (!current()) return;
810
+ if (!view.name && !view.namePending && rt.getLocalNodeName) {
811
+ view.namePending = true;
812
+ void rt.getLocalNodeName().then((name) => {
813
+ if (!current()) return;
814
+ view.name = name;
815
+ setNodeName(name);
816
+ }).catch(() => {
817
+ }).finally(() => {
818
+ view.namePending = false;
819
+ });
820
+ }
821
+ if (!view.idPending && rt.getLocalNodeId) {
822
+ view.idPending = true;
823
+ void rt.getLocalNodeId().then((id) => {
824
+ if (current()) setBoundNodeId(id);
825
+ }).catch(() => {
826
+ }).finally(() => {
827
+ view.idPending = false;
828
+ });
829
+ }
830
+ };
831
+ refreshIdentity();
832
+ const unsub = runtimeRef.current.subscribeStatus?.(refreshIdentity);
833
+ const timer = setInterval(refreshIdentity, 3e3);
834
+ return () => {
835
+ view.active = false;
836
+ clearInterval(timer);
837
+ unsub?.();
838
+ };
839
+ }, [runtime.available, sessionKey, authenticated]);
840
+ const nodes = useLocalNodeList(client, runtime, session, boundNodeId, nodeName);
841
+ const prepareSetup = async (nodeId) => {
842
+ const view = viewRef.current;
843
+ const rt = runtimeRef.current;
844
+ const check = () => {
845
+ if (!view?.active || viewRef.current !== view || !view.isCurrent()) {
846
+ throw new Error("authentication session changed");
847
+ }
848
+ };
849
+ check();
850
+ const processRunning = rt.getNodeRunning ? await rt.getNodeRunning() : false;
851
+ check();
852
+ if (processRunning) {
853
+ const probe = await client.nodes.probe(nodeId);
854
+ check();
855
+ if (probe.online) return;
856
+ if (rt.stopNode) {
857
+ await rt.stopNode();
858
+ check();
859
+ }
860
+ }
861
+ if (rt.startNode) {
862
+ await rt.startNode();
863
+ check();
864
+ }
865
+ rt.notifyStatusChanged?.();
866
+ const deadline = Date.now() + 3e4;
867
+ do {
868
+ const probe = await client.nodes.probe(nodeId);
869
+ check();
870
+ if (probe.online) {
871
+ void nodes.refetch();
872
+ rt.notifyStatusChanged?.();
873
+ return;
874
+ }
875
+ await new Promise((resolve) => setTimeout(resolve, 500));
876
+ check();
877
+ } while (Date.now() < deadline);
878
+ throw new Error(t("sdkSettings.nodeConnectTimeout"));
879
+ };
880
+ const node = nodes.data?.find((n) => boundNodeId ? n.id === boundNodeId : Boolean(nodeName) && n.name === nodeName) ?? null;
881
+ const renderPanel = (target) => {
882
+ if (renderNodeCapability) {
883
+ return renderNodeCapability({ node: target, isTauri: true, beforeSetup: prepareSetup });
884
+ }
885
+ const inner = /* @__PURE__ */ jsx(NodeCapabilityPanel, { node: target, isTauri: true, beforeSetup: prepareSetup });
886
+ if (!optionalConfig && "cfg" in client && client.cfg) {
887
+ return /* @__PURE__ */ jsx(AixResolvedProvider, { config: client.cfg, children: inner });
888
+ }
889
+ return inner;
890
+ };
891
+ return /* @__PURE__ */ jsxs("div", { className: className ? `flex flex-col ${className}` : "flex flex-col", children: [
892
+ /* @__PURE__ */ jsxs("div", { className: "mb-4", children: [
893
+ /* @__PURE__ */ jsx("h2", { className: "text-sm font-semibold text-foreground", children: t("sdkSettings.nodeDetailsTitle") }),
894
+ /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("sdkSettings.nodeDetailsDesc") })
895
+ ] }),
896
+ node && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 border-b border-border/60 py-3", children: [
897
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.gatewayNode") }),
898
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t(node.status === "online" ? "sdkSettings.online" : "sdkSettings.offline") })
899
+ ] }),
900
+ !runtime.available ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-border bg-card px-5 py-3 text-xs text-muted-foreground", children: t("sdkSettings.desktopOnly") }) : !nodeName && !boundNodeId ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-border bg-card px-5 py-3 text-xs text-muted-foreground", children: t("sdkSettings.startFirst") }) : nodes.error && !node ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 rounded-lg border border-border bg-card px-5 py-3", children: [
901
+ /* @__PURE__ */ jsxs("span", { role: "alert", className: "break-words text-xs text-destructive", children: [
902
+ t("sdkSettings.error"),
903
+ ": ",
904
+ nodes.error
905
+ ] }),
906
+ /* @__PURE__ */ jsx(
907
+ "button",
908
+ {
909
+ type: "button",
910
+ disabled: nodes.loading,
911
+ onClick: () => void nodes.refetch(),
912
+ className: "rounded border border-border px-2.5 py-1 text-xs text-foreground hover:bg-secondary disabled:opacity-50",
913
+ children: t("sdkSettings.refresh")
914
+ }
915
+ )
916
+ ] }) : nodes.loading && !node ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 rounded-lg border border-border bg-card px-5 py-3 text-xs text-muted-foreground", children: [
917
+ /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
918
+ " ",
919
+ t("sdkSettings.loadingNode")
920
+ ] }) : !node ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 rounded-lg border border-border bg-card px-5 py-3", children: [
921
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("sdkSettings.nodeNotFound") }),
922
+ /* @__PURE__ */ jsx(
923
+ "button",
924
+ {
925
+ type: "button",
926
+ onClick: () => void nodes.refetch(),
927
+ className: "rounded border border-border px-2.5 py-1 text-xs text-foreground hover:bg-secondary",
928
+ children: t("sdkSettings.refresh")
929
+ }
930
+ )
931
+ ] }) : renderPanel(node)
932
+ ] });
933
+ }
934
+ function WebNodeDetailsView({
935
+ client,
936
+ session,
937
+ renderNodeCapability,
938
+ className
939
+ }) {
940
+ const t = useAixT();
941
+ const optionalConfig = useOptionalAixConfig();
942
+ const [nodes, setNodes] = useState(null);
943
+ const [loading, setLoading] = useState(true);
944
+ const [error, setError] = useState(null);
945
+ const [selectedId, setSelectedId] = useState("");
946
+ const seqRef = useRef(0);
947
+ const sessionKey = session?.id ?? "default";
948
+ const authenticated = session?.authenticated !== false;
949
+ const load = async () => {
950
+ if (!authenticated) return;
951
+ const seq = ++seqRef.current;
952
+ setLoading(true);
953
+ setError(null);
954
+ try {
955
+ const list = await client.nodes.list();
956
+ if (seqRef.current !== seq) return;
957
+ setNodes(list);
958
+ setSelectedId((prev) => {
959
+ if (prev && list.some((n) => n.id === prev)) return prev;
960
+ return (list.find((n) => n.status === "online") ?? list[0])?.id ?? "";
961
+ });
962
+ } catch (e) {
963
+ if (seqRef.current !== seq) return;
964
+ setNodes(null);
965
+ setError(errorMessage(e));
966
+ } finally {
967
+ if (seqRef.current === seq) setLoading(false);
968
+ }
969
+ };
970
+ useEffect(() => {
971
+ seqRef.current += 1;
972
+ setNodes(null);
973
+ setSelectedId("");
974
+ setError(null);
975
+ if (!authenticated) {
976
+ setLoading(false);
977
+ return;
978
+ }
979
+ void load();
980
+ }, [client, sessionKey, authenticated]);
981
+ const selected = nodes?.find((n) => n.id === selectedId) ?? nodes?.[0] ?? null;
982
+ const renderPanel = (target) => {
983
+ if (renderNodeCapability) {
984
+ return renderNodeCapability({ node: target, isTauri: false });
985
+ }
986
+ const inner = /* @__PURE__ */ jsx(NodeCapabilityPanel, { node: target, isTauri: false });
987
+ if (!optionalConfig && "cfg" in client && client.cfg) {
988
+ return /* @__PURE__ */ jsx(AixResolvedProvider, { config: client.cfg, children: inner });
989
+ }
990
+ return inner;
991
+ };
992
+ return /* @__PURE__ */ jsxs("div", { className: className ? `flex flex-col ${className}` : "flex flex-col", children: [
993
+ /* @__PURE__ */ jsxs("div", { className: "mb-4 flex flex-wrap items-start justify-between gap-3", children: [
994
+ /* @__PURE__ */ jsxs("div", { children: [
995
+ /* @__PURE__ */ jsx("h2", { className: "text-sm font-semibold text-foreground", children: t("sdkSettings.nodeDetailsTitle") }),
996
+ /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("sdkSettings.nodeDetailsWebDesc") })
997
+ ] }),
998
+ /* @__PURE__ */ jsx(
999
+ "button",
1000
+ {
1001
+ type: "button",
1002
+ disabled: loading,
1003
+ onClick: () => void load(),
1004
+ className: "rounded border border-border px-2.5 py-1 text-xs text-foreground hover:bg-secondary disabled:opacity-50",
1005
+ children: t("sdkSettings.refresh")
1006
+ }
1007
+ )
1008
+ ] }),
1009
+ loading && !nodes ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 rounded-lg border border-border bg-card px-5 py-3 text-xs text-muted-foreground", children: [
1010
+ /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
1011
+ " ",
1012
+ t("sdkSettings.loadingNode")
1013
+ ] }) : error && !nodes ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between gap-4 rounded-lg border border-border bg-card px-5 py-3", children: /* @__PURE__ */ jsxs("span", { role: "alert", className: "break-words text-xs text-destructive", children: [
1014
+ t("sdkSettings.error"),
1015
+ ": ",
1016
+ error
1017
+ ] }) }) : !selected ? /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-border bg-card px-5 py-3 text-xs text-muted-foreground", children: t("sdkSettings.noNodes") }) : /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
1018
+ nodes && nodes.length > 1 && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 rounded-lg border border-border bg-card px-5 py-3", children: [
1019
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.selectNode") }),
1020
+ /* @__PURE__ */ jsx(
1021
+ Select,
1022
+ {
1023
+ className: "w-56",
1024
+ value: selected.id,
1025
+ onChange: setSelectedId,
1026
+ placeholder: "",
1027
+ options: nodes.map((n) => ({
1028
+ value: n.id,
1029
+ label: `${n.name} (${t(n.status === "online" ? "sdkSettings.online" : "sdkSettings.offline")})`
1030
+ }))
1031
+ }
1032
+ )
1033
+ ] }),
1034
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 border-b border-border/60 py-2", children: [
1035
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.gatewayNode") }),
1036
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t(selected.status === "online" ? "sdkSettings.online" : "sdkSettings.offline") })
1037
+ ] }),
1038
+ renderPanel(selected)
1039
+ ] })
1040
+ ] });
1041
+ }
1042
+ function SdkNodeDetailsView({
1043
+ client,
1044
+ runtime,
1045
+ session,
1046
+ renderNodeCapability,
1047
+ className
1048
+ }) {
1049
+ if (runtime) {
1050
+ return /* @__PURE__ */ jsx(
1051
+ DesktopNodeDetailsView,
1052
+ {
1053
+ client,
1054
+ runtime,
1055
+ session,
1056
+ renderNodeCapability,
1057
+ className
1058
+ }
1059
+ );
1060
+ }
1061
+ return /* @__PURE__ */ jsx(
1062
+ WebNodeDetailsView,
1063
+ {
1064
+ client,
1065
+ session,
1066
+ renderNodeCapability,
1067
+ className
1068
+ }
1069
+ );
1070
+ }
1071
+ function ContextSdkNodeDetailsSection(props) {
1072
+ const client = useClient();
1073
+ return /* @__PURE__ */ jsx(SdkNodeDetailsView, { ...props, client });
1074
+ }
1075
+ function SdkNodeDetailsSection({ client, ...rest }) {
1076
+ if (client) {
1077
+ return /* @__PURE__ */ jsx(SdkNodeDetailsView, { ...rest, client });
1078
+ }
1079
+ return /* @__PURE__ */ jsx(ContextSdkNodeDetailsSection, { ...rest });
1080
+ }
1081
+
1082
+ // src/ui/settings/protocol.ts
1083
+ var PHASES = [
1084
+ "queued",
1085
+ "checking",
1086
+ "downloading",
1087
+ "verifying",
1088
+ "installing",
1089
+ "restarting",
1090
+ "completed",
1091
+ "failed"
1092
+ ];
1093
+ function parseSdkUpdate(result, operationId) {
1094
+ const response = result;
1095
+ const text = response?.content?.filter((item) => item.type === "text").map((item) => item.text ?? "").join("\n");
1096
+ if (response?.isError || response?.is_error) throw new Error(text || "SDK update tool failed");
1097
+ let status;
1098
+ try {
1099
+ status = JSON.parse(text ?? "");
1100
+ } catch {
1101
+ throw new Error("Invalid SDK update response");
1102
+ }
1103
+ if (status.api_version !== 1 || !PHASES.includes(status.phase) || !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(status.operation_id) || typeof status.installed_version !== "string" || !status.installed_version || status.target_version !== null && typeof status.target_version !== "string" || status.error !== null && typeof status.error !== "string" || operationId && status.operation_id !== operationId) {
1104
+ throw new Error("Unsupported or mismatched SDK update protocol");
1105
+ }
1106
+ return status;
1107
+ }
1108
+ function sdkVersion(output) {
1109
+ return output.trim().replace(/^\S+\s+(?=v?\d)/, "").replace(/^v/, "");
1110
+ }
1111
+ function verifySdkCompletion(status) {
1112
+ if (status.phase !== "completed") throw new Error(status.error || "SDK update has not completed");
1113
+ if (status.error) throw new Error(status.error);
1114
+ if (!status.target_version?.trim() || !status.installed_version.trim()) {
1115
+ throw new Error("SDK completion is missing version information");
1116
+ }
1117
+ }
1118
+ var DEFAULT_READY_TIMEOUT_MS = 18e4;
1119
+ var DEFAULT_HEALTH_READ_MS = 2e3;
1120
+ var DEFAULT_STORAGE_PREFIX = "aixautots.sdkUpdate";
1121
+ var SdkReadinessError = class extends Error {
1122
+ constructor(health) {
1123
+ super("SDK helper is not ready");
1124
+ this.health = health;
1125
+ }
1126
+ };
1127
+ function updatePhaseKey(phase) {
1128
+ return `sdkSettings.updatePhase${phase.charAt(0).toUpperCase()}${phase.slice(1)}`;
1129
+ }
1130
+ function SdkVersionSection({
1131
+ runtime,
1132
+ session,
1133
+ appName,
1134
+ className
1135
+ }) {
1136
+ const t = useAixT();
1137
+ const resolvedAppName = appName?.trim() || t("sdkSettings.defaultAppName");
1138
+ const storagePrefix = session?.storagePrefix || DEFAULT_STORAGE_PREFIX;
1139
+ const opKey = `${storagePrefix}.operationId`;
1140
+ const ownerKey = `${storagePrefix}.ownerEpoch`;
1141
+ const unknownKey = `${storagePrefix}.resultUnknown`;
1142
+ const [version, setVersion] = useState(null);
1143
+ const [status, setStatus] = useState(null);
1144
+ const [busy, setBusy] = useState(false);
1145
+ const [success, setSuccess] = useState(false);
1146
+ const [completion, setCompletion] = useState("checked");
1147
+ const [waitingForHelper, setWaitingForHelper] = useState(false);
1148
+ const [error, setError] = useState(null);
1149
+ const [resumeId, setResumeId] = useState(null);
1150
+ const [resultUnknown, setResultUnknown] = useState(false);
1151
+ const runtimeRef = useRef(runtime);
1152
+ runtimeRef.current = runtime;
1153
+ const sessionRef = useRef(session);
1154
+ sessionRef.current = session;
1155
+ const viewRef = useRef(null);
1156
+ const current = (view) => view.active && viewRef.current === view && view.isCurrent();
1157
+ const remember = (view, id, unknown = false) => {
1158
+ if (!current(view)) return;
1159
+ view.operationId = id;
1160
+ view.unknown = unknown;
1161
+ setResumeId(id);
1162
+ setResultUnknown(unknown);
1163
+ try {
1164
+ const storage = globalThis.localStorage;
1165
+ if (!storage) return;
1166
+ if (view.sessionId !== void 0) storage.setItem(ownerKey, String(view.sessionId));
1167
+ if (id) storage.setItem(opKey, id);
1168
+ else storage.removeItem(opKey);
1169
+ if (unknown) storage.setItem(unknownKey, "1");
1170
+ else storage.removeItem(unknownKey);
1171
+ } catch {
1172
+ }
1173
+ };
1174
+ const refreshVersion = async (view) => {
1175
+ if (!runtimeRef.current.getLauncherVersion) return null;
1176
+ const actual = sdkVersion(await runtimeRef.current.getLauncherVersion());
1177
+ if (current(view)) setVersion(actual);
1178
+ return actual;
1179
+ };
1180
+ const delay = (view, ms) => new Promise((resolve) => {
1181
+ const timer = setTimeout(() => {
1182
+ view.cancelDelay = void 0;
1183
+ resolve();
1184
+ }, ms);
1185
+ view.cancelDelay = () => {
1186
+ clearTimeout(timer);
1187
+ view.cancelDelay = void 0;
1188
+ resolve();
1189
+ };
1190
+ });
1191
+ const waitForHelper = async (view) => {
1192
+ if (!runtimeRef.current.getRuntimeHealth) return;
1193
+ setWaitingForHelper(true);
1194
+ const readinessMs = runtimeRef.current.readinessTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS;
1195
+ const healthReadMs = runtimeRef.current.healthReadTimeoutMs ?? DEFAULT_HEALTH_READ_MS;
1196
+ const deadline = Date.now() + readinessMs;
1197
+ let last = null;
1198
+ while (current(view)) {
1199
+ const readHealth = runtimeRef.current.getRuntimeHealth;
1200
+ const health = await new Promise((resolve) => {
1201
+ let settled = false;
1202
+ const finish = (value) => {
1203
+ if (settled) return;
1204
+ settled = true;
1205
+ clearTimeout(timer);
1206
+ if (view.cancelDelay === cancel) view.cancelDelay = void 0;
1207
+ resolve(value);
1208
+ };
1209
+ const cancel = () => finish(null);
1210
+ const timer = setTimeout(cancel, Math.min(healthReadMs, Math.max(0, deadline - Date.now())));
1211
+ view.cancelDelay = cancel;
1212
+ if (!readHealth) {
1213
+ finish(null);
1214
+ return;
1215
+ }
1216
+ void readHealth().then(finish, cancel);
1217
+ });
1218
+ if (!current(view)) return;
1219
+ if (health) last = health;
1220
+ const observed = health ?? last;
1221
+ if (observed?.app.phase === "accepting" && observed.mcp.phase === "running") return;
1222
+ const terminal = observed != null && (observed.app.phase !== "accepting" || ["backoff", "blocked", "disabled", "stopping", "stopped"].includes(observed.mcp.phase));
1223
+ if (terminal || Date.now() >= deadline) throw new SdkReadinessError(observed);
1224
+ await delay(view, 500);
1225
+ }
1226
+ };
1227
+ const formatUpdateError = (e) => {
1228
+ if (e instanceof SdkReadinessError) {
1229
+ const phase = e.health ? t(helperPhaseKey(e.health.mcp.phase)) : t("sdkSettings.unknown");
1230
+ return t("sdkSettings.updateHelperNotReady", { phase, appName: resolvedAppName });
1231
+ }
1232
+ const classified = runtimeRef.current.classifyError?.(e);
1233
+ if (classified?.code === "unavailable") {
1234
+ return t("sdkSettings.updateHelperUnavailable", { appName: resolvedAppName });
1235
+ }
1236
+ return errorMessage(e);
1237
+ };
1238
+ const follow = async (view, first) => {
1239
+ let update = first;
1240
+ while (current(view)) {
1241
+ setStatus(update);
1242
+ if (update.phase !== "completed" && update.phase !== "failed" && view.firstInstalledVersion === null) {
1243
+ view.firstInstalledVersion = update.installed_version;
1244
+ }
1245
+ if (update.phase === "completed" || update.phase === "failed") {
1246
+ if (update.phase === "failed") {
1247
+ view.terminalFailed = true;
1248
+ throw new Error(update.error || "SDK update failed");
1249
+ }
1250
+ verifySdkCompletion(update);
1251
+ const before = view.firstInstalledVersion;
1252
+ setCompletion(
1253
+ before !== null && before === update.installed_version && before === update.target_version ? "unchanged" : before !== null && before !== update.installed_version && update.installed_version === update.target_version ? "upgraded" : "checked"
1254
+ );
1255
+ remember(view, null);
1256
+ setSuccess(true);
1257
+ return;
1258
+ }
1259
+ await delay(view, 1e3);
1260
+ if (!current(view) || !runtimeRef.current.getUpdateStatus) return;
1261
+ const response = await runtimeRef.current.getUpdateStatus(update.operation_id);
1262
+ if (!current(view)) return;
1263
+ update = parseSdkUpdate(response, update.operation_id);
1264
+ }
1265
+ };
1266
+ const run = async (view) => {
1267
+ const rt = runtimeRef.current;
1268
+ if (!current(view) || !rt.available || !rt.triggerUpdate || !rt.getUpdateStatus) return;
1269
+ if (view.pending || view.unknown && !view.operationId) return;
1270
+ view.pending = true;
1271
+ setBusy(true);
1272
+ setSuccess(false);
1273
+ setCompletion("checked");
1274
+ setError(null);
1275
+ setStatus(null);
1276
+ try {
1277
+ await waitForHelper(view);
1278
+ if (!current(view)) return;
1279
+ setWaitingForHelper(false);
1280
+ const operationId = view.terminalFailed ? null : view.operationId;
1281
+ view.terminalFailed = false;
1282
+ if (!operationId) {
1283
+ view.firstInstalledVersion = null;
1284
+ remember(view, null, true);
1285
+ }
1286
+ const response = operationId ? await rt.getUpdateStatus(operationId) : await rt.triggerUpdate();
1287
+ if (!current(view)) return;
1288
+ const first = parseSdkUpdate(response, operationId ?? void 0);
1289
+ if (operationId && first.operation_id !== operationId) view.firstInstalledVersion = null;
1290
+ remember(view, first.operation_id);
1291
+ await follow(view, first);
1292
+ } catch (e) {
1293
+ if (!current(view)) return;
1294
+ const classified = rt.classifyError?.(e);
1295
+ if (!view.operationId && classified?.delivery === "not_sent") {
1296
+ remember(view, null);
1297
+ }
1298
+ setError(formatUpdateError(e));
1299
+ try {
1300
+ await refreshVersion(view);
1301
+ } catch {
1302
+ if (current(view)) setVersion(null);
1303
+ }
1304
+ } finally {
1305
+ view.pending = false;
1306
+ if (current(view)) {
1307
+ setBusy(false);
1308
+ setWaitingForHelper(false);
1309
+ }
1310
+ }
1311
+ };
1312
+ const sessionKey = session?.id ?? "default";
1313
+ const authenticated = session?.authenticated !== false;
1314
+ useEffect(() => {
1315
+ const capturedSession = sessionRef.current;
1316
+ const view = {
1317
+ sessionId: capturedSession?.id,
1318
+ isCurrent: () => isSessionActive(capturedSession),
1319
+ active: true,
1320
+ pending: false,
1321
+ operationId: null,
1322
+ unknown: false,
1323
+ terminalFailed: false,
1324
+ firstInstalledVersion: null
1325
+ };
1326
+ viewRef.current = view;
1327
+ setVersion(null);
1328
+ setStatus(null);
1329
+ setBusy(false);
1330
+ setSuccess(false);
1331
+ setCompletion("checked");
1332
+ setError(null);
1333
+ setWaitingForHelper(false);
1334
+ setResumeId(null);
1335
+ setResultUnknown(false);
1336
+ if (runtimeRef.current.available && authenticated) {
1337
+ try {
1338
+ const storage = globalThis.localStorage;
1339
+ if (storage) {
1340
+ const owner = storage.getItem(ownerKey);
1341
+ if (owner === null || capturedSession?.id === void 0 || owner === String(capturedSession.id)) {
1342
+ view.operationId = storage.getItem(opKey);
1343
+ view.unknown = storage.getItem(unknownKey) === "1";
1344
+ }
1345
+ }
1346
+ } catch {
1347
+ }
1348
+ setResumeId(view.operationId);
1349
+ setResultUnknown(view.unknown);
1350
+ void refreshVersion(view).catch(() => {
1351
+ if (current(view)) setVersion(null);
1352
+ });
1353
+ if (view.operationId) void run(view);
1354
+ }
1355
+ return () => {
1356
+ view.active = false;
1357
+ view.cancelDelay?.();
1358
+ };
1359
+ }, [runtime.available, sessionKey, authenticated, opKey, ownerKey, unknownKey]);
1360
+ const completionText = (() => {
1361
+ if (!status) return null;
1362
+ if (status.phase === "completed" && success) {
1363
+ const suffix = completion === "unchanged" ? "Unchanged" : completion === "upgraded" ? "Upgraded" : "Checked";
1364
+ return t(`sdkSettings.updateResult${suffix}`);
1365
+ }
1366
+ if (status.phase === "completed") return t("sdkSettings.updatePhaseVerifying");
1367
+ return t(updatePhaseKey(status.phase));
1368
+ })();
1369
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col", className), children: [
1370
+ /* @__PURE__ */ jsxs("div", { className: "mb-4", children: [
1371
+ /* @__PURE__ */ jsx("h2", { className: "text-sm font-semibold text-foreground", children: t("sdkSettings.versionTitle") }),
1372
+ /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("sdkSettings.versionDesc") })
1373
+ ] }),
1374
+ /* @__PURE__ */ jsx("p", { className: "mb-2 text-xs text-muted-foreground", children: t("sdkSettings.launcherRuntimeHint") }),
1375
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-border bg-card px-5 py-1", children: [
1376
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 border-b border-border/60 py-3 last:border-0", children: [
1377
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.launcherSdkVersion") }),
1378
+ /* @__PURE__ */ jsx("div", { className: "min-w-0 shrink-0 text-right", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-3", children: [
1379
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-xs text-muted-foreground", children: version ?? "\u2014" }),
1380
+ /* @__PURE__ */ jsxs(
1381
+ "button",
1382
+ {
1383
+ type: "button",
1384
+ disabled: !runtime.available || !authenticated || !runtime.triggerUpdate || busy || resultUnknown && !resumeId,
1385
+ onClick: () => {
1386
+ if (viewRef.current) void run(viewRef.current);
1387
+ },
1388
+ className: "inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-xs text-foreground hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-50",
1389
+ children: [
1390
+ busy && /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" }),
1391
+ t(resumeId && status?.phase !== "failed" ? "sdkSettings.resumeUpdate" : "sdkSettings.manualUpdate")
1392
+ ]
1393
+ }
1394
+ )
1395
+ ] }) })
1396
+ ] }),
1397
+ success && status && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4 border-b border-border/60 py-3 last:border-0", children: [
1398
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-foreground", children: t("sdkSettings.installedSdkVersion") }),
1399
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-xs text-muted-foreground", children: status.installed_version })
1400
+ ] }),
1401
+ resultUnknown && !resumeId && /* @__PURE__ */ jsx("p", { role: "status", className: "pb-3 text-xs text-muted-foreground", children: t("sdkSettings.updateResultUnknown", { appName: resolvedAppName }) }),
1402
+ busy && !status && !error && /* @__PURE__ */ jsx("p", { role: "status", className: "pb-3 text-xs text-muted-foreground", children: t(waitingForHelper ? "sdkSettings.updateWaitingHelper" : "sdkSettings.updatePhaseChecking") }),
1403
+ completionText && !error && /* @__PURE__ */ jsx("p", { role: "status", className: "pb-3 text-xs text-muted-foreground", children: completionText }),
1404
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words pb-3 text-xs text-destructive", children: error })
1405
+ ] })
1406
+ ] });
1407
+ }
1408
+ function SdkWalletSectionView({
1409
+ billing,
1410
+ clientCfg,
1411
+ sessionKey = "default",
1412
+ authenticated = true,
1413
+ blockedMessage,
1414
+ channel,
1415
+ returnUrl,
1416
+ cancelUrl,
1417
+ openExternalUrl,
1418
+ onOpenRecharge,
1419
+ onTopupCompleted,
1420
+ subscribeBillingUpdated,
1421
+ className
1422
+ }) {
1423
+ const t = useAixT();
1424
+ const optionalConfig = useOptionalAixConfig();
1425
+ const [wallet, setWallet] = useState({ status: "loading" });
1426
+ const [busy, setBusy] = useState(false);
1427
+ const [rechargeOpen, setRechargeOpen] = useState(false);
1428
+ const [billingOpen, setBillingOpen] = useState(false);
1429
+ const seqRef = useRef(0);
1430
+ const loadBalance = useCallback(async () => {
1431
+ if (!authenticated || blockedMessage) return;
1432
+ const seq = ++seqRef.current;
1433
+ setBusy(true);
1434
+ try {
1435
+ const data = await billing.balance();
1436
+ if (seqRef.current === seq) {
1437
+ setWallet({ status: "ready", data });
1438
+ }
1439
+ } catch {
1440
+ if (seqRef.current === seq) {
1441
+ setWallet({ status: "error" });
1442
+ }
1443
+ } finally {
1444
+ if (seqRef.current === seq) {
1445
+ setBusy(false);
1446
+ }
1447
+ }
1448
+ }, [authenticated, billing, blockedMessage]);
1449
+ useEffect(() => {
1450
+ seqRef.current += 1;
1451
+ setWallet({ status: "loading" });
1452
+ setRechargeOpen(false);
1453
+ setBillingOpen(false);
1454
+ if (!authenticated || blockedMessage) {
1455
+ setBusy(false);
1456
+ return;
1457
+ }
1458
+ void loadBalance();
1459
+ }, [authenticated, blockedMessage, loadBalance, sessionKey]);
1460
+ useEffect(() => {
1461
+ if (!subscribeBillingUpdated || !authenticated || blockedMessage) return;
1462
+ return subscribeBillingUpdated(() => {
1463
+ void loadBalance();
1464
+ });
1465
+ }, [authenticated, blockedMessage, loadBalance, subscribeBillingUpdated]);
1466
+ if (!authenticated) return null;
1467
+ const hasContextOrCfg = Boolean(optionalConfig || clientCfg);
1468
+ const wrapWithProvider = (node) => {
1469
+ if (!optionalConfig && clientCfg) {
1470
+ return /* @__PURE__ */ jsx(AixResolvedProvider, { config: clientCfg, children: node });
1471
+ }
1472
+ return node;
1473
+ };
1474
+ return /* @__PURE__ */ jsxs("section", { className: cn("space-y-3 text-xs text-foreground", className), "aria-labelledby": "sdk-wallet-title", children: [
1475
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
1476
+ /* @__PURE__ */ jsx("h2", { id: "sdk-wallet-title", className: "text-sm font-semibold text-foreground", children: t("sdkSettings.walletTitle") }),
1477
+ !blockedMessage && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1478
+ (onOpenRecharge || hasContextOrCfg) && /* @__PURE__ */ jsxs(
1479
+ "button",
1480
+ {
1481
+ type: "button",
1482
+ onClick: () => {
1483
+ if (onOpenRecharge) onOpenRecharge();
1484
+ else setRechargeOpen(true);
1485
+ },
1486
+ className: "inline-flex items-center gap-1 rounded bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground hover:bg-primary/90",
1487
+ children: [
1488
+ /* @__PURE__ */ jsx(Wallet, { className: "h-3.5 w-3.5" }),
1489
+ t("sdkSettings.topUp")
1490
+ ]
1491
+ }
1492
+ ),
1493
+ hasContextOrCfg && /* @__PURE__ */ jsxs(
1494
+ "button",
1495
+ {
1496
+ type: "button",
1497
+ onClick: () => setBillingOpen(true),
1498
+ className: "inline-flex items-center gap-1 rounded border border-border px-2.5 py-1 text-xs text-foreground hover:bg-secondary",
1499
+ children: [
1500
+ /* @__PURE__ */ jsx(Receipt, { className: "h-3.5 w-3.5" }),
1501
+ t("sdkSettings.viewBilling")
1502
+ ]
1503
+ }
1504
+ ),
1505
+ /* @__PURE__ */ jsxs(
1506
+ "button",
1507
+ {
1508
+ type: "button",
1509
+ disabled: busy,
1510
+ onClick: () => void loadBalance(),
1511
+ className: "inline-flex items-center gap-1 rounded border border-border px-2.5 py-1 text-xs text-foreground hover:bg-secondary disabled:opacity-50",
1512
+ children: [
1513
+ /* @__PURE__ */ jsx(RefreshCw, { className: cn("h-3.5 w-3.5", busy && "animate-spin") }),
1514
+ t("sdkSettings.refresh")
1515
+ ]
1516
+ }
1517
+ )
1518
+ ] })
1519
+ ] }),
1520
+ blockedMessage ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: blockedMessage }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1521
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("sdkSettings.walletDesc") }),
1522
+ /* @__PURE__ */ jsxs("div", { "aria-live": "polite", "aria-busy": busy, className: "space-y-2 rounded-lg border border-border bg-card px-5 py-3", children: [
1523
+ /* @__PURE__ */ jsxs("p", { children: [
1524
+ t("sdkSettings.walletBalance"),
1525
+ /* @__PURE__ */ jsx("span", { className: "font-mono font-medium", children: wallet.status === "error" ? t("sdkSettings.walletUnavailable") : wallet.status === "loading" ? t("sdkSettings.walletLoading") : `${wallet.data.balance} ${wallet.data.currency}` })
1526
+ ] }),
1527
+ wallet.status === "ready" && /* @__PURE__ */ jsxs("details", { children: [
1528
+ /* @__PURE__ */ jsx("summary", { className: "cursor-pointer text-muted-foreground hover:text-foreground", children: t("sdkSettings.recentActivity") }),
1529
+ wallet.data.recent.length > 0 ? /* @__PURE__ */ jsx("ul", { className: "mt-2 space-y-1", children: wallet.data.recent.map((row) => /* @__PURE__ */ jsxs("li", { className: "font-mono text-[11px] text-muted-foreground", children: [
1530
+ row.created_at.slice(0, 10),
1531
+ " \xB7 ",
1532
+ row.kind,
1533
+ " \xB7 ",
1534
+ String(row.amount),
1535
+ " ",
1536
+ row.currency
1537
+ ] }, row.id)) }) : /* @__PURE__ */ jsx("p", { className: "mt-2 text-muted-foreground", children: t("sdkSettings.noActivity") })
1538
+ ] })
1539
+ ] })
1540
+ ] }),
1541
+ !onOpenRecharge && rechargeOpen && hasContextOrCfg && wrapWithProvider(
1542
+ /* @__PURE__ */ jsx(
1543
+ RechargeDrawer,
1544
+ {
1545
+ open: rechargeOpen,
1546
+ onClose: () => setRechargeOpen(false),
1547
+ channel,
1548
+ returnUrl,
1549
+ cancelUrl,
1550
+ openExternalUrl,
1551
+ onTopupCompleted: async (res) => {
1552
+ await onTopupCompleted?.(res);
1553
+ await loadBalance();
1554
+ }
1555
+ }
1556
+ )
1557
+ ),
1558
+ billingOpen && hasContextOrCfg && wrapWithProvider(
1559
+ /* @__PURE__ */ jsx(
1560
+ Drawer,
1561
+ {
1562
+ open: billingOpen,
1563
+ onClose: () => setBillingOpen(false),
1564
+ title: t("billing.title"),
1565
+ widthClass: "max-w-3xl",
1566
+ children: /* @__PURE__ */ jsx(
1567
+ BillingPage,
1568
+ {
1569
+ channel,
1570
+ returnUrl,
1571
+ cancelUrl,
1572
+ openExternalUrl,
1573
+ onTopupCompleted: async (res) => {
1574
+ await onTopupCompleted?.(res);
1575
+ await loadBalance();
1576
+ }
1577
+ }
1578
+ )
1579
+ }
1580
+ )
1581
+ )
1582
+ ] });
1583
+ }
1584
+ function ContextSdkWalletSection(props) {
1585
+ const client = useClient();
1586
+ return /* @__PURE__ */ jsx(SdkWalletSectionView, { ...props, billing: client.billing, clientCfg: client.cfg });
1587
+ }
1588
+ function SdkWalletSection({ client, ...rest }) {
1589
+ if (client) {
1590
+ const cfg = "cfg" in client ? client.cfg : void 0;
1591
+ return /* @__PURE__ */ jsx(SdkWalletSectionView, { ...rest, billing: client.billing, clientCfg: cfg });
1592
+ }
1593
+ return /* @__PURE__ */ jsx(ContextSdkWalletSection, { ...rest });
1594
+ }
1595
+ function SdkSettingsPage({
1596
+ localRuntime,
1597
+ session,
1598
+ client,
1599
+ appName,
1600
+ channel,
1601
+ returnUrl,
1602
+ cancelUrl,
1603
+ openExternalUrl,
1604
+ onOpenRecharge,
1605
+ onTopupCompleted,
1606
+ subscribeBillingUpdated,
1607
+ walletBlockedMessage,
1608
+ sections,
1609
+ beforeSections,
1610
+ afterSections,
1611
+ wrapGatewaySections,
1612
+ renderNodeCapability,
1613
+ className
1614
+ }) {
1615
+ const optionalConfig = useOptionalAixConfig();
1616
+ const showVersion = sections?.version ?? Boolean(localRuntime);
1617
+ const showLocalNode = sections?.localNode ?? Boolean(localRuntime);
1618
+ const showWallet = sections?.wallet ?? true;
1619
+ const showNodeDetails = sections?.nodeDetails ?? true;
1620
+ const renderGatewaySections = (bridge) => {
1621
+ const resolvedClient = bridge?.client ?? client;
1622
+ const resolvedRenderer = bridge?.renderNodeCapability ?? renderNodeCapability;
1623
+ if (!showWallet && !showNodeDetails) return null;
1624
+ const content = /* @__PURE__ */ jsxs("div", { className: "space-y-10", children: [
1625
+ showWallet && /* @__PURE__ */ jsx(
1626
+ SdkWalletSection,
1627
+ {
1628
+ client: resolvedClient,
1629
+ sessionKey: session?.id,
1630
+ authenticated: session?.authenticated !== false,
1631
+ blockedMessage: walletBlockedMessage,
1632
+ channel,
1633
+ returnUrl,
1634
+ cancelUrl,
1635
+ openExternalUrl,
1636
+ onOpenRecharge,
1637
+ onTopupCompleted,
1638
+ subscribeBillingUpdated
1639
+ }
1640
+ ),
1641
+ showNodeDetails && /* @__PURE__ */ jsx(
1642
+ SdkNodeDetailsSection,
1643
+ {
1644
+ client: resolvedClient,
1645
+ runtime: localRuntime,
1646
+ session,
1647
+ renderNodeCapability: resolvedRenderer
1648
+ }
1649
+ )
1650
+ ] });
1651
+ if (!optionalConfig && resolvedClient && "cfg" in resolvedClient && resolvedClient.cfg) {
1652
+ return /* @__PURE__ */ jsx(AixResolvedProvider, { config: resolvedClient.cfg, children: content });
1653
+ }
1654
+ return content;
1655
+ };
1656
+ return /* @__PURE__ */ jsxs("div", { className: cn("space-y-10", className), children: [
1657
+ beforeSections,
1658
+ showVersion && localRuntime && /* @__PURE__ */ jsx(SdkVersionSection, { runtime: localRuntime, session, appName }),
1659
+ showLocalNode && localRuntime && /* @__PURE__ */ jsx(SdkLocalNodeSection, { runtime: localRuntime, session, appName }),
1660
+ wrapGatewaySections ? wrapGatewaySections(renderGatewaySections) : renderGatewaySections(),
1661
+ afterSections
1662
+ ] });
1663
+ }
1664
+
1665
+ export { EnvInitDialog, NodeCapabilityPanel, SdkLocalNodeSection, SdkNodeDetailsSection, SdkSettingsPage, SdkVersionSection, SdkWalletSection, parseSdkUpdate, sdkVersion, verifySdkCompletion, vmPlan };