@aixnn/aixautots 0.0.0-stage → 0.5.2

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 (67) hide show
  1. package/README.md +239 -2
  2. package/dist/ScriptStudio-DaCqOF5H.d.ts +43 -0
  3. package/dist/agent-runner-V60B0is1.d.ts +57 -0
  4. package/dist/automation-queue-8HqRJV_K.d.ts +72 -0
  5. package/dist/chunk-536WVCTB.js +5744 -0
  6. package/dist/chunk-5BMFMDQR.js +18 -0
  7. package/dist/chunk-64Q7BBIQ.js +1347 -0
  8. package/dist/chunk-6YUAACW6.js +866 -0
  9. package/dist/chunk-AIUOLJZA.js +412 -0
  10. package/dist/chunk-CVV7FOMQ.js +175 -0
  11. package/dist/chunk-EHF2WQUR.js +2042 -0
  12. package/dist/chunk-EVHTAXQG.js +273 -0
  13. package/dist/chunk-FW23FLAF.js +56 -0
  14. package/dist/chunk-GKEPMDXO.js +410 -0
  15. package/dist/chunk-H7MHGYF3.js +341 -0
  16. package/dist/chunk-MRQ7VJFJ.js +1074 -0
  17. package/dist/chunk-NWFYTFMI.js +65 -0
  18. package/dist/chunk-OEZFYKL6.js +1 -0
  19. package/dist/chunk-PCYERBNZ.js +1564 -0
  20. package/dist/chunk-PUPVZRKZ.js +668 -0
  21. package/dist/chunk-SUKFJ73W.js +217 -0
  22. package/dist/config-Bm1hmXhD.d.ts +1380 -0
  23. package/dist/coords-LPR_MPyp.d.ts +22 -0
  24. package/dist/core/index.d.ts +135 -0
  25. package/dist/core/index.js +5 -0
  26. package/dist/device-normalize-BaThgnH7.d.ts +43 -0
  27. package/dist/device-session-KZVGLPOI.js +2 -0
  28. package/dist/i18n/index.d.ts +30 -0
  29. package/dist/i18n/index.js +1 -0
  30. package/dist/mirror-session-C_1vFkRV.d.ts +108 -0
  31. package/dist/nav/index.d.ts +19 -0
  32. package/dist/nav/index.js +1 -0
  33. package/dist/react/index.d.ts +487 -0
  34. package/dist/react/index.js +7 -0
  35. package/dist/script-debugger-Cw5jVRoz.d.ts +114 -0
  36. package/dist/task-agent-runner-eD9-SCJz.d.ts +160 -0
  37. package/dist/types-C2WXVcam.d.ts +1005 -0
  38. package/dist/ui/billing.d.ts +48 -0
  39. package/dist/ui/billing.js +425 -0
  40. package/dist/ui/device-create.d.ts +55 -0
  41. package/dist/ui/device-create.js +9 -0
  42. package/dist/ui/device-mirror.d.ts +42 -0
  43. package/dist/ui/device-mirror.js +10 -0
  44. package/dist/ui/devices.d.ts +223 -0
  45. package/dist/ui/devices.js +15 -0
  46. package/dist/ui/editor.d.ts +64 -0
  47. package/dist/ui/editor.js +344 -0
  48. package/dist/ui/index.d.ts +104 -0
  49. package/dist/ui/index.js +676 -0
  50. package/dist/ui/inspector.d.ts +5 -0
  51. package/dist/ui/inspector.js +1250 -0
  52. package/dist/ui/market.d.ts +10 -0
  53. package/dist/ui/market.js +60 -0
  54. package/dist/ui/mirror.d.ts +52 -0
  55. package/dist/ui/mirror.js +3 -0
  56. package/dist/ui/primitives/index.d.ts +101 -0
  57. package/dist/ui/primitives/index.js +1 -0
  58. package/dist/ui/script-studio.d.ts +85 -0
  59. package/dist/ui/script-studio.js +10 -0
  60. package/dist/ui/scripts.d.ts +18 -0
  61. package/dist/ui/scripts.js +210 -0
  62. package/dist/ui/tasks.d.ts +10 -0
  63. package/dist/ui/tasks.js +1039 -0
  64. package/dist/use-script-run-Diay7ibY.d.ts +50 -0
  65. package/package.json +76 -4
  66. package/styles.css +97 -0
  67. package/tailwind-preset.cjs +84 -0
@@ -0,0 +1,341 @@
1
+ import { getIceServers, mintViewerToken } from './chunk-PUPVZRKZ.js';
2
+ import { FlowRun } from './chunk-GKEPMDXO.js';
3
+ import { resolveConfig, ReconnectingSocket, joinUrl } from './chunk-PCYERBNZ.js';
4
+
5
+ // src/core/automation-queue.ts
6
+ async function submitBatch(cfg, config) {
7
+ const { script, flow, deviceIds, expiresIn } = config;
8
+ const mode = config.mode ?? "round-robin";
9
+ if (script && flow !== void 0) {
10
+ throw new Error("submitBatch: pass exactly one of script or flow");
11
+ }
12
+ if (!script && flow === void 0) {
13
+ throw new Error("submitBatch: script or flow required");
14
+ }
15
+ if (deviceIds.length === 0) {
16
+ throw new Error("submitBatch: deviceIds required");
17
+ }
18
+ const rows = config.rows.length > 0 ? config.rows : [{}];
19
+ const taskIds = [];
20
+ for (let i = 0; i < rows.length; i++) {
21
+ const row = rows[i];
22
+ const targetIds = mode === "broadcast" ? deviceIds : [deviceIds[i % deviceIds.length]];
23
+ const fr = await FlowRun.submit(cfg, {
24
+ scriptId: script?.id,
25
+ flow,
26
+ deviceIds: targetIds,
27
+ params: row,
28
+ // 全量模式下后端按 Broadcast 在每台设备各跑一遍;轮询模式单目标无需 mode。
29
+ mode: mode === "broadcast" ? "Broadcast" : void 0,
30
+ expiresIn
31
+ });
32
+ fr.close();
33
+ taskIds.push(fr.taskId);
34
+ }
35
+ return taskIds;
36
+ }
37
+ var AutomationQueue = class {
38
+ constructor(cfg) {
39
+ this.cfg = cfg;
40
+ }
41
+ /** 展开并提交一个批次,返回 task id 数组。见 [`submitBatch`]。 */
42
+ submit(config) {
43
+ return submitBatch(this.cfg, config);
44
+ }
45
+ };
46
+
47
+ // src/core/script-params.ts
48
+ var SCHEMA_KEY = "__schema__";
49
+ var VALID_TYPES = /* @__PURE__ */ new Set([
50
+ "text",
51
+ "textarea",
52
+ "number",
53
+ "select",
54
+ "boolean"
55
+ ]);
56
+ function coerceParam(raw) {
57
+ if (!raw || typeof raw !== "object") return null;
58
+ const o = raw;
59
+ const key = typeof o.key === "string" ? o.key : "";
60
+ if (!key || key.startsWith("__")) return null;
61
+ const type = typeof o.type === "string" && VALID_TYPES.has(o.type) ? o.type : "text";
62
+ const p = { key, type };
63
+ if (typeof o.label === "string") p.label = o.label;
64
+ if (o.default != null) p.default = String(o.default);
65
+ if (Array.isArray(o.options)) p.options = o.options.map((x) => String(x));
66
+ if (o.randomable === true) p.randomable = true;
67
+ if (o.isTarget === true) p.isTarget = true;
68
+ return p;
69
+ }
70
+ function variablesToSchema(variables) {
71
+ const vars = variables ?? {};
72
+ const rawSchema = vars[SCHEMA_KEY];
73
+ if (Array.isArray(rawSchema)) {
74
+ const params = rawSchema.map(coerceParam).filter((p) => p !== null);
75
+ let seenTarget = false;
76
+ for (const p of params) {
77
+ if (p.isTarget) {
78
+ if (seenTarget) delete p.isTarget;
79
+ else seenTarget = true;
80
+ }
81
+ }
82
+ return params;
83
+ }
84
+ return Object.entries(vars).filter(([k]) => !k.startsWith("__")).map(([k, v]) => ({ key: k, type: "text", default: String(v) }));
85
+ }
86
+ function schemaToVariables(schema, base) {
87
+ const out = {};
88
+ for (const [k, v] of Object.entries(base ?? {})) {
89
+ if (k === SCHEMA_KEY) continue;
90
+ if (k.startsWith("__")) out[k] = v;
91
+ }
92
+ out[SCHEMA_KEY] = schema;
93
+ for (const p of schema) out[p.key] = p.default ?? "";
94
+ return out;
95
+ }
96
+ function targetParam(schema) {
97
+ return schema.find((p) => p.isTarget);
98
+ }
99
+ function schemaDefaults(schema) {
100
+ return Object.fromEntries(schema.map((p) => [p.key, p.default ?? ""]));
101
+ }
102
+
103
+ // src/core/mirror-session.ts
104
+ var SCRCPY_PROFILES = {
105
+ balanced: { max_size: 1280, bitrate: 6e6, fps: 60 },
106
+ low_latency: { max_size: 1024, bitrate: 4e6, fps: 30 },
107
+ high_quality: { max_size: 0, bitrate: 8e6, fps: 60 }
108
+ };
109
+ function qualityMessage(profile) {
110
+ return { t: "quality", ...SCRCPY_PROFILES[profile] };
111
+ }
112
+ function signalWsUrl(baseUrl) {
113
+ return joinUrl(baseUrl, "/ws/signal").replace(/^http/, "ws");
114
+ }
115
+ var MirrorSession = class _MirrorSession {
116
+ constructor(cfg, session, socket, iceServers, token) {
117
+ this.cfg = cfg;
118
+ this.session = session;
119
+ this.socket = socket;
120
+ this.iceServers = iceServers;
121
+ this.token = token;
122
+ this.pc = null;
123
+ this.input = null;
124
+ this._stream = null;
125
+ this.peerId = null;
126
+ this.remotePeer = null;
127
+ this.remoteDescriptionReady = false;
128
+ this.pendingIce = [];
129
+ this.stateListeners = /* @__PURE__ */ new Set();
130
+ this.streamListeners = /* @__PURE__ */ new Set();
131
+ }
132
+ /** Start a viewer session. On WebSocket reconnect the socket re-joins
133
+ * automatically; the node then sends a fresh offer, which is paired with a
134
+ * fresh RTCPeerConnection (see the `offer` handler) — no consumer action
135
+ * needed to restore the video track. */
136
+ static async join(cfg, session) {
137
+ const resolved = "fetchFn" in cfg ? cfg : resolveConfig(cfg);
138
+ const iceServers = await getIceServers(resolved);
139
+ const token = await mintViewerToken(resolved, session);
140
+ let ms;
141
+ const socket = new ReconnectingSocket({
142
+ urlProvider: async () => signalWsUrl(resolved.baseUrl),
143
+ wsFactory: resolved.wsFactory,
144
+ onOpen: () => ms.sendSignal({ type: "join", session, role: "viewer", token }),
145
+ onMessage: (text) => ms.onSignal(text)
146
+ });
147
+ ms = new _MirrorSession(resolved, session, socket, iceServers, token);
148
+ await socket.start();
149
+ return ms;
150
+ }
151
+ get stream() {
152
+ return this._stream;
153
+ }
154
+ onConnectionStateChange(cb) {
155
+ this.stateListeners.add(cb);
156
+ return () => this.stateListeners.delete(cb);
157
+ }
158
+ onStream(cb) {
159
+ this.streamListeners.add(cb);
160
+ return () => this.streamListeners.delete(cb);
161
+ }
162
+ sendInput(msg) {
163
+ if (this.input && this.input.readyState === "open") this.input.send(JSON.stringify(msg));
164
+ }
165
+ /** Ask the node to switch this device's encode profile (restarts its capture
166
+ * pipeline; the video blanks briefly while it re-syncs on a keyframe). */
167
+ setQuality(profile) {
168
+ this.sendInput(qualityMessage(profile));
169
+ }
170
+ /** Current round-trip time (seconds) from the active ICE candidate pair, or
171
+ * null when stats are unavailable (no pc yet / mock without getStats). Used
172
+ * by the auto quality heuristic. */
173
+ async currentRtt() {
174
+ const pc = this.pc;
175
+ if (!pc?.getStats) return null;
176
+ try {
177
+ const report = await pc.getStats();
178
+ let rtt = null;
179
+ const visit = (s) => {
180
+ const stat = s;
181
+ if (stat?.type === "candidate-pair" && (stat.nominated || stat.state === "succeeded") && typeof stat.currentRoundTripTime === "number") rtt = stat.currentRoundTripTime;
182
+ };
183
+ const r = report;
184
+ if (typeof r?.forEach === "function") r.forEach(visit);
185
+ else if (Symbol.iterator in Object(report)) for (const s of report) visit(s);
186
+ return rtt;
187
+ } catch {
188
+ return null;
189
+ }
190
+ }
191
+ sendSignal(msg) {
192
+ try {
193
+ this.socket.send(JSON.stringify(msg));
194
+ } catch {
195
+ }
196
+ }
197
+ ensurePc() {
198
+ if (this.pc) return this.pc;
199
+ const pc = this.cfg.rtcFactory({ iceServers: this.iceServers });
200
+ pc.ontrack = (ev) => {
201
+ if (ev.receiver && "playoutDelayHint" in ev.receiver) ev.receiver.playoutDelayHint = 0;
202
+ if (ev.streams && ev.streams[0]) {
203
+ this._stream = ev.streams[0];
204
+ for (const cb of this.streamListeners) cb(this._stream);
205
+ }
206
+ };
207
+ pc.onicecandidate = (ev) => {
208
+ if (ev.candidate && this.remotePeer) this.sendSignal({ type: "ice", session: this.session, to: this.remotePeer, candidate: ev.candidate });
209
+ };
210
+ pc.ondatachannel = (ev) => {
211
+ if (ev.channel.label === "control") this.attachInput(ev.channel);
212
+ };
213
+ pc.onconnectionstatechange = () => {
214
+ for (const cb of this.stateListeners) cb(pc.connectionState);
215
+ };
216
+ this.pc = pc;
217
+ return pc;
218
+ }
219
+ attachInput(dc) {
220
+ this.input = dc;
221
+ }
222
+ /** Drop the current peer connection (keeps the last frame on screen until
223
+ * the replacement track arrives). */
224
+ resetPeer() {
225
+ try {
226
+ this.input?.close();
227
+ } catch {
228
+ }
229
+ try {
230
+ this.pc?.close();
231
+ } catch {
232
+ }
233
+ this.input = null;
234
+ this.pc = null;
235
+ this.remoteDescriptionReady = false;
236
+ this.pendingIce = [];
237
+ }
238
+ async onSignal(text) {
239
+ let m;
240
+ try {
241
+ m = JSON.parse(text);
242
+ } catch {
243
+ return;
244
+ }
245
+ switch (m.type) {
246
+ case "welcome":
247
+ this.peerId = m.peer_id ?? null;
248
+ break;
249
+ case "peers":
250
+ break;
251
+ // node initiates the offer; viewer waits
252
+ case "offer":
253
+ if (m.sdp && m.from) {
254
+ if (this.pc) this.resetPeer();
255
+ this.remotePeer = m.from;
256
+ const pc = this.ensurePc();
257
+ await pc.setRemoteDescription({ type: "offer", sdp: m.sdp });
258
+ this.remoteDescriptionReady = true;
259
+ for (const candidate of this.pendingIce.splice(0)) await pc.addIceCandidate(candidate);
260
+ const answer = await pc.createAnswer();
261
+ await pc.setLocalDescription(answer);
262
+ this.sendSignal({ type: "answer", session: this.session, to: m.from, sdp: answer.sdp });
263
+ }
264
+ break;
265
+ case "ice":
266
+ if (m.candidate) {
267
+ if (!this.pc || !this.remoteDescriptionReady) this.pendingIce.push(m.candidate);
268
+ else await this.pc.addIceCandidate(m.candidate);
269
+ }
270
+ break;
271
+ }
272
+ }
273
+ leave() {
274
+ this.sendSignal({ type: "leave", session: this.session });
275
+ this.input?.close();
276
+ this.pc?.close();
277
+ this.pendingIce = [];
278
+ this.socket.close();
279
+ }
280
+ };
281
+
282
+ // src/core/resources/device-normalize.ts
283
+ function metaStr(r, key) {
284
+ const v = r.meta?.[key];
285
+ return typeof v === "string" && v ? v : null;
286
+ }
287
+ function seenMs(r) {
288
+ return r.last_seen_at ? Date.parse(r.last_seen_at) || 0 : 0;
289
+ }
290
+ function toTransport(r) {
291
+ return {
292
+ external_id: r.external_id,
293
+ transport: metaStr(r, "transport"),
294
+ online: r.online === true,
295
+ node_id: r.node_id ?? null,
296
+ node_name: r.node_name ?? null,
297
+ last_seen_at: r.last_seen_at
298
+ };
299
+ }
300
+ function pickPrimary(group) {
301
+ const mostRecent = (rows) => rows.reduce((best, r) => seenMs(r) > seenMs(best) ? r : best);
302
+ const online = group.filter((r) => r.online === true);
303
+ if (!online.length) return mostRecent(group);
304
+ const provisioned = group.filter((r) => r.meta?.provisioned === true);
305
+ if (provisioned.length) return mostRecent(provisioned);
306
+ const usb = online.filter((r) => metaStr(r, "transport") === "usb");
307
+ return mostRecent(usb.length ? usb : online);
308
+ }
309
+ function normalizeDevices(rows) {
310
+ const serialnoSet = /* @__PURE__ */ new Set();
311
+ for (const r of rows) {
312
+ const sn = metaStr(r, "serialno");
313
+ if (sn) serialnoSet.add(sn);
314
+ }
315
+ const groups = /* @__PURE__ */ new Map();
316
+ for (const r of rows) {
317
+ const serialno = metaStr(r, "serialno");
318
+ let key;
319
+ if (serialno) {
320
+ key = `sn:${serialno}`;
321
+ } else if (serialnoSet.has(r.external_id)) {
322
+ key = `sn:${r.external_id}`;
323
+ } else {
324
+ key = `ext:${r.external_id}`;
325
+ }
326
+ const g = groups.get(key);
327
+ if (g) g.push(r);
328
+ else groups.set(key, [r]);
329
+ }
330
+ return [...groups.values()].map((group) => {
331
+ const primary = pickPrimary(group);
332
+ return {
333
+ ...primary,
334
+ online: group.some((r) => r.online === true),
335
+ device_id: primary.external_id,
336
+ transports: group.map(toTransport)
337
+ };
338
+ });
339
+ }
340
+
341
+ export { AutomationQueue, MirrorSession, SCHEMA_KEY, SCRCPY_PROFILES, normalizeDevices, qualityMessage, schemaDefaults, schemaToVariables, submitBatch, targetParam, variablesToSchema };