dsh-world 0.7.6 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +541 -479
- package/CONTRIBUTING.md +174 -174
- package/INSTALL.md +314 -314
- package/NOTES.md +57 -3
- package/README.md +332 -259
- package/client/index.js +1126 -991
- package/lib/compaction.d.ts +1 -0
- package/lib/compaction.js +1 -1
- package/lib/console/routes.d.ts +11 -3
- package/lib/console/routes.js +12 -7
- package/lib/console/snapshot.d.ts +2 -0
- package/lib/console/snapshot.js +1 -0
- package/lib/ecosystem/computer/browser/browser.d.ts +34 -0
- package/lib/ecosystem/computer/browser/browser.js +101 -0
- package/lib/ecosystem/computer/browser/cdp.d.ts +22 -0
- package/lib/ecosystem/computer/browser/cdp.js +91 -0
- package/lib/ecosystem/computer/browser/edge.d.ts +15 -0
- package/lib/ecosystem/computer/browser/edge.js +80 -0
- package/lib/ecosystem/computer/browser/page.d.ts +41 -0
- package/lib/ecosystem/computer/browser/page.js +140 -0
- package/lib/ecosystem/computer/browser/pageLib.d.ts +7 -0
- package/lib/ecosystem/computer/browser/pageLib.js +106 -0
- package/lib/ecosystem/computer/desktop/desktop.d.ts +91 -0
- package/lib/ecosystem/computer/desktop/desktop.js +322 -0
- package/lib/ecosystem/computer/desktop/driver.d.ts +34 -0
- package/lib/ecosystem/computer/desktop/driver.js +197 -0
- package/lib/ecosystem/computer/desktop/processes.d.ts +5 -0
- package/lib/ecosystem/computer/desktop/processes.js +15 -0
- package/lib/ecosystem/computer/desktop/recording.d.ts +77 -0
- package/lib/ecosystem/computer/desktop/recording.js +187 -0
- package/lib/ecosystem/computer/desktop/screen.d.ts +33 -0
- package/lib/ecosystem/computer/desktop/screen.js +182 -0
- package/lib/ecosystem/computer/desktop/turns.d.ts +58 -0
- package/lib/ecosystem/computer/desktop/turns.js +94 -0
- package/lib/ecosystem/computer/desktop/watching.d.ts +25 -0
- package/lib/ecosystem/computer/desktop/watching.js +81 -0
- package/lib/ecosystem/computer/inbox/inbox.d.ts +32 -0
- package/lib/ecosystem/computer/inbox/inbox.js +142 -0
- package/lib/ecosystem/computer/index.d.ts +82 -0
- package/lib/ecosystem/computer/index.js +133 -0
- package/lib/ecosystem/computer/procedures/alarm.d.ts +13 -0
- package/lib/ecosystem/computer/procedures/alarm.js +46 -0
- package/lib/ecosystem/computer/procedures/archive.d.ts +32 -0
- package/lib/ecosystem/computer/procedures/archive.js +68 -0
- package/lib/ecosystem/computer/procedures/catalog.d.ts +7 -0
- package/lib/ecosystem/computer/procedures/catalog.js +75 -0
- package/lib/ecosystem/computer/procedures/format.d.ts +167 -0
- package/lib/ecosystem/computer/procedures/format.js +332 -0
- package/lib/ecosystem/computer/procedures/library.d.ts +53 -0
- package/lib/ecosystem/computer/procedures/library.js +178 -0
- package/lib/ecosystem/computer/procedures/run.d.ts +80 -0
- package/lib/ecosystem/computer/procedures/run.js +245 -0
- package/lib/ecosystem/computer/tools.d.ts +21 -0
- package/lib/ecosystem/computer/tools.js +197 -0
- package/lib/ecosystem/qq-native/images.d.ts +3 -0
- package/lib/ecosystem/qq-native/images.js +18 -6
- package/lib/ecosystem/qq-native/index.js +2 -2
- package/lib/ecosystem/shared/turn.d.ts +3 -0
- package/lib/ecosystem/shared/turn.js +13 -3
- package/lib/ecosystem/wechat/home.d.ts +1 -0
- package/lib/ecosystem/wechat/home.js +9 -3
- package/lib/ecosystem/wechat/images.js +3 -5
- package/lib/ecosystem/wechat/index.d.ts +1 -0
- package/lib/ecosystem/wechat/reading.d.ts +1 -1
- package/lib/ecosystem/wechat/reading.js +2 -2
- package/lib/history.js +2 -1
- package/lib/images.d.ts +30 -0
- package/lib/images.js +101 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +90 -5
- package/lib/life/photoTools.js +4 -15
- package/lib/life/runtime.d.ts +12 -2
- package/lib/life/runtime.js +93 -12
- package/lib/life/toolRegistry.d.ts +9 -3
- package/lib/life/toolRegistry.js +46 -27
- package/lib/life/turnCost.d.ts +16 -0
- package/lib/life/turnCost.js +44 -0
- package/lib/life/types.d.ts +17 -0
- package/lib/memoryTools.d.ts +2 -1
- package/lib/memoryTools.js +16 -3
- package/lib/promptSection.d.ts +1 -0
- package/lib/promptSection.js +29 -42
- package/lib/runtime.js +1 -1
- package/lib/types.d.ts +4 -0
- package/lib/worldAdd.d.ts +9 -0
- package/lib/worldAdd.js +39 -0
- package/lib/worldPrompt.d.ts +3 -2
- package/lib/worldPrompt.js +3 -2
- package/lib/worldRoutes.d.ts +5 -2
- package/lib/worldRoutes.js +29 -4
- package/lib/worldSwitch.d.ts +8 -2
- package/lib/worldSwitch.js +11 -5
- package/package.json +132 -129
- package/src/ecosystem/README.md +2 -1
- package/src/ecosystem/computer/NOTICE.md +27 -0
- package/src/ecosystem/computer/README.md +244 -0
- package/src/ecosystem/computer/desktop/win32.ps1 +858 -0
- package/src/ecosystem/wechat/windows/README.md +4 -2
- package/src/ecosystem/wechat/windows/engine/NOTICE.md +6 -0
- package/src/ecosystem/wechat/windows/engine/profiles.json +28 -0
- package/templates/world-prompt-memory.md +10 -10
- package/templates/world-prompt.md +65 -65
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// src/ecosystem/computer/browser/pageLib.ts
|
|
2
|
+
/**
|
|
3
|
+
* Installed into her page on every call; a no-op while the same version is already there, which is what keeps an
|
|
4
|
+
* element's number the same across reads until the page navigates. Roles and names are computed here once, so a read
|
|
5
|
+
* and an anchor in one of her tools mean the same thing. The registry, roles, names and visibility rules are ported
|
|
6
|
+
* from dsh-inner-browser-use's read.js (MIT, see ../NOTICE.md).
|
|
7
|
+
*/
|
|
8
|
+
export const PAGE_LIB = String.raw `(() => {
|
|
9
|
+
const VERSION = 1;
|
|
10
|
+
if (window.__dshWorld && window.__dshWorld.version === VERSION) return;
|
|
11
|
+
const SELECTOR = 'a[href],button,input:not([type="hidden"]),select,textarea,summary,label[for],[contenteditable="true"],[tabindex]:not([tabindex="-1"]),[role="button"],[role="link"],[role="tab"],[role="checkbox"],[role="radio"],[role="switch"],[role="combobox"],[role="menuitem"],[role="option"],[role="textbox"],[role="searchbox"]';
|
|
12
|
+
const refs = new Map(); const ids = new WeakMap(); let seq = Number(window.__dshBase) || 0;
|
|
13
|
+
const clean = s => String(s == null ? '' : s).replace(/\s+/g, ' ').trim();
|
|
14
|
+
const id = el => { const known = ids.get(el); if (known !== undefined && refs.get(known) === el) return known; seq += 1; ids.set(el, seq); refs.set(seq, el); return seq; };
|
|
15
|
+
const roots = () => { const out = [document]; for (let i = 0; i < out.length; i++) for (const el of out[i].querySelectorAll('*')) if (el.shadowRoot) out.push(el.shadowRoot); return out; };
|
|
16
|
+
// Walking the shadow roots is the costly part, so each exported call does it once and passes the list down.
|
|
17
|
+
const all = (selector, scope, rs) => scope ? Array.from(scope.querySelectorAll(selector)) : rs.flatMap(root => Array.from(root.querySelectorAll(selector)));
|
|
18
|
+
const role = el => {
|
|
19
|
+
const explicit = el.getAttribute('role'); if (explicit) return explicit;
|
|
20
|
+
const tag = el.tagName.toLowerCase();
|
|
21
|
+
if (tag === 'a') return 'link'; if (tag === 'summary') return 'button'; if (tag === 'li') return 'listitem';
|
|
22
|
+
if (tag === 'textarea' || el.isContentEditable) return 'textbox';
|
|
23
|
+
if (tag === 'input') { const type = String(el.type || 'text'); return type === 'submit' || type === 'button' ? 'button' : type === 'checkbox' || type === 'radio' ? type : 'textbox'; }
|
|
24
|
+
return tag;
|
|
25
|
+
};
|
|
26
|
+
const name = el => {
|
|
27
|
+
const labelled = clean(String(el.getAttribute('aria-labelledby') || '').split(/\s+/).filter(Boolean).map(x => { const o = el.ownerDocument.getElementById(x); return o ? (o.innerText || o.textContent) : ''; }).join(' '));
|
|
28
|
+
const label = el.labels && el.labels[0] ? clean(el.labels[0].innerText) : '';
|
|
29
|
+
const value = el.tagName === 'INPUT' && el.type !== 'password' ? el.value : '';
|
|
30
|
+
return clean(labelled || el.getAttribute('aria-label') || label || el.getAttribute('title') || el.getAttribute('placeholder') || el.innerText || value || el.getAttribute('alt') || '').slice(0, 140);
|
|
31
|
+
};
|
|
32
|
+
const shown = el => { const b = el.getBoundingClientRect(); if (b.width < 2 || b.height < 2) return false; const s = getComputedStyle(el); return s.visibility !== 'hidden' && s.display !== 'none' && Number(s.opacity) > 0.05; };
|
|
33
|
+
const inView = el => { const b = el.getBoundingClientRect(); return b.bottom > 0 && b.right > 0 && b.top < innerHeight && b.left < innerWidth; };
|
|
34
|
+
const matches = (el, a) => (!a.role || role(el) === a.role) && (!a.name || name(el).includes(a.name)) && (!a.text || (clean(el.textContent).includes(a.text) && clean(el.innerText).includes(a.text)));
|
|
35
|
+
const visibleMatches = (a, scope, rs) => all(a.css || '*', scope, rs).filter(el => matches(el, a) && shown(el));
|
|
36
|
+
// The innermost of nested matches: a page wraps the same words in several boxes.
|
|
37
|
+
const innermost = hits => hits.filter(el => !hits.some(other => other !== el && el.contains(other)));
|
|
38
|
+
const locate = (a, scope, rs) => innermost(visibleMatches(a, scope, rs))[a.nth || 0] || null;
|
|
39
|
+
const find = ref => { const el = refs.get(ref); if (!el || !el.isConnected) { refs.delete(ref); return null; } return el; };
|
|
40
|
+
const target = (t, rs) => t.ref !== undefined ? find(t.ref) : locate(t.anchor, null, rs);
|
|
41
|
+
const reaches = (el, hit) => { for (let n = el; n; n = n.getRootNode().host) if (n === hit || n.contains(hit)) return true; return false; };
|
|
42
|
+
const controls = (scope, rs) => {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const el of all(SELECTOR, scope, rs)) {
|
|
45
|
+
if (!shown(el)) continue;
|
|
46
|
+
const label = name(el);
|
|
47
|
+
if (!label && !['INPUT', 'SELECT', 'TEXTAREA'].includes(el.tagName)) continue;
|
|
48
|
+
out.push({ ref: id(el), role: role(el), name: label, view: inView(el), value: el.tagName === 'INPUT' && el.type !== 'password' ? clean(el.value).slice(0, 80) : '' });
|
|
49
|
+
}
|
|
50
|
+
return out.sort((a, b) => Number(b.view) - Number(a.view));
|
|
51
|
+
};
|
|
52
|
+
const visibleText = (scope, budget) => {
|
|
53
|
+
const parts = []; let used = 0;
|
|
54
|
+
const walker = document.createTreeWalker(scope || document.querySelector('main, article, [role="main"]') || document.body, NodeFilter.SHOW_TEXT);
|
|
55
|
+
for (let node = walker.nextNode(); node && used < budget; node = walker.nextNode()) {
|
|
56
|
+
const words = clean(node.nodeValue); const parent = node.parentElement;
|
|
57
|
+
if (!words || !parent || !shown(parent) || !inView(parent)) continue;
|
|
58
|
+
parts.push(words); used += words.length + 1;
|
|
59
|
+
}
|
|
60
|
+
return parts.join('\n');
|
|
61
|
+
};
|
|
62
|
+
window.__dshWorld = {
|
|
63
|
+
version: VERSION,
|
|
64
|
+
snapshot(ref, budget) {
|
|
65
|
+
const scope = ref == null ? null : find(ref);
|
|
66
|
+
if (ref != null && !scope) return { missing: true };
|
|
67
|
+
return { url: location.href, title: document.title, controls: controls(scope, scope ? null : roots()), text: visibleText(scope, budget + 1) };
|
|
68
|
+
},
|
|
69
|
+
point(t) {
|
|
70
|
+
const el = target(t, roots()); if (!el) return null;
|
|
71
|
+
el.scrollIntoView({ block: 'center', inline: 'center', behavior: 'instant' });
|
|
72
|
+
const b = el.getClientRects()[0] || el.getBoundingClientRect();
|
|
73
|
+
const x = b.left + b.width / 2, y = b.top + b.height / 2;
|
|
74
|
+
const hit = document.elementFromPoint(x, y);
|
|
75
|
+
if (!(hit && reaches(el, hit))) return { covered: true, by: hit ? hit.tagName.toLowerCase() + ' ' + name(hit).slice(0, 30) : '页面之外' };
|
|
76
|
+
return { x, y };
|
|
77
|
+
},
|
|
78
|
+
focus(t) {
|
|
79
|
+
const el = target(t, roots()); if (!el) return 'missing';
|
|
80
|
+
el.scrollIntoView({ block: 'center', behavior: 'instant' }); el.focus();
|
|
81
|
+
if (!(document.activeElement === el || el.contains(document.activeElement))) return 'unfocusable';
|
|
82
|
+
// Typing replaces what is there, as a person would after selecting it.
|
|
83
|
+
try {
|
|
84
|
+
if (el.select) el.select();
|
|
85
|
+
else if (el.isContentEditable) { const range = document.createRange(); range.selectNodeContents(el); const sel = getSelection(); sel.removeAllRanges(); sel.addRange(range); }
|
|
86
|
+
} catch (e) { /* an input type that cannot select: typing then adds */ }
|
|
87
|
+
return 'ok';
|
|
88
|
+
},
|
|
89
|
+
has(c) {
|
|
90
|
+
return (!c.text || (!!document.body && clean(document.body.innerText).includes(c.text))) && (!c.url || location.href.includes(c.url)) && (!c.anchor || !!locate(c.anchor, null, roots()));
|
|
91
|
+
},
|
|
92
|
+
extract(spec) {
|
|
93
|
+
const rs = roots();
|
|
94
|
+
// Every visible item in document order; nested items keep their parents.
|
|
95
|
+
return visibleMatches(spec.list, null, rs).slice(0, spec.limit || 8).map(item => {
|
|
96
|
+
const row = {};
|
|
97
|
+
for (const key of Object.keys(spec.fields)) {
|
|
98
|
+
const field = spec.fields[key];
|
|
99
|
+
const el = !field.role && !field.name && !field.text && !field.css ? item : locate(field, item, null);
|
|
100
|
+
row[key] = !el ? '' : field.attr ? clean(el.getAttribute(field.attr)).slice(0, 200) : clean(el.innerText || el.textContent).slice(0, 200);
|
|
101
|
+
}
|
|
102
|
+
return row;
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
})()`;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { DesktopDriver } from './driver.ts';
|
|
2
|
+
import { type DesktopResult } from './turns.ts';
|
|
3
|
+
export { STOPPED, type DesktopAction, type DesktopResult } from './turns.ts';
|
|
4
|
+
export type Desktop = ReturnType<typeof createDesktop>;
|
|
5
|
+
/** The screenshot's long edge; her coordinates are in this image's pixels and are mapped back to the window's. */
|
|
6
|
+
export declare const IMAGE_EDGE = 1280;
|
|
7
|
+
/** A zoomed part is enlarged at most this many times, past which it only gets blurrier. */
|
|
8
|
+
export declare const ZOOM_GROW = 4;
|
|
9
|
+
/** Mouse-wheel notches per scroll: about a screenful in most programs. */
|
|
10
|
+
export declare const NOTCHES = 3;
|
|
11
|
+
export declare const VK: Record<string, number>;
|
|
12
|
+
export declare const DESKTOP_KEYS = "return\u3001tab\u3001escape\u3001space\u3001backspace\u3001delete\u3001home\u3001end\u3001pageup\u3001pagedown\u3001\u65B9\u5411\u952E up/down/left/right\u3001f1\u2013f12\u3001\u5355\u4E2A\u5B57\u6BCD\u6216\u6570\u5B57\uFF0C\u53EF\u52A0 ctrl+\u3001shift+\u3001alt+";
|
|
13
|
+
/** `owner` is the window it belongs to (0 for a main window): dialogs and panels such as WeChat's Moments composer. */
|
|
14
|
+
export interface Listed {
|
|
15
|
+
hwnd: number;
|
|
16
|
+
owner: number;
|
|
17
|
+
pid: number;
|
|
18
|
+
exe: string;
|
|
19
|
+
title: string;
|
|
20
|
+
minimized: boolean;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}
|
|
24
|
+
export declare const largest: (windows: Listed[]) => Listed;
|
|
25
|
+
/** A key as people write it (`Enter`, `ctrl+f`) to its virtual-key code and modifiers; anything else is refused. */
|
|
26
|
+
export declare function desktopKey(text: string): {
|
|
27
|
+
vk: number;
|
|
28
|
+
modifiers: number[];
|
|
29
|
+
};
|
|
30
|
+
/** The longest she can hold a button or a key: the helper does nothing else meanwhile, and cannot be stopped mid-press. */
|
|
31
|
+
export declare const MAX_HOLD_SECONDS = 10;
|
|
32
|
+
/** `hold` (seconds) as milliseconds, 0 for a plain press; out of range is refused. */
|
|
33
|
+
export declare function holdMs(hold: number | undefined): number;
|
|
34
|
+
/** What she is told she did: a press, or a press held for so long. */
|
|
35
|
+
/** What she is told after a drag: where it went, and how long it was held first. */
|
|
36
|
+
export declare const dragged: (hold: number | undefined) => string;
|
|
37
|
+
export declare const pressed: (what: string, hold: number | undefined) => string;
|
|
38
|
+
/** The program's windows, by her name for it: an exact title, the executable, then a title that starts with it. */
|
|
39
|
+
export declare function windowsNamed(windows: Listed[], name: string): Listed[];
|
|
40
|
+
/**
|
|
41
|
+
* Her turn on the partner's computer: one current window, its last picture, and what she did. She sees screenshots
|
|
42
|
+
* and acts by their pixels, the way a person does. Input is posted to the window, so the partner's pointer and focus
|
|
43
|
+
* stay theirs; a window that is brought up or launched hands the focus straight back. One action at a time, in order.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createDesktop(deps: {
|
|
46
|
+
driver: Pick<DesktopDriver, 'call'>;
|
|
47
|
+
running?(executable: string): Promise<boolean>;
|
|
48
|
+
settleMs?: number;
|
|
49
|
+
appearMs?: number;
|
|
50
|
+
secondMs?: number;
|
|
51
|
+
/** Her name on the banner the partner sees while she acts; without it there is no banner. */
|
|
52
|
+
companion?(): string;
|
|
53
|
+
/** A banner that could not be drawn: said in the console's health, never a failed action of hers. */
|
|
54
|
+
signFault?(text: string | undefined): void;
|
|
55
|
+
lingerMs?: number;
|
|
56
|
+
}): {
|
|
57
|
+
actions: string[];
|
|
58
|
+
act: (input: DesktopInput) => Promise<DesktopResult>;
|
|
59
|
+
recent: () => import("./turns.ts").DesktopAction[];
|
|
60
|
+
halt: () => {
|
|
61
|
+
cut: boolean;
|
|
62
|
+
recording: boolean;
|
|
63
|
+
};
|
|
64
|
+
release: () => void;
|
|
65
|
+
halted: () => boolean;
|
|
66
|
+
/** When the switch goes off: nothing she opened stays "current" for a later turn, and what she recorded is deleted. */
|
|
67
|
+
reset(): void;
|
|
68
|
+
};
|
|
69
|
+
export interface DesktopInput {
|
|
70
|
+
action: string;
|
|
71
|
+
app?: string;
|
|
72
|
+
x?: number;
|
|
73
|
+
y?: number;
|
|
74
|
+
x2?: number;
|
|
75
|
+
y2?: number;
|
|
76
|
+
text?: string;
|
|
77
|
+
submit?: boolean;
|
|
78
|
+
key?: string;
|
|
79
|
+
direction?: string;
|
|
80
|
+
double?: boolean;
|
|
81
|
+
right?: boolean;
|
|
82
|
+
/** For `click`, `drag` and `press`: seconds to keep the button or the key down (a long press, or walking in a game). */
|
|
83
|
+
hold?: number;
|
|
84
|
+
/** For `record`: how long, and how far apart the frames are. For `review`: a stretch of the recording, or one moment of it. */
|
|
85
|
+
seconds?: number;
|
|
86
|
+
every?: number;
|
|
87
|
+
from?: number;
|
|
88
|
+
to?: number;
|
|
89
|
+
at?: number;
|
|
90
|
+
pause?: boolean;
|
|
91
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// src/ecosystem/computer/desktop/desktop.ts
|
|
2
|
+
import { readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { isRunning } from "./processes.js";
|
|
6
|
+
import { createRecording } from "./recording.js";
|
|
7
|
+
import { createTurns } from "./turns.js";
|
|
8
|
+
import { watching } from "./watching.js";
|
|
9
|
+
export { STOPPED } from "./turns.js";
|
|
10
|
+
/** The screenshot's long edge; her coordinates are in this image's pixels and are mapped back to the window's. */
|
|
11
|
+
export const IMAGE_EDGE = 1280;
|
|
12
|
+
/** A zoomed part is enlarged at most this many times, past which it only gets blurrier. */
|
|
13
|
+
export const ZOOM_GROW = 4;
|
|
14
|
+
const WINDOWS_SHOWN = 30;
|
|
15
|
+
/** How long a program has to repaint after input before the next picture, and to show a window after a launch. */
|
|
16
|
+
const SETTLE_MS = 400, APPEAR_MS = 10_000, GIVE_BACK_TRIES = 3;
|
|
17
|
+
/** Mouse-wheel notches per scroll: about a screenful in most programs. */
|
|
18
|
+
export const NOTCHES = 3;
|
|
19
|
+
export const VK = {
|
|
20
|
+
return: 0x0d, tab: 0x09, escape: 0x1b, space: 0x20, backspace: 0x08, delete: 0x2e, home: 0x24, end: 0x23,
|
|
21
|
+
pageup: 0x21, pagedown: 0x22, left: 0x25, up: 0x26, right: 0x27, down: 0x28,
|
|
22
|
+
};
|
|
23
|
+
const MODIFIER_VK = { ctrl: 0x11, shift: 0x10, alt: 0x12 };
|
|
24
|
+
const KEY_ALIASES = { enter: 'return', esc: 'escape', pgup: 'pageup', pgdn: 'pagedown', del: 'delete' };
|
|
25
|
+
export const DESKTOP_KEYS = 'return、tab、escape、space、backspace、delete、home、end、pageup、pagedown、方向键 up/down/left/right、f1–f12、单个字母或数字,可加 ctrl+、shift+、alt+';
|
|
26
|
+
/** `D:\\微信\\Weixin\\Weixin.exe` → `Weixin`; a Store app's id has no executable. */
|
|
27
|
+
const executable = (appId) => /([^\\/"]+)\.exe$/i.exec(appId)?.[1];
|
|
28
|
+
const area = (window) => window.width * window.height;
|
|
29
|
+
export const largest = (windows) => [...windows].sort((a, b) => area(b) - area(a))[0];
|
|
30
|
+
const pause = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
31
|
+
/** A key as people write it (`Enter`, `ctrl+f`) to its virtual-key code and modifiers; anything else is refused. */
|
|
32
|
+
export function desktopKey(text) {
|
|
33
|
+
const parts = text.toLowerCase().split('+').map(part => KEY_ALIASES[part.trim()] ?? part.trim());
|
|
34
|
+
const last = parts.pop() ?? '';
|
|
35
|
+
const vk = VK[last] ?? (/^f([1-9]|1[0-2])$/.test(last) ? 0x6f + Number(last.slice(1)) : /^[a-z0-9]$/.test(last) ? last.toUpperCase().charCodeAt(0) : undefined);
|
|
36
|
+
if (vk === undefined || !parts.every(part => part in MODIFIER_VK))
|
|
37
|
+
throw new Error(`不认识按键 ${text},可用:${DESKTOP_KEYS}`);
|
|
38
|
+
return { vk, modifiers: parts.map(part => MODIFIER_VK[part]) };
|
|
39
|
+
}
|
|
40
|
+
/** The longest she can hold a button or a key: the helper does nothing else meanwhile, and cannot be stopped mid-press. */
|
|
41
|
+
export const MAX_HOLD_SECONDS = 10;
|
|
42
|
+
/** `hold` (seconds) as milliseconds, 0 for a plain press; out of range is refused. */
|
|
43
|
+
export function holdMs(hold) {
|
|
44
|
+
if (hold === undefined)
|
|
45
|
+
return 0;
|
|
46
|
+
if (!(hold > 0 && hold <= MAX_HOLD_SECONDS))
|
|
47
|
+
throw new Error(`hold 是按住的秒数,大于 0、最多 ${MAX_HOLD_SECONDS}`);
|
|
48
|
+
return Math.round(hold * 1000);
|
|
49
|
+
}
|
|
50
|
+
/** What she is told she did: a press, or a press held for so long. */
|
|
51
|
+
/** What she is told after a drag: where it went, and how long it was held first. */
|
|
52
|
+
export const dragged = (hold) => hold === undefined ? '已拖过去。' : `已按住 ${hold} 秒再拖过去。`;
|
|
53
|
+
export const pressed = (what, hold) => hold === undefined ? `已${what}。` : `已${what === '点击' ? '长按' : what},按住 ${hold} 秒。`;
|
|
54
|
+
/** The program's windows, by her name for it: an exact title, the executable, then a title that starts with it. */
|
|
55
|
+
export function windowsNamed(windows, name) {
|
|
56
|
+
const wanted = name.toLowerCase();
|
|
57
|
+
const hit = windows.find(entry => entry.title.toLowerCase() === wanted) ?? windows.find(entry => entry.exe.toLowerCase() === wanted)
|
|
58
|
+
?? windows.find(entry => entry.title.toLowerCase().startsWith(wanted));
|
|
59
|
+
return hit ? windows.filter(entry => entry.pid === hit.pid) : [];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Her turn on the partner's computer: one current window, its last picture, and what she did. She sees screenshots
|
|
63
|
+
* and acts by their pixels, the way a person does. Input is posted to the window, so the partner's pointer and focus
|
|
64
|
+
* stay theirs; a window that is brought up or launched hands the focus straight back. One action at a time, in order.
|
|
65
|
+
*/
|
|
66
|
+
export function createDesktop(deps) {
|
|
67
|
+
const running = deps.running ?? isRunning, settleMs = deps.settleMs ?? SETTLE_MS, appearMs = deps.appearMs ?? APPEAR_MS;
|
|
68
|
+
let window, view, shots = 0;
|
|
69
|
+
/** The program's windows as last seen, and her last input: what changed after it, and how soon, is told to her. */
|
|
70
|
+
let known, acted;
|
|
71
|
+
const call = (op, args = {}) => deps.driver.call(op, args).catch((error) => {
|
|
72
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
73
|
+
// Windows keeps an ordinary program away from an administrator's windows; background mode has no way round that.
|
|
74
|
+
if (/ELEVATED/.test(why))
|
|
75
|
+
throw new Error(`${window?.app ?? '这个窗口'}是以管理员权限运行的程序,后台模式截不到、也点不了它。要操作它,请伙伴切到前台模式。`);
|
|
76
|
+
throw new Error(`没做成:${why}`);
|
|
77
|
+
});
|
|
78
|
+
const recording = createRecording({ call, ...(deps.secondMs === undefined ? {} : { secondMs: deps.secondMs }) });
|
|
79
|
+
async function list() {
|
|
80
|
+
const data = await call('windows');
|
|
81
|
+
return { windows: data.windows ?? [], foreground: Number(data.foreground ?? 0) };
|
|
82
|
+
}
|
|
83
|
+
function current() {
|
|
84
|
+
if (!window)
|
|
85
|
+
throw new Error('还没有打开窗口:先 desktop open 一个程序');
|
|
86
|
+
return window;
|
|
87
|
+
}
|
|
88
|
+
/** A picture pixel to a window pixel; outside the picture is refused, it would land in some other window. */
|
|
89
|
+
function onWindow(x, y) {
|
|
90
|
+
current();
|
|
91
|
+
if (!view)
|
|
92
|
+
throw new Error('还没看过这个窗口:先 desktop shot');
|
|
93
|
+
if (typeof x !== 'number' || typeof y !== 'number')
|
|
94
|
+
throw new Error('要给 x、y(截图上的像素)');
|
|
95
|
+
if (x < 0 || y < 0 || x > view.width || y > view.height)
|
|
96
|
+
throw new Error(`x、y 要在截图里面(${view.width}×${view.height})`);
|
|
97
|
+
return { x: Math.round(x * view.scale), y: Math.round(y * view.scale) };
|
|
98
|
+
}
|
|
99
|
+
/** A window that went away (closed, minimized, into the tray) is never pictured; she is told and opens it again. */
|
|
100
|
+
async function visible() {
|
|
101
|
+
const open = current(), { windows } = await list();
|
|
102
|
+
if (windows.some(entry => entry.hwnd === open.hwnd && !entry.minimized))
|
|
103
|
+
return { open, windows };
|
|
104
|
+
window = undefined;
|
|
105
|
+
view = undefined;
|
|
106
|
+
throw new Error(`${open.app} 的窗口不见了(关掉了、最小化了或收进了托盘):先 desktop open 它`);
|
|
107
|
+
}
|
|
108
|
+
/** A picture holds one window only, so a dialog or panel the program opened beside it is named, or she would never know. */
|
|
109
|
+
function others({ open, windows }) {
|
|
110
|
+
const titles = [...new Set(windows.filter(entry => entry.pid === open.pid && entry.hwnd !== open.hwnd && !entry.minimized).map(entry => `「${entry.title}」`))];
|
|
111
|
+
return titles.length ? `\n${open.app} 还开着别的窗口:${titles.join('、')},不在这张截图里;要操作它就 desktop open 它的标题。` : '';
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A dialog or panel opens a moment after the input that asked for it. By hand she never notices, since she looks
|
|
115
|
+
* between steps; a replay does not wait unless she wrote it down. So each change is told with the time it took.
|
|
116
|
+
*/
|
|
117
|
+
function changes({ open, windows }) {
|
|
118
|
+
const now = new Map(windows.filter(entry => entry.pid === open.pid && !entry.minimized).map(entry => [entry.hwnd, entry.title]));
|
|
119
|
+
const before = known;
|
|
120
|
+
known = now;
|
|
121
|
+
if (!before || !acted)
|
|
122
|
+
return '';
|
|
123
|
+
const appeared = [...now].filter(([hwnd]) => !before.has(hwnd)).map(([, title]) => `「${title}」`);
|
|
124
|
+
const gone = [...before].filter(([hwnd]) => !now.has(hwnd)).map(([, title]) => `「${title}」`);
|
|
125
|
+
if (!appeared.length && !gone.length)
|
|
126
|
+
return '';
|
|
127
|
+
const what = [appeared.length ? `出现了${appeared.join('、')}` : '', gone.length ? `关掉了${gone.join('、')}` : ''].filter(Boolean).join(',');
|
|
128
|
+
return `\n窗口变了:${what}(在上一次${acted.what}之后 ${((Date.now() - acted.at) / 1000).toFixed(1)} 秒内)。窗口是过一会儿才变的;存成操作时,用到它的那一步前面要加 wait,回放时步与步之间不停。`;
|
|
129
|
+
}
|
|
130
|
+
async function picture(region, mark) {
|
|
131
|
+
const seen = await visible(), { hwnd } = seen.open;
|
|
132
|
+
const file = join(tmpdir(), `dsh-world-desktop-${process.pid}-${++shots}.png`);
|
|
133
|
+
try {
|
|
134
|
+
const shot = await call('shot', { hwnd, file, edge: IMAGE_EDGE, grow: region ? ZOOM_GROW : 1, ...(region ?? { x: 0, y: 0, w: 0, h: 0 }), markX: mark?.x ?? -1, markY: mark?.y ?? -1 });
|
|
135
|
+
return { data: readFileSync(file), width: Number(shot.width), height: Number(shot.height), clientWidth: Number(shot.clientWidth), also: changes(seen) + others(seen) };
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
rmSync(file, { force: true });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function shot(said = '', mark) {
|
|
142
|
+
const taken = await picture(undefined, mark);
|
|
143
|
+
if (mark)
|
|
144
|
+
said += '图上的红圈是刚才点到的地方,没点中就看偏了多少,改了再点。';
|
|
145
|
+
view = { scale: taken.clientWidth / taken.width, width: taken.width, height: taken.height };
|
|
146
|
+
return { text: `${said}${current().app} 的截图附在下一条消息里(${taken.width}×${taken.height})。按图上的像素用 desktop click 带 x、y;字太小就 desktop zoom。${taken.also}`, image: { data: taken.data, mediaType: 'image/png' } };
|
|
147
|
+
}
|
|
148
|
+
/** After acting she sees the result: a wrong click is caught by her, not assumed fine. */
|
|
149
|
+
async function after(done, clicked) {
|
|
150
|
+
await pause(settleMs);
|
|
151
|
+
return shot(done, clicked);
|
|
152
|
+
}
|
|
153
|
+
/** Waits for a window of the program to show up, as one does after a click on the tray or a launch. */
|
|
154
|
+
async function appear(name, exe, before) {
|
|
155
|
+
for (const deadline = Date.now() + appearMs;;) {
|
|
156
|
+
const { windows } = await list();
|
|
157
|
+
const fresh = windows.filter(entry => !before.has(entry.hwnd));
|
|
158
|
+
const mine = windowsNamed(windows, name).length ? windowsNamed(windows, name)
|
|
159
|
+
: exe ? windows.filter(entry => entry.exe.toLowerCase() === exe.toLowerCase()) : [];
|
|
160
|
+
if (mine.length)
|
|
161
|
+
return mine;
|
|
162
|
+
if (Date.now() >= deadline)
|
|
163
|
+
return fresh.length === 1 ? fresh : [];
|
|
164
|
+
await pause(Math.min(500, appearMs));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** The partner's window goes back in front; a sentence for her when that did not work. */
|
|
168
|
+
async function giveBack(foreground) {
|
|
169
|
+
if (!foreground)
|
|
170
|
+
return '原来在前面的是桌面,焦点留在新窗口上。';
|
|
171
|
+
// The program pulls itself to the front a moment after its window shows (WeChat from the tray does), which undoes
|
|
172
|
+
// a hand-back made too early; so it is checked after a pause and made again.
|
|
173
|
+
for (let attempt = 0; attempt < GIVE_BACK_TRIES; attempt++) {
|
|
174
|
+
await pause(settleMs);
|
|
175
|
+
await call('refocus', { hwnd: foreground });
|
|
176
|
+
await pause(settleMs);
|
|
177
|
+
if ((await list()).foreground === foreground)
|
|
178
|
+
return '焦点还给了伙伴原来的窗口。';
|
|
179
|
+
}
|
|
180
|
+
return '焦点没能还给伙伴原来的窗口。';
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A program closed to the tray has no window, and launching it again opens a second copy (WeChat 4.x does), so
|
|
184
|
+
* its tray icon is clicked: that is the program showing itself, which a window forced visible from outside is not.
|
|
185
|
+
*/
|
|
186
|
+
async function fromTray(name, foreground, before) {
|
|
187
|
+
const cursor = (await call('cursor')).cursor;
|
|
188
|
+
const tray = await call('tray', { name });
|
|
189
|
+
if (tray.result !== 'opened')
|
|
190
|
+
return { windows: [], told: '' };
|
|
191
|
+
const windows = await appear(name, undefined, before);
|
|
192
|
+
if (!windows.length)
|
|
193
|
+
throw new Error(`点了 ${name} 的托盘图标,但 ${appearMs / 1000} 秒内没有出现它的窗口`);
|
|
194
|
+
const moved = JSON.stringify(tray.cursor) !== JSON.stringify(cursor) ? '(伙伴的鼠标位置变了,可能是伙伴自己在动。)' : '';
|
|
195
|
+
return { windows, told: `它收在托盘里,已经从托盘图标点开;${await giveBack(foreground)}${moved}\n` };
|
|
196
|
+
}
|
|
197
|
+
async function launch(name, foreground, before) {
|
|
198
|
+
const apps = (await call('apps')).apps ?? [];
|
|
199
|
+
const wanted = name.toLowerCase();
|
|
200
|
+
const app = apps.find(entry => entry.name.toLowerCase() === wanted) ?? apps.find(entry => entry.name.toLowerCase().includes(wanted));
|
|
201
|
+
if (!app)
|
|
202
|
+
throw new Error(`找不到叫「${name}」的程序:开着的窗口、托盘图标和开始菜单里都没有。不带 app 调 desktop open 看看开着哪些`);
|
|
203
|
+
const exe = executable(app.appId);
|
|
204
|
+
if (exe && await running(exe))
|
|
205
|
+
throw new Error(`${app.name} 开着,但没有窗口,托盘里也找不到它的图标;再启动会多开一个,所以不启动。请伙伴把它打开。`);
|
|
206
|
+
await call('launch', { appId: app.appId });
|
|
207
|
+
const windows = await appear(app.name, exe, before);
|
|
208
|
+
if (!windows.length)
|
|
209
|
+
throw new Error(`${app.name} 启动了,但 ${appearMs / 1000} 秒内没有出现窗口`);
|
|
210
|
+
return { windows, told: `${app.name} 没开,已经启动;${await giveBack(foreground)}\n` };
|
|
211
|
+
}
|
|
212
|
+
async function open(app) {
|
|
213
|
+
const { windows, foreground } = await list();
|
|
214
|
+
if (!app?.trim()) {
|
|
215
|
+
const titles = [...new Set(windows.map(entry => entry.title))].slice(0, WINDOWS_SHOWN);
|
|
216
|
+
return { text: `开着的窗口:${titles.join('、') || '(没有)'}。收在托盘里的、没开的,写它的名字也能打开。` };
|
|
217
|
+
}
|
|
218
|
+
const name = app.trim(), before = new Set(windows.map(entry => entry.hwnd));
|
|
219
|
+
let mine = windowsNamed(windows, name), told = '';
|
|
220
|
+
if (!mine.length)
|
|
221
|
+
({ windows: mine, told } = await fromTray(name, foreground, before));
|
|
222
|
+
if (!mine.length)
|
|
223
|
+
({ windows: mine, told } = await launch(name, foreground, before));
|
|
224
|
+
// Her name may be one window's own title (a panel such as 朋友圈); otherwise the program's main window.
|
|
225
|
+
const titled = mine.find(entry => entry.title.toLowerCase() === name.toLowerCase() && !entry.minimized);
|
|
226
|
+
let chosen = titled ?? largest(mine.filter(entry => !entry.minimized && !entry.owner)) ?? largest(mine.filter(entry => !entry.minimized));
|
|
227
|
+
if (!chosen) {
|
|
228
|
+
const minimized = largest(mine);
|
|
229
|
+
if ((await call('restore', { hwnd: minimized.hwnd })).restored !== true)
|
|
230
|
+
throw new Error(`${name} 最小化着,还原不出来`);
|
|
231
|
+
chosen = minimized;
|
|
232
|
+
told += '它原来最小化着,已经还原,没有抢伙伴的焦点。\n';
|
|
233
|
+
}
|
|
234
|
+
// Switching between one program's windows keeps what was seen; another program starts afresh.
|
|
235
|
+
if (window?.pid !== chosen.pid)
|
|
236
|
+
known = undefined;
|
|
237
|
+
window = { hwnd: chosen.hwnd, pid: chosen.pid, app: name };
|
|
238
|
+
view = undefined;
|
|
239
|
+
return shot(told);
|
|
240
|
+
}
|
|
241
|
+
// The sign: a banner the program words (never her text) and a frame around the window she is on, while she acts.
|
|
242
|
+
async function sign(show) {
|
|
243
|
+
if (!deps.companion || (show && !window))
|
|
244
|
+
return;
|
|
245
|
+
try {
|
|
246
|
+
await deps.driver.call('sign', show && window ? { show: true, hwnd: window.hwnd, text: `${deps.companion()}正在操作`, hint: '连按两下 Esc 停下', stop: '停下', stopped: '已停下' } : { show: false });
|
|
247
|
+
deps.signFault?.(undefined);
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
deps.signFault?.(`她操作时的提示没能显示:${error instanceof Error ? error.message : String(error)}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const watch = watching({
|
|
254
|
+
recording, what: app => ` ${app} 的窗口`, keep: '窗口不能最小化、不能收进托盘。',
|
|
255
|
+
target: async () => {
|
|
256
|
+
const { open: target } = await visible();
|
|
257
|
+
return {
|
|
258
|
+
key: `window:${target.hwnd}`, app: target.app,
|
|
259
|
+
capture: async (file, edge) => String((await call('shot', { hwnd: target.hwnd, file, edge, grow: 1, x: 0, y: 0, w: 0, h: 0, markX: -1, markY: -1 })).print ?? ''),
|
|
260
|
+
space: () => call('key', { hwnd: target.hwnd, vk: VK.space, modifiers: [] }),
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
const run = {
|
|
265
|
+
record: input => watch.record(input),
|
|
266
|
+
stop: () => watch.stop(),
|
|
267
|
+
review: input => watch.review(input),
|
|
268
|
+
open: input => open(input.app),
|
|
269
|
+
shot: () => shot(),
|
|
270
|
+
click: async (input) => {
|
|
271
|
+
const at = onWindow(input.x, input.y);
|
|
272
|
+
await call('click', { hwnd: current().hwnd, ...at, right: input.right === true, count: input.double ? 2 : 1, hold: holdMs(input.hold) });
|
|
273
|
+
return after(pressed('点击', input.hold), at);
|
|
274
|
+
},
|
|
275
|
+
drag: async (input) => {
|
|
276
|
+
const from = onWindow(input.x, input.y), to = onWindow(input.x2, input.y2);
|
|
277
|
+
await call('drag', { hwnd: current().hwnd, x: from.x, y: from.y, x2: to.x, y2: to.y, right: input.right === true, hold: holdMs(input.hold) });
|
|
278
|
+
return after(dragged(input.hold), to);
|
|
279
|
+
},
|
|
280
|
+
type: async (input) => {
|
|
281
|
+
if (typeof input.text !== 'string' || !input.text)
|
|
282
|
+
throw new Error('text 不能是空的');
|
|
283
|
+
const at = input.x !== undefined || input.y !== undefined ? onWindow(input.x, input.y) : undefined;
|
|
284
|
+
if (at)
|
|
285
|
+
await call('click', { hwnd: current().hwnd, ...at, right: false, count: 1 });
|
|
286
|
+
await call('type', { hwnd: current().hwnd, text: input.text });
|
|
287
|
+
if (input.submit)
|
|
288
|
+
await call('key', { hwnd: current().hwnd, vk: VK.return, modifiers: [] });
|
|
289
|
+
return after(input.submit ? '已输入并回车。' : '已输入。', at);
|
|
290
|
+
},
|
|
291
|
+
press: async (input) => {
|
|
292
|
+
await call('key', { hwnd: current().hwnd, ...desktopKey(String(input.key ?? '')), hold: holdMs(input.hold) });
|
|
293
|
+
return after(pressed(`按 ${input.key}`, input.hold));
|
|
294
|
+
},
|
|
295
|
+
scroll: async (input) => {
|
|
296
|
+
const step = { up: [NOTCHES, 0], down: [-NOTCHES, 0], left: [0, -NOTCHES], right: [0, NOTCHES] }[String(input.direction)];
|
|
297
|
+
if (!step)
|
|
298
|
+
throw new Error('direction 只能是 up、down、left 或 right');
|
|
299
|
+
if (!view)
|
|
300
|
+
throw new Error('还没看过这个窗口:先 desktop shot');
|
|
301
|
+
const at = input.x === undefined && input.y === undefined ? onWindow(view.width / 2, view.height / 2) : onWindow(input.x, input.y);
|
|
302
|
+
await call('scroll', { hwnd: current().hwnd, ...at, up: step[0], right: step[1] });
|
|
303
|
+
return after('已滚动。');
|
|
304
|
+
},
|
|
305
|
+
zoom: async (input) => {
|
|
306
|
+
const from = onWindow(input.x, input.y), to = onWindow(input.x2, input.y2);
|
|
307
|
+
if (!(to.x > from.x && to.y > from.y))
|
|
308
|
+
throw new Error('zoom 要给左上角 x、y 和右下角 x2、y2(截图上的像素)');
|
|
309
|
+
const part = await picture({ x: from.x, y: from.y, w: to.x - from.x, h: to.y - from.y });
|
|
310
|
+
return { text: '放大的局部附在下一条消息里;在它上面量的坐标不能直接点,回到整张截图上点。', image: { data: part.data, mediaType: 'image/png' } };
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
const turns = createTurns({
|
|
314
|
+
run, sign, recording, app: () => window?.app, ...(deps.lingerMs === undefined ? {} : { lingerMs: deps.lingerMs }),
|
|
315
|
+
acted: what => { acted = { what, at: Date.now() }; },
|
|
316
|
+
});
|
|
317
|
+
return {
|
|
318
|
+
actions: turns.actions, act: turns.act, recent: turns.recent, halt: turns.halt, release: turns.release, halted: turns.halted,
|
|
319
|
+
/** When the switch goes off: nothing she opened stays "current" for a later turn, and what she recorded is deleted. */
|
|
320
|
+
reset() { window = undefined; view = undefined; known = undefined; acted = undefined; recording.clear(); turns.reset(); },
|
|
321
|
+
};
|
|
322
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Faults } from '../../../faults.ts';
|
|
2
|
+
export type DesktopDriver = ReturnType<typeof createDesktopDriver>;
|
|
3
|
+
export declare const HELPER_SCRIPT: string;
|
|
4
|
+
/**
|
|
5
|
+
* The Windows helper (`win32.ps1`) in a child process, started on first use and ended with the module. A crash or a
|
|
6
|
+
* hung call fails what is pending, is a fault, and the next call starts it again; starts that keep dying stop there,
|
|
7
|
+
* so a broken machine is said once instead of relaunched on every step. Her inbox runs a helper of its own (`as`), so
|
|
8
|
+
* a slow step of hers and a look at the notifications never wait on each other.
|
|
9
|
+
*
|
|
10
|
+
* `elevated` is foreground mode's helper: started as administrator, so the partner approves it once through UAC. A UAC
|
|
11
|
+
* prompt cannot share stdin and stdout, so it dials back to a pipe opened here and proves itself with a one-time key.
|
|
12
|
+
* It is never restarted behind the partner's back: once it is gone, foreground mode is over until it is turned on again.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createDesktopDriver(deps: {
|
|
15
|
+
faults: Faults;
|
|
16
|
+
command?: string[];
|
|
17
|
+
callMs?: number;
|
|
18
|
+
as?: {
|
|
19
|
+
fault: string;
|
|
20
|
+
name: string;
|
|
21
|
+
stopped: string;
|
|
22
|
+
};
|
|
23
|
+
events?(name: string): void;
|
|
24
|
+
elevated?: boolean;
|
|
25
|
+
elevateMs?: number;
|
|
26
|
+
}): {
|
|
27
|
+
/** One helper operation by name, e.g. `windows` or `click`; a refusal rejects with the helper's reason. */
|
|
28
|
+
call(op: string, args?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
29
|
+
/** Starts it now rather than on first use: foreground mode asks for administrator rights when it is turned on. */
|
|
30
|
+
start: () => Promise<void>;
|
|
31
|
+
running: () => boolean;
|
|
32
|
+
/** Ends the helper and forgets a halted start, so turning the switch on again tries afresh. */
|
|
33
|
+
stop(): void;
|
|
34
|
+
};
|