@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,13 +1,14 @@
1
- import { LogConsole } from './chunk-D7J4EQTA.js';
2
- import { requestPreviewFrame, MirrorSurface, DeviceMirror, ConnectDevicesDialog } from './chunk-XCYGBYFC.js';
3
- import { ControlBar, MirrorView } from './chunk-E7WMHM63.js';
4
- import { deviceProxyCapabilities, createProxyProbeGuard, proxySummaryFromDevice, isProxyApplyStatus, proxyCapabilityReason, proxyProbeExitIp, proxyProbeMessage, DeviceCreate, isProxyProbeUnsupported, isRedactedProxyUrl, isSupportedProxyUrl, redactProxyUrl } from './chunk-5KZB6M2S.js';
5
- import { IosDeviceDiagnostics } from './chunk-SL6M6CC6.js';
1
+ import { LogConsole } from './chunk-S5N4EOCP.js';
2
+ import { requestPreviewFrame, MirrorSurface, DeviceMirror, ConnectDevicesDialog } from './chunk-U4QW45MB.js';
3
+ import { ControlBar, MirrorView } from './chunk-MBBVYSPD.js';
4
+ import { deviceProxyCapabilities, createProxyProbeGuard, proxySummaryFromDevice, isProxyApplyStatus, proxyCapabilityReason, proxyProbeExitIp, proxyProbeMessage, DeviceCreate, isProxyProbeUnsupported, isRedactedProxyUrl, isSupportedProxyUrl, redactProxyUrl } from './chunk-Q5I63UYT.js';
5
+ import { IosDeviceDiagnostics } from './chunk-T6X6TWHK.js';
6
+ import { IpCommercePanel } from './chunk-QFGMQLRB.js';
6
7
  import { isPhysicalIos } from './chunk-ZB5ET67B.js';
7
- import { useAixT, useAixLang } from './chunk-LO3XD4T5.js';
8
- import { cn, Badge, Button, Dialog, Input, Popover, Select, useToast, ToastViewport, Drawer } from './chunk-SKTL6ACT.js';
9
- import { useClient, useDevicesView, useShortcutsView, GROUP_MIRROR_MAX, useGroupMirror, useScripts, useFleetRun, useTaskAgentRun, preflightTaskAgentDevice, createAgentTaskRunner, useNodesView } from './chunk-7IXBWJHB.js';
10
- import { DeviceSession, pushFile, pullFile } from './chunk-PUEKOYSH.js';
8
+ import { useAixT } from './chunk-QRIWTPN3.js';
9
+ import { cn, Badge, Button, Dialog, Input, Popover, Select, useToast, ToastViewport, Drawer } from './chunk-VMA3QOYR.js';
10
+ import { useClient, useDevicesView, useShortcutsView, GROUP_MIRROR_MAX, useGroupMirror, useScripts, useFleetRun, useTaskAgentRun, preflightTaskAgentDevice, createAgentTaskRunner, useNodesView } from './chunk-QEK25NUA.js';
11
+ import { DeviceSession, pushFile, pullFile, AixError } from './chunk-2KPZSPV6.js';
11
12
  import { useState, useRef, useCallback, useEffect, useMemo, useLayoutEffect } from 'react';
12
13
  import * as Icons from 'lucide-react';
13
14
  import { Monitor, Eye, Play, Power, RefreshCw, Server, Pencil, Trash2, FolderPlus, Upload, ArrowUp, Folder, File, Download, Dices, ShieldCheck, AlertTriangle, X, Crown, RotateCcw, Square, Plus, Search, LayoutGrid, List, ChevronLeft, Link, Link2Off, Terminal as Terminal$1, PackagePlus, MonitorPlay, ChevronRight, ChevronDown, PlusSquare, Maximize2, Info, ChevronsLeft, ChevronsRight, Check, Copy, Tablet, Smartphone } from 'lucide-react';
@@ -288,44 +289,6 @@ function DeviceCard({
288
289
  }
289
290
 
290
291
  // src/ui/devices/managed-proxy-state.ts
291
- function proxyRequestStorageKey(baseUrl, owner, project, deviceId) {
292
- return owner ? `aix-managed-proxy:v1:${JSON.stringify([baseUrl, owner, project ?? "", deviceId])}` : null;
293
- }
294
- function readProxyRequest(key) {
295
- if (!key) return null;
296
- try {
297
- const value = JSON.parse(localStorage.getItem(key) ?? "null");
298
- if (!value || typeof value.requestId !== "string") return null;
299
- if (value.action === "purchase" && typeof value.quoteId === "string") return value;
300
- if (["rotate", "apply", "release"].includes(value.action) && "orderId" in value && typeof value.orderId === "string") return value;
301
- } catch {
302
- }
303
- return null;
304
- }
305
- function writeProxyRequest(key, request) {
306
- if (!key) return;
307
- if (request) localStorage.setItem(key, JSON.stringify(request));
308
- else localStorage.removeItem(key);
309
- }
310
- function proxyOrderBusy(order) {
311
- return !!order.pending_action || order.status === "pending" || order.status === "reconciling" || order.status === "fulfilled" && order.apply_status === "pending";
312
- }
313
- function isDefiniteProxyRejection(error) {
314
- const state = error?.requestState;
315
- if (state === "rejected") return true;
316
- if (state === "unknown") return false;
317
- const status = error?.status ?? error?.meta?.status;
318
- return status !== void 0 && [400, 402, 403, 404, 410, 422].includes(status);
319
- }
320
- function mergeProxyOrders(history, active) {
321
- const merged = new Map(history.map((order) => [order.id, order]));
322
- for (const order of active) merged.set(order.id, order);
323
- return [...merged.values()].sort((a, b) => {
324
- const activeA = ["pending", "reconciling", "fulfilled"].includes(a.status) || !!a.pending_action;
325
- const activeB = ["pending", "reconciling", "fulfilled"].includes(b.status) || !!b.pending_action;
326
- return Number(activeB) - Number(activeA) || Date.parse(b.created_at) - Date.parse(a.created_at);
327
- });
328
- }
329
292
  function proxySelectionFromMeta(meta) {
330
293
  const source = meta.proxy_source;
331
294
  const summary = meta.proxy_summary;
@@ -337,9 +300,6 @@ function proxySelectionFromMeta(meta) {
337
300
  observedStatus: typeof summary?.observed_status === "string" ? summary.observed_status : void 0
338
301
  };
339
302
  }
340
- function proxyOrderCurrentlyApplied(order, selection) {
341
- return selection?.kind === "aixips" && selection.orderId === order.id && selection.desiredRevision !== void 0 && selection.desiredRevision === order.applied_revision && selection.observedRevision === selection.desiredRevision && selection.observedStatus === "applied";
342
- }
343
303
  function ConfirmDialog({
344
304
  open,
345
305
  title,
@@ -369,368 +329,7 @@ function ConfirmDialog({
369
329
  }
370
330
  function ManagedProxyPanel(props) {
371
331
  const client = useClient();
372
- return /* @__PURE__ */ jsx(ManagedProxySession, { ...props }, JSON.stringify([client.cfg.baseUrl, props.ownerUserId, props.projectId, props.deviceId]));
373
- }
374
- function ManagedProxySession({ deviceId, ownerUserId, projectId, supported, selection, onChanged }) {
375
- const client = useClient();
376
- const t = useAixT();
377
- const lang = useAixLang();
378
- const storageKey = proxyRequestStorageKey(client.cfg.baseUrl, ownerUserId, projectId, deviceId);
379
- const [catalog, setCatalog] = useState(null);
380
- const [orders, setOrders] = useState([]);
381
- const [kind, setKind] = useState("static");
382
- const [productId, setProductId] = useState("");
383
- const [quote, setQuote] = useState(null);
384
- const [pending, setPending] = useState(() => readProxyRequest(storageKey));
385
- const [busy, setBusy] = useState(false);
386
- const [loading, setLoading] = useState(true);
387
- const [ordersLoaded, setOrdersLoaded] = useState(false);
388
- const [error, setError] = useState(null);
389
- const [refreshError, setRefreshError] = useState(null);
390
- const [activeFresh, setActiveFresh] = useState(false);
391
- const [historyCount, setHistoryCount] = useState(0);
392
- const [notice, setNotice] = useState(null);
393
- const [releaseOrder, setReleaseOrder] = useState(null);
394
- const [now, setNow] = useState(Date.now());
395
- const active = useRef(true);
396
- const lock = useRef(false);
397
- const pendingRef = useRef(pending);
398
- const refreshInFlight = useRef(null);
399
- const fastPoll = useRef(false);
400
- const changedCallback = useRef(onChanged);
401
- const appliedSnapshot = useRef(null);
402
- changedCallback.current = onChanged;
403
- pendingRef.current = pending;
404
- const money = (minor) => `\xA5${(minor / 100).toFixed(2)}`;
405
- const duration = (seconds) => seconds % 86400 === 0 ? t("managed.days", { n: seconds / 86400 }) : seconds % 3600 === 0 ? t("managed.hours", { n: seconds / 3600 }) : seconds % 60 === 0 ? t("managed.minutes", { n: seconds / 60 }) : t("managed.seconds", { n: seconds });
406
- const date = (value) => value ? new Date(value).toLocaleString(lang === "zh" ? "zh-CN" : "en-US") : "\u2014";
407
- const clearPending = useCallback((requestId, accepted = false) => {
408
- try {
409
- const stored = readProxyRequest(storageKey);
410
- if (!accepted && stored?.requestId === requestId && stored.uncertain) return;
411
- if (!stored || stored.requestId === requestId) writeProxyRequest(storageKey, null);
412
- } catch {
413
- }
414
- if (!requestId || pendingRef.current?.requestId === requestId) {
415
- setPending(null);
416
- pendingRef.current = null;
417
- }
418
- }, [storageKey]);
419
- const refresh = useCallback(() => {
420
- if (refreshInFlight.current) return refreshInFlight.current;
421
- const run = async () => {
422
- const [history, current] = await Promise.allSettled([
423
- client.proxies.list(deviceId),
424
- client.proxies.list(deviceId, { active: true })
425
- ]);
426
- if (!active.current) return;
427
- const currentOk = current.status === "fulfilled";
428
- setActiveFresh(currentOk);
429
- if (currentOk) setOrdersLoaded(true);
430
- if (history.status === "fulfilled") setHistoryCount(history.value.length);
431
- const failures = [current, history].filter((result) => result.status === "rejected");
432
- setRefreshError(failures.length ? failures[0].reason?.message ?? "Unable to refresh orders" : null);
433
- if (history.status === "fulfilled" || currentOk) {
434
- setOrders((previous) => mergeProxyOrders(
435
- history.status === "fulfilled" ? history.value : previous,
436
- currentOk ? current.value : previous.filter((order) => ["pending", "reconciling", "fulfilled"].includes(order.status))
437
- ));
438
- }
439
- const changed = currentOk ? JSON.stringify(current.value.map((order) => [order.id, order.apply_status, order.applied_revision])) : null;
440
- if (changed !== null) {
441
- if (appliedSnapshot.current !== null && appliedSnapshot.current !== changed) changedCallback.current?.();
442
- appliedSnapshot.current = changed;
443
- }
444
- const request = pendingRef.current;
445
- if (request) {
446
- const visible = [...currentOk ? current.value : [], ...history.status === "fulfilled" ? history.value : []];
447
- const match = visible.find((order) => request.action === "purchase" ? order.request_id === request.requestId : order.pending_request_id === request.requestId);
448
- try {
449
- const recovered = match ?? await client.proxies.byRequest(deviceId, request.requestId);
450
- if (!active.current || pendingRef.current?.requestId !== request.requestId) return;
451
- setOrders((previous) => mergeProxyOrders(previous, [recovered]));
452
- clearPending(request.requestId, true);
453
- } catch {
454
- }
455
- }
456
- };
457
- const promise = run().finally(() => {
458
- refreshInFlight.current = null;
459
- });
460
- refreshInFlight.current = promise;
461
- return promise;
462
- }, [client, deviceId, clearPending]);
463
- useEffect(() => {
464
- active.current = true;
465
- let timer;
466
- const poll = async () => {
467
- if (document.visibilityState !== "hidden") await refresh();
468
- if (active.current) timer = setTimeout(() => void poll(), fastPoll.current ? 3e3 : 3e4);
469
- };
470
- void Promise.all([client.proxies.catalog().then((value) => {
471
- if (active.current) setCatalog(value);
472
- }), refresh()]).catch((e) => {
473
- if (active.current) setError(e.message);
474
- }).finally(() => {
475
- if (active.current) {
476
- setLoading(false);
477
- timer = setTimeout(() => void poll(), fastPoll.current ? 3e3 : 3e4);
478
- }
479
- });
480
- const clock = setInterval(() => setNow(Date.now()), 1e3);
481
- const visible = () => {
482
- if (document.visibilityState === "visible") void refresh();
483
- };
484
- const storage = (event) => {
485
- if (event.key !== storageKey) return;
486
- const request = readProxyRequest(storageKey);
487
- pendingRef.current = request;
488
- setPending(request);
489
- void refresh();
490
- };
491
- document.addEventListener("visibilitychange", visible);
492
- window.addEventListener("storage", storage);
493
- return () => {
494
- active.current = false;
495
- clearTimeout(timer);
496
- clearInterval(clock);
497
- document.removeEventListener("visibilitychange", visible);
498
- window.removeEventListener("storage", storage);
499
- };
500
- }, [client, refresh, storageKey]);
501
- const products = catalog?.products.filter((product) => product.kind === kind) ?? [];
502
- const selected = products.find((product) => product.id === productId) ?? products[0];
503
- const expired = quote ? !Number.isFinite(Date.parse(quote.expires_at)) || Date.parse(quote.expires_at) <= now : false;
504
- const processing = orders.some(proxyOrderBusy);
505
- fastPoll.current = !!pending || processing;
506
- const disabled = !supported || !storageKey || busy || loading || !ordersLoaded || !activeFresh || !!pending || processing;
507
- const requestQuote = async (id, replacesOrderId) => {
508
- if (!supported || lock.current || pendingRef.current) return;
509
- lock.current = true;
510
- setBusy(true);
511
- setError(null);
512
- setNotice(null);
513
- setQuote(null);
514
- try {
515
- const value = await client.proxies.quote({ device_id: deviceId, product_id: id, ...replacesOrderId ? { replaces_order_id: replacesOrderId } : {} });
516
- if (active.current) {
517
- setQuote(value);
518
- setNow(Date.now());
519
- }
520
- } catch (e) {
521
- if (active.current) setError(e.message);
522
- } finally {
523
- lock.current = false;
524
- if (active.current) setBusy(false);
525
- }
526
- };
527
- const execute = async (request) => {
528
- if (lock.current || !supported && request.action !== "release") return;
529
- lock.current = true;
530
- setBusy(true);
531
- setError(null);
532
- setNotice(null);
533
- const run = async () => {
534
- let uncertain = !!request.uncertain;
535
- let sent = false;
536
- try {
537
- if (!storageKey) throw new Error(t("managed.identityUnavailable"));
538
- const existing = readProxyRequest(storageKey);
539
- if (existing && existing.requestId !== request.requestId) {
540
- pendingRef.current = existing;
541
- setPending(existing);
542
- throw new Error(t("managed.otherRequest"));
543
- }
544
- uncertain ||= pendingRef.current?.requestId === request.requestId || existing?.requestId === request.requestId;
545
- const durable = uncertain ? { ...request, uncertain: true } : request;
546
- writeProxyRequest(storageKey, durable);
547
- setPending(durable);
548
- pendingRef.current = durable;
549
- sent = true;
550
- const order = request.action === "purchase" ? await client.proxies.purchase({ quote_id: request.quoteId, request_id: request.requestId }) : await client.proxies[request.action](request.orderId, request.requestId);
551
- if (!active.current) return;
552
- clearPending(request.requestId, true);
553
- setQuote(null);
554
- setReleaseOrder(null);
555
- setOrders((previous) => [order, ...previous.filter((item) => item.id !== order.id)]);
556
- setNotice(t("managed.accepted"));
557
- onChanged?.();
558
- await refresh();
559
- } catch (e) {
560
- if (!active.current) return;
561
- const stored = readProxyRequest(storageKey);
562
- uncertain ||= stored?.requestId === request.requestId && !!stored.uncertain;
563
- if (sent && isDefiniteProxyRejection(e) && !uncertain) {
564
- clearPending(request.requestId);
565
- setQuote(null);
566
- } else if (sent) {
567
- if (stored?.requestId === request.requestId) {
568
- const durable = { ...stored, uncertain: true };
569
- try {
570
- writeProxyRequest(storageKey, durable);
571
- } catch {
572
- }
573
- pendingRef.current = durable;
574
- setPending(durable);
575
- }
576
- await refresh();
577
- }
578
- if (active.current) setError(e.message);
579
- }
580
- };
581
- try {
582
- if (storageKey && navigator.locks?.request) {
583
- await navigator.locks.request(storageKey, { mode: "exclusive", ifAvailable: true }, async (held) => {
584
- if (held) return run();
585
- const existing = readProxyRequest(storageKey);
586
- if (active.current) {
587
- pendingRef.current = existing;
588
- setPending(existing);
589
- setNotice(t("managed.otherRequest"));
590
- await refresh();
591
- }
592
- });
593
- } else await run();
594
- } catch (e) {
595
- if (active.current) setError(e.message);
596
- } finally {
597
- lock.current = false;
598
- if (active.current) setBusy(false);
599
- }
600
- };
601
- const act = (action, orderId) => void execute({ action, orderId, requestId: crypto.randomUUID() });
602
- return /* @__PURE__ */ jsxs("div", { className: "space-y-3 rounded-lg border border-border p-3 text-xs", "aria-busy": busy || loading, children: [
603
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
604
- /* @__PURE__ */ jsx("h4", { className: "font-semibold", children: t("managed.title") }),
605
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy || loading, onClick: () => {
606
- setError(null);
607
- setLoading(true);
608
- void Promise.all([refresh(), client.proxies.catalog().then((value) => {
609
- if (active.current) setCatalog(value);
610
- })]).catch((e) => {
611
- if (active.current) setError(e.message);
612
- }).finally(() => {
613
- if (active.current) setLoading(false);
614
- });
615
- }, children: t("common.refresh") })
616
- ] }),
617
- /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.description") }),
618
- selection && /* @__PURE__ */ jsx("p", { children: t(`managed.selection.${selection.kind}`) }),
619
- !storageKey && /* @__PURE__ */ jsx("p", { className: "text-warning", children: t("managed.identityUnavailable") }),
620
- !supported && /* @__PURE__ */ jsx("p", { className: "text-warning", children: t("managed.unsupported") }),
621
- loading && /* @__PURE__ */ jsx("p", { role: "status", children: t("common.loading") }),
622
- refreshError && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words text-warning", children: t("managed.refreshFailed", { error: refreshError }) }),
623
- error && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words text-destructive", children: error }),
624
- notice && /* @__PURE__ */ jsx("p", { role: "status", className: "text-muted-foreground", children: notice }),
625
- pending && /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded border border-warning/50 p-2", children: [
626
- /* @__PURE__ */ jsx("p", { children: t("managed.unknown") }),
627
- /* @__PURE__ */ jsxs("p", { className: "break-all text-muted-foreground", children: [
628
- t("managed.request"),
629
- ": ",
630
- pending.requestId
631
- ] }),
632
- /* @__PURE__ */ jsx(Button, { size: "sm", disabled: busy || !storageKey || !supported && pending.action !== "release", onClick: () => void execute(pending), children: t("managed.retry") })
633
- ] }),
634
- catalog && !catalog.enabled && /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground", children: [
635
- t("managed.unavailable"),
636
- catalog.unavailable_reason ? `: ${catalog.unavailable_reason}` : ""
637
- ] }),
638
- catalog?.enabled && supported && /* @__PURE__ */ jsxs(Fragment, { children: [
639
- /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", role: "group", "aria-label": t("managed.kind"), children: ["static", "dynamic"].map((value) => /* @__PURE__ */ jsx(Button, { size: "sm", variant: kind === value ? "primary" : "secondary", "aria-pressed": kind === value, disabled, onClick: () => {
640
- setKind(value);
641
- setQuote(null);
642
- setProductId("");
643
- }, children: t(`managed.${value}`) }, value)) }),
644
- /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t(`managed.${kind}Hint`) }),
645
- selected ? /* @__PURE__ */ jsxs(Fragment, { children: [
646
- /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
647
- /* @__PURE__ */ jsx("span", { children: t("managed.product") }),
648
- /* @__PURE__ */ jsx("select", { className: "w-full min-h-10 rounded-md border border-border bg-secondary px-2 focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary", value: selected.id, disabled, onChange: (event) => {
649
- setProductId(event.target.value);
650
- setQuote(null);
651
- }, children: products.map((product) => /* @__PURE__ */ jsxs("option", { value: product.id, children: [
652
- product.region,
653
- " \xB7 ",
654
- product.name,
655
- " \xB7 ",
656
- duration(product.duration_seconds),
657
- " \xB7 ",
658
- money(product.cost_minor)
659
- ] }, product.id)) })
660
- ] }),
661
- /* @__PURE__ */ jsx("p", { children: t("managed.budget", { amount: money(selected.quota_value) }) }),
662
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled, onClick: () => void requestQuote(selected.id), children: t("managed.quote") })
663
- ] }) : /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.emptyCatalog") })
664
- ] }),
665
- quote && /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded-md border border-primary/40 bg-secondary/40 p-3", children: [
666
- /* @__PURE__ */ jsx("h5", { className: "font-semibold", children: quote.replaces_order_id ? t("managed.replaceQuote") : t("managed.quoteTitle") }),
667
- /* @__PURE__ */ jsxs("p", { children: [
668
- t(`managed.${quote.product.kind}`),
669
- " \xB7 ",
670
- quote.product.region,
671
- " \xB7 ",
672
- duration(quote.product.duration_seconds)
673
- ] }),
674
- /* @__PURE__ */ jsx("p", { children: t("managed.budget", { amount: money(quote.product.quota_value) }) }),
675
- /* @__PURE__ */ jsx("p", { children: t("managed.total", { amount: money(quote.total_minor) }) }),
676
- quote.product.fixed_cost_minor != null && /* @__PURE__ */ jsx("p", { children: t("managed.fixedCost", { amount: money(quote.product.fixed_cost_minor) }) }),
677
- quote.product.rate_minor_per_gib != null && /* @__PURE__ */ jsx("p", { children: t("managed.rate", { amount: money(quote.product.rate_minor_per_gib) }) }),
678
- quote.product.refund_policy === "no_refund_after_allocation" && /* @__PURE__ */ jsx("p", { children: t("managed.noRefund") }),
679
- quote.product.budget_accounting === "reserved_upper_bound" && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.reservations", { kib: (quote.product.reservation_bytes ?? 16384) / 1024 }) }),
680
- quote.product.handshake_reservation_bytes != null && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.handshakeReservation", { kib: quote.product.handshake_reservation_bytes / 1024 }) }),
681
- /* @__PURE__ */ jsx("p", { children: quote.product.replacement_policy.mode === "free" ? t("managed.freeRotate") : t("managed.newPurchase") }),
682
- /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.noRenew") }),
683
- /* @__PURE__ */ jsx("p", { className: expired ? "text-warning" : "text-muted-foreground", children: expired ? t("managed.quoteExpired") : t("managed.quoteExpiry", { at: date(quote.expires_at) }) }),
684
- /* @__PURE__ */ jsx(Button, { size: "sm", disabled: disabled || expired, onClick: () => {
685
- if (Date.parse(quote.expires_at) <= Date.now()) {
686
- setNow(Date.now());
687
- return;
688
- }
689
- void execute({ action: "purchase", quoteId: quote.id, requestId: crypto.randomUUID() });
690
- }, children: t("managed.pay", { amount: money(quote.total_minor) }) })
691
- ] }),
692
- historyCount >= 100 && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.historyLimit") }),
693
- !!orders.length && /* @__PURE__ */ jsx("ul", { "aria-label": t("managed.orders"), className: "space-y-2", children: orders.map((order) => /* @__PURE__ */ jsxs("li", { className: "space-y-2 rounded border border-border p-2", children: [
694
- /* @__PURE__ */ jsxs("p", { className: "font-medium", children: [
695
- t(`managed.${order.product.kind}`),
696
- " \xB7 ",
697
- order.product.region
698
- ] }),
699
- /* @__PURE__ */ jsxs("p", { children: [
700
- t(`managed.status.${order.status}`),
701
- " \xB7 ",
702
- t(order.apply_status === "applied" ? proxyOrderCurrentlyApplied(order, selection) ? "managed.currentlyApplied" : "managed.previouslyApplied" : `managed.apply.${order.apply_status}`)
703
- ] }),
704
- selection?.kind === "aixips" && selection.orderId === order.id && /* @__PURE__ */ jsx("p", { className: "font-medium", children: t("managed.selectedOrder") }),
705
- order.pending_action && /* @__PURE__ */ jsxs("p", { role: "status", children: [
706
- t("managed.processing"),
707
- ": ",
708
- t(`managed.action.${order.pending_action}`)
709
- ] }),
710
- /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground", children: [
711
- t("managed.total", { amount: money(order.total_minor) }),
712
- " \xB7 ",
713
- t("managed.expires", { at: date(order.expires_at) })
714
- ] }),
715
- /* @__PURE__ */ jsx("p", { children: t("managed.remaining", { amount: order.remaining_budget_minor == null ? "\u2014" : order.status === "fulfilled" && order.remaining_budget_minor === 0 ? t("managed.fractionalBalance") : money(order.remaining_budget_minor) }) }),
716
- order.failure_reason && /* @__PURE__ */ jsx("p", { className: "break-words text-destructive", children: order.failure_reason }),
717
- order.status === "fulfilled" && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
718
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled, onClick: () => act("apply", order.id), children: t("managed.apply") }),
719
- order.product.kind === "dynamic" && order.product.replacement_policy.mode === "free" ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled, onClick: () => act("rotate", order.id), children: t("managed.rotate") }) : /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled: disabled || !catalog?.enabled, onClick: () => void requestQuote(order.product.id, order.id), children: t("managed.replace") }),
720
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: !storageKey || busy || loading || !ordersLoaded || !!pending || order.pending_action === "release", onClick: () => setReleaseOrder(order), children: t("managed.release") })
721
- ] }),
722
- /* @__PURE__ */ jsxs("p", { className: "break-all text-muted-foreground", children: [
723
- t("managed.order"),
724
- ": ",
725
- order.id
726
- ] })
727
- ] }, order.id)) }),
728
- /* @__PURE__ */ jsx(ConfirmDialog, { open: !!releaseOrder, title: t("managed.releaseTitle"), description: t("managed.releaseDescription"), confirmLabel: t("managed.release"), busy, destructive: true, onClose: () => {
729
- if (!busy) setReleaseOrder(null);
730
- }, onConfirm: () => {
731
- if (releaseOrder) act("release", releaseOrder.id);
732
- } })
733
- ] });
332
+ return /* @__PURE__ */ jsx(IpCommercePanel, { deviceId: props.deviceId, supported: props.supported, onChanged: props.onChanged }, JSON.stringify([client.cfg.baseUrl, props.ownerUserId, props.projectId, props.deviceId]));
734
333
  }
735
334
  function supportsDataSnapshots(meta) {
736
335
  const spec = meta.spec;
@@ -852,6 +451,321 @@ function SnapshotWorkspace({ deviceId, online, supported, onChanged }) {
852
451
  ] });
853
452
  }
854
453
 
454
+ // src/ui/devices/portable-operation.ts
455
+ async function snapshotOperationStorageKey(cfg, deviceId) {
456
+ try {
457
+ const headers = await cfg.auth.headers("caller");
458
+ const bearer = headers.Authorization?.replace(/^Bearer /, "");
459
+ let scope;
460
+ if (bearer) {
461
+ try {
462
+ const segment = bearer.split(".")[1];
463
+ if (!segment) throw new Error("opaque credential");
464
+ const claims = JSON.parse(atob(segment.replace(/-/g, "+").replace(/_/g, "/")));
465
+ if (claims.typ === "user" && typeof claims.sub === "string" && typeof claims.project_id === "string") {
466
+ scope = JSON.stringify([claims.typ, claims.sub, claims.project_id]);
467
+ }
468
+ } catch {
469
+ }
470
+ }
471
+ if (!scope) {
472
+ const serialized = JSON.stringify(Object.entries(headers).sort(([a], [b]) => a.localeCompare(b)));
473
+ if (serialized === "[]" || !globalThis.crypto?.subtle) return null;
474
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(serialized));
475
+ scope = Array.from(new Uint8Array(digest), (value) => value.toString(16).padStart(2, "0")).join("");
476
+ }
477
+ return `aix:portable-operation:v1:${JSON.stringify([cfg.baseUrl, scope, deviceId])}`;
478
+ } catch {
479
+ return null;
480
+ }
481
+ }
482
+ function readSnapshotOperation(key) {
483
+ if (!key) return null;
484
+ try {
485
+ const value = JSON.parse(sessionStorage.getItem(key) ?? "null");
486
+ return value && typeof value.id === "string" && value.id.length > 0 && value.id.length <= 200 && (value.action === "save" || value.action === "restore") ? { id: value.id, action: value.action } : null;
487
+ } catch {
488
+ return null;
489
+ }
490
+ }
491
+ function writeSnapshotOperation(key, operation) {
492
+ if (!key) return;
493
+ try {
494
+ if (operation) sessionStorage.setItem(key, JSON.stringify({ id: operation.id, action: operation.action }));
495
+ else sessionStorage.removeItem(key);
496
+ } catch {
497
+ }
498
+ }
499
+ var uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
500
+ var message = (error) => error instanceof Error ? error.message : String(error);
501
+ var warningKeys = { proxy_reset_incomplete: "portable.warning.proxy", kernelsu_bootstrap_unverified: "portable.warning.kernelsu" };
502
+ function PortableSnapshotsPanel(props) {
503
+ return /* @__PURE__ */ jsx(Workspace, { ...props }, props.deviceId);
504
+ }
505
+ function Workspace({ deviceId, online, supported, onChanged }) {
506
+ const client = useClient();
507
+ const t = useAixT();
508
+ const alive = useRef(true);
509
+ const submitting = useRef(false);
510
+ const sequence = useRef(0);
511
+ const storageKey = useRef(null);
512
+ const [resuming, setResuming] = useState(true);
513
+ const [snapshots, setSnapshots] = useState([]);
514
+ const [nodes, setNodes] = useState([]);
515
+ const [label, setLabel] = useState("");
516
+ const [kind, setKind] = useState("full");
517
+ const [loading, setLoading] = useState(false);
518
+ const [mutating, setMutating] = useState(false);
519
+ const [error, setError] = useState("");
520
+ const [notice, setNotice] = useState("");
521
+ const [warnings, setWarnings] = useState([]);
522
+ const [operation, setOperation] = useState(null);
523
+ const [pollVersion, setPollVersion] = useState(0);
524
+ const [pending, setPending] = useState(null);
525
+ const [nodeId, setNodeId] = useState("");
526
+ const [sharing, setSharing] = useState(null);
527
+ const [grants, setGrants] = useState([]);
528
+ const [userId, setUserId] = useState("");
529
+ const busy = resuming || mutating || operation !== null;
530
+ const refresh = useCallback(async () => {
531
+ const version = ++sequence.current;
532
+ setLoading(true);
533
+ try {
534
+ const result = await client.snapshots.list();
535
+ if (alive.current && version === sequence.current) setSnapshots(result.snapshots);
536
+ } catch (e) {
537
+ if (alive.current && version === sequence.current) setError(message(e));
538
+ } finally {
539
+ if (alive.current && version === sequence.current) setLoading(false);
540
+ }
541
+ }, [client]);
542
+ useEffect(() => {
543
+ alive.current = true;
544
+ void refresh();
545
+ void client.nodes.list().then((result) => {
546
+ if (alive.current) setNodes(result);
547
+ }).catch(() => {
548
+ });
549
+ return () => {
550
+ alive.current = false;
551
+ sequence.current++;
552
+ };
553
+ }, [client, refresh]);
554
+ useEffect(() => {
555
+ let active = true;
556
+ setResuming(true);
557
+ void snapshotOperationStorageKey(client.cfg, deviceId).then((key) => {
558
+ if (!active) return;
559
+ storageKey.current = key;
560
+ const saved = readSnapshotOperation(key);
561
+ if (saved) setOperation({ ...saved, paused: false });
562
+ setResuming(false);
563
+ });
564
+ return () => {
565
+ active = false;
566
+ };
567
+ }, [client, deviceId]);
568
+ useEffect(() => {
569
+ if (!operation || operation.paused) return;
570
+ let active = true;
571
+ let timer;
572
+ const controller = new AbortController();
573
+ const poll = async () => {
574
+ try {
575
+ const result = await client.snapshots.operation(operation.id, { signal: controller.signal });
576
+ if (!active || !alive.current) return;
577
+ if (result.status === "ready") {
578
+ writeSnapshotOperation(storageKey.current, null);
579
+ setOperation(null);
580
+ setNotice(operation.action === "restore" ? t("portable.restored", { id: result.device_id ?? "" }) : t("portable.saved"));
581
+ setWarnings(result.warnings ?? []);
582
+ if (operation.action === "save") setLabel("");
583
+ onChanged?.();
584
+ void refresh();
585
+ } else if (result.status === "failed") {
586
+ writeSnapshotOperation(storageKey.current, null);
587
+ setOperation(null);
588
+ setError(result.error || t("portable.failed"));
589
+ void refresh();
590
+ } else {
591
+ timer = setTimeout(poll, 1500);
592
+ }
593
+ } catch (e) {
594
+ if (!active || !alive.current) return;
595
+ if (e instanceof AixError && [401, 403, 404].includes(e.status ?? 0)) {
596
+ writeSnapshotOperation(storageKey.current, null);
597
+ setOperation(null);
598
+ setError(message(e));
599
+ return;
600
+ }
601
+ setError(`${t("portable.unknown")} ${message(e)}`);
602
+ setOperation((current) => current ? { ...current, paused: true } : null);
603
+ }
604
+ };
605
+ void poll();
606
+ return () => {
607
+ active = false;
608
+ controller.abort();
609
+ if (timer) clearTimeout(timer);
610
+ };
611
+ }, [client, operation?.id, operation?.paused, pollVersion, refresh]);
612
+ const run = async (action) => {
613
+ if (submitting.current || operation || resuming) return;
614
+ submitting.current = true;
615
+ setMutating(true);
616
+ setError("");
617
+ setNotice("");
618
+ setWarnings([]);
619
+ try {
620
+ await action();
621
+ } catch (e) {
622
+ if (alive.current) setError(message(e));
623
+ } finally {
624
+ submitting.current = false;
625
+ if (alive.current) setMutating(false);
626
+ }
627
+ };
628
+ const start = async (action, request) => {
629
+ try {
630
+ const result = await request();
631
+ writeSnapshotOperation(storageKey.current, { id: result.operation_id, action });
632
+ if (!alive.current) return;
633
+ setPending(null);
634
+ setOperation({ id: result.operation_id, action, paused: false });
635
+ } catch (e) {
636
+ if (alive.current) setError(e instanceof AixError && e.status && e.status < 500 ? message(e) : `${t("portable.unknown")} ${message(e)}`);
637
+ }
638
+ };
639
+ const openGrants = (snapshot) => {
640
+ setSharing(snapshot);
641
+ setGrants([]);
642
+ setUserId("");
643
+ void run(async () => {
644
+ const result = await client.snapshots.grants(snapshot.id);
645
+ if (alive.current) setGrants(result.grants);
646
+ });
647
+ };
648
+ const share = (revoke) => void run(async () => {
649
+ if (!sharing) return;
650
+ if (revoke) await client.snapshots.revoke(sharing.id, revoke);
651
+ else await client.snapshots.grant(sharing.id, userId.trim());
652
+ const result = await client.snapshots.grants(sharing.id);
653
+ if (alive.current) {
654
+ setGrants(result.grants);
655
+ setUserId("");
656
+ }
657
+ });
658
+ return /* @__PURE__ */ jsxs("section", { className: "space-y-3 text-xs", "aria-label": t("portable.title"), "aria-busy": busy || loading, children: [
659
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
660
+ /* @__PURE__ */ jsx("h3", { className: "font-semibold", children: t("portable.title") }),
661
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: loading || mutating, onClick: () => {
662
+ setError("");
663
+ void refresh();
664
+ }, children: t("common.refresh") })
665
+ ] }),
666
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("portable.description") }),
667
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("portable.policy") }),
668
+ supported ? /* @__PURE__ */ jsxs("form", { className: "space-y-2", onSubmit: (event) => {
669
+ event.preventDefault();
670
+ if (online && label.trim()) void run(() => start("save", () => client.snapshots.create({ device_id: deviceId, label: label.trim(), kind })));
671
+ }, children: [
672
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
673
+ /* @__PURE__ */ jsx("span", { children: t("portable.label") }),
674
+ /* @__PURE__ */ jsx(Input, { value: label, maxLength: 120, disabled: busy || !online, onChange: (e) => setLabel(e.target.value) })
675
+ ] }),
676
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
677
+ /* @__PURE__ */ jsx("span", { children: t("portable.kind") }),
678
+ /* @__PURE__ */ jsxs("select", { className: "w-full rounded border border-input bg-background p-2", value: kind, disabled: busy || !online, onChange: (e) => setKind(e.target.value), children: [
679
+ /* @__PURE__ */ jsx("option", { value: "full", children: t("portable.full") }),
680
+ /* @__PURE__ */ jsx("option", { value: "template", children: t("portable.template") })
681
+ ] })
682
+ ] }),
683
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t(kind === "full" ? "portable.fullHint" : "portable.templateHint") }),
684
+ /* @__PURE__ */ jsx(Button, { type: "submit", size: "sm", disabled: busy || !online || !label.trim(), children: t("portable.save") }),
685
+ !online && /* @__PURE__ */ jsx("p", { children: t("portable.offline") })
686
+ ] }) : /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("portable.unsupported") }),
687
+ operation && /* @__PURE__ */ jsxs("div", { role: "status", className: "space-y-2", children: [
688
+ /* @__PURE__ */ jsx("p", { children: t("portable.working", { id: operation.id }) }),
689
+ operation.paused && /* @__PURE__ */ jsx(Button, { size: "sm", onClick: () => {
690
+ setError("");
691
+ setOperation({ ...operation, paused: false });
692
+ setPollVersion((v) => v + 1);
693
+ }, children: t("portable.check") })
694
+ ] }),
695
+ mutating && /* @__PURE__ */ jsx("p", { role: "status", children: t("common.loading") }),
696
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: error }),
697
+ notice && /* @__PURE__ */ jsx("p", { role: "status", children: notice }),
698
+ warnings.length > 0 && /* @__PURE__ */ jsx("div", { role: "alert", className: "space-y-1 text-warning", children: warnings.map((warning) => /* @__PURE__ */ jsx("p", { children: t(warningKeys[warning] ?? "portable.warning.other", { code: warning }) }, warning)) }),
699
+ loading && /* @__PURE__ */ jsx("p", { children: t("common.loading") }),
700
+ !loading && snapshots.length === 0 && /* @__PURE__ */ jsx("p", { children: t("portable.empty") }),
701
+ /* @__PURE__ */ jsx("ul", { className: "max-h-96 space-y-2 overflow-y-auto", "aria-label": t("portable.list"), children: snapshots.map((snapshot) => /* @__PURE__ */ jsxs("li", { className: "space-y-2 rounded border border-border p-3", children: [
702
+ /* @__PURE__ */ jsx("p", { className: "break-words font-medium", children: snapshot.label }),
703
+ /* @__PURE__ */ jsxs("p", { children: [
704
+ t(snapshot.kind === "full" ? "portable.full" : "portable.template"),
705
+ " \xB7 ",
706
+ t(snapshot.owned ? "portable.owned" : "portable.shared"),
707
+ " \xB7 ",
708
+ t(`portable.state.${snapshot.status}`)
709
+ ] }),
710
+ /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground", children: [
711
+ new Date(snapshot.created_at).toLocaleString(),
712
+ " \xB7 ",
713
+ snapshot.size_bytes == null ? "\u2014" : `${(snapshot.size_bytes / 1048576).toFixed(1)} MB`
714
+ ] }),
715
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
716
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled: busy || snapshot.status !== "ready", onClick: () => {
717
+ setNodeId("");
718
+ setPending({ action: "restore", snapshot });
719
+ }, children: t("portable.restore") }),
720
+ snapshot.owned && /* @__PURE__ */ jsxs(Fragment, { children: [
721
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: () => openGrants(snapshot), children: t("portable.share") }),
722
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy || snapshot.status === "pending" || snapshot.status === "running", onClick: () => setPending({ action: "delete", snapshot }), children: t("common.delete") })
723
+ ] })
724
+ ] })
725
+ ] }, snapshot.id)) }),
726
+ /* @__PURE__ */ jsx(Dialog, { open: pending?.action === "restore", onClose: () => {
727
+ if (!busy) setPending(null);
728
+ }, title: t("portable.restoreTitle"), description: t("portable.restoreHint"), children: /* @__PURE__ */ jsxs("div", { className: "space-y-3 text-xs", children: [
729
+ /* @__PURE__ */ jsx("p", { className: "break-words font-medium", children: pending?.snapshot.label }),
730
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
731
+ /* @__PURE__ */ jsx("span", { children: t("portable.node") }),
732
+ /* @__PURE__ */ jsxs("select", { className: "w-full rounded border border-input bg-background p-2", value: nodeId, disabled: busy, onChange: (e) => setNodeId(e.target.value), children: [
733
+ /* @__PURE__ */ jsx("option", { value: "", children: t("portable.autoNode") }),
734
+ nodes.filter((node) => node.status === "online" && node.reported_caps?.portable_snapshot_v2 === true).map((node) => /* @__PURE__ */ jsx("option", { value: node.id, children: node.name || node.id }, node.id))
735
+ ] })
736
+ ] }),
737
+ /* @__PURE__ */ jsx(Button, { disabled: busy, onClick: () => {
738
+ if (pending) void run(() => start("restore", () => client.snapshots.restore(pending.snapshot.id, nodeId ? { node_id: nodeId } : {})));
739
+ }, children: t("portable.restore") })
740
+ ] }) }),
741
+ /* @__PURE__ */ jsx(ConfirmDialog, { open: pending?.action === "delete", title: t("portable.deleteTitle"), description: t("portable.deleteHint"), destructive: true, busy, onClose: () => {
742
+ if (!busy) setPending(null);
743
+ }, onConfirm: () => void run(async () => {
744
+ if (!pending) return;
745
+ await client.snapshots.delete(pending.snapshot.id);
746
+ if (alive.current) {
747
+ setPending(null);
748
+ setNotice(t("portable.deleted"));
749
+ await refresh();
750
+ }
751
+ }) }),
752
+ /* @__PURE__ */ jsx(Dialog, { open: sharing !== null, onClose: () => {
753
+ if (!mutating) setSharing(null);
754
+ }, title: t("portable.shareTitle"), description: t("portable.shareHint"), children: /* @__PURE__ */ jsxs("div", { className: "space-y-3 text-xs", children: [
755
+ /* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
756
+ /* @__PURE__ */ jsx("span", { children: t("portable.user") }),
757
+ /* @__PURE__ */ jsx(Input, { value: userId, disabled: busy, onChange: (e) => setUserId(e.target.value) })
758
+ ] }),
759
+ /* @__PURE__ */ jsx(Button, { disabled: busy || !uuid.test(userId.trim()), onClick: () => share(), children: t("portable.grant") }),
760
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: error }),
761
+ /* @__PURE__ */ jsx("ul", { className: "max-h-64 space-y-2 overflow-auto", "aria-label": t("portable.grants"), children: grants.map((grant) => /* @__PURE__ */ jsxs("li", { className: "space-y-1", children: [
762
+ /* @__PURE__ */ jsx("p", { className: "break-all", children: grant.user_id }),
763
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: () => share(grant.user_id), children: t("portable.revoke") })
764
+ ] }, grant.user_id)) })
765
+ ] }) })
766
+ ] });
767
+ }
768
+
855
769
  // src/ui/devices/file-transfer.ts
856
770
  function triggerDownload(bytes, filename) {
857
771
  const blob = new Blob([bytes.slice().buffer]);
@@ -3126,6 +3040,7 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
3126
3040
  const [appSearching, setAppSearching] = useState(false);
3127
3041
  const [showReinstallPicker, setShowReinstallPicker] = useState(false);
3128
3042
  const [showDelete, setShowDelete] = useState(false);
3043
+ const [manualProxy, setManualProxy] = useState(false);
3129
3044
  const [proxyInput, setProxyInput] = useState("");
3130
3045
  const [proxySummary, setProxySummary] = useState("");
3131
3046
  const [proxyApply, setProxyApply] = useState(null);
@@ -3230,6 +3145,7 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
3230
3145
  setProxyProbeUnsupported(false);
3231
3146
  return;
3232
3147
  }
3148
+ setManualProxy(false);
3233
3149
  setTab("overview");
3234
3150
  const cur = devices.find((d) => d.id === deviceId);
3235
3151
  const storedLocation = cur?.meta?.location;
@@ -3380,7 +3296,7 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
3380
3296
  ["files", t("drawer.tab.files")],
3381
3297
  ["terminal", t("drawer.tab.terminal")],
3382
3298
  ["fingerprint", t("drawer.tab.fingerprint")],
3383
- ["snapshots", t("snapshots.title")]
3299
+ ["snapshots", t("portable.tab")]
3384
3300
  ].map(([key, label]) => /* @__PURE__ */ jsx(
3385
3301
  "button",
3386
3302
  {
@@ -3394,7 +3310,10 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
3394
3310
  device && deviceId && tab === "files" && /* @__PURE__ */ jsx(FileManager, { deviceId }),
3395
3311
  device && deviceId && tab === "terminal" && /* @__PURE__ */ jsx(DeviceTerminal, { deviceId }),
3396
3312
  device && deviceId && tab === "fingerprint" && /* @__PURE__ */ jsx(FingerprintPanel, { deviceId }),
3397
- device && deviceId && /* @__PURE__ */ jsx("div", { hidden: tab !== "snapshots", children: /* @__PURE__ */ jsx(DeviceSnapshotsPanel, { deviceId, online: device.online, supported: supportsDataSnapshots(device.meta), onChanged: () => void fetchDevices() }) }),
3313
+ device && deviceId && /* @__PURE__ */ jsxs("div", { hidden: tab !== "snapshots", className: "space-y-6", children: [
3314
+ /* @__PURE__ */ jsx(PortableSnapshotsPanel, { deviceId, online: device.online, supported: supportsDataSnapshots(device.meta), onChanged: () => void fetchDevices() }),
3315
+ /* @__PURE__ */ jsx("div", { className: "border-t border-border pt-4", children: /* @__PURE__ */ jsx(DeviceSnapshotsPanel, { deviceId, online: device.online, supported: supportsDataSnapshots(device.meta), onChanged: () => void fetchDevices() }) })
3316
+ ] }),
3398
3317
  tab === "overview" && device && /* @__PURE__ */ jsxs("section", { children: [
3399
3318
  /* @__PURE__ */ jsx("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: t("drawer.capability") }),
3400
3319
  /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-xs", children: [
@@ -3642,6 +3561,17 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
3642
3561
  tab === "overview" && device && deviceId && /* @__PURE__ */ jsxs("section", { children: [
3643
3562
  /* @__PURE__ */ jsx("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: t("drawer.proxy") }),
3644
3563
  /* @__PURE__ */ jsx(
3564
+ "button",
3565
+ {
3566
+ type: "button",
3567
+ className: "mb-2 py-2 text-xs text-primary hover:underline focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary",
3568
+ "aria-pressed": manualProxy,
3569
+ disabled: proxySaving,
3570
+ onClick: () => setManualProxy((value) => !value),
3571
+ children: t(manualProxy ? "proxy.chooseManaged" : "proxy.manualInput")
3572
+ }
3573
+ ),
3574
+ /* @__PURE__ */ jsx("div", { hidden: manualProxy, children: /* @__PURE__ */ jsx(
3645
3575
  ManagedProxyPanel,
3646
3576
  {
3647
3577
  deviceId,
@@ -3654,9 +3584,8 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
3654
3584
  void probeProxy(deviceId);
3655
3585
  }
3656
3586
  }
3657
- ),
3658
- /* @__PURE__ */ jsxs("details", { className: "mt-3 rounded border border-border p-3", children: [
3659
- /* @__PURE__ */ jsx("summary", { className: "cursor-pointer text-xs font-medium", children: t("managed.custom") }),
3587
+ ) }),
3588
+ manualProxy && /* @__PURE__ */ jsxs("div", { className: "mt-3 rounded border border-border p-3", role: "group", "aria-label": t("managed.custom"), children: [
3660
3589
  /* @__PURE__ */ jsx("p", { className: "my-2 text-xs text-muted-foreground", children: t("managed.customHint") }),
3661
3590
  /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mb-2", children: t("drawer.proxyDesc") }),
3662
3591
  proxySummary && /* @__PURE__ */ jsxs("p", { className: "mb-2 rounded border border-border/70 bg-secondary/40 px-2 py-1 text-[11px] text-muted-foreground", children: [
@@ -5767,9 +5696,9 @@ function DevicesPage({ taskAgentRunner: providedTaskAgentRunner } = {}) {
5767
5696
  /* @__PURE__ */ jsx(BulkInstallAppsDialog, { devices: bulkInstallDevices, onClose: () => setBulkInstallDevices(null) }),
5768
5697
  connectTargets && /* @__PURE__ */ jsx(ConnectDevicesDialog, { devices: connectTargets, onClose: () => setConnectTargets(null), onComplete: async (results) => {
5769
5698
  const failed = results.filter((result) => !result.ok).length;
5770
- const message = t("deviceConnect.summary", { ok: results.length - failed, failed });
5771
- if (failed) toast.error(message);
5772
- else toast.success(message);
5699
+ const message2 = t("deviceConnect.summary", { ok: results.length - failed, failed });
5700
+ if (failed) toast.error(message2);
5701
+ else toast.success(message2);
5773
5702
  await fetchDevices();
5774
5703
  await fetchNodes();
5775
5704
  } }),