@causyne/agent 1.10.20 → 1.10.21
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/docs/THIRD_PARTY_NOTICES.md +44 -0
- package/package.json +1 -1
- package/src/computerUse/visionGrounding.js +249 -0
- package/src/computerUse/visionGrounding.ts +331 -0
- package/src/sandbox.js +4 -1
- package/src/toolPacks.js +5 -3
- package/src/tools/computerUse.js +139 -0
- package/src/tools/computerUse.ts +147 -0
- package/src/tools/desktopAct.d.ts +10 -0
- package/src/tools/registry.js +4 -1
- package/src/tools/uiForge.js +132 -0
- package/src/tools/uiForge.ts +145 -0
- package/src/uiEngine/uiForge.js +211 -0
- package/src/uiEngine/uiForge.ts +258 -0
|
@@ -61,6 +61,50 @@ adapted from the MIT-licensed Camofox Browser project at source commit
|
|
|
61
61
|
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
62
62
|
> SOFTWARE.
|
|
63
63
|
|
|
64
|
+
The computer-use action parser and coordinate grounding engine in `src/computerUse/visionGrounding.ts`
|
|
65
|
+
and `src/tools/computerUse.ts` power **Causyne Vision Desktop** (`computer_use`). Algorithms for coordinate
|
|
66
|
+
grounding and action grammar contain adaptations from upstream open-source work:
|
|
67
|
+
|
|
68
|
+
> Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
69
|
+
> Licensed under the Apache License, Version 2.0 (the "License");
|
|
70
|
+
> you may not use this file except in compliance with the License.
|
|
71
|
+
> You may obtain a copy of the License at
|
|
72
|
+
>
|
|
73
|
+
> http://www.apache.org/licenses/LICENSE-2.0
|
|
74
|
+
>
|
|
75
|
+
> Unless required by applicable law or agreed to in writing, software
|
|
76
|
+
> distributed under the License is distributed on an "AS IS" BASIS,
|
|
77
|
+
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
78
|
+
> See the License for the specific language governing permissions and
|
|
79
|
+
> limitations under the License.
|
|
80
|
+
|
|
81
|
+
The generative UI component and preview engine in `src/uiEngine/uiForge.ts` and
|
|
82
|
+
`src/tools/uiForge.ts` power **Causyne UI Forge** (`ui_forge`). Code generation algorithms
|
|
83
|
+
contain adaptations from upstream open-source work:
|
|
84
|
+
|
|
85
|
+
> MIT License
|
|
86
|
+
>
|
|
87
|
+
> Copyright (c) 2011-2024 Thesys Inc.
|
|
88
|
+
>
|
|
89
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
90
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
91
|
+
> in the Software without restriction, including without limitation the rights
|
|
92
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
93
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
94
|
+
> furnished to do so, subject to the following conditions:
|
|
95
|
+
>
|
|
96
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
97
|
+
> copies or substantial portions of the Software.
|
|
98
|
+
>
|
|
99
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
100
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
101
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
102
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
103
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
104
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
105
|
+
> SOFTWARE.
|
|
106
|
+
|
|
107
|
+
|
|
64
108
|
Repository scanning found no third-party copyright header or license marker in
|
|
65
109
|
the project-authored source and skill files. That negative scan alone cannot
|
|
66
110
|
establish authorship or permission. On 2026-10-19, the licensor confirmed that
|
package/package.json
CHANGED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*
|
|
5
|
+
* Adapted for Causyne Vision Desktop & Coordinate Grounding Engine.
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_FACTOR = [1000, 1000];
|
|
8
|
+
/**
|
|
9
|
+
* Extract numbers from a coordinate string like "(250, 400)" or "[100, 200, 300, 400]"
|
|
10
|
+
*/
|
|
11
|
+
export function extractCoordinateNumbers(raw) {
|
|
12
|
+
const clean = String(raw || '').replace(/[()[\]]/g, ' ').trim();
|
|
13
|
+
if (!clean)
|
|
14
|
+
return [];
|
|
15
|
+
return clean
|
|
16
|
+
.split(/[\s,]+/)
|
|
17
|
+
.map((s) => Number.parseFloat(s))
|
|
18
|
+
.filter((n) => Number.isFinite(n));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Ground normalized coordinates (0-1000) to actual screen pixels.
|
|
22
|
+
*/
|
|
23
|
+
export function groundPoint(nums, screen = { width: 1920, height: 1080, scaleFactor: 1 }, factor = DEFAULT_FACTOR) {
|
|
24
|
+
if (nums.length < 2)
|
|
25
|
+
return null;
|
|
26
|
+
const rawX = nums[0] ?? 0;
|
|
27
|
+
const rawY = nums[1] ?? 0;
|
|
28
|
+
const scale = screen.scaleFactor || 1;
|
|
29
|
+
const normX = Math.max(0, Math.min(1, rawX / factor[0]));
|
|
30
|
+
const normY = Math.max(0, Math.min(1, rawY / factor[1]));
|
|
31
|
+
return {
|
|
32
|
+
x: Math.round(normX * screen.width * scale),
|
|
33
|
+
y: Math.round(normY * screen.height * scale)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Ground a bounding box (x1, y1, x2, y2) into its midpoint (center click).
|
|
38
|
+
*/
|
|
39
|
+
export function groundBoxCenter(nums, screen = { width: 1920, height: 1080, scaleFactor: 1 }, factor = DEFAULT_FACTOR) {
|
|
40
|
+
if (nums.length < 2)
|
|
41
|
+
return null;
|
|
42
|
+
if (nums.length === 2) {
|
|
43
|
+
return groundPoint(nums, screen, factor);
|
|
44
|
+
}
|
|
45
|
+
const x1 = nums[0] ?? 0;
|
|
46
|
+
const y1 = nums[1] ?? 0;
|
|
47
|
+
const x2 = nums[2] ?? x1;
|
|
48
|
+
const y2 = nums[3] ?? y1;
|
|
49
|
+
const midX = (x1 + x2) / 2;
|
|
50
|
+
const midY = (y1 + y2) / 2;
|
|
51
|
+
return groundPoint([midX, midY], screen, factor);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parse vision grounding action format:
|
|
55
|
+
* E.g. Action: click(start_box='(240, 500)')
|
|
56
|
+
*/
|
|
57
|
+
export function parseSingleAction(rawAction, screenContext = { width: 1920, height: 1080, scaleFactor: 1 }) {
|
|
58
|
+
const line = rawAction.trim();
|
|
59
|
+
if (!line)
|
|
60
|
+
return null;
|
|
61
|
+
const callMatch = line.match(/^([a-zA-Z_0-9]+)\s*\((.*)\)$/);
|
|
62
|
+
if (!callMatch) {
|
|
63
|
+
if (/finished/i.test(line)) {
|
|
64
|
+
return { action: 'finished', rawStr: line };
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const funcName = callMatch[1]?.toLowerCase();
|
|
69
|
+
const argsRaw = callMatch[2] || '';
|
|
70
|
+
const argsMap = {};
|
|
71
|
+
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*['"]([^'"]+)['"]/g;
|
|
72
|
+
let match;
|
|
73
|
+
while ((match = kvRegex.exec(argsRaw)) !== null) {
|
|
74
|
+
const key = match[1];
|
|
75
|
+
const val = match[2];
|
|
76
|
+
if (key && val) {
|
|
77
|
+
argsMap[key] = val;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (Object.keys(argsMap).length === 0) {
|
|
81
|
+
const boxMatch = argsRaw.match(/['"]?(\([0-9\s,.]+\)|\[[0-9\s,.]+\])['"]?/);
|
|
82
|
+
if (boxMatch && boxMatch[1]) {
|
|
83
|
+
argsMap['start_box'] = boxMatch[1];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const actionObj = {
|
|
87
|
+
action: funcName,
|
|
88
|
+
rawStr: line
|
|
89
|
+
};
|
|
90
|
+
const startBox = argsMap['start_box'] || argsMap['point'] || argsMap['box'];
|
|
91
|
+
if (startBox) {
|
|
92
|
+
const nums = extractCoordinateNumbers(startBox);
|
|
93
|
+
const center = groundBoxCenter(nums, screenContext);
|
|
94
|
+
if (center) {
|
|
95
|
+
actionObj.coordinates = center;
|
|
96
|
+
actionObj.startCoordinates = center;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const endBox = argsMap['end_box'];
|
|
100
|
+
if (endBox) {
|
|
101
|
+
const nums = extractCoordinateNumbers(endBox);
|
|
102
|
+
const center = groundBoxCenter(nums, screenContext);
|
|
103
|
+
if (center) {
|
|
104
|
+
actionObj.endCoordinates = center;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (argsMap['content']) {
|
|
108
|
+
actionObj.text = argsMap['content'];
|
|
109
|
+
}
|
|
110
|
+
if (argsMap['text']) {
|
|
111
|
+
actionObj.text = argsMap['text'];
|
|
112
|
+
}
|
|
113
|
+
if (argsMap['key']) {
|
|
114
|
+
actionObj.key = argsMap['key'];
|
|
115
|
+
}
|
|
116
|
+
if (argsMap['direction']) {
|
|
117
|
+
const dir = argsMap['direction'].toLowerCase();
|
|
118
|
+
if (dir === 'up' || dir === 'down' || dir === 'left' || dir === 'right') {
|
|
119
|
+
actionObj.direction = dir;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (argsMap['time'] || argsMap['seconds']) {
|
|
123
|
+
const sec = Number.parseFloat(argsMap['time'] || argsMap['seconds'] || '1');
|
|
124
|
+
actionObj.seconds = Number.isFinite(sec) ? sec : 1;
|
|
125
|
+
}
|
|
126
|
+
return actionObj;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Parse complete vision grounding prediction text with Thought and Action blocks.
|
|
130
|
+
*/
|
|
131
|
+
export function parseVisionGroundingPrediction(predictionText, screenContext = { width: 1920, height: 1080, scaleFactor: 1 }) {
|
|
132
|
+
let thought;
|
|
133
|
+
let reflection;
|
|
134
|
+
const text = (predictionText || '').trim();
|
|
135
|
+
if (text.includes('Thought:')) {
|
|
136
|
+
const tMatch = text.match(/Thought:\s*([\s\S]+?)(?=\s*Action[::]|$)/i);
|
|
137
|
+
if (tMatch && tMatch[1]) {
|
|
138
|
+
thought = tMatch[1].trim();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (text.includes('Reflection:')) {
|
|
142
|
+
const rMatch = text.match(/Reflection:\s*([\s\S]+?)(?=\s*(?:Action_Summary|Action)[::]|$)/i);
|
|
143
|
+
if (rMatch && rMatch[1]) {
|
|
144
|
+
reflection = rMatch[1].trim();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const actionLines = [];
|
|
148
|
+
if (/Action[::]/i.test(text)) {
|
|
149
|
+
const parts = text.split(/Action[::]/i);
|
|
150
|
+
for (let i = 1; i < parts.length; i++) {
|
|
151
|
+
const seg = parts[i] || '';
|
|
152
|
+
const lines = seg.split(/\n+/).map((l) => l.trim()).filter(Boolean);
|
|
153
|
+
actionLines.push(...lines);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
actionLines.push(...text.split(/\n+/).map((l) => l.trim()).filter(Boolean));
|
|
158
|
+
}
|
|
159
|
+
const actions = [];
|
|
160
|
+
for (const line of actionLines) {
|
|
161
|
+
const parsed = parseSingleAction(line, screenContext);
|
|
162
|
+
if (parsed) {
|
|
163
|
+
if (thought && !parsed.thought)
|
|
164
|
+
parsed.thought = thought;
|
|
165
|
+
if (reflection && !parsed.reflection)
|
|
166
|
+
parsed.reflection = reflection;
|
|
167
|
+
actions.push(parsed);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { thought, reflection, actions };
|
|
171
|
+
}
|
|
172
|
+
const MAC_KEY_CODES = {
|
|
173
|
+
return: 36,
|
|
174
|
+
enter: 36,
|
|
175
|
+
tab: 48,
|
|
176
|
+
space: 49,
|
|
177
|
+
backspace: 51,
|
|
178
|
+
escape: 53,
|
|
179
|
+
esc: 53,
|
|
180
|
+
up: 126,
|
|
181
|
+
down: 125,
|
|
182
|
+
left: 123,
|
|
183
|
+
right: 124
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Convert parsed vision grounding actions into Causyne desktop_act equivalent instructions.
|
|
187
|
+
*/
|
|
188
|
+
export function visionGroundingToDesktopAct(actions) {
|
|
189
|
+
const result = [];
|
|
190
|
+
for (const act of actions) {
|
|
191
|
+
switch (act.action) {
|
|
192
|
+
case 'click':
|
|
193
|
+
case 'left_click':
|
|
194
|
+
case 'double_click':
|
|
195
|
+
case 'triple_click': {
|
|
196
|
+
const point = act.coordinates;
|
|
197
|
+
if (point) {
|
|
198
|
+
result.push({
|
|
199
|
+
verb: 'clickxy',
|
|
200
|
+
x: point.x,
|
|
201
|
+
y: point.y
|
|
202
|
+
});
|
|
203
|
+
if (act.action === 'double_click') {
|
|
204
|
+
result.push({ verb: 'clickxy', x: point.x, y: point.y });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case 'type': {
|
|
210
|
+
if (act.coordinates) {
|
|
211
|
+
result.push({ verb: 'clickxy', x: act.coordinates.x, y: act.coordinates.y });
|
|
212
|
+
}
|
|
213
|
+
if (act.text) {
|
|
214
|
+
result.push({ verb: 'type', text: act.text });
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case 'press_key':
|
|
219
|
+
case 'hotkey': {
|
|
220
|
+
const keyName = (act.key || '').toLowerCase().trim();
|
|
221
|
+
const code = MAC_KEY_CODES[keyName];
|
|
222
|
+
if (code !== undefined) {
|
|
223
|
+
result.push({ verb: 'key', keyCode: code });
|
|
224
|
+
}
|
|
225
|
+
else if (keyName) {
|
|
226
|
+
result.push({ verb: 'type', text: keyName });
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case 'wait': {
|
|
231
|
+
result.push({ verb: 'wait', seconds: act.seconds || 1 });
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case 'drag': {
|
|
235
|
+
if (act.startCoordinates) {
|
|
236
|
+
result.push({ verb: 'clickxy', x: act.startCoordinates.x, y: act.startCoordinates.y });
|
|
237
|
+
}
|
|
238
|
+
if (act.endCoordinates) {
|
|
239
|
+
result.push({ verb: 'clickxy', x: act.endCoordinates.x, y: act.endCoordinates.y });
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case 'finished':
|
|
244
|
+
default:
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*
|
|
5
|
+
* Adapted for Causyne Vision Desktop & Coordinate Grounding Engine.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface ScreenContext {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
scaleFactor?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ActionVerb =
|
|
15
|
+
| 'click'
|
|
16
|
+
| 'left_click'
|
|
17
|
+
| 'right_click'
|
|
18
|
+
| 'double_click'
|
|
19
|
+
| 'triple_click'
|
|
20
|
+
| 'middle_click'
|
|
21
|
+
| 'mouse_down'
|
|
22
|
+
| 'mouse_up'
|
|
23
|
+
| 'drag'
|
|
24
|
+
| 'move'
|
|
25
|
+
| 'type'
|
|
26
|
+
| 'press_key'
|
|
27
|
+
| 'hotkey'
|
|
28
|
+
| 'scroll'
|
|
29
|
+
| 'wait'
|
|
30
|
+
| 'finished';
|
|
31
|
+
|
|
32
|
+
export interface VisionAction {
|
|
33
|
+
action: ActionVerb;
|
|
34
|
+
thought?: string;
|
|
35
|
+
reflection?: string;
|
|
36
|
+
coordinates?: { x: number; y: number };
|
|
37
|
+
startCoordinates?: { x: number; y: number };
|
|
38
|
+
endCoordinates?: { x: number; y: number };
|
|
39
|
+
text?: string;
|
|
40
|
+
key?: string;
|
|
41
|
+
direction?: 'up' | 'down' | 'left' | 'right';
|
|
42
|
+
seconds?: number;
|
|
43
|
+
rawStr?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DesktopActEquivalent {
|
|
47
|
+
verb: 'press' | 'clickxy' | 'type' | 'key' | 'wait';
|
|
48
|
+
x?: number;
|
|
49
|
+
y?: number;
|
|
50
|
+
text?: string;
|
|
51
|
+
keyCode?: number;
|
|
52
|
+
target?: string;
|
|
53
|
+
seconds?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const DEFAULT_FACTOR: [number, number] = [1000, 1000];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Extract numbers from a coordinate string like "(250, 400)" or "[100, 200, 300, 400]"
|
|
60
|
+
*/
|
|
61
|
+
export function extractCoordinateNumbers(raw: string): number[] {
|
|
62
|
+
const clean = String(raw || '').replace(/[()[\]]/g, ' ').trim();
|
|
63
|
+
if (!clean) return [];
|
|
64
|
+
return clean
|
|
65
|
+
.split(/[\s,]+/)
|
|
66
|
+
.map((s) => Number.parseFloat(s))
|
|
67
|
+
.filter((n) => Number.isFinite(n));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Ground normalized coordinates (0-1000) to actual screen pixels.
|
|
72
|
+
*/
|
|
73
|
+
export function groundPoint(
|
|
74
|
+
nums: number[],
|
|
75
|
+
screen: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 },
|
|
76
|
+
factor: [number, number] = DEFAULT_FACTOR
|
|
77
|
+
): { x: number; y: number } | null {
|
|
78
|
+
if (nums.length < 2) return null;
|
|
79
|
+
const rawX = nums[0] ?? 0;
|
|
80
|
+
const rawY = nums[1] ?? 0;
|
|
81
|
+
const scale = screen.scaleFactor || 1;
|
|
82
|
+
|
|
83
|
+
const normX = Math.max(0, Math.min(1, rawX / factor[0]));
|
|
84
|
+
const normY = Math.max(0, Math.min(1, rawY / factor[1]));
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
x: Math.round(normX * screen.width * scale),
|
|
88
|
+
y: Math.round(normY * screen.height * scale)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Ground a bounding box (x1, y1, x2, y2) into its midpoint (center click).
|
|
94
|
+
*/
|
|
95
|
+
export function groundBoxCenter(
|
|
96
|
+
nums: number[],
|
|
97
|
+
screen: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 },
|
|
98
|
+
factor: [number, number] = DEFAULT_FACTOR
|
|
99
|
+
): { x: number; y: number } | null {
|
|
100
|
+
if (nums.length < 2) return null;
|
|
101
|
+
if (nums.length === 2) {
|
|
102
|
+
return groundPoint(nums, screen, factor);
|
|
103
|
+
}
|
|
104
|
+
const x1 = nums[0] ?? 0;
|
|
105
|
+
const y1 = nums[1] ?? 0;
|
|
106
|
+
const x2 = nums[2] ?? x1;
|
|
107
|
+
const y2 = nums[3] ?? y1;
|
|
108
|
+
|
|
109
|
+
const midX = (x1 + x2) / 2;
|
|
110
|
+
const midY = (y1 + y2) / 2;
|
|
111
|
+
return groundPoint([midX, midY], screen, factor);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Parse vision grounding action format:
|
|
116
|
+
* E.g. Action: click(start_box='(240, 500)')
|
|
117
|
+
*/
|
|
118
|
+
export function parseSingleAction(
|
|
119
|
+
rawAction: string,
|
|
120
|
+
screenContext: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 }
|
|
121
|
+
): VisionAction | null {
|
|
122
|
+
const line = rawAction.trim();
|
|
123
|
+
if (!line) return null;
|
|
124
|
+
|
|
125
|
+
const callMatch = line.match(/^([a-zA-Z_0-9]+)\s*\((.*)\)$/);
|
|
126
|
+
if (!callMatch) {
|
|
127
|
+
if (/finished/i.test(line)) {
|
|
128
|
+
return { action: 'finished', rawStr: line };
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const funcName = callMatch[1]?.toLowerCase() as ActionVerb;
|
|
134
|
+
const argsRaw = callMatch[2] || '';
|
|
135
|
+
|
|
136
|
+
const argsMap: Record<string, string> = {};
|
|
137
|
+
const kvRegex = /([a-zA-Z_0-9]+)\s*=\s*['"]([^'"]+)['"]/g;
|
|
138
|
+
let match: RegExpExecArray | null;
|
|
139
|
+
while ((match = kvRegex.exec(argsRaw)) !== null) {
|
|
140
|
+
const key = match[1];
|
|
141
|
+
const val = match[2];
|
|
142
|
+
if (key && val) {
|
|
143
|
+
argsMap[key] = val;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (Object.keys(argsMap).length === 0) {
|
|
148
|
+
const boxMatch = argsRaw.match(/['"]?(\([0-9\s,.]+\)|\[[0-9\s,.]+\])['"]?/);
|
|
149
|
+
if (boxMatch && boxMatch[1]) {
|
|
150
|
+
argsMap['start_box'] = boxMatch[1];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const actionObj: VisionAction = {
|
|
155
|
+
action: funcName,
|
|
156
|
+
rawStr: line
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const startBox = argsMap['start_box'] || argsMap['point'] || argsMap['box'];
|
|
160
|
+
if (startBox) {
|
|
161
|
+
const nums = extractCoordinateNumbers(startBox);
|
|
162
|
+
const center = groundBoxCenter(nums, screenContext);
|
|
163
|
+
if (center) {
|
|
164
|
+
actionObj.coordinates = center;
|
|
165
|
+
actionObj.startCoordinates = center;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const endBox = argsMap['end_box'];
|
|
170
|
+
if (endBox) {
|
|
171
|
+
const nums = extractCoordinateNumbers(endBox);
|
|
172
|
+
const center = groundBoxCenter(nums, screenContext);
|
|
173
|
+
if (center) {
|
|
174
|
+
actionObj.endCoordinates = center;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (argsMap['content']) {
|
|
179
|
+
actionObj.text = argsMap['content'];
|
|
180
|
+
}
|
|
181
|
+
if (argsMap['text']) {
|
|
182
|
+
actionObj.text = argsMap['text'];
|
|
183
|
+
}
|
|
184
|
+
if (argsMap['key']) {
|
|
185
|
+
actionObj.key = argsMap['key'];
|
|
186
|
+
}
|
|
187
|
+
if (argsMap['direction']) {
|
|
188
|
+
const dir = argsMap['direction'].toLowerCase();
|
|
189
|
+
if (dir === 'up' || dir === 'down' || dir === 'left' || dir === 'right') {
|
|
190
|
+
actionObj.direction = dir;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (argsMap['time'] || argsMap['seconds']) {
|
|
194
|
+
const sec = Number.parseFloat(argsMap['time'] || argsMap['seconds'] || '1');
|
|
195
|
+
actionObj.seconds = Number.isFinite(sec) ? sec : 1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return actionObj;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Parse complete vision grounding prediction text with Thought and Action blocks.
|
|
203
|
+
*/
|
|
204
|
+
export function parseVisionGroundingPrediction(
|
|
205
|
+
predictionText: string,
|
|
206
|
+
screenContext: ScreenContext = { width: 1920, height: 1080, scaleFactor: 1 }
|
|
207
|
+
): { thought?: string | undefined; reflection?: string | undefined; actions: VisionAction[] } {
|
|
208
|
+
let thought: string | undefined;
|
|
209
|
+
let reflection: string | undefined;
|
|
210
|
+
|
|
211
|
+
const text = (predictionText || '').trim();
|
|
212
|
+
|
|
213
|
+
if (text.includes('Thought:')) {
|
|
214
|
+
const tMatch = text.match(/Thought:\s*([\s\S]+?)(?=\s*Action[::]|$)/i);
|
|
215
|
+
if (tMatch && tMatch[1]) {
|
|
216
|
+
thought = tMatch[1].trim();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (text.includes('Reflection:')) {
|
|
220
|
+
const rMatch = text.match(/Reflection:\s*([\s\S]+?)(?=\s*(?:Action_Summary|Action)[::]|$)/i);
|
|
221
|
+
if (rMatch && rMatch[1]) {
|
|
222
|
+
reflection = rMatch[1].trim();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const actionLines: string[] = [];
|
|
227
|
+
if (/Action[::]/i.test(text)) {
|
|
228
|
+
const parts = text.split(/Action[::]/i);
|
|
229
|
+
for (let i = 1; i < parts.length; i++) {
|
|
230
|
+
const seg = parts[i] || '';
|
|
231
|
+
const lines = seg.split(/\n+/).map((l) => l.trim()).filter(Boolean);
|
|
232
|
+
actionLines.push(...lines);
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
actionLines.push(...text.split(/\n+/).map((l) => l.trim()).filter(Boolean));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const actions: VisionAction[] = [];
|
|
239
|
+
|
|
240
|
+
for (const line of actionLines) {
|
|
241
|
+
const parsed = parseSingleAction(line, screenContext);
|
|
242
|
+
if (parsed) {
|
|
243
|
+
if (thought && !parsed.thought) parsed.thought = thought;
|
|
244
|
+
if (reflection && !parsed.reflection) parsed.reflection = reflection;
|
|
245
|
+
actions.push(parsed);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return { thought, reflection, actions };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const MAC_KEY_CODES: Record<string, number> = {
|
|
253
|
+
return: 36,
|
|
254
|
+
enter: 36,
|
|
255
|
+
tab: 48,
|
|
256
|
+
space: 49,
|
|
257
|
+
backspace: 51,
|
|
258
|
+
escape: 53,
|
|
259
|
+
esc: 53,
|
|
260
|
+
up: 126,
|
|
261
|
+
down: 125,
|
|
262
|
+
left: 123,
|
|
263
|
+
right: 124
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Convert parsed vision grounding actions into Causyne desktop_act equivalent instructions.
|
|
268
|
+
*/
|
|
269
|
+
export function visionGroundingToDesktopAct(actions: VisionAction[]): DesktopActEquivalent[] {
|
|
270
|
+
const result: DesktopActEquivalent[] = [];
|
|
271
|
+
|
|
272
|
+
for (const act of actions) {
|
|
273
|
+
switch (act.action) {
|
|
274
|
+
case 'click':
|
|
275
|
+
case 'left_click':
|
|
276
|
+
case 'double_click':
|
|
277
|
+
case 'triple_click': {
|
|
278
|
+
const point = act.coordinates;
|
|
279
|
+
if (point) {
|
|
280
|
+
result.push({
|
|
281
|
+
verb: 'clickxy',
|
|
282
|
+
x: point.x,
|
|
283
|
+
y: point.y
|
|
284
|
+
});
|
|
285
|
+
if (act.action === 'double_click') {
|
|
286
|
+
result.push({ verb: 'clickxy', x: point.x, y: point.y });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case 'type': {
|
|
292
|
+
if (act.coordinates) {
|
|
293
|
+
result.push({ verb: 'clickxy', x: act.coordinates.x, y: act.coordinates.y });
|
|
294
|
+
}
|
|
295
|
+
if (act.text) {
|
|
296
|
+
result.push({ verb: 'type', text: act.text });
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
case 'press_key':
|
|
301
|
+
case 'hotkey': {
|
|
302
|
+
const keyName = (act.key || '').toLowerCase().trim();
|
|
303
|
+
const code = MAC_KEY_CODES[keyName];
|
|
304
|
+
if (code !== undefined) {
|
|
305
|
+
result.push({ verb: 'key', keyCode: code });
|
|
306
|
+
} else if (keyName) {
|
|
307
|
+
result.push({ verb: 'type', text: keyName });
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case 'wait': {
|
|
312
|
+
result.push({ verb: 'wait', seconds: act.seconds || 1 });
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
case 'drag': {
|
|
316
|
+
if (act.startCoordinates) {
|
|
317
|
+
result.push({ verb: 'clickxy', x: act.startCoordinates.x, y: act.startCoordinates.y });
|
|
318
|
+
}
|
|
319
|
+
if (act.endCoordinates) {
|
|
320
|
+
result.push({ verb: 'clickxy', x: act.endCoordinates.x, y: act.endCoordinates.y });
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case 'finished':
|
|
325
|
+
default:
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return result;
|
|
331
|
+
}
|
package/src/sandbox.js
CHANGED
|
@@ -357,9 +357,12 @@ export class Sandbox {
|
|
|
357
357
|
|
|
358
358
|
// Mode C. Section 4 says gated, not walled — the capability is real, the
|
|
359
359
|
// human just says yes first.
|
|
360
|
-
if (toolName === 'desktop_act') {
|
|
360
|
+
if (toolName === 'desktop_act' || toolName === 'computer_use') {
|
|
361
361
|
return { allowed: true, risk: 'extreme' };
|
|
362
362
|
}
|
|
363
|
+
if (toolName === 'ui_forge') {
|
|
364
|
+
return { allowed: true, risk: 'safe' };
|
|
365
|
+
}
|
|
363
366
|
if (toolName === 'fs_write' || toolName === 'fs_move' || toolName === 'fs_edit' || toolName === 'MultiEdit') {
|
|
364
367
|
return { allowed: true, risk: 'moderate' };
|
|
365
368
|
}
|
package/src/toolPacks.js
CHANGED
|
@@ -76,7 +76,8 @@ export const PACKS = {
|
|
|
76
76
|
'screenshot',
|
|
77
77
|
'vision_inspect_ui',
|
|
78
78
|
'view_image',
|
|
79
|
-
'astryx_oracle'
|
|
79
|
+
'astryx_oracle',
|
|
80
|
+
'ui_forge'
|
|
80
81
|
],
|
|
81
82
|
media: [
|
|
82
83
|
'generate_media_via_api',
|
|
@@ -96,6 +97,7 @@ export const PACKS = {
|
|
|
96
97
|
// Channel C. Ships beside its observer on purpose: acting on a screen you
|
|
97
98
|
// have not read is how an agent clicks the wrong button confidently.
|
|
98
99
|
'desktop_act',
|
|
100
|
+
'computer_use',
|
|
99
101
|
'process_list',
|
|
100
102
|
'proc_term',
|
|
101
103
|
'archive',
|
|
@@ -362,11 +364,11 @@ When the user asks you to build, create, test, expand, or develop ANY game, you
|
|
|
362
364
|
|
|
363
365
|
const GAME_INTENT = /\b(game|games|gamedev|permainan|godot|unity|unreal|rpg|platformer|roguelike|arcade|sprite|spritesheet|tilemap|voxel|minecraft|aetheria|voxellia|nes|snes|gameplay|player character|level design|boss fight)\b|\.(tscn|gd)\b/i;
|
|
364
366
|
|
|
365
|
-
const WEB_INTENT = /\b(web|webpage|website|situs|frontend|front-end|landing page|homepage|dashboard|portfolio|html|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive)\b/i;
|
|
367
|
+
const WEB_INTENT = /\b(web|webpage|website|situs|frontend|front-end|landing page|homepage|dashboard|portfolio|html|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component)\b/i;
|
|
366
368
|
|
|
367
369
|
const MEDIA_INTENT = /\b(image|images|picture|photo|gambar|render|3d model|blender|animation|animate|video|movie|film|klip|audio|sound|sfx|music|musik|song|lagu|voice|suara|tts|text.to.speech|narration|podcast|thumbnail|poster|illustration|logo)\b/i;
|
|
368
370
|
|
|
369
|
-
const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|compress|extract|clipboard|copy to clipboard|print|printer|cetak|open in browser|launch app)\b/i;
|
|
371
|
+
const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|compress|extract|clipboard|copy to clipboard|print|printer|cetak|open in browser|launch app|computer use|vision grounding|desktop vision|gui agent|coordinate click|desktop control)\b/i;
|
|
370
372
|
|
|
371
373
|
const ADVANCED_INTENT = /\b(pdf|forge a tool|custom tool|new tool|plugin|plugins|custom plugin|subagent|sub-agent|parallel agent|swarm|ast|symbols|refactor across)\b/i;
|
|
372
374
|
|