@aixnn/aixautots 0.6.13 → 0.6.20

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 (55) hide show
  1. package/dist/{automation-queue-BFWqw32O.d.ts → automation-queue-GhfQtZLm.d.ts} +2 -2
  2. package/dist/{chunk-S5N4EOCP.js → chunk-3OBCSW2J.js} +1 -1
  3. package/dist/{chunk-SKI7TINK.js → chunk-4NRIEM5Z.js} +269 -53
  4. package/dist/{chunk-VMA3QOYR.js → chunk-7RQTSTR6.js} +1 -1
  5. package/dist/{chunk-HMDUSVQ3.js → chunk-DAU3FVCV.js} +4 -4
  6. package/dist/chunk-DTXXQPOU.js +693 -0
  7. package/dist/{chunk-7BJPVSEZ.js → chunk-ED6CB3B4.js} +222 -12
  8. package/dist/{chunk-Q5I63UYT.js → chunk-FJKMRWYC.js} +97 -75
  9. package/dist/{chunk-U4QW45MB.js → chunk-H7KZUU67.js} +14 -7
  10. package/dist/{chunk-QRIWTPN3.js → chunk-HQ2L4NQ2.js} +270 -12
  11. package/dist/{chunk-QFGMQLRB.js → chunk-JQBSGFAR.js} +31 -14
  12. package/dist/{chunk-2KPZSPV6.js → chunk-OJK35AQD.js} +105 -17
  13. package/dist/chunk-QISBQ532.js +1665 -0
  14. package/dist/{chunk-T6X6TWHK.js → chunk-RFOJSDYI.js} +3 -3
  15. package/dist/{chunk-QEK25NUA.js → chunk-UEZVXYGP.js} +12 -5
  16. package/dist/{config-UmU2_q5M.d.ts → config-C79rcedl.d.ts} +53 -11
  17. package/dist/core/index.d.ts +13 -9
  18. package/dist/core/index.js +2 -2
  19. package/dist/core/network-adb-node.d.ts +23 -0
  20. package/dist/core/network-adb-node.js +171 -0
  21. package/dist/{script-debugger-F5UGUq5t.d.ts → device-channel-OiZwAqNQ.d.ts} +41 -55
  22. package/dist/{device-normalize-CWJFr_sf.d.ts → device-normalize-ODrxJb-a.d.ts} +1 -1
  23. package/dist/device-session-PVHD6PNR.js +1 -0
  24. package/dist/i18n/index.js +1 -1
  25. package/dist/{mirror-session-Cy20lIHP.d.ts → mirror-session-DifANocH.d.ts} +2 -2
  26. package/dist/react/index.d.ts +19 -12
  27. package/dist/react/index.js +3 -3
  28. package/dist/script-debugger-DjxpvdaN.d.ts +56 -0
  29. package/dist/{task-agent-runner-Cj_u-3DS.d.ts → task-agent-runner-CAt-z8gr.d.ts} +3 -3
  30. package/dist/{types-BvrppNIZ.d.ts → types-CBI5SIH5.d.ts} +103 -5
  31. package/dist/ui/billing.d.ts +43 -6
  32. package/dist/ui/billing.js +190 -309
  33. package/dist/ui/device-create.d.ts +5 -2
  34. package/dist/ui/device-create.js +8 -8
  35. package/dist/ui/device-mirror.js +6 -6
  36. package/dist/ui/devices.d.ts +5 -5
  37. package/dist/ui/devices.js +11 -11
  38. package/dist/ui/editor.d.ts +2 -2
  39. package/dist/ui/editor.js +7 -7
  40. package/dist/ui/index.d.ts +6 -4
  41. package/dist/ui/index.js +13 -492
  42. package/dist/ui/inspector.js +5 -5
  43. package/dist/ui/ip-commerce.d.ts +4 -2
  44. package/dist/ui/ip-commerce.js +6 -6
  45. package/dist/ui/market.js +4 -4
  46. package/dist/ui/mirror.d.ts +3 -3
  47. package/dist/ui/primitives/index.js +1 -1
  48. package/dist/ui/script-studio.js +6 -6
  49. package/dist/ui/scripts.d.ts +1 -1
  50. package/dist/ui/scripts.js +5 -5
  51. package/dist/ui/settings.d.ts +164 -0
  52. package/dist/ui/settings.js +10 -0
  53. package/dist/ui/tasks.js +11 -11
  54. package/package.json +9 -1
  55. package/dist/device-session-3XK2SZDF.js +0 -1
@@ -1,4 +1,4 @@
1
- import { joinUrl, AixAuthError, AixLocked, AixError, resolveConfig, ReconnectingSocket, AixTimeout, parseIncoming, isRetFrame, errorFromRet, isFridaEventFrame, isScriptletEventFrame, isStatusFrame, executionWsTicketUrl, isExecutionFrame, getIceServers, mintViewerToken, mintViewerGrant, validateViewerGrant, validUuid, executionStreamEventsAfter } from './chunk-2KPZSPV6.js';
1
+ import { joinUrl, AixAuthError, AixLocked, AixError, resolveConfig, ReconnectingSocket, AixTimeout, AixProtocolError, parseIncoming, isRetFrame, errorFromRet, isStatusFrame, isFridaEventFrame, isScriptletEventFrame, executionWsTicketUrl, isExecutionFrame, mintViewerToken, getIceServers, mintViewerGrant, validateViewerGrant, validUuid, executionStreamEventsAfter } from './chunk-OJK35AQD.js';
2
2
 
3
3
  // src/core/ws-access.ts
4
4
  async function mintDeviceAccess(cfg, deviceId) {
@@ -40,22 +40,85 @@ function fallbackUuid() {
40
40
  });
41
41
  }
42
42
  var DeviceTunnel = class {
43
- constructor(streamId, sink) {
43
+ constructor(streamId, sink, canSend = () => true) {
44
44
  this.streamId = streamId;
45
45
  this.sink = sink;
46
+ this.canSend = canSend;
46
47
  this.dataListeners = /* @__PURE__ */ new Set();
48
+ this.closeListeners = /* @__PURE__ */ new Set();
49
+ this.closed = false;
50
+ this.opened = false;
51
+ this.readyPromise = new Promise((resolve, reject) => {
52
+ this.readyResolve = resolve;
53
+ this.readyReject = reject;
54
+ });
55
+ void this.readyPromise.catch(() => {
56
+ });
57
+ }
58
+ /** Resolves only when the server confirms this stream opened, never on permission grant. */
59
+ waitReady(timeoutMs = 1e4) {
60
+ if (!this.opened && !this.closed && !this.readyTimer) {
61
+ this.readyTimer = setTimeout(() => {
62
+ this._end("ADB stream open timed out");
63
+ try {
64
+ this.sink({ t: "close", stream: this.streamId });
65
+ } catch {
66
+ }
67
+ }, timeoutMs);
68
+ }
69
+ return this.readyPromise;
47
70
  }
48
71
  send(bytes) {
49
- this.sink({ t: "data", stream: this.streamId, b64: bytesToB64(bytes) });
72
+ if (this.closed || !this.canSend()) throw new AixError("stream closed or no longer granted", "auth");
73
+ try {
74
+ this.sink({ t: "data", stream: this.streamId, b64: bytesToB64(bytes) });
75
+ } catch (e) {
76
+ try {
77
+ this.close();
78
+ } catch {
79
+ }
80
+ throw e;
81
+ }
50
82
  }
51
83
  onData(cb) {
52
84
  this.dataListeners.add(cb);
53
85
  return () => this.dataListeners.delete(cb);
54
86
  }
87
+ onClose(cb) {
88
+ this.closeListeners.add(cb);
89
+ return () => this.closeListeners.delete(cb);
90
+ }
91
+ _opened() {
92
+ if (!this.closed) {
93
+ this.opened = true;
94
+ this._clearTimer();
95
+ this.readyResolve?.();
96
+ }
97
+ }
55
98
  _deliver(b) {
56
- for (const cb of this.dataListeners) cb(b);
99
+ if (!this.closed) for (const cb of this.dataListeners) cb(b);
100
+ }
101
+ _end(reason) {
102
+ if (this.closed) return;
103
+ this.closed = true;
104
+ this._clearTimer();
105
+ if (!this.opened) this.readyReject?.(new AixError(reason ?? "stream closed", "offline"));
106
+ for (const cb of this.closeListeners) {
107
+ try {
108
+ cb(reason);
109
+ } catch {
110
+ }
111
+ }
112
+ this.dataListeners.clear();
113
+ this.closeListeners.clear();
114
+ }
115
+ _clearTimer() {
116
+ if (this.readyTimer) clearTimeout(this.readyTimer);
117
+ this.readyTimer = void 0;
57
118
  }
58
119
  close() {
120
+ if (this.closed) return;
121
+ this._end("stream closed");
59
122
  this.sink({ t: "close", stream: this.streamId });
60
123
  }
61
124
  };
@@ -71,21 +134,49 @@ var DeviceChannel = class _DeviceChannel {
71
134
  this.scriptletListeners = /* @__PURE__ */ new Set();
72
135
  this.statusListeners = /* @__PURE__ */ new Set();
73
136
  this.tunnels = /* @__PURE__ */ new Map();
137
+ this.networkAdbEnabled = false;
138
+ this.networkAdbListeners = /* @__PURE__ */ new Set();
139
+ this.networkAdbStreams = /* @__PURE__ */ new Set();
140
+ this.networkAdbGeneration = 0;
141
+ this.networkAdbOperation = Promise.resolve();
142
+ this.networkAdbIntent = 0;
74
143
  }
75
144
  static async open(cfg, deviceId, opts) {
76
145
  const resolved = "fetchFn" in cfg ? cfg : resolveConfig(cfg);
77
146
  const prefer = opts?.prefer ?? "direct";
78
147
  const ch = new _DeviceChannel(resolved, deviceId);
148
+ let ready;
149
+ const connected = new Promise((resolve) => {
150
+ ready = resolve;
151
+ });
79
152
  const socket = new ReconnectingSocket({
80
153
  urlProvider: async () => {
81
154
  const access = await mintDeviceAccess(resolved, deviceId);
82
155
  return wsUrlFromAccess(access, prefer);
83
156
  },
84
157
  wsFactory: resolved.wsFactory,
85
- onMessage: (text) => ch.onMessage(text)
158
+ onMessage: (text) => ch.onMessage(text),
159
+ onOpen: () => {
160
+ ch.emitNetworkAdb();
161
+ ready();
162
+ },
163
+ onClose: () => ch.resetNetworkAdb()
86
164
  });
87
165
  ch.socketRef = socket;
88
166
  await socket.start();
167
+ if (!socket.isConnected()) {
168
+ let timer;
169
+ try {
170
+ await Promise.race([connected, new Promise((_, reject) => {
171
+ timer = setTimeout(() => reject(new AixTimeout("device channel connection timed out")), 1e4);
172
+ })]);
173
+ } catch (error) {
174
+ ch.close();
175
+ throw error;
176
+ } finally {
177
+ clearTimeout(timer);
178
+ }
179
+ }
89
180
  return ch;
90
181
  }
91
182
  nextId() {
@@ -119,9 +210,92 @@ var DeviceChannel = class _DeviceChannel {
119
210
  this.scriptletListeners.add(cb);
120
211
  return () => this.scriptletListeners.delete(cb);
121
212
  }
213
+ if (event === "network_adb") {
214
+ this.networkAdbListeners.add(cb);
215
+ return () => this.networkAdbListeners.delete(cb);
216
+ }
122
217
  this.statusListeners.add(cb);
123
218
  return () => this.statusListeners.delete(cb);
124
219
  }
220
+ /** Permission is scoped to this socket only; an ack does not establish an ADB byte connection. */
221
+ get networkAdbState() {
222
+ return { enabled: this.networkAdbEnabled, socketConnected: !this.channelClosed && this.socketRef.isConnected() };
223
+ }
224
+ emitNetworkAdb() {
225
+ const state = this.networkAdbState;
226
+ for (const cb of this.networkAdbListeners) {
227
+ try {
228
+ cb(state);
229
+ } catch {
230
+ }
231
+ }
232
+ }
233
+ resetNetworkAdb() {
234
+ this.networkAdbGeneration++;
235
+ this.networkAdbEnabled = false;
236
+ this.networkAdbStreams.clear();
237
+ for (const tun of this.tunnels.values()) tun._end("socket disconnected");
238
+ this.tunnels.clear();
239
+ for (const [, p] of this.pending) {
240
+ clearTimeout(p.timer);
241
+ p.reject(new AixError("socket disconnected", "offline"));
242
+ }
243
+ this.pending.clear();
244
+ this.emitNetworkAdb();
245
+ }
246
+ setNetworkAdb(enabled) {
247
+ const intent = ++this.networkAdbIntent;
248
+ if (enabled === false) {
249
+ this.networkAdbEnabled = false;
250
+ for (const id of this.networkAdbStreams) {
251
+ try {
252
+ this.tunnels.get(id)?.close();
253
+ } catch {
254
+ }
255
+ }
256
+ this.networkAdbStreams.clear();
257
+ this.emitNetworkAdb();
258
+ }
259
+ const next = this.networkAdbOperation.then(() => this.applyNetworkAdb(enabled, intent));
260
+ this.networkAdbOperation = next.catch(() => {
261
+ this.close();
262
+ });
263
+ return next;
264
+ }
265
+ async applyNetworkAdb(enabled, intent) {
266
+ if (typeof enabled !== "boolean") throw new AixProtocolError("network_adb enabled must be boolean");
267
+ if (this.channelClosed || !this.socketRef.isConnected()) throw new AixError("socket not connected", "offline");
268
+ const generation = this.networkAdbGeneration;
269
+ const value = await this.request({ t: "network_adb", enabled });
270
+ if (generation !== this.networkAdbGeneration || this.channelClosed) throw new AixError("socket disconnected", "offline");
271
+ if (typeof value !== "object" || value === null || value.enabled !== enabled) {
272
+ throw new AixProtocolError("invalid network_adb acknowledgment");
273
+ }
274
+ if (intent !== this.networkAdbIntent) return { enabled: false };
275
+ this.networkAdbEnabled = enabled;
276
+ if (!enabled) {
277
+ this.networkAdbStreams.clear();
278
+ }
279
+ this.emitNetworkAdb();
280
+ return { enabled };
281
+ }
282
+ /** Opens raw ADB bytes on this granted channel, not a local TCP listener. */
283
+ async openNetworkAdbTunnel() {
284
+ if (!this.networkAdbEnabled || this.channelClosed || !this.socketRef.isConnected()) {
285
+ throw new AixError("network ADB is not granted on this socket", "auth");
286
+ }
287
+ const tun = this.openTunnel("adb");
288
+ try {
289
+ await tun.waitReady();
290
+ return tun;
291
+ } catch (e) {
292
+ try {
293
+ tun.close();
294
+ } catch {
295
+ }
296
+ throw e;
297
+ }
298
+ }
125
299
  fridaRun(script, target, spawn = false) {
126
300
  return this.request({ t: "frida_run", script, target, spawn });
127
301
  }
@@ -159,6 +333,15 @@ var DeviceChannel = class _DeviceChannel {
159
333
  return;
160
334
  }
161
335
  }
336
+ if (frame.t === "close") {
337
+ const raw = frame;
338
+ if (typeof raw.stream === "string") this.endTunnel(raw.stream, typeof raw.code === "string" ? raw.code : "remote closed");
339
+ return;
340
+ }
341
+ if (isStatusFrame(frame) && typeof frame.stream === "string") {
342
+ if (frame.state === "opened") this.tunnels.get(frame.stream)?._opened();
343
+ else if (frame.state === "error") this.endTunnel(frame.stream, frame.detail ?? "stream error");
344
+ }
162
345
  if (isFridaEventFrame(frame)) {
163
346
  const { t: _t, ...payload } = frame;
164
347
  for (const cb of this.fridaListeners) cb(payload);
@@ -175,13 +358,28 @@ var DeviceChannel = class _DeviceChannel {
175
358
  return;
176
359
  }
177
360
  }
361
+ endTunnel(streamId, reason) {
362
+ this.tunnels.get(streamId)?._end(reason);
363
+ this.tunnels.delete(streamId);
364
+ this.networkAdbStreams.delete(streamId);
365
+ }
178
366
  openTunnel(kind, addr) {
179
367
  if (this.channelClosed) throw new AixError("channel is closed", "offline");
180
368
  if (!this.socketRef.isConnected()) throw new AixError("socket not connected", "offline");
369
+ if (kind === "adb" && !this.networkAdbEnabled) throw new AixError("network ADB is not granted on this socket", "auth");
181
370
  const streamId = globalThis.crypto?.randomUUID?.() ?? fallbackUuid();
182
- const send = (frame) => this.socketRef.send(JSON.stringify(frame));
183
- const tun = new DeviceTunnel(streamId, send);
371
+ const send = (frame) => {
372
+ const text = JSON.stringify(frame);
373
+ if (kind === "adb" && frame.t === "data") this.socketRef.sendBounded(text, 1048576);
374
+ else this.socketRef.send(text);
375
+ };
376
+ const tun = new DeviceTunnel(streamId, send, () => kind !== "adb" || this.networkAdbEnabled && this.networkAdbStreams.has(streamId));
184
377
  this.tunnels.set(streamId, tun);
378
+ if (kind === "adb") this.networkAdbStreams.add(streamId);
379
+ tun.onClose(() => {
380
+ this.tunnels.delete(streamId);
381
+ this.networkAdbStreams.delete(streamId);
382
+ });
185
383
  send({ t: "open", stream: streamId, kind, addr });
186
384
  return tun;
187
385
  }
@@ -193,6 +391,9 @@ var DeviceChannel = class _DeviceChannel {
193
391
  }
194
392
  close() {
195
393
  this.channelClosed = true;
394
+ this.networkAdbEnabled = false;
395
+ this.networkAdbGeneration++;
396
+ this.emitNetworkAdb();
196
397
  for (const tun of this.tunnels.values()) {
197
398
  try {
198
399
  tun.close();
@@ -200,6 +401,7 @@ var DeviceChannel = class _DeviceChannel {
200
401
  }
201
402
  }
202
403
  this.tunnels.clear();
404
+ this.networkAdbStreams.clear();
203
405
  for (const [, p] of this.pending) {
204
406
  clearTimeout(p.timer);
205
407
  p.reject(new AixError("channel closed", "offline"));
@@ -557,13 +759,20 @@ var MirrorSession = class _MirrorSession {
557
759
  let open = false;
558
760
  let joined = false;
559
761
  let stopped = false;
762
+ let viewerToken = "";
560
763
  const joinIfReady = () => {
561
- if (stopped || !open || joined || !ms || ms.left) return;
764
+ if (stopped || !open || joined || !ms || ms.left || !viewerToken) return;
562
765
  joined = true;
563
- ms.sendSignal({ type: "join", session, role: "viewer", token: ms.token });
766
+ ms.token = viewerToken;
767
+ ms.sendSignal({ type: "join", session, role: "viewer", token: viewerToken });
564
768
  };
565
769
  const socket = new ReconnectingSocket({
566
- urlProvider: async () => signalWsUrl(resolved.baseUrl),
770
+ // Each socket open mints against the backend that will accept the join.
771
+ // A process restart drops the in-memory grant; reusing the old token stays black.
772
+ urlProvider: async () => {
773
+ viewerToken = await mintViewerToken(resolved, session);
774
+ return signalWsUrl(resolved.baseUrl);
775
+ },
567
776
  wsFactory: resolved.wsFactory,
568
777
  onOpen: () => {
569
778
  if (!open) {
@@ -595,10 +804,11 @@ var MirrorSession = class _MirrorSession {
595
804
  };
596
805
  signal?.addEventListener("abort", onAbort, { once: true });
597
806
  try {
598
- const [iceServers, token] = await Promise.race([
599
- Promise.all([getIceServers(resolved), mintViewerToken(resolved, session), socket.start()]),
807
+ const [iceServers] = await Promise.race([
808
+ Promise.all([getIceServers(resolved), socket.start()]),
600
809
  aborted
601
810
  ]);
811
+ const token = viewerToken;
602
812
  if (stopped || signal?.aborted) throw abortError();
603
813
  ms = new _MirrorSession(resolved, session, socket, iceServers, token);
604
814
  joinIfReady();