@jackwener/browsermcp 0.0.34 → 0.0.35-embedded.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 +30 -0
- package/README.md +91 -0
- package/dist/docs/errors.md +2 -0
- package/dist/src/api/action-input.d.ts +47 -0
- package/dist/src/api/agent.d.ts +10 -0
- package/dist/src/api/api.d.ts +50 -0
- package/dist/src/api/browser.d.ts +92 -0
- package/dist/src/api/context.d.ts +7 -0
- package/dist/src/api/diff.d.ts +8 -0
- package/dist/src/api/errors.d.ts +12 -0
- package/dist/src/api/network.d.ts +10 -0
- package/dist/src/api/observation.d.ts +4 -0
- package/dist/src/api/streams.d.ts +13 -0
- package/dist/src/api/tab.d.ts +312 -0
- package/dist/src/api/webmcp.d.ts +19 -0
- package/dist/src/backends/backend.d.ts +14 -0
- package/dist/src/backends/browser-helpers.d.ts +17 -0
- package/dist/src/backends/extension-page.d.ts +5 -0
- package/dist/src/backends/managed-page.d.ts +47 -0
- package/dist/src/backends/page-transport.d.ts +10 -0
- package/dist/src/backends/page-types.d.ts +82 -0
- package/dist/src/docs/embedded.d.ts +2 -0
- package/dist/src/docs/embedded.js +39 -0
- package/dist/src/docs/embedded.js.map +1 -0
- package/dist/src/docs/manifest.d.ts +23 -0
- package/dist/src/docs/manifest.js +6 -3
- package/dist/src/docs/manifest.js.map +1 -1
- package/dist/src/docs/surface.d.ts +12 -0
- package/dist/src/electron/backend.d.ts +50 -0
- package/dist/src/electron/backend.js +375 -0
- package/dist/src/electron/backend.js.map +1 -0
- package/dist/src/electron/chrome.d.ts +24 -0
- package/dist/src/electron/chrome.js +133 -0
- package/dist/src/electron/chrome.js.map +1 -0
- package/dist/src/electron/driver.d.ts +43 -0
- package/dist/src/electron/driver.js +241 -0
- package/dist/src/electron/driver.js.map +1 -0
- package/dist/src/electron/event-buffer.d.ts +16 -0
- package/dist/src/electron/event-buffer.js +59 -0
- package/dist/src/electron/event-buffer.js.map +1 -0
- package/dist/src/electron/page.js +834 -0
- package/dist/src/electron/registry.d.ts +104 -0
- package/dist/src/electron/registry.js +316 -0
- package/dist/src/electron/registry.js.map +1 -0
- package/dist/src/electron/streams.d.ts +16 -0
- package/dist/src/electron/streams.js +48 -0
- package/dist/src/electron/streams.js.map +1 -0
- package/dist/src/embedded/index.d.ts +39 -0
- package/dist/src/embedded/index.js +71 -0
- package/dist/src/embedded/index.js.map +1 -0
- package/dist/src/host/bridge.d.ts +50 -0
- package/dist/src/host/doctor.d.ts +34 -0
- package/dist/src/host/extension.d.ts +3 -0
- package/dist/src/host/host.d.ts +3 -0
- package/dist/src/host/ipc.d.ts +14 -0
- package/dist/src/host/jsonc-config.d.ts +1 -0
- package/dist/src/host/launch.d.ts +11 -0
- package/dist/src/host/native-messaging.d.ts +28 -0
- package/dist/src/host/opencode.d.ts +6 -0
- package/dist/src/host/pi.d.ts +6 -0
- package/dist/src/host/registration.d.ts +24 -0
- package/dist/src/host/setup.d.ts +7 -0
- package/dist/src/host/socket.d.ts +25 -0
- package/dist/src/host/state.d.ts +39 -0
- package/dist/src/launcher/stdio.d.ts +3 -0
- package/dist/src/lib/paths.d.ts +1 -0
- package/dist/src/lib/sources.d.ts +5 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/mcp/catalog.d.ts +202 -0
- package/dist/src/mcp/js-session.d.ts +64 -0
- package/dist/src/mcp/server.d.ts +15 -0
- package/dist/src/protocol.d.ts +319 -0
- package/dist/src/recon/analyzer.d.ts +43 -0
- package/dist/src/recon/discover.d.ts +48 -0
- package/dist/src/runtime/runtime.d.ts +148 -0
- package/dist/src/shared/api-contract.d.ts +86 -0
- package/dist/src/shared/aria-tree.d.ts +2 -0
- package/dist/src/shared/element-ref.d.ts +4 -0
- package/dist/src/shared/engine.d.ts +50 -0
- package/dist/src/shared/injected-source.d.ts +2 -0
- package/dist/src/shared/page-contract.d.ts +256 -0
- package/dist/src/sites/define.d.ts +28 -0
- package/dist/src/sites/drafts.d.ts +39 -0
- package/dist/src/sites/executor.d.ts +34 -0
- package/dist/src/sites/loader.d.ts +84 -0
- package/dist/src/sites/schema.d.ts +11 -0
- package/dist/src/version.d.ts +2 -0
- package/docs/errors.md +2 -0
- package/package.json +12 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.35-embedded.0 — 2026-10-22
|
|
4
|
+
|
|
5
|
+
Includes stable 0.0.34 strict evaluation and lossless RPC contracts, shared tab discovery with scope/counts/pagination, and invalid-response detection. Fixes debugger cleanup after WebContents destruction. Verified with 31 tests, real Electron MCP flows and the installed npm package inside app.asar. openTabs now returns an envelope; read items.
|
|
6
|
+
|
|
3
7
|
## 0.0.34 — 2026-10-22
|
|
4
8
|
|
|
5
9
|
Enforce strict evaluate options and lossless REPL call transport. Separate user data from internal RPC references. Return explicit tab discovery scope, counts and pagination using shared backend contracts. Reject malformed backend responses. Protocol revision 4 requires updating host and extension together; read openTabs results from items.
|
|
6
10
|
|
|
11
|
+
## 0.0.34-embedded.3 — 2026-10-22
|
|
12
|
+
|
|
13
|
+
Host-owned logical tabs, lazy page registration, active-tab selection, session lifecycle events, and retention controls. Includes session-bound adapters and automatic npm publishing through GitHub Actions OIDC.
|
|
14
|
+
|
|
15
|
+
## 0.0.34-embedded.2 — 2026-10-22
|
|
16
|
+
|
|
17
|
+
- Preserve logical tab identity, session ownership and retention across WebContents replacement.
|
|
18
|
+
- Define host-owned create/load/close callbacks and explicit attach/detach lifecycle operations.
|
|
19
|
+
- Report structured host failures with recoverable tab state; protect cleanup against invalid keep entries.
|
|
20
|
+
- Add handle-based deliverable/handoff retention and safe local remote-method inspection.
|
|
21
|
+
- Verify background duplicate claims, host failure recovery and installed ASAR execution.
|
|
22
|
+
|
|
23
|
+
## 0.0.34-embedded.1 — 2026-10-21
|
|
24
|
+
|
|
25
|
+
- Model host tabs independently of WebContents, with stable logical IDs, explicit active selection, metadata updates and lazy loading.
|
|
26
|
+
- Expose typed host events and snapshots with public MCP session IDs; reserve ownership during loading and roll back or cancel failed/revoked claims.
|
|
27
|
+
- Unify tab state across MCP and Chrome APIs, and default MCP version to the installed package version.
|
|
28
|
+
- Migration: use registerPage handles and reported tabId values; tabId no longer equals webContents.id. Synchronize host selection with setActivePage(scope, handle).
|
|
29
|
+
- Share runtime isolation, storage injection, package version resolution and release infrastructure with main.
|
|
30
|
+
|
|
31
|
+
## 0.0.34-embedded.0 — 2026-10-21
|
|
32
|
+
|
|
33
|
+
- Add the embedded Electron SDK with host-owned storage, profiles and page lifecycle.
|
|
34
|
+
- Support MCP sessions, adapter creation and updates, Chrome API compatibility and CDP in embedded Chromium.
|
|
35
|
+
- Import @jackwener/browsermcp/embedded without CLI setup or a Chrome extension.
|
|
36
|
+
|
|
7
37
|
## 0.0.33 — 2026-10-20
|
|
8
38
|
|
|
9
39
|
- refactor: standardize BrowserMCP runtime names and simplify configuration
|
package/README.md
CHANGED
|
@@ -143,6 +143,97 @@ Site commands execute directly without additional approval prompts. The read/wri
|
|
|
143
143
|
| [Tab lifecycle](docs/tab-lifecycle.md) | Claiming tabs, grouping, and cleanup |
|
|
144
144
|
| [Errors](docs/errors.md) | Error codes and recovery |
|
|
145
145
|
|
|
146
|
+
## Embedded Electron applications
|
|
147
|
+
|
|
148
|
+
Import `@jackwener/browsermcp/embedded` from Electron's main process. This entry does not run setup, register Native Messaging, discover Chrome, read global CLI configuration, or install an extension. The application supplies its writable directory, profile sessions, and page lifecycle callbacks. Adapters can still be created, verified, activated, updated, and removed through `tools`.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { app, BrowserWindow, session } from 'electron';
|
|
152
|
+
import path from 'node:path';
|
|
153
|
+
import { createEmbeddedBrowser } from '@jackwener/browsermcp/embedded';
|
|
154
|
+
|
|
155
|
+
await app.whenReady();
|
|
156
|
+
const windows = new Map<number, BrowserWindow>();
|
|
157
|
+
const profile = ({ profileId }) => session.fromPartition(`persist:${profileId}`);
|
|
158
|
+
const browser = await createEmbeddedBrowser({
|
|
159
|
+
dataDir: path.join(app.getPath('userData'), 'browsermcp'),
|
|
160
|
+
execution: 'trusted-node',
|
|
161
|
+
browser: {
|
|
162
|
+
profile,
|
|
163
|
+
async createPage(scope) {
|
|
164
|
+
const window = new BrowserWindow({
|
|
165
|
+
webPreferences: {
|
|
166
|
+
session: profile(scope), contextIsolation: true,
|
|
167
|
+
sandbox: true, nodeIntegration: false,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
const id = window.webContents.id;
|
|
171
|
+
windows.set(id, window);
|
|
172
|
+
window.once('closed', () => windows.delete(id));
|
|
173
|
+
return { contents: window.webContents, close: async () => { window.destroy(); } };
|
|
174
|
+
},
|
|
175
|
+
async activatePage(contents) { windows.get(contents.id)?.show(); },
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Scope comes from the application, not from agent-provided MCP arguments.
|
|
180
|
+
const connection = browser.createSession({ workspaceId: 'project-a', profileId: 'personal' });
|
|
181
|
+
await connection.server.connect(transport); // Any host-provided MCP SDK transport.
|
|
182
|
+
// On disconnect, cleanup is automatic. Explicit close and application shutdown:
|
|
183
|
+
await connection.close();
|
|
184
|
+
await browser.dispose();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The host owns logical tabs; a tab does not need a `WebContents` until it is claimed. Register restored tabs immediately, and synchronize selection from the host UI:
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
const scope = { workspaceId: 'workspace', profileId: 'personal' };
|
|
191
|
+
const handle = browser.registerPage({
|
|
192
|
+
scope,
|
|
193
|
+
url: restoredTab.url,
|
|
194
|
+
title: restoredTab.title,
|
|
195
|
+
load: async (signal) => {
|
|
196
|
+
// Resolve only once the restored tab has loaded; honor cancellation.
|
|
197
|
+
return hostTabs.ensureLoaded(restoredTab.id, { signal });
|
|
198
|
+
},
|
|
199
|
+
close: async () => { await hostTabs.close(restoredTab.id); },
|
|
200
|
+
});
|
|
201
|
+
browser.setActivePage(scope, handle); // Call on each host selection change.
|
|
202
|
+
browser.updatePage(handle, { url: restoredTab.url, title: restoredTab.title });
|
|
203
|
+
const unsubscribe = browser.subscribe((event) => {
|
|
204
|
+
// event.sessionId matches createSession().id, with no internal prefix.
|
|
205
|
+
// event.page.sessionId is the current owner; undefined after release.
|
|
206
|
+
hostTabs.setAgentOwner(event.page.handle, event.page.sessionId);
|
|
207
|
+
});
|
|
208
|
+
const snapshot = browser.getPages(scope); // Initialize/reconcile host UI.
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`registerPage` takes a descriptor with `scope`, `url`, optional `title` / `contents` / `load(signal)`, and a required `close()` callback. For restored tabs, pass metadata and `load(signal)`; enumeration and matching do not trigger loading. A claim reserves exclusive ownership before loading, validates the resolved Electron profile, and returns only after loading succeeds. Failed loads return an unowned tab to the pool. Loading is cancelled on release, unregister, or session cleanup, and is bounded to 30 seconds. A host must honor the signal to prevent its own late side effects; BrowserMCP never attaches a result after access is revoked. WebContents destruction detaches the execution resource; the logical tab, ownership and retention remain intact. Use `attachPage(handle, contents)` to attach a replacement, or let `load(signal)` restore it on demand. `detachPage(handle)` explicitly detaches a resource. `close()` must close the logical host tab, including dormant tabs and tabs whose WebContents was replaced; bind it to the host tab identity, not an obsolete WebContents. Call `unregisterPage(handle)` when the logical host tab is removed.
|
|
212
|
+
|
|
213
|
+
**Identity contract:** the returned handle and the numeric `tabId` in `getPages()` / agent tab lists belong to BrowserMCP. `tabId` is not `webContents.id`. Use the handle to map to your host tab and use the reported `tabId` for Chrome-shaped calls. Both stay stable across loading and WebContents replacement. `webContentsId` identifies only the current execution resource. This changes the implicit `webContents.id` behavior in `0.0.34-embedded.0` and the original vendored branch.
|
|
214
|
+
|
|
215
|
+
`setActivePage(scope, handle | null)` is authoritative; keyboard focus is never used to infer the selected tab. Each workspace/profile has at most one active tab. `openTabs`, `claimTab({ active: true })`, owned-tab lists and `chrome.tabs.query` read the same registry state. `activatePage(contents)` implements agent-requested activation, after which the registry selection is updated. A zero-match claim reports `tab_not_found`; multiple matches report `ambiguous_tab`.
|
|
216
|
+
|
|
217
|
+
Host `subscribe()` emits typed snapshots for registration, metadata/lifecycle changes, activation, acquisition, release, navigation, closure and unregister. Acquisition is idempotent for the same session. Listener exceptions cannot break ownership transitions. Subscribe before taking `getPages(scope)` when initializing UI, and unsubscribe when disposing it. MCP version defaults to the installed BrowserMCP package version; explicit `version` remains available for bundled hosts.
|
|
218
|
+
|
|
219
|
+
The callbacks can manage `WebContentsView` instead of `BrowserWindow`; layout is entirely application-owned. Use `browser.registerPage({ scope, url, contents, close })` to make an existing user page available for claiming. Register only intended browser content, not application settings or privileged UI. `unregisterPage(handle)` revokes access without closing the page. User pages are released during cleanup; unkept agent pages are closed. Profile IDs must map to the intended Electron `Session`, and the backend checks this identity when registering/creating pages.
|
|
220
|
+
|
|
221
|
+
The current evaluator explicitly requires **trusted Node execution**. REPL and adapter modules can access Node capabilities; neither `vm`, a Worker, nor page registration is a sandbox against malicious host code. The REPL runs in a Worker; adapter modules execute in the runtime process. This main-process entry is for applications that trust the connected agent and loaded adapter code. Browser pages should retain `sandbox: true`, `contextIsolation: true`, and `nodeIntegration: false`.
|
|
222
|
+
|
|
223
|
+
Storage is confined by configuration: generated adapters are in `<dataDir>/adapters`, inactive candidates in `<dataDir>/drafts`, and a small standalone adapter SDK in `<dataDir>/node_modules`. No implicit `~/.browsermcp` or `~/.opencli-mcp` source is loaded. Optional `sources` are explicit; generated adapters override them. Adapter code is shared within the service, while execution uses the caller's authorized profile and pages. No login credentials are copied between profiles.
|
|
224
|
+
|
|
225
|
+
`browser.chrome.call/describe/watch` remain available. Electron implements `tabs.query/get/create/update/remove/reload` and `cookies.getAll/get/set/remove`, plus session-scoped `tabs.onCreated/onUpdated/onRemoved/onActivated` events. Call `describe` for method availability and differences. Only registered, accessible tabs are returned; `windowId` is `-1` because window organization belongs to the host. Unsupported methods/options return `capability_unavailable`. Page-scoped CDP is available through `tab.cdp.send`; browser-wide `Target.*` and `Browser.*` commands are rejected. This is an explicit compatibility surface, not an emulation of every extension API.
|
|
226
|
+
|
|
227
|
+
Package the generated `dist`, `docs`, and `adapter-sdk` resources with the npm package. When using ASAR, unpack `**/js-*.mjs` so the REPL worker and evaluator remain loadable. Keep Electron as an application dependency; it is only a development dependency here. Call `dispose()` before quitting, await it, and handle cleanup failures; it is safe to retry. The SDK does not install process exit handlers or call `process.exit()`.
|
|
228
|
+
|
|
229
|
+
Validation:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm run build:embedded # SDK and page resources; no extension build required
|
|
233
|
+
npm run smoke:embedded # real Electron + MCP, two profiles, adapter editing, cleanup
|
|
234
|
+
npm run smoke:embedded:package # installed npm package inside app.asar
|
|
235
|
+
```
|
|
236
|
+
|
|
146
237
|
## Development
|
|
147
238
|
|
|
148
239
|
```bash
|
package/dist/docs/errors.md
CHANGED
|
@@ -50,3 +50,5 @@ A read-only inspection of the locally installed ChatGPT.app ASAR on 2026-10-22 f
|
|
|
50
50
|
- `runLoggedRequest`: attach session/request/turn context to failures and rethrow them.
|
|
51
51
|
|
|
52
52
|
These are observations of the installed desktop bundle, not claims about ChatGPT's server implementation or original source. We independently implement shared discovery contracts and retain host-owned logical tabs. We do not adopt its fallback to the first tab as an indication of the user's foreground intent. No vendor code is included in this repository.
|
|
53
|
+
|
|
54
|
+
The installed `openai-bundled/browser/26.1007.30912/scripts/browser-client.mjs` provides more direct evidence: `BrowserUser.openTabs()` accepts no query and returns `.tabs`; `PlaywrightAPI.evaluate` takes `(function, arg, options)`. Its argument serializer uses `JSON.stringify`; isolated execution confirmed `NaN` becomes `null` and `{x:undefined}` becomes `{}`. Those are reasons to enforce our own lossless contract, not copy that implementation. The positional signature explains a plausible source of API confusion, but does not establish what happened in either reporter's session.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Expectation } from '../shared/page-contract.js';
|
|
2
|
+
import type { ActAction, Target } from './tab.js';
|
|
3
|
+
export interface RawTarget {
|
|
4
|
+
ref?: string | number;
|
|
5
|
+
selector?: string;
|
|
6
|
+
within?: string;
|
|
7
|
+
nth?: number;
|
|
8
|
+
role?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
testid?: string;
|
|
13
|
+
x?: number;
|
|
14
|
+
y?: number;
|
|
15
|
+
frame?: Target['frame'];
|
|
16
|
+
}
|
|
17
|
+
export interface ActToolInput {
|
|
18
|
+
action: ActAction;
|
|
19
|
+
target?: RawTarget;
|
|
20
|
+
to?: RawTarget;
|
|
21
|
+
value?: string;
|
|
22
|
+
files?: string[];
|
|
23
|
+
direction?: 'up' | 'down' | 'left' | 'right';
|
|
24
|
+
amount?: number;
|
|
25
|
+
method?: 'cdp' | 'dom';
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
settleMs?: number;
|
|
28
|
+
}
|
|
29
|
+
type Need = 'required' | 'nonempty' | 'present' | 'optional' | 'forbidden';
|
|
30
|
+
export declare const ACTION_RULES: Record<ActAction, {
|
|
31
|
+
target: Need;
|
|
32
|
+
value: Need;
|
|
33
|
+
files: Need;
|
|
34
|
+
to: Need;
|
|
35
|
+
scroll: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
/** What the model can copy into the next call. Wire shape is error.details.expected. */
|
|
38
|
+
export declare function expectedAct(action: ActAction): Record<string, string>;
|
|
39
|
+
export declare function pickTarget(t: RawTarget | undefined, action: ActAction, slot: 'target' | 'to'): Target | undefined;
|
|
40
|
+
export declare function checkActInput(input: ActToolInput): {
|
|
41
|
+
target?: Target;
|
|
42
|
+
to?: Target;
|
|
43
|
+
method?: 'cdp' | 'dom';
|
|
44
|
+
};
|
|
45
|
+
/** Validate the public contract before sending a compiled expectation to the page. */
|
|
46
|
+
export declare function checkExpect(what: Expectation): void;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The object model — the single surface behind both the typed MCP tools and the `js` session.
|
|
3
|
+
* agent.browsers → browser.tabs / browser.user / browser.capabilities → tab.observe / tab.act / …
|
|
4
|
+
* sites.<site>.<command>(args) · recon.discover(tab) · tools.define · browser.nameSession / browser.tabs.finalize
|
|
5
|
+
* Split by object: tab.ts, browser.ts, api.ts (context.ts carries what they share). This file re-exports them.
|
|
6
|
+
*/
|
|
7
|
+
export * from './tab.js';
|
|
8
|
+
export * from './browser.js';
|
|
9
|
+
export * from './api.js';
|
|
10
|
+
export * from './context.js';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The object model's entry: agent.browsers · sites.<site>.<command>() · recon.discover(tab) · tools.define.
|
|
3
|
+
* One surface behind both the typed entry tools and the `js` session.
|
|
4
|
+
*/
|
|
5
|
+
import type { Runtime } from '../runtime/runtime.js';
|
|
6
|
+
import { discoverEndpoints, type DiscoverResult } from '../recon/discover.js';
|
|
7
|
+
import { listDefinedTools, type ToolDefinition } from '../sites/define.js';
|
|
8
|
+
import type { DraftExpectation } from '../sites/drafts.js';
|
|
9
|
+
import { Tab } from './tab.js';
|
|
10
|
+
import { Browser } from './browser.js';
|
|
11
|
+
export interface AgentApi {
|
|
12
|
+
agent: {
|
|
13
|
+
browsers: {
|
|
14
|
+
getDefault(): Promise<Browser>;
|
|
15
|
+
};
|
|
16
|
+
browser: Browser;
|
|
17
|
+
documentation: {
|
|
18
|
+
get(name: string): Promise<string | null>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
sites: Record<string, unknown> & {
|
|
22
|
+
search(q: string, limit?: number): Promise<unknown>;
|
|
23
|
+
list(): Promise<unknown>;
|
|
24
|
+
enable(site: string, opts?: {
|
|
25
|
+
write?: boolean;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
site: string;
|
|
28
|
+
tools: string[];
|
|
29
|
+
}>;
|
|
30
|
+
disable(site: string): Promise<boolean>;
|
|
31
|
+
run(site: string, name: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
32
|
+
};
|
|
33
|
+
recon: {
|
|
34
|
+
discover(tab: Tab, opts?: Parameters<typeof discoverEndpoints>[1]): Promise<DiscoverResult>;
|
|
35
|
+
};
|
|
36
|
+
tools: {
|
|
37
|
+
define(def: ToolDefinition | (Omit<ToolDefinition, 'func'> & {
|
|
38
|
+
func?: string | ((ctx: Record<string, unknown>) => unknown);
|
|
39
|
+
})): ReturnType<Runtime['defineTool']>;
|
|
40
|
+
try(draftId: string, args: Record<string, unknown>, expect: DraftExpectation): ReturnType<Runtime['tryToolDraft']>;
|
|
41
|
+
activate(draftId: string): ReturnType<Runtime['activateToolDraft']>;
|
|
42
|
+
discard(draftId: string): Promise<ReturnType<Runtime['discardToolDraft']>>;
|
|
43
|
+
list(): Promise<ReturnType<typeof listDefinedTools>>;
|
|
44
|
+
remove(site: string, name: string): ReturnType<Runtime['removeTool']>;
|
|
45
|
+
};
|
|
46
|
+
session: {
|
|
47
|
+
id: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare function createAgentApi(rt: Runtime, sessionId: string): AgentApi;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type TabDiscoveryOptions, type TabDiscoveryResult } from '../shared/api-contract.js';
|
|
2
|
+
import type { StreamOptions, StreamReadOptions, StreamBatch } from '../protocol.js';
|
|
3
|
+
import type { CloseUserTabsResult } from '../protocol.js';
|
|
4
|
+
import { Tab } from './tab.js';
|
|
5
|
+
import type { SessionContext } from './context.js';
|
|
6
|
+
export declare class Browser {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly type: 'extension' | 'electron';
|
|
9
|
+
private readonly ctx;
|
|
10
|
+
constructor(id: string, type: 'extension' | 'electron', ctx: SessionContext);
|
|
11
|
+
toJSON(): {
|
|
12
|
+
type: 'Browser';
|
|
13
|
+
id: string;
|
|
14
|
+
backend: string;
|
|
15
|
+
};
|
|
16
|
+
private page;
|
|
17
|
+
private ext;
|
|
18
|
+
/** Chrome APIs through the connected backend. Electron supports an explicit compatibility subset. */
|
|
19
|
+
readonly chrome: {
|
|
20
|
+
call: (method: string, args?: unknown[]) => Promise<unknown>;
|
|
21
|
+
describe: (member: string) => Promise<unknown>;
|
|
22
|
+
watch: (event: string, options?: StreamOptions) => Promise<import("./streams.js").EventStream>;
|
|
23
|
+
};
|
|
24
|
+
/** This extension's own service-worker logs; not logs of other installed extensions. */
|
|
25
|
+
readonly logs: {
|
|
26
|
+
watch: (options?: StreamOptions) => Promise<import("./streams.js").EventStream>;
|
|
27
|
+
read: (options?: StreamReadOptions) => Promise<StreamBatch>;
|
|
28
|
+
};
|
|
29
|
+
readonly tabs: {
|
|
30
|
+
new: (url?: string) => Promise<Tab>;
|
|
31
|
+
list: () => Promise<Array<{
|
|
32
|
+
id?: string;
|
|
33
|
+
tabId: number;
|
|
34
|
+
pending?: true;
|
|
35
|
+
url?: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
active: boolean;
|
|
38
|
+
selected: boolean;
|
|
39
|
+
lifecycle?: "dormant" | "loading" | "ready";
|
|
40
|
+
origin: "agent" | "user";
|
|
41
|
+
state: "active" | "handoff";
|
|
42
|
+
}>>;
|
|
43
|
+
get: (tab: string | {
|
|
44
|
+
tab?: string;
|
|
45
|
+
tabId: number;
|
|
46
|
+
}, opts?: {
|
|
47
|
+
timeoutMs?: number;
|
|
48
|
+
}) => Promise<Tab>;
|
|
49
|
+
selected: () => Promise<Tab | undefined>;
|
|
50
|
+
finalize: (opts?: {
|
|
51
|
+
keep?: Array<{
|
|
52
|
+
tab: string | Tab;
|
|
53
|
+
status: "deliverable" | "handoff";
|
|
54
|
+
}>;
|
|
55
|
+
}) => Promise<{
|
|
56
|
+
closed: string[];
|
|
57
|
+
kept: string[];
|
|
58
|
+
failed: Array<{
|
|
59
|
+
page: string;
|
|
60
|
+
reason: string;
|
|
61
|
+
}>;
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
readonly user: {
|
|
65
|
+
/** Unclaimed supported tabs in the visible scope. Query is trimmed, case-insensitive literal substring of URL OR title (no token splitting). Inspect items, matched, totalInScope, excluded and hasMore; continue with nextOffset. Each call takes a fresh snapshot. */
|
|
66
|
+
openTabs: (options?: {
|
|
67
|
+
query?: string | undefined;
|
|
68
|
+
limit?: number | undefined;
|
|
69
|
+
offset?: number | undefined;
|
|
70
|
+
} | undefined) => Promise<TabDiscoveryResult>;
|
|
71
|
+
/** Claim by foreground, id, or unique url/title lookup; expected fields verify the tab's current identity. */
|
|
72
|
+
claimTab: (tab: {
|
|
73
|
+
tabId?: number;
|
|
74
|
+
active?: boolean;
|
|
75
|
+
title?: string;
|
|
76
|
+
url?: string;
|
|
77
|
+
expectedUrl?: string;
|
|
78
|
+
expectedTitle?: string;
|
|
79
|
+
}) => Promise<Tab>;
|
|
80
|
+
/** Close user tabs by Chrome id without claiming or loading their pages. */
|
|
81
|
+
closeTabs: (tabIds: number[]) => Promise<CloseUserTabsResult>;
|
|
82
|
+
};
|
|
83
|
+
nameSession(name: string): Promise<void>;
|
|
84
|
+
readonly capabilities: {
|
|
85
|
+
list: () => Promise<Array<{
|
|
86
|
+
id: string;
|
|
87
|
+
description: string;
|
|
88
|
+
}>>;
|
|
89
|
+
get: (id: string) => Promise<Record<string, unknown>>;
|
|
90
|
+
};
|
|
91
|
+
documentation(): Promise<string>;
|
|
92
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** What every object of the model carries: the runtime, the MCP session id, and that session's state. */
|
|
2
|
+
import type { Runtime, SessionState } from '../runtime/runtime.js';
|
|
3
|
+
export interface SessionContext {
|
|
4
|
+
rt: Runtime;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
state: SessionState;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Stable, branchable errors for the object API and typed tools. */
|
|
2
|
+
export declare class ActionError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly hint?: string | undefined;
|
|
5
|
+
readonly data?: Record<string, unknown> | undefined;
|
|
6
|
+
constructor(code: string, message: string, hint?: string | undefined, data?: Record<string, unknown> | undefined);
|
|
7
|
+
toJSON(): Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export declare function errorEnvelope(err: unknown): {
|
|
10
|
+
ok: false;
|
|
11
|
+
error: Record<string, unknown>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Bounded, two-stage network evidence for agents. Raw captures stay in the session log. */
|
|
2
|
+
export interface NetworkEntry extends Record<string, unknown> {
|
|
3
|
+
seq: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function networkSummary(e: NetworkEntry): Record<string, unknown>;
|
|
6
|
+
export declare function networkDetail(e: NetworkEntry, opts?: {
|
|
7
|
+
part?: 'request' | 'response';
|
|
8
|
+
start?: number;
|
|
9
|
+
maxChars?: number;
|
|
10
|
+
}): Record<string, unknown>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ObserveResult } from './tab.js';
|
|
2
|
+
export declare const OBSERVATION_BUDGET = 10000;
|
|
3
|
+
/** Page one immutable capture across documents. Offsets are text characters or DOM entries. */
|
|
4
|
+
export declare function observationPage(capture: ObserveResult, cursor?: string): ObserveResult;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Command, StreamBatch, StreamOptions, StreamReadOptions } from '../protocol.js';
|
|
2
|
+
import type { SessionContext } from './context.js';
|
|
3
|
+
export interface EventStream {
|
|
4
|
+
/** Reads after the handle's last read, or an explicit cursor. Filtering still advances the cursor. */
|
|
5
|
+
read(options?: StreamReadOptions): Promise<StreamBatch>;
|
|
6
|
+
/** Idempotently releases this subscription. */
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare function browserCommand(ctx: SessionContext, feature: import('../protocol.js').BrowserFeature, action: Command['action'], params?: Partial<Command>): Promise<unknown>;
|
|
10
|
+
export declare function watch(ctx: SessionContext, source: 'chrome' | 'cdp' | 'console' | 'extension', event?: string, options?: StreamOptions, page?: string, route?: {
|
|
11
|
+
session: string;
|
|
12
|
+
surface: 'browser' | 'adapter';
|
|
13
|
+
}): Promise<EventStream>;
|