@aixnn/aixautots 0.5.3 → 0.5.4

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.
@@ -0,0 +1,43 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ /** Context handed to host-injected slots (agent / inspector). */
5
+ interface ScriptStudioSlotContext {
6
+ /** Persisted script id (undefined until first save). */
7
+ scriptId?: string;
8
+ /** Currently selected run device id. */
9
+ deviceId: string | null;
10
+ /** Resolved platform of the selected device ('android' | 'ios' | …). */
11
+ platform: 'android' | 'ios';
12
+ /** Current editor source. */
13
+ code: string;
14
+ /** Replace the entire editor source. */
15
+ setCode: (code: string) => void;
16
+ /** Append a snippet to the editor source (newline-separated). */
17
+ insertSnippet: (snippet: string) => void;
18
+ /** Open the host-injected device inspector (same as the header button). */
19
+ openInspector: () => void;
20
+ }
21
+ interface ScriptStudioProps {
22
+ /** Route param: the script to open. Undefined ⇒ a fresh "New Script". */
23
+ scriptId?: string;
24
+ /** Called after the first create assigns an id, so the host can switch the
25
+ * URL to `/editor/:id` (the SDK does not depend on a router). */
26
+ onScriptIdChange?: (id: string) => void;
27
+ /** Host-injected LLM agent panel (right column). Not rendered if omitted. */
28
+ renderAgentPanel?: (ctx: ScriptStudioSlotContext) => ReactNode;
29
+ /** Host-injected device inspector (modal/overlay). Not rendered if omitted.
30
+ * `open`/`onClose` are driven by the studio's "设备/Inspector" button. */
31
+ renderInspector?: (ctx: ScriptStudioSlotContext & {
32
+ open: boolean;
33
+ onClose: () => void;
34
+ }) => ReactNode;
35
+ /** localStorage key for the resizable console height. */
36
+ consoleHeightStorageKey?: string;
37
+ /** Extra controls rendered at the right end of the header (e.g. a language
38
+ * toggle). The studio itself stays app-chrome-agnostic. */
39
+ headerExtra?: ReactNode;
40
+ }
41
+ declare function ScriptStudio({ scriptId, onScriptIdChange, renderAgentPanel, renderInspector, consoleHeightStorageKey, headerExtra, }: ScriptStudioProps): react.JSX.Element;
42
+
43
+ export { type ScriptStudioProps as S, type ScriptStudioSlotContext as a, ScriptStudio as b };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * LLM agent 传输的注入接口。`AgentPanel` 的 UI 与可移植逻辑在 aixautots 内,但「如何
3
+ * 真正跑一个本地 agent」是宿主特有的(桌面端经 Tauri IPC spawn claude/codex CLI,
4
+ * 经事件流式回传)——所以这部分由宿主实现 `AgentRunner` 注入,aixautots 不依赖 Tauri。
5
+ *
6
+ * 非桌面/无本地 agent 的宿主可传 `available: false`,面板会显示「需在桌面应用中使用」。
7
+ *
8
+ * ── 实现是可替换的:Tauri 只是其中一种 ──
9
+ * 本接口刻意与传输解耦,`AgentPanel` 不知底层是本机还是服务端。已有/可有的实现:
10
+ * 1) 本机 CLI(现状):桌面端 `frontend/src/lib/agentRunner.ts` 用 Tauri `invoke`/`listen`
11
+ * spawn 本机 claude/codex CLI(密钥/算力在用户机器)。
12
+ * 2) 服务端 agent:服务器跑 claude/codex CLI(密钥/算力在后端),HTTP 起停 + SSE 流式
13
+ * 回传。**SDK 已内置实现** `createBackendAgentRunner(client)`(见 `backend-agent-runner.ts`);
14
+ * editor 薄壳按环境切换即可,aixautots 与 AgentPanel 零改动:
15
+ * agentRunner={isTauri() ? tauriAgentRunner : createBackendAgentRunner(client)}
16
+ * (仅待后端落地 `/api/agent/*` 端点;客户端侧已就绪。)
17
+ *
18
+ * 后端端点契约(详见 `backend-agent-runner.ts`):`POST /api/agent/{start,send,stop}` +
19
+ * `GET /api/agent/stream`(SSE);事件载荷映射到本文件的 `AgentStreamEvent`
20
+ * (`stream: 'stdout'|'stderr'|'done'`,done 带最终 `script` 全文)。鉴权复用 user JWT。
21
+ * 失败可经 `stream:'stderr'` 文本上报,或 `done` 不带 `script` 表示无产出。
22
+ */
23
+ type AgentKind = 'claude' | 'codex';
24
+ interface AgentStreamEvent {
25
+ /** 该事件所属脚本 id(面板按当前 scriptId 过滤)。 */
26
+ scriptId: string;
27
+ stream: 'stdout' | 'stderr' | 'done';
28
+ /** stdout/stderr 增量文本。 */
29
+ chunk?: string;
30
+ /** done 时回带的最终 script.ts 全文(非空且有变化则替换编辑器)。 */
31
+ script?: string;
32
+ }
33
+ interface AgentSendRequest {
34
+ agent: AgentKind;
35
+ scriptId: string;
36
+ code: string;
37
+ deviceId: string;
38
+ userMsg: string;
39
+ /** 本轮是否是会话首轮(决定 start vs send 语义,由实现自行处理)。 */
40
+ isFirst: boolean;
41
+ }
42
+ interface AgentRunner {
43
+ /** 本机 agent 后端是否可用(如桌面/Tauri 环境)。false 时面板显示提示而不渲染交互。 */
44
+ available: boolean;
45
+ /** 可选:从宿主设置读默认 agent / 权限模式(面板挂载时调用)。 */
46
+ defaults?: () => Promise<{
47
+ agent?: AgentKind;
48
+ }>;
49
+ /** 启动或继续一轮 agent。权限模式等宿主细节由实现内部处理。 */
50
+ send: (req: AgentSendRequest) => Promise<void>;
51
+ /** 停止进行中的一轮。 */
52
+ stop: (scriptId: string) => Promise<void>;
53
+ /** 订阅流式输出;返回取消订阅函数。面板内部按 scriptId 过滤事件。 */
54
+ subscribe: (on: (ev: AgentStreamEvent) => void) => () => void;
55
+ }
56
+
57
+ export type { AgentKind as A, AgentRunner as a, AgentSendRequest as b, AgentStreamEvent as c };
@@ -0,0 +1,72 @@
1
+ import { a as RunEventKind, A as AixConfig, R as ResolvedConfig } from './config-fsx4jlLK.js';
2
+ import { S as Script } from './types-C2WXVcam.js';
3
+
4
+ interface FlowSubmit {
5
+ /** Inline flow JSON (XOR scriptId). */
6
+ flow?: unknown;
7
+ /** Reference a stored script by id (XOR flow). */
8
+ scriptId?: string;
9
+ /** Internal device UUIDs (non-empty). */
10
+ deviceIds: string[];
11
+ params?: unknown;
12
+ mode?: unknown;
13
+ expiresIn?: number;
14
+ }
15
+ /** A normalized per-device execution event. */
16
+ interface FlowEvent {
17
+ deviceId: string;
18
+ event: RunEventKind;
19
+ }
20
+ declare class FlowRun {
21
+ readonly taskId: string;
22
+ readonly targets: string[];
23
+ private readonly socket;
24
+ private readonly eventListeners;
25
+ private readonly doneListeners;
26
+ private readonly finished;
27
+ private doneFired;
28
+ private cursor;
29
+ private constructor();
30
+ static submit(cfg: AixConfig | ResolvedConfig, body: FlowSubmit): Promise<FlowRun>;
31
+ on(event: 'event', cb: (e: FlowEvent) => void): () => void;
32
+ on(event: 'done', cb: () => void): () => void;
33
+ /** Called (via microtask) when submit() returns targets:[]. */
34
+ fireDoneIfEmpty(): void;
35
+ private onMessage;
36
+ close(): void;
37
+ }
38
+
39
+ /** 批次派发模式。`'round-robin'` 为默认(行分摊到设备);`'broadcast'` 每行全量。 */
40
+ type QueueMode = 'round-robin' | 'broadcast';
41
+ /** 一个批次的输入。`script` 与 `flow` 二选一(与 `FlowRun`/后端的 flow XOR
42
+ * script 约束一致)。`rows` 每项是一组动态参数值(覆写 `flow.variables`);空
43
+ * 数组等价于「无参数」单组(提交一次,沿用脚本自带 variables)。 */
44
+ interface BatchConfig {
45
+ /** 引用已存库脚本(XOR flow)。 */
46
+ script?: Pick<Script, 'id'> & {
47
+ id: string;
48
+ };
49
+ /** 内联 flow JSON(XOR script)。 */
50
+ flow?: unknown;
51
+ /** 每行 = 一组动态参数(如不同账户)。空 ⇒ 视作单组空参数,提交一次。 */
52
+ rows: Array<Record<string, unknown>>;
53
+ /** 目标设备内部 UUID(非空)。 */
54
+ deviceIds: string[];
55
+ /** 派发模式,默认 `'round-robin'`。 */
56
+ mode?: QueueMode;
57
+ /** 透传给 `FlowRun.submit` 的任务过期秒数(可选)。 */
58
+ expiresIn?: number;
59
+ }
60
+ /** 把 rows×mode 展开为多次 `FlowRun.submit`,返回每次提交得到的 task id 顺序数组。
61
+ * 逐行顺序提交(保留行序);任一行失败即抛出(已提交的行不回滚——它们是独立任务)。 */
62
+ declare function submitBatch(cfg: AixConfig | ResolvedConfig, config: BatchConfig): Promise<string[]>;
63
+ /** 自动化队列的薄封装:绑定一份 config,`submit(batch)` 即提交。无状态——
64
+ * 追踪/暂停/恢复由 `TasksApi`(`useAutomationQueue`)负责。 */
65
+ declare class AutomationQueue {
66
+ private readonly cfg;
67
+ constructor(cfg: AixConfig | ResolvedConfig);
68
+ /** 展开并提交一个批次,返回 task id 数组。见 [`submitBatch`]。 */
69
+ submit(config: BatchConfig): Promise<string[]>;
70
+ }
71
+
72
+ export { AutomationQueue as A, type BatchConfig as B, type FlowEvent as F, type QueueMode as Q, FlowRun as a, type FlowSubmit as b, submitBatch as s };