@aivin-labs/cli 1.0.57 → 1.0.60
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/bin/cli.mjs +2 -1
- package/bin/lib/auth.mjs +119 -88
- package/bin/lib/context.mjs +58 -5
- package/bin/lib/loginHandoff.mjs +87 -0
- package/bin/lib/openFile.mjs +29 -4
- package/bin/lib/remote/client.mjs +1456 -1454
- package/bin/lib/remote/credentials.mjs +131 -125
- package/bin/lib/remote/desktop/castAuth.mjs +274 -259
- package/bin/lib/remote/desktop/castConsent.mjs +155 -154
- package/bin/lib/remote/desktop/castTrust.mjs +220 -183
- package/bin/lib/remote/desktop/desktopCastSource.mjs +77 -31
- package/bin/lib/remote/desktop/strings.mjs +158 -138
- package/bin/lib/remote/desktop/traySource.mjs +89 -15
- package/bin/lib/remote/desktop/webrtcWorker.mjs +4 -0
- package/bin/lib/remote/dpapiHelper.mjs +91 -0
- package/bin/lib/remote/gui/index.mjs +839 -567
- package/bin/lib/remote/gui/windowsHostSource.mjs +2418 -2127
- package/bin/lib/remote/tokenStore.mjs +19 -2
- package/package.json +1 -1
|
@@ -1,567 +1,839 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { spawn } from 'child_process';
|
|
4
|
-
import { DeviceErrorCode, ToolGroup } from '../constants.mjs';
|
|
5
|
-
import { DeviceToolError, resolveInRoots } from '../sandbox.mjs';
|
|
6
|
-
import { showOSNotification } from '../notify.mjs';
|
|
7
|
-
import { PS_UTF8_PREFIX } from '../processes.mjs';
|
|
8
|
-
import { createWindowsHost } from './windowsHost.mjs';
|
|
9
|
-
import { isProtectedPromptWindow } from '../humanInput.mjs';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Tầng điều khiển giao diện (28/10/2026, đợt 1: Windows). Nhìn cửa sổ bằng cây trợ năng của hệ điều hành (UI Automation) + ảnh khi cây
|
|
13
|
-
* nghèo; thao tác theo "pattern" (Invoke / Value / Toggle…) trước, chuột / phím giả lập sau. Mọi thao tác ghi trả bằng chứng đọc lại
|
|
14
|
-
* sau khi làm (giá trị mới, tiêu đề cửa sổ, phần tử còn / mất).
|
|
15
|
-
*
|
|
16
|
-
* Đợt 2 (30/10/2026): cây nghèo → host đọc chữ trên ảnh bằng OCR có sẵn của Windows (chạy trên máy), mỗi cụm chữ thành node `<snap>.t<k>`
|
|
17
|
-
* click / gõ được — BE tìm "nút Ghi sổ" theo chữ thay vì nhờ VLM đoán toạ độ; `gui.wait_for` chờ phần tử / cửa sổ hiện ra hoặc mất đi
|
|
18
|
-
* thay cho observe lặp.
|
|
19
|
-
*
|
|
20
|
-
* Sàn cứng trên máy (BE không đổi được): không gõ vào ô mật khẩu (host chặn), không điều khiển ứng dụng nhạy cảm (`BLOCKED_PROCESSES`),
|
|
21
|
-
* máy chỉ mở thư mục (không toàn quyền) thì không điều khiển cửa sổ dòng lệnh / registry — không lách vùng thư mục bằng cách gõ lệnh
|
|
22
|
-
* vào terminal; người dùng đang dùng chuột / phím → dừng (`GUI_USER_ACTIVE`).
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/** Tiến trình không bao giờ điều khiển: quản lý mật khẩu, hộp nâng quyền, bảo mật hệ thống, màn hình khoá. */
|
|
26
|
-
const BLOCKED_PROCESSES = new Set([
|
|
27
|
-
'consent', 'credentialuihost', 'credentialuibroker', 'lockapp', 'logonui', 'securityhealthsystray', 'securityhealthhost', 'windowsdefender', 'msmpeng',
|
|
28
|
-
'keepass', 'keepassxc', '1password', 'bitwarden', 'lastpass', 'dashlane', 'enpass', 'nordpass', 'roboform',
|
|
29
|
-
]);
|
|
30
|
-
/**
|
|
31
|
-
* Chỉ cho khi máy toàn quyền — điều khiển được những thứ này là chạy lệnh tuỳ ý ngoài vùng thư mục: terminal / registry, và (30/10/2026)
|
|
32
|
-
* trình soạn code có terminal tích hợp + ứng dụng agent tự chạy lệnh (VS Code, Cursor, Claude…) — gõ vào terminal của VS Code hay nhờ panel
|
|
33
|
-
* Claude chạy lệnh cũng là lách vùng thư mục như gõ vào cmd.
|
|
34
|
-
*/
|
|
35
|
-
const SHELL_PROCESSES = new Set([
|
|
36
|
-
'cmd', 'powershell', 'pwsh', 'windowsterminal', 'wt', 'openconsole', 'conhost', 'regedit', 'mmc', 'taskmgr', 'wsl', 'bash', 'mintty',
|
|
37
|
-
'code', 'code - insiders', 'codium', 'cursor', 'windsurf', 'zed', 'devenv', 'idea64', 'pycharm64', 'webstorm64', 'rider64', 'goland64',
|
|
38
|
-
'claude', 'chatgpt', 'warp', 'alacritty', 'wezterm-gui', 'hyper', 'tabby',
|
|
39
|
-
]);
|
|
40
|
-
/** Cùng nhóm đó theo tên trong menu Start (`gui.open_app` tìm theo tên, khác tên tiến trình) — chặn trước khi mở. */
|
|
41
|
-
const SHELL_APP_NAME = /\b(command prompt|powershell|terminal|registry editor|task manager|visual studio|vs ?code|cursor|windsurf|zed|intellij|pycharm|webstorm|rider|goland|claude|chatgpt|warp|alacritty|wezterm|hyper|tabby|wsl|ubuntu|git bash)\b/i;
|
|
42
|
-
/** Không mở tệp có đuôi chạy được bằng `gui.open_app` (mở = chạy chương trình). */
|
|
43
|
-
const EXECUTABLE_EXT = /\.(exe|com|bat|cmd|ps1|psm1|vbs|vbe|js|jse|wsf|wsh|msi|msp|lnk|scr|pif|hta|cpl|jar|reg|url|appref-ms|application)$/i;
|
|
44
|
-
|
|
45
|
-
const OBSERVE_MAX_NODES = 300;
|
|
46
|
-
const APPS_CACHE_MS = 10 * 60_000;
|
|
47
|
-
const OPEN_WAIT_MS = 10_000;
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
export const
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (!
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
*
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (
|
|
365
|
-
|
|
366
|
-
if (
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
async function
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import { DeviceErrorCode, ToolGroup } from '../constants.mjs';
|
|
5
|
+
import { DeviceToolError, resolveInRoots } from '../sandbox.mjs';
|
|
6
|
+
import { showOSNotification } from '../notify.mjs';
|
|
7
|
+
import { PS_UTF8_PREFIX } from '../processes.mjs';
|
|
8
|
+
import { createWindowsHost } from './windowsHost.mjs';
|
|
9
|
+
import { isProtectedPromptWindow } from '../humanInput.mjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Tầng điều khiển giao diện (28/10/2026, đợt 1: Windows). Nhìn cửa sổ bằng cây trợ năng của hệ điều hành (UI Automation) + ảnh khi cây
|
|
13
|
+
* nghèo; thao tác theo "pattern" (Invoke / Value / Toggle…) trước, chuột / phím giả lập sau. Mọi thao tác ghi trả bằng chứng đọc lại
|
|
14
|
+
* sau khi làm (giá trị mới, tiêu đề cửa sổ, phần tử còn / mất).
|
|
15
|
+
*
|
|
16
|
+
* Đợt 2 (30/10/2026): cây nghèo → host đọc chữ trên ảnh bằng OCR có sẵn của Windows (chạy trên máy), mỗi cụm chữ thành node `<snap>.t<k>`
|
|
17
|
+
* click / gõ được — BE tìm "nút Ghi sổ" theo chữ thay vì nhờ VLM đoán toạ độ; `gui.wait_for` chờ phần tử / cửa sổ hiện ra hoặc mất đi
|
|
18
|
+
* thay cho observe lặp.
|
|
19
|
+
*
|
|
20
|
+
* Sàn cứng trên máy (BE không đổi được): không gõ vào ô mật khẩu (host chặn), không điều khiển ứng dụng nhạy cảm (`BLOCKED_PROCESSES`),
|
|
21
|
+
* máy chỉ mở thư mục (không toàn quyền) thì không điều khiển cửa sổ dòng lệnh / registry — không lách vùng thư mục bằng cách gõ lệnh
|
|
22
|
+
* vào terminal; người dùng đang dùng chuột / phím → dừng (`GUI_USER_ACTIVE`).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** Tiến trình không bao giờ điều khiển: quản lý mật khẩu, hộp nâng quyền, bảo mật hệ thống, màn hình khoá. */
|
|
26
|
+
const BLOCKED_PROCESSES = new Set([
|
|
27
|
+
'consent', 'credentialuihost', 'credentialuibroker', 'lockapp', 'logonui', 'securityhealthsystray', 'securityhealthhost', 'windowsdefender', 'msmpeng',
|
|
28
|
+
'keepass', 'keepassxc', '1password', 'bitwarden', 'lastpass', 'dashlane', 'enpass', 'nordpass', 'roboform',
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* Chỉ cho khi máy toàn quyền — điều khiển được những thứ này là chạy lệnh tuỳ ý ngoài vùng thư mục: terminal / registry, và (30/10/2026)
|
|
32
|
+
* trình soạn code có terminal tích hợp + ứng dụng agent tự chạy lệnh (VS Code, Cursor, Claude…) — gõ vào terminal của VS Code hay nhờ panel
|
|
33
|
+
* Claude chạy lệnh cũng là lách vùng thư mục như gõ vào cmd.
|
|
34
|
+
*/
|
|
35
|
+
const SHELL_PROCESSES = new Set([
|
|
36
|
+
'cmd', 'powershell', 'pwsh', 'windowsterminal', 'wt', 'openconsole', 'conhost', 'regedit', 'mmc', 'taskmgr', 'wsl', 'bash', 'mintty',
|
|
37
|
+
'code', 'code - insiders', 'codium', 'cursor', 'windsurf', 'zed', 'devenv', 'idea64', 'pycharm64', 'webstorm64', 'rider64', 'goland64',
|
|
38
|
+
'claude', 'chatgpt', 'warp', 'alacritty', 'wezterm-gui', 'hyper', 'tabby',
|
|
39
|
+
]);
|
|
40
|
+
/** Cùng nhóm đó theo tên trong menu Start (`gui.open_app` tìm theo tên, khác tên tiến trình) — chặn trước khi mở. */
|
|
41
|
+
const SHELL_APP_NAME = /\b(command prompt|powershell|terminal|registry editor|task manager|visual studio|vs ?code|cursor|windsurf|zed|intellij|pycharm|webstorm|rider|goland|claude|chatgpt|warp|alacritty|wezterm|hyper|tabby|wsl|ubuntu|git bash)\b/i;
|
|
42
|
+
/** Không mở tệp có đuôi chạy được bằng `gui.open_app` (mở = chạy chương trình). */
|
|
43
|
+
const EXECUTABLE_EXT = /\.(exe|com|bat|cmd|ps1|psm1|vbs|vbe|js|jse|wsf|wsh|msi|msp|lnk|scr|pif|hta|cpl|jar|reg|url|appref-ms|application)$/i;
|
|
44
|
+
|
|
45
|
+
const OBSERVE_MAX_NODES = 300;
|
|
46
|
+
const APPS_CACHE_MS = 10 * 60_000;
|
|
47
|
+
const OPEN_WAIT_MS = 10_000;
|
|
48
|
+
/** Mở tệp: Excel / Word khởi động nguội mất 10–15 s mới ghi tên tệp lên tiêu đề. */
|
|
49
|
+
const OPEN_FILE_WAIT_MS = 20_000;
|
|
50
|
+
const WAIT_MAX_MS = 60_000;
|
|
51
|
+
const FIND_DEFAULT = 20;
|
|
52
|
+
const FIND_MAX = 60;
|
|
53
|
+
const SEMANTIC_CHOICES = 5;
|
|
54
|
+
/** Báo người dùng "AI đang điều khiển" một lần mỗi quãng này (lần thao tác ghi đầu tiên). */
|
|
55
|
+
const NOTIFY_EVERY_MS = 5 * 60_000;
|
|
56
|
+
/** Không hỏi người dùng (10/11/2026, user: "xin quyền gì lắt nhắt thế"): cần chuột / phím thật thì chờ họ ngừng tay chừng này rồi mượn thật nhanh. */
|
|
57
|
+
export const REAL_INPUT_IDLE_MS = 2500;
|
|
58
|
+
/** Họ bận liên tục quá chừng này thì thôi, báo Planner để nói trong khung chat. */
|
|
59
|
+
export const REAL_INPUT_WAIT_MS = 30_000;
|
|
60
|
+
const REAL_INPUT_POLL_MS = 400;
|
|
61
|
+
const GUI_PERSON_PRESENT = 'GUI_PERSON_PRESENT';
|
|
62
|
+
|
|
63
|
+
const str = (description) => ({ type: 'string', description });
|
|
64
|
+
const num = (description) => ({ type: 'number', description });
|
|
65
|
+
const bool = (description) => ({ type: 'boolean', description });
|
|
66
|
+
const schema = (properties, required = []) => ({ type: 'object', properties, required });
|
|
67
|
+
|
|
68
|
+
export const GuiAction = Object.freeze({
|
|
69
|
+
CLICK: 'click', DOUBLE_CLICK: 'double_click', RIGHT_CLICK: 'right_click', SET_VALUE: 'set_value', TYPE: 'type', KEY: 'key',
|
|
70
|
+
SCROLL: 'scroll', SELECT: 'select', TOGGLE: 'toggle', EXPAND: 'expand', COLLAPSE: 'collapse', DRAG: 'drag',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/** Năng lực GUI khai trong hồ sơ máy. Chỉ Windows ở đợt này; máy tính tổ chức (nhiều người chung) không có màn hình. */
|
|
74
|
+
export function detectGui({ disabled = false, multiUser = false, platform = process.platform } = {}) {
|
|
75
|
+
if (disabled || multiUser || platform !== 'win32') return null;
|
|
76
|
+
// Phiên 0 (dịch vụ) không có màn hình tương tác.
|
|
77
|
+
if (process.env.SESSIONNAME === 'Services') return null;
|
|
78
|
+
return { backend: 'uia', actions: Object.values(GuiAction) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const normalizeProcess = (name) => String(name || '').toLowerCase().replace(/\.exe$/, '');
|
|
82
|
+
|
|
83
|
+
/** PickerHost còn mở các hộp chọn tệp bình thường, nên chỉ chặn đúng hộp xác thực "Windows Security" của nó. */
|
|
84
|
+
function isWindowsSecurityPrompt(windowInfo) {
|
|
85
|
+
if (normalizeProcess(windowInfo?.process) !== 'pickerhost') return false;
|
|
86
|
+
const title = normalizeName(windowInfo?.title);
|
|
87
|
+
return title === 'windows security' || title === 'bao mat windows';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Ứng dụng này có được điều khiển không — ném lỗi nếu bị chặn. */
|
|
91
|
+
export function assertWindowAllowed(windowInfo, { fullAccess }) {
|
|
92
|
+
if (isWindowsSecurityPrompt(windowInfo)) throw new DeviceToolError(DeviceErrorCode.GUI_BLOCKED_APP, 'This is a Windows Security prompt — only the person at this computer can answer it');
|
|
93
|
+
// Hộp xác nhận / đồng ý của chính Aivin: chỉ người ở máy trả lời — AI bấm "Cho phép" là tự duyệt việc của mình (humanInput.mjs).
|
|
94
|
+
if (isProtectedPromptWindow(windowInfo?.title)) {
|
|
95
|
+
throw new DeviceToolError(DeviceErrorCode.GUI_BLOCKED_APP, 'This is an Aivin confirmation box — only the person at this computer can answer it');
|
|
96
|
+
}
|
|
97
|
+
const proc = normalizeProcess(windowInfo?.process);
|
|
98
|
+
if (!proc) return;
|
|
99
|
+
if (BLOCKED_PROCESSES.has(proc)) throw new DeviceToolError(DeviceErrorCode.GUI_BLOCKED_APP, `Controlling "${windowInfo.process}" is not allowed on this device`);
|
|
100
|
+
if (!fullAccess && SHELL_PROCESSES.has(proc)) {
|
|
101
|
+
throw new DeviceToolError(DeviceErrorCode.GUI_BLOCKED_APP, `Controlling "${windowInfo.process}" needs full device access (aivin remote start --full-access)`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Ứng dụng này (tên trong menu Start) có được mở không — ném lỗi trước khi mở. */
|
|
106
|
+
export function assertAppAllowed(name, { fullAccess }) {
|
|
107
|
+
if (BLOCKED_PROCESSES.has(normalizeProcess(String(name || '').replace(/\s+/g, '')))) throw new DeviceToolError(DeviceErrorCode.GUI_BLOCKED_APP, `Opening "${name}" is not allowed`);
|
|
108
|
+
if (!fullAccess && SHELL_APP_NAME.test(String(name || ''))) {
|
|
109
|
+
throw new DeviceToolError(DeviceErrorCode.GUI_BLOCKED_APP, `Opening "${name}" needs full device access (aivin remote start --full-access)`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const normalizeName = (s) => String(s || '').normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/đ/gi, 'd').toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Planner nhìn ảnh nói theo ký hiệu trên nút ("×", "7", "☰"), cây trợ năng gọi bằng chữ ("Multiply by", "Seven", "Open Navigation").
|
|
117
|
+
* Mỗi ký hiệu → các tên chữ hay gặp; khớp qua tên chữ bị trừ nhẹ điểm so với khớp thẳng (gui-bench 13/11/2026: "×" / "=" bị bỏ hết ký tự
|
|
118
|
+
* thành truy vấn rỗng, "7" không khớp "Seven").
|
|
119
|
+
*/
|
|
120
|
+
const GLYPH_ALIASES = {
|
|
121
|
+
'×': ['multiply', 'times', 'close'], '*': ['multiply'], '✕': ['close'], '✖': ['close'], '╳': ['close'], 'x': ['close'],
|
|
122
|
+
'÷': ['divide'], '/': ['divide'], '+': ['plus', 'add', 'new'], '-': ['minus', 'subtract'], '−': ['minus', 'subtract'], '–': ['minus'],
|
|
123
|
+
'=': ['equals', 'equal'], '%': ['percent'], '±': ['positive negative', 'negate'], '+/-': ['positive negative', 'negate'], '.': ['decimal'], ',': ['decimal'],
|
|
124
|
+
'←': ['back'], '→': ['forward', 'next'], '↑': ['up'], '↓': ['down'], '⌫': ['backspace'],
|
|
125
|
+
'☰': ['navigation', 'menu'], '≡': ['navigation', 'menu'], '⋯': ['more'], '…': ['more'], '...': ['more'], '⋮': ['more'],
|
|
126
|
+
'🔍': ['search'], '⚙': ['settings'], '⚙️': ['settings'], '⟳': ['refresh'], '↻': ['refresh'], '✓': ['ok', 'done'], '✔': ['ok', 'done'],
|
|
127
|
+
menu: ['navigation'], hamburger: ['navigation', 'menu'],
|
|
128
|
+
};
|
|
129
|
+
const DIGIT_WORDS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Từ chỉ loại phần tử ở đầu / cuối mô tả ("nút Lưu", "Save button", "ô Họ tên", "text area") là gợi ý vai trò chứ không phải chữ trên phần
|
|
133
|
+
* tử. Không tách ra thì "Save button" chỉ khớp nửa câu → mơ hồ; "text area" không khớp gì dù cửa sổ chỉ có một ô soạn thảo.
|
|
134
|
+
*/
|
|
135
|
+
const EDITABLE_ROLES = ['edit', 'document', 'combobox'];
|
|
136
|
+
const ROLE_HINTS = [
|
|
137
|
+
[/^(text ?box|text ?field|text ?area|text ?input|input ?box|input ?field|input|edit ?box|field|box|editor|o nhap|o)$/, EDITABLE_ROLES],
|
|
138
|
+
[/^(button|btn|nut|icon|bieu tuong)$/, ['button', 'splitbutton', 'menuitem', 'hyperlink']],
|
|
139
|
+
[/^(link|hyperlink|lien ket|duong dan)$/, ['hyperlink']],
|
|
140
|
+
[/^(tab)$/, ['tabitem']],
|
|
141
|
+
[/^(check ?box|o tich|o danh dau)$/, ['checkbox']],
|
|
142
|
+
[/^(drop ?down|combo ?box|combo|danh sach chon)$/, ['combobox']],
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
function roleHintOf(phrase) {
|
|
146
|
+
for (const [re, roles] of ROLE_HINTS) if (re.test(phrase)) return roles;
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Tách từ chỉ loại ở cuối rồi ở đầu (một hoặc hai từ). Không có → null. */
|
|
151
|
+
function splitRoleHint(q) {
|
|
152
|
+
const words = q.split(' ').filter(Boolean);
|
|
153
|
+
for (const n of [2, 1]) {
|
|
154
|
+
if (words.length >= n) {
|
|
155
|
+
const tail = roleHintOf(words.slice(-n).join(' '));
|
|
156
|
+
if (tail) return { rest: words.slice(0, -n).join(' '), roles: tail };
|
|
157
|
+
const head = roleHintOf(words.slice(0, n).join(' '));
|
|
158
|
+
if (head) return { rest: words.slice(n).join(' '), roles: head };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Các cách hiểu một mô tả: nguyên văn, qua ký hiệu / chữ số, và bỏ từ chỉ loại (kèm vai trò gợi ý). */
|
|
165
|
+
function queryVariants(raw) {
|
|
166
|
+
const text = String(raw || '').trim();
|
|
167
|
+
const out = [];
|
|
168
|
+
const add = (q, alias, roles) => {
|
|
169
|
+
const n = normalizeName(q);
|
|
170
|
+
const words = n.split(' ').filter(Boolean);
|
|
171
|
+
if (!words.length && !roles) return;
|
|
172
|
+
if (out.some((v) => v.q === n && String(v.roles) === String(roles))) return;
|
|
173
|
+
out.push({ q: n, words, alias, roles });
|
|
174
|
+
};
|
|
175
|
+
add(text, false);
|
|
176
|
+
const lower = text.toLowerCase();
|
|
177
|
+
for (const a of GLYPH_ALIASES[lower] || []) add(a, true);
|
|
178
|
+
if (/^\d$/.test(lower)) add(DIGIT_WORDS[+lower], true);
|
|
179
|
+
const hint = splitRoleHint(normalizeName(text).replace(/^(the|a|an) /, ''));
|
|
180
|
+
if (hint) add(hint.rest, false, hint.roles);
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Mô tả nói thẳng tới khung cửa sổ — chỉ khi đó mới chọn phần tử khung (nút thu nhỏ / đóng, menu hệ thống). */
|
|
185
|
+
const CHROME_QUERY = /\b(minimi[sz]e|maximi[sz]e|restore|close|system menu|title ?bar)\b/;
|
|
186
|
+
const CHROME_QUERY_VI = /(thu nhỏ|phóng to|khôi phục|đóng|thanh tiêu đề)/i;
|
|
187
|
+
|
|
188
|
+
/** Phần tử làm được thao tác này không (fill cần ô nhập, toggle cần ô tích…). undefined = không biết thao tác. */
|
|
189
|
+
function compatibleWith(node, action) {
|
|
190
|
+
const role = String(node.role || '').toLowerCase();
|
|
191
|
+
const p = node.patterns || [];
|
|
192
|
+
if (node.source === 'ocr') return true;
|
|
193
|
+
switch (action) {
|
|
194
|
+
case GuiAction.SET_VALUE: case GuiAction.TYPE: return !node.readonly && (EDITABLE_ROLES.includes(role) || p.includes('value'));
|
|
195
|
+
case GuiAction.TOGGLE: return p.includes('toggle') || role === 'checkbox' || role === 'radiobutton';
|
|
196
|
+
case GuiAction.SELECT: return p.includes('select') || p.includes('expand') || ['combobox', 'list', 'listitem', 'tabitem', 'radiobutton', 'dataitem', 'treeitem'].includes(role);
|
|
197
|
+
case GuiAction.CLICK: case GuiAction.DOUBLE_CLICK: return p.length > 0 || ['button', 'menuitem', 'hyperlink', 'listitem', 'tabitem', 'treeitem', 'checkbox', 'radiobutton', 'dataitem', 'splitbutton'].includes(role);
|
|
198
|
+
default: return undefined;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Từ ngắn (≤ 2 ký tự) và số chỉ khớp nguyên một từ của chữ hiện trên phần tử — không khớp đầu từ, không khớp AutomationId ("1" ≠ "Item 1"). */
|
|
203
|
+
const strictWord = (word) => word.length <= 2 || /^\d+$/.test(word);
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Rank UI nodes with richer evidence while keeping the model-facing schema small. Hard exclusions happen
|
|
207
|
+
* before scoring; exact accessible names and AutomationIds beat loose word matches. The margin between the
|
|
208
|
+
* first two candidates is used by gui.do to refuse ambiguous actions instead of guessing.
|
|
209
|
+
* `complete` = mọi từ của (một cách hiểu) mô tả đều khớp. `action` (tuỳ chọn) ưu tiên phần tử làm được thao tác đó.
|
|
210
|
+
*/
|
|
211
|
+
export function rankGuiNodes(nodes, query, role = '', { matchValue = true, action, includeOffscreen = false } = {}) {
|
|
212
|
+
const variants = queryVariants(query);
|
|
213
|
+
const wantedRole = String(role || '').toLowerCase();
|
|
214
|
+
if (!variants.length) return [];
|
|
215
|
+
const allowChrome = CHROME_QUERY.test(normalizeName(query)) || CHROME_QUERY_VI.test(String(query || ''));
|
|
216
|
+
// Chữ OCR nằm trên một phần tử đã tắt cũng là đã tắt: bấm vào đó không có tác dụng mà vẫn báo thành công.
|
|
217
|
+
const disabledRects = (nodes || []).filter((n) => n.disabled && n.rect).map((n) => n.rect);
|
|
218
|
+
const onDisabled = (n) => n.source === 'ocr' && n.rect && disabledRects.some((r) => {
|
|
219
|
+
const cx = n.rect.x + n.rect.w / 2;
|
|
220
|
+
const cy = n.rect.y + n.rect.h / 2;
|
|
221
|
+
return cx >= r.x && cx <= r.x + r.w && cy >= r.y && cy <= r.y + r.h;
|
|
222
|
+
});
|
|
223
|
+
const pool = (nodes || []).filter((n) => (!wantedRole || String(n.role || '').toLowerCase() === wantedRole || n.source === 'ocr')
|
|
224
|
+
&& !n.disabled && (includeOffscreen || !n.offscreen) && !onDisabled(n) && (allowChrome || !n.chrome));
|
|
225
|
+
// Mô tả chỉ có từ chỉ loại ("text area"): ứng viên là mọi phần tử đúng loại làm được thao tác — chỉ một thì chắc, nhiều thì mơ hồ.
|
|
226
|
+
const roleOnly = variants.find((v) => !v.words.length && v.roles);
|
|
227
|
+
const roleOnlyHits = roleOnly ? pool.filter((n) => roleOnly.roles.includes(String(n.role || '').toLowerCase()) && compatibleWith(n, action) !== false) : [];
|
|
228
|
+
return pool
|
|
229
|
+
.map((node, order) => {
|
|
230
|
+
const name = normalizeName(node.name);
|
|
231
|
+
const aid = normalizeName(node.automation_id);
|
|
232
|
+
const value = matchValue ? normalizeName(node.value) : '';
|
|
233
|
+
const help = normalizeName(node.help);
|
|
234
|
+
const combined = [name, aid, value, help].filter(Boolean).join(' ');
|
|
235
|
+
const shown = [name, value, help].filter(Boolean).join(' ').split(' ');
|
|
236
|
+
// Khớp theo đầu từ; chỉ từ đủ dài mới được khớp giữa chuỗi (AutomationId dính liền) — "ton" (tồn) không được khớp "TogglePaneButton".
|
|
237
|
+
const tokens = combined.split(' ');
|
|
238
|
+
const nodeRole = String(node.role || '').toLowerCase();
|
|
239
|
+
const compat = compatibleWith(node, action);
|
|
240
|
+
let best = null;
|
|
241
|
+
for (const v of variants) {
|
|
242
|
+
if (!v.words.length) {
|
|
243
|
+
if (!roleOnlyHits.includes(node)) continue;
|
|
244
|
+
const entry = { score: 55, hits: 1, total: 1, complete: roleOnlyHits.length === 1, evidence: ['only_of_role'] };
|
|
245
|
+
if (!best || entry.score > best.score) best = entry;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
const { q, words } = v;
|
|
249
|
+
const hits = words.filter((word) => (strictWord(word)
|
|
250
|
+
? shown.includes(word)
|
|
251
|
+
: tokens.some((token) => token.startsWith(word)) || (word.length >= 4 && combined.includes(word)))).length;
|
|
252
|
+
if (!hits) continue;
|
|
253
|
+
let score = Math.round((hits / words.length) * 50);
|
|
254
|
+
const evidence = [];
|
|
255
|
+
const longQ = q.length > 2;
|
|
256
|
+
if (name === q) { score += 50; evidence.push('exact_name'); }
|
|
257
|
+
else if (longQ && aid === q) { score += 45; evidence.push('exact_automation_id'); }
|
|
258
|
+
else if (longQ && name.startsWith(q)) { score += 35; evidence.push('name_prefix'); }
|
|
259
|
+
else if (words.every((word) => (strictWord(word) ? name.split(' ').includes(word) : name.includes(word)))) { score += 30; evidence.push('all_words_in_name'); }
|
|
260
|
+
else if (hits === words.length) { score += 20; evidence.push('all_words'); }
|
|
261
|
+
if (v.alias) { score -= 5; evidence.push('alias'); }
|
|
262
|
+
if (v.roles) {
|
|
263
|
+
if (v.roles.includes(nodeRole)) { score += 8; evidence.push('role_hint'); } else if (node.source !== 'ocr') score -= 10;
|
|
264
|
+
}
|
|
265
|
+
const entry = { score, hits, total: words.length, complete: hits === words.length, evidence };
|
|
266
|
+
if (!best || entry.score > best.score || (entry.score === best.score && entry.complete && !best.complete)) best = entry;
|
|
267
|
+
}
|
|
268
|
+
if (!best) return null;
|
|
269
|
+
if (node.source === 'ocr') { best.score -= 5; best.evidence.push('ocr'); }
|
|
270
|
+
if (node.patterns?.length) { best.score += 3; best.evidence.push('actionable_pattern'); }
|
|
271
|
+
// fill vào nhãn chữ / toggle một nút thường không làm được gì mà có thể vẫn "thành công": ưu tiên phần tử làm được thao tác.
|
|
272
|
+
if (compat === true) { best.score += 8; best.evidence.push('fits_action'); }
|
|
273
|
+
else if (compat === false && action !== GuiAction.CLICK) { best.score -= 30; best.evidence.push('wrong_kind'); }
|
|
274
|
+
return { node, ...best, order };
|
|
275
|
+
})
|
|
276
|
+
.filter(Boolean)
|
|
277
|
+
.sort((a, b) => b.score - a.score || Number(b.complete) - Number(a.complete) || b.hits - a.hits || a.order - b.order);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Nhãn nút chốt / phá huỷ (đã bỏ dấu, viết thường). Cổng duyệt trên BE xét câu mô tả, nên khi máy tự chọn phần tử có nhãn kiểu này mà câu
|
|
282
|
+
* mô tả không nói tới (vd "Lưu" khớp tiền tố "Lưu và gửi") thì không bấm thẳng — trả mơ hồ để BE phân giải + xét sàn an toàn trên đúng nút.
|
|
283
|
+
*/
|
|
284
|
+
const RISKY_LABEL_WORDS = new Set([
|
|
285
|
+
'send', 'submit', 'post', 'publish', 'delete', 'remove', 'erase', 'pay', 'purchase', 'buy', 'order', 'confirm', 'approve', 'transfer', 'logout', 'signout',
|
|
286
|
+
'gui', 'dang', 'xoa', 'go', 'huy', 'mua', 'chuyen', 'duyet',
|
|
287
|
+
]);
|
|
288
|
+
const RISKY_LABEL_PHRASES = ['sign out', 'log out', 'thanh toan', 'xac nhan', 'dang xuat', 'dat hang', 'chuyen tien', 'go bo'];
|
|
289
|
+
|
|
290
|
+
export function riskyLabelWords(label) {
|
|
291
|
+
const n = normalizeName(label);
|
|
292
|
+
const words = n.split(' ').filter((w) => RISKY_LABEL_WORDS.has(w));
|
|
293
|
+
return [...words, ...RISKY_LABEL_PHRASES.filter((p) => ` ${n} `.includes(` ${p} `))];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Phần tử đã chọn mang nhãn chốt / phá huỷ mà câu mô tả không có → không bấm thẳng. */
|
|
297
|
+
export function needsServerCheck(query, node) {
|
|
298
|
+
const asked = new Set(riskyLabelWords(query));
|
|
299
|
+
return riskyLabelWords(node?.name || node?.automation_id).some((w) => !asked.has(w));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* gui.do không chắc → trả ứng viên để BE phân giải. BE đọc `role` / `name` / `id` (DeviceGuiService: `${role} "${name}" [${id}]`), bản cũ chỉ
|
|
304
|
+
* có `ref` / `label` nên thông báo cho Planner thành `item "" []` — giữ cả hai kiểu.
|
|
305
|
+
*/
|
|
306
|
+
function ambiguousResult(found) {
|
|
307
|
+
return {
|
|
308
|
+
ok: false, code: DeviceErrorCode.GUI_AMBIGUOUS_TARGET,
|
|
309
|
+
choices: found.nodes.map((n) => ({
|
|
310
|
+
ref: n.id, id: n.id, role: n.role, name: n.name || n.automation_id || undefined,
|
|
311
|
+
label: [n.name || n.automation_id || n.role, n.role].filter(Boolean).join(' — '),
|
|
312
|
+
})),
|
|
313
|
+
observation: found._raw_observation,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Khung cửa sổ trong kết quả observe: bỏ thanh tiêu đề / menu hệ thống (thang phân giải ở BE cũng chọn nhầm chúng: "System" của Settings),
|
|
319
|
+
* giữ mỗi loại nút thu nhỏ / phóng to / đóng một cái (ứng dụng Store có hai bộ). Id của các node còn lại không đổi.
|
|
320
|
+
*/
|
|
321
|
+
export function withoutChromeNoise(nodes) {
|
|
322
|
+
const seenCaption = new Set();
|
|
323
|
+
return nodes.filter((n) => {
|
|
324
|
+
if (!n.chrome) return true;
|
|
325
|
+
if (n.role !== 'button') return false;
|
|
326
|
+
const key = n.automation_id || n.name;
|
|
327
|
+
if (seenCaption.has(key)) return false;
|
|
328
|
+
seenCaption.add(key);
|
|
329
|
+
return true;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Nhiều ô nhập cùng tên: MSAA đặt tên ô theo nhãn chữ đứng trước nó, nên ô không có nhãn ngay sau cũng mang tên nhãn trên (gui-bench
|
|
335
|
+
* 13/11/2026: phiếu thu WinForms có hai ô "Số tiền"). Lấy ô nằm cùng hàng, bên phải nhãn chữ đúng tên đó; không phân định được → null.
|
|
336
|
+
*/
|
|
337
|
+
export function pickByLabelRow(candidates, nodes, query) {
|
|
338
|
+
const editable = candidates.filter((n) => n.rect && compatibleWith(n, GuiAction.SET_VALUE) === true);
|
|
339
|
+
if (editable.length < 2) return null;
|
|
340
|
+
const want = normalizeName(query);
|
|
341
|
+
const labels = nodes.filter((n) => n.rect && n.source !== 'ocr' && String(n.role || '').toLowerCase() === 'text' && normalizeName(n.name) === want);
|
|
342
|
+
const sameRow = editable.filter((e) => labels.some((l) => {
|
|
343
|
+
const cy = e.rect.y + e.rect.h / 2;
|
|
344
|
+
return cy >= l.rect.y - 4 && cy <= l.rect.y + l.rect.h + 4 && e.rect.x >= l.rect.x + l.rect.w - 4;
|
|
345
|
+
}));
|
|
346
|
+
return sameRow.length === 1 ? sameRow[0] : null;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const CLICK_GROUND_ROLES = new Set(['button', 'splitbutton', 'menuitem', 'hyperlink', 'listitem', 'tabitem', 'treeitem', 'checkbox', 'radiobutton', 'dataitem']);
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Chữ đọc trên ảnh nằm gọn trong một phần tử thật làm được thao tác (nút hiện "C" là "Clear", nút biểu tượng có chữ khác tên trợ năng) →
|
|
353
|
+
* thao tác trên phần tử đó: chạy bằng pattern dưới nền, có bằng chứng đọc lại, thay vì bấm toạ độ bằng chuột thật. Phần tử chứa phải ôm sát
|
|
354
|
+
* chữ (không lấy cả khung / vùng cuộn chứa mọi chữ). Không có → giữ node chữ.
|
|
355
|
+
*/
|
|
356
|
+
export function groundOcrNode(ocrNode, nodes, action) {
|
|
357
|
+
if (ocrNode?.source !== 'ocr' || !ocrNode.rect) return ocrNode;
|
|
358
|
+
const r = ocrNode.rect;
|
|
359
|
+
const cx = r.x + r.w / 2;
|
|
360
|
+
const cy = r.y + r.h / 2;
|
|
361
|
+
const textArea = Math.max(1, r.w * r.h);
|
|
362
|
+
let best = null;
|
|
363
|
+
for (const n of nodes) {
|
|
364
|
+
if (n.source === 'ocr' || n.chrome || n.disabled || n.offscreen || !n.rect) continue;
|
|
365
|
+
const b = n.rect;
|
|
366
|
+
if (cx < b.x || cx > b.x + b.w || cy < b.y || cy > b.y + b.h) continue;
|
|
367
|
+
const area = b.w * b.h;
|
|
368
|
+
if (area > Math.max(60 * textArea, 6000) || area > 160_000) continue;
|
|
369
|
+
const role = String(n.role || '').toLowerCase();
|
|
370
|
+
const fits = action === GuiAction.CLICK || action === GuiAction.DOUBLE_CLICK || action === GuiAction.RIGHT_CLICK
|
|
371
|
+
? CLICK_GROUND_ROLES.has(role) || (n.patterns || []).includes('invoke')
|
|
372
|
+
: compatibleWith(n, action) === true;
|
|
373
|
+
if (fits && (!best || area < best.rect.w * best.rect.h)) best = n;
|
|
374
|
+
}
|
|
375
|
+
return best || ocrNode;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** Chọn ứng dụng theo tên: trùng hẳn > bắt đầu bằng > chứa. Nhiều ứng viên ngang nhau → trả danh sách để Planner chọn lại. */
|
|
379
|
+
export function matchApps(apps, query) {
|
|
380
|
+
const q = normalizeName(query);
|
|
381
|
+
if (!q) return [];
|
|
382
|
+
const scored = apps.map((app) => {
|
|
383
|
+
const n = normalizeName(app.name);
|
|
384
|
+
const score = n === q ? 3 : n.startsWith(q) ? 2 : n.includes(q) ? 1 : 0;
|
|
385
|
+
return { app, score };
|
|
386
|
+
}).filter((x) => x.score > 0).sort((a, b) => b.score - a.score || a.app.name.length - b.app.name.length);
|
|
387
|
+
if (!scored.length) return [];
|
|
388
|
+
const top = scored[0].score;
|
|
389
|
+
return scored.filter((x) => x.score === top).map((x) => x.app);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Mở qua explorer.exe. KHÔNG `windowsHide` (13/11/2026, gui-bench): cờ đó đặt SW_HIDE trong STARTUPINFO và Explorer / ứng dụng mở tệp làm
|
|
394
|
+
* theo — thư mục, Notepad lần đầu mở ra cửa sổ ẨN: người dùng không thấy, gui.windows không liệt kê, open_app chờ hết 10 s rồi báo không có
|
|
395
|
+
* cửa sổ. explorer.exe không có cửa sổ console nên không cần giấu gì; cửa sổ mới vẫn được đưa xuống nền ở settleNewWindow.
|
|
396
|
+
*/
|
|
397
|
+
/** Lệnh liên kết tệp là "Open with AIVIN Office Suite" (`"…\Aivin.exe" --open "%1"`). */
|
|
398
|
+
export function isAivinOpenCommand(command, executable) {
|
|
399
|
+
const exe = path.win32.basename(String(executable || '')).toLowerCase();
|
|
400
|
+
const cmd = String(command || '');
|
|
401
|
+
return (exe === 'aivin.exe' || /\baivin\.exe\b/i.test(cmd)) && /(^|\s)--open\b/i.test(cmd);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function launchShell(target) {
|
|
405
|
+
spawn('explorer.exe', [target], { windowsHide: false, detached: true, stdio: 'ignore' }).on('error', () => undefined).unref();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function runPowerShellJson(script, signal) {
|
|
409
|
+
return new Promise((resolve, reject) => {
|
|
410
|
+
// Đầu ra UTF-8: tên cửa sổ / ứng dụng tiếng Việt không thành `?` (PowerShell không console ghi theo bảng mã OEM).
|
|
411
|
+
const c = spawn('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', `${PS_UTF8_PREFIX}${script}`], { windowsHide: true });
|
|
412
|
+
const chunks = [];
|
|
413
|
+
c.stdout.on('data', (d) => { chunks.push(d); });
|
|
414
|
+
const onAbort = () => { try { c.kill(); } catch { /* đã thoát */ } };
|
|
415
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
416
|
+
c.on('error', (e) => reject(e));
|
|
417
|
+
c.on('close', () => {
|
|
418
|
+
signal?.removeEventListener('abort', onAbort);
|
|
419
|
+
const out = Buffer.concat(chunks).toString('utf8');
|
|
420
|
+
try { const v = JSON.parse(out || 'null'); resolve(Array.isArray(v) ? v : v ? [v] : []); } catch (e) { reject(e); }
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Bộ điều khiển GUI của máy. `env.fullAccess` quyết định có cho điều khiển terminal không. `host` truyền vào được (test dùng host giả).
|
|
427
|
+
*/
|
|
428
|
+
export function createGuiController({
|
|
429
|
+
fullAccess = false, host = createWindowsHost(), notify = showOSNotification, say = () => {}, background = true, defaultWindow = () => null, realInputIdleMs = REAL_INPUT_IDLE_MS, realInputWaitMs = REAL_INPUT_WAIT_MS, fetchApps = (signal) => runPowerShellJson('Get-StartApps | Select-Object Name, AppID | ConvertTo-Json -Compress', signal),
|
|
430
|
+
} = {}) {
|
|
431
|
+
let appsCache = null;
|
|
432
|
+
let appsInflight = null;
|
|
433
|
+
let lastNotifyAt = 0;
|
|
434
|
+
/** Cửa sổ của từng lần observe — để kiểm ứng dụng bị chặn ở thao tác theo node_id. */
|
|
435
|
+
const snapshotWindows = new Map();
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Thao tác chạy dưới nền thì đi thẳng. Host chỉ báo GUI_PERSON_PRESENT ngay trước lần đầu đụng chuột / phím thật, lúc chưa làm gì, nên thử lại
|
|
439
|
+
* là an toàn: chờ người dùng ngừng tay. Họ bận suốt → GUI_USER_ACTIVE, không có hộp hỏi nào.
|
|
440
|
+
*/
|
|
441
|
+
async function whenPersonPauses(ctx, run) {
|
|
442
|
+
const deadline = Date.now() + Math.min(realInputWaitMs, (ctx?.timeoutMs || Infinity) / 2);
|
|
443
|
+
for (;;) {
|
|
444
|
+
try {
|
|
445
|
+
return await run(realInputIdleMs);
|
|
446
|
+
} catch (e) {
|
|
447
|
+
if (e?.code !== GUI_PERSON_PRESENT) throw e;
|
|
448
|
+
if (ctx?.signal?.aborted) throw ctx.signal.reason;
|
|
449
|
+
if (Date.now() + REAL_INPUT_POLL_MS >= deadline) throw new DeviceToolError(DeviceErrorCode.GUI_USER_ACTIVE, 'The person at this computer kept using it and this step needs the real mouse/keyboard — nothing was done. Tell them in the chat so they can do this step themselves or pause for a few seconds');
|
|
450
|
+
await new Promise((r) => setTimeout(r, REAL_INPUT_POLL_MS));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const announce = (windowInfo) => {
|
|
456
|
+
const now = Date.now();
|
|
457
|
+
if (now - lastNotifyAt < NOTIFY_EVERY_MS) return;
|
|
458
|
+
lastNotifyAt = now;
|
|
459
|
+
say(`🖱 AI đang điều khiển ${windowInfo?.process || 'màn hình'} — di chuột hoặc gõ phím để AI dừng lại.`);
|
|
460
|
+
notify({ title: 'Aivin đang điều khiển máy này', body: `AI đang thao tác trên ${windowInfo?.title || windowInfo?.process || 'màn hình'}. Di chuột hoặc gõ phím để AI dừng và hỏi bạn.` });
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
async function windows(args, ctx) {
|
|
464
|
+
const list = await host.call('windows', { all: !!args.include_dialogs }, ctx);
|
|
465
|
+
return { windows: list.map((w) => ({ ...w, blocked: BLOCKED_PROCESSES.has(normalizeProcess(w.process)) || (!fullAccess && SHELL_PROCESSES.has(normalizeProcess(w.process))) || isProtectedPromptWindow(w.title) || isWindowsSecurityPrompt(w) || undefined })) };
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Không nói cửa sổ = cửa sổ đang focus; nhưng chủ máy vừa gõ vào ô hỏi của linh vật thì focus là chính linh vật → host đổi sang cửa sổ họ
|
|
470
|
+
* đang dùng ngay trước đó (`defaultWindow()` = `{ avoid_pid, fallback }`).
|
|
471
|
+
*/
|
|
472
|
+
const target = (args) => (args.window ? { window: args.window } : { ...defaultWindow() });
|
|
473
|
+
const windowInfoOf = (args, ctx) => host.call('window_info', target(args), ctx);
|
|
474
|
+
/**
|
|
475
|
+
* Thao tác có thay đổi mà không nêu cửa sổ (02/11/2026): không lấy cửa sổ đang focus — người dùng có thể vừa chuyển sang cửa sổ khác. Chỉ
|
|
476
|
+
* cho khi hỏi từ linh vật (có cửa sổ chủ máy dùng ngay trước đó); host kiểm lại đúng lúc thao tác (linh vật có đang được focus không).
|
|
477
|
+
*/
|
|
478
|
+
const assertWindowNamed = (windowArg) => {
|
|
479
|
+
if (windowArg || defaultWindow()?.fallback) return;
|
|
480
|
+
throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, 'Name the window for this action (window / within: a handle 0x… or a title/process from gui.windows) — input is never sent to whatever window happens to be focused');
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
async function observe(args, ctx) {
|
|
484
|
+
const res = await host.call('observe', {
|
|
485
|
+
...target(args),
|
|
486
|
+
max_nodes: Math.min(Number(args.max_nodes) || OBSERVE_MAX_NODES, 1500),
|
|
487
|
+
include_image: !!args.include_image,
|
|
488
|
+
image_when_poor: args.image_when_poor !== false,
|
|
489
|
+
ocr: typeof args.ocr === 'boolean' ? args.ocr : undefined,
|
|
490
|
+
image_max_width: Number(args.image_max_width) || 1366,
|
|
491
|
+
image_quality: Number(args.image_quality) || 70,
|
|
492
|
+
budget_ms: Number(args.budget_ms) || undefined,
|
|
493
|
+
}, ctx);
|
|
494
|
+
assertWindowAllowed(res.window, { fullAccess });
|
|
495
|
+
if (Array.isArray(res.nodes)) res.nodes = withoutChromeNoise(res.nodes);
|
|
496
|
+
snapshotWindows.set(String(res.snapshot), res.window);
|
|
497
|
+
if (snapshotWindows.size > 20) snapshotWindows.delete(snapshotWindows.keys().next().value);
|
|
498
|
+
return res;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Chỉ những phần tử khớp chữ cần tìm (cửa sổ lớn: Excel, ERP có hàng trăm phần tử) — đi cả cây (tới 1500) rồi lọc ở đây; id vẫn của lần
|
|
503
|
+
* observe đó nên `gui.act` dùng được ngay. Mọi từ đều có trong tên / AutomationId / giá trị / chú thích (bỏ dấu); không phần tử nào đủ
|
|
504
|
+
* hết từ thì lấy phần tử khớp nhiều từ nhất.
|
|
505
|
+
*/
|
|
506
|
+
async function find(args, ctx) {
|
|
507
|
+
if (!queryVariants(args.query).length) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, 'Give query (words of the element to find)');
|
|
508
|
+
const res = await observe({ ...args, max_nodes: 1500, budget_ms: 10_000 }, ctx);
|
|
509
|
+
return rankObservation(res, args);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** Lọc / xếp hạng một lần observe theo mô tả (dùng chung cho gui.find và cho gui.do sau khi thêm chữ OCR vào cùng snapshot). */
|
|
513
|
+
function rankObservation(res, args) {
|
|
514
|
+
const role = String(args.role || '').toLowerCase();
|
|
515
|
+
const max = Math.max(1, Math.min(Number(args.max) || FIND_DEFAULT, FIND_MAX));
|
|
516
|
+
// gui.do chọn phần tử để BẤM: không tính nội dung ô — chữ trên màn hình (thư, trang web) không được lái việc chọn nút (02/11/2026).
|
|
517
|
+
let scored = rankGuiNodes(res.nodes, args.query, role, { matchValue: args.match_value !== false, action: args.action });
|
|
518
|
+
// Không có phần tử đang hiện nào khớp đủ: xét cả phần tử khuất trong vùng cuộn (mục cuối trang Settings, danh sách dài) — host cuộn tới
|
|
519
|
+
// hoặc gọi pattern khi thao tác. Phần tử đang hiện luôn được ưu tiên, menu ẩn không lấn được nút đang thấy.
|
|
520
|
+
if (!scored.some((x) => x.complete)) {
|
|
521
|
+
const hidden = rankGuiNodes(res.nodes, args.query, role, { matchValue: args.match_value !== false, action: args.action, includeOffscreen: true });
|
|
522
|
+
if (hidden.some((x) => x.complete)) scored = hidden;
|
|
523
|
+
}
|
|
524
|
+
const all = scored.filter((x) => x.complete);
|
|
525
|
+
const cover = (x) => x.hits / x.total;
|
|
526
|
+
const pool = all.length ? all : scored.filter((x) => cover(x) === cover(scored[0]));
|
|
527
|
+
const picked = pool.slice(0, max);
|
|
528
|
+
const margin = picked.length > 1 ? picked[0].score - picked[1].score : picked.length ? picked[0].score : 0;
|
|
529
|
+
const out = { ...res, nodes: picked.map((x) => x.node), query: String(args.query), matched: all.length || scored.length, exact: all.length > 0, confidence: !picked.length ? 'none' : margin >= 15 || picked.length === 1 ? 'high' : margin >= 5 ? 'medium' : 'low', ambiguous: picked.length > 1 && margin < 5 || undefined };
|
|
530
|
+
Object.defineProperty(out, '_raw_observation', { value: res, enumerable: false });
|
|
531
|
+
return out;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Compact semantic fast path. The caller states intent; candidate evidence, exclusions, ambiguity handling,
|
|
536
|
+
* execution and cheap post-action verification stay inside the device runtime.
|
|
537
|
+
*/
|
|
538
|
+
async function semanticDo(args, ctx, env) {
|
|
539
|
+
const command = String(args.do || '').toLowerCase();
|
|
540
|
+
if (command === 'open') return openApp({ name: args.target, file: args.file }, ctx, env);
|
|
541
|
+
const action = {
|
|
542
|
+
click: GuiAction.CLICK, fill: GuiAction.SET_VALUE, select: GuiAction.SELECT, toggle: GuiAction.TOGGLE,
|
|
543
|
+
key: GuiAction.KEY, scroll: GuiAction.SCROLL,
|
|
544
|
+
}[command];
|
|
545
|
+
if (!action) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, `Unknown semantic action: ${args.do || ''}`);
|
|
546
|
+
assertWindowNamed(args.within || args.window);
|
|
547
|
+
|
|
548
|
+
if ((command === 'key' || command === 'scroll') && !args.target) {
|
|
549
|
+
const result = await act({
|
|
550
|
+
action, window: args.within || args.window, keys: command === 'key' ? args.value : undefined,
|
|
551
|
+
direction: command === 'scroll' ? args.value : undefined,
|
|
552
|
+
}, ctx);
|
|
553
|
+
return { ok: true, action: command, method: result.method, effect: result.window_title_changed || result.focused_element || command };
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const query = String(args.target || '').trim();
|
|
557
|
+
if (!query) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, 'Give target');
|
|
558
|
+
const findArgs = { query, role: args.role, window: args.within || args.window, max: SEMANTIC_CHOICES, match_value: false, action };
|
|
559
|
+
let found = await find(findArgs, ctx);
|
|
560
|
+
if ((!found.nodes.length || !found.exact) && !found.ocr && found.tree_quality !== 'poor') {
|
|
561
|
+
// Đọc chữ trên ảnh của CHÍNH lần observe vừa rồi (cùng snapshot, id nối tiếp) — không đi lại cây trợ năng lần hai.
|
|
562
|
+
const raw = found._raw_observation;
|
|
563
|
+
const extra = await host.call('ocr', { snapshot: raw.snapshot }, ctx).catch(() => null);
|
|
564
|
+
if (extra?.nodes?.length) {
|
|
565
|
+
const viaOcr = rankObservation({ ...raw, nodes: [...raw.nodes, ...extra.nodes], ocr: extra.ocr }, findArgs);
|
|
566
|
+
if (viaOcr.nodes.length && (viaOcr.exact || !found.nodes.length)) found = viaOcr;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (!found.nodes.length) throw new DeviceToolError(DeviceErrorCode.GUI_TARGET_NOT_FOUND, `No enabled visible target matched "${query}"`);
|
|
570
|
+
let picked = found.ambiguous ? null : found.nodes[0];
|
|
571
|
+
if (found.ambiguous && found.exact && action === GuiAction.SET_VALUE) picked = pickByLabelRow(found.nodes, found._raw_observation?.nodes || [], query);
|
|
572
|
+
// Khớp một phần (không phần tử nào có đủ mọi từ) cũng là không chắc: chỉ trả ứng viên để BE phân giải, không bấm thẳng.
|
|
573
|
+
if (!picked || !found.exact) return ambiguousResult(found);
|
|
574
|
+
|
|
575
|
+
const node = groundOcrNode(picked, found._raw_observation?.nodes || [], action);
|
|
576
|
+
if (command !== 'fill' && needsServerCheck(query, node)) return ambiguousResult(found);
|
|
577
|
+
if (command === 'fill' && node.password) {
|
|
578
|
+
throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, 'AI may not fill password or secret fields — ask the user to enter it');
|
|
579
|
+
}
|
|
580
|
+
const result = await act({
|
|
581
|
+
action, node_id: node.id,
|
|
582
|
+
text: command === 'fill' ? args.value : undefined,
|
|
583
|
+
option: command === 'select' ? args.value : undefined,
|
|
584
|
+
state: command === 'toggle' ? args.value : undefined,
|
|
585
|
+
}, ctx);
|
|
586
|
+
let verified;
|
|
587
|
+
if (command === 'fill' && Object.hasOwn(result.target || {}, 'value')) verified = String(result.target.value) === String(args.value ?? '');
|
|
588
|
+
if (command === 'select' && Object.hasOwn(result.target || {}, 'selected')) verified = result.target.selected === true;
|
|
589
|
+
if (command === 'toggle' && Object.hasOwn(result.target || {}, 'checked')) {
|
|
590
|
+
const expected = String(args.value || '').toLowerCase();
|
|
591
|
+
verified = expected === 'on' ? result.target.checked === 'on' : expected === 'off' ? result.target.checked === 'off' : undefined;
|
|
592
|
+
}
|
|
593
|
+
if (verified === false) {
|
|
594
|
+
throw new DeviceToolError(DeviceErrorCode.GUI_NO_EFFECT, `${command} ran but the target did not reach the requested state`);
|
|
595
|
+
}
|
|
596
|
+
return {
|
|
597
|
+
ok: true, action: command, target: node.name || node.automation_id || node.role,
|
|
598
|
+
...(verified === undefined ? {} : { verified }),
|
|
599
|
+
...(result.screen_point ? { screen_point: result.screen_point } : {}),
|
|
600
|
+
...(result.app_busy ? { app_busy: true } : {}),
|
|
601
|
+
method: result.method,
|
|
602
|
+
window_class: result.window_class,
|
|
603
|
+
effect: result.window_title_changed || result.target || result.focused_element || command,
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** Chờ phần tử / cửa sổ hiện ra hoặc mất đi — chỉ đọc. Chờ trong một cửa sổ thì cửa sổ đó phải được phép điều khiển. */
|
|
608
|
+
async function waitFor(args, ctx) {
|
|
609
|
+
const elementWait = !!(args.name || args.automation_id);
|
|
610
|
+
if (elementWait || args.window) assertWindowAllowed(await windowInfoOf(args, ctx), { fullAccess });
|
|
611
|
+
return host.call('wait_for', {
|
|
612
|
+
...(elementWait || args.window ? target(args) : {}),
|
|
613
|
+
until: args.until, name: args.name, automation_id: args.automation_id, role: args.role, title_contains: args.title_contains,
|
|
614
|
+
timeout_ms: Math.min(Number(args.timeout_ms) || 10_000, WAIT_MAX_MS),
|
|
615
|
+
}, ctx);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
async function focus(args, ctx) {
|
|
619
|
+
const windowInfo = await windowInfoOf(args, ctx);
|
|
620
|
+
assertWindowAllowed(windowInfo, { fullAccess });
|
|
621
|
+
return whenPersonPauses(ctx, (grace) => host.call('focus', { ...target(args), check_user_input: true, user_input_grace_ms: grace }, ctx));
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
async function act(args, ctx) {
|
|
625
|
+
const action = String(args.action || GuiAction.CLICK);
|
|
626
|
+
if (!Object.values(GuiAction).includes(action)) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, `Unknown action: ${action}`);
|
|
627
|
+
const snap = args.node_id ? String(args.node_id).split('.')[0] : null;
|
|
628
|
+
// node_id đã chỉ đúng phần tử của một lần observe (kèm cửa sổ của nó) — chỉ thao tác không node_id mới phải nêu cửa sổ.
|
|
629
|
+
if (!snap) assertWindowNamed(args.window);
|
|
630
|
+
const windowInfo = snap ? snapshotWindows.get(snap) : await windowInfoOf(args, ctx);
|
|
631
|
+
if (snap && !windowInfo) throw new DeviceToolError(DeviceErrorCode.GUI_STALE_NODE, `Node ${args.node_id} is from an old observation — observe again`);
|
|
632
|
+
assertWindowAllowed(windowInfo, { fullAccess });
|
|
633
|
+
announce(windowInfo);
|
|
634
|
+
return whenPersonPauses(ctx, (grace) => host.call('act', {
|
|
635
|
+
action, node_id: args.node_id, ...(args.node_id ? {} : target(args)), method: args.method, text: args.text, keys: args.keys,
|
|
636
|
+
option: args.option, state: args.state, direction: args.direction, amount: args.amount, point: args.point, to: args.to,
|
|
637
|
+
image_scale: args.image_scale, settle_ms: args.settle_ms,
|
|
638
|
+
// Planner chỉ được xin chờ lâu hơn, không được rút ngắn: rút ngắn là tự cho phép lấy chuột của người đang dùng máy.
|
|
639
|
+
check_user_input: true, user_input_grace_ms: Math.max(grace, Number(args.user_input_grace_ms) || 0),
|
|
640
|
+
}, ctx));
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/** Đọc cả bảng dưới nền: host tự cuộn, gộp các dòng rồi cuộn về chỗ cũ. */
|
|
644
|
+
async function readTable(args, ctx) {
|
|
645
|
+
const snap = args.node_id ? String(args.node_id).split('.')[0] : null;
|
|
646
|
+
if (!snap || String(args.node_id).includes('.t')) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, 'Give node_id of the table (from gui.observe or gui.find)');
|
|
647
|
+
const windowInfo = snapshotWindows.get(snap);
|
|
648
|
+
if (!windowInfo) throw new DeviceToolError(DeviceErrorCode.GUI_STALE_NODE, `Node ${args.node_id} is from an old observation — observe again`);
|
|
649
|
+
assertWindowAllowed(windowInfo, { fullAccess });
|
|
650
|
+
return host.call('read_table', { node_id: args.node_id, max_rows: Math.max(1, Math.min(Number(args.max_rows) || 300, 2000)) }, ctx);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
async function listApps(signal) {
|
|
654
|
+
if (appsCache && Date.now() - appsCache.at < APPS_CACHE_MS) return appsCache.apps;
|
|
655
|
+
if (appsInflight && !signal) return appsInflight;
|
|
656
|
+
const task = Promise.resolve().then(() => fetchApps(signal)).catch(() => []).then((rows) => {
|
|
657
|
+
const apps = (rows || []).filter((r) => r?.Name && r?.AppID).map((r) => ({ name: String(r.Name), app_id: String(r.AppID) }));
|
|
658
|
+
if (apps.length) appsCache = { at: Date.now(), apps };
|
|
659
|
+
return apps.length ? apps : (appsCache?.apps || []);
|
|
660
|
+
}).finally(() => { if (appsInflight === task) appsInflight = null; });
|
|
661
|
+
if (!signal) appsInflight = task;
|
|
662
|
+
return task;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
async function waitNewWindow(before, ctx, hint) {
|
|
666
|
+
const known = new Set(before.map((w) => w.window));
|
|
667
|
+
const deadline = Date.now() + OPEN_WAIT_MS;
|
|
668
|
+
while (Date.now() < deadline) {
|
|
669
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
670
|
+
if (ctx.signal?.aborted) throw ctx.signal.reason;
|
|
671
|
+
const now = await host.call('windows', {}, ctx);
|
|
672
|
+
const fresh = now.filter((w) => !known.has(w.window));
|
|
673
|
+
const pick = fresh.find((w) => hint && normalizeName(`${w.title} ${w.process}`).includes(normalizeName(hint).split(' ')[0])) || fresh[0];
|
|
674
|
+
if (pick) return pick;
|
|
675
|
+
}
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Cửa sổ đang hiện tệp vừa mở: tiêu đề chứa tên tệp, là cửa sổ mới HOẶC cửa sổ có sẵn vừa đổi tiêu đề. gui-bench 13/11/2026: Notepad / Excel /
|
|
681
|
+
* Explorer đang chạy thì mở tệp thành tab trong cửa sổ cũ và đóng cửa sổ tạm — trước đây trả về cửa sổ tạm (đã chết, GUI_WINDOW_GONE ở bước
|
|
682
|
+
* sau) hoặc chờ đủ 10 s "cửa sổ mới" không bao giờ tới. Ứng dụng không ghi tên tệp lên tiêu đề → lấy cửa sổ mới đầu tiên còn sống.
|
|
683
|
+
*/
|
|
684
|
+
async function waitFileWindow(before, base, ctx) {
|
|
685
|
+
const want = normalizeName(base);
|
|
686
|
+
const titleOf = new Map(before.map((w) => [w.window, w.title]));
|
|
687
|
+
const started = Date.now();
|
|
688
|
+
const deadline = started + OPEN_FILE_WAIT_MS;
|
|
689
|
+
let firstFresh = null;
|
|
690
|
+
let freshSince = 0;
|
|
691
|
+
while (Date.now() < deadline) {
|
|
692
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
693
|
+
if (ctx.signal?.aborted) throw ctx.signal.reason;
|
|
694
|
+
const now = await host.call('windows', {}, ctx);
|
|
695
|
+
const showing = now.filter((w) => normalizeName(w.title).includes(want));
|
|
696
|
+
const hit = showing.find((w) => titleOf.get(w.window) !== w.title)
|
|
697
|
+
// Tệp đã mở sẵn ở tab đang hiện: tiêu đề không đổi — nhận sau một nhịp (không thì vừa mở là trả ngay cửa sổ cũ trước khi tab mới kịp hiện).
|
|
698
|
+
|| (Date.now() - started > 1500 ? showing[0] : undefined);
|
|
699
|
+
if (hit) return hit;
|
|
700
|
+
const fresh = now.find((w) => !titleOf.has(w.window));
|
|
701
|
+
if (fresh && !firstFresh) { firstFresh = fresh; freshSince = Date.now(); }
|
|
702
|
+
if (firstFresh && !now.some((w) => w.window === firstFresh.window)) firstFresh = null;
|
|
703
|
+
// Cửa sổ mới đã đứng yên một lúc mà tiêu đề không có tên tệp: ứng dụng đó không ghi tên tệp lên tiêu đề.
|
|
704
|
+
if (firstFresh && Date.now() - freshSince > 2500) return now.find((w) => w.window === firstFresh.window);
|
|
705
|
+
}
|
|
706
|
+
return firstFresh;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/** Cửa sổ đang ở trên cùng trước khi mở ứng dụng, kể cả loại không có trong gui.windows (hộp hệ thống, cửa sổ công cụ). */
|
|
710
|
+
const currentForeground = (ctx) => host.call('window_info', {}, ctx).then((w) => w?.window).catch(() => undefined);
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Cửa sổ AI vừa mở được Windows đưa lên trước → đẩy xuống dưới, trả focus cho cửa sổ người dùng đang dùng (chạy nền). Ứng dụng thường tự
|
|
714
|
+
* kích hoạt lại ngay sau khi cửa sổ hiện ra, nên làm thêm vài lượt ngắn; host chỉ trả focus khi nó vẫn đang ở ứng dụng vừa mở.
|
|
715
|
+
*/
|
|
716
|
+
async function sendToBack(win, userWindow, ctx) {
|
|
717
|
+
if (!win || background === false) return;
|
|
718
|
+
for (const [i, wait] of [0, 350, 600].entries()) {
|
|
719
|
+
if (wait) await new Promise((r) => setTimeout(r, wait));
|
|
720
|
+
if (ctx.signal?.aborted) return;
|
|
721
|
+
await host.call('to_back', { window: win.window, restore_to: userWindow, wait_content: i === 0 }, ctx).catch(() => undefined);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/** Đưa cửa sổ mới xuống nền; cửa sổ đầu tiên đôi khi chỉ là màn hình chờ đã đóng (Sticky Notes) → trả cửa sổ thật thay vì handle đã chết. */
|
|
726
|
+
async function settleNewWindow(win, before, userWindow, hint, ctx) {
|
|
727
|
+
if (!win) return win;
|
|
728
|
+
await sendToBack(win, userWindow, ctx);
|
|
729
|
+
const alive = await host.call('window_info', { window: win.window }, ctx).then(() => true).catch(() => false);
|
|
730
|
+
if (alive) return win;
|
|
731
|
+
const next = await waitNewWindow(before, ctx, hint);
|
|
732
|
+
await sendToBack(next, userWindow, ctx);
|
|
733
|
+
return next;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Chặn mở tệp khi ứng dụng Windows sẽ dùng là "Open with AIVIN Office Suite" (`Aivin.exe --open`) — 13/11/2026, gui-bench: `.csv` trong HKCU
|
|
738
|
+
* trỏ tới ProgID không tồn tại nên Windows rơi về verb AIVIN, tệp bị đem TẢI LÊN Drive thay vì mở trong Excel. AI mở tệp trên máy không được
|
|
739
|
+
* kéo theo việc tải tệp lên mạng. Host không trả lời được thì cho qua (không chặn nhầm vì lỗi tra cứu).
|
|
740
|
+
*/
|
|
741
|
+
async function assertNotAivinOpen(abs, ctx) {
|
|
742
|
+
const ext = path.extname(abs);
|
|
743
|
+
if (!ext) return;
|
|
744
|
+
const assoc = await host.call('assoc', { ext }, ctx).catch(() => null);
|
|
745
|
+
if (!assoc || !isAivinOpenCommand(assoc.command, assoc.executable)) return;
|
|
746
|
+
throw new DeviceToolError(DeviceErrorCode.GUI_BLOCKED_APP,
|
|
747
|
+
`Windows opens ${ext} files on this computer with "AIVIN Office Suite", which uploads the file to Drive — not opened. Open the app by name (e.g. gui.open_app name="Excel") and open the file from there, or ask the user`);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/** Mở ứng dụng theo tên trong danh sách Start, hoặc mở một tệp trong vùng được phép bằng ứng dụng mặc định. Không chạy lệnh tuỳ ý. */
|
|
751
|
+
async function openApp(args, ctx, env) {
|
|
752
|
+
const before = await host.call('windows', {}, ctx);
|
|
753
|
+
const userWindow = await currentForeground(ctx);
|
|
754
|
+
if (args.file) {
|
|
755
|
+
const abs = resolveInRoots(env.roots, String(args.file));
|
|
756
|
+
if (EXECUTABLE_EXT.test(abs)) throw new DeviceToolError(DeviceErrorCode.GUI_BLOCKED_APP, 'Opening programs or scripts is not allowed — use an app name, or shell.exec');
|
|
757
|
+
if (!fs.existsSync(abs)) throw new DeviceToolError(DeviceErrorCode.NOT_FOUND, `File not found: ${args.file}`);
|
|
758
|
+
await assertNotAivinOpen(abs, ctx);
|
|
759
|
+
launchShell(abs);
|
|
760
|
+
const base = path.basename(abs, path.extname(abs));
|
|
761
|
+
const shown = await waitFileWindow(before, base, ctx);
|
|
762
|
+
const win = shown && before.some((w) => w.window === shown.window)
|
|
763
|
+
? (await sendToBack(shown, userWindow, ctx), shown)
|
|
764
|
+
: await settleNewWindow(shown, before, userWindow, base, ctx);
|
|
765
|
+
return { opened: path.basename(abs), window: win, hint: win ? undefined : 'No window shows this file yet — Windows may have no working default app for this file type; check gui.windows, or open the app by name' };
|
|
766
|
+
}
|
|
767
|
+
const name = String(args.name || '').trim();
|
|
768
|
+
if (!name) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, 'Give name (an installed app) or file');
|
|
769
|
+
const matches = matchApps(await listApps(ctx.signal), name);
|
|
770
|
+
if (!matches.length) throw new DeviceToolError(DeviceErrorCode.NOT_FOUND, `No installed app named "${name}"`);
|
|
771
|
+
if (matches.length > 1 && !args.first) return { ambiguous: true, candidates: matches.slice(0, 10).map((m) => m.name), hint: 'Call again with the exact name' };
|
|
772
|
+
const app = matches[0];
|
|
773
|
+
assertAppAllowed(app.name, { fullAccess });
|
|
774
|
+
launchShell(`shell:AppsFolder\\${app.app_id}`);
|
|
775
|
+
const win = await settleNewWindow(await waitNewWindow(before, ctx, app.name), before, userWindow, app.name, ctx);
|
|
776
|
+
if (win) assertWindowAllowed(win, { fullAccess });
|
|
777
|
+
return { opened: app.name, window: win, hint: win ? undefined : 'App started but no new window yet — call gui.windows in a moment' };
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
return { windows, observe, find, waitFor, focus, act, readTable, semanticDo, openApp, prewarm: () => listApps(), close: () => host.close() };
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/** Công cụ GUI cho danh mục của Planner. */
|
|
784
|
+
export function buildGuiTools(gui) {
|
|
785
|
+
const target = {
|
|
786
|
+
node_id: str('target element id from the latest gui.observe (preferred)'),
|
|
787
|
+
window: str('window handle (0x…) or a title/process to match; reading defaults to the focused window, but an action without node_id must name it (asked from the mascot: the window the person was using)'),
|
|
788
|
+
};
|
|
789
|
+
return [
|
|
790
|
+
{ name: 'gui.do', group: ToolGroup.GUI, handler: (a, c, e) => gui.semanticDo(a, c, e),
|
|
791
|
+
description: 'Fast semantic desktop action. State the intent briefly; the device finds one enabled visible target, refuses ambiguity, acts, and verifies simple value/state changes. Use precise gui.find/gui.act only after an ambiguous result.',
|
|
792
|
+
input_schema: schema({
|
|
793
|
+
do: str('click | fill | select | toggle | key | scroll | open'), target: str('short visible label or app name'),
|
|
794
|
+
value: str('text, option, on/off, key chord, or scroll direction'), within: str('window title/process to act in (required, except when asked from the mascot)'),
|
|
795
|
+
role: str('optional role such as button or edit'), file: str('document path for open'),
|
|
796
|
+
}, ['do']) },
|
|
797
|
+
{ name: 'gui.windows', group: ToolGroup.GUI, read_only: true, handler: (a, c) => gui.windows(a, c),
|
|
798
|
+
description: 'List open desktop windows: title, app process, handle, position, which is focused/minimized. blocked = the AI may not control it.',
|
|
799
|
+
input_schema: schema({ include_dialogs: bool('also list owned dialogs') }) },
|
|
800
|
+
{ name: 'gui.observe', group: ToolGroup.GUI, read_only: true, handler: (a, c) => gui.observe(a, c),
|
|
801
|
+
description: 'Read a window as an accessibility tree: each element has an id (node_id), role, name, value, state and supported actions. tree_quality "poor" = the app draws its own UI; a screenshot is then attached and the text on it is read on the device (OCR): each text run becomes a node with role "text", source "ocr" and an id like "4.t2" that gui.act can click / type at. Ids are only valid until the next observe of that window. truncated_by = why the list is partial: time / long_list (a very long table or list; scroll it, or use gui.find) / node_limit. In a long table scrolled far down, the rows on screen come back with role "row", source "accessible" and an id like "4.t2" that gui.act can click. content_unavailable = a Store app shows only its frame because it is still starting or suspended — gui.focus it, then observe again. image_error = no screenshot this time (the app can only be captured from the screen and the window is behind/covered — gui.focus it first if a screenshot is needed).',
|
|
802
|
+
input_schema: schema({
|
|
803
|
+
window: target.window, include_image: bool('attach a screenshot even when the tree is good'), max_nodes: num('default 300'),
|
|
804
|
+
ocr: bool('read the text on the window even when the tree is good (default: only when poor)'),
|
|
805
|
+
}) },
|
|
806
|
+
{ name: 'gui.find', group: ToolGroup.GUI, read_only: true, handler: (a, c) => gui.find(a, c),
|
|
807
|
+
description: 'Like gui.observe but returns only the elements whose name / AutomationId / value contains the query words (accents ignored), optionally of one role — for big windows (spreadsheets, ERP forms) where the full tree is too long. Ids work with gui.act right away. exact=false means no element had every word; the closest ones are returned.',
|
|
808
|
+
input_schema: schema({
|
|
809
|
+
query: str('words of the element, e.g. "Save", "Số tiền", "Customer name"'), window: target.window,
|
|
810
|
+
role: str('only this role, e.g. button, edit, menuitem, dataitem'), max: num('default 20, max 60'),
|
|
811
|
+
}, ['query']) },
|
|
812
|
+
{ name: 'gui.wait_for', group: ToolGroup.GUI, read_only: true, handler: (a, c) => gui.waitFor(a, c),
|
|
813
|
+
description: 'Wait until the UI reaches a state instead of observing again and again: an element (name contains / automation_id, optional role) appears or is gone in a window, or a window whose title contains some text appears or is gone (no window = any window). Returns met + waited_ms + the match; GUI_WAIT_TIMEOUT if it did not happen in time.',
|
|
814
|
+
input_schema: schema({
|
|
815
|
+
until: str('appears (default) | gone'), window: target.window, name: str('element name contains this text (case-insensitive)'),
|
|
816
|
+
automation_id: str('element AutomationId (exact)'), role: str('element role, e.g. button, menuitem, edit, window'),
|
|
817
|
+
title_contains: str('wait on a window title instead of an element'), timeout_ms: num('default 10000, max 60000'),
|
|
818
|
+
}) },
|
|
819
|
+
{ name: 'gui.read_table', group: ToolGroup.GUI, read_only: true, handler: (a, c) => gui.readTable(a, c),
|
|
820
|
+
description: 'Read a whole long table as data, in the background: scrolls it, joins the rows, scrolls back. Prefer this to observing and scrolling screen by screen. node_id = the table, from gui.observe or gui.find. Returns columns, rows (each one line of cells), complete, reason when incomplete, gaps = rows may be missing between pages.',
|
|
821
|
+
input_schema: schema({ node_id: target.node_id, max_rows: num('default 300, at most 2000') }, ['node_id']) },
|
|
822
|
+
{ name: 'gui.focus', group: ToolGroup.GUI, handler: (a, c) => gui.focus(a, c),
|
|
823
|
+
description: 'Bring a window to the front (restores it if minimized). This takes the screen from the person using the computer: most actions work on windows behind others, so only use it when an action really needs the window in front.',
|
|
824
|
+
input_schema: schema({ window: target.window }, ['window']) },
|
|
825
|
+
{ name: 'gui.act', group: ToolGroup.GUI, handler: (a, c) => gui.act(a, c),
|
|
826
|
+
description: 'Runs behind the person\'s windows whenever the app allows it. Result method: invoke/value/select/toggle/scroll/background/posted = done without the real mouse; accessible = the control selected the item but no click event fired, so check the app reacted (observe) before relying on it. The real mouse/keyboard is only borrowed when the person pauses for a moment, then given back; GUI_USER_ACTIVE = they kept using the computer, nothing was done, so tell them in the chat. Do one action on an element (node_id) or at a point of the last screenshot: click, double_click, right_click, set_value (replace a field\'s text), type (keystrokes into the focused element), key (shortcut like "ctrl+s", "alt+f4", "enter"), scroll, select (option of a list/combo), toggle, expand, collapse, drag. Uses accessibility actions first (works even when the window is behind), real mouse/keyboard otherwise. Returns evidence: the element\'s new value/state, window title change, focused element; app_busy = the action ran but the app is still working, so no evidence yet — gui.wait_for or observe later. OCR text nodes ("4.t2") take click / double_click / right_click, or set_value / type (clicks there, then types). Without node_id give window. Stops with GUI_USER_ACTIVE if the person is using the mouse/keyboard, and with GUI_FOCUS_LOST (nothing clicked / the rest not typed) if real mouse/keyboard input could not reach the window — it could not come to the front, or another window covers the point.',
|
|
827
|
+
// method trong kết quả: posted = gửi thẳng vào cửa sổ; accessible = control tự chọn mục, không phát sự kiện bấm.
|
|
828
|
+
input_schema: schema({
|
|
829
|
+
action: str(Object.values(GuiAction).join(' | ')), ...target, text: str('text for set_value / type'), keys: str('for key: e.g. "ctrl+s", several separated by spaces'),
|
|
830
|
+
option: str('for select: the option name'), state: str('for toggle: on | off'), direction: str('for scroll: up | down | left | right'), amount: num('scroll steps, default 3'),
|
|
831
|
+
point: { type: 'object', description: '{x,y} on the last screenshot when no node_id', properties: { x: num('x'), y: num('y') } },
|
|
832
|
+
to: { type: 'object', description: 'drag destination {x,y} on the last screenshot', properties: { x: num('x'), y: num('y') } },
|
|
833
|
+
image_scale: num('scale of the screenshot the point was taken from'), method: str('auto | pattern | mouse | background (default auto; background = never touch the real mouse/keyboard, fail with GUI_NEEDS_REAL_INPUT instead)'),
|
|
834
|
+
}, ['action']) },
|
|
835
|
+
{ name: 'gui.open_app', group: ToolGroup.GUI, handler: (a, c, e) => gui.openApp(a, c, e),
|
|
836
|
+
description: 'Open an installed app by name (from the Start menu list), or open a document file with its default app. Returns the new window. Does not run programs or scripts by path.',
|
|
837
|
+
input_schema: schema({ name: str('app name, e.g. "Excel", "Calculator"'), file: str('a document path inside the allowed folders'), first: bool('take the first match when several apps share the name') }) },
|
|
838
|
+
];
|
|
839
|
+
}
|