@aixnn/aixautots 0.6.17 → 0.6.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/{automation-queue-DO8fOG6l.d.ts → automation-queue-GhfQtZLm.d.ts} +2 -2
  2. package/dist/{chunk-TJ2QIP5M.js → chunk-4NRIEM5Z.js} +249 -33
  3. package/dist/chunk-6IH74UX6.js +1693 -0
  4. package/dist/{chunk-WOPEKCVC.js → chunk-DAU3FVCV.js} +2 -2
  5. package/dist/chunk-DTXXQPOU.js +693 -0
  6. package/dist/{chunk-7BJPVSEZ.js → chunk-ED6CB3B4.js} +222 -12
  7. package/dist/{chunk-NIEGPH3E.js → chunk-FJKMRWYC.js} +55 -23
  8. package/dist/{chunk-ZDCTHR7D.js → chunk-H7KZUU67.js} +2 -2
  9. package/dist/{chunk-FJPIY4YI.js → chunk-HQ2L4NQ2.js} +262 -10
  10. package/dist/{chunk-LOKPZ677.js → chunk-JQBSGFAR.js} +2 -2
  11. package/dist/{chunk-2KPZSPV6.js → chunk-OJK35AQD.js} +105 -17
  12. package/dist/{chunk-KASSYUGM.js → chunk-RFOJSDYI.js} +2 -2
  13. package/dist/{chunk-QEK25NUA.js → chunk-UEZVXYGP.js} +12 -5
  14. package/dist/{config-CBUhr4Gl.d.ts → config-C79rcedl.d.ts} +52 -10
  15. package/dist/core/index.d.ts +13 -9
  16. package/dist/core/index.js +2 -2
  17. package/dist/core/network-adb-node.d.ts +23 -0
  18. package/dist/core/network-adb-node.js +171 -0
  19. package/dist/{script-debugger-DoT02din.d.ts → device-channel-OiZwAqNQ.d.ts} +41 -55
  20. package/dist/{device-normalize-Vl5JYbAI.d.ts → device-normalize-ODrxJb-a.d.ts} +1 -1
  21. package/dist/device-session-PVHD6PNR.js +1 -0
  22. package/dist/i18n/index.js +1 -1
  23. package/dist/{mirror-session-Y1InpkUY.d.ts → mirror-session-DifANocH.d.ts} +2 -2
  24. package/dist/react/index.d.ts +19 -12
  25. package/dist/react/index.js +3 -3
  26. package/dist/script-debugger-DjxpvdaN.d.ts +56 -0
  27. package/dist/{task-agent-runner-Cl2ickJ1.d.ts → task-agent-runner-CAt-z8gr.d.ts} +3 -3
  28. package/dist/{types-Cp1ohbTb.d.ts → types-CBI5SIH5.d.ts} +102 -4
  29. package/dist/ui/billing.d.ts +43 -6
  30. package/dist/ui/billing.js +190 -309
  31. package/dist/ui/device-create.d.ts +1 -1
  32. package/dist/ui/device-create.js +7 -7
  33. package/dist/ui/device-mirror.js +5 -5
  34. package/dist/ui/devices.d.ts +5 -5
  35. package/dist/ui/devices.js +9 -9
  36. package/dist/ui/editor.d.ts +2 -2
  37. package/dist/ui/editor.js +5 -5
  38. package/dist/ui/index.d.ts +6 -4
  39. package/dist/ui/index.js +13 -492
  40. package/dist/ui/inspector.js +4 -4
  41. package/dist/ui/ip-commerce.d.ts +2 -2
  42. package/dist/ui/ip-commerce.js +5 -5
  43. package/dist/ui/market.js +4 -4
  44. package/dist/ui/mirror.d.ts +3 -3
  45. package/dist/ui/script-studio.js +4 -4
  46. package/dist/ui/scripts.d.ts +1 -1
  47. package/dist/ui/scripts.js +4 -4
  48. package/dist/ui/settings.d.ts +164 -0
  49. package/dist/ui/settings.js +10 -0
  50. package/dist/ui/tasks.js +9 -9
  51. package/package.json +9 -1
  52. package/dist/device-session-3XK2SZDF.js +0 -1
@@ -1,18 +1,55 @@
1
1
  import * as react from 'react';
2
- import { g as Decimal, B as BalanceLedgerRow } from '../types-Cp1ohbTb.js';
2
+ import { b1 as StripeReconcileResult, O as Decimal, B as BalanceLedgerRow } from '../types-CBI5SIH5.js';
3
3
  import { LucideIcon } from 'lucide-react';
4
4
 
5
- declare function BillingPage(): react.JSX.Element;
5
+ interface BillingPageProps {
6
+ channel?: string;
7
+ returnUrl?: string;
8
+ cancelUrl?: string;
9
+ openExternalUrl?: (url: string) => void | Promise<void>;
10
+ onTopupCompleted?: (result: StripeReconcileResult) => void | Promise<void>;
11
+ }
12
+ declare function BillingPage({ channel, returnUrl, cancelUrl, openExternalUrl, onTopupCompleted, }?: BillingPageProps): react.JSX.Element;
6
13
 
7
14
  interface RechargeDrawerProps {
8
15
  open: boolean;
9
16
  onClose: () => void;
17
+ channel?: string;
18
+ returnUrl?: string;
19
+ cancelUrl?: string;
20
+ openExternalUrl?: (url: string) => void | Promise<void>;
21
+ onTopupCompleted?: (result: StripeReconcileResult) => void | Promise<void>;
10
22
  }
11
- declare function RechargeDrawer({ open, onClose }: RechargeDrawerProps): react.JSX.Element;
23
+ declare function RechargeDrawer({ open, onClose, channel, returnUrl, cancelUrl, openExternalUrl, onTopupCompleted, }: RechargeDrawerProps): react.JSX.Element;
12
24
 
13
- declare function RechargePage(): react.JSX.Element;
25
+ interface RechargePageProps {
26
+ channel?: string;
27
+ returnUrl?: string;
28
+ cancelUrl?: string;
29
+ openExternalUrl?: (url: string) => void | Promise<void>;
30
+ onTopupCompleted?: (result: StripeReconcileResult) => void | Promise<void>;
31
+ }
32
+ declare function RechargePage({ channel, returnUrl, cancelUrl, openExternalUrl, onTopupCompleted, }?: RechargePageProps): react.JSX.Element;
14
33
 
15
- declare function RechargeMethods(): react.JSX.Element;
34
+ interface RechargeMethodsProps {
35
+ refreshBalance: () => Promise<void>;
36
+ channel?: string;
37
+ returnUrl?: string;
38
+ cancelUrl?: string;
39
+ openExternalUrl?: (url: string) => void | Promise<void>;
40
+ onTopupCompleted?: (result: StripeReconcileResult) => void | Promise<void>;
41
+ }
42
+ declare function RechargeMethods({ refreshBalance, channel, returnUrl, cancelUrl, openExternalUrl, onTopupCompleted, }: RechargeMethodsProps): react.JSX.Element;
43
+
44
+ interface StripeTopupPanelProps {
45
+ refreshBalance: () => Promise<void>;
46
+ channel?: string;
47
+ returnUrl?: string;
48
+ cancelUrl?: string;
49
+ openExternalUrl?: (url: string) => void | Promise<void>;
50
+ onTopupCompleted?: (result: StripeReconcileResult) => void | Promise<void>;
51
+ }
52
+ declare function StripeTopupPanel({ refreshBalance, channel, returnUrl, cancelUrl, openExternalUrl, onTopupCompleted, }: StripeTopupPanelProps): react.JSX.Element;
16
53
 
17
54
  interface TopupDrawerProps {
18
55
  open: boolean;
@@ -45,4 +82,4 @@ interface LedgerKindMeta {
45
82
  */
46
83
  declare function ledgerKindMeta(kind: BalanceLedgerRow['kind'], amount?: number): LedgerKindMeta;
47
84
 
48
- export { BillingPage, type LedgerKindMeta, RechargeDrawer, type RechargeDrawerProps, RechargeMethods, RechargePage, TopupDrawer, type TopupDrawerProps, ledgerKindMeta };
85
+ export { BillingPage, type BillingPageProps, type LedgerKindMeta, RechargeDrawer, type RechargeDrawerProps, RechargeMethods, type RechargeMethodsProps, RechargePage, type RechargePageProps, StripeTopupPanel, type StripeTopupPanelProps, TopupDrawer, type TopupDrawerProps, ledgerKindMeta };
@@ -1,290 +1,22 @@
1
- import { useAixT } from '../chunk-FJPIY4YI.js';
2
- import { cn, Button, Badge, Input } from '../chunk-7RQTSTR6.js';
3
- import { useBilling, useClient } from '../chunk-QEK25NUA.js';
4
- import '../chunk-7BJPVSEZ.js';
5
- import '../chunk-2KPZSPV6.js';
1
+ import { RechargeMethods } from '../chunk-DTXXQPOU.js';
2
+ export { BillingPage, RechargeDrawer, RechargeMethods, StripeTopupPanel, ledgerKindMeta } from '../chunk-DTXXQPOU.js';
3
+ import { Button, cn, Input } from '../chunk-7RQTSTR6.js';
4
+ import { useAixT } from '../chunk-HQ2L4NQ2.js';
5
+ import { useBilling } from '../chunk-UEZVXYGP.js';
6
+ import '../chunk-ED6CB3B4.js';
7
+ import { normalizeTopupAmount, AixError } from '../chunk-OJK35AQD.js';
6
8
  import '../chunk-NWFYTFMI.js';
7
- import { useState, useEffect } from 'react';
8
- import { SlidersHorizontal, Globe, ArrowUpCircle, Server, CalendarClock, Smartphone, ArrowDownCircle, HeadphonesIcon, Wallet, X, RefreshCw } from 'lucide-react';
9
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
9
+ import { RefreshCw, Wallet, X } from 'lucide-react';
10
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
11
+ import { useRef, useState, useEffect } from 'react';
10
12
 
11
- var TABLE = {
12
- topup: { icon: ArrowUpCircle, i18nKey: "billing.kind.topup", sign: "credit" },
13
- platform_session: { icon: Smartphone, i18nKey: "billing.kind.platform_session", sign: "debit" },
14
- subscription: { icon: CalendarClock, i18nKey: "billing.kind.subscription", sign: "debit" },
15
- own_node_daily: { icon: Server, i18nKey: "billing.kind.own_node_daily", sign: "debit" },
16
- proxy_purchase: { icon: Globe, i18nKey: "billing.kind.proxy_purchase", sign: "debit" },
17
- proxy_refund: { icon: ArrowUpCircle, i18nKey: "billing.kind.proxy_refund", sign: "credit" },
18
- ip_hold: { icon: Globe, i18nKey: "billing.kind.ip_hold", sign: "debit" },
19
- ip_hold_release: { icon: ArrowUpCircle, i18nKey: "billing.kind.ip_hold_release", sign: "credit" },
20
- ip_purchase: { icon: Globe, i18nKey: "billing.kind.ip_purchase", sign: "debit" },
21
- ip_usage: { icon: Globe, i18nKey: "billing.kind.ip_usage", sign: "debit" },
22
- adjust: { icon: SlidersHorizontal, i18nKey: "billing.kind.adjust", sign: "debit" }
23
- };
24
- var FALLBACK = {
25
- icon: ArrowDownCircle,
26
- i18nKey: "billing.kind.adjust",
27
- sign: "debit"
28
- };
29
- function ledgerKindMeta(kind, amount) {
30
- const base = TABLE[kind] ?? FALLBACK;
31
- if (kind === "adjust" && amount !== void 0) {
32
- return { ...base, sign: amount >= 0 ? "credit" : "debit" };
33
- }
34
- return base;
35
- }
36
- function RechargeMethods() {
37
- const t = useAixT();
38
- const channels = [
39
- {
40
- key: "wechat",
41
- label: t("recharge.wechat"),
42
- icon: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", className: "h-5 w-5 fill-current", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.295.295a.326.326 0 0 0 .167-.054l1.903-1.114a.864.864 0 0 1 .717-.098 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 3.882-1.98 5.853-1.838-.576-3.583-3.898-6.348-7.601-6.348zM5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178 1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18zm5.34 2.867c-1.797-.052-3.746.512-5.28 1.786-1.72 1.428-2.687 3.72-1.78 6.22.942 2.453 3.666 4.229 6.884 4.229.826 0 1.622-.12 2.361-.336a.722.722 0 0 1 .598.082l1.584.926a.272.272 0 0 0 .14.047c.134 0 .24-.111.24-.247 0-.06-.023-.12-.038-.177l-.327-1.233a.582.582 0 0 1-.023-.156.49.49 0 0 1 .201-.398C23.024 18.48 24 16.82 24 14.98c0-3.21-2.931-5.837-7.063-6.122zm-3.494 3.096c.529 0 .957.44.957.983a.97.97 0 0 1-.957.981.97.97 0 0 1-.957-.981c0-.544.429-.983.957-.983zm4.976 0c.529 0 .957.44.957.983a.97.97 0 0 1-.957.981.97.97 0 0 1-.957-.981c0-.544.428-.983.957-.983z" }) }),
43
- color: "text-green-500",
44
- bg: "bg-green-500/10"
45
- },
46
- {
47
- key: "alipay",
48
- label: t("recharge.alipay"),
49
- icon: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", className: "h-5 w-5 fill-current", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M21.422 15.358c-3.83-1.153-6.055-1.84-6.055-1.84s1.485-3.37 1.822-5.51H13.5V6.85h4.5V5.768H13.5V3h-2.723v2.768H6.234v1.082h4.543v1.158H7.09v1.056h8.35c-.217 1.115-.672 2.514-1.207 3.528-1.983-.53-4.084-.946-5.873-.622-3.586.646-4.783 3.204-4.5 5.084.295 1.95 2.156 3.603 5.019 3.603 2.85 0 5.535-1.61 7.534-4.477 1.91.853 4.286 1.805 6.586 2.56L24 16.74c0-.001-.887-.864-2.578-1.382zm-12.27 2.936c-2.064 0-3.357-1.025-3.52-2.137-.186-1.25.814-2.477 2.658-2.797 1.016-.18 2.357.04 3.82.59-1.366 2.78-2.91 4.344-4.958 4.344z" }) }),
50
- color: "text-blue-500",
51
- bg: "bg-blue-500/10"
52
- }
53
- ];
54
- return /* @__PURE__ */ jsxs("section", { children: [
55
- /* @__PURE__ */ jsx("h3", { className: "mb-1 text-xs font-semibold text-foreground", children: t("recharge.methods") }),
56
- /* @__PURE__ */ jsx("p", { className: "mb-3 text-xs text-muted-foreground", children: t("recharge.desc") }),
57
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 sm:grid-cols-2", children: [
58
- channels.map((ch) => /* @__PURE__ */ jsxs(
59
- "div",
60
- {
61
- className: "flex cursor-default items-center gap-2.5 rounded-md border border-border px-3 py-2.5 transition-colors hover:bg-secondary/40",
62
- title: t("recharge.comingSoon"),
63
- children: [
64
- /* @__PURE__ */ jsx("span", { className: cn("flex h-8 w-8 shrink-0 items-center justify-center rounded-full", ch.bg, ch.color), children: ch.icon }),
65
- /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
66
- /* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-foreground", children: ch.label }),
67
- /* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: t("recharge.comingSoon") })
68
- ] })
69
- ]
70
- },
71
- ch.key
72
- )),
73
- /* @__PURE__ */ jsxs("div", { className: "flex cursor-default items-center gap-2.5 rounded-md border border-border px-3 py-2.5 transition-colors hover:bg-secondary/40", children: [
74
- /* @__PURE__ */ jsx("span", { className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-muted/40 text-muted-foreground", children: /* @__PURE__ */ jsx(HeadphonesIcon, { className: "h-4 w-4" }) }),
75
- /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
76
- /* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-foreground", children: t("recharge.contact") }),
77
- /* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: t("recharge.contactDesc") })
78
- ] })
79
- ] })
80
- ] })
81
- ] });
82
- }
83
- function RechargeDrawer({ open, onClose }) {
84
- const t = useAixT();
85
- const { data: balance, loading } = useBilling();
86
- return /* @__PURE__ */ jsxs(Fragment, { children: [
87
- /* @__PURE__ */ jsx(
88
- "div",
89
- {
90
- className: cn(
91
- "fixed inset-0 z-30 bg-black/40 transition-opacity duration-300",
92
- open ? "opacity-100" : "pointer-events-none opacity-0"
93
- ),
94
- onClick: onClose
95
- }
96
- ),
97
- /* @__PURE__ */ jsxs(
98
- "div",
99
- {
100
- className: cn(
101
- "fixed right-0 top-0 z-40 flex h-full w-full max-w-md flex-col border-l border-border bg-card transition-transform duration-300 ease-in-out",
102
- open ? "translate-x-0" : "translate-x-full"
103
- ),
104
- role: "dialog",
105
- "aria-label": t("recharge.title"),
106
- children: [
107
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border px-4 py-3", children: [
108
- /* @__PURE__ */ jsxs("h2", { className: "flex items-center gap-2 text-body-md font-semibold text-foreground", children: [
109
- /* @__PURE__ */ jsx(Wallet, { className: "h-4 w-4" }),
110
- t("recharge.title")
111
- ] }),
112
- /* @__PURE__ */ jsx(
113
- "button",
114
- {
115
- type: "button",
116
- "aria-label": t("common.close"),
117
- onClick: onClose,
118
- className: "rounded p-1 text-muted-foreground hover:bg-secondary hover:text-foreground",
119
- children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
120
- }
121
- )
122
- ] }),
123
- /* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-4 overflow-y-auto p-4", children: [
124
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-lg border border-border bg-card p-4", children: [
125
- /* @__PURE__ */ jsx("div", { className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary", children: /* @__PURE__ */ jsx(Wallet, { className: "h-5 w-5" }) }),
126
- /* @__PURE__ */ jsxs("div", { children: [
127
- /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("billing.balance") }),
128
- /* @__PURE__ */ jsx("p", { className: "text-lg font-semibold text-foreground", children: balance ? `${balance.balance} ${balance.currency}` : loading ? t("billing.loading") : "\u2014" })
129
- ] })
130
- ] }),
131
- /* @__PURE__ */ jsx(RechargeMethods, {})
132
- ] })
133
- ]
134
- }
135
- )
136
- ] });
137
- }
138
- function BillingPage() {
139
- const t = useAixT();
140
- const client = useClient();
141
- const { data: balance, loading, error, refetch: refresh } = useBilling();
142
- const [subs, setSubs] = useState([]);
143
- const [charges, setCharges] = useState([]);
144
- const [rechargeOpen, setRechargeOpen] = useState(false);
145
- useEffect(() => {
146
- let cancelled = false;
147
- (async () => {
148
- try {
149
- const [s, c] = await Promise.all([
150
- client.billing.subscriptions().catch(() => []),
151
- client.billing.ownNodeCharges().catch(() => [])
152
- ]);
153
- if (!cancelled) {
154
- setSubs(s);
155
- setCharges(c);
156
- }
157
- } catch {
158
- }
159
- })();
160
- return () => {
161
- cancelled = true;
162
- };
163
- }, [client]);
164
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col", children: [
165
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border px-3 py-2 sm:px-6", children: [
166
- /* @__PURE__ */ jsx("h1", { className: "text-body-md font-semibold text-foreground", children: t("billing.title") }),
167
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
168
- /* @__PURE__ */ jsxs(Button, { variant: "secondary", size: "sm", onClick: () => void refresh(), disabled: loading, children: [
169
- /* @__PURE__ */ jsx(RefreshCw, { className: cn("h-3.5 w-3.5", loading && "animate-spin") }),
170
- t("billing.refresh")
171
- ] }),
172
- /* @__PURE__ */ jsxs(Button, { variant: "primary", size: "sm", onClick: () => setRechargeOpen(true), children: [
173
- /* @__PURE__ */ jsx(Wallet, { className: "h-3.5 w-3.5" }),
174
- t("recharge.title")
175
- ] })
176
- ] })
177
- ] }),
178
- /* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-4 overflow-auto p-3 sm:p-6", children: [
179
- error && /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: error.message }),
180
- /* @__PURE__ */ jsx(LedgerSection, { rows: balance?.recent ?? [], loading, t }),
181
- /* @__PURE__ */ jsx(SubsSection, { subs, t }),
182
- /* @__PURE__ */ jsx(OwnNodeSection, { charges, t })
183
- ] }),
184
- /* @__PURE__ */ jsx(RechargeDrawer, { open: rechargeOpen, onClose: () => setRechargeOpen(false) })
185
- ] });
186
- }
187
- function LedgerSection({ rows, loading, t }) {
188
- return /* @__PURE__ */ jsxs("section", { className: "rounded-lg border border-border bg-card p-3 sm:p-4", children: [
189
- /* @__PURE__ */ jsx("h2", { className: "mb-2 text-xs font-semibold text-foreground", children: t("billing.ledger") }),
190
- rows.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-6 text-center text-xs text-muted-foreground", children: loading ? t("common.loading") : t("billing.ledger.empty") }) : /* @__PURE__ */ jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-xs", children: [
191
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b border-border text-left text-muted-foreground", children: [
192
- /* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 font-medium", children: t("billing.col.kind") }),
193
- /* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 text-right font-medium", children: t("billing.col.amount") }),
194
- /* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 text-right font-medium", children: t("billing.col.balanceAfter") }),
195
- /* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 font-medium", children: t("billing.col.ref") }),
196
- /* @__PURE__ */ jsx("th", { className: "py-1.5 font-medium", children: t("billing.col.time") })
197
- ] }) }),
198
- /* @__PURE__ */ jsx("tbody", { children: rows.map((r) => {
199
- const meta = ledgerKindMeta(r.kind, Number(r.amount));
200
- const Icon = meta.icon;
201
- const credit = meta.sign === "credit";
202
- return /* @__PURE__ */ jsxs("tr", { className: "border-b border-border/50", children: [
203
- /* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2", children: /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5 text-foreground", children: [
204
- /* @__PURE__ */ jsx(
205
- Icon,
206
- {
207
- className: cn("h-3.5 w-3.5", credit ? "text-green-500" : "text-muted-foreground")
208
- }
209
- ),
210
- t(meta.i18nKey)
211
- ] }) }),
212
- /* @__PURE__ */ jsxs(
213
- "td",
214
- {
215
- className: cn(
216
- "py-1.5 pr-2 text-right font-mono",
217
- credit ? "text-green-500" : "text-destructive"
218
- ),
219
- children: [
220
- credit ? "+" : "-",
221
- String(r.amount).replace(/^[-+]/, "")
222
- ]
223
- }
224
- ),
225
- /* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2 text-right font-mono text-muted-foreground", children: String(r.balance_after) }),
226
- /* @__PURE__ */ jsx("td", { className: "max-w-[12rem] truncate py-1.5 pr-2 text-muted-foreground", title: r.ref, children: r.ref }),
227
- /* @__PURE__ */ jsx("td", { className: "py-1.5 text-muted-foreground", children: new Date(r.created_at).toLocaleString() })
228
- ] }, r.id);
229
- }) })
230
- ] }) })
231
- ] });
232
- }
233
- function SubsSection({ subs, t }) {
234
- return /* @__PURE__ */ jsxs("section", { className: "rounded-lg border border-border bg-card p-3 sm:p-4", children: [
235
- /* @__PURE__ */ jsx("h2", { className: "mb-2 text-xs font-semibold text-foreground", children: t("billing.subs") }),
236
- subs.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-4 text-center text-xs text-muted-foreground", children: t("billing.subs.empty") }) : /* @__PURE__ */ jsx("div", { className: "space-y-1.5", children: subs.map((s) => /* @__PURE__ */ jsxs(
237
- "div",
238
- {
239
- className: "flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md border border-border/60 px-2.5 py-1.5 text-xs",
240
- children: [
241
- /* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: s.tier }),
242
- /* @__PURE__ */ jsx(Badge, { variant: s.status === "active" ? "success" : "muted", children: s.status }),
243
- s.remaining_hours != null && /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
244
- t("billing.subs.remaining"),
245
- ": ",
246
- String(s.remaining_hours)
247
- ] }),
248
- /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
249
- t("billing.subs.expires"),
250
- ": ",
251
- new Date(s.expires_at).toLocaleDateString()
252
- ] }),
253
- s.bound_device_id && /* @__PURE__ */ jsxs("span", { className: "truncate font-mono text-muted-foreground", title: s.bound_device_id, children: [
254
- t("billing.subs.boundDevice"),
255
- ": ",
256
- s.bound_device_id.slice(0, 8)
257
- ] })
258
- ]
259
- },
260
- s.id
261
- )) })
262
- ] });
263
- }
264
- function OwnNodeSection({ charges, t }) {
265
- return /* @__PURE__ */ jsxs("section", { className: "rounded-lg border border-border bg-card p-3 sm:p-4", children: [
266
- /* @__PURE__ */ jsx("h2", { className: "mb-2 text-xs font-semibold text-foreground", children: t("billing.ownNode") }),
267
- charges.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-4 text-center text-xs text-muted-foreground", children: t("billing.ownNode.empty") }) : /* @__PURE__ */ jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-xs", children: [
268
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b border-border text-left text-muted-foreground", children: [
269
- /* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 font-medium", children: t("billing.ownNode.day") }),
270
- /* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 text-right font-medium", children: t("billing.ownNode.devices") }),
271
- /* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 text-right font-medium", children: t("billing.ownNode.billable") }),
272
- /* @__PURE__ */ jsx("th", { className: "py-1.5 text-right font-medium", children: t("billing.ownNode.amount") })
273
- ] }) }),
274
- /* @__PURE__ */ jsx("tbody", { children: charges.map((c) => /* @__PURE__ */ jsxs("tr", { className: "border-b border-border/50", children: [
275
- /* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2 text-foreground", children: c.day }),
276
- /* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2 text-right text-muted-foreground", children: c.device_count }),
277
- /* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2 text-right text-muted-foreground", children: c.billable }),
278
- /* @__PURE__ */ jsxs("td", { className: "py-1.5 text-right font-mono text-foreground", children: [
279
- String(c.amount),
280
- " ",
281
- c.currency
282
- ] })
283
- ] }, c.id)) })
284
- ] }) })
285
- ] });
286
- }
287
- function RechargePage() {
13
+ function RechargePage({
14
+ channel,
15
+ returnUrl,
16
+ cancelUrl,
17
+ openExternalUrl,
18
+ onTopupCompleted
19
+ } = {}) {
288
20
  const t = useAixT();
289
21
  const { data: balance, loading, error, refetch: refresh } = useBilling();
290
22
  return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col", children: [
@@ -310,39 +42,165 @@ function RechargePage() {
310
42
  " \u2193"
311
43
  ] })
312
44
  ] }),
313
- /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-border bg-card p-3 sm:p-4", children: /* @__PURE__ */ jsx(RechargeMethods, {}) })
45
+ /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-border bg-card p-3 sm:p-4", children: /* @__PURE__ */ jsx(
46
+ RechargeMethods,
47
+ {
48
+ refreshBalance: refresh,
49
+ channel,
50
+ returnUrl,
51
+ cancelUrl,
52
+ openExternalUrl,
53
+ onTopupCompleted
54
+ }
55
+ ) })
314
56
  ] })
315
57
  ] });
316
58
  }
317
59
  function TopupDrawer({ open, onClose, ownerUserId, ownerLabel, onDone }) {
318
60
  const t = useAixT();
319
- const { topup } = useBilling();
61
+ const translate = useRef(t);
62
+ translate.current = t;
63
+ const { topup, lookupTopup } = useBilling();
320
64
  const [amount, setAmount] = useState("");
321
65
  const [note, setNote] = useState("");
322
66
  const [submitting, setSubmitting] = useState(false);
323
67
  const [error, setError] = useState(null);
324
68
  const [result, setResult] = useState(null);
325
- const numeric = Number(amount);
326
- const canSubmit = !submitting && Number.isFinite(numeric) && numeric > 0;
69
+ const numeric = normalizeTopupAmount(amount);
70
+ const key = JSON.stringify([ownerUserId, numeric, note.trim()]);
71
+ const intent = useRef(null);
72
+ const previousOwner = useRef(ownerUserId);
73
+ const busy = useRef(null);
74
+ const [completed, setCompleted] = useState(null);
75
+ const [actor, setActor] = useState(null);
76
+ const activeScope = useRef({ actor: null, owner: ownerUserId });
77
+ activeScope.current = { actor, owner: ownerUserId };
78
+ const lastActor = useRef(null);
79
+ const [ready, setReady] = useState(false);
80
+ const pending = useRef(null);
81
+ const storageKey = (id) => `aixautots:manual-topup:${id}:${ownerUserId}`;
82
+ const noteInvalid = [...note.trim()].length > 500 || note.includes("\0");
83
+ const canSubmit = open && ready && actor !== null && !submitting && numeric !== null && !noteInvalid && completed !== key;
84
+ useEffect(() => {
85
+ if (previousOwner.current === ownerUserId) return;
86
+ previousOwner.current = ownerUserId;
87
+ intent.current = null;
88
+ pending.current = null;
89
+ setReady(false);
90
+ setActor(null);
91
+ setSubmitting(false);
92
+ setAmount("");
93
+ setNote("");
94
+ setError(null);
95
+ setResult(null);
96
+ setCompleted(null);
97
+ }, [ownerUserId]);
98
+ useEffect(() => {
99
+ if (!open) return;
100
+ let cancelled = false;
101
+ setReady(false);
102
+ setActor(null);
103
+ setError(null);
104
+ const load = async () => {
105
+ try {
106
+ const identity = await lookupTopup();
107
+ if (cancelled) return;
108
+ if (lastActor.current !== null && lastActor.current !== identity.developer_id) {
109
+ pending.current = null;
110
+ intent.current = null;
111
+ setAmount("");
112
+ setNote("");
113
+ setResult(null);
114
+ setCompleted(null);
115
+ setError(null);
116
+ }
117
+ lastActor.current = identity.developer_id;
118
+ const saved = sessionStorage.getItem(storageKey(identity.developer_id));
119
+ const value = saved ? JSON.parse(saved) : null;
120
+ if (value && value.developer_id === identity.developer_id && value.owner_user_id === ownerUserId && typeof value.request_id === "string" && typeof value.amount === "string") {
121
+ pending.current = value;
122
+ setAmount(value.amount);
123
+ setNote(value.note ?? "");
124
+ const lookup = await lookupTopup(value.request_id);
125
+ if (cancelled) return;
126
+ if (lookup.developer_id !== identity.developer_id) throw new Error("administrator changed");
127
+ if (lookup.receipt?.request_id === value.request_id) {
128
+ if (lookup.receipt.developer_id !== identity.developer_id || lookup.receipt.owner_user_id !== ownerUserId || normalizeTopupAmount(String(lookup.receipt.amount)) !== normalizeTopupAmount(value.amount) || (lookup.receipt.note ?? "") !== (value.note ?? "") || lookup.receipt.currency !== "USD") {
129
+ throw new Error("top-up receipt mismatch");
130
+ }
131
+ sessionStorage.removeItem(storageKey(identity.developer_id));
132
+ pending.current = null;
133
+ setResult(lookup.receipt.balance_after);
134
+ setCompleted(JSON.stringify([ownerUserId, normalizeTopupAmount(value.amount), (value.note ?? "").trim()]));
135
+ }
136
+ } else if (saved) {
137
+ throw new Error("stored top-up request is invalid");
138
+ } else pending.current = null;
139
+ setActor(identity.developer_id);
140
+ setReady(true);
141
+ } catch (err) {
142
+ if (!cancelled) setError(translate.current("topup.failed", { err: String(err) }));
143
+ }
144
+ };
145
+ void load();
146
+ return () => {
147
+ cancelled = true;
148
+ };
149
+ }, [open, ownerUserId, lookupTopup]);
150
+ useEffect(() => {
151
+ if (!open && completed !== null) {
152
+ intent.current = null;
153
+ setCompleted(null);
154
+ setResult(null);
155
+ setAmount("");
156
+ setNote("");
157
+ }
158
+ }, [open, completed]);
327
159
  const submit = async () => {
328
- if (!Number.isFinite(numeric) || numeric <= 0) {
329
- setError(t("topup.amountInvalid"));
160
+ if (!open || !ready || !actor || busy.current === `${actor}:${ownerUserId}` || completed === key) return;
161
+ if (numeric === null || noteInvalid) {
162
+ setError(t(numeric === null ? "topup.amountInvalid" : "topup.noteInvalid"));
330
163
  return;
331
164
  }
332
165
  setError(null);
166
+ const busyScope = `${actor}:${ownerUserId}`;
167
+ busy.current = busyScope;
333
168
  setSubmitting(true);
169
+ let requestId = null;
170
+ const firstAttempt = pending.current === null;
334
171
  try {
335
- const res = await topup({
336
- owner_user_id: ownerUserId,
337
- amount: numeric,
338
- note: note.trim() || void 0
339
- });
172
+ if (!pending.current) {
173
+ if (intent.current?.key !== key) intent.current = { key, id: crypto.randomUUID() };
174
+ const created = { request_id: intent.current.id, owner_user_id: ownerUserId, developer_id: actor, amount: numeric, note: note.trim() || void 0 };
175
+ sessionStorage.setItem(storageKey(actor), JSON.stringify(created));
176
+ pending.current = created;
177
+ }
178
+ const request = pending.current;
179
+ requestId = request.request_id;
180
+ const res = await topup(request);
181
+ if (res.request_id !== request.request_id || res.owner_user_id !== request.owner_user_id) throw new Error("top-up receipt mismatch");
182
+ if (activeScope.current.owner !== request.owner_user_id || activeScope.current.actor !== request.developer_id) return;
183
+ if (pending.current?.request_id !== request.request_id) return;
184
+ sessionStorage.removeItem(storageKey(actor));
185
+ pending.current = null;
186
+ setCompleted(key);
340
187
  setResult(res.new_balance);
341
188
  onDone?.(res.new_balance);
342
189
  } catch (err) {
343
- setError(t("topup.failed", { err: String(err) }));
190
+ if (activeScope.current.owner !== ownerUserId || activeScope.current.actor !== actor) return;
191
+ if (firstAttempt && err instanceof AixError && [400, 403, 404, 405, 422].includes(err.status ?? 0)) {
192
+ if (requestId && pending.current?.request_id === requestId) {
193
+ sessionStorage.removeItem(storageKey(actor));
194
+ pending.current = null;
195
+ intent.current = null;
196
+ }
197
+ }
198
+ setError(err instanceof AixError && err.status === 409 ? t("topup.conflict") : t("topup.failed", { err: String(err) }));
344
199
  } finally {
345
- setSubmitting(false);
200
+ if (busy.current === busyScope) {
201
+ busy.current = null;
202
+ setSubmitting(false);
203
+ }
346
204
  }
347
205
  };
348
206
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -386,31 +244,54 @@ function TopupDrawer({ open, onClose, ownerUserId, ownerLabel, onDone }) {
386
244
  /* @__PURE__ */ jsx("div", { className: "rounded-md border border-border bg-secondary/40 px-2.5 py-1.5 text-xs text-foreground", children: ownerLabel || ownerUserId })
387
245
  ] }),
388
246
  /* @__PURE__ */ jsxs("div", { children: [
389
- /* @__PURE__ */ jsx("label", { className: "mb-1 block text-xs font-medium", children: t("topup.amount") }),
247
+ /* @__PURE__ */ jsxs("label", { htmlFor: "topup-amount", className: "mb-1 block text-xs font-medium", children: [
248
+ t("topup.amount"),
249
+ " (USD)"
250
+ ] }),
390
251
  /* @__PURE__ */ jsx(
391
252
  Input,
392
253
  {
393
- type: "number",
394
- min: 0,
395
- value: amount,
254
+ id: "topup-amount",
255
+ "aria-invalid": amount !== "" && numeric === null,
256
+ type: "text",
257
+ inputMode: "decimal",
258
+ disabled: submitting || !ready || pending.current !== null,
259
+ value: ready ? amount : "",
396
260
  placeholder: t("topup.amountPlaceholder"),
397
- onChange: (e) => setAmount(e.target.value)
261
+ onChange: (e) => {
262
+ intent.current = null;
263
+ setCompleted(null);
264
+ setResult(null);
265
+ setError(null);
266
+ setAmount(e.target.value);
267
+ }
398
268
  }
399
269
  )
400
270
  ] }),
401
271
  /* @__PURE__ */ jsxs("div", { children: [
402
- /* @__PURE__ */ jsx("label", { className: "mb-1 block text-xs font-medium", children: t("topup.note") }),
272
+ /* @__PURE__ */ jsx("label", { htmlFor: "topup-note", className: "mb-1 block text-xs font-medium", children: t("topup.note") }),
403
273
  /* @__PURE__ */ jsx(
404
274
  Input,
405
275
  {
406
- value: note,
276
+ id: "topup-note",
277
+ "aria-invalid": noteInvalid,
278
+ disabled: submitting || !ready || pending.current !== null,
279
+ value: ready ? note : "",
407
280
  placeholder: t("topup.notePlaceholder"),
408
- onChange: (e) => setNote(e.target.value)
281
+ onChange: (e) => {
282
+ intent.current = null;
283
+ setCompleted(null);
284
+ setResult(null);
285
+ setError(null);
286
+ setNote(e.target.value);
287
+ }
409
288
  }
410
289
  )
411
290
  ] }),
412
- result != null && /* @__PURE__ */ jsx("p", { className: "text-xs text-green-500", children: t("topup.done", { balance: String(result) }) }),
413
- error && /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: error })
291
+ amount && numeric === null && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-xs text-destructive", children: t("topup.amountInvalid") }),
292
+ noteInvalid && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-xs text-destructive", children: t("topup.noteInvalid") }),
293
+ ready && completed === key && result != null && /* @__PURE__ */ jsx("p", { className: "text-xs text-green-500", children: t("topup.done", { balance: String(result) }) }),
294
+ error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-xs text-destructive", children: error })
414
295
  ] }),
415
296
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2 border-t border-border p-4", children: [
416
297
  /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", onClick: onClose, children: t("common.cancel") }),
@@ -425,4 +306,4 @@ function TopupDrawer({ open, onClose, ownerUserId, ownerLabel, onDone }) {
425
306
  ] });
426
307
  }
427
308
 
428
- export { BillingPage, RechargeDrawer, RechargeMethods, RechargePage, TopupDrawer, ledgerKindMeta };
309
+ export { RechargePage, TopupDrawer };
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { a as ProvisionResult, P as ProvisionSpec, b as DiscoveredDevice } from '../types-Cp1ohbTb.js';
3
+ import { a as ProvisionResult, P as ProvisionSpec, b as DiscoveredDevice } from '../types-CBI5SIH5.js';
4
4
 
5
5
  interface DeviceCreateProps {
6
6
  open: boolean;
@@ -1,10 +1,10 @@
1
- export { AddWirelessDeviceDialog, DeviceCreate, NodePicker, ProxySpoofStep, RealDiscoverStep, VirtualSpecStep } from '../chunk-NIEGPH3E.js';
2
- import '../chunk-KASSYUGM.js';
3
- import '../chunk-LOKPZ677.js';
1
+ export { AddWirelessDeviceDialog, DeviceCreate, NodePicker, ProxySpoofStep, RealDiscoverStep, VirtualSpecStep } from '../chunk-FJKMRWYC.js';
2
+ import '../chunk-JQBSGFAR.js';
3
+ import '../chunk-RFOJSDYI.js';
4
4
  import '../chunk-ZB5ET67B.js';
5
- import '../chunk-FJPIY4YI.js';
6
5
  import '../chunk-7RQTSTR6.js';
7
- import '../chunk-QEK25NUA.js';
8
- import '../chunk-7BJPVSEZ.js';
9
- import '../chunk-2KPZSPV6.js';
6
+ import '../chunk-HQ2L4NQ2.js';
7
+ import '../chunk-UEZVXYGP.js';
8
+ import '../chunk-ED6CB3B4.js';
9
+ import '../chunk-OJK35AQD.js';
10
10
  import '../chunk-NWFYTFMI.js';