Skip to content

Commit 9fe28d8

Browse files
committed
feat: add ui-tars Android operator for cli
1 parent 572683e commit 9fe28d8

File tree

14 files changed

+673
-12
lines changed

14 files changed

+673
-12
lines changed

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"js-yaml": "^4.1.0",
3838
"@clack/prompts": "^0.10.0",
3939
"@ui-tars/operator-nut-js": "workspace:*",
40+
"@ui-tars/operator-adb": "workspace:*",
4041
"@ui-tars/sdk": "workspace:*",
4142
"node-fetch": "^2.7.0"
4243
},

packages/cli/src/cli/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const run = () => {
1414
.command('start')
1515
.description('starting the ui-tars agent...')
1616
.option('-p, --presets <url>', 'Model Config Presets')
17+
.option('-t, --target <target>', 'The target operator')
18+
.option('-q, --query <query>', "Use's query")
1719
.action(async (options: CliOptions) => {
1820
try {
1921
await start(options);

packages/cli/src/cli/start.ts

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import * as p from '@clack/prompts';
1212
import yaml from 'js-yaml';
1313

1414
import { NutJSOperator } from '@ui-tars/operator-nut-js';
15+
import { getAndroidDeviceId, AdbOperator } from '@ui-tars/operator-adb';
1516

1617
export interface CliOptions {
1718
presets?: string;
19+
target?: string;
20+
query?: string;
1821
}
1922
export const start = async (options: CliOptions) => {
2023
const CONFIG_PATH = path.join(os.homedir(), '.ui-tars-cli.json');
@@ -73,17 +76,50 @@ export const start = async (options: CliOptions) => {
7376
}
7477
}
7578

76-
const answers = await p.group(
77-
{
78-
instruction: () => p.text({ message: 'Input your instruction' }),
79-
},
80-
{
81-
onCancel: () => {
82-
p.cancel('操作已取消');
79+
let targetOperator = null;
80+
const targetType =
81+
options.target ||
82+
((await p.select({
83+
message: 'Please select your operator target:',
84+
options: [
85+
{ value: 'nut-js', label: 'nut-js' },
86+
{ value: 'adb', label: 'adb' },
87+
],
88+
})) as string);
89+
90+
switch (targetType) {
91+
case 'adb':
92+
const deviceId = await getAndroidDeviceId();
93+
if (deviceId == null) {
94+
console.error(
95+
'No Android devices found. Please connect a device and try again.',
96+
);
8397
process.exit(0);
84-
},
85-
},
86-
);
98+
}
99+
targetOperator = new AdbOperator(deviceId);
100+
break;
101+
// case 'browser':
102+
// // TODO: implement browser operator
103+
// break;
104+
case 'nut-js':
105+
default:
106+
targetOperator = new NutJSOperator();
107+
break;
108+
}
109+
110+
const answers = options.query
111+
? { instruction: options.query }
112+
: await p.group(
113+
{
114+
instruction: () => p.text({ message: 'Input your instruction' }),
115+
},
116+
{
117+
onCancel: () => {
118+
p.cancel('操作已取消');
119+
process.exit(0);
120+
},
121+
},
122+
);
87123

88124
const abortController = new AbortController();
89125
process.on('SIGINT', () => {
@@ -96,7 +132,7 @@ export const start = async (options: CliOptions) => {
96132
apiKey: config.apiKey,
97133
model: config.model,
98134
},
99-
operator: new NutJSOperator(),
135+
operator: targetOperator,
100136
signal: abortController.signal,
101137
// onData: ({ data }) => {
102138
// console.log(

packages/operators/adb/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @ui-tars/operator-adb

packages/operators/adb/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# @ui-tars/operator-adb
2+
3+
Operator Android SDK for UI-TARS using ADB.
4+
5+
To enable Chinese text input via ADB, please install [ADBKeyBoard](https://github.com/senzhk/ADBKeyBoard/blob/master/ADBKeyboard.apk) and activate it in your device's Settings.
6+
7+
**Install ADBKeyBoard:**
8+
9+
```Shell
10+
adb install /path/to/AdbKeyboard.apk
11+
```
12+
13+
**Activate ADBKeyBoard:**
14+
15+
```Shell
16+
adb shell ime set com.android.adbkeyboard/.AdbIME
17+
```

packages/operators/adb/package.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@ui-tars/operator-adb",
3+
"version": "1.0.0",
4+
"description": "Operator Android SDK for UI-TARS",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/bytedance/UI-TARS-desktop"
8+
},
9+
"bugs": {
10+
"url": "https://github.com/bytedance/UI-TARS-desktop/issues"
11+
},
12+
"keywords": [
13+
"AI",
14+
"Core",
15+
"SDK",
16+
"Operator",
17+
"UI-TARS"
18+
],
19+
"main": "./dist/index.js",
20+
"module": "./dist/index.mjs",
21+
"types": "./dist/index.d.ts",
22+
"scripts": {
23+
"dev": "tsup --watch",
24+
"prepare": "npm run build",
25+
"build": "tsup",
26+
"test": "vitest"
27+
},
28+
"license": "Apache-2.0",
29+
"files": [
30+
"dist"
31+
],
32+
"publishConfig": {
33+
"access": "public",
34+
"registry": "https://registry.npmjs.org"
35+
},
36+
"dependencies": {
37+
"@ui-tars/shared": "workspace:*",
38+
"execa": "5.0.1",
39+
"inquirer": "8.2.4",
40+
"jimp": "1.6.0"
41+
},
42+
"devDependencies": {
43+
"@ui-tars/sdk": "workspace:*",
44+
"tsup": "^8.3.5",
45+
"typescript": "^5.7.2",
46+
"vitest": "^3.0.2",
47+
"@types/big.js": "^6.2.2",
48+
"@types/inquirer": "9.0.7"
49+
}
50+
}

0 commit comments

Comments
 (0)