@jackwener/browsermcp 0.0.32 → 0.0.34-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 +24 -1
- package/README.md +67 -7
- package/adapters/discord/_shared.js +1 -1
- package/adapters/facebook/_graphql.js +1 -1
- package/adapters/facebook/events.js +1 -1
- package/adapters/facebook/feed.js +2 -2
- package/adapters/facebook/friends.js +1 -1
- package/adapters/facebook/groups.js +1 -1
- package/adapters/facebook/notifications.js +1 -1
- package/adapters/gmail/_shared.js +1 -1
- package/cordis.patch.yml +1 -3
- package/dist/docs/api-reference.md +22 -16
- package/dist/docs/api-use.md +69 -65
- package/dist/docs/capabilities/webmcp.md +5 -1
- package/dist/docs/define-tools.md +1 -1
- package/dist/docs/errors.md +1 -1
- package/dist/docs/instructions.md +1 -1
- package/dist/docs/js-tool.md +4 -2
- package/dist/docs/sites.md +1 -1
- package/dist/src/api/action-input.d.ts +47 -0
- package/dist/src/api/action-input.js +13 -7
- package/dist/src/api/action-input.js.map +1 -1
- package/dist/src/api/agent.d.ts +10 -0
- package/dist/src/api/api.d.ts +50 -0
- package/dist/src/api/api.js +8 -9
- package/dist/src/api/api.js.map +1 -1
- package/dist/src/api/browser.d.ts +89 -0
- package/dist/src/api/browser.js +25 -6
- package/dist/src/api/browser.js.map +1 -1
- 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/observation.js +2 -1
- package/dist/src/api/observation.js.map +1 -1
- package/dist/src/api/streams.d.ts +13 -0
- package/dist/src/api/streams.js +1 -1
- package/dist/src/api/streams.js.map +1 -1
- package/dist/src/api/tab.d.ts +308 -0
- package/dist/src/api/tab.js +86 -13
- package/dist/src/api/tab.js.map +1 -1
- package/dist/src/api/webmcp.d.ts +19 -0
- package/dist/src/api/webmcp.js +43 -0
- package/dist/src/api/webmcp.js.map +1 -0
- package/dist/src/backends/backend.d.ts +14 -0
- package/dist/src/backends/backend.js +2 -0
- package/dist/src/backends/backend.js.map +1 -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/extension-page.js +23 -6
- package/dist/src/backends/extension-page.js.map +1 -1
- package/dist/src/backends/managed-page.d.ts +57 -0
- package/dist/src/backends/managed-page.js +2 -0
- package/dist/src/backends/managed-page.js.map +1 -0
- package/dist/src/backends/page-transport.d.ts +10 -0
- package/dist/src/backends/page-transport.js +2 -0
- package/dist/src/backends/page-transport.js.map +1 -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 +33 -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 +46 -0
- package/dist/src/electron/backend.js +333 -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 +135 -0
- package/dist/src/electron/chrome.js.map +1 -0
- package/dist/src/electron/driver.d.ts +42 -0
- package/dist/src/electron/driver.js +238 -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 +33 -0
- package/dist/src/electron/registry.js +85 -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 +30 -0
- package/dist/src/embedded/index.js +57 -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/extension.js +1 -1
- package/dist/src/host/extension.js.map +1 -1
- package/dist/src/host/host.d.ts +3 -0
- package/dist/src/host/host.js +2 -1
- package/dist/src/host/host.js.map +1 -1
- package/dist/src/host/ipc.d.ts +14 -0
- package/dist/src/host/ipc.js +1 -1
- package/dist/src/host/ipc.js.map +1 -1
- package/dist/src/host/jsonc-config.d.ts +1 -0
- package/dist/src/host/jsonc-config.js +4 -7
- package/dist/src/host/jsonc-config.js.map +1 -1
- package/dist/src/host/launch.d.ts +11 -0
- package/dist/src/host/launch.js +3 -3
- package/dist/src/host/launch.js.map +1 -1
- package/dist/src/host/native-messaging.d.ts +28 -0
- package/dist/src/host/opencode.d.ts +6 -0
- package/dist/src/host/opencode.js +1 -1
- package/dist/src/host/opencode.js.map +1 -1
- package/dist/src/host/pi.d.ts +6 -0
- package/dist/src/host/pi.js +1 -1
- package/dist/src/host/pi.js.map +1 -1
- package/dist/src/host/registration.d.ts +24 -0
- package/dist/src/host/registration.js +2 -2
- package/dist/src/host/registration.js.map +1 -1
- package/dist/src/host/setup.d.ts +7 -0
- package/dist/src/host/setup.js +0 -8
- package/dist/src/host/setup.js.map +1 -1
- package/dist/src/host/socket.d.ts +25 -0
- package/dist/src/host/socket.js +1 -1
- package/dist/src/host/socket.js.map +1 -1
- package/dist/src/host/state.d.ts +39 -0
- package/dist/src/host/state.js +5 -6
- package/dist/src/host/state.js.map +1 -1
- package/dist/src/launcher/stdio.d.ts +3 -0
- package/dist/src/launcher/stdio.js +1 -1
- package/dist/src/launcher/stdio.js.map +1 -1
- package/dist/src/lib/paths.d.ts +1 -0
- package/dist/src/lib/paths.js +4 -0
- package/dist/src/lib/paths.js.map +1 -0
- package/dist/src/lib/sources.d.ts +5 -0
- package/dist/src/lib/sources.js +2 -2
- package/dist/src/lib/sources.js.map +1 -1
- package/dist/src/main.d.ts +2 -0
- package/dist/src/mcp/catalog.d.ts +202 -0
- package/dist/src/mcp/js-evaluator.mjs +3 -3
- package/dist/src/mcp/js-session.d.ts +63 -0
- package/dist/src/mcp/server.d.ts +15 -0
- package/dist/src/mcp/server.js +5 -5
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/protocol.d.ts +318 -0
- package/dist/src/protocol.js +1 -1
- package/dist/src/protocol.js.map +1 -1
- 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/runtime/runtime.js +79 -34
- package/dist/src/runtime/runtime.js.map +1 -1
- 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/engine.js +3 -3
- package/dist/src/shared/engine.js.map +1 -1
- package/dist/src/shared/injected-source.d.ts +2 -0
- package/dist/src/shared/page-contract.d.ts +256 -0
- package/dist/src/shared/page-contract.js +3 -3
- package/dist/src/shared/page-contract.js.map +1 -1
- package/dist/src/sites/define.d.ts +28 -0
- package/dist/src/sites/define.js +25 -29
- package/dist/src/sites/define.js.map +1 -1
- package/dist/src/sites/drafts.d.ts +39 -0
- package/dist/src/sites/drafts.js +117 -115
- package/dist/src/sites/drafts.js.map +1 -1
- package/dist/src/sites/executor.d.ts +34 -0
- package/dist/src/sites/loader.d.ts +84 -0
- package/dist/src/sites/loader.js +1 -1
- package/dist/src/sites/schema.d.ts +11 -0
- package/docs/api-reference.md +22 -16
- package/docs/api-use.md +69 -65
- package/docs/capabilities/webmcp.md +5 -1
- package/docs/define-tools.md +1 -1
- package/docs/errors.md +1 -1
- package/docs/guide.zh-CN.md +4 -4
- package/docs/instructions.md +1 -1
- package/docs/js-tool.md +4 -2
- package/docs/observation-design.md +11 -3
- package/docs/releasing.md +8 -0
- package/docs/setup.md +22 -8
- package/docs/sites.md +1 -1
- package/extension/dist/background.js +20 -22
- package/extension/dist/content/cursor.js +3 -3
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/page.js +48 -15
- package/package.json +12 -3
package/dist/src/sites/drafts.js
CHANGED
|
@@ -3,132 +3,134 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createHash, randomUUID } from 'node:crypto';
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
|
-
import { USER_ADAPTERS_DIR } from '../lib/sources.js';
|
|
7
6
|
import { ensureUserSource, renderAdapterModule, validateDefinition } from './define.js';
|
|
8
7
|
import { argSpec } from './schema.js';
|
|
9
8
|
import { adapterCommandFromDescriptor } from './loader.js';
|
|
10
9
|
import { ActionError } from '../api/errors.js';
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
export function createDraftStore(userAdaptersDir) {
|
|
11
|
+
const DRAFT_DIR = path.join(path.dirname(userAdaptersDir), 'drafts');
|
|
12
|
+
const inFlight = new Set();
|
|
13
|
+
const draftPath = (id, ext) => {
|
|
14
|
+
if (!/^[0-9a-f-]{36}$/.test(id))
|
|
15
|
+
throw new ActionError('unknown_draft', 'Invalid draft id.');
|
|
16
|
+
return path.join(DRAFT_DIR, `${id}.${ext}`);
|
|
17
|
+
};
|
|
18
|
+
const digest = (file) => fs.existsSync(file) ? createHash('sha256').update(fs.readFileSync(file)).digest('hex') : null;
|
|
19
|
+
const targetPath = (site, name) => path.join(userAdaptersDir, site, `${name}.js`);
|
|
20
|
+
function readRecord(id) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(fs.readFileSync(draftPath(id, 'json'), 'utf8'));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new ActionError('unknown_draft', `No adapter draft ${id}.`, 'Create one with tools.define.');
|
|
26
|
+
}
|
|
26
27
|
}
|
|
27
|
-
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
function writeRecord(record) { fs.writeFileSync(draftPath(record.id, 'json'), JSON.stringify(record, null, 2)); }
|
|
29
|
+
async function createDraft(def, activeFile) {
|
|
30
|
+
validateDefinition(def);
|
|
31
|
+
ensureUserSource(userAdaptersDir);
|
|
32
|
+
fs.mkdirSync(DRAFT_DIR, { recursive: true });
|
|
33
|
+
const id = randomUUID();
|
|
34
|
+
const file = draftPath(id, 'js');
|
|
35
|
+
try {
|
|
36
|
+
fs.writeFileSync(file, renderAdapterModule(def));
|
|
37
|
+
await import(`${pathToFileURL(file).href}?draft=${id}`);
|
|
38
|
+
writeRecord({ id, site: def.site, name: def.name, createdAt: new Date().toISOString(), baselineFile: activeFile ?? null, baseline: activeFile ? digest(activeFile) : null, verified: false });
|
|
39
|
+
return { draftId: id, site: def.site, name: def.name, args: argSpec(def.args) };
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
fs.rmSync(file, { force: true });
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
async function loadDraftCommand(id) {
|
|
47
|
+
const record = readRecord(id);
|
|
48
|
+
const file = draftPath(id, 'js');
|
|
49
|
+
const descriptor = (await import(`${pathToFileURL(file).href}?t=${digest(file)}`)).default;
|
|
50
|
+
if (!descriptor || typeof descriptor.run !== 'function')
|
|
51
|
+
throw new ActionError('invalid_definition', 'Draft does not export an adapter run function.');
|
|
52
|
+
return adapterCommandFromDescriptor(record.site, record.name, 'user', descriptor);
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
function pathValue(value, expression) {
|
|
55
|
-
let current = value;
|
|
56
|
-
for (const key of expression.split('.').filter(Boolean)) {
|
|
57
|
-
if (current === null || typeof current !== 'object' || !Object.hasOwn(current, key))
|
|
58
|
-
return { found: false, value: undefined };
|
|
59
|
-
current = current[key];
|
|
54
|
+
function pathValue(value, expression) {
|
|
55
|
+
let current = value;
|
|
56
|
+
for (const key of expression.split('.').filter(Boolean)) {
|
|
57
|
+
if (current === null || typeof current !== 'object' || !Object.hasOwn(current, key))
|
|
58
|
+
return { found: false, value: undefined };
|
|
59
|
+
current = current[key];
|
|
60
|
+
}
|
|
61
|
+
return { found: true, value: current };
|
|
60
62
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
function checkDraftResult(result, expect) {
|
|
64
|
+
const checks = [];
|
|
65
|
+
if (!result.ok)
|
|
66
|
+
return { passed: false, checks: [{ check: 'adapter execution', passed: false, actual: result.error }] };
|
|
67
|
+
if (expect.minRows !== undefined)
|
|
68
|
+
checks.push({ check: `rows.length >= ${expect.minRows}`, passed: Array.isArray(result.rows) && result.rows.length >= expect.minRows, actual: result.rows?.length });
|
|
69
|
+
if (expect.path !== undefined) {
|
|
70
|
+
const found = pathValue(result, expect.path);
|
|
71
|
+
const equal = !Object.hasOwn(expect, 'equals') || JSON.stringify(found.value) === JSON.stringify(expect.equals);
|
|
72
|
+
checks.push({ check: Object.hasOwn(expect, 'equals') ? `${expect.path} equals expected value` : `${expect.path} exists`, passed: found.found && found.value !== undefined && equal, actual: found.value });
|
|
73
|
+
}
|
|
74
|
+
if (!checks.length)
|
|
75
|
+
throw new ActionError('invalid_args', 'Verification needs minRows or path (with optional equals).', 'Choose an assertion about the real result before activating.');
|
|
76
|
+
return { passed: checks.every((c) => c.passed), checks };
|
|
73
77
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
record
|
|
99
|
-
|
|
100
|
-
|
|
78
|
+
async function tryDraft(run, id, args, expect) {
|
|
79
|
+
if (expect.minRows === undefined && !expect.path?.trim())
|
|
80
|
+
throw new ActionError('invalid_args', 'Verification needs minRows or path.', 'Choose an assertion about the real result before running the draft.');
|
|
81
|
+
if (expect.minRows !== undefined && (!Number.isInteger(expect.minRows) || expect.minRows < 1))
|
|
82
|
+
throw new ActionError('invalid_args', 'minRows must be at least 1.', 'Assert a returned row, or use path and equals to verify an empty result.');
|
|
83
|
+
if (expect.path && !/^(rows|value)(\.|$)/.test(expect.path))
|
|
84
|
+
throw new ActionError('invalid_args', 'Verification path must point into rows or value.', 'Assert the adapter output, not the runtime envelope.');
|
|
85
|
+
if (Object.hasOwn(expect, 'equals') && !expect.path?.trim())
|
|
86
|
+
throw new ActionError('invalid_args', 'equals needs path.', 'Add the dot path to compare.');
|
|
87
|
+
const record = readRecord(id);
|
|
88
|
+
if (inFlight.has(id))
|
|
89
|
+
throw new ActionError('draft_in_use', 'This draft is already being tried.', 'Wait for the current trial to finish.');
|
|
90
|
+
inFlight.add(id);
|
|
91
|
+
try {
|
|
92
|
+
const cmd = await loadDraftCommand(id);
|
|
93
|
+
const result = await run(cmd, args);
|
|
94
|
+
const verification = checkDraftResult(result, expect);
|
|
95
|
+
record.verified = verification.passed;
|
|
96
|
+
if (verification.passed) {
|
|
97
|
+
record.verifiedAt = new Date().toISOString();
|
|
98
|
+
record.verifiedDigest = digest(draftPath(id, 'js')) ?? undefined;
|
|
99
|
+
record.sampleArgs = args;
|
|
100
|
+
record.expectation = expect;
|
|
101
|
+
}
|
|
102
|
+
writeRecord(record);
|
|
103
|
+
return { result, verification };
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
inFlight.delete(id);
|
|
101
107
|
}
|
|
102
|
-
writeRecord(record);
|
|
103
|
-
return { result, verification };
|
|
104
108
|
}
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
function activateDraft(id, sourceFile) {
|
|
110
|
+
const record = readRecord(id);
|
|
111
|
+
if (inFlight.has(id))
|
|
112
|
+
throw new ActionError('draft_in_use', 'This draft is still being tried.', 'Wait for the trial to finish before activation.');
|
|
113
|
+
const activeFile = sourceFile(record.site, record.name);
|
|
114
|
+
if (!record.verified || !record.verifiedAt)
|
|
115
|
+
throw new ActionError('draft_not_verified', 'This draft has not passed a real trial with an output assertion.', 'Run tools.try with sample args and expect first.');
|
|
116
|
+
if (digest(draftPath(id, 'js')) !== record.verifiedDigest)
|
|
117
|
+
throw new ActionError('draft_changed', 'This draft changed after its verified trial.', 'Run tools.try again before activating.');
|
|
118
|
+
const target = targetPath(record.site, record.name);
|
|
119
|
+
if ((activeFile ?? null) !== record.baselineFile || (activeFile ? digest(activeFile) : null) !== record.baseline || (target !== activeFile && digest(target) !== null))
|
|
120
|
+
throw new ActionError('draft_conflict', 'The active adapter changed after this draft was created.', 'Create a new draft from the latest definition.');
|
|
121
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
122
|
+
fs.renameSync(draftPath(id, 'js'), target);
|
|
123
|
+
fs.rmSync(draftPath(id, 'json'), { force: true });
|
|
124
|
+
return { site: record.site, name: record.name, file: target, verifiedAt: record.verifiedAt };
|
|
107
125
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
throw new ActionError('draft_changed', 'This draft changed after its verified trial.', 'Run tools.try again before activating.');
|
|
118
|
-
const target = targetPath(record.site, record.name);
|
|
119
|
-
if ((activeFile ?? null) !== record.baselineFile || (activeFile ? digest(activeFile) : null) !== record.baseline || (target !== activeFile && digest(target) !== null))
|
|
120
|
-
throw new ActionError('draft_conflict', 'The active adapter changed after this draft was created.', 'Create a new draft from the latest definition.');
|
|
121
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
122
|
-
fs.renameSync(draftPath(id, 'js'), target);
|
|
123
|
-
fs.rmSync(draftPath(id, 'json'), { force: true });
|
|
124
|
-
return { site: record.site, name: record.name, file: target, verifiedAt: record.verifiedAt };
|
|
125
|
-
}
|
|
126
|
-
export function discardDraft(id) {
|
|
127
|
-
readRecord(id);
|
|
128
|
-
if (inFlight.has(id))
|
|
129
|
-
throw new ActionError('draft_in_use', 'This draft is still being tried.', 'Wait for the trial to finish before discarding it.');
|
|
130
|
-
fs.rmSync(draftPath(id, 'js'), { force: true });
|
|
131
|
-
fs.rmSync(draftPath(id, 'json'), { force: true });
|
|
132
|
-
return { draftId: id, discarded: true };
|
|
126
|
+
function discardDraft(id) {
|
|
127
|
+
readRecord(id);
|
|
128
|
+
if (inFlight.has(id))
|
|
129
|
+
throw new ActionError('draft_in_use', 'This draft is still being tried.', 'Wait for the trial to finish before discarding it.');
|
|
130
|
+
fs.rmSync(draftPath(id, 'js'), { force: true });
|
|
131
|
+
fs.rmSync(draftPath(id, 'json'), { force: true });
|
|
132
|
+
return { draftId: id, discarded: true };
|
|
133
|
+
}
|
|
134
|
+
return { createDraft, tryDraft, activateDraft, discardDraft };
|
|
133
135
|
}
|
|
134
136
|
//# sourceMappingURL=drafts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drafts.js","sourceRoot":"","sources":["../../../src/sites/drafts.ts"],"names":[],"mappings":"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C;IAED,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AdapterCommand } from './loader.js';
|
|
2
|
+
import type { RuntimePage } from '../backends/page-types.js';
|
|
3
|
+
export interface PageProvider {
|
|
4
|
+
getAdapterPage(site: string): Promise<RuntimePage>;
|
|
5
|
+
browserAvailable(): boolean;
|
|
6
|
+
/** The object model bound to a page: the same `tab`/`sites`/`recon` an agent uses in `js`. */
|
|
7
|
+
toolContext(page: RuntimePage, site: string): Promise<Record<string, unknown>>;
|
|
8
|
+
}
|
|
9
|
+
export interface CommandRunResult {
|
|
10
|
+
ok: true;
|
|
11
|
+
site: string;
|
|
12
|
+
name: string;
|
|
13
|
+
rows?: unknown[];
|
|
14
|
+
value?: unknown;
|
|
15
|
+
nextCursor?: string;
|
|
16
|
+
elapsedMs: number;
|
|
17
|
+
}
|
|
18
|
+
export interface CommandRunError {
|
|
19
|
+
ok: false;
|
|
20
|
+
site: string;
|
|
21
|
+
name: string;
|
|
22
|
+
error: {
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
hint?: string;
|
|
26
|
+
details?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
elapsedMs: number;
|
|
29
|
+
}
|
|
30
|
+
export declare const DEFAULT_TIMEOUT_MS = 120000;
|
|
31
|
+
export declare function runAdapter(provider: PageProvider, cmd: AdapterCommand, rawArgs: Record<string, unknown>, opts?: {
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}): Promise<CommandRunResult | CommandRunError>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type Arg, type ArgView } from './schema.js';
|
|
2
|
+
export type SourceKind = 'builtin' | 'user';
|
|
3
|
+
export interface Source {
|
|
4
|
+
dir: string;
|
|
5
|
+
kind: SourceKind;
|
|
6
|
+
}
|
|
7
|
+
export interface AdapterContext {
|
|
8
|
+
args: Record<string, unknown>;
|
|
9
|
+
tab: unknown;
|
|
10
|
+
sites: unknown;
|
|
11
|
+
recon: unknown;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
/** A loaded adapter: the descriptor from the module plus its path-derived identity. */
|
|
15
|
+
export interface AdapterCommand {
|
|
16
|
+
site: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
access: 'read' | 'write';
|
|
20
|
+
domain?: string;
|
|
21
|
+
result?: {
|
|
22
|
+
kind: 'rows' | 'value';
|
|
23
|
+
description: string;
|
|
24
|
+
fields?: Record<string, string>;
|
|
25
|
+
paginated?: boolean;
|
|
26
|
+
};
|
|
27
|
+
args: Arg[];
|
|
28
|
+
aliases?: string[];
|
|
29
|
+
source: SourceKind;
|
|
30
|
+
run: (ctx: AdapterContext) => Promise<unknown>;
|
|
31
|
+
}
|
|
32
|
+
/** One descriptor validation path for built-in, user, and draft adapters. */
|
|
33
|
+
export declare function adapterCommandFromDescriptor(site: string, name: string, source: SourceKind, descriptor: Record<string, unknown>): AdapterCommand;
|
|
34
|
+
export declare class SiteRegistry {
|
|
35
|
+
private sources;
|
|
36
|
+
loadedAt: number | null;
|
|
37
|
+
private index;
|
|
38
|
+
private indexStamp;
|
|
39
|
+
constructor(sources?: Source[]);
|
|
40
|
+
/** Replace the source list (later overrides earlier). */
|
|
41
|
+
setSources(sources: Source[]): void;
|
|
42
|
+
addSource(source: Source): void;
|
|
43
|
+
load(): Promise<void>;
|
|
44
|
+
private existingDirs;
|
|
45
|
+
/** Include file identity: replacing an adapter does not update its parent directory mtime. */
|
|
46
|
+
private stamp;
|
|
47
|
+
private siteDirs;
|
|
48
|
+
private siteAliases;
|
|
49
|
+
/** site -> command-name -> absolute file path (later source wins). */
|
|
50
|
+
private map;
|
|
51
|
+
private kindOf;
|
|
52
|
+
private importDescriptor;
|
|
53
|
+
private toCommand;
|
|
54
|
+
private buildIndex;
|
|
55
|
+
private all;
|
|
56
|
+
has(site: string): boolean;
|
|
57
|
+
sites(): Array<{
|
|
58
|
+
site: string;
|
|
59
|
+
aliases: string[];
|
|
60
|
+
commands: number;
|
|
61
|
+
read: number;
|
|
62
|
+
write: number;
|
|
63
|
+
domains: string[];
|
|
64
|
+
source: SourceKind;
|
|
65
|
+
sample: string[];
|
|
66
|
+
}>;
|
|
67
|
+
commandNames(site: string): string[];
|
|
68
|
+
sourceFile(site: string, name: string): string | undefined;
|
|
69
|
+
/** Command metadata for a site (from the index; loads it if cold). */
|
|
70
|
+
commands(site: string): Promise<Array<Omit<AdapterCommand, 'run'>>>;
|
|
71
|
+
/** Rank commands for a free-text query, using the in-memory index. */
|
|
72
|
+
search(query: string, limit?: number): Promise<Array<{
|
|
73
|
+
site: string;
|
|
74
|
+
name: string;
|
|
75
|
+
description: string;
|
|
76
|
+
score: number;
|
|
77
|
+
access: string;
|
|
78
|
+
domain?: string;
|
|
79
|
+
args: ArgView[];
|
|
80
|
+
result?: AdapterCommand['result'];
|
|
81
|
+
}>>;
|
|
82
|
+
/** Load a command with its `run` implementation. Resolves aliases via the index. */
|
|
83
|
+
resolve(site: string, name: string): Promise<AdapterCommand>;
|
|
84
|
+
}
|
package/dist/src/sites/loader.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* a small in-memory index (rebuilt on directory mtime change) for cross-site search.
|
|
6
6
|
*
|
|
7
7
|
* Sources are an ordered list; a later source overrides an earlier one for the same `<site>/<command>` — so the
|
|
8
|
-
* built-in corpus, the user's `~/.
|
|
8
|
+
* built-in corpus, the user's `~/.browsermcp/adapters`, and agent-defined tools are one mechanism, not three.
|
|
9
9
|
*/
|
|
10
10
|
import fs from 'node:fs';
|
|
11
11
|
import path from 'node:path';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** One adapter argument contract drives discovery, MCP schemas, and runtime validation. */
|
|
2
|
+
import { type ZodTypeAny } from 'zod';
|
|
3
|
+
import type { Arg } from '@jackwener/browsermcp/adapter-sdk';
|
|
4
|
+
export type { Arg } from '@jackwener/browsermcp/adapter-sdk';
|
|
5
|
+
export type ArgView = Arg;
|
|
6
|
+
export declare function argSpec(args?: Arg[]): ArgView[];
|
|
7
|
+
export declare function argToZod(arg: Arg): ZodTypeAny;
|
|
8
|
+
export declare function argsToShape(args?: Arg[], extra?: Record<string, ZodTypeAny>): Record<string, ZodTypeAny>;
|
|
9
|
+
export declare function validateArgDefinitions(args?: Arg[]): void;
|
|
10
|
+
/** Coerce CLI-like scalar input once, then validate the same schema exposed to MCP. */
|
|
11
|
+
export declare function coerceArgs(cmdArgs: Arg[] | undefined, kwargs: Record<string, unknown>): Record<string, unknown>;
|
package/docs/api-reference.md
CHANGED
|
@@ -21,9 +21,9 @@ interface AgentApi {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
class Browser {
|
|
24
|
-
id:
|
|
25
|
-
type: "extension";
|
|
26
|
-
chrome: { //
|
|
24
|
+
id: string;
|
|
25
|
+
type: "extension" | "electron";
|
|
26
|
+
chrome: { // Chrome APIs through the connected backend. Electron supports an explicit compatibility subset.
|
|
27
27
|
call(method: string, args?: Array<unknown>): Promise<unknown>;
|
|
28
28
|
describe(member: string): Promise<unknown>;
|
|
29
29
|
watch(event: string, options?: StreamOptions): Promise<EventStream>;
|
|
@@ -35,7 +35,7 @@ class Browser {
|
|
|
35
35
|
tabs: {
|
|
36
36
|
new(url?: string): Promise<Tab>;
|
|
37
37
|
list(): Promise<Array<{ id?: string; tabId: number; pending?: true; url?: string; title?: string; active: boolean; selected: boolean; origin: "agent" | "user"; state: "active" | "handoff"; }>>;
|
|
38
|
-
get(
|
|
38
|
+
get(tab: string | { tab?: string; tabId: number; }, opts?: { timeoutMs?: number; }): Promise<Tab>;
|
|
39
39
|
selected(): Promise<Tab | undefined>;
|
|
40
40
|
finalize(opts?: { keep?: Array<{ tab: string | Tab; status: "handoff" | "deliverable"; }>; }): Promise<{ closed: Array<string>; kept: Array<string>; failed: Array<{ page: string; reason: string; }>; }>;
|
|
41
41
|
};
|
|
@@ -63,18 +63,18 @@ class Tab {
|
|
|
63
63
|
reload(): Promise<void>;
|
|
64
64
|
close(): Promise<void>; // Close this tab, whether it was opened or claimed by this session.
|
|
65
65
|
release(): Promise<void>; // Keep this tab open and give up this session's control of it.
|
|
66
|
-
observe(opts?: ObserveOptions): Promise<ObserveResult>; // ARIA overview by default; format:'dom' reveals visible controls and live attributes.
|
|
66
|
+
observe(opts?: ObserveOptions): Promise<ObserveResult>; // ARIA overview by default; format:'dom' reveals visible controls and live attributes. Observed refs automatically route to their frame.
|
|
67
67
|
screenshot(opts?: { fullPage?: boolean; annotate?: boolean; format?: "png" | "jpeg"; quality?: number; }): Promise<ImageValue>;
|
|
68
68
|
find(target: (Target & { limit?: number; }) | { query: string; limit?: number; frame?: FrameStep | Array<FrameStep>; }): Promise<FindResult | ElementAtResult | QueryFindResult>;
|
|
69
|
-
read(opts: ReadElementOptions): Promise<ElementDetails>; // With target: exact current element text, attributes and live values, without scrolling. Otherwise: bounded document text scan (including open shadow roots), restores scroll;
|
|
70
|
-
read(opts?: ReadOptions): Promise<
|
|
69
|
+
read(opts: ReadElementOptions): Promise<ElementDetails>; // With target: exact current element text, attributes and live values, without scrolling. Otherwise: bounded document text scan (including open shadow roots), restores scroll; pass result.next to continue. A growing feed returns reason `unbounded`; the scan stops rather than chasing an endless bottom.
|
|
70
|
+
read(opts?: ReadOptions): Promise<DocumentReadResult>; // With target: exact current element text, attributes and live values, without scrolling. Otherwise: bounded document text scan (including open shadow roots), restores scroll; pass result.next to continue. A growing feed returns reason `unbounded`; the scan stops rather than chasing an endless bottom.
|
|
71
71
|
act(opts: ActOptions): Promise<ActionOutcome>; // wait + act in one call at the runtime edge: locate → wait actionable → hit-test → real input → settle. `method:'dom'` skips the mouse event.
|
|
72
72
|
webmcp: { // WebMCP: tools the page itself registers via navigator.modelContext (page-provided tool source).
|
|
73
|
-
list(
|
|
74
|
-
call(name: string, input?: Record<string, unknown
|
|
73
|
+
list(options?: { name?: string; frame?: FrameStep | Array<FrameStep>; }): Promise<Array<PageTool>>; // List names/descriptions, or fetch one full schema by name. Scoped to the requested frame.
|
|
74
|
+
call(name: string, input?: Record<string, unknown>, options?: { frame?: FrameStep | Array<FrameStep>; }): Promise<unknown>;
|
|
75
75
|
};
|
|
76
76
|
expect(what: Expectation, opts?: { timeoutMs?: number; }): Promise<CheckResult>; // Assert what the page must show now (polled up to timeoutMs).
|
|
77
|
-
evaluate(script: string | ((arg: any) => any), opts?: { arg?: unknown; frame?:
|
|
77
|
+
evaluate(script: string | ((arg: any) => any), opts?: { arg?: unknown; frame?: FrameStep | Array<FrameStep>; timeoutMs?: number; }): Promise<unknown>; // Main World page code; functions receive only opts.arg, never host closures. Dispatched scripts are never replayed.
|
|
78
78
|
cdp: { // Native CDP on this Tab's shared debugger attachment. Parameters are not rewritten.
|
|
79
79
|
send(method: string, params?: Record<string, unknown>, target?: { frameId: string; }): Promise<unknown>;
|
|
80
80
|
watch(event: string, options?: StreamOptions): Promise<EventStream>;
|
|
@@ -98,7 +98,7 @@ class Tab {
|
|
|
98
98
|
cookie(name: string, opts?: { domain?: string; }): Promise<string | undefined>; // Read one cookie's value at run time — useful for per-request tokens an adapter needs (csrf/ct0/ csrftoken/XSRF-TOKEN). Defaults to the current page's host. Returns undefined when the cookie is absent.
|
|
99
99
|
fetchJson(url: string, opts?: Record<string, unknown>): Promise<unknown>; // Fetch JSON through the page (its cookies and origin) after verifying the endpoint.
|
|
100
100
|
frames(): Promise<Array<{ index: number; frameId: string; url: string; name: string; crossOrigin?: boolean; oopif?: boolean; }>>;
|
|
101
|
-
download(afterSequence: number, timeoutMs?: number): Promise<DownloadWaitResult>; // Wait for the page download begun after a tab.act cursor, then check Chrome's file state.
|
|
101
|
+
download(download: { tab: string; afterSequence: number; started: Array<{ seq: number; guid?: string; url: string; suggestedFilename: string; }>; }, timeoutMs?: number): Promise<DownloadWaitResult>; // Wait for the page download begun after a tab.act cursor, then check Chrome's file state.
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
type Target = ({ frame?: FrameStep | FrameStep[]; within?: string }) & (
|
|
@@ -123,7 +123,7 @@ interface ActionOutcome {
|
|
|
123
123
|
ref?: string; filled?: boolean; verified?: boolean; actual?: string;
|
|
124
124
|
checked?: boolean; changed?: boolean; selected?: string[]; files?: number;
|
|
125
125
|
openedTabs?: Array<{ tab?: string; tabId: number; url?: string; title?: string; pending?: true }>;
|
|
126
|
-
download?: { afterSequence: number; started: Array<{ seq: number; guid?: string; url: string; suggestedFilename: string }> }; method?: 'dom';
|
|
126
|
+
download?: { tab: string; afterSequence: number; started: Array<{ seq: number; guid?: string; url: string; suggestedFilename: string }> }; method?: 'dom';
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
interface ObserveOptions { cursor?: string;
|
|
@@ -156,9 +156,9 @@ interface ElementAtResult { matches_n: number; entries: FindEntry[] }
|
|
|
156
156
|
|
|
157
157
|
interface ReadTextResult { readId: string; text: string; complete: boolean; reason?: 'budget' | 'scan_limit' | 'unbounded' | 'stale'; chars: number; start: number; nextStart?: number }
|
|
158
158
|
|
|
159
|
-
interface Expectation { text?: string; notText?: string;
|
|
159
|
+
interface Expectation { target?: Target; text?: string; notText?: string; url?: string; title?: string; visible?: boolean; value?: string; checked?: boolean; selected?: string[]; enabled?: boolean }
|
|
160
160
|
|
|
161
|
-
interface CheckResult { ok: boolean; failed: string[]; url: string; title: string }
|
|
161
|
+
interface CheckResult { ok: boolean; failed: string[]; url: string; title: string; actual?: Record<string, unknown> }
|
|
162
162
|
|
|
163
163
|
interface DialogInfo { type: 'alert' | 'confirm' | 'prompt' | 'beforeunload'; message: string; defaultPrompt?: string; url?: string; openedAt: number }
|
|
164
164
|
|
|
@@ -190,6 +190,10 @@ interface DownloadWaitResult {
|
|
|
190
190
|
elapsedMs: number;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
interface PageTool { name: string; description?: string; inputSchema?: unknown }
|
|
194
|
+
|
|
195
|
+
interface PageToolsUpdate { status: 'ready' | 'unavailable'; frame: FrameStep[]; tools: Array<{ name: string; description?: string }>; truncated?: boolean }
|
|
196
|
+
|
|
193
197
|
interface EventStream { read(options?: StreamReadOptions): Promise<StreamBatch>; close(): Promise<void>;
|
|
194
198
|
}
|
|
195
199
|
|
|
@@ -197,15 +201,17 @@ interface ObservedContent { metadataTruncated?: boolean; stateContinued?: boolea
|
|
|
197
201
|
|
|
198
202
|
interface ObservedFrame extends ObservedContent { frame: FrameStep[]; owner: FrameOwner; unavailable?: string }
|
|
199
203
|
|
|
200
|
-
interface ObserveResult extends ObservedContent { complete?: boolean; nextCursor?: string;
|
|
204
|
+
interface ObserveResult extends ObservedContent { complete?: boolean; webmcp?: PageToolsUpdate; nextCursor?: string; next?: { cursor: string };
|
|
201
205
|
url: string | null; title: string | null; snapshotId?: string; image?: ImageValue; frames?: ObservedFrame[]; framesComplete?: boolean;
|
|
202
206
|
}
|
|
203
207
|
|
|
208
|
+
interface DocumentReadResult extends ReadTextResult { next?: ReadOptions }
|
|
209
|
+
|
|
204
210
|
interface ReadElementOptions { target: Target }
|
|
205
211
|
|
|
206
212
|
interface DomEntry { ref: string; tag: string; text: string; attrs: Record<string, string>; truncated: boolean }
|
|
207
213
|
|
|
208
|
-
interface DomSnapshot { entries: DomEntry[]; total: number; start: number; nextStart?: number; scope: 'viewport' | 'document' }
|
|
214
|
+
interface DomSnapshot { entries: DomEntry[]; total: number; start: number; nextStart?: number; scope: 'viewport' | 'document'; next?: { format: 'dom'; frame?: FrameStep[]; target?: Target; start: number; limit?: number; viewport: boolean; includeFrames: false } }
|
|
209
215
|
|
|
210
216
|
interface FrameOwner { ref: string; id: string; name: string; src: string }
|
|
211
217
|
|