@aixnn/aixautots 0.6.4 → 0.6.6

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 (51) hide show
  1. package/dist/{automation-queue-BxrSIkG3.d.ts → automation-queue-aYRO9JLj.d.ts} +2 -2
  2. package/dist/{chunk-JTFZSFFA.js → chunk-7H4CYM42.js} +414 -5
  3. package/dist/{chunk-UJO7BJUV.js → chunk-A2CKXQ7U.js} +876 -106
  4. package/dist/{chunk-SAB5CH2K.js → chunk-AVRM42RS.js} +578 -141
  5. package/dist/{chunk-M4DO7SSZ.js → chunk-D7J4EQTA.js} +1 -1
  6. package/dist/{chunk-B2BOVLI6.js → chunk-F76N3GOA.js} +1077 -313
  7. package/dist/{chunk-Q63FQ7B5.js → chunk-LWTL4AIC.js} +254 -13
  8. package/dist/chunk-QZ3XJS2W.js +102 -0
  9. package/dist/{chunk-NGW34POA.js → chunk-SF5R25DU.js} +318 -15
  10. package/dist/{chunk-YFF7VLNT.js → chunk-SKTL6ACT.js} +40 -2
  11. package/dist/{chunk-T3QVYTOT.js → chunk-WUT5OUBG.js} +418 -0
  12. package/dist/{chunk-BYL2S2H6.js → chunk-X5KVYWUK.js} +4 -5
  13. package/dist/{config-CLi5IhmO.d.ts → config-B7t1Ln3w.d.ts} +177 -8
  14. package/dist/core/index.d.ts +21 -16
  15. package/dist/core/index.js +2 -4
  16. package/dist/{device-normalize-BaThgnH7.d.ts → device-normalize-CuGflfZA.d.ts} +1 -1
  17. package/dist/device-session-OFGN4KUD.js +1 -0
  18. package/dist/i18n/index.js +1 -1
  19. package/dist/{mirror-session-BP7Rd3Jk.d.ts → mirror-session-DK0OQvA3.d.ts} +11 -3
  20. package/dist/react/index.d.ts +10 -8
  21. package/dist/react/index.js +3 -6
  22. package/dist/{script-debugger-DtUGxK9i.d.ts → script-debugger-6hoLEwEz.d.ts} +1 -1
  23. package/dist/{task-agent-runner-DzV_OUZ7.d.ts → task-agent-runner-BwRW88rl.d.ts} +5 -3
  24. package/dist/{types-C2WXVcam.d.ts → types-BbtVr3QM.d.ts} +34 -3
  25. package/dist/ui/billing.d.ts +1 -1
  26. package/dist/ui/billing.js +5 -9
  27. package/dist/ui/device-create.d.ts +4 -3
  28. package/dist/ui/device-create.js +7 -9
  29. package/dist/ui/device-mirror.d.ts +16 -2
  30. package/dist/ui/device-mirror.js +6 -8
  31. package/dist/ui/devices.d.ts +5 -5
  32. package/dist/ui/devices.js +10 -13
  33. package/dist/ui/editor.d.ts +2 -2
  34. package/dist/ui/editor.js +7 -11
  35. package/dist/ui/index.d.ts +4 -4
  36. package/dist/ui/index.js +9 -15
  37. package/dist/ui/inspector.js +5 -9
  38. package/dist/ui/market.js +4 -7
  39. package/dist/ui/mirror.d.ts +3 -3
  40. package/dist/ui/primitives/index.d.ts +1 -1
  41. package/dist/ui/primitives/index.js +1 -2
  42. package/dist/ui/script-studio.js +6 -10
  43. package/dist/ui/scripts.d.ts +1 -1
  44. package/dist/ui/scripts.js +5 -9
  45. package/dist/ui/tasks.js +10 -13
  46. package/package.json +1 -1
  47. package/dist/chunk-A5VNENHD.js +0 -229
  48. package/dist/chunk-BUW45GM2.js +0 -341
  49. package/dist/chunk-H37NHOYU.js +0 -44
  50. package/dist/chunk-LAZ3RQ7X.js +0 -668
  51. package/dist/device-session-CVT7OY4H.js +0 -2
@@ -1,7 +1,8 @@
1
- import { cn, Select, Dialog, Button, Input, Badge } from './chunk-YFF7VLNT.js';
2
- import { useNodes, useDevices } from './chunk-Q63FQ7B5.js';
3
- import { useClient } from './chunk-A5VNENHD.js';
4
- import { useMemo, useEffect, useState, useCallback } from 'react';
1
+ import { canConnectPhysicalDevice, IosDeviceDiagnostics } from './chunk-QZ3XJS2W.js';
2
+ import { useAixT } from './chunk-WUT5OUBG.js';
3
+ import { cn, Select, Dialog, Button, Input, Badge } from './chunk-SKTL6ACT.js';
4
+ import { useNodes, useClient, useDevices } from './chunk-LWTL4AIC.js';
5
+ import { useMemo, useEffect, useState, useCallback, useRef } from 'react';
5
6
  import { Server, RefreshCw, Smartphone, Usb, Wifi, Info } from 'lucide-react';
6
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
8
 
@@ -336,145 +337,162 @@ function VirtualSpecStep({ spec, onChange, nodeId }) {
336
337
  }
337
338
  function AddWirelessDeviceDialog({ open, onClose, nodeId: initialNode, platform: initialPlatform }) {
338
339
  const client = useClient();
339
- const { refetch: fetchDevices } = useDevices();
340
340
  const [platform, setPlatform] = useState(initialPlatform ?? "android");
341
341
  const [nodes, setNodes] = useState([]);
342
342
  const [nodeId, setNodeId] = useState("");
343
343
  const [error, setError] = useState("");
344
- const [busy, setBusy] = useState(false);
345
- const [scan, setScan] = useState(null);
346
- const [manual, setManual] = useState(false);
347
- const [addr, setAddr] = useState("");
348
- const [code, setCode] = useState("");
349
- const [iosDevices, setIosDevices] = useState(null);
344
+ const [loading, setLoading] = useState(false);
350
345
  useEffect(() => {
351
346
  if (!open) return;
347
+ let cancelled = false;
352
348
  setPlatform(initialPlatform ?? "android");
349
+ setNodeId("");
350
+ setNodes([]);
353
351
  setError("");
354
- setScan(null);
355
- setIosDevices(null);
356
- setManual(false);
357
- setAddr("");
358
- setCode("");
359
- (async () => {
360
- try {
361
- const rows = (await client.nodes.list()).filter((n) => n.status === "online");
362
- setNodes(rows);
363
- const preferred = rows.find((n) => n.id === initialNode) ?? rows[0];
364
- setNodeId(preferred?.id ?? "");
365
- } catch (e) {
366
- setError(e.message);
367
- }
368
- })();
352
+ setLoading(true);
353
+ void client.nodes.list().then((rows) => {
354
+ if (cancelled) return;
355
+ setNodes(rows);
356
+ setNodeId(initialNode ?? "");
357
+ }).catch((e) => {
358
+ if (!cancelled) setError(e.message);
359
+ }).finally(() => {
360
+ if (!cancelled) setLoading(false);
361
+ });
362
+ return () => {
363
+ cancelled = true;
364
+ };
369
365
  }, [open, initialNode, initialPlatform, client]);
366
+ const available = nodes.filter((node) => canConnectPhysicalDevice(node, platform));
367
+ const selectedNode = available.find((node) => node.id === nodeId) ?? available[0];
368
+ return /* @__PURE__ */ jsx(Dialog, { open, onClose, title: "\u6DFB\u52A0\u65E0\u7EBF\u8BBE\u5907", description: "Android \u8D70 ADB \u914D\u5BF9/\u8FDE\u63A5\uFF1BiOS \u8D70\u4FE1\u4EFB\u914D\u5BF9\u540E\u542F\u7528\u65E0\u7EBF\u3002", children: /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
369
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 rounded-md border border-border bg-secondary p-0.5", children: [
370
+ /* @__PURE__ */ jsx(SegBtn, { active: platform === "android", onClick: () => setPlatform("android"), children: "Android" }),
371
+ /* @__PURE__ */ jsx(SegBtn, { active: platform === "ios", onClick: () => setPlatform("ios"), children: "iOS" })
372
+ ] }),
373
+ /* @__PURE__ */ jsxs("div", { children: [
374
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "\u8282\u70B9\uFF08\u4EC5\u672C\u4EBA\u5728\u7EBF\u4E14\u5141\u8BB8\u6B64\u7C7B\u771F\u673A\u63A5\u5165\u7684\u8282\u70B9\uFF09" }),
375
+ loading ? /* @__PURE__ */ jsx("p", { role: "status", className: "text-xs", children: "\u52A0\u8F7D\u8282\u70B9\u4E2D\u2026" }) : !selectedNode ? /* @__PURE__ */ jsx("p", { className: "rounded bg-secondary px-2 py-1.5 text-xs text-muted-foreground", children: platform === "ios" ? "\u6CA1\u6709\u53EF\u63A5\u5165 iOS \u771F\u673A\u7684\u8282\u70B9\u3002\u8BF7\u786E\u8BA4\u672C\u4EBA\u8282\u70B9\u5DF2\u5728\u7EBF\u3001\u5DF2\u4E0A\u62A5 iOS \u771F\u673A\u80FD\u529B\uFF0C\u5E76\u542F\u7528 iOS \u548C\u771F\u673A\u6743\u9650\u3002" : "\u6CA1\u6709\u53EF\u63A5\u5165 Android \u771F\u673A\u7684\u8282\u70B9\u3002\u8BF7\u786E\u8BA4\u672C\u4EBA\u8282\u70B9\u5DF2\u5728\u7EBF\u5E76\u542F\u7528\u771F\u673A\u6743\u9650\u3002" }) : /* @__PURE__ */ jsx(Select, { value: selectedNode.id, onChange: setNodeId, options: available.map((node) => ({ value: node.id, label: node.name })), placeholder: "\u9009\u62E9\u8282\u70B9" })
376
+ ] }),
377
+ open && selectedNode && !loading && /* @__PURE__ */ jsx(WirelessConnection, { nodeId: selectedNode.id, platform, lifecycleSupported: selectedNode.reported_caps?.ios_control?.diagnostics === true, onClose }, `${selectedNode.id}:${platform}`),
378
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-xs text-destructive", children: error }),
379
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onClose, children: "\u5173\u95ED" }) })
380
+ ] }) });
381
+ }
382
+ function WirelessConnection({ nodeId, platform, lifecycleSupported, onClose }) {
383
+ const client = useClient();
384
+ const { refetch: fetchDevices } = useDevices();
385
+ const [scan, setScan] = useState(null);
386
+ const [iosDevices, setIosDevices] = useState(null);
387
+ const [manual, setManual] = useState(false);
388
+ const [addr, setAddr] = useState("");
389
+ const [code, setCode] = useState("");
390
+ const [busy, setBusy] = useState(false);
391
+ const [error, setError] = useState("");
392
+ const alive = useRef(true);
393
+ const generation = useRef(0);
394
+ const mutation = useRef(false);
395
+ useEffect(() => {
396
+ alive.current = true;
397
+ return () => {
398
+ alive.current = false;
399
+ generation.current += 1;
400
+ };
401
+ }, []);
370
402
  const runScan = useCallback(async () => {
371
- if (!nodeId) return;
403
+ if (!alive.current || mutation.current) return;
404
+ const token = ++generation.current;
372
405
  setBusy(true);
373
406
  setError("");
407
+ setScan(null);
408
+ setIosDevices(null);
374
409
  try {
375
410
  if (platform === "android") {
376
- setScan(await client.nodes.adbScan(nodeId));
411
+ const result = await client.nodes.adbScan(nodeId);
412
+ if (alive.current && generation.current === token) setScan(result);
377
413
  } else {
378
- setIosDevices((await client.nodes.iosScan(nodeId)).devices);
414
+ const result = await client.nodes.iosScan(nodeId);
415
+ if (alive.current && generation.current === token) setIosDevices(result.devices);
379
416
  }
380
417
  } catch (e) {
381
- setError(friendly(e.message));
418
+ if (alive.current && generation.current === token) setError(friendly(e.message));
382
419
  } finally {
383
- setBusy(false);
420
+ if (alive.current && generation.current === token) setBusy(false);
384
421
  }
385
- }, [nodeId, platform, client]);
422
+ }, [client, nodeId, platform]);
386
423
  useEffect(() => {
387
- if (open && nodeId && !manual) runScan();
388
- }, [open, nodeId, platform, manual, runScan]);
424
+ if (!manual) void runScan();
425
+ }, [manual, runScan]);
389
426
  const wrap = async (fn, close = false) => {
427
+ if (!alive.current || mutation.current || busy) return;
428
+ mutation.current = true;
429
+ generation.current += 1;
390
430
  setBusy(true);
391
431
  setError("");
392
432
  try {
393
433
  await fn();
434
+ if (!alive.current) return;
394
435
  await fetchDevices();
436
+ if (!alive.current) return;
395
437
  if (close) onClose();
396
- else await runScan();
438
+ else {
439
+ mutation.current = false;
440
+ await runScan();
441
+ }
397
442
  } catch (e) {
398
- setError(friendly(e.message));
443
+ if (alive.current) setError(friendly(e.message));
399
444
  } finally {
400
- setBusy(false);
445
+ mutation.current = false;
446
+ if (alive.current) setBusy(false);
401
447
  }
402
448
  };
403
- const noNode = nodes.length === 0;
404
- return /* @__PURE__ */ jsx(
405
- Dialog,
406
- {
407
- open,
408
- onClose,
409
- title: "\u6DFB\u52A0\u65E0\u7EBF\u8BBE\u5907",
410
- description: "Android \u8D70 ADB \u914D\u5BF9/\u8FDE\u63A5\uFF1BiOS \u8D70\u4FE1\u4EFB\u914D\u5BF9\u540E\u542F\u7528\u65E0\u7EBF\u3002",
411
- children: /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
412
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 rounded-md border border-border bg-secondary p-0.5", children: [
413
- /* @__PURE__ */ jsx(SegBtn, { active: platform === "android", onClick: () => setPlatform("android"), children: "Android" }),
414
- /* @__PURE__ */ jsx(SegBtn, { active: platform === "ios", onClick: () => setPlatform("ios"), children: "iOS" })
415
- ] }),
416
- /* @__PURE__ */ jsxs("div", { children: [
417
- /* @__PURE__ */ jsx("label", { className: "text-[11px] text-muted-foreground", children: "\u8282\u70B9\uFF08\u4EC5\u5728\u7EBF\uFF09" }),
418
- noNode ? /* @__PURE__ */ jsx("p", { className: "rounded bg-secondary px-2 py-1.5 text-[11px] text-muted-foreground", children: "\u65E0\u5728\u7EBF\u8282\u70B9\u3002\u8BF7\u5148\u5728\u76EE\u6807\u8282\u70B9\u542F\u52A8 aixauto daemon \u540E\u5237\u65B0\u3002" }) : /* @__PURE__ */ jsx(
419
- Select,
420
- {
421
- value: nodeId,
422
- onChange: setNodeId,
423
- options: nodes.map((n) => ({ value: n.id, label: n.name })),
424
- placeholder: "\u9009\u62E9\u8282\u70B9"
425
- }
426
- )
427
- ] }),
428
- !noNode && /* @__PURE__ */ jsxs(Fragment, { children: [
429
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
430
- /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: platform === "android" ? "\u8282\u70B9\u4E0A\u62A5\u7684\u65E0\u7EBF ADB \u8BBE\u5907" : "\u8282\u70B9\u8FDE\u63A5\u7684 iOS \u8BBE\u5907" }),
431
- /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: runScan, children: [
432
- /* @__PURE__ */ jsx(RefreshCw, { className: cn("h-3.5 w-3.5", busy && "animate-spin") }),
433
- busy ? "\u626B\u63CF\u4E2D\u2026" : "\u626B\u63CF"
434
- ] })
435
- ] }),
436
- platform === "android" ? manual ? /* @__PURE__ */ jsx(
437
- AndroidManual,
438
- {
439
- addr,
440
- code,
441
- busy,
442
- onAddr: setAddr,
443
- onCode: setCode,
444
- onPair: () => {
445
- if (!addr.trim() || !code.trim())
446
- return setError("\u5730\u5740\u548C\u914D\u5BF9\u7801\u5FC5\u586B");
447
- wrap(() => client.nodes.adbPair(nodeId, addr.trim(), code.trim()), true);
448
- },
449
- onBack: () => setManual(false)
450
- }
451
- ) : /* @__PURE__ */ jsx(
452
- AndroidDiscover,
453
- {
454
- scan,
455
- busy,
456
- onConnect: (e) => wrap(() => client.nodes.adbConnect(nodeId, `${e.host}:${e.port}`), true),
457
- onManual: () => setManual(true)
458
- }
459
- ) : /* @__PURE__ */ jsx(
460
- IosDiscover,
461
- {
462
- devices: iosDevices,
463
- busy,
464
- onTrust: (udid) => wrap(() => client.nodes.iosPair(nodeId, udid)),
465
- onWifi: (udid) => wrap(() => client.nodes.iosWifi(nodeId, udid, true)),
466
- onUse: () => {
467
- void fetchDevices();
468
- onClose();
469
- }
470
- }
471
- )
472
- ] }),
473
- error && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-destructive", children: error }),
474
- /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onClose, children: "\u5173\u95ED" }) })
449
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
450
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
451
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: platform === "android" ? "\u8282\u70B9\u4E0A\u62A5\u7684\u65E0\u7EBF ADB \u8BBE\u5907" : "\u8282\u70B9\u8FDE\u63A5\u7684 iOS \u8BBE\u5907" }),
452
+ /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: () => void runScan(), children: [
453
+ /* @__PURE__ */ jsx(RefreshCw, { className: cn("h-3.5 w-3.5", busy && "animate-spin") }),
454
+ busy ? "\u626B\u63CF\u4E2D\u2026" : "\u626B\u63CF"
475
455
  ] })
476
- }
477
- );
456
+ ] }),
457
+ platform === "android" ? manual ? /* @__PURE__ */ jsx(
458
+ AndroidManual,
459
+ {
460
+ addr,
461
+ code,
462
+ busy,
463
+ onAddr: setAddr,
464
+ onCode: setCode,
465
+ onPair: () => {
466
+ if (!addr.trim() || !code.trim()) return setError("\u5730\u5740\u548C\u914D\u5BF9\u7801\u5FC5\u586B");
467
+ void wrap(() => client.nodes.adbPair(nodeId, addr.trim(), code.trim()), true);
468
+ },
469
+ onBack: () => setManual(false)
470
+ }
471
+ ) : /* @__PURE__ */ jsx(
472
+ AndroidDiscover,
473
+ {
474
+ scan,
475
+ busy,
476
+ onConnect: (entry) => void wrap(() => client.nodes.adbConnect(nodeId, `${entry.host}:${entry.port}`), true),
477
+ onManual: () => setManual(true)
478
+ }
479
+ ) : /* @__PURE__ */ jsx(
480
+ IosDiscover,
481
+ {
482
+ nodeId,
483
+ lifecycleSupported,
484
+ devices: iosDevices,
485
+ busy,
486
+ onTrust: (udid) => void wrap(() => client.nodes.iosPair(nodeId, udid)),
487
+ onWifi: (udid) => void wrap(() => client.nodes.iosWifi(nodeId, udid, true)),
488
+ onUse: () => {
489
+ void fetchDevices();
490
+ onClose();
491
+ }
492
+ }
493
+ ),
494
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-xs text-destructive", children: error })
495
+ ] });
478
496
  }
479
497
  function AndroidDiscover({
480
498
  scan,
@@ -545,6 +563,8 @@ function AndroidManual({
545
563
  ] });
546
564
  }
547
565
  function IosDiscover({
566
+ nodeId,
567
+ lifecycleSupported,
548
568
  devices,
549
569
  busy,
550
570
  onTrust,
@@ -555,30 +575,32 @@ function IosDiscover({
555
575
  return /* @__PURE__ */ jsx("p", { className: "py-4 text-center text-[11px] text-muted-foreground", children: busy ? "\u626B\u63CF\u4E2D\u2026" : "\u672A\u53D1\u73B0 iOS \u8BBE\u5907\u3002USB \u8FDE\u63A5\u8BBE\u5907\u540E\u5237\u65B0\u91CD\u8BD5\u3002" });
556
576
  }
557
577
  return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
558
- /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground/70", children: "\u65B0\u8BBE\u5907\u9700\u5148 USB \u8FDE\u63A5\u5E76\u5728\u8BBE\u5907\u4E0A\u70B9\u300C\u4FE1\u4EFB\u300D\uFF0C\u518D\u542F\u7528\u65E0\u7EBF\u5373\u53EF\u62D4\u7EBF\u4F7F\u7528\u3002" }),
578
+ /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground/70", children: "\u65B0\u8BBE\u5907\u9700\u5148 USB \u8FDE\u63A5\u5E76\u5728\u8BBE\u5907\u4E0A\u70B9\u300C\u4FE1\u4EFB\u300D\uFF0C\u518D\u542F\u7528\u65E0\u7EBF\u3002\u5F00\u542F\u914D\u7F6E\u4E0D\u4EE3\u8868\u65E0\u7EBF\u5DF2\u8FDE\u901A\uFF1B\u540C\u4E00\u7F51\u7EDC\u4E0B\u62D4\u7EBF\u540E\u91CD\u65B0\u626B\u63CF\u5E76\u9A8C\u8BC1\u622A\u56FE\u3002\u672A\u77E5\u901A\u9053\u4E0D\u89C6\u4E3A USB \u6216\u65E0\u7EBF\u5C31\u7EEA\u3002" }),
559
579
  devices.map((d) => /* @__PURE__ */ jsxs(
560
580
  "div",
561
581
  {
562
- className: "flex items-center gap-2 rounded-md border border-border bg-card px-2 py-1.5",
582
+ className: "flex flex-wrap items-center gap-2 rounded-md border border-border bg-card px-2 py-1.5",
563
583
  children: [
564
584
  /* @__PURE__ */ jsx(Smartphone, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
565
585
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
566
586
  /* @__PURE__ */ jsx("code", { className: "block truncate text-[11px]", children: d.udid }),
567
587
  /* @__PURE__ */ jsxs("div", { className: "mt-0.5 flex items-center gap-1", children: [
568
- d.usb && /* @__PURE__ */ jsxs(Badge, { variant: "info", children: [
588
+ d.usb === true && /* @__PURE__ */ jsxs(Badge, { variant: "info", children: [
569
589
  /* @__PURE__ */ jsx(Usb, { className: "mr-0.5 h-3 w-3" }),
570
590
  "USB"
571
591
  ] }),
572
- d.wireless && /* @__PURE__ */ jsxs(Badge, { variant: "success", children: [
592
+ d.wireless === true && /* @__PURE__ */ jsxs(Badge, { variant: "success", children: [
573
593
  /* @__PURE__ */ jsx(Wifi, { className: "mr-0.5 h-3 w-3" }),
574
- "\u65E0\u7EBF"
575
- ] })
594
+ "\u7F51\u7EDC\u901A\u9053\u5DF2\u53D1\u73B0"
595
+ ] }),
596
+ (d.usb == null || d.wireless == null) && /* @__PURE__ */ jsx(Badge, { children: "\u90E8\u5206\u8FDE\u63A5\u901A\u9053\u672A\u77E5" })
576
597
  ] })
577
598
  ] }),
578
- d.wireless ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: onUse, children: "\u4F7F\u7528" }) : /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [
599
+ d.wireless === true ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: onUse, children: "\u4F7F\u7528" }) : /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [
579
600
  /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: () => onTrust(d.udid), children: "\u4FE1\u4EFB\u914D\u5BF9" }),
580
601
  /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: () => onWifi(d.udid), children: "\u542F\u7528\u65E0\u7EBF" })
581
- ] })
602
+ ] }),
603
+ lifecycleSupported && /* @__PURE__ */ jsx(IosDeviceDiagnostics, { nodeId, udid: d.udid })
582
604
  ]
583
605
  },
584
606
  d.udid
@@ -720,10 +742,8 @@ function RealDiscoverStep({ nodeId, picked, onPick }) {
720
742
  function redactProxyUrl(value) {
721
743
  const at = value.lastIndexOf("@");
722
744
  if (at < 0) return value;
723
- const credentials = value.slice(0, at);
724
- const separator = credentials.lastIndexOf(":");
725
- if (separator < 0) return value;
726
- return `${credentials.slice(0, separator + 1)}***${value.slice(at)}`;
745
+ const scheme = value.indexOf("://");
746
+ return `${scheme >= 0 ? value.slice(0, scheme + 3) : ""}***:***${value.slice(at)}`;
727
747
  }
728
748
  function isRedactedProxyUrl(value) {
729
749
  return value.includes(":***@");
@@ -758,11 +778,21 @@ function proxySummaryFromDevice(device) {
758
778
  function isProxyApplyStatus(value) {
759
779
  return value === "pending" || value === "applied" || value === "failed" || value === "unsupported" || value === "unsupported_legacy";
760
780
  }
781
+ function deviceProxyCapabilities(device, node) {
782
+ const meta = device?.meta ?? {};
783
+ const spec = meta.spec;
784
+ const platform = meta.platform ?? spec?.platform ?? device?.platform;
785
+ const redroid = meta.provisioned === true && [void 0, "android", "redroid"].includes(platform) && spec?.kind !== "android-real" && spec?.platform !== "android-real";
786
+ const nodeId = typeof meta.node_id === "string" ? meta.node_id : null;
787
+ const cap = node?.reported_caps?.egress_proxy;
788
+ const custom = redroid && !!nodeId && node?.id === nodeId && cap?.supported === true;
789
+ return { custom, managed: custom && cap?.revision_fencing === true };
790
+ }
761
791
  function proxyCapabilityReason(device) {
762
792
  if (device.platform !== "android" || device.meta?.provisioned !== true) {
763
793
  return "Per-device transparent proxy requires a provisioned virtual Android Redroid device.";
764
794
  }
765
- if (!(device.node_id ?? device.nodeId) && !device.meta?.node_id) {
795
+ if (typeof device.meta?.node_id !== "string" || !device.meta.node_id) {
766
796
  return "The owning node is unknown, so per-device proxy is unavailable.";
767
797
  }
768
798
  return "The owning node does not report per-device transparent proxy capability.";
@@ -804,7 +834,7 @@ var LOCALE_OPTIONS = [
804
834
  { value: "ja-JP", label: "\u65E5\u672C\u8A9E (ja-JP)" },
805
835
  { value: "ko-KR", label: "\uD55C\uAD6D\uC5B4 (ko-KR)" }
806
836
  ];
807
- function ProxySpoofStep({ spec, onChange, isReal }) {
837
+ function ProxySpoofStep({ spec, onChange, isReal, showProxy = !isReal }) {
808
838
  const proxy = spec.proxy ?? "";
809
839
  const locale = spec.config?.locale ?? "";
810
840
  const proxyInvalid = proxy.trim().length > 0 && !isSupportedProxyUrl(proxy.trim());
@@ -825,7 +855,7 @@ function ProxySpoofStep({ spec, onChange, isReal }) {
825
855
  onChange({ ...spec, config, region });
826
856
  };
827
857
  return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
828
- /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
858
+ showProxy && /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
829
859
  /* @__PURE__ */ jsx("p", { className: "text-label-caps text-muted-foreground", children: "\u4EE3\u7406 proxy" }),
830
860
  /* @__PURE__ */ jsxs("div", { children: [
831
861
  /* @__PURE__ */ jsx("label", { className: "text-[11px] text-muted-foreground", children: "\u4EE3\u7406\u5730\u5740 URL" }),
@@ -850,7 +880,7 @@ function ProxySpoofStep({ spec, onChange, isReal }) {
850
880
  proxyInvalid && /* @__PURE__ */ jsx("p", { className: "mt-1 text-[11px] text-destructive", children: "\u8BF7\u8F93\u5165 http://\u4E3B\u673A:\u7AEF\u53E3 \u6216 http://\u7528\u6237\u540D:\u5BC6\u7801@\u4E3B\u673A:\u7AEF\u53E3\uFF1B\u4E0D\u652F\u6301 socks/https\u3002" })
851
881
  ] })
852
882
  ] }),
853
- /* @__PURE__ */ jsxs("section", { className: "space-y-2", children: [
883
+ !isReal && /* @__PURE__ */ jsxs("section", { className: "space-y-2", children: [
854
884
  /* @__PURE__ */ jsx("p", { className: "text-label-caps text-muted-foreground", children: "\u6307\u7EB9 spoof" }),
855
885
  /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: "\u8BBE\u5907\u6307\u7EB9\u7531\u540E\u7AEF\u81EA\u52A8\u968F\u673A\u751F\u6210\uFF08device_profile\uFF09\u3002\u4E0B\u65B9\u4E3A\u53EF\u9009\u7684\u5730\u533A/\u8BED\u8A00\u63D0\u793A\u3002" }),
856
886
  /* @__PURE__ */ jsxs("div", { children: [
@@ -868,13 +898,383 @@ function ProxySpoofStep({ spec, onChange, isReal }) {
868
898
  ] }),
869
899
  /* @__PURE__ */ jsxs("div", { className: "flex gap-2 rounded-md border border-border bg-secondary px-3 py-2", children: [
870
900
  /* @__PURE__ */ jsx(Info, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
871
- /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: isReal ? "\u771F\u673A\u7684\u4EE3\u7406/\u6307\u7EB9\u914D\u7F6E\u4F1A\u88AB\u8BB0\u5F55\uFF0C\u4F46\u8282\u70B9\u4FA7\u5F3A\u5236\u8DEF\u7531\u4ECD\u5728\u5F00\u53D1\u4E2D\uFF08follow-up\uFF09\uFF0C\u6682\u4E0D\u4F1A\u5B9E\u9645\u751F\u6548\u3002" : "\u865A\u62DF\u8BBE\u5907\u7684\u4EE3\u7406\u968F provision \u89C4\u683C\u4E0B\u53D1\u5230\u8282\u70B9\u5E76\u5B8C\u6574\u751F\u6548\u3002" })
901
+ /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground", children: isReal ? "\u6B64\u6B65\u9AA4\u4EC5\u767B\u8BB0\u771F\u673A\uFF0C\u4E0D\u4F1A\u5E94\u7528\u7CFB\u7EDF\u4EE3\u7406\u6216\u6307\u7EB9\u8BBE\u7F6E\u3002" : "\u4EE3\u7406\u4EC5\u7528\u4E8E\u5DF2\u62A5\u544A\u652F\u6301\u7684 Redroid \u8282\u70B9\u3002\u81EA\u5B9A\u4E49\u4EE3\u7406\u53EA\u63A5\u7BA1\u652F\u6301\u7684 TCP \u6D41\u91CF\uFF0CUDP/QUIC/DNS \u4E0D\u7ECF\u8FC7\u6B64\u4EE3\u7406\u3002" })
902
+ ] })
903
+ ] });
904
+ }
905
+
906
+ // src/ui/device-create/managed-creation-state.ts
907
+ var creationStorageKey = (baseUrl, owner, project) => `aix-managed-creation:v1:${JSON.stringify([baseUrl, owner, project])}`;
908
+ function readCreationRequest(key) {
909
+ if (!key) return null;
910
+ try {
911
+ const value = JSON.parse(localStorage.getItem(key) ?? "null");
912
+ return value && typeof value.request_id === "string" && typeof value.quote_id === "string" && Number.isSafeInteger(value.authorized_total_minor) && value.authorized_total_minor >= 0 && value.currency === "CNY" ? value : null;
913
+ } catch {
914
+ return null;
915
+ }
916
+ }
917
+ function validCreationQuote(quote) {
918
+ return !!quote && typeof quote.id === "string" && typeof quote.owner_user_id === "string" && typeof quote.project_id === "string" && Number.isSafeInteger(quote.total_minor) && quote.total_minor >= 0 && quote.currency === "CNY" && !!quote.product && quote.product.currency === "CNY" && quote.product.billing_mode === "one_time" && quote.product.auto_renew === false && quote.product.refund_policy === "no_refund_after_allocation" && Number.isSafeInteger(quote.product.fixed_cost_minor) && (quote.product.fixed_cost_minor ?? -1) >= 0 && Number.isSafeInteger(quote.product.quota_value) && quote.product.quota_value >= 0 && Number.isFinite(quote.product.rate_minor_per_gib) && (quote.product.rate_minor_per_gib ?? -1) >= 0 && quote.product.budget_accounting === "reserved_upper_bound" && (quote.product.reservation_bytes ?? 0) > 0 && (quote.product.handshake_reservation_bytes ?? 0) > 0 && !!quote.device_billing && ["personal_free", "metered"].includes(quote.device_billing.kind) && typeof quote.device_billing.rate_per_hour === "string" && Number.isFinite(Number(quote.device_billing.rate_per_hour)) && Number(quote.device_billing.rate_per_hour) >= 0 && typeof quote.device_billing.currency === "string" && Number.isFinite(Date.parse(quote.expires_at));
919
+ }
920
+ function creationReady(receipt) {
921
+ return receipt?.creation_status === "ready" && receipt.proxy_order.status === "fulfilled" && receipt.proxy_order.apply_status === "applied";
922
+ }
923
+ function creationRejected(error) {
924
+ return error?.requestState === "rejected";
925
+ }
926
+ var money = (minor) => `\xA5${(minor / 100).toFixed(2)}`;
927
+ function ManagedCreationPanel(props) {
928
+ const client = useClient();
929
+ const t = useAixT();
930
+ const translate = useRef(t);
931
+ translate.current = t;
932
+ const epoch = useRef(0);
933
+ const [catalog, setCatalog] = useState(null);
934
+ const [identity, setIdentity] = useState(null);
935
+ const [request, setRequest] = useState(null);
936
+ const [receipt, setReceipt] = useState(null);
937
+ const [quote, setQuote] = useState(null);
938
+ const [productId, setProductId] = useState("");
939
+ const [region, setRegion] = useState("");
940
+ const [kind, setKind] = useState("static");
941
+ const [error, setError] = useState("");
942
+ const [busy, setBusy] = useState(false);
943
+ const [loaded, setLoaded] = useState(false);
944
+ const [fresh, setFresh] = useState(false);
945
+ const [now, setNow] = useState(Date.now());
946
+ const active = useRef(true);
947
+ const inFlight = useRef(false);
948
+ const pollInFlight = useRef(null);
949
+ const requestRef = useRef(request);
950
+ const storageRef = useRef(null);
951
+ const identityClient = useRef(null);
952
+ const controllers = useRef(/* @__PURE__ */ new Set());
953
+ const propsRef = useRef(props);
954
+ propsRef.current = props;
955
+ const setPending = (value) => {
956
+ requestRef.current = value;
957
+ setRequest(value);
958
+ };
959
+ const scopeKey = identity ? creationStorageKey(client.cfg.baseUrl, identity.owner_user_id, identity.project_id) : null;
960
+ storageRef.current = scopeKey;
961
+ const run = useCallback(async (operation) => {
962
+ const controller = new AbortController();
963
+ controllers.current.add(controller);
964
+ const timer = setTimeout(() => controller.abort(), 3e4);
965
+ try {
966
+ return await operation(controller.signal);
967
+ } finally {
968
+ clearTimeout(timer);
969
+ controllers.current.delete(controller);
970
+ }
971
+ }, []);
972
+ const refresh = useCallback(async () => {
973
+ const generation = epoch.current;
974
+ if (pollInFlight.current === generation) return;
975
+ pollInFlight.current = generation;
976
+ try {
977
+ const context = await run((signal) => client.proxies.creations({ signal }));
978
+ if (!active.current || generation !== epoch.current) return;
979
+ if (!context || typeof context.owner_user_id !== "string" || typeof context.project_id !== "string" || !Array.isArray(context.items)) throw new Error(translate.current("creation.invalidService"));
980
+ const key = creationStorageKey(client.cfg.baseUrl, context.owner_user_id, context.project_id);
981
+ if (storageRef.current && storageRef.current !== key) {
982
+ controllers.current.forEach((controller) => controller.abort());
983
+ setQuote(null);
984
+ setReceipt(null);
985
+ setError("");
986
+ setBusy(false);
987
+ }
988
+ storageRef.current = key;
989
+ identityClient.current = client;
990
+ setIdentity(context);
991
+ setFresh(true);
992
+ let pending = readCreationRequest(key);
993
+ let found = pending ? context.items.find((item) => item.request_id === pending.request_id) : context.items[0];
994
+ if (pending && !found) {
995
+ try {
996
+ found = await run((signal) => client.proxies.creationByRequest(pending.request_id, { signal }));
997
+ } catch {
998
+ }
999
+ }
1000
+ if (!active.current || generation !== epoch.current) return;
1001
+ if (found && (!pending || pending.request_id === found.request_id)) {
1002
+ if (!pending) {
1003
+ pending = { request_id: found.request_id, quote_id: found.quote_id, authorized_total_minor: found.proxy_order.total_minor, currency: "CNY", uncertain: true };
1004
+ localStorage.setItem(key, JSON.stringify(pending));
1005
+ }
1006
+ setReceipt(found);
1007
+ } else setReceipt((previous) => previous?.request_id === pending?.request_id ? previous : null);
1008
+ setPending(pending);
1009
+ propsRef.current.onPendingChange(!!pending);
1010
+ } catch (e) {
1011
+ if (active.current && generation === epoch.current) {
1012
+ setFresh(false);
1013
+ setError(e.message);
1014
+ }
1015
+ } finally {
1016
+ if (pollInFlight.current === generation) pollInFlight.current = null;
1017
+ if (active.current && generation === epoch.current) setLoaded(true);
1018
+ }
1019
+ }, [client, run]);
1020
+ useEffect(() => {
1021
+ active.current = true;
1022
+ const generation = ++epoch.current;
1023
+ storageRef.current = null;
1024
+ identityClient.current = null;
1025
+ setIdentity(null);
1026
+ setFresh(false);
1027
+ setQuote(null);
1028
+ setReceipt(null);
1029
+ setPending(null);
1030
+ setLoaded(false);
1031
+ setBusy(false);
1032
+ propsRef.current.onPendingChange(false);
1033
+ let timer;
1034
+ const poll = async () => {
1035
+ if (!document.hidden) await refresh();
1036
+ if (active.current && generation === epoch.current) timer = setTimeout(() => void poll(), requestRef.current ? 3e3 : 3e4);
1037
+ };
1038
+ void run((signal) => client.proxies.catalog({ signal })).then((value) => {
1039
+ if (!value || typeof value.enabled !== "boolean" || !Array.isArray(value.products)) throw new Error(translate.current("creation.invalidService"));
1040
+ if (active.current && generation === epoch.current) setCatalog(value);
1041
+ }).catch((e) => {
1042
+ if (active.current && generation === epoch.current) setError(e.message);
1043
+ });
1044
+ void poll();
1045
+ const clock = setInterval(() => setNow(Date.now()), 1e3);
1046
+ const visible = () => {
1047
+ if (!document.hidden) void refresh();
1048
+ };
1049
+ const storage = (event) => {
1050
+ if (event.key === storageRef.current) void refresh();
1051
+ };
1052
+ document.addEventListener("visibilitychange", visible);
1053
+ window.addEventListener("storage", storage);
1054
+ return () => {
1055
+ active.current = false;
1056
+ epoch.current++;
1057
+ clearTimeout(timer);
1058
+ clearInterval(clock);
1059
+ controllers.current.forEach((c) => c.abort());
1060
+ document.removeEventListener("visibilitychange", visible);
1061
+ window.removeEventListener("storage", storage);
1062
+ };
1063
+ }, [client, refresh, run]);
1064
+ const specKey = JSON.stringify(props.spec);
1065
+ useEffect(() => {
1066
+ setQuote(null);
1067
+ }, [specKey, productId, kind, region, props.quantity, props.supported, scopeKey]);
1068
+ const regions = [...new Set(catalog?.products.map((product) => product.region) ?? [])];
1069
+ const selectedRegion = regions.includes(region) ? region : regions[0] ?? "";
1070
+ const products = catalog?.products.filter((product) => product.kind === kind && product.region === selectedRegion) ?? [];
1071
+ const selected = products.find((product) => product.id === productId) ?? products[0];
1072
+ const disabled = !props.supported || props.quantity !== 1 || !catalog?.enabled || !identity || identityClient.current !== client || !loaded || !fresh || busy || !!request;
1073
+ const expired = quote ? Date.parse(quote.expires_at) <= now : true;
1074
+ const getQuote = async () => {
1075
+ if (disabled || !selected || inFlight.current) return;
1076
+ inFlight.current = true;
1077
+ setBusy(true);
1078
+ setError("");
1079
+ setQuote(null);
1080
+ const inputSnapshot = specKey;
1081
+ const generation = epoch.current;
1082
+ const key = scopeKey;
1083
+ try {
1084
+ const value = await run((signal) => client.proxies.creationQuote({ spec: props.spec, product_id: selected.id }, { signal }));
1085
+ if (!active.current || generation !== epoch.current || storageRef.current !== key || JSON.stringify(propsRef.current.spec) !== inputSnapshot) return;
1086
+ if (!validCreationQuote(value) || value.owner_user_id !== identity.owner_user_id || value.project_id !== identity.project_id || value.node_id !== props.spec.node_id || value.product.id !== selected.id) throw new Error(t("creation.invalidQuote"));
1087
+ setQuote(value);
1088
+ setNow(Date.now());
1089
+ } catch (e) {
1090
+ if (active.current && generation === epoch.current && storageRef.current === key) setError(e.message);
1091
+ } finally {
1092
+ inFlight.current = false;
1093
+ if (active.current && generation === epoch.current && storageRef.current === key) setBusy(false);
1094
+ }
1095
+ };
1096
+ const submit = async (input) => {
1097
+ if (!scopeKey || inFlight.current || !request && disabled) return;
1098
+ inFlight.current = true;
1099
+ setBusy(true);
1100
+ setError("");
1101
+ const key = scopeKey;
1102
+ const generation = epoch.current;
1103
+ const current = () => active.current && generation === epoch.current && storageRef.current === key && identityClient.current === client;
1104
+ const send = async () => {
1105
+ if (!current()) return;
1106
+ let uncertain = !!input.uncertain;
1107
+ let sent = false;
1108
+ try {
1109
+ const previous = readCreationRequest(key);
1110
+ if (previous && previous.request_id !== input.request_id) {
1111
+ setPending(previous);
1112
+ throw new Error(t("managed.otherRequest"));
1113
+ }
1114
+ uncertain ||= previous?.request_id === input.request_id || requestRef.current?.request_id === input.request_id;
1115
+ const durable = { ...input, uncertain };
1116
+ localStorage.setItem(key, JSON.stringify(durable));
1117
+ setPending(durable);
1118
+ propsRef.current.onPendingChange(true);
1119
+ sent = true;
1120
+ const value = await run((signal) => client.proxies.create({ request_id: input.request_id, quote_id: input.quote_id, authorized_total_minor: input.authorized_total_minor, currency: "CNY" }, { signal }));
1121
+ if (value.request_id !== input.request_id || value.quote_id !== input.quote_id) throw new Error(translate.current("creation.invalidService"));
1122
+ if (current()) {
1123
+ setReceipt(value);
1124
+ setQuote(null);
1125
+ await refresh();
1126
+ }
1127
+ } catch (e) {
1128
+ const stored = readCreationRequest(key);
1129
+ uncertain ||= stored?.request_id === input.request_id && !!stored.uncertain;
1130
+ if (sent && creationRejected(e) && !uncertain) {
1131
+ if (stored?.request_id === input.request_id) localStorage.removeItem(key);
1132
+ if (current()) {
1133
+ setPending(null);
1134
+ setQuote(null);
1135
+ propsRef.current.onPendingChange(false);
1136
+ }
1137
+ } else if (sent) {
1138
+ if (stored?.request_id === input.request_id) localStorage.setItem(key, JSON.stringify({ ...stored, uncertain: true }));
1139
+ if (current()) await refresh();
1140
+ }
1141
+ if (current()) setError(e.message);
1142
+ }
1143
+ };
1144
+ try {
1145
+ if (typeof navigator.locks?.request === "function") {
1146
+ await navigator.locks.request(key, { ifAvailable: true }, async (lock) => {
1147
+ if (lock) await send();
1148
+ else {
1149
+ if (current()) setError(t("managed.otherRequest"));
1150
+ await refresh();
1151
+ }
1152
+ });
1153
+ } else await send();
1154
+ } catch (e) {
1155
+ if (current()) setError(e.message);
1156
+ } finally {
1157
+ inFlight.current = false;
1158
+ if (current()) setBusy(false);
1159
+ }
1160
+ };
1161
+ const acknowledge = () => {
1162
+ if (!scopeKey || identityClient.current !== client || !receipt || !creationReady(receipt) && receipt.creation_status !== "failed") return;
1163
+ if (readCreationRequest(scopeKey)?.request_id === receipt.request_id) localStorage.removeItem(scopeKey);
1164
+ setPending(null);
1165
+ propsRef.current.onPendingChange(false);
1166
+ propsRef.current.onComplete(receipt.device_id, creationReady(receipt));
1167
+ };
1168
+ if (!props.visible && !request) return null;
1169
+ return /* @__PURE__ */ jsxs("section", { className: "space-y-3 text-sm", "aria-label": t("creation.title"), children: [
1170
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words text-destructive", children: error }),
1171
+ !loaded && /* @__PURE__ */ jsx("p", { role: "status", children: t("creation.loading") }),
1172
+ !fresh && loaded && /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => void refresh(), children: t("common.refresh") }),
1173
+ request ? /* @__PURE__ */ jsxs("div", { className: "space-y-3 rounded-md border border-border p-3", children: [
1174
+ /* @__PURE__ */ jsx("p", { role: "status", className: "font-medium", children: creationReady(receipt) ? t("creation.ready") : t(`creation.status.${receipt?.creation_status ?? "unknown"}`) }),
1175
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("creation.recovery") }),
1176
+ /* @__PURE__ */ jsxs("p", { className: "break-all", children: [
1177
+ t("creation.request"),
1178
+ ": ",
1179
+ request.request_id
1180
+ ] }),
1181
+ receipt && /* @__PURE__ */ jsxs(Fragment, { children: [
1182
+ /* @__PURE__ */ jsxs("p", { className: "break-all", children: [
1183
+ t("creation.device"),
1184
+ ": ",
1185
+ receipt.device_id
1186
+ ] }),
1187
+ /* @__PURE__ */ jsxs("p", { children: [
1188
+ t("managed.order"),
1189
+ ": ",
1190
+ receipt.proxy_order.id,
1191
+ " \xB7 ",
1192
+ t(`managed.status.${receipt.proxy_order.status}`)
1193
+ ] }),
1194
+ receipt.failure_reason && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words text-destructive", children: receipt.failure_reason }),
1195
+ receipt.creation_status === "failed" && /* @__PURE__ */ jsx("p", { children: t("creation.failedTerms") })
1196
+ ] }),
1197
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
1198
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", disabled: busy, onClick: () => void refresh(), children: t("common.refresh") }),
1199
+ !receipt && /* @__PURE__ */ jsx(Button, { disabled: busy || !fresh, onClick: () => void submit(request), children: t("managed.retry") }),
1200
+ (creationReady(receipt) || receipt?.creation_status === "failed") && /* @__PURE__ */ jsx(Button, { disabled: busy, onClick: acknowledge, children: t("creation.done") })
1201
+ ] })
1202
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1203
+ !props.supported && /* @__PURE__ */ jsx("p", { children: t("creation.unsupported") }),
1204
+ props.quantity !== 1 && /* @__PURE__ */ jsx("p", { role: "status", children: t("creation.singleOnly") }),
1205
+ catalog && !catalog.enabled && /* @__PURE__ */ jsxs("p", { role: "status", children: [
1206
+ t("creation.unavailable"),
1207
+ catalog.unavailable_reason ? ` \xB7 ${catalog.unavailable_reason}` : ""
1208
+ ] }),
1209
+ catalog?.enabled && props.supported && /* @__PURE__ */ jsxs(Fragment, { children: [
1210
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
1211
+ /* @__PURE__ */ jsx("span", { children: t("creation.country") }),
1212
+ /* @__PURE__ */ jsx("select", { className: "min-h-10 w-full rounded border border-border bg-background px-2", disabled, value: selectedRegion, onChange: (e) => {
1213
+ setRegion(e.target.value);
1214
+ setQuote(null);
1215
+ }, children: regions.map((value) => /* @__PURE__ */ jsx("option", { children: value }, value)) })
1216
+ ] }),
1217
+ /* @__PURE__ */ jsx("div", { className: "flex gap-2", role: "group", "aria-label": t("managed.kind"), children: ["static", "dynamic"].map((value) => /* @__PURE__ */ jsx(Button, { variant: kind === value ? "primary" : "secondary", "aria-pressed": kind === value, disabled, onClick: () => {
1218
+ setKind(value);
1219
+ setQuote(null);
1220
+ }, children: t(`managed.${value}`) }, value)) }),
1221
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t(`managed.${kind}Hint`) }),
1222
+ selected ? /* @__PURE__ */ jsxs(Fragment, { children: [
1223
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
1224
+ /* @__PURE__ */ jsx("span", { children: t("managed.product") }),
1225
+ /* @__PURE__ */ jsx("select", { className: "min-h-10 w-full rounded border border-border bg-background px-2", disabled, value: selected.id, onChange: (e) => {
1226
+ setProductId(e.target.value);
1227
+ setQuote(null);
1228
+ }, children: products.map((product) => /* @__PURE__ */ jsxs("option", { value: product.id, children: [
1229
+ product.name,
1230
+ " \xB7 ",
1231
+ t("managed.hours", { n: product.duration_seconds / 3600 }),
1232
+ " \xB7 ",
1233
+ money(product.cost_minor)
1234
+ ] }, product.id)) })
1235
+ ] }),
1236
+ /* @__PURE__ */ jsx("p", { children: t("managed.budget", { amount: money(selected.quota_value) }) }),
1237
+ /* @__PURE__ */ jsx(Button, { disabled, onClick: () => void getQuote(), children: t("managed.quote") })
1238
+ ] }) : /* @__PURE__ */ jsx("p", { children: t("managed.emptyCatalog") })
1239
+ ] }),
1240
+ quote && /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded-md border border-primary/40 p-3", children: [
1241
+ /* @__PURE__ */ jsx("p", { className: "font-semibold", children: t("creation.ipTotal", { amount: money(quote.total_minor) }) }),
1242
+ /* @__PURE__ */ jsxs("p", { children: [
1243
+ quote.product.region,
1244
+ " \xB7 ",
1245
+ t(`managed.${quote.product.kind}`),
1246
+ " \xB7 ",
1247
+ t("managed.hours", { n: quote.product.duration_seconds / 3600 })
1248
+ ] }),
1249
+ /* @__PURE__ */ jsx("p", { children: t("managed.fixedCost", { amount: money(quote.product.fixed_cost_minor) }) }),
1250
+ /* @__PURE__ */ jsx("p", { children: t("managed.budget", { amount: money(quote.product.quota_value) }) }),
1251
+ quote.product.rate_minor_per_gib != null && /* @__PURE__ */ jsx("p", { children: t("managed.rate", { amount: money(quote.product.rate_minor_per_gib) }) }),
1252
+ quote.product.budget_accounting === "reserved_upper_bound" && /* @__PURE__ */ jsx("p", { children: t("managed.reservations", { kib: (quote.product.reservation_bytes ?? 16384) / 1024 }) }),
1253
+ quote.product.handshake_reservation_bytes != null && /* @__PURE__ */ jsx("p", { children: t("managed.handshakeReservation", { kib: quote.product.handshake_reservation_bytes / 1024 }) }),
1254
+ /* @__PURE__ */ jsx("p", { children: t("managed.noRenew") }),
1255
+ /* @__PURE__ */ jsx("p", { children: t("creation.failedTerms") }),
1256
+ /* @__PURE__ */ jsx("p", { className: "font-medium", children: t("creation.startupNetwork") }),
1257
+ /* @__PURE__ */ jsx("p", { children: quote.device_billing.kind === "metered" ? t("creation.metered", { amount: quote.device_billing.rate_per_hour, currency: quote.device_billing.currency }) : t("creation.personalFree") }),
1258
+ /* @__PURE__ */ jsx("p", { children: expired ? t("managed.quoteExpired") : t("managed.quoteExpiry", { at: new Date(quote.expires_at).toLocaleString() }) }),
1259
+ /* @__PURE__ */ jsx(Button, { disabled: disabled || expired, onClick: () => {
1260
+ if (Date.parse(quote.expires_at) > Date.now()) void submit({ request_id: crypto.randomUUID(), quote_id: quote.id, authorized_total_minor: quote.total_minor, currency: "CNY" });
1261
+ }, children: t("creation.authorize", { amount: money(quote.total_minor) }) })
1262
+ ] })
872
1263
  ] })
873
1264
  ] });
874
1265
  }
1266
+
1267
+ // src/ui/device-create/create-proxy-capabilities.ts
1268
+ function createProxyCapabilities(kind, spec, node) {
1269
+ const cap = node?.reported_caps?.egress_proxy;
1270
+ const android = kind === "virtual" && (spec.platform === void 0 || spec.platform === "android") && node?.status === "online" && node.reported_caps?.redroid_capable === true && node.owner_policy?.android !== false && node.effective_caps?.android !== false;
1271
+ const custom = android && cap?.supported === true;
1272
+ return { custom, managed: custom && cap?.revision_fencing === true && node?.reported_caps?.device_provision_v2 === true };
1273
+ }
875
1274
  var emptySpec = { platform: "android" };
876
1275
  function DeviceCreate({ open, onClose, onCreated }) {
877
1276
  const client = useClient();
1277
+ const t = useAixT();
878
1278
  const { refetch: fetchDevices } = useDevices();
879
1279
  const { data: nodes } = useNodes();
880
1280
  const [step, setStep] = useState(0);
@@ -885,6 +1285,9 @@ function DeviceCreate({ open, onClose, onCreated }) {
885
1285
  const [busy, setBusy] = useState(false);
886
1286
  const [error, setError] = useState("");
887
1287
  const [quantity, setQuantity] = useState(1);
1288
+ const [networkMode, setNetworkMode] = useState("none");
1289
+ const [managedPending, setManagedPending] = useState(false);
1290
+ const proxyCapabilities = createProxyCapabilities(kind, spec, nodes?.find((node) => node.id === nodeId));
888
1291
  useEffect(() => {
889
1292
  if (!open) return;
890
1293
  setStep(0);
@@ -895,8 +1298,10 @@ function DeviceCreate({ open, onClose, onCreated }) {
895
1298
  setBusy(false);
896
1299
  setError("");
897
1300
  setQuantity(1);
1301
+ setNetworkMode("none");
1302
+ setManagedPending(false);
898
1303
  }, [open]);
899
- const proxyOk = isSupportedProxyUrl(spec.proxy?.trim() ?? "");
1304
+ const proxyOk = networkMode !== "custom" || proxyCapabilities.custom && isSupportedProxyUrl(spec.proxy?.trim() ?? "");
900
1305
  const canNext = (() => {
901
1306
  if (step === 0) return true;
902
1307
  if (step === 1) return !!nodeId;
@@ -919,6 +1324,13 @@ function DeviceCreate({ open, onClose, onCreated }) {
919
1324
  setError("\u8BF7\u9009\u62E9\u8BE5\u8282\u70B9\u5DF2\u5B89\u88C5\u7684\u7CFB\u7EDF\u7248\u672C\u540E\u518D\u521B\u5EFA\u3002");
920
1325
  return;
921
1326
  }
1327
+ if (managedPending || networkMode === "managed") return;
1328
+ if (networkMode === "custom" && !proxyCapabilities.custom) {
1329
+ setError(t("creation.unsupported"));
1330
+ return;
1331
+ }
1332
+ const provisionSpec = { ...spec, node_id: nodeId };
1333
+ if (networkMode !== "custom") delete provisionSpec.proxy;
922
1334
  setBusy(true);
923
1335
  setError("");
924
1336
  try {
@@ -927,7 +1339,7 @@ function DeviceCreate({ open, onClose, onCreated }) {
927
1339
  const settled = await Promise.allSettled(
928
1340
  Array.from(
929
1341
  { length: quantity },
930
- () => client.devices.provision({ ...spec, node_id: nodeId })
1342
+ () => client.devices.provision(provisionSpec)
931
1343
  )
932
1344
  );
933
1345
  const fulfilled = settled.filter(
@@ -947,7 +1359,7 @@ function DeviceCreate({ open, onClose, onCreated }) {
947
1359
  return;
948
1360
  }
949
1361
  if (kind === "virtual") {
950
- result = await client.devices.provision({ ...spec, node_id: nodeId });
1362
+ result = await client.devices.provision(provisionSpec);
951
1363
  } else if (picked) {
952
1364
  await enrollDiscovered(picked);
953
1365
  }
@@ -995,15 +1407,40 @@ function DeviceCreate({ open, onClose, onCreated }) {
995
1407
  ] }),
996
1408
  step === 1 && /* @__PURE__ */ jsx(NodePicker, { value: nodeId, onChange: setNodeId, hidePlatform: kind === "real" }),
997
1409
  step === 2 && (kind === "virtual" ? /* @__PURE__ */ jsx(VirtualSpecStep, { spec, onChange: setSpec, nodeId }) : /* @__PURE__ */ jsx(RealDiscoverStep, { nodeId, picked, onPick: setPicked })),
998
- step === 3 && /* @__PURE__ */ jsx(
999
- ProxySpoofStep,
1410
+ step === 3 && !managedPending && /* @__PURE__ */ jsxs(Fragment, { children: [
1411
+ /* @__PURE__ */ jsxs("fieldset", { className: "space-y-2", children: [
1412
+ /* @__PURE__ */ jsx("legend", { className: "text-sm font-medium", children: t("creation.network") }),
1413
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
1414
+ proxyCapabilities.managed && /* @__PURE__ */ jsx(Button, { variant: networkMode === "managed" ? "primary" : "secondary", "aria-pressed": networkMode === "managed", disabled: busy, onClick: () => setNetworkMode("managed"), children: t("creation.managed") }),
1415
+ proxyCapabilities.custom && /* @__PURE__ */ jsx(Button, { variant: networkMode === "custom" ? "primary" : "secondary", "aria-pressed": networkMode === "custom", disabled: busy, onClick: () => setNetworkMode("custom"), children: t("creation.custom") }),
1416
+ /* @__PURE__ */ jsx(Button, { variant: networkMode === "none" ? "primary" : "secondary", "aria-pressed": networkMode === "none", disabled: busy, onClick: () => setNetworkMode("none"), children: t("creation.none") })
1417
+ ] }),
1418
+ !proxyCapabilities.custom && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("creation.unsupported") })
1419
+ ] }),
1420
+ /* @__PURE__ */ jsx(ProxySpoofStep, { spec, onChange: setSpec, isReal: kind === "real", showProxy: networkMode === "custom" && proxyCapabilities.custom })
1421
+ ] }),
1422
+ open && /* @__PURE__ */ jsx(
1423
+ ManagedCreationPanel,
1000
1424
  {
1001
- spec,
1002
- onChange: setSpec,
1003
- isReal: kind === "real"
1425
+ visible: step === 3 && networkMode === "managed",
1426
+ supported: proxyCapabilities.managed,
1427
+ quantity,
1428
+ spec: { ...spec, proxy: void 0, node_id: nodeId },
1429
+ onPendingChange: (pending) => {
1430
+ setManagedPending(pending);
1431
+ if (pending) {
1432
+ setNetworkMode("managed");
1433
+ setStep(3);
1434
+ }
1435
+ },
1436
+ onComplete: (_deviceId, ready) => {
1437
+ void fetchDevices();
1438
+ if (ready) onCreated?.(null);
1439
+ onClose();
1440
+ }
1004
1441
  }
1005
1442
  ),
1006
- step === 3 && kind === "virtual" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1443
+ step === 3 && kind === "virtual" && !managedPending && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1007
1444
  /* @__PURE__ */ jsx("label", { className: "text-[11px] text-muted-foreground", children: "\u521B\u5EFA\u6570\u91CF" }),
1008
1445
  /* @__PURE__ */ jsx(
1009
1446
  "input",
@@ -1019,12 +1456,12 @@ function DeviceCreate({ open, onClose, onCreated }) {
1019
1456
  /* @__PURE__ */ jsx("span", { className: "text-[10px] text-muted-foreground/60", children: "\u4E00\u6B21\u5E76\u53D1\u521B\u5EFA\u591A\u53F0\u76F8\u540C\u89C4\u683C\u7684\u8BBE\u5907\uFF081\u201320\uFF09" })
1020
1457
  ] }),
1021
1458
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-t border-border pt-3", children: [
1022
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: step === 0 || busy, onClick: back, children: "\u4E0A\u4E00\u6B65" }),
1023
- step < 3 ? /* @__PURE__ */ jsx(Button, { size: "sm", disabled: !canNext, onClick: next, children: "\u4E0B\u4E00\u6B65" }) : /* @__PURE__ */ jsx(
1459
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: step === 0 || busy || managedPending, onClick: back, children: "\u4E0A\u4E00\u6B65" }),
1460
+ step < 3 ? /* @__PURE__ */ jsx(Button, { size: "sm", disabled: !canNext || managedPending, onClick: next, children: "\u4E0B\u4E00\u6B65" }) : networkMode === "managed" || managedPending ? null : /* @__PURE__ */ jsx(
1024
1461
  Button,
1025
1462
  {
1026
1463
  size: "sm",
1027
- disabled: busy || !proxyOk || kind === "virtual" && !spec.image_id || kind === "virtual" && (quantity < 1 || quantity > 20),
1464
+ disabled: busy || !proxyOk || kind === "virtual" && !spec.image_id || kind === "virtual" && (!Number.isInteger(quantity) || quantity < 1 || quantity > 20),
1028
1465
  onClick: finish,
1029
1466
  children: busy ? "\u521B\u5EFA\u4E2D\u2026" : quantity > 1 ? `\u521B\u5EFA ${quantity} \u53F0` : "\u521B\u5EFA"
1030
1467
  }
@@ -1082,4 +1519,4 @@ function TypeCard({
1082
1519
  );
1083
1520
  }
1084
1521
 
1085
- export { AddWirelessDeviceDialog, DeviceCreate, NodePicker, ProxySpoofStep, RealDiscoverStep, VirtualSpecStep, createProxyProbeGuard, isProxyApplyStatus, isProxyProbeUnsupported, isRedactedProxyUrl, isSupportedProxyUrl, proxyCapabilityReason, proxyProbeExitIp, proxyProbeMessage, proxySummaryFromDevice, redactProxyUrl };
1522
+ export { AddWirelessDeviceDialog, DeviceCreate, NodePicker, ProxySpoofStep, RealDiscoverStep, VirtualSpecStep, createProxyProbeGuard, deviceProxyCapabilities, isProxyApplyStatus, isProxyProbeUnsupported, isRedactedProxyUrl, isSupportedProxyUrl, proxyCapabilityReason, proxyProbeExitIp, proxyProbeMessage, proxySummaryFromDevice, redactProxyUrl };