@aixnn/aixautots 0.6.10 → 0.6.13

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-CvrWEOw2.d.ts → automation-queue-BFWqw32O.d.ts} +2 -2
  2. package/dist/{chunk-PUEKOYSH.js → chunk-2KPZSPV6.js} +131 -3
  3. package/dist/{chunk-UH5OYPXE.js → chunk-7BJPVSEZ.js} +205 -18
  4. package/dist/{chunk-LR5LJJNM.js → chunk-HMDUSVQ3.js} +4 -4
  5. package/dist/{chunk-E7WMHM63.js → chunk-MBBVYSPD.js} +7 -0
  6. package/dist/{chunk-5KZB6M2S.js → chunk-Q5I63UYT.js} +127 -419
  7. package/dist/{chunk-7IXBWJHB.js → chunk-QEK25NUA.js} +5 -5
  8. package/dist/chunk-QFGMQLRB.js +405 -0
  9. package/dist/{chunk-LO3XD4T5.js → chunk-QRIWTPN3.js} +114 -4
  10. package/dist/{chunk-D7J4EQTA.js → chunk-S5N4EOCP.js} +1 -1
  11. package/dist/{chunk-NEQFR75E.js → chunk-SKI7TINK.js} +349 -420
  12. package/dist/{chunk-SL6M6CC6.js → chunk-T6X6TWHK.js} +3 -3
  13. package/dist/{chunk-XCYGBYFC.js → chunk-U4QW45MB.js} +208 -126
  14. package/dist/{chunk-SKTL6ACT.js → chunk-VMA3QOYR.js} +3 -3
  15. package/dist/chunk-ZCTAYVPK.js +1 -0
  16. package/dist/{config-BUH2EYHO.d.ts → config-UmU2_q5M.d.ts} +173 -2
  17. package/dist/core/index.d.ts +29 -11
  18. package/dist/core/index.js +2 -2
  19. package/dist/{device-normalize-DzuVemCy.d.ts → device-normalize-CWJFr_sf.d.ts} +7 -4
  20. package/dist/device-session-3XK2SZDF.js +1 -0
  21. package/dist/i18n/index.js +1 -1
  22. package/dist/{mirror-session-D2YY9mKf.d.ts → mirror-session-Cy20lIHP.d.ts} +14 -4
  23. package/dist/react/index.d.ts +9 -9
  24. package/dist/react/index.js +3 -3
  25. package/dist/{script-debugger-Csm4CrfY.d.ts → script-debugger-F5UGUq5t.d.ts} +1 -1
  26. package/dist/{task-agent-runner-C4WfT77g.d.ts → task-agent-runner-Cj_u-3DS.d.ts} +3 -3
  27. package/dist/{types-BfIeUpsU.d.ts → types-BvrppNIZ.d.ts} +34 -2
  28. package/dist/ui/billing.d.ts +2 -2
  29. package/dist/ui/billing.js +14 -8
  30. package/dist/ui/device-create.d.ts +7 -5
  31. package/dist/ui/device-create.js +8 -7
  32. package/dist/ui/device-mirror.js +7 -7
  33. package/dist/ui/devices.d.ts +5 -5
  34. package/dist/ui/devices.js +12 -11
  35. package/dist/ui/editor.d.ts +2 -2
  36. package/dist/ui/editor.js +7 -7
  37. package/dist/ui/index.d.ts +5 -4
  38. package/dist/ui/index.js +9 -7
  39. package/dist/ui/inspector.js +5 -5
  40. package/dist/ui/ip-commerce.d.ts +26 -0
  41. package/dist/ui/ip-commerce.js +8 -0
  42. package/dist/ui/market.js +4 -4
  43. package/dist/ui/mirror.d.ts +5 -4
  44. package/dist/ui/mirror.js +1 -1
  45. package/dist/ui/primitives/index.js +1 -1
  46. package/dist/ui/script-studio.js +6 -6
  47. package/dist/ui/scripts.d.ts +1 -1
  48. package/dist/ui/scripts.js +5 -5
  49. package/dist/ui/tasks.js +12 -11
  50. package/package.json +6 -2
  51. package/dist/device-session-7MKEJTIA.js +0 -1
@@ -1,12 +1,28 @@
1
- import { IosDeviceDiagnostics } from './chunk-SL6M6CC6.js';
1
+ import { IosDeviceDiagnostics } from './chunk-T6X6TWHK.js';
2
+ import { IpCommercePanel } from './chunk-QFGMQLRB.js';
2
3
  import { canConnectPhysicalDevice } from './chunk-ZB5ET67B.js';
3
- import { useAixT } from './chunk-LO3XD4T5.js';
4
- import { cn, Select, Dialog, Button, Input, Badge } from './chunk-SKTL6ACT.js';
5
- import { useNodes, useClient, useDevices } from './chunk-7IXBWJHB.js';
6
- import { useMemo, useEffect, useState, useCallback, useRef } from 'react';
4
+ import { useAixT } from './chunk-QRIWTPN3.js';
5
+ import { cn, Select, Dialog, Button, Input, Badge } from './chunk-VMA3QOYR.js';
6
+ import { useNodes, useClient, useDevices } from './chunk-QEK25NUA.js';
7
+ import { useState, useEffect, useMemo, useCallback, useRef } from 'react';
7
8
  import { Server, RefreshCw, Smartphone, Usb, Wifi, Info } from 'lucide-react';
8
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
9
10
 
11
+ // src/ui/device-create/virtual-catalog.ts
12
+ function supportsVirtualPlatform(node, platform) {
13
+ if (!node || node.status !== "online" || node.effective_caps?.[platform] === false || node.owner_policy?.[platform] === false) return false;
14
+ const provider = platform === "android" ? "redroid_capable" : "vphone_capable";
15
+ return node.reported_caps?.[provider] === true;
16
+ }
17
+ function availableVirtualImages(node, catalog, platform) {
18
+ if (!supportsVirtualPlatform(node, platform)) return [];
19
+ const installed = node?.reported_caps?.installed_images;
20
+ if (!Array.isArray(installed)) return [];
21
+ return catalog.filter((image) => image.platform === platform && typeof image.image_tag === "string" && installed.includes(image.image_tag));
22
+ }
23
+ function availableVirtualPlatforms(node, catalog) {
24
+ return ["android", "ios"].filter((platform) => availableVirtualImages(node, catalog, platform).length > 0);
25
+ }
10
26
  var SCOPE_META = {
11
27
  platform: { label: "\u5E73\u53F0", order: 0 },
12
28
  project: { label: "\u9879\u76EE", order: 1 },
@@ -16,28 +32,50 @@ var CURRENCY_SYMBOL = { CNY: "\xA5", USD: "$" };
16
32
  function nodeMetric(n) {
17
33
  if (n.is_platform) {
18
34
  if (n.starting_price == null) return "\u5E73\u53F0\u8282\u70B9";
19
- const sym = CURRENCY_SYMBOL[n.price_currency ?? "CNY"] ?? "";
35
+ const sym = CURRENCY_SYMBOL[n.price_currency ?? "USD"] ?? "";
20
36
  return `${sym}${Number(n.starting_price)}/\u5C0F\u65F6 \u8D77`;
21
37
  }
22
38
  return `${n.device_count} devices`;
23
39
  }
24
- function NodePicker({ value, onChange, hidePlatform = false }) {
40
+ function NodePicker({ value, onChange, hidePlatform = false, virtualOnly = false }) {
25
41
  const { data, loading, error, refetch } = useNodes();
42
+ const client = useClient();
43
+ const [catalog, setCatalog] = useState(null);
44
+ const [catalogError, setCatalogError] = useState(false);
45
+ const catalogLoading = virtualOnly && catalog === null && !catalogError;
46
+ useEffect(() => {
47
+ if (!virtualOnly) return;
48
+ let alive = true;
49
+ setCatalog(null);
50
+ setCatalogError(false);
51
+ client.images.options().then((images) => {
52
+ if (!Array.isArray(images)) throw new Error("Invalid image catalog");
53
+ if (alive) setCatalog(images);
54
+ }).catch(() => {
55
+ if (alive) {
56
+ setCatalog([]);
57
+ setCatalogError(true);
58
+ }
59
+ });
60
+ return () => {
61
+ alive = false;
62
+ };
63
+ }, [client, virtualOnly]);
26
64
  const nodes = useMemo(() => data ?? [], [data]);
27
65
  useEffect(() => {
28
66
  void refetch();
29
67
  }, [refetch]);
30
68
  const onlineNodes = useMemo(
31
69
  () => nodes.filter(
32
- (n) => n.status === "online" && !(hidePlatform && (n.is_platform || n.scope === "platform"))
70
+ (n) => n.status === "online" && !(hidePlatform && (n.is_platform || n.scope === "platform")) && (!virtualOnly || catalog !== null && availableVirtualPlatforms(n, catalog).length > 0)
33
71
  ),
34
- [nodes, hidePlatform]
72
+ [nodes, hidePlatform, virtualOnly, catalog]
35
73
  );
36
74
  useEffect(() => {
37
- if (value && onlineNodes.length > 0 && !onlineNodes.some((n) => n.id === value)) {
75
+ if (!loading && !catalogLoading && value && (error || !onlineNodes.some((n) => n.id === value))) {
38
76
  onChange("");
39
77
  }
40
- }, [value, onlineNodes, onChange]);
78
+ }, [value, onlineNodes, onChange, loading, error, catalogLoading]);
41
79
  const groups = useMemo(() => {
42
80
  const by = {
43
81
  platform: [],
@@ -47,14 +85,17 @@ function NodePicker({ value, onChange, hidePlatform = false }) {
47
85
  for (const n of onlineNodes) (by[n.scope] ?? by.personal).push(n);
48
86
  return Object.keys(by).filter((s) => by[s].length > 0).sort((a, b) => SCOPE_META[a].order - SCOPE_META[b].order).map((scope) => ({ scope, rows: by[scope] }));
49
87
  }, [onlineNodes]);
50
- if (loading && nodes.length === 0) {
88
+ if (loading && nodes.length === 0 || catalogLoading) {
51
89
  return /* @__PURE__ */ jsx("p", { className: "py-6 text-center text-body-sm text-muted-foreground", children: "\u52A0\u8F7D\u8282\u70B9\u4E2D\u2026" });
52
90
  }
53
91
  if (error) {
54
92
  return /* @__PURE__ */ jsx("p", { className: "py-2 text-[11px] text-destructive", children: error.message });
55
93
  }
94
+ if (catalogError && virtualOnly) {
95
+ return /* @__PURE__ */ jsx("p", { className: "py-2 text-[11px] text-destructive", children: "\u53EF\u7528\u7CFB\u7EDF\u7248\u672C\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" });
96
+ }
56
97
  if (onlineNodes.length === 0) {
57
- return /* @__PURE__ */ jsx("p", { className: "py-6 text-center text-body-sm text-muted-foreground", children: "\u6682\u65E0\u5728\u7EBF\u8282\u70B9\u3002\u8BF7\u5148\u542F\u52A8\u4E00\u4E2A\u8282\u70B9\uFF08\u672C\u673A\u8282\u70B9\u6216\u6CE8\u518C\u65B0\u8282\u70B9\uFF09\u540E\u518D\u521B\u5EFA\u8BBE\u5907\u3002" });
98
+ return /* @__PURE__ */ jsx("p", { className: "py-6 text-center text-body-sm text-muted-foreground", children: virtualOnly ? "\u6682\u65E0\u5DF2\u5B89\u88C5\u53EF\u7528\u865A\u62DF\u8BBE\u5907\u955C\u50CF\u7684\u5728\u7EBF\u8282\u70B9\u3002\u8BF7\u68C0\u67E5\u8282\u70B9\u5728\u7EBF\u72B6\u6001\u53CA\u955C\u50CF\u51C6\u5907\u60C5\u51B5\u3002" : "\u6682\u65E0\u5728\u7EBF\u8282\u70B9\u3002\u8BF7\u5148\u542F\u52A8\u4E00\u4E2A\u8282\u70B9\uFF08\u672C\u673A\u8282\u70B9\u6216\u6CE8\u518C\u65B0\u8282\u70B9\uFF09\u540E\u518D\u521B\u5EFA\u8BBE\u5907\u3002" });
58
99
  }
59
100
  return /* @__PURE__ */ jsx("div", { className: "space-y-3", children: groups.map(({ scope, rows }) => /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
60
101
  /* @__PURE__ */ jsx("p", { className: "text-label-caps text-muted-foreground", children: SCOPE_META[scope].label }),
@@ -137,14 +178,16 @@ var GPU_OPTIONS = [
137
178
  { value: "host", label: "\u786C\u4EF6 GPU host(\u8282\u70B9\u9700 /dev/dri)" },
138
179
  { value: "guest", label: "\u8F6F\u4EF6\u6E32\u67D3 guest(\u65E0\u9700 GPU)" }
139
180
  ];
140
- function VirtualSpecStep({ spec, onChange, nodeId }) {
181
+ function VirtualSpecStep({ spec, onChange, nodeId, onValidityChange }) {
141
182
  const client = useClient();
142
183
  const platform = spec.platform ?? "android";
143
184
  const memory = spec.hardware?.memory_mb ?? 2048;
144
185
  const [versions, setVersions] = useState([]);
145
- const [loading, setLoading] = useState(false);
146
- const [installed, setInstalled] = useState([]);
147
- const [installedLoading, setInstalledLoading] = useState(false);
186
+ const [loading, setLoading] = useState(true);
187
+ const [catalogError, setCatalogError] = useState(false);
188
+ const [nodeState, setNodeState] = useState(null);
189
+ const [installedLoading, setInstalledLoading] = useState(true);
190
+ const selectedNode = nodeState && nodeState.id === nodeId ? nodeState.node : void 0;
148
191
  const [catalog, setCatalog] = useState([]);
149
192
  const [brand, setBrand] = useState("");
150
193
  const patch = (p) => onChange({ ...spec, ...p });
@@ -173,31 +216,38 @@ function VirtualSpecStep({ spec, onChange, nodeId }) {
173
216
  useEffect(() => {
174
217
  let alive = true;
175
218
  setLoading(true);
176
- client.images.options(platform).then((opts) => {
177
- if (alive) setVersions(opts);
219
+ setCatalogError(false);
220
+ client.images.options().then((opts) => {
221
+ if (alive) {
222
+ setVersions(Array.isArray(opts) ? opts : []);
223
+ if (!Array.isArray(opts)) setCatalogError(true);
224
+ }
178
225
  }).catch(() => {
179
- if (alive) setVersions([]);
226
+ if (alive) {
227
+ setVersions([]);
228
+ setCatalogError(true);
229
+ }
180
230
  }).finally(() => {
181
231
  if (alive) setLoading(false);
182
232
  });
183
233
  return () => {
184
234
  alive = false;
185
235
  };
186
- }, [platform, client]);
236
+ }, [client]);
187
237
  useEffect(() => {
188
238
  if (!nodeId) {
189
- setInstalled([]);
239
+ setNodeState(null);
240
+ setInstalledLoading(false);
190
241
  return;
191
242
  }
192
243
  let alive = true;
193
244
  setInstalledLoading(true);
245
+ setNodeState(null);
194
246
  client.nodes.list().then((nodes) => {
195
247
  if (!alive) return;
196
- const n = nodes.find((x) => x.id === nodeId);
197
- const v = n?.reported_caps?.installed_images;
198
- setInstalled(Array.isArray(v) ? v.filter((s) => typeof s === "string") : []);
248
+ setNodeState({ id: nodeId, node: nodes.find((x) => x.id === nodeId) });
199
249
  }).catch(() => {
200
- if (alive) setInstalled([]);
250
+ if (alive) setNodeState({ id: nodeId, error: true });
201
251
  }).finally(() => {
202
252
  if (alive) setInstalledLoading(false);
203
253
  });
@@ -216,11 +266,21 @@ function VirtualSpecStep({ spec, onChange, nodeId }) {
216
266
  alive = false;
217
267
  };
218
268
  }, [client]);
219
- const availableVersions = nodeId ? versions.filter((o) => installed.includes(o.image_tag)) : versions;
269
+ const availableVersions = availableVirtualImages(selectedNode, versions, platform);
270
+ const allowedPlatforms = availableVirtualPlatforms(selectedNode, versions);
271
+ const platformOptions = PLATFORM_OPTIONS.filter((option) => allowedPlatforms.includes(option.value));
220
272
  const versionOptions = availableVersions.map((o) => ({ value: o.id, label: o.label }));
221
- const versionsLoading = loading || installedLoading;
222
- const noPlatformImages = versions.length === 0;
273
+ const versionsLoading = loading || installedLoading || !!nodeId && nodeState?.id !== nodeId;
274
+ const noPlatformImages = !versions.some((image) => image.platform === platform);
223
275
  const selectedImage = spec.image_id ?? "";
276
+ useEffect(() => {
277
+ onValidityChange?.(!versionsLoading && availableVersions.some((image) => image.id === selectedImage));
278
+ }, [versionsLoading, selectedImage, nodeId, selectedNode, versions, platform, onValidityChange]);
279
+ useEffect(() => {
280
+ if (!versionsLoading && allowedPlatforms.length > 0 && !allowedPlatforms.includes(platform)) {
281
+ setPlatform(allowedPlatforms[0]);
282
+ }
283
+ }, [versionsLoading, selectedNode, versions, platform]);
224
284
  useEffect(() => {
225
285
  if (versionsLoading) return;
226
286
  if (!selectedImage && availableVersions.length === 1) {
@@ -262,15 +322,16 @@ function VirtualSpecStep({ spec, onChange, nodeId }) {
262
322
  /* @__PURE__ */ jsx(
263
323
  Select,
264
324
  {
265
- value: platform,
325
+ value: platformOptions.some((option) => option.value === platform) ? platform : "",
326
+ disabled: versionsLoading || platformOptions.length === 0,
266
327
  onChange: (v) => setPlatform(v),
267
- options: PLATFORM_OPTIONS
328
+ options: platformOptions
268
329
  }
269
330
  )
270
331
  ] }),
271
332
  /* @__PURE__ */ jsxs("div", { children: [
272
333
  /* @__PURE__ */ jsx("label", { className: "text-[11px] text-muted-foreground", children: "\u7CFB\u7EDF\u7248\u672C version" }),
273
- versionsLoading ? /* @__PURE__ */ jsx("div", { className: "text-body-sm text-muted-foreground py-2", children: "\u6B63\u5728\u52A0\u8F7D\u53EF\u7528\u7248\u672C\u2026" }) : versionOptions.length === 0 ? /* @__PURE__ */ jsx("div", { className: "text-body-sm text-muted-foreground py-2", children: noPlatformImages ? "\u8BE5\u5E73\u53F0\u6682\u65E0\u53EF\u7528\u7248\u672C\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u914D\u7F6E\u955C\u50CF\u3002" : "\u8BE5\u8282\u70B9\u672A\u5B89\u88C5\u6B64\u5E73\u53F0\u7684\u955C\u50CF\uFF0C\u8BF7\u6362\u4E00\u4E2A\u8282\u70B9\uFF0C\u6216\u5728\u8282\u70B9\u4E0A\u5B89\u88C5\u955C\u50CF\u540E\u91CD\u8BD5\u3002" }) : /* @__PURE__ */ jsx(
334
+ versionsLoading ? /* @__PURE__ */ jsx("div", { className: "text-body-sm text-muted-foreground py-2", children: "\u6B63\u5728\u52A0\u8F7D\u53EF\u7528\u7248\u672C\u2026" }) : versionOptions.length === 0 ? /* @__PURE__ */ jsx("div", { className: "text-body-sm text-muted-foreground py-2", children: catalogError ? "\u7CFB\u7EDF\u7248\u672C\u5217\u8868\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" : nodeState?.error ? "\u8282\u70B9\u4FE1\u606F\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" : !selectedNode ? "\u8BE5\u8282\u70B9\u5F53\u524D\u4E0D\u53EF\u7528\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u8282\u70B9\u3002" : selectedNode.status !== "online" ? "\u8BE5\u8282\u70B9\u5DF2\u79BB\u7EBF\uFF0C\u8BF7\u9009\u62E9\u5728\u7EBF\u8282\u70B9\u3002" : !supportsVirtualPlatform(selectedNode, platform) ? "\u8BE5\u8282\u70B9\u4E0D\u652F\u6301\u6B64\u7C7B\u865A\u62DF\u8BBE\u5907\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u8282\u70B9\u3002" : noPlatformImages ? "\u8BE5\u5E73\u53F0\u6682\u65E0\u53EF\u7528\u7248\u672C\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u914D\u7F6E\u955C\u50CF\u3002" : "\u8BE5\u8282\u70B9\u6682\u65E0\u5339\u914D\u7684\u5DF2\u5B89\u88C5\u865A\u62DF\u8BBE\u5907\u955C\u50CF\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u8282\u70B9\u3002" }) : /* @__PURE__ */ jsx(
274
335
  Select,
275
336
  {
276
337
  value: selectedImage,
@@ -904,367 +965,6 @@ function ProxySpoofStep({ spec, onChange, isReal, showProxy = !isReal }) {
904
965
  ] });
905
966
  }
906
967
 
907
- // src/ui/device-create/managed-creation-state.ts
908
- var creationStorageKey = (baseUrl, owner, project) => `aix-managed-creation:v1:${JSON.stringify([baseUrl, owner, project])}`;
909
- function readCreationRequest(key) {
910
- if (!key) return null;
911
- try {
912
- const value = JSON.parse(localStorage.getItem(key) ?? "null");
913
- 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;
914
- } catch {
915
- return null;
916
- }
917
- }
918
- function validCreationQuote(quote) {
919
- 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));
920
- }
921
- function creationReady(receipt) {
922
- return receipt?.creation_status === "ready" && receipt.proxy_order.status === "fulfilled" && receipt.proxy_order.apply_status === "applied";
923
- }
924
- function creationRejected(error) {
925
- return error?.requestState === "rejected";
926
- }
927
- var money = (minor) => `\xA5${(minor / 100).toFixed(2)}`;
928
- function ManagedCreationPanel(props) {
929
- const client = useClient();
930
- const t = useAixT();
931
- const translate = useRef(t);
932
- translate.current = t;
933
- const epoch = useRef(0);
934
- const [catalog, setCatalog] = useState(null);
935
- const [identity, setIdentity] = useState(null);
936
- const [request, setRequest] = useState(null);
937
- const [receipt, setReceipt] = useState(null);
938
- const [quote, setQuote] = useState(null);
939
- const [productId, setProductId] = useState("");
940
- const [region, setRegion] = useState("");
941
- const [kind, setKind] = useState("static");
942
- const [error, setError] = useState("");
943
- const [busy, setBusy] = useState(false);
944
- const [loaded, setLoaded] = useState(false);
945
- const [fresh, setFresh] = useState(false);
946
- const [now, setNow] = useState(Date.now());
947
- const active = useRef(true);
948
- const inFlight = useRef(false);
949
- const pollInFlight = useRef(null);
950
- const requestRef = useRef(request);
951
- const storageRef = useRef(null);
952
- const identityClient = useRef(null);
953
- const controllers = useRef(/* @__PURE__ */ new Set());
954
- const propsRef = useRef(props);
955
- propsRef.current = props;
956
- const setPending = (value) => {
957
- requestRef.current = value;
958
- setRequest(value);
959
- };
960
- const scopeKey = identity ? creationStorageKey(client.cfg.baseUrl, identity.owner_user_id, identity.project_id) : null;
961
- storageRef.current = scopeKey;
962
- const run = useCallback(async (operation) => {
963
- const controller = new AbortController();
964
- controllers.current.add(controller);
965
- const timer = setTimeout(() => controller.abort(), 3e4);
966
- try {
967
- return await operation(controller.signal);
968
- } finally {
969
- clearTimeout(timer);
970
- controllers.current.delete(controller);
971
- }
972
- }, []);
973
- const refresh = useCallback(async () => {
974
- const generation = epoch.current;
975
- if (pollInFlight.current === generation) return;
976
- pollInFlight.current = generation;
977
- try {
978
- const context = await run((signal) => client.proxies.creations({ signal }));
979
- if (!active.current || generation !== epoch.current) return;
980
- if (!context || typeof context.owner_user_id !== "string" || typeof context.project_id !== "string" || !Array.isArray(context.items)) throw new Error(translate.current("creation.invalidService"));
981
- const key = creationStorageKey(client.cfg.baseUrl, context.owner_user_id, context.project_id);
982
- if (storageRef.current && storageRef.current !== key) {
983
- controllers.current.forEach((controller) => controller.abort());
984
- setQuote(null);
985
- setReceipt(null);
986
- setError("");
987
- setBusy(false);
988
- }
989
- storageRef.current = key;
990
- identityClient.current = client;
991
- setIdentity(context);
992
- setFresh(true);
993
- let pending = readCreationRequest(key);
994
- let found = pending ? context.items.find((item) => item.request_id === pending.request_id) : context.items[0];
995
- if (pending && !found) {
996
- try {
997
- found = await run((signal) => client.proxies.creationByRequest(pending.request_id, { signal }));
998
- } catch {
999
- }
1000
- }
1001
- if (!active.current || generation !== epoch.current) return;
1002
- if (found && (!pending || pending.request_id === found.request_id)) {
1003
- if (!pending) {
1004
- pending = { request_id: found.request_id, quote_id: found.quote_id, authorized_total_minor: found.proxy_order.total_minor, currency: "CNY", uncertain: true };
1005
- localStorage.setItem(key, JSON.stringify(pending));
1006
- }
1007
- setReceipt(found);
1008
- } else setReceipt((previous) => previous?.request_id === pending?.request_id ? previous : null);
1009
- setPending(pending);
1010
- propsRef.current.onPendingChange(!!pending);
1011
- } catch (e) {
1012
- if (active.current && generation === epoch.current) {
1013
- setFresh(false);
1014
- setError(e.message);
1015
- }
1016
- } finally {
1017
- if (pollInFlight.current === generation) pollInFlight.current = null;
1018
- if (active.current && generation === epoch.current) setLoaded(true);
1019
- }
1020
- }, [client, run]);
1021
- useEffect(() => {
1022
- active.current = true;
1023
- const generation = ++epoch.current;
1024
- storageRef.current = null;
1025
- identityClient.current = null;
1026
- setIdentity(null);
1027
- setFresh(false);
1028
- setQuote(null);
1029
- setReceipt(null);
1030
- setPending(null);
1031
- setLoaded(false);
1032
- setBusy(false);
1033
- propsRef.current.onPendingChange(false);
1034
- let timer;
1035
- const poll = async () => {
1036
- if (!document.hidden) await refresh();
1037
- if (active.current && generation === epoch.current) timer = setTimeout(() => void poll(), requestRef.current ? 3e3 : 3e4);
1038
- };
1039
- void run((signal) => client.proxies.catalog({ signal })).then((value) => {
1040
- if (!value || typeof value.enabled !== "boolean" || !Array.isArray(value.products)) throw new Error(translate.current("creation.invalidService"));
1041
- if (active.current && generation === epoch.current) setCatalog(value);
1042
- }).catch((e) => {
1043
- if (active.current && generation === epoch.current) setError(e.message);
1044
- });
1045
- void poll();
1046
- const clock = setInterval(() => setNow(Date.now()), 1e3);
1047
- const visible = () => {
1048
- if (!document.hidden) void refresh();
1049
- };
1050
- const storage = (event) => {
1051
- if (event.key === storageRef.current) void refresh();
1052
- };
1053
- document.addEventListener("visibilitychange", visible);
1054
- window.addEventListener("storage", storage);
1055
- return () => {
1056
- active.current = false;
1057
- epoch.current++;
1058
- clearTimeout(timer);
1059
- clearInterval(clock);
1060
- controllers.current.forEach((c) => c.abort());
1061
- document.removeEventListener("visibilitychange", visible);
1062
- window.removeEventListener("storage", storage);
1063
- };
1064
- }, [client, refresh, run]);
1065
- const specKey = JSON.stringify(props.spec);
1066
- useEffect(() => {
1067
- setQuote(null);
1068
- }, [specKey, productId, kind, region, props.quantity, props.supported, scopeKey]);
1069
- const regions = [...new Set(catalog?.products.map((product) => product.region) ?? [])];
1070
- const selectedRegion = regions.includes(region) ? region : regions[0] ?? "";
1071
- const products = catalog?.products.filter((product) => product.kind === kind && product.region === selectedRegion) ?? [];
1072
- const selected = products.find((product) => product.id === productId) ?? products[0];
1073
- const disabled = !props.supported || props.quantity !== 1 || !catalog?.enabled || !identity || identityClient.current !== client || !loaded || !fresh || busy || !!request;
1074
- const expired = quote ? Date.parse(quote.expires_at) <= now : true;
1075
- const getQuote = async () => {
1076
- if (disabled || !selected || inFlight.current) return;
1077
- inFlight.current = true;
1078
- setBusy(true);
1079
- setError("");
1080
- setQuote(null);
1081
- const inputSnapshot = specKey;
1082
- const generation = epoch.current;
1083
- const key = scopeKey;
1084
- try {
1085
- const value = await run((signal) => client.proxies.creationQuote({ spec: props.spec, product_id: selected.id }, { signal }));
1086
- if (!active.current || generation !== epoch.current || storageRef.current !== key || JSON.stringify(propsRef.current.spec) !== inputSnapshot) return;
1087
- 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"));
1088
- setQuote(value);
1089
- setNow(Date.now());
1090
- } catch (e) {
1091
- if (active.current && generation === epoch.current && storageRef.current === key) setError(e.message);
1092
- } finally {
1093
- inFlight.current = false;
1094
- if (active.current && generation === epoch.current && storageRef.current === key) setBusy(false);
1095
- }
1096
- };
1097
- const submit = async (input) => {
1098
- if (!scopeKey || inFlight.current || !request && disabled) return;
1099
- inFlight.current = true;
1100
- setBusy(true);
1101
- setError("");
1102
- const key = scopeKey;
1103
- const generation = epoch.current;
1104
- const current = () => active.current && generation === epoch.current && storageRef.current === key && identityClient.current === client;
1105
- const send = async () => {
1106
- if (!current()) return;
1107
- let uncertain = !!input.uncertain;
1108
- let sent = false;
1109
- try {
1110
- const previous = readCreationRequest(key);
1111
- if (previous && previous.request_id !== input.request_id) {
1112
- setPending(previous);
1113
- throw new Error(t("managed.otherRequest"));
1114
- }
1115
- uncertain ||= previous?.request_id === input.request_id || requestRef.current?.request_id === input.request_id;
1116
- const durable = { ...input, uncertain };
1117
- localStorage.setItem(key, JSON.stringify(durable));
1118
- setPending(durable);
1119
- propsRef.current.onPendingChange(true);
1120
- sent = true;
1121
- 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 }));
1122
- if (value.request_id !== input.request_id || value.quote_id !== input.quote_id) throw new Error(translate.current("creation.invalidService"));
1123
- if (current()) {
1124
- setReceipt(value);
1125
- setQuote(null);
1126
- await refresh();
1127
- }
1128
- } catch (e) {
1129
- const stored = readCreationRequest(key);
1130
- uncertain ||= stored?.request_id === input.request_id && !!stored.uncertain;
1131
- if (sent && creationRejected(e) && !uncertain) {
1132
- if (stored?.request_id === input.request_id) localStorage.removeItem(key);
1133
- if (current()) {
1134
- setPending(null);
1135
- setQuote(null);
1136
- propsRef.current.onPendingChange(false);
1137
- }
1138
- } else if (sent) {
1139
- if (stored?.request_id === input.request_id) localStorage.setItem(key, JSON.stringify({ ...stored, uncertain: true }));
1140
- if (current()) await refresh();
1141
- }
1142
- if (current()) setError(e.message);
1143
- }
1144
- };
1145
- try {
1146
- if (typeof navigator.locks?.request === "function") {
1147
- await navigator.locks.request(key, { ifAvailable: true }, async (lock) => {
1148
- if (lock) await send();
1149
- else {
1150
- if (current()) setError(t("managed.otherRequest"));
1151
- await refresh();
1152
- }
1153
- });
1154
- } else await send();
1155
- } catch (e) {
1156
- if (current()) setError(e.message);
1157
- } finally {
1158
- inFlight.current = false;
1159
- if (current()) setBusy(false);
1160
- }
1161
- };
1162
- const acknowledge = () => {
1163
- if (!scopeKey || identityClient.current !== client || !receipt || !creationReady(receipt) && receipt.creation_status !== "failed") return;
1164
- if (readCreationRequest(scopeKey)?.request_id === receipt.request_id) localStorage.removeItem(scopeKey);
1165
- setPending(null);
1166
- propsRef.current.onPendingChange(false);
1167
- propsRef.current.onComplete(receipt.device_id, creationReady(receipt));
1168
- };
1169
- if (!props.visible && !request) return null;
1170
- return /* @__PURE__ */ jsxs("section", { className: "space-y-3 text-sm", "aria-label": t("creation.title"), children: [
1171
- error && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words text-destructive", children: error }),
1172
- !loaded && /* @__PURE__ */ jsx("p", { role: "status", children: t("creation.loading") }),
1173
- !fresh && loaded && /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => void refresh(), children: t("common.refresh") }),
1174
- request ? /* @__PURE__ */ jsxs("div", { className: "space-y-3 rounded-md border border-border p-3", children: [
1175
- /* @__PURE__ */ jsx("p", { role: "status", className: "font-medium", children: creationReady(receipt) ? t("creation.ready") : t(`creation.status.${receipt?.creation_status ?? "unknown"}`) }),
1176
- /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("creation.recovery") }),
1177
- /* @__PURE__ */ jsxs("p", { className: "break-all", children: [
1178
- t("creation.request"),
1179
- ": ",
1180
- request.request_id
1181
- ] }),
1182
- receipt && /* @__PURE__ */ jsxs(Fragment, { children: [
1183
- /* @__PURE__ */ jsxs("p", { className: "break-all", children: [
1184
- t("creation.device"),
1185
- ": ",
1186
- receipt.device_id
1187
- ] }),
1188
- /* @__PURE__ */ jsxs("p", { children: [
1189
- t("managed.order"),
1190
- ": ",
1191
- receipt.proxy_order.id,
1192
- " \xB7 ",
1193
- t(`managed.status.${receipt.proxy_order.status}`)
1194
- ] }),
1195
- receipt.failure_reason && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words text-destructive", children: receipt.failure_reason }),
1196
- receipt.creation_status === "failed" && /* @__PURE__ */ jsx("p", { children: t("creation.failedTerms") })
1197
- ] }),
1198
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
1199
- /* @__PURE__ */ jsx(Button, { variant: "secondary", disabled: busy, onClick: () => void refresh(), children: t("common.refresh") }),
1200
- !receipt && /* @__PURE__ */ jsx(Button, { disabled: busy || !fresh, onClick: () => void submit(request), children: t("managed.retry") }),
1201
- (creationReady(receipt) || receipt?.creation_status === "failed") && /* @__PURE__ */ jsx(Button, { disabled: busy, onClick: acknowledge, children: t("creation.done") })
1202
- ] })
1203
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1204
- !props.supported && /* @__PURE__ */ jsx("p", { children: t("creation.unsupported") }),
1205
- props.quantity !== 1 && /* @__PURE__ */ jsx("p", { role: "status", children: t("creation.singleOnly") }),
1206
- catalog && !catalog.enabled && /* @__PURE__ */ jsxs("p", { role: "status", children: [
1207
- t("creation.unavailable"),
1208
- catalog.unavailable_reason ? ` \xB7 ${catalog.unavailable_reason}` : ""
1209
- ] }),
1210
- catalog?.enabled && props.supported && /* @__PURE__ */ jsxs(Fragment, { children: [
1211
- /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
1212
- /* @__PURE__ */ jsx("span", { children: t("creation.country") }),
1213
- /* @__PURE__ */ jsx("select", { className: "min-h-10 w-full rounded border border-border bg-background px-2", disabled, value: selectedRegion, onChange: (e) => {
1214
- setRegion(e.target.value);
1215
- setQuote(null);
1216
- }, children: regions.map((value) => /* @__PURE__ */ jsx("option", { children: value }, value)) })
1217
- ] }),
1218
- /* @__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: () => {
1219
- setKind(value);
1220
- setQuote(null);
1221
- }, children: t(`managed.${value}`) }, value)) }),
1222
- /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t(`managed.${kind}Hint`) }),
1223
- selected ? /* @__PURE__ */ jsxs(Fragment, { children: [
1224
- /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
1225
- /* @__PURE__ */ jsx("span", { children: t("managed.product") }),
1226
- /* @__PURE__ */ jsx("select", { className: "min-h-10 w-full rounded border border-border bg-background px-2", disabled, value: selected.id, onChange: (e) => {
1227
- setProductId(e.target.value);
1228
- setQuote(null);
1229
- }, children: products.map((product) => /* @__PURE__ */ jsxs("option", { value: product.id, children: [
1230
- product.name,
1231
- " \xB7 ",
1232
- t("managed.hours", { n: product.duration_seconds / 3600 }),
1233
- " \xB7 ",
1234
- money(product.cost_minor)
1235
- ] }, product.id)) })
1236
- ] }),
1237
- /* @__PURE__ */ jsx("p", { children: t("managed.budget", { amount: money(selected.quota_value) }) }),
1238
- /* @__PURE__ */ jsx(Button, { disabled, onClick: () => void getQuote(), children: t("managed.quote") })
1239
- ] }) : /* @__PURE__ */ jsx("p", { children: t("managed.emptyCatalog") })
1240
- ] }),
1241
- quote && /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded-md border border-primary/40 p-3", children: [
1242
- /* @__PURE__ */ jsx("p", { className: "font-semibold", children: t("creation.ipTotal", { amount: money(quote.total_minor) }) }),
1243
- /* @__PURE__ */ jsxs("p", { children: [
1244
- quote.product.region,
1245
- " \xB7 ",
1246
- t(`managed.${quote.product.kind}`),
1247
- " \xB7 ",
1248
- t("managed.hours", { n: quote.product.duration_seconds / 3600 })
1249
- ] }),
1250
- /* @__PURE__ */ jsx("p", { children: t("managed.fixedCost", { amount: money(quote.product.fixed_cost_minor) }) }),
1251
- /* @__PURE__ */ jsx("p", { children: t("managed.budget", { amount: money(quote.product.quota_value) }) }),
1252
- quote.product.rate_minor_per_gib != null && /* @__PURE__ */ jsx("p", { children: t("managed.rate", { amount: money(quote.product.rate_minor_per_gib) }) }),
1253
- quote.product.budget_accounting === "reserved_upper_bound" && /* @__PURE__ */ jsx("p", { children: t("managed.reservations", { kib: (quote.product.reservation_bytes ?? 16384) / 1024 }) }),
1254
- quote.product.handshake_reservation_bytes != null && /* @__PURE__ */ jsx("p", { children: t("managed.handshakeReservation", { kib: quote.product.handshake_reservation_bytes / 1024 }) }),
1255
- /* @__PURE__ */ jsx("p", { children: t("managed.noRenew") }),
1256
- /* @__PURE__ */ jsx("p", { children: t("creation.failedTerms") }),
1257
- /* @__PURE__ */ jsx("p", { className: "font-medium", children: t("creation.startupNetwork") }),
1258
- /* @__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") }),
1259
- /* @__PURE__ */ jsx("p", { children: expired ? t("managed.quoteExpired") : t("managed.quoteExpiry", { at: new Date(quote.expires_at).toLocaleString() }) }),
1260
- /* @__PURE__ */ jsx(Button, { disabled: disabled || expired, onClick: () => {
1261
- 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" });
1262
- }, children: t("creation.authorize", { amount: money(quote.total_minor) }) })
1263
- ] })
1264
- ] })
1265
- ] });
1266
- }
1267
-
1268
968
  // src/ui/device-create/create-proxy-capabilities.ts
1269
969
  function createProxyCapabilities(kind, spec, node) {
1270
970
  const cap = node?.reported_caps?.egress_proxy;
@@ -1281,12 +981,13 @@ function DeviceCreate({ open, onClose, onCreated }) {
1281
981
  const [step, setStep] = useState(0);
1282
982
  const [kind, setKind] = useState("virtual");
1283
983
  const [nodeId, setNodeId] = useState("");
984
+ const [virtualSpecValid, setVirtualSpecValid] = useState(false);
1284
985
  const [spec, setSpec] = useState(emptySpec);
1285
986
  const [picked, setPicked] = useState(null);
1286
987
  const [busy, setBusy] = useState(false);
1287
988
  const [error, setError] = useState("");
1288
989
  const [quantity, setQuantity] = useState(1);
1289
- const [networkMode, setNetworkMode] = useState("none");
990
+ const [networkMode, setNetworkMode] = useState("managed");
1290
991
  const [managedPending, setManagedPending] = useState(false);
1291
992
  const proxyCapabilities = createProxyCapabilities(kind, spec, nodes?.find((node) => node.id === nodeId));
1292
993
  useEffect(() => {
@@ -1294,19 +995,20 @@ function DeviceCreate({ open, onClose, onCreated }) {
1294
995
  setStep(0);
1295
996
  setKind("virtual");
1296
997
  setNodeId("");
998
+ setVirtualSpecValid(false);
1297
999
  setSpec(emptySpec);
1298
1000
  setPicked(null);
1299
1001
  setBusy(false);
1300
1002
  setError("");
1301
1003
  setQuantity(1);
1302
- setNetworkMode("none");
1004
+ setNetworkMode("managed");
1303
1005
  setManagedPending(false);
1304
1006
  }, [open]);
1305
1007
  const proxyOk = networkMode !== "custom" || proxyCapabilities.custom && isSupportedProxyUrl(spec.proxy?.trim() ?? "");
1306
1008
  const canNext = (() => {
1307
1009
  if (step === 0) return true;
1308
1010
  if (step === 1) return !!nodeId;
1309
- if (step === 2) return kind === "virtual" ? !!spec.image_id : !!picked;
1011
+ if (step === 2) return kind === "virtual" ? virtualSpecValid && !!spec.image_id : !!picked;
1310
1012
  return true;
1311
1013
  })();
1312
1014
  const enrollDiscovered = async (d) => {
@@ -1321,7 +1023,7 @@ function DeviceCreate({ open, onClose, onCreated }) {
1321
1023
  }
1322
1024
  };
1323
1025
  const finish = async () => {
1324
- if (kind === "virtual" && !spec.image_id) {
1026
+ if (kind === "virtual" && (!virtualSpecValid || !spec.image_id)) {
1325
1027
  setError("\u8BF7\u9009\u62E9\u8BE5\u8282\u70B9\u5DF2\u5B89\u88C5\u7684\u7CFB\u7EDF\u7248\u672C\u540E\u518D\u521B\u5EFA\u3002");
1326
1028
  return;
1327
1029
  }
@@ -1393,7 +1095,10 @@ function DeviceCreate({ open, onClose, onCreated }) {
1393
1095
  active: kind === "virtual",
1394
1096
  title: "\u865A\u62DF\u8BBE\u5907",
1395
1097
  desc: "Android / iOS \u4E91\u8BBE\u5907\uFF0C\u6309\u89C4\u683C\u65B0\u5EFA",
1396
- onClick: () => setKind("virtual")
1098
+ onClick: () => {
1099
+ setKind("virtual");
1100
+ setNetworkMode("managed");
1101
+ }
1397
1102
  }
1398
1103
  ),
1399
1104
  /* @__PURE__ */ jsx(
@@ -1402,31 +1107,33 @@ function DeviceCreate({ open, onClose, onCreated }) {
1402
1107
  active: kind === "real",
1403
1108
  title: "\u771F\u673A",
1404
1109
  desc: "\u4ECE\u8282\u70B9\u5DF2\u4E0A\u62A5\u7684\u771F\u673A\u4E2D\u9009\u53D6",
1405
- onClick: () => setKind("real")
1110
+ onClick: () => {
1111
+ setKind("real");
1112
+ setNetworkMode("none");
1113
+ }
1406
1114
  }
1407
1115
  )
1408
1116
  ] }),
1409
- step === 1 && /* @__PURE__ */ jsx(NodePicker, { value: nodeId, onChange: setNodeId, hidePlatform: kind === "real" }),
1410
- step === 2 && (kind === "virtual" ? /* @__PURE__ */ jsx(VirtualSpecStep, { spec, onChange: setSpec, nodeId }) : /* @__PURE__ */ jsx(RealDiscoverStep, { nodeId, picked, onPick: setPicked })),
1411
- step === 3 && !managedPending && /* @__PURE__ */ jsxs(Fragment, { children: [
1412
- /* @__PURE__ */ jsxs("fieldset", { className: "space-y-2", children: [
1413
- /* @__PURE__ */ jsx("legend", { className: "text-sm font-medium", children: t("creation.network") }),
1414
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
1415
- proxyCapabilities.managed && /* @__PURE__ */ jsx(Button, { variant: networkMode === "managed" ? "primary" : "secondary", "aria-pressed": networkMode === "managed", disabled: busy, onClick: () => setNetworkMode("managed"), children: t("creation.managed") }),
1416
- proxyCapabilities.custom && /* @__PURE__ */ jsx(Button, { variant: networkMode === "custom" ? "primary" : "secondary", "aria-pressed": networkMode === "custom", disabled: busy, onClick: () => setNetworkMode("custom"), children: t("creation.custom") }),
1417
- /* @__PURE__ */ jsx(Button, { variant: networkMode === "none" ? "primary" : "secondary", "aria-pressed": networkMode === "none", disabled: busy, onClick: () => setNetworkMode("none"), children: t("creation.none") })
1418
- ] }),
1419
- !proxyCapabilities.custom && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("creation.unsupported") })
1117
+ step === 1 && /* @__PURE__ */ jsx(NodePicker, { value: nodeId, onChange: (id) => {
1118
+ setNodeId(id);
1119
+ setVirtualSpecValid(false);
1120
+ }, hidePlatform: kind === "real", virtualOnly: kind === "virtual" }),
1121
+ step === 2 && (kind === "virtual" ? /* @__PURE__ */ jsx(VirtualSpecStep, { spec, onChange: setSpec, nodeId, onValidityChange: setVirtualSpecValid }) : /* @__PURE__ */ jsx(RealDiscoverStep, { nodeId, picked, onPick: setPicked })),
1122
+ step === 3 && !managedPending && /* @__PURE__ */ jsx(Fragment, { children: kind === "virtual" && /* @__PURE__ */ jsxs("fieldset", { className: "space-y-2", children: [
1123
+ /* @__PURE__ */ jsx("legend", { className: "text-sm font-medium", children: t("creation.network") }),
1124
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-2", children: [
1125
+ /* @__PURE__ */ jsx("button", { type: "button", className: "py-2 text-xs font-medium text-primary hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary", "aria-pressed": networkMode === "managed", disabled: busy, onClick: () => setNetworkMode("managed"), children: t("creation.managed") }),
1126
+ /* @__PURE__ */ jsx("button", { type: "button", className: "py-2 text-xs text-primary hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:opacity-50", "aria-pressed": networkMode === "custom", disabled: busy || !proxyCapabilities.custom, onClick: () => setNetworkMode("custom"), children: t("proxy.manualInput") }),
1127
+ /* @__PURE__ */ jsx("button", { type: "button", className: "py-2 text-xs text-muted-foreground hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary", "aria-pressed": networkMode === "none", disabled: busy, onClick: () => setNetworkMode("none"), children: t("creation.none") })
1420
1128
  ] }),
1421
- /* @__PURE__ */ jsx(ProxySpoofStep, { spec, onChange: setSpec, isReal: kind === "real", showProxy: networkMode === "custom" && proxyCapabilities.custom })
1422
- ] }),
1129
+ networkMode === "none" && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("proxy.directHint") })
1130
+ ] }) }),
1423
1131
  open && /* @__PURE__ */ jsx(
1424
- ManagedCreationPanel,
1132
+ IpCommercePanel,
1425
1133
  {
1426
1134
  visible: step === 3 && networkMode === "managed",
1427
- supported: proxyCapabilities.managed,
1428
- quantity,
1429
- spec: { ...spec, proxy: void 0, node_id: nodeId },
1135
+ supported: proxyCapabilities.managed && quantity === 1,
1136
+ creationSpec: { ...spec, proxy: void 0, node_id: nodeId },
1430
1137
  onPendingChange: (pending) => {
1431
1138
  setManagedPending(pending);
1432
1139
  if (pending) {
@@ -1434,13 +1141,14 @@ function DeviceCreate({ open, onClose, onCreated }) {
1434
1141
  setStep(3);
1435
1142
  }
1436
1143
  },
1437
- onComplete: (_deviceId, ready) => {
1144
+ onCreated: () => {
1438
1145
  void fetchDevices();
1439
- if (ready) onCreated?.(null);
1146
+ onCreated?.(null);
1440
1147
  onClose();
1441
1148
  }
1442
1149
  }
1443
1150
  ),
1151
+ step === 3 && !managedPending && /* @__PURE__ */ jsx(ProxySpoofStep, { spec, onChange: setSpec, isReal: kind === "real", showProxy: networkMode === "custom" && proxyCapabilities.custom }),
1444
1152
  step === 3 && kind === "virtual" && !managedPending && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1445
1153
  /* @__PURE__ */ jsx("label", { className: "text-[11px] text-muted-foreground", children: "\u521B\u5EFA\u6570\u91CF" }),
1446
1154
  /* @__PURE__ */ jsx(
@@ -1462,7 +1170,7 @@ function DeviceCreate({ open, onClose, onCreated }) {
1462
1170
  Button,
1463
1171
  {
1464
1172
  size: "sm",
1465
- disabled: busy || !proxyOk || kind === "virtual" && !spec.image_id || kind === "virtual" && (!Number.isInteger(quantity) || quantity < 1 || quantity > 20),
1173
+ disabled: busy || !proxyOk || kind === "virtual" && (!virtualSpecValid || !spec.image_id) || kind === "virtual" && (!Number.isInteger(quantity) || quantity < 1 || quantity > 20),
1466
1174
  onClick: finish,
1467
1175
  children: busy ? "\u521B\u5EFA\u4E2D\u2026" : quantity > 1 ? `\u521B\u5EFA ${quantity} \u53F0` : "\u521B\u5EFA"
1468
1176
  }