askui 0.25.1 → 0.26.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/dist/cjs/core/models/anthropic/askui-agent.js +20 -32
- package/dist/cjs/core/models/anthropic/claude-agent.d.ts +16 -4
- package/dist/cjs/core/models/anthropic/claude-agent.js +43 -5
- package/dist/cjs/core/models/anthropic/index.d.ts +1 -2
- package/dist/cjs/core/models/anthropic/tools/os-agent-tools.d.ts +59 -5
- package/dist/cjs/core/models/anthropic/tools/os-agent-tools.js +340 -75
- package/dist/cjs/core/ui-control-commands/input-event.d.ts +3 -1
- package/dist/cjs/core/ui-control-commands/input-event.js +2 -0
- package/dist/cjs/execution/execution-runtime.d.ts +4 -0
- package/dist/cjs/execution/inference-client.d.ts +4 -0
- package/dist/cjs/execution/ui-control-client.d.ts +84 -34
- package/dist/cjs/execution/ui-control-client.js +4 -48
- package/dist/esm/core/models/anthropic/askui-agent.js +21 -33
- package/dist/esm/core/models/anthropic/claude-agent.d.ts +16 -4
- package/dist/esm/core/models/anthropic/claude-agent.js +43 -5
- package/dist/esm/core/models/anthropic/index.d.ts +1 -2
- package/dist/esm/core/models/anthropic/tools/os-agent-tools.d.ts +59 -5
- package/dist/esm/core/models/anthropic/tools/os-agent-tools.js +332 -72
- package/dist/esm/core/ui-control-commands/input-event.d.ts +3 -1
- package/dist/esm/core/ui-control-commands/input-event.js +2 -0
- package/dist/esm/execution/execution-runtime.d.ts +4 -0
- package/dist/esm/execution/inference-client.d.ts +4 -0
- package/dist/esm/execution/ui-control-client.d.ts +84 -34
- package/dist/esm/execution/ui-control-client.js +4 -48
- package/package.json +2 -2
|
@@ -37,9 +37,14 @@ class AskUIAgent extends claude_agent_1.ClaudeAgent {
|
|
|
37
37
|
new os_agent_tools_1.MouseMoveTool(this.osAgentHandler),
|
|
38
38
|
new os_agent_tools_1.MouseClickTool(this.osAgentHandler),
|
|
39
39
|
new os_agent_tools_1.MouseScrollTool(this.osAgentHandler),
|
|
40
|
-
new os_agent_tools_1.DesktopKeyPressSequenceTool(this.osAgentHandler),
|
|
41
|
-
new os_agent_tools_1.DesktopSingleKeyPressTool(this.osAgentHandler),
|
|
42
40
|
new os_agent_tools_1.TypeTool(this.osAgentHandler),
|
|
41
|
+
new os_agent_tools_1.DesktopPressAndReleaseKeysTool(this.osAgentHandler),
|
|
42
|
+
new os_agent_tools_1.DesktopKeyHoldDownTool(this.osAgentHandler),
|
|
43
|
+
new os_agent_tools_1.DesktopKeyReleaseTool(this.osAgentHandler),
|
|
44
|
+
new os_agent_tools_1.MouseHoldLeftButtonDownTool(this.osAgentHandler),
|
|
45
|
+
new os_agent_tools_1.MouseReleaseLeftButtonTool(this.osAgentHandler),
|
|
46
|
+
new os_agent_tools_1.MouseDragAndDropTool(this.osAgentHandler),
|
|
47
|
+
new os_agent_tools_1.WaitTool(),
|
|
43
48
|
];
|
|
44
49
|
this.setTools(tools);
|
|
45
50
|
this.setSystemPrompt(AskUIAgent.DesktopSystemPrompt);
|
|
@@ -60,6 +65,7 @@ class AskUIAgent extends claude_agent_1.ClaudeAgent {
|
|
|
60
65
|
new os_agent_tools_1.AndroidSequenceKeyPressTool(this.osAgentHandler),
|
|
61
66
|
new os_agent_tools_1.TypeTool(this.osAgentHandler),
|
|
62
67
|
new os_agent_tools_1.ExecuteShellCommandTool(this.osAgentHandler),
|
|
68
|
+
new os_agent_tools_1.WaitTool(),
|
|
63
69
|
];
|
|
64
70
|
this.setTools(tools);
|
|
65
71
|
this.setSystemPrompt(AskUIAgent.AndroidSystemPrompt);
|
|
@@ -70,22 +76,13 @@ exports.AskUIAgent = AskUIAgent;
|
|
|
70
76
|
AskUIAgent.DesktopSystemPrompt = `
|
|
71
77
|
<SYSTEM_CAPABILITY>
|
|
72
78
|
You are an autonomous AI assistant operating on a ${process.platform} machine with ${process.arch} architecture. You have full access to the system and internet connectivity.
|
|
73
|
-
Your main goal is to mimic a human user interacting with a desktop computer.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* PDF document handling and text extraction
|
|
81
|
-
* Error handling and recovery mechanisms
|
|
82
|
-
|
|
83
|
-
Available Tools:
|
|
84
|
-
* Mouse control (move, click, scroll)
|
|
85
|
-
* Keyboard input (single keys, key combinations, typing)
|
|
86
|
-
* Screen capture and analysis
|
|
87
|
-
* Error reporting and recovery
|
|
88
|
-
|
|
79
|
+
Your main goal is to mimic a human user interacting with a desktop computer.
|
|
80
|
+
Use a mouse and keyboard to interact with a computer, and take screenshots.
|
|
81
|
+
* This is an interface to a desktop GUI. You do not have access to a terminal or applications menu. You must click on desktop icons to start applications.
|
|
82
|
+
* Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions. E.g. if you click on Firefox and a window doesn't open, try taking another screenshot.
|
|
83
|
+
* Whenever you intend to move the cursor to click on an element like an icon, you should consult a screenshot to determine the coordinates of the element before moving the cursor.
|
|
84
|
+
* If you tried clicking on a program or link but it failed to load, even after waiting, try adjusting your cursor position so that the tip of the cursor visually falls on the element that you want to click.
|
|
85
|
+
* Make sure to click any buttons, links, icons, etc with the cursor tip in the center of the element. Don't click boxes on their edges unless asked.
|
|
89
86
|
Current Date: ${new Date().toUTCString()} UTC
|
|
90
87
|
</SYSTEM_CAPABILITY>
|
|
91
88
|
|
|
@@ -134,20 +131,11 @@ AskUIAgent.AndroidSystemPrompt = `
|
|
|
134
131
|
<SYSTEM_CAPABILITY>
|
|
135
132
|
You are an autonomous AI assistant operating on an Android device via ADB. The host machine is ${process.platform} with ${process.arch} architecture and internet connectivity.
|
|
136
133
|
Your main goal is to mimic a human user interacting with an Android device. So you should try to use the tools in a way that a human would use a touch screen to interact with an Android device.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* Android-specific key events
|
|
143
|
-
* Error handling and recovery mechanisms
|
|
144
|
-
|
|
145
|
-
Available Tools:
|
|
146
|
-
* Touch control (click, swipe, scroll)
|
|
147
|
-
* Android key events (single and sequence)
|
|
148
|
-
* Screen capture and analysis
|
|
149
|
-
* Error reporting and recovery
|
|
150
|
-
|
|
134
|
+
Use a gestures and adb commands to interact with the android device, and take screenshots.
|
|
135
|
+
* Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions. E.g. if you click on Firefox and a window doesn't open, try taking another screenshot.
|
|
136
|
+
* Whenever you intend to move the cursor to click on an element like an icon, you should consult a screenshot to determine the coordinates of the element before moving the cursor.
|
|
137
|
+
* If you tried clicking on a program or link but it failed to load, even after waiting, try adjusting your cursor position so that the tip of the cursor visually falls on the element that you want to click.
|
|
138
|
+
* Make sure to click any buttons, links, icons, etc with the cursor tip in the center of the element. Don't click boxes on their edges unless asked.
|
|
151
139
|
Current Date: ${new Date().toUTCString()} UTC
|
|
152
140
|
</SYSTEM_CAPABILITY>
|
|
153
141
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Beta } from '@anthropic-ai/sdk/resources';
|
|
2
2
|
import { BaseAgentTool } from './tools/base';
|
|
3
|
+
import { BetaMessageParam } from '@anthropic-ai/sdk/resources/beta/messages';
|
|
3
4
|
type PredictActResponseFunction = (params: {
|
|
4
5
|
max_tokens: number;
|
|
5
6
|
messages: Beta.BetaMessageParam[];
|
|
@@ -7,7 +8,16 @@ type PredictActResponseFunction = (params: {
|
|
|
7
8
|
system?: string;
|
|
8
9
|
tools?: any[];
|
|
9
10
|
betas?: string[];
|
|
11
|
+
tool_choice?: {
|
|
12
|
+
type: 'tool' | 'any' | 'auto';
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
10
15
|
}) => Promise<Beta.BetaMessage>;
|
|
16
|
+
export type AgentHistory = BetaMessageParam[];
|
|
17
|
+
export interface ActOptions {
|
|
18
|
+
chatId?: string;
|
|
19
|
+
agentHistory?: Beta.BetaMessageParam[];
|
|
20
|
+
}
|
|
11
21
|
export declare class ClaudeAgent {
|
|
12
22
|
private predictActResponseFunction;
|
|
13
23
|
private maxTokens;
|
|
@@ -19,7 +29,12 @@ export declare class ClaudeAgent {
|
|
|
19
29
|
private _toolCollection;
|
|
20
30
|
private tools;
|
|
21
31
|
private history;
|
|
32
|
+
private toolChoice;
|
|
22
33
|
constructor(predictActResponseFunction: PredictActResponseFunction);
|
|
34
|
+
setToolChoice(toolChoice: {
|
|
35
|
+
type: 'tool' | 'any' | 'auto';
|
|
36
|
+
name?: string;
|
|
37
|
+
}): void;
|
|
23
38
|
setTools(tools: BaseAgentTool[]): void;
|
|
24
39
|
addTool(tool: BaseAgentTool): void;
|
|
25
40
|
listToolNames(): string[];
|
|
@@ -29,10 +44,7 @@ export declare class ClaudeAgent {
|
|
|
29
44
|
private get toolCollection();
|
|
30
45
|
private setHistory;
|
|
31
46
|
private getHistory;
|
|
32
|
-
act(goal: string, options?:
|
|
33
|
-
chatId?: string;
|
|
34
|
-
agentHistory?: Beta.BetaMessageParam[];
|
|
35
|
-
}): Promise<Beta.BetaMessageParam[]>;
|
|
47
|
+
act(goal: string, imagePathOrBase64String?: string, options?: ActOptions): Promise<Beta.BetaMessageParam[]>;
|
|
36
48
|
private makeApiToolResult;
|
|
37
49
|
private maybePrependSystemToolResult;
|
|
38
50
|
private static filterNMostRecentImages;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ClaudeAgent = void 0;
|
|
13
13
|
const base_1 = require("./tools/base");
|
|
14
14
|
const logger_1 = require("../../../lib/logger");
|
|
15
|
+
const base_64_image_1 = require("../../../utils/base_64_image/base-64-image");
|
|
15
16
|
class ClaudeAgent {
|
|
16
17
|
constructor(predictActResponseFunction) {
|
|
17
18
|
this.predictActResponseFunction = predictActResponseFunction;
|
|
@@ -19,11 +20,17 @@ class ClaudeAgent {
|
|
|
19
20
|
this.onlyNMostRecentImages = 3;
|
|
20
21
|
this.imageTruncationThreshold = 10;
|
|
21
22
|
this.systemPrompt = '';
|
|
22
|
-
this.model = 'claude-
|
|
23
|
-
this.betas = ['computer-use-
|
|
23
|
+
this.model = 'claude-sonnet-4-20250514';
|
|
24
|
+
this.betas = ['computer-use-2025-01-24'];
|
|
24
25
|
this._toolCollection = undefined;
|
|
25
26
|
this.tools = [];
|
|
26
27
|
this.history = {};
|
|
28
|
+
this.toolChoice = {
|
|
29
|
+
type: 'any',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
setToolChoice(toolChoice) {
|
|
33
|
+
this.toolChoice = toolChoice;
|
|
27
34
|
}
|
|
28
35
|
setTools(tools) {
|
|
29
36
|
this._toolCollection = undefined;
|
|
@@ -40,7 +47,14 @@ class ClaudeAgent {
|
|
|
40
47
|
this.tools = this.tools.filter((tool) => tool.ToolName !== toolName);
|
|
41
48
|
}
|
|
42
49
|
setSystemPrompt(systemPrompt) {
|
|
43
|
-
|
|
50
|
+
const enhancedPrompt = `${systemPrompt}
|
|
51
|
+
If you cannot complete a request due to safety concerns, please:
|
|
52
|
+
1. Explain what specific aspect is problematic
|
|
53
|
+
2. Suggest alternative approaches that would be acceptable
|
|
54
|
+
3. Provide partial assistance where possible within guidelines.
|
|
55
|
+
Raise an exception After you have provided the above information. include the error message in the exception.
|
|
56
|
+
`;
|
|
57
|
+
this.systemPrompt = enhancedPrompt;
|
|
44
58
|
}
|
|
45
59
|
IsConfigured() {
|
|
46
60
|
return this.tools.length > 0 && this.systemPrompt !== '';
|
|
@@ -57,7 +71,7 @@ class ClaudeAgent {
|
|
|
57
71
|
getHistory(key) {
|
|
58
72
|
return this.history[key] || [];
|
|
59
73
|
}
|
|
60
|
-
act(goal, options) {
|
|
74
|
+
act(goal, imagePathOrBase64String, options) {
|
|
61
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
76
|
if (!goal.trim()) {
|
|
63
77
|
throw new Error('Goal cannot be empty');
|
|
@@ -73,8 +87,24 @@ class ClaudeAgent {
|
|
|
73
87
|
messages.push(...this.getHistory(options.chatId));
|
|
74
88
|
}
|
|
75
89
|
// Add the new goal as a user message
|
|
90
|
+
const userContent = [{
|
|
91
|
+
type: 'text',
|
|
92
|
+
text: goal,
|
|
93
|
+
}];
|
|
94
|
+
if (imagePathOrBase64String !== undefined) {
|
|
95
|
+
const image = yield base_64_image_1.Base64Image.fromPathOrString(imagePathOrBase64String);
|
|
96
|
+
const imageString = image.toString(false);
|
|
97
|
+
userContent.push({
|
|
98
|
+
type: 'image',
|
|
99
|
+
source: {
|
|
100
|
+
type: 'base64',
|
|
101
|
+
media_type: 'image/png',
|
|
102
|
+
data: imageString,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
76
106
|
messages.push({
|
|
77
|
-
content:
|
|
107
|
+
content: userContent,
|
|
78
108
|
role: 'user',
|
|
79
109
|
});
|
|
80
110
|
if (this.onlyNMostRecentImages) {
|
|
@@ -88,7 +118,15 @@ class ClaudeAgent {
|
|
|
88
118
|
system: this.systemPrompt,
|
|
89
119
|
tools: (new base_1.ToolCollection(this.tools).toParams()),
|
|
90
120
|
betas: this.betas,
|
|
121
|
+
tool_choice: this.toolChoice,
|
|
91
122
|
});
|
|
123
|
+
if (response.stop_reason === 'refusal') {
|
|
124
|
+
const refusalMessage = response.content
|
|
125
|
+
.filter(block => block.type === 'text')
|
|
126
|
+
.map(block => block.text)
|
|
127
|
+
.join(' ');
|
|
128
|
+
throw new Error(`Agent refused to answer: ${refusalMessage || 'The request violates agent\'s usage policies'}`);
|
|
129
|
+
}
|
|
92
130
|
messages.push({
|
|
93
131
|
content: response.content,
|
|
94
132
|
role: 'assistant',
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BetaMessageParam } from '@anthropic-ai/sdk/resources/beta/messages';
|
|
2
|
-
export type AgentHistory = BetaMessageParam[];
|
|
3
1
|
export { AskUIAgent } from './askui-agent';
|
|
4
2
|
export { ToolFailure, ToolError, BaseAgentTool } from './tools/base';
|
|
3
|
+
export { AgentHistory, ActOptions } from './claude-agent';
|
|
@@ -5,21 +5,36 @@ import { ExecutionRuntime } from '../../../../execution/execution-runtime';
|
|
|
5
5
|
import { ControlCommand } from '../../../ui-control-commands';
|
|
6
6
|
export declare class OsAgentHandler {
|
|
7
7
|
private AgentOsClient;
|
|
8
|
-
private
|
|
8
|
+
private targetResolution;
|
|
9
9
|
private screenDimensions;
|
|
10
|
+
private paddingInfo;
|
|
10
11
|
constructor(AgentOsClient: ExecutionRuntime, screenDimensions: {
|
|
11
12
|
width: number;
|
|
12
13
|
height: number;
|
|
13
14
|
});
|
|
15
|
+
private updatePaddingInfo;
|
|
14
16
|
static createInstance(AgentOsClient: ExecutionRuntime): Promise<OsAgentHandler>;
|
|
15
17
|
getTargetResolution(): {
|
|
16
18
|
width: number;
|
|
17
19
|
height: number;
|
|
18
20
|
};
|
|
21
|
+
getScreenDimensions(): {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
};
|
|
19
25
|
setTargetResolution(width: number, height: number): void;
|
|
20
26
|
takeScreenshot(): Promise<string>;
|
|
21
27
|
private scaleCoordinates;
|
|
22
28
|
requestControl(controlCommand: ControlCommand): Promise<void>;
|
|
29
|
+
mouseMove(x: number, y: number): Promise<void>;
|
|
30
|
+
mouseClick(button: "left" | "right" | "middle", doubleClick: boolean): Promise<void>;
|
|
31
|
+
mouseScroll(dx: number, dy: number): Promise<void>;
|
|
32
|
+
mouseHoldLeftButtonDown(): Promise<void>;
|
|
33
|
+
mouseReleaseLeftButton(): Promise<void>;
|
|
34
|
+
desktopKeyPressAndRelease(key: PC_AND_MODIFIER_KEY, modifiers?: MODIFIER_KEY[]): Promise<void>;
|
|
35
|
+
desktopKeyHoldDown(key: PC_AND_MODIFIER_KEY, modifiers?: MODIFIER_KEY[]): Promise<void>;
|
|
36
|
+
desktopKeyRelease(key: PC_AND_MODIFIER_KEY, modifiers?: MODIFIER_KEY[]): Promise<void>;
|
|
37
|
+
typeText(text: string): Promise<void>;
|
|
23
38
|
}
|
|
24
39
|
export declare class ScreenShotTool extends BaseAgentTool {
|
|
25
40
|
private osAgentHandler;
|
|
@@ -54,21 +69,53 @@ export declare class MouseScrollTool extends BaseAgentTool {
|
|
|
54
69
|
}): Promise<ToolResult>;
|
|
55
70
|
toParams(): BetaTool;
|
|
56
71
|
}
|
|
57
|
-
export declare class
|
|
72
|
+
export declare class MouseDragAndDropTool extends BaseAgentTool {
|
|
73
|
+
private osAgentHandler;
|
|
74
|
+
constructor(osAgentHandler: OsAgentHandler);
|
|
75
|
+
execute(command: {
|
|
76
|
+
startX: number;
|
|
77
|
+
startY: number;
|
|
78
|
+
endX: number;
|
|
79
|
+
endY: number;
|
|
80
|
+
}): Promise<ToolResult>;
|
|
81
|
+
toParams(): BetaTool;
|
|
82
|
+
}
|
|
83
|
+
export declare class MouseHoldLeftButtonDownTool extends BaseAgentTool {
|
|
84
|
+
private osAgentHandler;
|
|
85
|
+
constructor(osAgentHandler: OsAgentHandler);
|
|
86
|
+
execute(): Promise<ToolResult>;
|
|
87
|
+
toParams(): BetaTool;
|
|
88
|
+
}
|
|
89
|
+
export declare class MouseReleaseLeftButtonTool extends BaseAgentTool {
|
|
90
|
+
private osAgentHandler;
|
|
91
|
+
constructor(osAgentHandler: OsAgentHandler);
|
|
92
|
+
execute(): Promise<ToolResult>;
|
|
93
|
+
toParams(): BetaTool;
|
|
94
|
+
}
|
|
95
|
+
export declare class DesktopPressAndReleaseKeysTool extends BaseAgentTool {
|
|
58
96
|
private osAgentHandler;
|
|
59
97
|
constructor(osAgentHandler: OsAgentHandler);
|
|
60
98
|
execute(command: {
|
|
61
99
|
key: PC_KEY;
|
|
62
|
-
|
|
63
|
-
secondModifier?: MODIFIER_KEY;
|
|
100
|
+
modifiers?: MODIFIER_KEY[];
|
|
64
101
|
}): Promise<ToolResult>;
|
|
65
102
|
toParams(): BetaTool;
|
|
66
103
|
}
|
|
67
|
-
export declare class
|
|
104
|
+
export declare class DesktopKeyHoldDownTool extends BaseAgentTool {
|
|
68
105
|
private osAgentHandler;
|
|
69
106
|
constructor(osAgentHandler: OsAgentHandler);
|
|
70
107
|
execute(command: {
|
|
71
108
|
key: PC_AND_MODIFIER_KEY;
|
|
109
|
+
modifiers?: MODIFIER_KEY[];
|
|
110
|
+
}): Promise<ToolResult>;
|
|
111
|
+
toParams(): BetaTool;
|
|
112
|
+
}
|
|
113
|
+
export declare class DesktopKeyReleaseTool extends BaseAgentTool {
|
|
114
|
+
private osAgentHandler;
|
|
115
|
+
constructor(osAgentHandler: OsAgentHandler);
|
|
116
|
+
execute(command: {
|
|
117
|
+
key: PC_AND_MODIFIER_KEY;
|
|
118
|
+
modifiers?: MODIFIER_KEY[];
|
|
72
119
|
}): Promise<ToolResult>;
|
|
73
120
|
toParams(): BetaTool;
|
|
74
121
|
}
|
|
@@ -111,3 +158,10 @@ export declare class ExecuteShellCommandTool extends BaseAgentTool {
|
|
|
111
158
|
}): Promise<ToolResult>;
|
|
112
159
|
toParams(): BetaTool;
|
|
113
160
|
}
|
|
161
|
+
export declare class WaitTool extends BaseAgentTool {
|
|
162
|
+
constructor();
|
|
163
|
+
execute(command: {
|
|
164
|
+
milliseconds: number;
|
|
165
|
+
}): Promise<ToolResult>;
|
|
166
|
+
toParams(): BetaTool;
|
|
167
|
+
}
|