@1outres/dsh-bot-connector-browser 0.0.0-stage → 0.3.1
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/LICENSE +21 -0
- package/README.md +53 -2
- package/cordis.patch.yml +6 -0
- package/icon.svg +9 -0
- package/lib/index.js +1762 -0
- package/locale/en.json +6 -0
- package/locale/ja.json +6 -0
- package/package.json +60 -3
- package/scripts/generate-tools.mjs +89 -0
- package/src/generated/playwright-mcp.json +1033 -0
- package/src/host/catalog.ts +104 -0
- package/src/host/connections.ts +21 -0
- package/src/host/connector.ts +48 -0
- package/src/host/mcp/client.ts +190 -0
- package/src/host/mcp/protocol.ts +104 -0
- package/src/host/mcp/server.ts +101 -0
- package/src/host/preparation.ts +120 -0
- package/src/host/result.ts +67 -0
- package/src/host/schema.ts +111 -0
- package/src/host/session.ts +41 -0
- package/src/host/tools.ts +89 -0
- package/src/host/vm/commands.ts +67 -0
- package/src/host/vm/layout.ts +22 -0
- package/src/index.ts +52 -0
- package/src/shared/connector.ts +4 -0
- package/vm/install-mcp.sh +17 -0
- package/vm/mcp/npm-shrinkwrap.json +56 -0
- package/vm/mcp/package.json +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 1outres
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @1outres/dsh-bot-connector-browser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A bot-core connector (`browser`) that lets each bot drive the **Google Chrome on its VM's desktop** with [Playwright MCP](https://github.com/microsoft/playwright-mcp) running inside the VM: page snapshots, clicks and forms, screenshots, tabs, network and console. A person sees the same Chrome in the bot's **Desktop** panel and can take it over. Row id `bot-connector-browser`. Host only; it needs `@1outres/dsh-bot-core`, a bot environment (`@1outres/dsh-bot-vm`) and the desktop connector (`@1outres/dsh-bot-connector-desktop`).
|
|
4
|
+
|
|
5
|
+
It is off for every bot until enabled (or the bot was created with **Turn on the desktop and browser**, `creationOption: "workstation"`). It `requires: ["desktop"]`: a bot turns it on only while the desktop is on, and the desktop off only after it (the settings say "Turn on Desktop first" / "Turn off Browser first"); bot-core keeps it `unavailable` while the desktop is off, missing or failed, `preparing` (stage `requirements`) while the desktop prepares, prepares it again whenever the desktop became ready again, and takes it out of ready (closing its server) whenever the desktop leaves ready. There is no headless browser and no other path.
|
|
6
|
+
|
|
7
|
+
## Who does what
|
|
8
|
+
|
|
9
|
+
| Part | Owner |
|
|
10
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------- |
|
|
11
|
+
| Google Chrome: Google's apt source and key, the `google-chrome-stable` package, the resident user service `dsh-desktop-chrome` (own profile `~/.local/share/dsh-desktop/chrome`, DevTools on `127.0.0.1:9222`, `--force-renderer-accessibility`), every way of launching it routed into it | desktop connector |
|
|
12
|
+
| Playwright MCP (pinned, `/opt/dsh-browser/mcp`), its tools, attaching it to that Chrome over DevTools | this connector |
|
|
13
|
+
|
|
14
|
+
Chrome is one per VM because a second Chrome on the same profile only hands its arguments to the first (`Opening in existing browser session`): whoever starts first decides whether DevTools is on. So the only owner is the desktop, which starts it as a user service with DevTools always on, and replaces `/usr/bin/google-chrome-stable` (`dpkg-divert`) with a script that starts that service and opens the arguments in it — the menu, `xdg-open`, `x-www-browser`, exo and `desktop_launch chrome` all end there. Chrome 136 and later refuse remote debugging on the default profile, hence the own profile. Closing Chrome's last window restarts it (`Restart=always`).
|
|
15
|
+
|
|
16
|
+
## What runs where
|
|
17
|
+
|
|
18
|
+
- **Host**: the connector definition, a JSON-RPC client of MCP, and the tools. It reaches the VM only through bot-core's environment (`exec`, `spawn`, `writeFile`, `sudo -n` to install); no Playwright and no browser on the Host.
|
|
19
|
+
- **VM**: Playwright MCP, started per bot by the connector's resident resource with `spawn` (`node /opt/dsh-browser/mcp/node_modules/@playwright/mcp/cli.js --caps vision,pdf --no-webmcp --cdp-endpoint http://127.0.0.1:9222 --codegen none --file-paths absolute --output-dir ~/.cache/dsh-browser/output --output-max-size 268435456`) and spoken to over its stdio. It runs as the bot's user in the workspace, so file uploads and saved files are the VM's. Chrome is the desktop's service, so tabs and cookies outlive the server: when the server ends (killed, the SSH channel dropped), bot-core opens a new one at the next call and that call's result starts with a note that earlier element refs are gone; the earlier call is not repeated.
|
|
20
|
+
|
|
21
|
+
Everything the server answers is untrusted (the bot is root in the VM): lines are bounded (48 MiB), every message is checked (`src/host/mcp/protocol.ts`), images must be PNG, JPEG or WebP in base64 under 16 MiB before `images.admit`.
|
|
22
|
+
|
|
23
|
+
## Preparation
|
|
24
|
+
|
|
25
|
+
One idempotent path (`src/host/preparation.ts`): read the account → compare `/opt/dsh-browser/mcp/npm-shrinkwrap.json` with `vm/mcp/npm-shrinkwrap.json` and, if it differs (a VM installed with an earlier `package-lock.json` has none), run `vm/install-mcp.sh` (`npm ci --omit=dev --ignore-scripts`, then swap the directory in) → ask `http://127.0.0.1:9222/json/version` and require `Chrome/<version>` → start the server and require its `tools/list` to equal the generated tools exactly (names, descriptions, schemas, annotations). There is nothing to stop when it is turned off: bot-core closes the server; Chrome stays the desktop's.
|
|
26
|
+
|
|
27
|
+
The bot base image runs the same `vm/install-mcp.sh` with the same shrinkwrap (`infra/vm/build-base-image.sh`), so a new VM installs nothing; `test/base-image.test.ts` checks that.
|
|
28
|
+
|
|
29
|
+
## Tools
|
|
30
|
+
|
|
31
|
+
Generated, not written: `scripts/generate-tools.mjs` lists the tools of the pinned `@playwright/mcp` (`vm/mcp/package.json`, the same version as the devDependency) with `--caps vision,pdf --no-webmcp` and writes `src/generated/playwright-mcp.json`; it also refreshes `vm/mcp/npm-shrinkwrap.json` (a shrinkwrap rather than a `package-lock.json`, which `pnpm pack` leaves out; `npm ci` installs from either). To move to another version: change both versions, `pnpm install`, `pnpm --filter @1outres/dsh-bot-connector-browser generate`, `pnpm test`.
|
|
32
|
+
|
|
33
|
+
From that file (`src/host/catalog.ts`, `src/host/tools.ts`):
|
|
34
|
+
|
|
35
|
+
- every tool `browser_<x>` becomes the connector's `<x>` (bot-core names it `browser_<x>` again), with the upstream description;
|
|
36
|
+
- `browser_close` and `browser_install` are not offered (closing would close the person's Chrome; Chrome is the desktop's); `browser_run_code_unsafe` is **disallow** (arbitrary code in the server's process); all others **allow**;
|
|
37
|
+
- `readOnly` is the upstream `readOnlyHint` (snapshot, find, take_screenshot, console_messages, network_requests, network_request, pdf_save, wait_for): only those run while a person operates the desktop; every other tool fails with `USER_IN_CONTROL` (bot-core checks it from the desktop's status `operatedBy`);
|
|
38
|
+
- the schema is the upstream JSON Schema converted to DSH's subset (`src/host/schema.ts`: `$schema` and `propertyNames: string` dropped, `anyOf` with branches of different types as `oneOf`, `minimum`/`maximum` and typed `additionalProperties` moved into the description; an unknown keyword fails the build's tests). It only loosens: the server checks every call against its own schema;
|
|
39
|
+
- `maxResultChars` 128 000 (snapshots), `exclusive: "page"` (the server does not queue calls; one call per bot at a time), a call times out after 180 s.
|
|
40
|
+
|
|
41
|
+
| Tool | Default |
|
|
42
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
|
|
43
|
+
| browser_navigate / navigate_back / wait_for / snapshot / find / take_screenshot / console_messages / network_requests / network_request | allow |
|
|
44
|
+
| browser_click / type / fill_form / press_key / select_option / hover / drag / handle_dialog / file_upload / drop / tabs / resize / emulate_media / evaluate / pdf_save / mouse_move_xy / mouse_click_xy / mouse_drag_xy / mouse_down / mouse_up / mouse_wheel | allow |
|
|
45
|
+
| browser_run_code_unsafe | disallow |
|
|
46
|
+
| browser_close / browser_install | not offered |
|
|
47
|
+
|
|
48
|
+
Action results carry the page's snapshot as a file link (`~/.cache/dsh-browser/output/page-….yml`, readable with the bot's file tools); `browser_snapshot` returns it inline. Screenshots are images for the calling model; an approved action (a tool someone set to ask) has no caller, so its images are left out and the text says so.
|
|
49
|
+
|
|
50
|
+
Do not sign the bot's Chrome in to anyone's personal accounts: it would hand the account to the bot without any approval.
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
Tests run without a VM (`pnpm test`): a fake MCP server answers from the generated file.
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Installs this plugin on its own (dsh plugin add @1outres/dsh-bot-connector-browser).
|
|
2
|
+
# The @1outres/dsh-bots bundle inserts the same "bot-connector-browser" row, so select
|
|
3
|
+
# one bundle or the other, never both.
|
|
4
|
+
- insert:
|
|
5
|
+
- id: bot-connector-browser
|
|
6
|
+
name: "@1outres/dsh-bot-connector-browser"
|
package/icon.svg
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" fill="none" role="img" aria-labelledby="title">
|
|
2
|
+
<title id="title">Bot browser connector</title>
|
|
3
|
+
<rect x="2" y="2" width="60" height="60" rx="14" fill="#BE185D"/>
|
|
4
|
+
<rect x="12" y="15" width="40" height="32" rx="4" fill="#FFFFFF"/>
|
|
5
|
+
<path d="M12 23h40" stroke="#BE185D" stroke-width="2.5"/>
|
|
6
|
+
<circle cx="17" cy="19" r="1.6" fill="#BE185D"/>
|
|
7
|
+
<circle cx="22" cy="19" r="1.6" fill="#BE185D"/>
|
|
8
|
+
<path d="M30 30l9 4-4 1.5L33.5 40z" fill="#BE185D"/>
|
|
9
|
+
</svg>
|