@aixnn/aixautots 0.6.4 → 0.6.5

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-BxrSIkG3.d.ts → automation-queue-aYRO9JLj.d.ts} +2 -2
  2. package/dist/chunk-7CN37G3W.js +102 -0
  3. package/dist/{chunk-JTFZSFFA.js → chunk-7H4CYM42.js} +414 -5
  4. package/dist/{chunk-M4DO7SSZ.js → chunk-D7J4EQTA.js} +1 -1
  5. package/dist/{chunk-B2BOVLI6.js → chunk-F76N3GOA.js} +1077 -313
  6. package/dist/{chunk-SAB5CH2K.js → chunk-FBWJUW4X.js} +578 -141
  7. package/dist/{chunk-T3QVYTOT.js → chunk-IFARWPMU.js} +364 -0
  8. package/dist/{chunk-UJO7BJUV.js → chunk-LMSN6Z3N.js} +668 -104
  9. package/dist/{chunk-Q63FQ7B5.js → chunk-LWTL4AIC.js} +254 -13
  10. package/dist/{chunk-YFF7VLNT.js → chunk-SKTL6ACT.js} +40 -2
  11. package/dist/{chunk-BYL2S2H6.js → chunk-X5KVYWUK.js} +4 -5
  12. package/dist/{chunk-NGW34POA.js → chunk-YWA47ARA.js} +318 -15
  13. package/dist/{config-CLi5IhmO.d.ts → config-B7t1Ln3w.d.ts} +177 -8
  14. package/dist/core/index.d.ts +21 -16
  15. package/dist/core/index.js +2 -4
  16. package/dist/{device-normalize-BaThgnH7.d.ts → device-normalize-CuGflfZA.d.ts} +1 -1
  17. package/dist/device-session-OFGN4KUD.js +1 -0
  18. package/dist/i18n/index.js +1 -1
  19. package/dist/{mirror-session-BP7Rd3Jk.d.ts → mirror-session-DK0OQvA3.d.ts} +11 -3
  20. package/dist/react/index.d.ts +10 -8
  21. package/dist/react/index.js +3 -6
  22. package/dist/{script-debugger-DtUGxK9i.d.ts → script-debugger-6hoLEwEz.d.ts} +1 -1
  23. package/dist/{task-agent-runner-DzV_OUZ7.d.ts → task-agent-runner-BwRW88rl.d.ts} +5 -3
  24. package/dist/{types-C2WXVcam.d.ts → types-BbtVr3QM.d.ts} +34 -3
  25. package/dist/ui/billing.d.ts +1 -1
  26. package/dist/ui/billing.js +5 -9
  27. package/dist/ui/device-create.d.ts +4 -3
  28. package/dist/ui/device-create.js +7 -9
  29. package/dist/ui/device-mirror.d.ts +16 -2
  30. package/dist/ui/device-mirror.js +6 -8
  31. package/dist/ui/devices.d.ts +5 -5
  32. package/dist/ui/devices.js +10 -13
  33. package/dist/ui/editor.d.ts +2 -2
  34. package/dist/ui/editor.js +7 -11
  35. package/dist/ui/index.d.ts +4 -4
  36. package/dist/ui/index.js +9 -15
  37. package/dist/ui/inspector.js +5 -9
  38. package/dist/ui/market.js +4 -7
  39. package/dist/ui/mirror.d.ts +3 -3
  40. package/dist/ui/primitives/index.d.ts +1 -1
  41. package/dist/ui/primitives/index.js +1 -2
  42. package/dist/ui/script-studio.js +6 -10
  43. package/dist/ui/scripts.d.ts +1 -1
  44. package/dist/ui/scripts.js +5 -9
  45. package/dist/ui/tasks.js +10 -13
  46. package/package.json +1 -1
  47. package/dist/chunk-A5VNENHD.js +0 -229
  48. package/dist/chunk-BUW45GM2.js +0 -341
  49. package/dist/chunk-H37NHOYU.js +0 -44
  50. package/dist/chunk-LAZ3RQ7X.js +0 -668
  51. package/dist/device-session-CVT7OY4H.js +0 -2
@@ -1,9 +1,51 @@
1
- import { MirrorSession, normalizeDevices, submitBatch } from './chunk-BUW45GM2.js';
2
- import { useDevice, useAixConfig, useClient, useQuery } from './chunk-A5VNENHD.js';
3
- import { FlowRun } from './chunk-JTFZSFFA.js';
4
- import { isFleetRunTerminal, resolveConfig, joinUrl, AixAuthError, AixError, detectEnvOs, EnvRun, summarizeEnv, ReconnectingSocket, executionWsTicketUrl } from './chunk-B2BOVLI6.js';
5
- import { createContext, useState, useRef, useEffect, useCallback, useMemo, createElement, useContext } from 'react';
1
+ import { DeviceChannel, ScriptDebugger, FlowRun, MirrorSession, normalizeDevices, submitBatch } from './chunk-7H4CYM42.js';
2
+ import { resolveConfig, AixClient, isFleetRunTerminal, joinUrl, AixAuthError, AixError, EnvRun, detectEnvOs, summarizeEnv, ReconnectingSocket, executionWsTicketUrl } from './chunk-F76N3GOA.js';
3
+ import React, { createContext, useContext, useState, useRef, useEffect, useCallback, useMemo, createElement } from 'react';
4
+ import { jsx } from 'react/jsx-runtime';
6
5
 
6
+ var Ctx = createContext(null);
7
+ function AixProvider({ config, children }) {
8
+ const resolved = React.useMemo(
9
+ () => resolveConfig(config),
10
+ // Spread individual stable primitives so an inline config object literal
11
+ // doesn't thrash the channel on every parent render.
12
+ // eslint-disable-next-line react-hooks/exhaustive-deps
13
+ [config.baseUrl, config.getAuthToken, config.fetchFn, config.wsFactory]
14
+ );
15
+ return /* @__PURE__ */ jsx(Ctx.Provider, { value: resolved, children });
16
+ }
17
+ function useAixConfig() {
18
+ const c = useContext(Ctx);
19
+ if (!c) throw new Error("useAixConfig must be used within <AixProvider>");
20
+ return c;
21
+ }
22
+ function useDevice(deviceId) {
23
+ const cfg = useAixConfig();
24
+ const [channel, setChannel] = useState(null);
25
+ const [error, setError] = useState(null);
26
+ const ref = useRef(null);
27
+ useEffect(() => {
28
+ let cancelled = false;
29
+ setChannel(null);
30
+ setError(null);
31
+ DeviceChannel.open(cfg, deviceId).then((ch) => {
32
+ if (cancelled) {
33
+ ch.close();
34
+ return;
35
+ }
36
+ ref.current = ch;
37
+ setChannel(ch);
38
+ }).catch((e) => {
39
+ if (!cancelled) setError(e instanceof Error ? e : new Error(String(e)));
40
+ });
41
+ return () => {
42
+ cancelled = true;
43
+ ref.current?.close();
44
+ ref.current = null;
45
+ };
46
+ }, [cfg, deviceId]);
47
+ return { deviceId, channel, error };
48
+ }
7
49
  function useCommands(deviceId) {
8
50
  const { channel, error: openError } = useDevice(deviceId);
9
51
  const [loading, setLoading] = useState(false);
@@ -62,6 +104,74 @@ function useCommands(deviceId) {
62
104
  }, [channel]);
63
105
  return { ready: channel !== null, loading, error: error ?? openError, lastResult, adb, wda };
64
106
  }
107
+ function useScript(deviceId, opts) {
108
+ const { channel, error: openError } = useDevice(deviceId);
109
+ const [running, setRunning] = useState(false);
110
+ const [runId, setRunId] = useState(null);
111
+ const [events, setEvents] = useState([]);
112
+ const [error, setError] = useState(null);
113
+ const mountedRef = useRef(true);
114
+ useEffect(() => {
115
+ mountedRef.current = true;
116
+ return () => {
117
+ mountedRef.current = false;
118
+ };
119
+ }, []);
120
+ const dbg = useMemo(
121
+ () => channel ? new ScriptDebugger({ engine: opts.engine, channel }) : null,
122
+ [channel, opts.engine]
123
+ );
124
+ useEffect(() => {
125
+ if (!dbg) return;
126
+ const unsub = dbg.on("event", (e) => {
127
+ if (mountedRef.current) setEvents((prev) => [...prev, e]);
128
+ });
129
+ return () => {
130
+ unsub();
131
+ void dbg.cancel().catch(() => {
132
+ });
133
+ if (mountedRef.current) {
134
+ setRunning(false);
135
+ setRunId(null);
136
+ }
137
+ };
138
+ }, [dbg]);
139
+ const run = useCallback(async (input) => {
140
+ if (!dbg) throw new Error("device channel not ready");
141
+ if (mountedRef.current) {
142
+ setError(null);
143
+ setEvents([]);
144
+ }
145
+ try {
146
+ const res = await dbg.run(input);
147
+ if (mountedRef.current) {
148
+ setRunId(res.runId);
149
+ setRunning(true);
150
+ }
151
+ return res;
152
+ } catch (e) {
153
+ const err = e instanceof Error ? e : new Error(String(e));
154
+ if (mountedRef.current) setError(err);
155
+ throw err;
156
+ }
157
+ }, [dbg]);
158
+ const call = useCallback(async (method, args) => {
159
+ if (!dbg) throw new Error("device channel not ready");
160
+ return dbg.call(method, args);
161
+ }, [dbg]);
162
+ const cancel = useCallback(async () => {
163
+ if (!dbg) return;
164
+ await dbg.cancel();
165
+ if (mountedRef.current) {
166
+ setRunning(false);
167
+ setRunId(null);
168
+ }
169
+ }, [dbg]);
170
+ const clearEvents = useCallback(() => {
171
+ if (mountedRef.current) setEvents([]);
172
+ }, []);
173
+ return { ready: channel !== null, running, runId, events, error: error ?? openError, run, call, cancel, clearEvents };
174
+ }
65
175
  function useFlowRun() {
66
176
  const cfg = useAixConfig();
67
177
  const [taskId, setTaskId] = useState(null);
@@ -114,14 +224,19 @@ function useMirror(sessionId) {
114
224
  const [session, setSession] = useState(null);
115
225
  const [stream, setStream] = useState(null);
116
226
  const [error, setError] = useState(null);
227
+ const [connectionState, setConnectionState] = useState("connecting");
228
+ const [controlReady, setControlReady] = useState(false);
117
229
  const ref = useRef(null);
118
230
  const mountedRef = useRef(true);
119
231
  useEffect(() => {
120
232
  mountedRef.current = true;
121
233
  let cancelled = false;
234
+ let unsubscribe = [];
122
235
  setSession(null);
123
236
  setStream(null);
124
237
  setError(null);
238
+ setConnectionState("connecting");
239
+ setControlReady(false);
125
240
  if (!sessionId) return () => {
126
241
  mountedRef.current = false;
127
242
  };
@@ -132,18 +247,31 @@ function useMirror(sessionId) {
132
247
  }
133
248
  ref.current = ms;
134
249
  setSession(ms);
135
- ms.onStream((s) => {
136
- if (mountedRef.current) setStream(s);
137
- });
138
- ms.onConnectionStateChange(() => {
139
- if (mountedRef.current) setStream(ms.stream);
140
- });
250
+ setStream(ms.stream);
251
+ setConnectionState(ms.connectionState);
252
+ setControlReady(ms.controlReady);
253
+ unsubscribe = [
254
+ ms.onStream((s) => {
255
+ if (!cancelled) setStream(s);
256
+ }),
257
+ ms.onConnectionStateChange((state) => {
258
+ if (!cancelled) {
259
+ setStream(ms.stream);
260
+ setConnectionState(state);
261
+ setControlReady(ms.controlReady);
262
+ }
263
+ }),
264
+ ms.onControlStateChange((ready) => {
265
+ if (!cancelled) setControlReady(ready);
266
+ })
267
+ ];
141
268
  }).catch((e) => {
142
269
  if (!cancelled) setError(e instanceof Error ? e : new Error(String(e)));
143
270
  });
144
271
  return () => {
145
272
  cancelled = true;
146
273
  mountedRef.current = false;
274
+ unsubscribe.forEach((stop) => stop());
147
275
  ref.current?.leave();
148
276
  ref.current = null;
149
277
  };
@@ -154,7 +282,7 @@ function useMirror(sessionId) {
154
282
  const setQuality = useCallback((profile) => {
155
283
  ref.current?.setQuality(profile);
156
284
  }, []);
157
- return { session, stream, error, sendInput, setQuality };
285
+ return { session, stream, error, connectionState, controlReady, sendInput, setQuality };
158
286
  }
159
287
  var GROUP_MIRROR_MAX = 9;
160
288
  function useGroupMirror(ids) {
@@ -203,6 +331,47 @@ function useGroupMirror(ids) {
203
331
  }, []);
204
332
  return { streams, errors, connected, broadcastInput, setQualityAll };
205
333
  }
334
+ function useClient() {
335
+ const cfg = useAixConfig();
336
+ return useMemo(() => new AixClient(cfg), [cfg]);
337
+ }
338
+ function useQuery(loader, deps) {
339
+ const [data, setData] = useState(null);
340
+ const [loading, setLoading] = useState(true);
341
+ const [error, setError] = useState(null);
342
+ const mounted = useRef(true);
343
+ const loaderRef = useRef(loader);
344
+ loaderRef.current = loader;
345
+ const run = useCallback(async () => {
346
+ if (mounted.current) {
347
+ setLoading(true);
348
+ setError(null);
349
+ }
350
+ try {
351
+ const r = await loaderRef.current();
352
+ if (mounted.current) {
353
+ setData(r);
354
+ setLoading(false);
355
+ }
356
+ } catch (e) {
357
+ if (mounted.current) {
358
+ setError(e instanceof Error ? e : new Error(String(e)));
359
+ setLoading(false);
360
+ }
361
+ }
362
+ }, deps);
363
+ useEffect(() => {
364
+ mounted.current = true;
365
+ void run();
366
+ return () => {
367
+ mounted.current = false;
368
+ };
369
+ }, [run]);
370
+ const patch = useCallback((updater) => {
371
+ if (mounted.current) setData((prev) => updater(prev));
372
+ }, []);
373
+ return { data, loading, error, refetch: run, setData: patch };
374
+ }
206
375
  function useAuth() {
207
376
  const c = useClient();
208
377
  return {
@@ -260,6 +429,8 @@ function mapDevice(r) {
260
429
  const booting = !online && provisioned && createdMs > 0 && Date.now() - createdMs < 12e4;
261
430
  return {
262
431
  id: r.device_id,
432
+ ownerUserId: r.owner_user_id,
433
+ projectId: r.project_id,
263
434
  name: r.name || meta.name || r.external_id,
264
435
  platform,
265
436
  status: online ? "connected" : booting ? "connecting" : "disconnected",
@@ -1890,6 +2061,76 @@ function useNodes() {
1890
2061
  }, [c, refetch]);
1891
2062
  return { ...q, register };
1892
2063
  }
2064
+ function useEnvRun(beforeSetup) {
2065
+ const cfg = useAixConfig();
2066
+ const [reqId, setReqId] = useState(null);
2067
+ const [events, setEvents] = useState([]);
2068
+ const [finished, setFinished] = useState(null);
2069
+ const [done, setDone] = useState(false);
2070
+ const [error, setError] = useState(null);
2071
+ const [preparing, setPreparing] = useState(false);
2072
+ const runRef = useRef(null);
2073
+ const mountedRef = useRef(true);
2074
+ useEffect(() => {
2075
+ mountedRef.current = true;
2076
+ return () => {
2077
+ mountedRef.current = false;
2078
+ runRef.current?.close();
2079
+ runRef.current = null;
2080
+ };
2081
+ }, []);
2082
+ const run = useCallback(
2083
+ async (start) => {
2084
+ runRef.current?.close();
2085
+ if (mountedRef.current) {
2086
+ setPreparing(true);
2087
+ setError(null);
2088
+ setEvents([]);
2089
+ setFinished(null);
2090
+ setDone(false);
2091
+ setReqId(null);
2092
+ }
2093
+ try {
2094
+ const r = await start();
2095
+ runRef.current = r;
2096
+ r.on("event", (e) => {
2097
+ if (!mountedRef.current) return;
2098
+ setEvents((prev) => [...prev, e]);
2099
+ if (e.kind === "finished") {
2100
+ setFinished(e);
2101
+ setDone(true);
2102
+ }
2103
+ });
2104
+ r.on("done", (f) => {
2105
+ if (mountedRef.current) {
2106
+ setFinished(f);
2107
+ setDone(true);
2108
+ }
2109
+ });
2110
+ if (mountedRef.current) setReqId(r.reqId);
2111
+ return { reqId: r.reqId };
2112
+ } catch (e) {
2113
+ const err = e instanceof Error ? e : new Error(String(e));
2114
+ if (mountedRef.current) setError(err);
2115
+ throw err;
2116
+ } finally {
2117
+ if (mountedRef.current) setPreparing(false);
2118
+ }
2119
+ },
2120
+ []
2121
+ );
2122
+ const setup = useCallback((nodeId, input) => run(async () => {
2123
+ await beforeSetup?.(nodeId);
2124
+ return EnvRun.start(cfg, nodeId, "setup", input);
2125
+ }), [cfg, run, beforeSetup]);
2126
+ const status = useCallback((nodeId, input) => run(() => EnvRun.start(cfg, nodeId, "status", input)), [cfg, run]);
2127
+ const teardown = useCallback((nodeId, input) => run(() => EnvRun.start(cfg, nodeId, "teardown", input)), [cfg, run]);
2128
+ const close = useCallback(() => {
2129
+ runRef.current?.close();
2130
+ runRef.current = null;
2131
+ }, []);
2132
+ return { reqId, events, finished, done, error, preparing, setup, status, teardown, close };
2133
+ }
1893
2134
  function useEnvGate(nodeId, opts) {
1894
2135
  const cfg = useAixConfig();
1895
2136
  const os = opts?.os !== void 0 ? opts.os : detectEnvOs();
@@ -2039,4 +2280,4 @@ function useApiTokens() {
2039
2280
  return { ...q, create, revoke, rotate };
2040
2281
  }
2041
2282
 
2042
- export { DevicesProvider, GROUP_MIRROR_MAX, InspectorProvider, NodesProvider, ShortcutsProvider, createAgentTaskRunner, mapDevice, preflightTaskAgentDevice, useAdmin, useApiTokens, useAuth, useAutomationQueue, useBilling, useClusters, useCommands, useDeviceActions, useDevices, useDevicesView, useEnvGate, useFleetRun, useFlowRun, useGroupMirror, useImages, useInspector, useInspectorView, useLlm, useLocators, useMirror, useNodes, useNodesView, useProjects, useScriptRun, useScripts, useShortcutsView, useTaskAgentRun, useTaskStatus, useTasks, useWebhooks };
2283
+ export { AixProvider, DevicesProvider, GROUP_MIRROR_MAX, InspectorProvider, NodesProvider, ShortcutsProvider, createAgentTaskRunner, mapDevice, preflightTaskAgentDevice, useAdmin, useAixConfig, useApiTokens, useAuth, useAutomationQueue, useBilling, useClient, useClusters, useCommands, useDevice, useDeviceActions, useDevices, useDevicesView, useEnvGate, useEnvRun, useFleetRun, useFlowRun, useGroupMirror, useImages, useInspector, useInspectorView, useLlm, useLocators, useMirror, useNodes, useNodesView, useProjects, useQuery, useScript, useScriptRun, useScripts, useShortcutsView, useTaskAgentRun, useTaskStatus, useTasks, useWebhooks };
@@ -3,7 +3,7 @@ import { twMerge } from 'tailwind-merge';
3
3
  import * as DialogPrimitive from '@radix-ui/react-dialog';
4
4
  import { X, CheckCircle2, XCircle, Info, ChevronDown } from 'lucide-react';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
- import { forwardRef, useState, useCallback, useEffect } from 'react';
6
+ import { forwardRef, useState, useCallback, useEffect, useRef } from 'react';
7
7
  import { cva } from 'class-variance-authority';
8
8
 
9
9
  // src/ui/primitives/utils.ts
@@ -235,5 +235,43 @@ var badgeVariants = cva(
235
235
  function Badge({ className, variant, ...props }) {
236
236
  return /* @__PURE__ */ jsx("span", { className: cn(badgeVariants({ variant, className })), ...props });
237
237
  }
238
+ function Popover({
239
+ trigger,
240
+ children,
241
+ align = "end",
242
+ className
243
+ }) {
244
+ const [open, setOpen] = useState(false);
245
+ const ref = useRef(null);
246
+ useEffect(() => {
247
+ if (!open) return;
248
+ const onDown = (e) => {
249
+ if (ref.current && !ref.current.contains(e.target)) setOpen(false);
250
+ };
251
+ const onKey = (e) => {
252
+ if (e.key === "Escape") {
253
+ e.preventDefault();
254
+ e.stopPropagation();
255
+ setOpen(false);
256
+ }
257
+ };
258
+ document.addEventListener("mousedown", onDown);
259
+ document.addEventListener("keydown", onKey);
260
+ return () => {
261
+ document.removeEventListener("mousedown", onDown);
262
+ document.removeEventListener("keydown", onKey);
263
+ };
264
+ }, [open]);
265
+ return /* @__PURE__ */ jsxs("div", { className: "relative inline-block", ref, children: [
266
+ trigger({ open, toggle: () => setOpen((o) => !o) }),
267
+ open && /* @__PURE__ */ jsx(
268
+ "div",
269
+ {
270
+ className: `absolute z-50 mt-1 min-w-[260px] rounded-md border border-border bg-background shadow-lg p-3 ${align === "end" ? "right-0" : "left-0"} ${className ?? ""}`,
271
+ children: children(() => setOpen(false))
272
+ }
273
+ )
274
+ ] });
275
+ }
238
276
 
239
- export { Badge, Button, Dialog, Drawer, Input, Select, ToastViewport, cn, useToast };
277
+ export { Badge, Button, Dialog, Drawer, Input, Popover, Select, ToastViewport, cn, useToast };
@@ -1,8 +1,7 @@
1
- import { LogConsole } from './chunk-M4DO7SSZ.js';
2
- import { cn, Button, Select } from './chunk-YFF7VLNT.js';
3
- import { useDevices, useScripts, useScriptRun } from './chunk-Q63FQ7B5.js';
4
- import { variablesToSchema, normalizeDevices, schemaToVariables } from './chunk-BUW45GM2.js';
5
- import { useClient } from './chunk-A5VNENHD.js';
1
+ import { LogConsole } from './chunk-D7J4EQTA.js';
2
+ import { cn, Button, Select } from './chunk-SKTL6ACT.js';
3
+ import { useDevices, useClient, useScripts, useScriptRun } from './chunk-LWTL4AIC.js';
4
+ import { variablesToSchema, normalizeDevices, schemaToVariables } from './chunk-7H4CYM42.js';
6
5
  import { useMemo, useState, useEffect, useRef, useCallback } from 'react';
7
6
  import { Trash2, Plus, Play, Pause, Square, ArrowDownToLine, WrapText, ChevronRight, Save, XCircle, CheckCircle2, Loader2, Circle } from 'lucide-react';
8
7
  import CodeMirror, { EditorView } from '@uiw/react-codemirror';