Skip to content

Commit f3b5b45

Browse files
authored
feat: implement UTIO (UI-TARS Insights and Observation) (#60)
1 parent 961d70f commit f3b5b45

File tree

17 files changed

+346
-58
lines changed

17 files changed

+346
-58
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@electron-toolkit/utils": "^3.0.0",
4545
"@ui-tars/action-parser": "workspace:*",
4646
"@ui-tars/shared": "workspace:*",
47+
"@ui-tars/utio": "workspace:*",
4748
"async-retry": "^1.3.3",
4849
"big.js": "^6.2.2",
4950
"dotenv": "^16.4.7",

packages/utio/package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@ui-tars/utio",
3+
"version": "1.0.0",
4+
"description": "UTIO (UI-TARS Insights and Observation)",
5+
"main": "./dist/index.js",
6+
"module": "./dist/index.mjs",
7+
"types": "./dist/index.d.ts",
8+
"scripts": {
9+
"prepare": "npm run build",
10+
"dev": "tsup --watch",
11+
"build": "tsup",
12+
"prepack": "npm run build"
13+
},
14+
"keywords": [
15+
"UI-TARS"
16+
],
17+
"license": "Apache-2.0",
18+
"publishConfig": {
19+
"registry": "https://registry.npmjs.org/"
20+
},
21+
"files": [
22+
"dist",
23+
"src"
24+
],
25+
"dependencies": {},
26+
"devDependencies": {
27+
"tsup": "^8.3.5",
28+
"typescript": "^5.7.2"
29+
}
30+
}

packages/utio/src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { EventPayload, EventType } from './types';
2+
3+
export type { EventPayload as UTIOPayload };
4+
5+
export class UTIO {
6+
constructor(private readonly endpoint: string) {}
7+
8+
async send<T extends EventType>(data: EventPayload<T>): Promise<void> {
9+
if (!this.endpoint) return;
10+
11+
try {
12+
const response = await fetch(this.endpoint, {
13+
method: 'POST',
14+
headers: {
15+
'Content-Type': 'application/json',
16+
},
17+
body: JSON.stringify(data),
18+
});
19+
20+
if (!response.ok) {
21+
throw new Error(`UTIO upload failed with status: ${response.status}`);
22+
}
23+
} catch (error) {
24+
// Silent fail
25+
}
26+
}
27+
}

packages/utio/src/types.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* Supported event types
8+
*/
9+
export type EventType = 'appLaunched' | 'sendInstruction' | 'shareReport';
10+
11+
interface BaseEvent<T extends EventType> {
12+
type: T;
13+
}
14+
15+
/**
16+
* Application launched event
17+
*/
18+
export interface AppLaunchedEvent extends BaseEvent<'appLaunched'> {
19+
/** Platform type */
20+
platform: string;
21+
/** OS version in "major.minor.patch" format */
22+
osVersion: string;
23+
/** Screen width in pixels */
24+
screenWidth: number;
25+
/** Screen height in pixels */
26+
screenHeight: number;
27+
}
28+
29+
/**
30+
* User-sent instruction event
31+
*/
32+
export interface SendInstructionEvent extends BaseEvent<'sendInstruction'> {
33+
/** Instruction content */
34+
instruction: string;
35+
}
36+
37+
/**
38+
* Report sharing event
39+
*/
40+
export interface ShareReportEvent extends BaseEvent<'shareReport'> {
41+
/** Optional last screenshot path */
42+
lastScreenshot?: string;
43+
/** Optional report content */
44+
report?: string;
45+
/** Related instruction */
46+
instruction: string;
47+
}
48+
49+
/**
50+
* Event type to payload mapping
51+
*/
52+
export type EventPayloadMap = {
53+
appLaunched: AppLaunchedEvent;
54+
sendInstruction: SendInstructionEvent;
55+
shareReport: ShareReportEvent;
56+
};
57+
58+
/**
59+
* Utility type to extract payloads by event type
60+
*/
61+
export type EventPayload<T extends EventType> = EventPayloadMap[T];

packages/utio/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"moduleResolution": "Bundler",
6+
"declaration": true,
7+
"declarationMap": true,
8+
"sourceMap": true,
9+
"outDir": "./dist",
10+
"strict": true,
11+
"esModuleInterop": true,
12+
"forceConsistentCasingInFileNames": true,
13+
"resolveJsonModule": true,
14+
"isolatedModules": true,
15+
"skipLibCheck": true
16+
},
17+
"include": ["src/**/*"],
18+
"exclude": ["node_modules", "dist"]
19+
}

packages/utio/tsup.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { defineConfig } from 'tsup';
6+
7+
export default defineConfig((options) => {
8+
return {
9+
entry: ['src/**/*.ts'],
10+
format: ['esm', 'cjs'],
11+
dts: true,
12+
clean: true,
13+
bundle: false,
14+
outDir: 'dist',
15+
};
16+
});

0 commit comments

Comments
 (0)