@everydaydevopsio/pilot 0.6.2 → 0.7.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/AGENTS.md +11 -0
- package/CHANGELOG.md +45 -0
- package/README.md +105 -11
- package/dist/browser/browser-manager.d.ts +7 -1
- package/dist/browser/browser-manager.d.ts.map +1 -1
- package/dist/browser/browser-manager.js +196 -40
- package/dist/browser/browser-manager.js.map +1 -1
- package/dist/browser/chrome-launcher.d.ts +13 -2
- package/dist/browser/chrome-launcher.d.ts.map +1 -1
- package/dist/browser/chrome-launcher.js +33 -4
- package/dist/browser/chrome-launcher.js.map +1 -1
- package/dist/browser/driver/capabilities.d.ts +22 -0
- package/dist/browser/driver/capabilities.d.ts.map +1 -0
- package/dist/browser/driver/capabilities.js +70 -0
- package/dist/browser/driver/capabilities.js.map +1 -0
- package/dist/browser/driver/cdp-driver.d.ts +77 -0
- package/dist/browser/driver/cdp-driver.d.ts.map +1 -0
- package/dist/browser/driver/cdp-driver.js +190 -0
- package/dist/browser/driver/cdp-driver.js.map +1 -0
- package/dist/browser/driver/factory.d.ts +10 -0
- package/dist/browser/driver/factory.d.ts.map +1 -0
- package/dist/browser/driver/factory.js +23 -0
- package/dist/browser/driver/factory.js.map +1 -0
- package/dist/browser/driver/index.d.ts +6 -0
- package/dist/browser/driver/index.d.ts.map +1 -0
- package/dist/browser/driver/index.js +5 -0
- package/dist/browser/driver/index.js.map +1 -0
- package/dist/browser/driver/types.d.ts +106 -0
- package/dist/browser/driver/types.d.ts.map +1 -0
- package/dist/browser/driver/types.js +25 -0
- package/dist/browser/driver/types.js.map +1 -0
- package/dist/browser/sessions.d.ts +49 -0
- package/dist/browser/sessions.d.ts.map +1 -0
- package/dist/browser/sessions.js +249 -0
- package/dist/browser/sessions.js.map +1 -0
- package/dist/browser/types.d.ts +13 -0
- package/dist/browser/types.d.ts.map +1 -1
- package/dist/cli/skill-template.d.ts +1 -1
- package/dist/cli/skill-template.d.ts.map +1 -1
- package/dist/cli/skill-template.js +1 -1
- package/dist/cli/skill-template.js.map +1 -1
- package/dist/commands/connect.d.ts +2 -2
- package/dist/commands/connect.d.ts.map +1 -1
- package/dist/commands/connect.js +2 -2
- package/dist/commands/connect.js.map +1 -1
- package/dist/mcp/server.d.ts +9 -15
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +32 -74
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/browser.d.ts +2 -3
- package/dist/mcp/tools/browser.d.ts.map +1 -1
- package/dist/mcp/tools/browser.js +85 -70
- package/dist/mcp/tools/browser.js.map +1 -1
- package/dist/mcp/tools/connect.d.ts +2 -3
- package/dist/mcp/tools/connect.d.ts.map +1 -1
- package/dist/mcp/tools/connect.js +9 -9
- package/dist/mcp/tools/connect.js.map +1 -1
- package/dist/mcp/tools/driver-context.d.ts +14 -0
- package/dist/mcp/tools/driver-context.d.ts.map +1 -0
- package/dist/mcp/tools/driver-context.js +43 -0
- package/dist/mcp/tools/driver-context.js.map +1 -0
- package/dist/mcp/tools/files.d.ts.map +1 -1
- package/dist/mcp/tools/files.js +5 -15
- package/dist/mcp/tools/files.js.map +1 -1
- package/dist/mcp/tools/interaction.d.ts.map +1 -1
- package/dist/mcp/tools/interaction.js +7 -26
- package/dist/mcp/tools/interaction.js.map +1 -1
- package/dist/mcp/tools/names.d.ts +1 -1
- package/dist/mcp/tools/names.d.ts.map +1 -1
- package/dist/mcp/tools/names.js +2 -0
- package/dist/mcp/tools/names.js.map +1 -1
- package/dist/mcp/tools/network.d.ts.map +1 -1
- package/dist/mcp/tools/network.js +3 -11
- package/dist/mcp/tools/network.js.map +1 -1
- package/dist/mcp/tools/performance.d.ts.map +1 -1
- package/dist/mcp/tools/performance.js +2 -12
- package/dist/mcp/tools/performance.js.map +1 -1
- package/dist/mcp/tools/snapshot.d.ts.map +1 -1
- package/dist/mcp/tools/snapshot.js +3 -14
- package/dist/mcp/tools/snapshot.js.map +1 -1
- package/dist/mcp/tools/styles.d.ts.map +1 -1
- package/dist/mcp/tools/styles.js +2 -11
- package/dist/mcp/tools/styles.js.map +1 -1
- package/package.json +1 -1
- package/skills/pilot/SKILL.md +9 -0
- package/src/browser/browser-manager.ts +248 -41
- package/src/browser/chrome-launcher.ts +40 -4
- package/src/browser/driver/capabilities.ts +88 -0
- package/src/browser/driver/cdp-driver.ts +260 -0
- package/src/browser/driver/factory.ts +33 -0
- package/src/browser/driver/index.ts +22 -0
- package/src/browser/driver/types.ts +156 -0
- package/src/browser/sessions.ts +299 -0
- package/src/browser/types.ts +14 -0
- package/src/cli/skill-template.ts +1 -1
- package/src/commands/connect.ts +3 -3
- package/src/mcp/server.ts +48 -91
- package/src/mcp/tools/browser.ts +105 -87
- package/src/mcp/tools/connect.ts +10 -11
- package/src/mcp/tools/driver-context.ts +56 -0
- package/src/mcp/tools/files.ts +5 -16
- package/src/mcp/tools/interaction.ts +7 -27
- package/src/mcp/tools/names.ts +2 -0
- package/src/mcp/tools/network.ts +2 -12
- package/src/mcp/tools/performance.ts +2 -13
- package/src/mcp/tools/snapshot.ts +3 -15
- package/src/mcp/tools/styles.ts +2 -12
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import type { Client } from 'chrome-remote-interface';
|
|
2
|
+
import { BrowserManager } from '../browser-manager.js';
|
|
3
|
+
import type { LaunchOptions, SessionInfo, TabInfo } from '../types.js';
|
|
4
|
+
import { resetCssState } from '../inspect/styles.js';
|
|
5
|
+
import { attachDialogHandler } from '../interaction/dialogs.js';
|
|
6
|
+
import {
|
|
7
|
+
attachDownloadHandler,
|
|
8
|
+
enableDownloads
|
|
9
|
+
} from '../interaction/downloads.js';
|
|
10
|
+
import { attachNetworkMonitor } from '../network/network-monitor.js';
|
|
11
|
+
import type { ConsoleMessage } from '../../mcp/console-buffer.js';
|
|
12
|
+
import type { Config } from '../../util/config.js';
|
|
13
|
+
import { applyViewport, type ViewportConfig } from '../../viewport.js';
|
|
14
|
+
import { executeCheck, type CheckParams } from '../../commands/check.js';
|
|
15
|
+
import { executeClick, type ClickParams } from '../../commands/click.js';
|
|
16
|
+
import { executeDialog, type DialogParams } from '../../commands/dialog.js';
|
|
17
|
+
import {
|
|
18
|
+
executeEvaluate,
|
|
19
|
+
type EvaluateParams
|
|
20
|
+
} from '../../commands/evaluate.js';
|
|
21
|
+
import { executeFill, type FillParams } from '../../commands/fill.js';
|
|
22
|
+
import { executeFind, type FindQuery } from '../../commands/find.js';
|
|
23
|
+
import { executeHover, type HoverParams } from '../../commands/hover.js';
|
|
24
|
+
import {
|
|
25
|
+
executeNavigate,
|
|
26
|
+
type NavigateParams
|
|
27
|
+
} from '../../commands/navigate.js';
|
|
28
|
+
import { executeNetwork, type NetworkParams } from '../../commands/network.js';
|
|
29
|
+
import { executePageInfo } from '../../commands/page_info.js';
|
|
30
|
+
import {
|
|
31
|
+
executePerformance,
|
|
32
|
+
type PerformanceParams
|
|
33
|
+
} from '../../commands/performance.js';
|
|
34
|
+
import {
|
|
35
|
+
executePressKey,
|
|
36
|
+
type PressKeyParams
|
|
37
|
+
} from '../../commands/press_key.js';
|
|
38
|
+
import {
|
|
39
|
+
executeScreenshot,
|
|
40
|
+
type ScreenshotParams
|
|
41
|
+
} from '../../commands/screenshot.js';
|
|
42
|
+
import { executeScroll, type ScrollParams } from '../../commands/scroll.js';
|
|
43
|
+
import { executeSelect, type SelectParams } from '../../commands/select.js';
|
|
44
|
+
import { executeSnapshot } from '../../commands/snapshot.js';
|
|
45
|
+
import { executeStyles, type StylesParams } from '../../commands/styles.js';
|
|
46
|
+
import {
|
|
47
|
+
executeCloseTab,
|
|
48
|
+
executeListTabs,
|
|
49
|
+
executeNewTab,
|
|
50
|
+
executeSwitchTab,
|
|
51
|
+
type NewTabResult
|
|
52
|
+
} from '../../commands/tabs.js';
|
|
53
|
+
import { executeType, type TypeParams } from '../../commands/type.js';
|
|
54
|
+
import { executeUpload, type UploadParams } from '../../commands/upload.js';
|
|
55
|
+
import { executeWait, type WaitParams } from '../../commands/wait.js';
|
|
56
|
+
import {
|
|
57
|
+
CAPABILITIES,
|
|
58
|
+
type BrowserDriver,
|
|
59
|
+
type Capability,
|
|
60
|
+
type ConnectExistingOptions,
|
|
61
|
+
type DriverSession,
|
|
62
|
+
type ViewportResizeParams
|
|
63
|
+
} from './types.js';
|
|
64
|
+
|
|
65
|
+
const CDP_CAPABILITIES: ReadonlySet<Capability> = new Set(CAPABILITIES);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Chrome driver over the Chrome DevTools Protocol. BrowserManager owns the
|
|
69
|
+
* Chrome process and CDP connection; this class wires CDP events into the
|
|
70
|
+
* session buffers and maps driver calls onto the CDP command implementations.
|
|
71
|
+
*/
|
|
72
|
+
export class CdpDriver implements BrowserDriver {
|
|
73
|
+
readonly kind = 'chrome' as const;
|
|
74
|
+
readonly capabilities = CDP_CAPABILITIES;
|
|
75
|
+
private monitoredClient: Client | null = null;
|
|
76
|
+
|
|
77
|
+
constructor(
|
|
78
|
+
private readonly session: DriverSession,
|
|
79
|
+
private readonly manager: BrowserManager
|
|
80
|
+
) {
|
|
81
|
+
manager.setEventCallback((event, data) => this.onBrowserEvent(event, data));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static create(config: Config, session: DriverSession): CdpDriver {
|
|
85
|
+
return new CdpDriver(session, new BrowserManager(config));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private onBrowserEvent(event: string, data: unknown): void {
|
|
89
|
+
if (event === 'console_message') {
|
|
90
|
+
this.session.consoleBuffer.push(data as ConsoleMessage);
|
|
91
|
+
}
|
|
92
|
+
if (event === 'page_navigated') {
|
|
93
|
+
this.session.elementRefMap.invalidate();
|
|
94
|
+
}
|
|
95
|
+
if (event === 'browser_disconnected') {
|
|
96
|
+
this.monitoredClient = null;
|
|
97
|
+
resetCssState();
|
|
98
|
+
this.session.dialogQueue.clear();
|
|
99
|
+
this.session.downloadTracker.clear();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// Covers browser_connected and tab switches, which swap the CDP client
|
|
103
|
+
// without emitting a connect event.
|
|
104
|
+
this.ensureMonitors();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private ensureMonitors(): void {
|
|
108
|
+
const client = this.manager.getClient();
|
|
109
|
+
if (!client || client === this.monitoredClient) return;
|
|
110
|
+
attachNetworkMonitor(client, this.session.networkBuffer);
|
|
111
|
+
attachDialogHandler(client, this.session.dialogQueue);
|
|
112
|
+
attachDownloadHandler(client, this.session.downloadTracker);
|
|
113
|
+
void enableDownloads(client).catch(() => {
|
|
114
|
+
// Download behavior setup may fail in some environments
|
|
115
|
+
});
|
|
116
|
+
this.monitoredClient = client;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private client(): Client {
|
|
120
|
+
const client = this.manager.getClient();
|
|
121
|
+
if (!client) {
|
|
122
|
+
throw new Error('Browser not started. Call browser_start first.');
|
|
123
|
+
}
|
|
124
|
+
return client;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
launch(opts?: LaunchOptions) {
|
|
128
|
+
return this.manager.launch(opts);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
connectExisting(opts: ConnectExistingOptions): Promise<{ tabs: TabInfo[] }> {
|
|
132
|
+
return this.manager.connectExisting(opts);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
destroy(): Promise<void> {
|
|
136
|
+
return this.manager.destroy();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
isConnected(): boolean {
|
|
140
|
+
return this.manager.isConnected();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getSessionInfo(): SessionInfo {
|
|
144
|
+
return { browser: this.kind, ...this.manager.getSessionInfo() };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
listTabs(): Promise<TabInfo[]> {
|
|
148
|
+
return executeListTabs(this.manager);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
newTab(url?: string): Promise<NewTabResult> {
|
|
152
|
+
return executeNewTab(this.manager, url);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
closeTab(targetId: string): Promise<void> {
|
|
156
|
+
return executeCloseTab(this.manager, targetId);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
switchTab(targetId: string): Promise<void> {
|
|
160
|
+
return executeSwitchTab(this.manager, targetId);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
navigate(params: NavigateParams) {
|
|
164
|
+
return executeNavigate(this.client(), this.manager, params);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
pageInfo() {
|
|
168
|
+
return executePageInfo(this.client());
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
evaluate(params: EvaluateParams) {
|
|
172
|
+
return executeEvaluate(this.client(), params);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
wait(params: WaitParams) {
|
|
176
|
+
return executeWait(this.client(), this.manager, params);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
screenshot(params: ScreenshotParams) {
|
|
180
|
+
return executeScreenshot(this.client(), params);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async resizeViewport(params: ViewportResizeParams): Promise<ViewportConfig> {
|
|
184
|
+
const client = this.client();
|
|
185
|
+
const current = this.manager.getViewportConfig();
|
|
186
|
+
const mobile = params.mobile ?? current?.mobile ?? false;
|
|
187
|
+
const config: ViewportConfig = {
|
|
188
|
+
width: params.width,
|
|
189
|
+
height: params.height,
|
|
190
|
+
deviceScaleFactor:
|
|
191
|
+
params.deviceScaleFactor ?? current?.deviceScaleFactor ?? 1,
|
|
192
|
+
mobile,
|
|
193
|
+
responsive: false,
|
|
194
|
+
...(mobile && current?.userAgent && { userAgent: current.userAgent })
|
|
195
|
+
};
|
|
196
|
+
await applyViewport(client, config);
|
|
197
|
+
this.manager.setViewportConfig(config);
|
|
198
|
+
return config;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
snapshot() {
|
|
202
|
+
return executeSnapshot(this.client(), this.session.elementRefMap);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
find(query: FindQuery) {
|
|
206
|
+
return executeFind(this.client(), this.session.elementRefMap, query);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
styles(params: StylesParams) {
|
|
210
|
+
return executeStyles(this.client(), this.session.elementRefMap, params);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
click(params: ClickParams) {
|
|
214
|
+
return executeClick(this.client(), params, this.session.elementRefMap);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
type(params: TypeParams) {
|
|
218
|
+
return executeType(this.client(), params, this.session.elementRefMap);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
fill(params: FillParams) {
|
|
222
|
+
return executeFill(this.client(), this.session.elementRefMap, params);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
hover(params: HoverParams) {
|
|
226
|
+
return executeHover(this.client(), this.session.elementRefMap, params);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
pressKey(params: PressKeyParams) {
|
|
230
|
+
return executePressKey(this.client(), params);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
select(params: SelectParams) {
|
|
234
|
+
return executeSelect(this.client(), this.session.elementRefMap, params);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
check(params: CheckParams) {
|
|
238
|
+
return executeCheck(this.client(), this.session.elementRefMap, params);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
scroll(params: ScrollParams) {
|
|
242
|
+
return executeScroll(this.client(), this.session.elementRefMap, params);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
dialog(params: DialogParams) {
|
|
246
|
+
return executeDialog(this.client(), this.session.dialogQueue, params);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
upload(params: UploadParams) {
|
|
250
|
+
return executeUpload(this.client(), this.session.elementRefMap, params);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
network(params: NetworkParams) {
|
|
254
|
+
return executeNetwork(this.client(), this.session.networkBuffer, params);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
performance(params: PerformanceParams) {
|
|
258
|
+
return executePerformance(this.client(), this.session.traceState, params);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Config } from '../../util/config.js';
|
|
2
|
+
import { CdpDriver } from './cdp-driver.js';
|
|
3
|
+
import type { BrowserDriver, BrowserKind, DriverSession } from './types.js';
|
|
4
|
+
|
|
5
|
+
/** Tracking issues for browsers that do not have a driver yet. */
|
|
6
|
+
export const PLANNED_DRIVERS: Readonly<
|
|
7
|
+
Record<Exclude<BrowserKind, 'chrome'>, string>
|
|
8
|
+
> = {
|
|
9
|
+
firefox: 'https://github.com/everydaydevopsio/pilot/issues/58',
|
|
10
|
+
safari: 'https://github.com/everydaydevopsio/pilot/issues/60',
|
|
11
|
+
webkit: 'https://github.com/everydaydevopsio/pilot/issues/61'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export class UnsupportedBrowserError extends Error {
|
|
15
|
+
constructor(readonly browser: Exclude<BrowserKind, 'chrome'>) {
|
|
16
|
+
super(
|
|
17
|
+
`Pilot does not support ${browser} yet; only chrome is available. ` +
|
|
18
|
+
`Progress is tracked in ${PLANNED_DRIVERS[browser]}.`
|
|
19
|
+
);
|
|
20
|
+
this.name = 'UnsupportedBrowserError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createDriver(
|
|
25
|
+
kind: BrowserKind,
|
|
26
|
+
config: Config,
|
|
27
|
+
session: DriverSession
|
|
28
|
+
): BrowserDriver {
|
|
29
|
+
if (kind === 'chrome') {
|
|
30
|
+
return CdpDriver.create(config, session);
|
|
31
|
+
}
|
|
32
|
+
throw new UnsupportedBrowserError(kind);
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { CdpDriver } from './cdp-driver.js';
|
|
2
|
+
export {
|
|
3
|
+
TOOL_CAPABILITIES,
|
|
4
|
+
CapabilityError,
|
|
5
|
+
assertToolSupported,
|
|
6
|
+
missingCapabilities,
|
|
7
|
+
unsupportedTools
|
|
8
|
+
} from './capabilities.js';
|
|
9
|
+
export {
|
|
10
|
+
createDriver,
|
|
11
|
+
PLANNED_DRIVERS,
|
|
12
|
+
UnsupportedBrowserError
|
|
13
|
+
} from './factory.js';
|
|
14
|
+
export { BROWSER_KINDS, CAPABILITIES } from './types.js';
|
|
15
|
+
export type {
|
|
16
|
+
BrowserDriver,
|
|
17
|
+
BrowserKind,
|
|
18
|
+
Capability,
|
|
19
|
+
ConnectExistingOptions,
|
|
20
|
+
DriverSession,
|
|
21
|
+
ViewportResizeParams
|
|
22
|
+
} from './types.js';
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { ConsoleBuffer } from '../../mcp/console-buffer.js';
|
|
2
|
+
import type { ElementRefMap } from '../inspect/element-ref.js';
|
|
3
|
+
import type { DialogQueue } from '../interaction/dialogs.js';
|
|
4
|
+
import type { DownloadTracker } from '../interaction/downloads.js';
|
|
5
|
+
import type { NetworkBuffer } from '../network/network-buffer.js';
|
|
6
|
+
import type { TraceState } from '../performance/trace.js';
|
|
7
|
+
import type { LaunchOptions, SessionInfo, TabInfo } from '../types.js';
|
|
8
|
+
import type { ViewportConfig } from '../../viewport.js';
|
|
9
|
+
import type { CheckParams, CheckResult } from '../../commands/check.js';
|
|
10
|
+
import type { ClickParams, ClickResult } from '../../commands/click.js';
|
|
11
|
+
import type { DialogParams, DialogResult } from '../../commands/dialog.js';
|
|
12
|
+
import type {
|
|
13
|
+
EvaluateParams,
|
|
14
|
+
EvaluateResult
|
|
15
|
+
} from '../../commands/evaluate.js';
|
|
16
|
+
import type { FillParams, FillResult } from '../../commands/fill.js';
|
|
17
|
+
import type { FindCommandResult, FindQuery } from '../../commands/find.js';
|
|
18
|
+
import type { HoverParams, HoverResult } from '../../commands/hover.js';
|
|
19
|
+
import type {
|
|
20
|
+
NavigateParams,
|
|
21
|
+
NavigateResult
|
|
22
|
+
} from '../../commands/navigate.js';
|
|
23
|
+
import type { NetworkParams, NetworkResult } from '../../commands/network.js';
|
|
24
|
+
import type { PageInfoResult } from '../../commands/page_info.js';
|
|
25
|
+
import type {
|
|
26
|
+
PerformanceParams,
|
|
27
|
+
PerformanceResult
|
|
28
|
+
} from '../../commands/performance.js';
|
|
29
|
+
import type {
|
|
30
|
+
PressKeyParams,
|
|
31
|
+
PressKeyResult
|
|
32
|
+
} from '../../commands/press_key.js';
|
|
33
|
+
import type {
|
|
34
|
+
ScreenshotParams,
|
|
35
|
+
ScreenshotResult
|
|
36
|
+
} from '../../commands/screenshot.js';
|
|
37
|
+
import type { ScrollParams, ScrollResult } from '../../commands/scroll.js';
|
|
38
|
+
import type { SelectParams, SelectResult } from '../../commands/select.js';
|
|
39
|
+
import type { SnapshotCommandResult } from '../../commands/snapshot.js';
|
|
40
|
+
import type {
|
|
41
|
+
StylesCommandResult,
|
|
42
|
+
StylesParams
|
|
43
|
+
} from '../../commands/styles.js';
|
|
44
|
+
import type { NewTabResult } from '../../commands/tabs.js';
|
|
45
|
+
import type { TypeParams, TypeResult } from '../../commands/type.js';
|
|
46
|
+
import type { UploadParams, UploadResult } from '../../commands/upload.js';
|
|
47
|
+
import type { WaitParams, WaitResult } from '../../commands/wait.js';
|
|
48
|
+
|
|
49
|
+
/** Browsers Pilot knows about. Only `chrome` has a driver today. */
|
|
50
|
+
export const BROWSER_KINDS = ['chrome', 'firefox', 'safari', 'webkit'] as const;
|
|
51
|
+
export type BrowserKind = (typeof BROWSER_KINDS)[number];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Features a driver may or may not provide. Each MCP tool declares the
|
|
55
|
+
* capabilities it needs (see capabilities.ts); a tool whose capabilities the
|
|
56
|
+
* active driver lacks fails with a CapabilityError before touching the browser.
|
|
57
|
+
*/
|
|
58
|
+
export const CAPABILITIES = [
|
|
59
|
+
'tabs',
|
|
60
|
+
'navigation',
|
|
61
|
+
'evaluate',
|
|
62
|
+
'input',
|
|
63
|
+
'screenshot',
|
|
64
|
+
'viewport',
|
|
65
|
+
'accessibilitySnapshot',
|
|
66
|
+
'styles',
|
|
67
|
+
'console',
|
|
68
|
+
'network',
|
|
69
|
+
'dialogs',
|
|
70
|
+
'uploads',
|
|
71
|
+
'downloads',
|
|
72
|
+
'performanceTrace',
|
|
73
|
+
'connectExisting'
|
|
74
|
+
] as const;
|
|
75
|
+
export type Capability = (typeof CAPABILITIES)[number];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Per-session buffers shared between a driver and the MCP tools. The driver
|
|
79
|
+
* fills them from browser events; tools such as browser_console read them
|
|
80
|
+
* directly.
|
|
81
|
+
*/
|
|
82
|
+
export interface DriverSession {
|
|
83
|
+
consoleBuffer: ConsoleBuffer;
|
|
84
|
+
elementRefMap: ElementRefMap;
|
|
85
|
+
networkBuffer: NetworkBuffer;
|
|
86
|
+
dialogQueue: DialogQueue;
|
|
87
|
+
downloadTracker: DownloadTracker;
|
|
88
|
+
traceState: TraceState;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ConnectExistingOptions {
|
|
92
|
+
host?: string;
|
|
93
|
+
port?: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ViewportResizeParams {
|
|
97
|
+
width: number;
|
|
98
|
+
height: number;
|
|
99
|
+
deviceScaleFactor?: number;
|
|
100
|
+
mobile?: boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Browser-agnostic surface the MCP tools call. Each implementation owns its
|
|
105
|
+
* protocol (CDP, WebDriver BiDi, ...) and must not leak protocol types here.
|
|
106
|
+
*/
|
|
107
|
+
export interface BrowserDriver {
|
|
108
|
+
readonly kind: BrowserKind;
|
|
109
|
+
readonly capabilities: ReadonlySet<Capability>;
|
|
110
|
+
|
|
111
|
+
// Lifecycle
|
|
112
|
+
launch(
|
|
113
|
+
opts?: LaunchOptions
|
|
114
|
+
): Promise<{ headless: boolean; viewport: string }>;
|
|
115
|
+
connectExisting(opts: ConnectExistingOptions): Promise<{ tabs: TabInfo[] }>;
|
|
116
|
+
destroy(): Promise<void>;
|
|
117
|
+
isConnected(): boolean;
|
|
118
|
+
getSessionInfo(): SessionInfo;
|
|
119
|
+
|
|
120
|
+
// Tabs
|
|
121
|
+
listTabs(): Promise<TabInfo[]>;
|
|
122
|
+
newTab(url?: string): Promise<NewTabResult>;
|
|
123
|
+
closeTab(targetId: string): Promise<void>;
|
|
124
|
+
switchTab(targetId: string): Promise<void>;
|
|
125
|
+
|
|
126
|
+
// Page
|
|
127
|
+
navigate(params: NavigateParams): Promise<NavigateResult>;
|
|
128
|
+
pageInfo(): Promise<PageInfoResult>;
|
|
129
|
+
evaluate(params: EvaluateParams): Promise<EvaluateResult>;
|
|
130
|
+
wait(params: WaitParams): Promise<WaitResult>;
|
|
131
|
+
screenshot(params: ScreenshotParams): Promise<ScreenshotResult>;
|
|
132
|
+
resizeViewport(params: ViewportResizeParams): Promise<ViewportConfig>;
|
|
133
|
+
|
|
134
|
+
// Inspection
|
|
135
|
+
snapshot(): Promise<SnapshotCommandResult>;
|
|
136
|
+
find(query: FindQuery): Promise<FindCommandResult>;
|
|
137
|
+
styles(params: StylesParams): Promise<StylesCommandResult>;
|
|
138
|
+
|
|
139
|
+
// Input
|
|
140
|
+
click(params: ClickParams): Promise<ClickResult>;
|
|
141
|
+
type(params: TypeParams): Promise<TypeResult>;
|
|
142
|
+
fill(params: FillParams): Promise<FillResult>;
|
|
143
|
+
hover(params: HoverParams): Promise<HoverResult>;
|
|
144
|
+
pressKey(params: PressKeyParams): Promise<PressKeyResult>;
|
|
145
|
+
select(params: SelectParams): Promise<SelectResult>;
|
|
146
|
+
check(params: CheckParams): Promise<CheckResult>;
|
|
147
|
+
scroll(params: ScrollParams): Promise<ScrollResult>;
|
|
148
|
+
|
|
149
|
+
// Files and dialogs
|
|
150
|
+
dialog(params: DialogParams): Promise<DialogResult>;
|
|
151
|
+
upload(params: UploadParams): Promise<UploadResult>;
|
|
152
|
+
|
|
153
|
+
// Diagnostics
|
|
154
|
+
network(params: NetworkParams): Promise<NetworkResult>;
|
|
155
|
+
performance(params: PerformanceParams): Promise<PerformanceResult>;
|
|
156
|
+
}
|