@aixnn/aixautots 0.6.17 → 0.6.21

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