@jackwener/browsermcp 0.0.37 → 0.0.38-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.
Files changed (88) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +91 -0
  3. package/dist/src/api/action-input.d.ts +87 -0
  4. package/dist/src/api/agent.d.ts +10 -0
  5. package/dist/src/api/api.d.ts +54 -0
  6. package/dist/src/api/browser.d.ts +93 -0
  7. package/dist/src/api/commands.d.ts +506 -0
  8. package/dist/src/api/context.d.ts +7 -0
  9. package/dist/src/api/diff.d.ts +8 -0
  10. package/dist/src/api/errors.d.ts +14 -0
  11. package/dist/src/api/network.d.ts +10 -0
  12. package/dist/src/api/observation.d.ts +4 -0
  13. package/dist/src/api/streams.d.ts +13 -0
  14. package/dist/src/api/tab.d.ts +319 -0
  15. package/dist/src/api/webmcp.d.ts +19 -0
  16. package/dist/src/backends/backend.d.ts +14 -0
  17. package/dist/src/backends/browser-helpers.d.ts +17 -0
  18. package/dist/src/backends/extension-page.d.ts +5 -0
  19. package/dist/src/backends/managed-page.d.ts +50 -0
  20. package/dist/src/backends/page-transport.d.ts +10 -0
  21. package/dist/src/backends/page-types.d.ts +82 -0
  22. package/dist/src/docs/embedded.d.ts +2 -0
  23. package/dist/src/docs/embedded.js +40 -0
  24. package/dist/src/docs/embedded.js.map +1 -0
  25. package/dist/src/docs/manifest.d.ts +23 -0
  26. package/dist/src/docs/manifest.js +6 -3
  27. package/dist/src/docs/manifest.js.map +1 -1
  28. package/dist/src/docs/surface.d.ts +12 -0
  29. package/dist/src/electron/backend.d.ts +50 -0
  30. package/dist/src/electron/backend.js +375 -0
  31. package/dist/src/electron/backend.js.map +1 -0
  32. package/dist/src/electron/chrome.d.ts +24 -0
  33. package/dist/src/electron/chrome.js +133 -0
  34. package/dist/src/electron/chrome.js.map +1 -0
  35. package/dist/src/electron/driver.d.ts +43 -0
  36. package/dist/src/electron/driver.js +241 -0
  37. package/dist/src/electron/driver.js.map +1 -0
  38. package/dist/src/electron/event-buffer.d.ts +16 -0
  39. package/dist/src/electron/event-buffer.js +59 -0
  40. package/dist/src/electron/event-buffer.js.map +1 -0
  41. package/dist/src/electron/page.js +834 -0
  42. package/dist/src/electron/registry.d.ts +104 -0
  43. package/dist/src/electron/registry.js +316 -0
  44. package/dist/src/electron/registry.js.map +1 -0
  45. package/dist/src/electron/streams.d.ts +16 -0
  46. package/dist/src/electron/streams.js +48 -0
  47. package/dist/src/electron/streams.js.map +1 -0
  48. package/dist/src/embedded/index.d.ts +39 -0
  49. package/dist/src/embedded/index.js +72 -0
  50. package/dist/src/embedded/index.js.map +1 -0
  51. package/dist/src/host/bridge.d.ts +50 -0
  52. package/dist/src/host/doctor.d.ts +34 -0
  53. package/dist/src/host/extension.d.ts +3 -0
  54. package/dist/src/host/host.d.ts +3 -0
  55. package/dist/src/host/ipc.d.ts +14 -0
  56. package/dist/src/host/jsonc-config.d.ts +1 -0
  57. package/dist/src/host/launch.d.ts +11 -0
  58. package/dist/src/host/native-messaging.d.ts +28 -0
  59. package/dist/src/host/opencode.d.ts +6 -0
  60. package/dist/src/host/pi.d.ts +6 -0
  61. package/dist/src/host/registration.d.ts +24 -0
  62. package/dist/src/host/setup.d.ts +7 -0
  63. package/dist/src/host/socket.d.ts +25 -0
  64. package/dist/src/host/state.d.ts +39 -0
  65. package/dist/src/launcher/stdio.d.ts +3 -0
  66. package/dist/src/lib/paths.d.ts +1 -0
  67. package/dist/src/lib/sources.d.ts +5 -0
  68. package/dist/src/main.d.ts +2 -0
  69. package/dist/src/mcp/catalog.d.ts +202 -0
  70. package/dist/src/mcp/js-session.d.ts +64 -0
  71. package/dist/src/mcp/server.d.ts +15 -0
  72. package/dist/src/protocol.d.ts +320 -0
  73. package/dist/src/recon/analyzer.d.ts +43 -0
  74. package/dist/src/recon/discover.d.ts +48 -0
  75. package/dist/src/runtime/runtime.d.ts +148 -0
  76. package/dist/src/shared/api-contract.d.ts +86 -0
  77. package/dist/src/shared/aria-tree.d.ts +2 -0
  78. package/dist/src/shared/element-ref.d.ts +4 -0
  79. package/dist/src/shared/engine.d.ts +50 -0
  80. package/dist/src/shared/injected-source.d.ts +2 -0
  81. package/dist/src/shared/page-contract.d.ts +256 -0
  82. package/dist/src/sites/define.d.ts +28 -0
  83. package/dist/src/sites/drafts.d.ts +39 -0
  84. package/dist/src/sites/executor.d.ts +34 -0
  85. package/dist/src/sites/loader.d.ts +84 -0
  86. package/dist/src/sites/schema.d.ts +11 -0
  87. package/dist/src/version.d.ts +2 -0
  88. package/package.json +12 -3
package/CHANGELOG.md CHANGED
@@ -1,21 +1,67 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.38-embedded.0 — 2026-10-28
4
+
5
+ Includes stable 0.0.37 Agent Experience improvements: compact viewport observations and semantic pagination, navigation readiness via expect, explicit evaluate timeout outcomes, bounded error details, API signatures for recovery, and close receipts. Retains built-in adapter defaults and application-owned custom adapters.
6
+
3
7
  ## 0.0.37 — 2026-10-28
4
8
 
5
9
  Improve Agent Experience across browser backends: compact viewport observations with explicit scope and semantic pagination; navigation readiness conditions shared with expect; explicit evaluation timeout outcomes and bounded error details; API signatures in unknown-method recovery; clear reading continuation and close receipts.
6
10
 
11
+ ## 0.0.37-embedded.1 — 2026-10-28
12
+
13
+ Embedded adapters load from the packaged defaults and application-owned dataDir. MCP instructions expose loaded sites and the sites_search to site_run workflow. Activated custom adapters are immediately usable; externally edited adapters refresh on demand during command search. Clarify source overrides and packaging requirements.
14
+
15
+ ## 0.0.37-embedded.0 — 2026-10-28
16
+
17
+ Load packaged site adapters by default in embedded applications while keeping custom adapters in application-owned dataDir. Surface loaded adapters and direct sites_search to site_run usage at agent initialization. Explicit sources replaces built-ins; sources: [] keeps application adapters only. Activated custom adapters are immediately available to existing sessions.
18
+
7
19
  ## 0.0.36 — 2026-10-28
8
20
 
9
21
  Make existing site adapters discoverable at agent initialization: show loaded sites and command counts, document direct sites_search to site_run invocation without enabling, and clarify application-owned adapter storage.
10
22
 
23
+ ## 0.0.36-embedded.0 — 2026-10-28
24
+
25
+ Includes stable 0.0.35 shared typed browser commands and helpers. navigate_tab reuses existing pages; close_tab is available through MCP and session.api.helper. Retained page handles stay usable until session closure.
26
+
11
27
  ## 0.0.35 — 2026-10-28
12
28
 
13
29
  Add shared typed browser commands and session helpers, including navigate_tab and close_tab. Reuse existing tabs and preserve handoff handles. Protocol revision 5 requires extension 0.0.27 and a matching host.
14
30
 
31
+ ## 0.0.35-embedded.0 — 2026-10-22
32
+
33
+ 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.
34
+
15
35
  ## 0.0.34 — 2026-10-22
16
36
 
17
37
  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.
18
38
 
39
+ ## 0.0.34-embedded.3 — 2026-10-22
40
+
41
+ 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.
42
+
43
+ ## 0.0.34-embedded.2 — 2026-10-22
44
+
45
+ - Preserve logical tab identity, session ownership and retention across WebContents replacement.
46
+ - Define host-owned create/load/close callbacks and explicit attach/detach lifecycle operations.
47
+ - Report structured host failures with recoverable tab state; protect cleanup against invalid keep entries.
48
+ - Add handle-based deliverable/handoff retention and safe local remote-method inspection.
49
+ - Verify background duplicate claims, host failure recovery and installed ASAR execution.
50
+
51
+ ## 0.0.34-embedded.1 — 2026-10-21
52
+
53
+ - Model host tabs independently of WebContents, with stable logical IDs, explicit active selection, metadata updates and lazy loading.
54
+ - Expose typed host events and snapshots with public MCP session IDs; reserve ownership during loading and roll back or cancel failed/revoked claims.
55
+ - Unify tab state across MCP and Chrome APIs, and default MCP version to the installed package version.
56
+ - Migration: use registerPage handles and reported tabId values; tabId no longer equals webContents.id. Synchronize host selection with setActivePage(scope, handle).
57
+ - Share runtime isolation, storage injection, package version resolution and release infrastructure with main.
58
+
59
+ ## 0.0.34-embedded.0 — 2026-10-21
60
+
61
+ - Add the embedded Electron SDK with host-owned storage, profiles and page lifecycle.
62
+ - Support MCP sessions, adapter creation and updates, Chrome API compatibility and CDP in embedded Chromium.
63
+ - Import @jackwener/browsermcp/embedded without CLI setup or a Chrome extension.
64
+
19
65
  ## 0.0.33 — 2026-10-20
20
66
 
21
67
  - 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. Built-in adapters load by default. Set `sources` to replace the read-only sources, or `sources: []` to use only application-owned adapters. Activated adapters in `<dataDir>/adapters` override these sources and become available to existing sessions immediately through `sites_search` and `site_run`. For files copied or edited externally, command searches recheck source file metadata and reload changed adapters on demand; no restart is required. 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`, `adapters`, 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
@@ -0,0 +1,87 @@
1
+ import { z } from 'zod';
2
+ import type { Expectation } from '../shared/page-contract.js';
3
+ import type { ActAction, Target } from './tab.js';
4
+ export interface RawTarget {
5
+ ref?: string | number;
6
+ selector?: string;
7
+ within?: string;
8
+ nth?: number;
9
+ role?: string;
10
+ name?: string;
11
+ label?: string;
12
+ text?: string;
13
+ testid?: string;
14
+ x?: number;
15
+ y?: number;
16
+ frame?: Target['frame'];
17
+ }
18
+ export interface ActToolInput {
19
+ action: ActAction;
20
+ target?: RawTarget;
21
+ to?: RawTarget;
22
+ value?: string;
23
+ files?: string[];
24
+ direction?: 'up' | 'down' | 'left' | 'right';
25
+ amount?: number;
26
+ method?: 'cdp' | 'dom';
27
+ timeoutMs?: number;
28
+ settleMs?: number;
29
+ }
30
+ export declare const targetShape: z.ZodObject<{
31
+ ref: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
32
+ selector: z.ZodOptional<z.ZodString>;
33
+ within: z.ZodOptional<z.ZodString>;
34
+ nth: z.ZodOptional<z.ZodNumber>;
35
+ role: z.ZodOptional<z.ZodString>;
36
+ name: z.ZodOptional<z.ZodString>;
37
+ label: z.ZodOptional<z.ZodString>;
38
+ text: z.ZodOptional<z.ZodString>;
39
+ testid: z.ZodOptional<z.ZodString>;
40
+ x: z.ZodOptional<z.ZodNumber>;
41
+ y: z.ZodOptional<z.ZodNumber>;
42
+ frame: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>]>>;
43
+ }, z.core.$strict>;
44
+ export declare const expectationShape: z.ZodObject<{
45
+ target: z.ZodOptional<z.ZodObject<{
46
+ ref: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
47
+ selector: z.ZodOptional<z.ZodString>;
48
+ within: z.ZodOptional<z.ZodString>;
49
+ nth: z.ZodOptional<z.ZodNumber>;
50
+ role: z.ZodOptional<z.ZodString>;
51
+ name: z.ZodOptional<z.ZodString>;
52
+ label: z.ZodOptional<z.ZodString>;
53
+ text: z.ZodOptional<z.ZodString>;
54
+ testid: z.ZodOptional<z.ZodString>;
55
+ x: z.ZodOptional<z.ZodNumber>;
56
+ y: z.ZodOptional<z.ZodNumber>;
57
+ frame: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>]>>;
58
+ }, z.core.$strict>>;
59
+ text: z.ZodOptional<z.ZodString>;
60
+ notText: z.ZodOptional<z.ZodString>;
61
+ url: z.ZodOptional<z.ZodString>;
62
+ title: z.ZodOptional<z.ZodString>;
63
+ visible: z.ZodOptional<z.ZodBoolean>;
64
+ value: z.ZodOptional<z.ZodString>;
65
+ checked: z.ZodOptional<z.ZodBoolean>;
66
+ selected: z.ZodOptional<z.ZodArray<z.ZodString>>;
67
+ enabled: z.ZodOptional<z.ZodBoolean>;
68
+ }, z.core.$strict>;
69
+ type Need = 'required' | 'nonempty' | 'present' | 'optional' | 'forbidden';
70
+ export declare const ACTION_RULES: Record<ActAction, {
71
+ target: Need;
72
+ value: Need;
73
+ files: Need;
74
+ to: Need;
75
+ scroll: boolean;
76
+ }>;
77
+ /** What the model can copy into the next call. Wire shape is error.details.expected. */
78
+ export declare function expectedAct(action: ActAction): Record<string, string>;
79
+ export declare function pickTarget(t: RawTarget | undefined, action: ActAction, slot: 'target' | 'to'): Target | undefined;
80
+ export declare function checkActInput(input: ActToolInput): {
81
+ target?: Target;
82
+ to?: Target;
83
+ method?: 'cdp' | 'dom';
84
+ };
85
+ /** Validate the public contract before sending a compiled expectation to the page. */
86
+ export declare function checkExpect(what: Expectation): void;
87
+ 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,54 @@
1
+ import { type BrowserHelper, type BrowserCommands } from './commands.js';
2
+ /**
3
+ * The object model's entry: agent.browsers · sites.<site>.<command>() · recon.discover(tab) · tools.define.
4
+ * One surface behind both the typed entry tools and the `js` session.
5
+ */
6
+ import type { Runtime } from '../runtime/runtime.js';
7
+ import { discoverEndpoints, type DiscoverResult } from '../recon/discover.js';
8
+ import { listDefinedTools, type ToolDefinition } from '../sites/define.js';
9
+ import type { DraftExpectation } from '../sites/drafts.js';
10
+ import { Tab } from './tab.js';
11
+ import { Browser } from './browser.js';
12
+ export interface AgentApi {
13
+ helper: BrowserHelper;
14
+ agent: {
15
+ browsers: {
16
+ getDefault(): Promise<Browser>;
17
+ };
18
+ browser: Browser;
19
+ documentation: {
20
+ get(name: string): Promise<string | null>;
21
+ };
22
+ };
23
+ sites: Record<string, unknown> & {
24
+ search(q: string, limit?: number): Promise<unknown>;
25
+ list(): Promise<unknown>;
26
+ enable(site: string, opts?: {
27
+ write?: boolean;
28
+ }): Promise<{
29
+ site: string;
30
+ tools: string[];
31
+ }>;
32
+ disable(site: string): Promise<boolean>;
33
+ run(site: string, name: string, args?: Record<string, unknown>): Promise<unknown>;
34
+ };
35
+ recon: {
36
+ discover(tab: Tab, opts?: Parameters<typeof discoverEndpoints>[1]): Promise<DiscoverResult>;
37
+ };
38
+ tools: {
39
+ define(def: ToolDefinition | (Omit<ToolDefinition, 'func'> & {
40
+ func?: string | ((ctx: Record<string, unknown>) => unknown);
41
+ })): ReturnType<Runtime['defineTool']>;
42
+ try(draftId: string, args: Record<string, unknown>, expect: DraftExpectation): ReturnType<Runtime['tryToolDraft']>;
43
+ activate(draftId: string): ReturnType<Runtime['activateToolDraft']>;
44
+ discard(draftId: string): Promise<ReturnType<Runtime['discardToolDraft']>>;
45
+ list(): Promise<ReturnType<typeof listDefinedTools>>;
46
+ remove(site: string, name: string): ReturnType<Runtime['removeTool']>;
47
+ };
48
+ session: {
49
+ id: string;
50
+ };
51
+ }
52
+ export declare function createAgentApi(rt: Runtime, sessionId: string): AgentApi & {
53
+ commands: BrowserCommands;
54
+ };
@@ -0,0 +1,93 @@
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
+ released: string[];
58
+ retained: string[];
59
+ failed: Array<{
60
+ page: string;
61
+ reason: string;
62
+ }>;
63
+ }>;
64
+ };
65
+ readonly user: {
66
+ /** 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. */
67
+ openTabs: (options?: {
68
+ query?: string | undefined;
69
+ limit?: number | undefined;
70
+ offset?: number | undefined;
71
+ } | undefined) => Promise<TabDiscoveryResult>;
72
+ /** Claim by foreground, id, or unique url/title lookup; expected fields verify the tab's current identity. */
73
+ claimTab: (tab: {
74
+ tabId?: number;
75
+ active?: boolean;
76
+ title?: string;
77
+ url?: string;
78
+ expectedUrl?: string;
79
+ expectedTitle?: string;
80
+ }) => Promise<Tab>;
81
+ /** Close user tabs by Chrome id without claiming or loading their pages. */
82
+ closeTabs: (tabIds: number[]) => Promise<CloseUserTabsResult>;
83
+ };
84
+ nameSession(name: string): Promise<void>;
85
+ readonly capabilities: {
86
+ list: () => Promise<Array<{
87
+ id: string;
88
+ description: string;
89
+ }>>;
90
+ get: (id: string) => Promise<Record<string, unknown>>;
91
+ };
92
+ documentation(): Promise<string>;
93
+ }