@namzu/computer-use 4.1.0 → 4.2.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 +12 -0
- package/dist/SubprocessComputerUseHost.d.ts +18 -1
- package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
- package/dist/SubprocessComputerUseHost.js +28 -2
- package/dist/SubprocessComputerUseHost.js.map +1 -1
- package/dist/a11y/a11y-script.d.ts +47 -0
- package/dist/a11y/a11y-script.d.ts.map +1 -0
- package/dist/a11y/a11y-script.js +738 -0
- package/dist/a11y/a11y-script.js.map +1 -0
- package/dist/a11y/a11y.d.ts +60 -0
- package/dist/a11y/a11y.d.ts.map +1 -0
- package/dist/a11y/a11y.js +400 -0
- package/dist/a11y/a11y.js.map +1 -0
- package/dist/a11y/index.d.ts +8 -0
- package/dist/a11y/index.d.ts.map +1 -0
- package/dist/a11y/index.js +5 -0
- package/dist/a11y/index.js.map +1 -0
- package/dist/a11y/interface.d.ts +198 -0
- package/dist/a11y/interface.d.ts.map +1 -0
- package/dist/a11y/interface.js +22 -0
- package/dist/a11y/interface.js.map +1 -0
- package/dist/a11y/windows.d.ts +20 -0
- package/dist/a11y/windows.d.ts.map +1 -0
- package/dist/a11y/windows.js +40 -0
- package/dist/a11y/windows.js.map +1 -0
- package/dist/adapters/cua-driver/adapter.d.ts +47 -0
- package/dist/adapters/cua-driver/adapter.d.ts.map +1 -1
- package/dist/adapters/cua-driver/adapter.js +138 -3
- package/dist/adapters/cua-driver/adapter.js.map +1 -1
- package/dist/adapters/types.d.ts +11 -0
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/adapters/win32.d.ts +3 -0
- package/dist/adapters/win32.d.ts.map +1 -1
- package/dist/adapters/win32.js +1 -0
- package/dist/adapters/win32.js.map +1 -1
- package/dist/foreground/guard.d.ts.map +1 -1
- package/dist/foreground/guard.js +1 -0
- package/dist/foreground/guard.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/presence/helper-script.d.ts +18 -11
- package/dist/presence/helper-script.d.ts.map +1 -1
- package/dist/presence/helper-script.js +301 -86
- package/dist/presence/helper-script.js.map +1 -1
- package/dist/presence/index.d.ts +3 -1
- package/dist/presence/index.d.ts.map +1 -1
- package/dist/presence/index.js +2 -1
- package/dist/presence/index.js.map +1 -1
- package/dist/presence/motion.d.ts +84 -0
- package/dist/presence/motion.d.ts.map +1 -0
- package/dist/presence/motion.js +114 -0
- package/dist/presence/motion.js.map +1 -0
- package/dist/presence/preview.d.ts +25 -0
- package/dist/presence/preview.d.ts.map +1 -0
- package/dist/presence/preview.js +32 -0
- package/dist/presence/preview.js.map +1 -0
- package/package.json +2 -2
- package/src/SubprocessComputerUseHost.ts +48 -1
- package/src/a11y/a11y-script.ts +740 -0
- package/src/a11y/a11y.ts +499 -0
- package/src/a11y/index.ts +24 -0
- package/src/a11y/interface.ts +226 -0
- package/src/a11y/windows.ts +56 -0
- package/src/adapters/cua-driver/adapter.ts +151 -6
- package/src/adapters/types.ts +8 -0
- package/src/adapters/win32.ts +4 -0
- package/src/foreground/guard.ts +1 -0
- package/src/index.ts +19 -0
- package/src/presence/helper-script.ts +327 -87
- package/src/presence/index.ts +10 -1
- package/src/presence/motion.ts +141 -0
- package/src/presence/preview.ts +42 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the computer-use host needs to know about a desktop's windows and
|
|
3
|
+
* their contents, written without any one platform's terms so a macOS or a
|
|
4
|
+
* Linux backend only adds a file that implements {@link AccessibilityBackend}.
|
|
5
|
+
*
|
|
6
|
+
* - A window is named by an opaque `windowId` string; the backend defines its
|
|
7
|
+
* format and accepts the ones it handed out.
|
|
8
|
+
* - Rectangles are virtual-desktop physical pixels.
|
|
9
|
+
* - Nothing here is a promise about speed except {@link AccessibilityBackend.listWindows},
|
|
10
|
+
* which a backend serves from the platform's window list without reading
|
|
11
|
+
* any window's contents.
|
|
12
|
+
*/
|
|
13
|
+
export interface A11yRect {
|
|
14
|
+
readonly x: number;
|
|
15
|
+
readonly y: number;
|
|
16
|
+
readonly width: number;
|
|
17
|
+
readonly height: number;
|
|
18
|
+
}
|
|
19
|
+
/** A top-level window a person would call a window. */
|
|
20
|
+
export interface A11yWindow {
|
|
21
|
+
readonly windowId: string;
|
|
22
|
+
readonly processId: number;
|
|
23
|
+
/** The program's file name (`app.exe` on Windows); empty when it cannot be read. */
|
|
24
|
+
readonly processName: string;
|
|
25
|
+
readonly title: string;
|
|
26
|
+
readonly bounds: A11yRect;
|
|
27
|
+
readonly minimized: boolean;
|
|
28
|
+
/** The window the user is typing into. */
|
|
29
|
+
readonly focused: boolean;
|
|
30
|
+
/** Position front to back among the listed windows; 0 is in front. */
|
|
31
|
+
readonly z: number;
|
|
32
|
+
}
|
|
33
|
+
export interface A11yDisplay {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly bounds: A11yRect;
|
|
36
|
+
/** The part of the display not taken by the shell's own bars. */
|
|
37
|
+
readonly workArea: A11yRect;
|
|
38
|
+
/** 1 is 96 dpi, 1.5 is 144 dpi. */
|
|
39
|
+
readonly scale: number;
|
|
40
|
+
readonly primary: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** What a control can be asked to do, by the pattern it offers. */
|
|
43
|
+
export type A11yAction = 'invoke' | 'value' | 'toggle' | 'expandCollapse' | 'selectionItem' | 'scroll';
|
|
44
|
+
export interface A11yNode {
|
|
45
|
+
/** Position in {@link A11ySnapshot.nodes}; the handle `identity` takes. */
|
|
46
|
+
readonly index: number;
|
|
47
|
+
/** Index of the parent, -1 for the window itself. */
|
|
48
|
+
readonly parent: number;
|
|
49
|
+
readonly depth: number;
|
|
50
|
+
/** The control's kind (`Button`, `Edit`, `Text`, …), as the platform names it. */
|
|
51
|
+
readonly role: string;
|
|
52
|
+
readonly name?: string;
|
|
53
|
+
readonly automationId?: string;
|
|
54
|
+
readonly className?: string;
|
|
55
|
+
readonly bounds: A11yRect;
|
|
56
|
+
readonly enabled: boolean;
|
|
57
|
+
readonly offscreen: boolean;
|
|
58
|
+
readonly focused: boolean;
|
|
59
|
+
readonly actions: readonly A11yAction[];
|
|
60
|
+
readonly value?: string;
|
|
61
|
+
readonly toggle?: 'on' | 'off' | 'mixed';
|
|
62
|
+
readonly expand?: 'expanded' | 'collapsed' | 'partial' | 'leaf';
|
|
63
|
+
readonly selected?: boolean;
|
|
64
|
+
/** Present when the children of this control were not all listed. */
|
|
65
|
+
readonly childCount?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface A11ySnapshotRequest {
|
|
68
|
+
readonly windowId: string;
|
|
69
|
+
/** Default 400. */
|
|
70
|
+
readonly maxNodes?: number;
|
|
71
|
+
/** Default 12. */
|
|
72
|
+
readonly maxDepth?: number;
|
|
73
|
+
/** Only the window, its children and theirs, with `childCount` on the containers. */
|
|
74
|
+
readonly skeleton?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Read a Chromium or Electron window anyway. Reading one switches its
|
|
77
|
+
* accessibility on for the rest of the session, so it is refused
|
|
78
|
+
* (`chromium_not_activated`) unless the caller asks.
|
|
79
|
+
*/
|
|
80
|
+
readonly allowChromium?: boolean;
|
|
81
|
+
/** Longest the read may take, ms. Default 8 000. */
|
|
82
|
+
readonly timeoutMs?: number;
|
|
83
|
+
}
|
|
84
|
+
export interface A11ySnapshot {
|
|
85
|
+
readonly windowId: string;
|
|
86
|
+
/** Names this read; `identity` refuses an index from an older one when given it. */
|
|
87
|
+
readonly revision: number;
|
|
88
|
+
readonly nodes: readonly A11yNode[];
|
|
89
|
+
/** Controls in the window, listed or not. */
|
|
90
|
+
readonly total: number;
|
|
91
|
+
readonly truncated: boolean;
|
|
92
|
+
readonly skeleton: boolean;
|
|
93
|
+
/** How long the platform call took, ms. */
|
|
94
|
+
readonly readMs: number;
|
|
95
|
+
}
|
|
96
|
+
/** Which kind of change to wait for. Default: all. */
|
|
97
|
+
export type A11yChangeKind = 'structure' | 'property' | 'location';
|
|
98
|
+
/** A marker in the stream of changes; see {@link AccessibilityBackend.seq}. Opaque. */
|
|
99
|
+
export type A11ySeq = number;
|
|
100
|
+
export interface A11yWaitRequest {
|
|
101
|
+
readonly windowId: string;
|
|
102
|
+
/** A token from {@link AccessibilityBackend.seq}: count changes since then. Default: since this call. */
|
|
103
|
+
readonly since?: A11ySeq;
|
|
104
|
+
/** How long the window must stay quiet after its last change, ms. Default 120. */
|
|
105
|
+
readonly quietMs?: number;
|
|
106
|
+
/** Longest to wait, ms. Default 2 000, at most 10 000. */
|
|
107
|
+
readonly timeoutMs?: number;
|
|
108
|
+
readonly kinds?: readonly A11yChangeKind[];
|
|
109
|
+
}
|
|
110
|
+
export type A11yWaitResult = {
|
|
111
|
+
readonly changed: true;
|
|
112
|
+
/** False when changes were still arriving at the timeout. */
|
|
113
|
+
readonly settled: boolean;
|
|
114
|
+
/** From the start of the wait to the first change; negative when it came earlier (see `since`). */
|
|
115
|
+
readonly firstEventMs: number;
|
|
116
|
+
readonly settledMs: number;
|
|
117
|
+
readonly events: number;
|
|
118
|
+
/** Windows of the same program that appeared. */
|
|
119
|
+
readonly newWindows: readonly string[];
|
|
120
|
+
} | {
|
|
121
|
+
readonly changed: false;
|
|
122
|
+
readonly timedOut: true;
|
|
123
|
+
readonly settledMs: number;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Names a control well enough to find it again after the window changed:
|
|
127
|
+
* the platform's own runtime id first, else its automation id and kind, else
|
|
128
|
+
* its kind, a hash of its name and the path of its ancestors. Holds no text.
|
|
129
|
+
*/
|
|
130
|
+
export interface A11yFingerprint {
|
|
131
|
+
readonly runtimeId: string;
|
|
132
|
+
readonly automationId: string;
|
|
133
|
+
readonly role: string;
|
|
134
|
+
readonly nameHash: string;
|
|
135
|
+
readonly parentPath: string;
|
|
136
|
+
/** Among siblings with the same kind and name. */
|
|
137
|
+
readonly ordinal: number;
|
|
138
|
+
/** When the owning process started (ms); a different value means a different program run. */
|
|
139
|
+
readonly processStart: number;
|
|
140
|
+
}
|
|
141
|
+
export interface A11yIdentityRequest {
|
|
142
|
+
readonly windowId: string;
|
|
143
|
+
readonly index: number;
|
|
144
|
+
/** Refuse (`stale_snapshot`) when the window was read again since this revision. */
|
|
145
|
+
readonly revision?: number;
|
|
146
|
+
}
|
|
147
|
+
export interface A11yResolveRequest {
|
|
148
|
+
readonly windowId: string;
|
|
149
|
+
readonly fingerprint: A11yFingerprint;
|
|
150
|
+
}
|
|
151
|
+
export type A11yResolution = {
|
|
152
|
+
readonly found: true;
|
|
153
|
+
/** Index in the read this call made (it is the window's latest snapshot now). */
|
|
154
|
+
readonly index: number;
|
|
155
|
+
readonly via: 'runtimeId' | 'automationId' | 'name';
|
|
156
|
+
readonly revision: number;
|
|
157
|
+
} | {
|
|
158
|
+
readonly found: false;
|
|
159
|
+
readonly code: 'not_found' | 'ambiguous';
|
|
160
|
+
readonly candidates?: number;
|
|
161
|
+
};
|
|
162
|
+
export interface AccessibilityBackend {
|
|
163
|
+
/** Which implementation this is, for diagnosis. */
|
|
164
|
+
readonly id: string;
|
|
165
|
+
/** True once the backend answered its first greeting and has not ended since. */
|
|
166
|
+
readonly isReady: boolean;
|
|
167
|
+
/** Starts the backend ahead of the first question. Does not wait; safe to repeat. */
|
|
168
|
+
warm(): void;
|
|
169
|
+
/** Resolves true when the backend is up; false (never throws) when it cannot be. */
|
|
170
|
+
ready(): Promise<boolean>;
|
|
171
|
+
/** The visible, un-cloaked, non-tool top-level windows, front to back. */
|
|
172
|
+
listWindows(options?: {
|
|
173
|
+
readonly includeOwned?: boolean;
|
|
174
|
+
}, signal?: AbortSignal): Promise<readonly A11yWindow[]>;
|
|
175
|
+
listDisplays(signal?: AbortSignal): Promise<readonly A11yDisplay[]>;
|
|
176
|
+
snapshot(request: A11ySnapshotRequest, signal?: AbortSignal): Promise<A11ySnapshot>;
|
|
177
|
+
/**
|
|
178
|
+
* A marker in the stream of changes. With a window it also starts
|
|
179
|
+
* watching that window (the first time costs about 100 ms), so that
|
|
180
|
+
* `const since = await seq(w); act(); await waitForChange({ windowId: w, since })`
|
|
181
|
+
* misses nothing the action did.
|
|
182
|
+
*/
|
|
183
|
+
seq(windowId?: string, signal?: AbortSignal): Promise<A11ySeq>;
|
|
184
|
+
/**
|
|
185
|
+
* Resolves from events, not from sleeping: after at least one change and
|
|
186
|
+
* then `quietMs` without another, or `{ changed: false }` after `timeoutMs`.
|
|
187
|
+
*/
|
|
188
|
+
waitForChange(request: A11yWaitRequest, signal?: AbortSignal): Promise<A11yWaitResult>;
|
|
189
|
+
identity(request: A11yIdentityRequest, signal?: AbortSignal): Promise<A11yFingerprint>;
|
|
190
|
+
resolve(request: A11yResolveRequest, signal?: AbortSignal): Promise<A11yResolution>;
|
|
191
|
+
close(): Promise<void>;
|
|
192
|
+
}
|
|
193
|
+
/** A failure the backend reports, or the client's own (`timeout`, `helper_exited`, `unavailable`, …). */
|
|
194
|
+
export declare class A11yError extends Error {
|
|
195
|
+
readonly code: string;
|
|
196
|
+
constructor(code: string, message: string);
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/a11y/interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACvB;AAED,uDAAuD;AACvD,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,oF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AO,CAAC,SAAS,UAAU,EAAE,CAAC,CAAA;IACjC,YAAY,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,WAAW,EAAE,CAAC,CAAA;IACnE,QAAQ,CAAC,OAAO,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IACnF;;;;;OAKG;IACH,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9D;;;OAGG;IACH,aAAa,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACtF,QAAQ,CAAC,OAAO,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IACtF,OAAO,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACnF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,yGAAyG;AACzG,qBAAa,SAAU,SAAQ,KAAK;IAElC,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKhB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the computer-use host needs to know about a desktop's windows and
|
|
3
|
+
* their contents, written without any one platform's terms so a macOS or a
|
|
4
|
+
* Linux backend only adds a file that implements {@link AccessibilityBackend}.
|
|
5
|
+
*
|
|
6
|
+
* - A window is named by an opaque `windowId` string; the backend defines its
|
|
7
|
+
* format and accepts the ones it handed out.
|
|
8
|
+
* - Rectangles are virtual-desktop physical pixels.
|
|
9
|
+
* - Nothing here is a promise about speed except {@link AccessibilityBackend.listWindows},
|
|
10
|
+
* which a backend serves from the platform's window list without reading
|
|
11
|
+
* any window's contents.
|
|
12
|
+
*/
|
|
13
|
+
/** A failure the backend reports, or the client's own (`timeout`, `helper_exited`, `unavailable`, …). */
|
|
14
|
+
export class A11yError extends Error {
|
|
15
|
+
code;
|
|
16
|
+
constructor(code, message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.name = 'A11yError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/a11y/interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA6MH,yGAAyG;AACzG,MAAM,OAAO,SAAU,SAAQ,KAAK;IAEzB;IADV,YACU,IAAY,EACrB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHL,SAAI,GAAJ,IAAI,CAAQ;QAIrB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;IACxB,CAAC;CACD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type WslProbes } from '../adapters/wsl.js';
|
|
2
|
+
import type { AccessibilityBackend } from './interface.js';
|
|
3
|
+
/** The environment variable that turns the accessibility host off (`off`, `0`, `false`, `no`). */
|
|
4
|
+
export declare const A11Y_ENV = "NAMZU_COMPUTER_USE_A11Y";
|
|
5
|
+
export interface WindowsA11yFactoryOptions {
|
|
6
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
7
|
+
readonly platform?: NodeJS.Platform;
|
|
8
|
+
readonly wslProbes?: WslProbes;
|
|
9
|
+
/** Default true. `false` starts nothing, whatever the environment says. */
|
|
10
|
+
readonly enabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Whether the environment asks for the accessibility host to be off. */
|
|
13
|
+
export declare function a11yDisabledByEnv(env: NodeJS.ProcessEnv): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The accessibility host for this machine's Windows desktop (WSL included),
|
|
16
|
+
* or undefined when it is turned off or there is no Windows PowerShell to run
|
|
17
|
+
* it in. Nothing is started until it is first used or warmed.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createWindowsA11yHost(options?: WindowsA11yFactoryOptions): AccessibilityBackend | undefined;
|
|
20
|
+
//# sourceMappingURL=windows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windows.d.ts","sourceRoot":"","sources":["../../src/a11y/windows.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,SAAS,EAKd,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAK1D,kGAAkG;AAClG,eAAO,MAAM,QAAQ,4BAA4B,CAAA;AAEjD,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAA;IACnC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAA;IAC9B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAGjE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACpC,OAAO,GAAE,yBAA8B,GACrC,oBAAoB,GAAG,SAAS,CAkBlC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isWsl, realWslProbes, wslChildEnv, wslPowerShellPath, } from '../adapters/wsl.js';
|
|
2
|
+
import { WindowsA11yHost } from './a11y.js';
|
|
3
|
+
/** Variable names never handed to a helper process. */
|
|
4
|
+
const SECRET_NAME = /(API_?KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL)/i;
|
|
5
|
+
/** The environment variable that turns the accessibility host off (`off`, `0`, `false`, `no`). */
|
|
6
|
+
export const A11Y_ENV = 'NAMZU_COMPUTER_USE_A11Y';
|
|
7
|
+
/** Whether the environment asks for the accessibility host to be off. */
|
|
8
|
+
export function a11yDisabledByEnv(env) {
|
|
9
|
+
const value = env[A11Y_ENV];
|
|
10
|
+
return value !== undefined && /^(off|0|false|no|none)$/i.test(value.trim());
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The accessibility host for this machine's Windows desktop (WSL included),
|
|
14
|
+
* or undefined when it is turned off or there is no Windows PowerShell to run
|
|
15
|
+
* it in. Nothing is started until it is first used or warmed.
|
|
16
|
+
*/
|
|
17
|
+
export function createWindowsA11yHost(options = {}) {
|
|
18
|
+
const env = options.env ?? process.env;
|
|
19
|
+
if (options.enabled === false || a11yDisabledByEnv(env))
|
|
20
|
+
return undefined;
|
|
21
|
+
const platform = options.platform ?? process.platform;
|
|
22
|
+
const probes = options.wslProbes ?? realWslProbes;
|
|
23
|
+
const wsl = isWsl(env, platform, probes);
|
|
24
|
+
const powershell = wsl
|
|
25
|
+
? wslPowerShellPath(probes)
|
|
26
|
+
: platform === 'win32'
|
|
27
|
+
? 'powershell.exe'
|
|
28
|
+
: undefined;
|
|
29
|
+
if (!powershell)
|
|
30
|
+
return undefined;
|
|
31
|
+
const clean = {};
|
|
32
|
+
for (const [name, value] of Object.entries(env))
|
|
33
|
+
if (!SECRET_NAME.test(name))
|
|
34
|
+
clean[name] = value;
|
|
35
|
+
return new WindowsA11yHost({
|
|
36
|
+
powershell,
|
|
37
|
+
env: wsl ? wslChildEnv(clean, [], probes) : clean,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=windows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windows.js","sourceRoot":"","sources":["../../src/a11y/windows.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,EACL,aAAa,EACb,WAAW,EACX,iBA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C,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;IACjG,OAAO,IAAI,eAAe,CAAC;QAC1B,UAAU;QACV,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;KACjD,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComputerUseAction, ComputerUseCapabilities, ComputerUseResult, DisplayGeometry, FocusWindowResult, UiActResult, UiElementAction, UiSnapshot, UiSnapshotOptions, WindowInfo, WindowInputAction, WindowInputResult, WindowScreenshotResult } from '@namzu/sdk';
|
|
2
|
+
import type { A11yWindow, AccessibilityBackend } from '../../a11y/interface.js';
|
|
2
3
|
import type { ForegroundLadder } from '../../foreground/ladder.js';
|
|
3
4
|
import type { Presence } from '../../presence/presence.js';
|
|
4
5
|
import type { Adapter } from '../types.js';
|
|
@@ -47,6 +48,14 @@ export interface CuaDriverAdapterOptions {
|
|
|
47
48
|
* Absent, nothing is drawn.
|
|
48
49
|
*/
|
|
49
50
|
readonly presence?: Presence;
|
|
51
|
+
/**
|
|
52
|
+
* A resident accessibility host. While it is up, the window list is served
|
|
53
|
+
* from it (a fraction of a millisecond, with no driver call), and a window
|
|
54
|
+
* input is followed by waiting for the window to stop changing instead of
|
|
55
|
+
* a fixed pause. Absent, or on any failure of it, the driver answers as it
|
|
56
|
+
* always did.
|
|
57
|
+
*/
|
|
58
|
+
readonly a11y?: AccessibilityBackend;
|
|
50
59
|
/** For tests: the clock the freshness of a read is judged by. */
|
|
51
60
|
readonly now?: () => number;
|
|
52
61
|
/** For tests: how the adapter waits for a window to show an input's effect. */
|
|
@@ -68,6 +77,13 @@ export declare class CuaDriverAdapter implements Adapter {
|
|
|
68
77
|
private readonly windowApps;
|
|
69
78
|
private readonly foreground;
|
|
70
79
|
private readonly presence;
|
|
80
|
+
private readonly a11y;
|
|
81
|
+
private a11yFailures;
|
|
82
|
+
private a11yRetryAt;
|
|
83
|
+
/** Whether the latest window list came from the accessibility host (its bounds are then its own, not the driver's). */
|
|
84
|
+
private listedByHost;
|
|
85
|
+
/** Per window: the change marker taken before the first input since its last capture. */
|
|
86
|
+
private readonly settleMarks;
|
|
71
87
|
/** False once the driver would not switch its own cursor off: Namzu's is then not shown, so there is never a second one. */
|
|
72
88
|
private driverCursorOff;
|
|
73
89
|
/** cua-driver's screenshot resize registry is per PID, so only this capture may drive input. */
|
|
@@ -93,6 +109,29 @@ export declare class CuaDriverAdapter implements Adapter {
|
|
|
93
109
|
getDisplayGeometry(): Promise<DisplayGeometry>;
|
|
94
110
|
execute(action: ComputerUseAction): Promise<ComputerUseResult>;
|
|
95
111
|
listWindows(): Promise<readonly WindowInfo[]>;
|
|
112
|
+
/**
|
|
113
|
+
* The window list from the accessibility host, or undefined when it is not
|
|
114
|
+
* up yet (it is started now and used from the next call), was given up
|
|
115
|
+
* on, or failed this time. A failure is never retried within the call:
|
|
116
|
+
* the driver answers it, and the host is left alone for a while.
|
|
117
|
+
*/
|
|
118
|
+
private windowsFromHost;
|
|
119
|
+
/**
|
|
120
|
+
* Called by the tool instead of its fixed pause after a batch: waits for
|
|
121
|
+
* the window the batch acted in to stop changing, as the window reports it.
|
|
122
|
+
* Undefined when there is nothing to wait on (the host is not up, the
|
|
123
|
+
* batch did not act in a window through this adapter, the host failed):
|
|
124
|
+
* the tool then pauses as it always did.
|
|
125
|
+
*/
|
|
126
|
+
settleAfterInput(request: {
|
|
127
|
+
readonly windowId?: string;
|
|
128
|
+
readonly budgetMs: number;
|
|
129
|
+
}, signal?: AbortSignal): Promise<{
|
|
130
|
+
readonly waitedMs: number;
|
|
131
|
+
readonly changed: boolean;
|
|
132
|
+
} | undefined>;
|
|
133
|
+
/** Takes (and, for a window not watched yet, starts) the change marker an input's settle counts from. Never fails the input. */
|
|
134
|
+
private markForSettle;
|
|
96
135
|
focusWindow(id: string): Promise<FocusWindowResult>;
|
|
97
136
|
captureWindow(id: string): Promise<WindowScreenshotResult>;
|
|
98
137
|
private captureWindowInternal;
|
|
@@ -281,4 +320,12 @@ export declare function parseWindowId(value: unknown): number | undefined;
|
|
|
281
320
|
* foreground window is the front of the non-topmost z-order.
|
|
282
321
|
*/
|
|
283
322
|
export declare function toWindowInfos(raw: unknown): WindowInfo[];
|
|
323
|
+
/**
|
|
324
|
+
* The accessibility host's window list → the host's `WindowInfo`, front to
|
|
325
|
+
* back, with the same drops as {@link toWindowInfos} (untitled windows, the
|
|
326
|
+
* driver's own, the shell's `Program Manager`, windows a pixel wide or tall).
|
|
327
|
+
* `focused` is the window the system reports as the foreground one when it
|
|
328
|
+
* is among those kept, else the front-most one that is not minimized.
|
|
329
|
+
*/
|
|
330
|
+
export declare function windowInfosFromHost(raw: readonly A11yWindow[]): WindowInfo[];
|
|
284
331
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/cua-driver/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGX,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EAEf,iBAAiB,EAGjB,WAAW,EAEX,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/cua-driver/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGX,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EAEf,iBAAiB,EAGjB,WAAW,EAEX,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,YAAY,CAAA;A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U,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,UAAU,GAAG,SAAS,GAC3B,WAAW,CA6Cb;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,CA2B1F;AAYD,mJAAmJ;AACnJ,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,CAe3F;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUhE;AAkBD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,EAAE,CAuCxD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,EAAE,CAwB5E"}
|
|
@@ -39,6 +39,12 @@ const OBSERVE_WAITS_MS = [0, 80, 200, 450];
|
|
|
39
39
|
* moves the check by that much later, not closer to the send.
|
|
40
40
|
*/
|
|
41
41
|
const WINDOW_LIST_FRESH_MS = 1_000;
|
|
42
|
+
/** After the accessibility host failed once, the driver answers alone for this long (ms), doubled for each further failure. */
|
|
43
|
+
const A11Y_BACKOFF_MS = 30_000;
|
|
44
|
+
/** The accessibility host is given up on for the session after this many failures. */
|
|
45
|
+
const A11Y_MAX_FAILURES = 3;
|
|
46
|
+
/** How long (ms) a window must stay quiet after its last change before an action counts as settled. */
|
|
47
|
+
const SETTLE_QUIET_MS = 120;
|
|
42
48
|
/** How many times a burst that a person's input stopped before anything was sent waits for the next pause and goes again. */
|
|
43
49
|
const PAUSE_RETRIES = 3;
|
|
44
50
|
const BROWSER_APP = /chrome|msedge|edge|brave|vivaldi|opera|firefox|chromium/i;
|
|
@@ -220,6 +226,13 @@ export class CuaDriverAdapter {
|
|
|
220
226
|
windowApps = new Map();
|
|
221
227
|
foreground;
|
|
222
228
|
presence;
|
|
229
|
+
a11y;
|
|
230
|
+
a11yFailures = 0;
|
|
231
|
+
a11yRetryAt = 0;
|
|
232
|
+
/** Whether the latest window list came from the accessibility host (its bounds are then its own, not the driver's). */
|
|
233
|
+
listedByHost = false;
|
|
234
|
+
/** Per window: the change marker taken before the first input since its last capture. */
|
|
235
|
+
settleMarks = new Map();
|
|
223
236
|
/** False once the driver would not switch its own cursor off: Namzu's is then not shown, so there is never a second one. */
|
|
224
237
|
driverCursorOff;
|
|
225
238
|
/** cua-driver's screenshot resize registry is per PID, so only this capture may drive input. */
|
|
@@ -243,6 +256,9 @@ export class CuaDriverAdapter {
|
|
|
243
256
|
this.backend = `cua-driver${options.version ? ` ${options.version}` : ''}`;
|
|
244
257
|
this.foreground = options.foreground;
|
|
245
258
|
this.presence = options.presence;
|
|
259
|
+
this.a11y = options.a11y;
|
|
260
|
+
// Compiling the helper takes a moment; start it now so the first window list can already use it.
|
|
261
|
+
options.a11y?.warm();
|
|
246
262
|
this.now = options.now ?? Date.now;
|
|
247
263
|
this.settle = options.settle ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
248
264
|
this.client = new McpStdioClient({
|
|
@@ -386,8 +402,11 @@ export class CuaDriverAdapter {
|
|
|
386
402
|
async listWindows() {
|
|
387
403
|
// The model is about to work in a window: have the overlay ready for its first action.
|
|
388
404
|
this.tryPresence((presence) => presence.warm());
|
|
389
|
-
const
|
|
390
|
-
|
|
405
|
+
const fromHost = await this.windowsFromHost();
|
|
406
|
+
this.listedByHost = fromHost !== undefined;
|
|
407
|
+
const windows = fromHost ??
|
|
408
|
+
toWindowInfos(structured(await this.callTool('list_windows', {}, LIST_TIMEOUT_MS), 'list_windows')
|
|
409
|
+
.windows);
|
|
391
410
|
this.windowPids.clear();
|
|
392
411
|
this.windowApps.clear();
|
|
393
412
|
for (const window of windows) {
|
|
@@ -396,6 +415,74 @@ export class CuaDriverAdapter {
|
|
|
396
415
|
}
|
|
397
416
|
return windows;
|
|
398
417
|
}
|
|
418
|
+
/**
|
|
419
|
+
* The window list from the accessibility host, or undefined when it is not
|
|
420
|
+
* up yet (it is started now and used from the next call), was given up
|
|
421
|
+
* on, or failed this time. A failure is never retried within the call:
|
|
422
|
+
* the driver answers it, and the host is left alone for a while.
|
|
423
|
+
*/
|
|
424
|
+
async windowsFromHost() {
|
|
425
|
+
const a11y = this.a11y;
|
|
426
|
+
if (!a11y || this.a11yFailures >= A11Y_MAX_FAILURES)
|
|
427
|
+
return undefined;
|
|
428
|
+
if (!a11y.isReady) {
|
|
429
|
+
a11y.warm();
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
if (this.now() < this.a11yRetryAt)
|
|
433
|
+
return undefined;
|
|
434
|
+
try {
|
|
435
|
+
const windows = windowInfosFromHost(await a11y.listWindows({ includeOwned: true }, currentCallSignal()));
|
|
436
|
+
this.a11yFailures = 0;
|
|
437
|
+
return windows;
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
this.a11yFailures++;
|
|
441
|
+
this.a11yRetryAt = this.now() + A11Y_BACKOFF_MS * 2 ** (this.a11yFailures - 1);
|
|
442
|
+
return undefined;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Called by the tool instead of its fixed pause after a batch: waits for
|
|
447
|
+
* the window the batch acted in to stop changing, as the window reports it.
|
|
448
|
+
* Undefined when there is nothing to wait on (the host is not up, the
|
|
449
|
+
* batch did not act in a window through this adapter, the host failed):
|
|
450
|
+
* the tool then pauses as it always did.
|
|
451
|
+
*/
|
|
452
|
+
async settleAfterInput(request, signal) {
|
|
453
|
+
const a11y = this.a11y;
|
|
454
|
+
if (!a11y || !a11y.isReady || request.windowId === undefined)
|
|
455
|
+
return undefined;
|
|
456
|
+
const hwnd = parseWindowId(request.windowId);
|
|
457
|
+
const since = hwnd === undefined ? undefined : this.settleMarks.get(hwnd);
|
|
458
|
+
if (hwnd === undefined || since === undefined)
|
|
459
|
+
return undefined;
|
|
460
|
+
this.settleMarks.delete(hwnd);
|
|
461
|
+
try {
|
|
462
|
+
const waited = await a11y.waitForChange({
|
|
463
|
+
windowId: windowIdOf(hwnd),
|
|
464
|
+
since,
|
|
465
|
+
quietMs: Math.min(SETTLE_QUIET_MS, request.budgetMs),
|
|
466
|
+
timeoutMs: request.budgetMs,
|
|
467
|
+
}, signal);
|
|
468
|
+
return { waitedMs: waited.settledMs, changed: waited.changed };
|
|
469
|
+
}
|
|
470
|
+
catch {
|
|
471
|
+
return undefined;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/** Takes (and, for a window not watched yet, starts) the change marker an input's settle counts from. Never fails the input. */
|
|
475
|
+
async markForSettle(hwnd) {
|
|
476
|
+
const a11y = this.a11y;
|
|
477
|
+
if (!a11y?.isReady || this.settleMarks.has(hwnd))
|
|
478
|
+
return;
|
|
479
|
+
try {
|
|
480
|
+
this.settleMarks.set(hwnd, await a11y.seq(windowIdOf(hwnd)));
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
this.settleMarks.delete(hwnd);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
399
486
|
async focusWindow(id) {
|
|
400
487
|
const hwnd = parseWindowId(id);
|
|
401
488
|
if (hwnd === undefined)
|
|
@@ -423,6 +510,17 @@ export class CuaDriverAdapter {
|
|
|
423
510
|
// A failed or overlapping capture invalidates the old resize ratio even
|
|
424
511
|
// if the driver returned no image. Never let it address a later action.
|
|
425
512
|
this.windowFrame = undefined;
|
|
513
|
+
// What an earlier input changed was seen by the screenshot being taken now; and the window
|
|
514
|
+
// starts being watched while it is captured, so the first input after it loses no event.
|
|
515
|
+
this.settleMarks.delete(target.hwnd);
|
|
516
|
+
const armed = this.a11y?.isReady
|
|
517
|
+
? this.a11y.seq(windowIdOf(target.hwnd)).catch(() => undefined)
|
|
518
|
+
: undefined;
|
|
519
|
+
// The window where the host says it is before the capture: the host's rectangle is its own,
|
|
520
|
+
// so "did not move during the capture" is judged against it, not against the driver's.
|
|
521
|
+
const hostBefore = this.listedByHost
|
|
522
|
+
? (await this.windowsFromHost())?.find((window) => window.id === windowIdOf(target.hwnd))
|
|
523
|
+
: undefined;
|
|
426
524
|
let captureStarts = 0;
|
|
427
525
|
let captureGeneration = this.sessionGeneration;
|
|
428
526
|
const result = await this.callTool('get_window_state', {
|
|
@@ -455,11 +553,12 @@ export class CuaDriverAdapter {
|
|
|
455
553
|
this.client.starts !== captureStarts ||
|
|
456
554
|
this.sessionGeneration !== captureGeneration)
|
|
457
555
|
throw new Error('cua-driver: the driver session changed after the window capture; take a new screenshot.');
|
|
556
|
+
await armed;
|
|
458
557
|
const listed = windows.find((window) => window.id === windowIdOf(target.hwnd));
|
|
459
558
|
if (!listed ||
|
|
460
559
|
listed.pid !== target.pid ||
|
|
461
560
|
listed.minimized ||
|
|
462
|
-
!sameBounds(listed.bounds, bounds))
|
|
561
|
+
!sameBounds(listed.bounds, this.listedByHost && hostBefore ? hostBefore.bounds : bounds))
|
|
463
562
|
throw new Error(`cua-driver: window ${id} moved, closed or was minimized during capture; take a new screenshot.`);
|
|
464
563
|
const frame = {
|
|
465
564
|
id: randomUUID(),
|
|
@@ -778,6 +877,7 @@ export class CuaDriverAdapter {
|
|
|
778
877
|
this.client.starts !== frame.processStarts)
|
|
779
878
|
throw new Error('computer-use: the captured window changed or its driver restarted; take a new window screenshot.');
|
|
780
879
|
this.showPresence(frame, current.bounds, name, args);
|
|
880
|
+
await this.markForSettle(target.window_id);
|
|
781
881
|
return this.callTool(name, { ...target, ...args }, undefined, undefined, undefined, frame);
|
|
782
882
|
};
|
|
783
883
|
// The driver's hotkey finds a shortcut only through an accelerator the window names, and refuses (sending
|
|
@@ -2138,6 +2238,41 @@ export function toWindowInfos(raw) {
|
|
|
2138
2238
|
const front = ordered.find((entry) => !entry.info.minimized && Number.isFinite(entry.z));
|
|
2139
2239
|
return ordered.map((entry) => ({ ...entry.info, focused: entry === front }));
|
|
2140
2240
|
}
|
|
2241
|
+
/**
|
|
2242
|
+
* The accessibility host's window list → the host's `WindowInfo`, front to
|
|
2243
|
+
* back, with the same drops as {@link toWindowInfos} (untitled windows, the
|
|
2244
|
+
* driver's own, the shell's `Program Manager`, windows a pixel wide or tall).
|
|
2245
|
+
* `focused` is the window the system reports as the foreground one when it
|
|
2246
|
+
* is among those kept, else the front-most one that is not minimized.
|
|
2247
|
+
*/
|
|
2248
|
+
export function windowInfosFromHost(raw) {
|
|
2249
|
+
const kept = [];
|
|
2250
|
+
for (const entry of raw) {
|
|
2251
|
+
const hwnd = parseWindowId(entry.windowId);
|
|
2252
|
+
if (hwnd === undefined || entry.title.trim().length === 0)
|
|
2253
|
+
continue;
|
|
2254
|
+
const app = entry.processName.toLowerCase();
|
|
2255
|
+
if (app === 'cua-driver.exe')
|
|
2256
|
+
continue;
|
|
2257
|
+
if (app === 'explorer.exe' && entry.title === 'Program Manager')
|
|
2258
|
+
continue;
|
|
2259
|
+
if (entry.bounds.width <= 1 || entry.bounds.height <= 1)
|
|
2260
|
+
continue;
|
|
2261
|
+
kept.push(entry);
|
|
2262
|
+
}
|
|
2263
|
+
kept.sort((a, b) => a.z - b.z);
|
|
2264
|
+
const front = kept.find((entry) => entry.focused && !entry.minimized) ??
|
|
2265
|
+
kept.find((entry) => !entry.minimized);
|
|
2266
|
+
return kept.map((entry) => ({
|
|
2267
|
+
id: windowIdOf(parseWindowId(entry.windowId)),
|
|
2268
|
+
title: entry.title,
|
|
2269
|
+
app: entry.processName.replace(/\.exe$/i, ''),
|
|
2270
|
+
pid: entry.processId,
|
|
2271
|
+
bounds: { ...entry.bounds },
|
|
2272
|
+
minimized: entry.minimized,
|
|
2273
|
+
focused: entry === front,
|
|
2274
|
+
}));
|
|
2275
|
+
}
|
|
2141
2276
|
function structured(result, tool) {
|
|
2142
2277
|
if (!result.structuredContent)
|
|
2143
2278
|
throw new Error(`cua-driver: ${tool} returned no structured result.`);
|