shellx-ai 1.0.0
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.
- package/README.md +335 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +14 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.js +398 -0
- package/dist/protocol.d.ts +319 -0
- package/dist/protocol.js +2 -0
- package/dist/shellx.d.ts +175 -0
- package/dist/shellx.js +866 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +37 -0
- package/package.json +61 -0
package/dist/shellx.d.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { ElementSelector, ActionSequence, UIElement, ScreenShotOptions, WsServer } from './protocol';
|
|
2
|
+
import WebSocketTaskClient from './index';
|
|
3
|
+
export type { UIElement, ElementSelector, ActionSequence };
|
|
4
|
+
export { ShellX as AutomationHelpers };
|
|
5
|
+
export { createShellX as createHelpers };
|
|
6
|
+
export { createShellXWithShellMonitoring as createHelpersWithShellMonitoring };
|
|
7
|
+
interface ShellCommandResult {
|
|
8
|
+
success: boolean;
|
|
9
|
+
output: string;
|
|
10
|
+
error?: string;
|
|
11
|
+
exitCode?: number;
|
|
12
|
+
duration: number;
|
|
13
|
+
}
|
|
14
|
+
interface ShellCommandOptions {
|
|
15
|
+
title?: string;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
waitAfterMs?: number;
|
|
18
|
+
onOutput?: (output: string) => void;
|
|
19
|
+
onError?: (error: string) => void;
|
|
20
|
+
expectedOutput?: string | RegExp;
|
|
21
|
+
successPattern?: string | RegExp;
|
|
22
|
+
errorPattern?: string | RegExp;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* ShellX automation utilities for common patterns
|
|
26
|
+
*/
|
|
27
|
+
export declare class ShellX {
|
|
28
|
+
private client;
|
|
29
|
+
private shellOutputBuffers;
|
|
30
|
+
private shellCommandPromises;
|
|
31
|
+
constructor(client: WebSocketTaskClient);
|
|
32
|
+
/**
|
|
33
|
+
* 设置 shell 输出监听器(需要在创建 WebSocketTaskClient 时调用)
|
|
34
|
+
*/
|
|
35
|
+
static createShellOutputHandler(helpers: ShellX): (message: WsServer) => void;
|
|
36
|
+
/**
|
|
37
|
+
* 处理 shell 输出数据
|
|
38
|
+
*/
|
|
39
|
+
handleShellOutput(chunks: [any, number, Uint8Array[]]): void;
|
|
40
|
+
/**
|
|
41
|
+
* 判断输出是否属于特定命令
|
|
42
|
+
*/
|
|
43
|
+
private isOutputForCommand;
|
|
44
|
+
/**
|
|
45
|
+
* 合并多个 session 的输出
|
|
46
|
+
*/
|
|
47
|
+
private combineSessionOutputs;
|
|
48
|
+
/**
|
|
49
|
+
* 检查输出是否包含提示符
|
|
50
|
+
*/
|
|
51
|
+
private containsPrompt;
|
|
52
|
+
/**
|
|
53
|
+
* 检查命令是否完成
|
|
54
|
+
*/
|
|
55
|
+
private checkCommandCompletion;
|
|
56
|
+
/**
|
|
57
|
+
* 检查输出是否包含错误指示器
|
|
58
|
+
*/
|
|
59
|
+
private hasErrorIndicators;
|
|
60
|
+
/**
|
|
61
|
+
* 判断命令是否完成(基于常见的提示符模式)
|
|
62
|
+
*/
|
|
63
|
+
private isCommandComplete;
|
|
64
|
+
/**
|
|
65
|
+
* 解析命令 Promise
|
|
66
|
+
*/
|
|
67
|
+
private resolveCommand;
|
|
68
|
+
/**
|
|
69
|
+
* 生成命令唯一标识
|
|
70
|
+
*/
|
|
71
|
+
private generateCommandKey;
|
|
72
|
+
/**
|
|
73
|
+
* Smart element finder with retry logic
|
|
74
|
+
*/
|
|
75
|
+
findElementWithRetry(selector: ElementSelector, maxRetries?: number, retryDelay?: number): Promise<UIElement | null>;
|
|
76
|
+
/**
|
|
77
|
+
* Smart multiple elements finder with retry logic
|
|
78
|
+
*/
|
|
79
|
+
findElementsWithRetry(selector: ElementSelector, maxRetries?: number, retryDelay?: number, options?: {
|
|
80
|
+
maxResults?: number;
|
|
81
|
+
visibleOnly?: boolean;
|
|
82
|
+
clickableOnly?: boolean;
|
|
83
|
+
}): Promise<UIElement[]>;
|
|
84
|
+
/**
|
|
85
|
+
* 打印元素信息的工具方法
|
|
86
|
+
*/
|
|
87
|
+
printElementInfo(element: UIElement, index?: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* 打印多个元素信息的工具方法
|
|
90
|
+
*/
|
|
91
|
+
printElementsInfo(elements: UIElement[], title?: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* Click element by text content
|
|
94
|
+
*/
|
|
95
|
+
clickByText(text: string, exact?: boolean): Promise<boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* Input text into field
|
|
98
|
+
*/
|
|
99
|
+
inputText(selector: ElementSelector, text: string, options?: {
|
|
100
|
+
clear?: boolean;
|
|
101
|
+
hideKeyboard?: boolean;
|
|
102
|
+
}): Promise<boolean>;
|
|
103
|
+
/**
|
|
104
|
+
* Swipe in a direction
|
|
105
|
+
*/
|
|
106
|
+
swipe(direction: 'up' | 'down' | 'left' | 'right', distance?: number, duration?: number): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Take screenshot and save info
|
|
109
|
+
*/
|
|
110
|
+
captureScreen(options?: ScreenShotOptions & {
|
|
111
|
+
saveInfo?: boolean;
|
|
112
|
+
}): Promise<import("./protocol").ScreenShotResponse>;
|
|
113
|
+
/**
|
|
114
|
+
* Wait for any of multiple elements to appear
|
|
115
|
+
*/
|
|
116
|
+
waitForAnyElement(selectors: ElementSelector[], timeout?: number): Promise<{
|
|
117
|
+
element: UIElement;
|
|
118
|
+
selectorIndex: number;
|
|
119
|
+
} | null>;
|
|
120
|
+
/**
|
|
121
|
+
* Login helper for common login flows
|
|
122
|
+
*/
|
|
123
|
+
performLogin(usernameSelector: ElementSelector, passwordSelector: ElementSelector, loginButtonSelector: ElementSelector, username: string, password: string): Promise<boolean>;
|
|
124
|
+
/**
|
|
125
|
+
* Navigate through app using a series of clicks
|
|
126
|
+
*/
|
|
127
|
+
navigateByPath(textPath: string[]): Promise<boolean>;
|
|
128
|
+
/**
|
|
129
|
+
* Scroll to find element
|
|
130
|
+
*/
|
|
131
|
+
scrollToFindElement(selector: ElementSelector, maxScrolls?: number, direction?: 'up' | 'down'): Promise<UIElement | null>;
|
|
132
|
+
/**
|
|
133
|
+
* Execute shell command action with output monitoring
|
|
134
|
+
*/
|
|
135
|
+
executeShellCommand(command: string, options?: ShellCommandOptions): Promise<ShellCommandResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Execute shell command with simple output (for backward compatibility)
|
|
138
|
+
*/
|
|
139
|
+
executeSimpleShellCommand(command: string, options?: {
|
|
140
|
+
title?: string;
|
|
141
|
+
timeout?: number;
|
|
142
|
+
waitAfterMs?: number;
|
|
143
|
+
}): Promise<ShellCommandResult>;
|
|
144
|
+
/**
|
|
145
|
+
* Execute multiple shell commands in sequence
|
|
146
|
+
*/
|
|
147
|
+
executeShellCommands(commands: Array<{
|
|
148
|
+
command: string;
|
|
149
|
+
title?: string;
|
|
150
|
+
waitAfterMs?: number;
|
|
151
|
+
}>, options?: {
|
|
152
|
+
continueOnError?: boolean;
|
|
153
|
+
timeout?: number;
|
|
154
|
+
}): Promise<ShellCommandResult[]>;
|
|
155
|
+
/**
|
|
156
|
+
* Common ADB commands helper
|
|
157
|
+
*/
|
|
158
|
+
adbCommand(command: string, options?: ShellCommandOptions): Promise<ShellCommandResult>;
|
|
159
|
+
/**
|
|
160
|
+
* Device info commands
|
|
161
|
+
*/
|
|
162
|
+
getDeviceInfo(): Promise<ShellCommandResult[]>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Create ShellX instance
|
|
166
|
+
*/
|
|
167
|
+
export declare function createShellX(client: WebSocketTaskClient): ShellX;
|
|
168
|
+
/**
|
|
169
|
+
* Create ShellX instance with automatic authentication and shell output monitoring
|
|
170
|
+
* 自动处理认证和连接,无需外部提供WebSocket URL
|
|
171
|
+
*/
|
|
172
|
+
export declare function createShellXWithShellMonitoring(config?: any): Promise<{
|
|
173
|
+
client: WebSocketTaskClient;
|
|
174
|
+
shellx: ShellX;
|
|
175
|
+
}>;
|