projectionlab-mcp 1.1.0 → 1.2.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/HOW-IT-WORKS.md +2 -2
- package/MANUAL-SETUP.md +19 -13
- package/README.md +3 -2
- package/REFERENCE.md +11 -2
- package/SETUP-FOR-AGENTS.md +7 -4
- package/dist/bootstrap.js +5 -3
- package/dist/bootstrap.js.map +1 -1
- package/dist/bridge.d.ts +2 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +41 -6
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -1
- package/dist/extensionBridge.d.ts +14 -1
- package/dist/extensionBridge.js +86 -26
- package/dist/extensionBridge.js.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/instructions.d.ts +1 -1
- package/dist/instructions.js +1 -1
- package/dist/largeOutput.js +25 -0
- package/dist/largeOutput.js.map +1 -1
- package/dist/logger.js +11 -4
- package/dist/logger.js.map +1 -1
- package/dist/pathPatch.js +5 -0
- package/dist/pathPatch.js.map +1 -1
- package/dist/plans.d.ts +45 -10
- package/dist/plans.js +139 -42
- package/dist/plans.js.map +1 -1
- package/dist/redact.d.ts +24 -0
- package/dist/redact.js +91 -0
- package/dist/redact.js.map +1 -1
- package/dist/resources/planData.js +3 -1
- package/dist/resources/planData.js.map +1 -1
- package/dist/resources/summary.js +4 -1
- package/dist/resources/summary.js.map +1 -1
- package/dist/snapshot.js +18 -11
- package/dist/snapshot.js.map +1 -1
- package/dist/tools/clonePlan.js +3 -3
- package/dist/tools/clonePlan.js.map +1 -1
- package/dist/tools/connection.js +21 -3
- package/dist/tools/connection.js.map +1 -1
- package/dist/tools/diff.js +7 -7
- package/dist/tools/diff.js.map +1 -1
- package/dist/tools/getPlan.js +4 -4
- package/dist/tools/getPlan.js.map +1 -1
- package/dist/tools/getPlanSection.js +5 -5
- package/dist/tools/getPlanSection.js.map +1 -1
- package/dist/tools/getPlanSettings.js +3 -3
- package/dist/tools/getPlanSettings.js.map +1 -1
- package/dist/tools/restore.js +18 -1
- package/dist/tools/restore.js.map +1 -1
- package/dist/tools/snapshots.js +17 -1
- package/dist/tools/snapshots.js.map +1 -1
- package/dist/tools/updatePlanEvent.js +63 -37
- package/dist/tools/updatePlanEvent.js.map +1 -1
- package/dist/tools/updatePlanSection.js +11 -6
- package/dist/tools/updatePlanSection.js.map +1 -1
- package/dist/tools/updatePlanSettings.js +3 -3
- package/dist/tools/updatePlanSettings.js.map +1 -1
- package/dist/types/wire.d.ts +38 -2
- package/dist/types/wire.js +12 -2
- package/dist/types/wire.js.map +1 -1
- package/dist/updateCheck.d.ts +22 -0
- package/dist/updateCheck.js +58 -0
- package/dist/updateCheck.js.map +1 -0
- package/dist/versionCompare.d.ts +5 -0
- package/dist/versionCompare.js +33 -0
- package/dist/versionCompare.js.map +1 -0
- package/dist/versionNotices.d.ts +9 -0
- package/dist/versionNotices.js +46 -0
- package/dist/versionNotices.js.map +1 -0
- package/package.json +1 -1
- package/skills/projectionlab/SKILL.md +71 -28
package/HOW-IT-WORKS.md
CHANGED
|
@@ -18,13 +18,13 @@ The server opens a WebSocket listener on `127.0.0.1:<PL_WS_PORT>`. A browser-sid
|
|
|
18
18
|
|
|
19
19
|
`src/types/wire.ts` is the contract shared by the server and every executor:
|
|
20
20
|
|
|
21
|
-
- The executor connects and sends a `hello` frame with a shared token
|
|
21
|
+
- The executor connects and sends a `hello` frame with a shared token, the protocol version, and an `instanceId` (a stable id for the installation: the extension persists one UUID, the snippet generates one per page load). The server validates the `Origin` header (extension or app origin only), checks the token, and replies `helloAck`, or closes with code `4001` (auth), `4002` (version), `4003` (a takeover replaced this executor), or `4004` (busy: another executor holds the connection, retry later). The server keeps one active executor and the incumbent keeps it: a second authenticated executor is refused with `4004`, retries on a slow schedule, and connects by itself when the active one goes away. It takes over only by sending `takeover: true` in the hello (the extension does that when the user presses Save on its options page) or by repeating the incumbent's `instanceId`, which lets an executor replace its own stale socket. The `helloAck` carries the server's release version in `serverVersion` so the extension can show a mismatch line; executors that ignore the field are unaffected, and servers older than the field simply omit it.
|
|
22
22
|
- Requests are `{ id, method, params }`; responses are `{ id, ok, result | error }`. Methods map directly to Plugin API calls plus `describeApi`/`waitForApi`.
|
|
23
23
|
- A ~20 s `ping`/`pong` heartbeat keeps the connection healthy (and keeps a Manifest V3 service worker from being suspended).
|
|
24
24
|
|
|
25
25
|
### The browser extension
|
|
26
26
|
|
|
27
|
-
Manifest V3, in `extension/`. A background service worker owns the WebSocket, reconnects with exponential backoff, and uses an `alarms` wake after suspension. For each request it locates a ProjectionLab tab (opening one in the background when configured to do so) and uses `scripting.executeScript` to run the operation directly in the page's **MAIN world**, where `window.projectionlabPluginAPI` is visible. The structured result returns through the scripting API without a content-script relay. Chrome/Edge/Brave use the service-worker manifest; Firefox 140 or newer uses an event-page manifest with MAIN-world scripting support.
|
|
27
|
+
Manifest V3, in `extension/`. A background service worker owns the WebSocket, reconnects with exponential backoff, and uses an `alarms` wake after suspension. An authentication refusal (bad token or protocol mismatch) blocks reconnecting; the block is stored in `storage.session` so the alarm-driven worker restarts honor it, and saving the options page clears it (Save also asks the server for a takeover, making this browser the active one even when no field was edited). A takeover (4003) or a busy refusal (4004) does not block: the extension shows "Standing by", retries at least 30 seconds apart, and connects on its own once the active browser disconnects. For each request it locates a ProjectionLab tab (opening one in the background when configured to do so) and uses `scripting.executeScript` to run the operation directly in the page's **MAIN world**, where `window.projectionlabPluginAPI` is visible. The structured result returns through the scripting API without a content-script relay. Chrome/Edge/Brave use the service-worker manifest; Firefox 140 or newer uses an event-page manifest with MAIN-world scripting support.
|
|
28
28
|
|
|
29
29
|
### The bootstrap snippet
|
|
30
30
|
|
package/MANUAL-SETUP.md
CHANGED
|
@@ -5,7 +5,8 @@ assistant and it does these steps with you. Follow this page to set things up
|
|
|
5
5
|
yourself instead.
|
|
6
6
|
|
|
7
7
|
You need **Node.js 20 or newer** ([nodejs.org](https://nodejs.org)) and
|
|
8
|
-
Chrome
|
|
8
|
+
Chrome or Firefox 140 or newer; both are tested with this server. Edge and
|
|
9
|
+
Brave run the same builds as Chrome and Firefox and are unverified.
|
|
9
10
|
|
|
10
11
|
**1. Turn on plugins and copy your API key.** In
|
|
11
12
|
[ProjectionLab](https://app.projectionlab.com), open **Account Settings →
|
|
@@ -39,20 +40,25 @@ For Claude Code and other assistants, see
|
|
|
39
40
|
**4. Restart your assistant.** It starts the server, which creates the browser
|
|
40
41
|
connection token on first start at `~/.projectionlab-mcp/ws-token`.
|
|
41
42
|
|
|
42
|
-
**5. Install the browser extension.**
|
|
43
|
-
the
|
|
44
|
-
|
|
43
|
+
**5. Install the browser extension.** Add **MCP Bridge for ProjectionLab**
|
|
44
|
+
from your browser's store. There is nothing to download, and the store keeps
|
|
45
|
+
the extension up to date.
|
|
45
46
|
|
|
46
|
-
- **Chrome, Edge, or Brave:** open
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
- **Chrome, Edge, or Brave:** open the
|
|
48
|
+
[Chrome Web Store listing](https://chromewebstore.google.com/detail/mcp-bridge-for-projection/njgjmcihabchffonldcgfjiocjalpoaf)
|
|
49
|
+
and choose **Add to Chrome**. Edge asks once whether to allow extensions
|
|
50
|
+
from other stores.
|
|
51
|
+
- **Firefox:** open the
|
|
52
|
+
[Firefox Add-ons listing](https://addons.mozilla.org/en-US/firefox/addon/mcp-bridge-for-projectionlab/)
|
|
53
|
+
and choose **Install Add-on**.
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
> **Upgrading from an unpacked zip?** Remove the unpacked extension from
|
|
56
|
+
> your browser's extensions page (`chrome://extensions` or `about:addons`)
|
|
57
|
+
> before adding the store version. Browsers isolate extension settings by
|
|
58
|
+
> extension ID, so enter the port and token into the new extension's options page.
|
|
59
|
+
|
|
60
|
+
Then click the extension's toolbar icon to open its options page and enter
|
|
61
|
+
port `8788` and the token from `~/.projectionlab-mcp/ws-token`.
|
|
56
62
|
|
|
57
63
|
**6. Check the connection.** Open ProjectionLab in that browser and log in.
|
|
58
64
|
Then ask your assistant to run `projectionlab_check_connection`. When every
|
package/README.md
CHANGED
|
@@ -26,10 +26,10 @@ Paste this into your AI assistant:
|
|
|
26
26
|
> package) for me. Follow the setup instructions at
|
|
27
27
|
> `https://github.com/Backroads4Me/projectionlab-mcp/blob/main/SETUP-FOR-AGENTS.md`.
|
|
28
28
|
> I'm not technical, so walk me through anything you need from me (like my
|
|
29
|
-
> ProjectionLab Plugin API key and
|
|
29
|
+
> ProjectionLab Plugin API key and installing the browser extension) one step at
|
|
30
30
|
> a time. Keep it in read-only mode until I say otherwise.
|
|
31
31
|
|
|
32
|
-
Your assistant installs the server, asks for your ProjectionLab Plugin API key, and walks you through a couple of short steps in your browser:
|
|
32
|
+
Your assistant installs the server, asks for your ProjectionLab Plugin API key, and walks you through a couple of short steps in your browser: adding a small helper extension from your browser's extension store and entering a connection code in its settings. When it's done, start asking questions about your plan.
|
|
33
33
|
|
|
34
34
|
If anything gets stuck, tell your assistant what you see on screen; it can troubleshoot from there.
|
|
35
35
|
|
|
@@ -44,6 +44,7 @@ Prefer to set it up yourself? See **[Manual setup](https://github.com/Backroads4
|
|
|
44
44
|
- **Undo.** Every confirmed change is backed up first, so it can be rolled back.
|
|
45
45
|
- **No overwriting your edits.** If a plan was saved in ProjectionLab after the assistant read it, the change is refused rather than overwriting your edit.
|
|
46
46
|
- **Stays on your computer.** Your API key and the connection token are stored only on your computer, and the browser connects only to the server running there.
|
|
47
|
+
- **Update-aware.** Your assistant mentions it once when a newer release is available; the server reads the latest release number from npm once per start (`PL_UPDATE_CHECK=false` turns that off).
|
|
47
48
|
|
|
48
49
|
Details are in the [safety model](https://github.com/Backroads4Me/projectionlab-mcp/blob/main/REFERENCE.md#safety-model) and [Privacy](https://github.com/Backroads4Me/projectionlab-mcp/blob/main/PRIVACY.md).
|
|
49
50
|
|
package/REFERENCE.md
CHANGED
|
@@ -89,13 +89,14 @@ The server starts without `PL_API_KEY` so it can tell the agent what is missing;
|
|
|
89
89
|
| `PL_PRETTY_JSON` | No | `false` | Pretty-print JSON output (uses ~25–40% more tokens) |
|
|
90
90
|
| `PL_READ_ONLY` | No | `true` | Write/mutation tools are disabled unless this is exactly `false` |
|
|
91
91
|
| `PL_SNAPSHOT_DIR` | No | `~/.projectionlab-mcp/snapshots` | Directory for pre-mutation snapshots |
|
|
92
|
+
| `PL_UPDATE_CHECK` | No | `true` | One request to `registry.npmjs.org` per start to read the latest release number; off only when this is exactly `false` |
|
|
92
93
|
| `LOG_LEVEL` | No | `info` | Log verbosity (`debug`, `info`, `warn`, `error`) |
|
|
93
94
|
|
|
94
95
|
## Available tools
|
|
95
96
|
|
|
96
97
|
| Tool | Description | Mutates |
|
|
97
98
|
|---|---|---|
|
|
98
|
-
| `projectionlab_check_connection` | Verify browser + API connectivity | No |
|
|
99
|
+
| `projectionlab_check_connection` | Verify browser + API connectivity; the result also carries `versions` (server, executor, latest npm release) and `notices` (plain-language update messages) | No |
|
|
99
100
|
| `projectionlab_get_bootstrap` | Return a console snippet to connect a ProjectionLab tab | No |
|
|
100
101
|
| `projectionlab_describe_plugin_api` | Describe the available Plugin API surface | No |
|
|
101
102
|
| `projectionlab_describe_schema` | Describe the data schema (plan names, account IDs) | No |
|
|
@@ -144,6 +145,10 @@ Write operations (`update_*`, `restore_*`, `clone_plan`, `delete_plan`) default
|
|
|
144
145
|
|
|
145
146
|
Every write that replaces the plans array re-reads the plans just before writing and refuses with `PLAN_CONFLICT` if any plan was added, removed, or saved in ProjectionLab since the tool read them, so an edit made in the ProjectionLab UI is never silently overwritten. `projectionlab_update_plan_section` also returns a `planVersion` in its dry run; pass it back as `expectedPlanVersion` when confirming to refuse the write if the plan was saved after the preview.
|
|
146
147
|
|
|
148
|
+
Plan reads hide secret values: a secret-named field (`apiKey`, `token`, `password`, …) comes back as `[REDACTED]`. A payload for `projectionlab_update_plan_section` or any `restore_*` tool that still holds that sentinel under a secret-named key is refused with `INVALID_INPUT`, dry runs included, naming the offending dot paths. Supply the real value, or change single fields with `projectionlab_update_plan_event` or `projectionlab_update_plan_settings`, which patch by path and never round-trip hidden values.
|
|
149
|
+
|
|
150
|
+
`projectionlab_update_plan_section` also refuses `sectionData` that does not match the section's current container shape (array for milestones, `{ events: [...] }` for event sections, plain object for `variables`, `montecarlo` and `withdrawalStrategy`), so a wrong or omitted payload can never delete a section or change its type.
|
|
151
|
+
|
|
147
152
|
For a small assumptions or strategy change, first call
|
|
148
153
|
`projectionlab_get_plan_settings` with the plan name. It returns the current
|
|
149
154
|
`variables`, `montecarlo`, and `withdrawalStrategy` values as dot paths with
|
|
@@ -171,7 +176,11 @@ Event forms use the same path workflow. Fetch one event with
|
|
|
171
176
|
`projectionlab_get_plan_section` using its `eventIdentifier` and
|
|
172
177
|
`"listPaths": true`, then pass selected paths to
|
|
173
178
|
`projectionlab_update_plan_event` as `pathChanges`. The older `patch` input
|
|
174
|
-
remains available for shallow top-level changes
|
|
179
|
+
remains available for shallow top-level changes: existing fields are
|
|
180
|
+
validated like `pathChanges` (same JSON type, secret-named fields refused)
|
|
181
|
+
and new fields must be plain, non-secret names. Both inputs report each
|
|
182
|
+
dry-run change as `{ "before": ..., "after": ... }`; a field the patch adds
|
|
183
|
+
reports `"before": "[ABSENT]"`.
|
|
175
184
|
|
|
176
185
|
Current Finances accounts also support targeted discovery and nested patches.
|
|
177
186
|
Call `projectionlab_get_current_finances` with an exact `accountId` and
|
package/SETUP-FOR-AGENTS.md
CHANGED
|
@@ -25,10 +25,13 @@ The config location varies by host; see [Adding the server to your MCP host](htt
|
|
|
25
25
|
|
|
26
26
|
**4. Connect the browser.** The server reaches ProjectionLab through the user's own browser. Pick the path that fits:
|
|
27
27
|
|
|
28
|
-
- **Recommended: the browser extension** (persists across restarts
|
|
29
|
-
- **Chrome / Edge / Brave:**
|
|
30
|
-
- **Firefox (140+):**
|
|
31
|
-
Then have them open the extension's **options page** and enter the WebSocket **port** (default `8788`) and the **shared token** from `~/.projectionlab-mcp/ws-token`.
|
|
28
|
+
- **Recommended: the browser extension** (persists across restarts, and the store keeps it updated). Have the user add **MCP Bridge for ProjectionLab** from their browser's store. Opening the page is yours to do; clicking the install button is theirs:
|
|
29
|
+
- **Chrome / Edge / Brave:** the [Chrome Web Store listing](https://chromewebstore.google.com/detail/mcp-bridge-for-projection/njgjmcihabchffonldcgfjiocjalpoaf) → **Add to Chrome**. Edge asks once whether to allow extensions from other stores.
|
|
30
|
+
- **Firefox (140+):** the [Firefox Add-ons listing](https://addons.mozilla.org/en-US/firefox/addon/mcp-bridge-for-projectionlab/) → **Install Add-on**.
|
|
31
|
+
Then have them open the extension's **options page** (click its toolbar icon) and enter the WebSocket **port** (default `8788`) and the **shared token** from `~/.projectionlab-mcp/ws-token`.
|
|
32
|
+
Chrome and Firefox are tested with this server; Edge and Brave run the same
|
|
33
|
+
builds and are unverified, so steer the user to Chrome or Firefox when they
|
|
34
|
+
have a choice, and treat a Brave or Edge report as unverified until reproduced.
|
|
32
35
|
|
|
33
36
|
- **Quick alternative: no install.** Call the `projectionlab_get_bootstrap` tool, then have the user paste the returned snippet into their ProjectionLab tab's developer console (F12 → Console). It works the same way but must be re-pasted if they reload the page. Good for a first test drive.
|
|
34
37
|
|
package/dist/bootstrap.js
CHANGED
|
@@ -32,6 +32,7 @@ export function buildBootstrapSnippet(port, token) {
|
|
|
32
32
|
if (window.__plmcpBootstrap) { console.log("[plmcp] bootstrap already running"); return; }
|
|
33
33
|
window.__plmcpBootstrap = true;
|
|
34
34
|
let stopped = false;
|
|
35
|
+
const instanceId = crypto.randomUUID();
|
|
35
36
|
const log = (m) => console.log("[plmcp]", m);
|
|
36
37
|
function waitForApi(timeoutMs) {
|
|
37
38
|
return new Promise((resolve, reject) => {
|
|
@@ -75,14 +76,14 @@ export function buildBootstrapSnippet(port, token) {
|
|
|
75
76
|
} catch (err) {
|
|
76
77
|
const msg = err && err.message ? err.message : String(err);
|
|
77
78
|
const code = err && err.code === "API_NOT_AVAILABLE" ? "API_NOT_AVAILABLE"
|
|
78
|
-
: /api.?key|invalid key|unauthori[sz]ed|forbidden
|
|
79
|
+
: /api.?key|invalid key|unauthori[sz]ed|forbidden|\\b401\\b|\\b403\\b/i.test(msg) ? "API_KEY_INVALID" : "UNKNOWN";
|
|
79
80
|
ws.send(JSON.stringify({ type: "response", id: frame.id, ok: false, error: { code, message: msg } }));
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
function connect() {
|
|
83
84
|
if (stopped) return;
|
|
84
85
|
const ws = new WebSocket("ws://127.0.0.1:" + cfg.port);
|
|
85
|
-
ws.onopen = () => ws.send(JSON.stringify({ type: "hello", token: cfg.token, protocolVersion: cfg.protocolVersion, executor: cfg.executor }));
|
|
86
|
+
ws.onopen = () => ws.send(JSON.stringify({ type: "hello", token: cfg.token, protocolVersion: cfg.protocolVersion, executor: cfg.executor, instanceId }));
|
|
86
87
|
ws.onmessage = (ev) => {
|
|
87
88
|
let frame;
|
|
88
89
|
try { frame = JSON.parse(ev.data); } catch { return; }
|
|
@@ -93,7 +94,8 @@ export function buildBootstrapSnippet(port, token) {
|
|
|
93
94
|
ws.onclose = (ev) => {
|
|
94
95
|
if (stopped) return;
|
|
95
96
|
if (ev.code === 4001 || ev.code === 4002) { stopped = true; window.__plmcpBootstrap = false; log("stopped: " + (ev.reason || ev.code)); return; }
|
|
96
|
-
if (ev.code ===
|
|
97
|
+
if (ev.code === 4004) { log("another executor is connected; this tab will connect if that one goes away (retrying in 30s)"); setTimeout(connect, 30000); return; }
|
|
98
|
+
if (ev.code === 4003) { log("another executor took over the connection (retrying in 30s)"); setTimeout(connect, 30000); return; }
|
|
97
99
|
log("disconnected; retrying in 3s");
|
|
98
100
|
setTimeout(connect, 3000);
|
|
99
101
|
};
|
package/dist/bootstrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAmB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;uEACuE;AACvE,MAAM,cAAc,GAAiE;IACnF,YAAY;IACZ,eAAe;IACf,wBAAwB;IACxB,cAAc;IACd,iBAAiB;IACjB,iBAAiB;IACjB,gBAAgB;CACjB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,KAAa;IAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QACzB,IAAI;QACJ,KAAK;QACL,eAAe,EAAE,gBAAgB;QACjC,QAAQ,EAAE,aAAa,OAAO,EAAE;KACjC,CAAC,CAAC;IACH,OAAO;gBACO,GAAG;2BACQ,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAmB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;uEACuE;AACvE,MAAM,cAAc,GAAiE;IACnF,YAAY;IACZ,eAAe;IACf,wBAAwB;IACxB,cAAc;IACd,iBAAiB;IACjB,iBAAiB;IACjB,gBAAgB;CACjB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,KAAa;IAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QACzB,IAAI;QACJ,KAAK;QACL,eAAe,EAAE,gBAAgB;QACjC,QAAQ,EAAE,aAAa,OAAO,EAAE;KACjC,CAAC,CAAC;IACH,OAAO;gBACO,GAAG;2BACQ,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA0EnD,CAAC;AACP,CAAC"}
|
package/dist/bridge.d.ts
CHANGED
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Per-user config file shared by every MCP host on the machine. */
|
|
2
2
|
export declare const USER_ENV_FILE: string;
|
|
3
|
+
declare const LOG_LEVELS: readonly ["error", "warn", "info", "debug"];
|
|
4
|
+
export type LogLevel = (typeof LOG_LEVELS)[number];
|
|
3
5
|
export declare const config: {
|
|
4
6
|
readonly apiKey: string | undefined;
|
|
5
7
|
readonly wsPort: number;
|
|
@@ -9,7 +11,9 @@ export declare const config: {
|
|
|
9
11
|
readonly exportCacheMs: number;
|
|
10
12
|
readonly prettyJson: boolean;
|
|
11
13
|
readonly readOnly: boolean;
|
|
14
|
+
readonly updateCheck: boolean;
|
|
12
15
|
readonly snapshotDir: string;
|
|
13
16
|
readonly logLevel: "error" | "warn" | "info" | "debug";
|
|
14
17
|
};
|
|
15
18
|
export type Config = typeof config;
|
|
19
|
+
export {};
|
package/dist/config.js
CHANGED
|
@@ -23,6 +23,36 @@ function optionalInt(name, fallback) {
|
|
|
23
23
|
}
|
|
24
24
|
return value;
|
|
25
25
|
}
|
|
26
|
+
/** A listen port: all digits, 1 to 65535. parseInt alone would accept
|
|
27
|
+
* "8788abc" and bind whatever number it reads out of it. */
|
|
28
|
+
function portFromEnv(name, fallback) {
|
|
29
|
+
const raw = process.env[name];
|
|
30
|
+
if (!raw)
|
|
31
|
+
return fallback;
|
|
32
|
+
const value = /^\d+$/.test(raw.trim()) ? Number(raw.trim()) : NaN;
|
|
33
|
+
if (!Number.isInteger(value) || value < 1 || value > 65535) {
|
|
34
|
+
throw new Error(`Invalid value for ${name}: "${raw}" (expected a port number from 1 to 65535)`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
const LOG_LEVELS = ["error", "warn", "info", "debug"];
|
|
39
|
+
/** The configured log level; anything else falls back to info. */
|
|
40
|
+
function logLevel() {
|
|
41
|
+
const raw = process.env.LOG_LEVEL;
|
|
42
|
+
return LOG_LEVELS.includes(raw) ? raw : "info";
|
|
43
|
+
}
|
|
44
|
+
/** The app origin the browser executors come from; it must parse as a URL
|
|
45
|
+
* because the connection handler derives the allowed origin from it. */
|
|
46
|
+
function appUrl() {
|
|
47
|
+
const raw = optional("PL_APP_URL", "https://app.projectionlab.com");
|
|
48
|
+
try {
|
|
49
|
+
new URL(raw);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new Error(`Invalid value for PL_APP_URL: "${raw}" (expected an absolute URL)`);
|
|
53
|
+
}
|
|
54
|
+
return raw;
|
|
55
|
+
}
|
|
26
56
|
function optionalBoolean(name) {
|
|
27
57
|
const value = process.env[name];
|
|
28
58
|
if (value === undefined)
|
|
@@ -41,11 +71,13 @@ export const config = {
|
|
|
41
71
|
// what is missing; operations that need the key reject without it.
|
|
42
72
|
apiKey: process.env.PL_API_KEY || undefined,
|
|
43
73
|
// Localhost WebSocket the browser extension (or bootstrap snippet) connects
|
|
44
|
-
// to. The token is a shared secret the executor must present; if unset
|
|
45
|
-
// ExtensionBridge generates one and persists it
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
74
|
+
// to. The token is a shared secret the executor must present; if unset or
|
|
75
|
+
// blank, ExtensionBridge generates one and persists it next to
|
|
76
|
+
// USER_ENV_FILE. A blank value never counts as a token: it would let any
|
|
77
|
+
// client authenticate with an empty string.
|
|
78
|
+
wsPort: portFromEnv("PL_WS_PORT", 8788),
|
|
79
|
+
wsToken: process.env.PL_WS_TOKEN?.trim() || undefined,
|
|
80
|
+
appUrl: appUrl(),
|
|
49
81
|
apiReadyTimeoutMs: optionalInt("PL_API_READY_TIMEOUT_MS", 30000),
|
|
50
82
|
// How long a full export may be served from cache. Writes always invalidate,
|
|
51
83
|
// so this can be generous for read-heavy analysis sessions.
|
|
@@ -54,7 +86,10 @@ export const config = {
|
|
|
54
86
|
prettyJson: optionalBoolean("PL_PRETTY_JSON") ?? false,
|
|
55
87
|
// Writes stay disabled unless PL_READ_ONLY is exactly "false".
|
|
56
88
|
readOnly: (process.env.PL_READ_ONLY ?? "").trim().toLowerCase() !== "false",
|
|
89
|
+
// On unless PL_UPDATE_CHECK is exactly "false"; the only registry request
|
|
90
|
+
// the server makes is the one this gates.
|
|
91
|
+
updateCheck: (process.env.PL_UPDATE_CHECK ?? "").trim().toLowerCase() !== "false",
|
|
57
92
|
snapshotDir: expandHome(optional("PL_SNAPSHOT_DIR", "~/.projectionlab-mcp/snapshots")),
|
|
58
|
-
logLevel:
|
|
93
|
+
logLevel: logLevel(),
|
|
59
94
|
};
|
|
60
95
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,oEAAoE;AACpE,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,oBAAoB,EAAE,MAAM,CAAC,CAAC;AAE3E,yEAAyE;AACzE,oEAAoE;AACpE,yEAAyE;AACzE,UAAU,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;AACpC,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,EAA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WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,OAAO;IACjF,WAAW,EAAE,UAAU,CAAC,QAAQ,CAAC,iBAAiB,EAAE,gCAAgC,CAAC,CAAC;IACtF,QAAQ,EAAE,QAAQ,EAAE;CACZ,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export declare class ProjectionLabError extends Error {
|
|
|
11
11
|
toResult(): PlError;
|
|
12
12
|
}
|
|
13
13
|
export declare function toPlError(err: unknown): PlError;
|
|
14
|
+
/**
|
|
15
|
+
* A whole-section or restore payload that still holds `[REDACTED]` under a
|
|
16
|
+
* secret-named key came from a redacted read; writing it back would store the
|
|
17
|
+
* sentinel in the user's data. Names the offending dot paths.
|
|
18
|
+
*/
|
|
19
|
+
export declare function redactedSecretsError(payloadName: string, paths: string[]): ProjectionLabError;
|
|
14
20
|
export declare function errorResult(err: unknown): {
|
|
15
21
|
content: {
|
|
16
22
|
type: "text";
|
package/dist/errors.js
CHANGED
|
@@ -27,6 +27,16 @@ export function toPlError(err) {
|
|
|
27
27
|
suggestion: "Check server logs for details",
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* A whole-section or restore payload that still holds `[REDACTED]` under a
|
|
32
|
+
* secret-named key came from a redacted read; writing it back would store the
|
|
33
|
+
* sentinel in the user's data. Names the offending dot paths.
|
|
34
|
+
*/
|
|
35
|
+
export function redactedSecretsError(payloadName, paths) {
|
|
36
|
+
return new ProjectionLabError("INVALID_INPUT", `${payloadName} contains redacted secret values at: ${paths.join(", ")}`, "These values were hidden by the read that produced this payload, so it cannot be written back. " +
|
|
37
|
+
"Supply the real values, or change single fields with projectionlab_update_plan_event or " +
|
|
38
|
+
"projectionlab_update_plan_settings, which patch by path and never round-trip hidden values.");
|
|
39
|
+
}
|
|
30
40
|
export function errorResult(err) {
|
|
31
41
|
// An error message can echo request data from the browser executor, so the
|
|
32
42
|
// Plugin API key is scrubbed from it like any other tool output.
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAsB5C,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAEzB;IAEA;IAHlB,YACkB,IAAe,EAC/B,OAAe,EACC,UAAkB;QAElC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAW;QAEf,eAAU,GAAV,UAAU,CAAQ;QAGlC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;IAED,QAAQ;QACN,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,IAAI;YAChB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,SAAS,CAAC,GAAY;IACpC,IAAI,GAAG,YAAY,kBAAkB,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO;QACL,KAAK,EAAE,SAAS;QAChB,OAAO;QACP,UAAU,EAAE,+BAA+B;KAC5C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,2EAA2E;IAC3E,iEAAiE;IACjE,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,C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AW,CAAC,GAAY;IACtC,2EAA2E;IAC3E,iEAAiE;IACjE,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACjE,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -4,6 +4,7 @@ export declare class ExtensionBridge implements Bridge {
|
|
|
4
4
|
private wss;
|
|
5
5
|
private conn;
|
|
6
6
|
private connExecutor;
|
|
7
|
+
private connInstanceId;
|
|
7
8
|
private readonly pending;
|
|
8
9
|
private nextId;
|
|
9
10
|
private heartbeat;
|
|
@@ -25,12 +26,24 @@ export declare class ExtensionBridge implements Bridge {
|
|
|
25
26
|
/** New sockets must send a valid hello before anything else. `helloRead`
|
|
26
27
|
* runs once the first message arrives, whatever it holds. */
|
|
27
28
|
private awaitHello;
|
|
28
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Decide whether an authenticated hello becomes the active executor. The
|
|
31
|
+
* incumbent keeps the connection: a newcomer is refused with BUSY unless it
|
|
32
|
+
* requests takeover, or repeats the incumbent's instance id (an executor
|
|
33
|
+
* must never be locked out by its own stale socket). An incumbent whose
|
|
34
|
+
* socket is not open is dead and gets dropped first; the heartbeat is what
|
|
35
|
+
* clears a crashed incumbent that still looks open.
|
|
36
|
+
*/
|
|
37
|
+
private admit;
|
|
38
|
+
/** Promote an authenticated socket to the active connection. Replacing a
|
|
39
|
+
* live incumbent (takeover or same instance id) closes it with 4003. */
|
|
29
40
|
private adopt;
|
|
30
41
|
private onFrame;
|
|
31
42
|
private settle;
|
|
32
43
|
private wireError;
|
|
33
44
|
private startHeartbeat;
|
|
45
|
+
/** Reject every in-flight request; the executor that was sent to is gone. */
|
|
46
|
+
private abandonRequests;
|
|
34
47
|
private dropConnection;
|
|
35
48
|
private serialize;
|
|
36
49
|
/** Why no executor can be reached, with the fix, for error messages. */
|
package/dist/extensionBridge.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
import { WebSocketServer } from "ws";
|
|
4
|
+
import { WebSocketServer, WebSocket } from "ws";
|
|
5
5
|
import { buildBootstrapSnippet } from "./bootstrap.js";
|
|
6
6
|
import { config, USER_ENV_FILE } from "./config.js";
|
|
7
7
|
import { ProjectionLabError } from "./errors.js";
|
|
8
8
|
import { log } from "./logger.js";
|
|
9
|
-
import {
|
|
9
|
+
import { VERSION } from "./version.js";
|
|
10
|
+
import { CLOSE_CODES, HEARTBEAT_INTERVAL_MS, MIN_EXTENSION_VERSION, PROTOCOL_VERSION, } from "./types/wire.js";
|
|
10
11
|
/** Origins allowed to open the WebSocket. Extensions plus the PL app itself
|
|
11
12
|
* (Tier 0 bootstrap snippet runs in page context, so the browser sends the
|
|
12
13
|
* app origin). Sockets with no Origin header (native clients, e.g. the fake
|
|
@@ -25,14 +26,26 @@ const HELLO_TIMEOUT_MS = 5_000;
|
|
|
25
26
|
const MAX_PRE_HELLO_BYTES = 64 * 1024;
|
|
26
27
|
/** How often to retry the WebSocket port while another instance holds it. */
|
|
27
28
|
const PORT_RETRY_MS = 3_000;
|
|
28
|
-
const EXTENSION_HELP = "Install the MCP Bridge for ProjectionLab extension
|
|
29
|
-
"https://
|
|
29
|
+
const EXTENSION_HELP = "Install the MCP Bridge for ProjectionLab extension from the Chrome Web Store " +
|
|
30
|
+
"(https://chromewebstore.google.com/detail/mcp-bridge-for-projection/njgjmcihabchffonldcgfjiocjalpoaf) " +
|
|
31
|
+
"or Firefox Add-ons (https://addons.mozilla.org/en-US/firefox/addon/mcp-bridge-for-projectionlab/); " +
|
|
32
|
+
"the store keeps it up to date. Then enter the token from " +
|
|
30
33
|
"~/.projectionlab-mcp/ws-token on its options page, and open https://app.projectionlab.com. " +
|
|
31
34
|
"Or call projectionlab_get_bootstrap and paste the snippet into the ProjectionLab tab's console. " +
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"folder) and re-enter the port and token if its options page is empty.";
|
|
35
|
+
"Install the extension from one source only: an unpacked copy alongside a store copy leaves the " +
|
|
36
|
+
"browser with two extensions competing for the server's single connection, and one of them stands by.";
|
|
35
37
|
const REQUEST_TIMEOUT_MS = 60_000;
|
|
38
|
+
/** Parses one text frame. Returns null unless it is a JSON object: valid JSON
|
|
39
|
+
* such as `null` or `42` has no `type` to read. */
|
|
40
|
+
function parseFrame(raw) {
|
|
41
|
+
try {
|
|
42
|
+
const frame = JSON.parse(String(raw));
|
|
43
|
+
return frame && typeof frame === "object" ? frame : null;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
36
49
|
/** Best-effort chmod; a file the process does not own keeps its mode. */
|
|
37
50
|
function restrictMode(path, mode) {
|
|
38
51
|
try {
|
|
@@ -46,6 +59,7 @@ export class ExtensionBridge {
|
|
|
46
59
|
wss = null;
|
|
47
60
|
conn = null;
|
|
48
61
|
connExecutor = "";
|
|
62
|
+
connInstanceId = "";
|
|
49
63
|
pending = new Map();
|
|
50
64
|
nextId = 1;
|
|
51
65
|
heartbeat = null;
|
|
@@ -162,11 +176,8 @@ export class ExtensionBridge {
|
|
|
162
176
|
ws.once("message", (raw) => {
|
|
163
177
|
clearTimeout(timer);
|
|
164
178
|
helloRead();
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
hello = JSON.parse(String(raw));
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
179
|
+
const hello = parseFrame(raw);
|
|
180
|
+
if (!hello) {
|
|
170
181
|
ws.close(CLOSE_CODES.AUTH_FAILED, "malformed hello");
|
|
171
182
|
return;
|
|
172
183
|
}
|
|
@@ -180,19 +191,65 @@ export class ExtensionBridge {
|
|
|
180
191
|
ws.close(CLOSE_CODES.VERSION_MISMATCH, "protocol version mismatch");
|
|
181
192
|
return;
|
|
182
193
|
}
|
|
183
|
-
|
|
194
|
+
// Only authenticated hellos reach the connection decision, so an
|
|
195
|
+
// unauthenticated client can neither displace an executor nor learn
|
|
196
|
+
// that one is connected.
|
|
197
|
+
const instanceId = typeof hello.instanceId === "string" &&
|
|
198
|
+
hello.instanceId.length >= 1 &&
|
|
199
|
+
hello.instanceId.length <= 64
|
|
200
|
+
? hello.instanceId
|
|
201
|
+
: "";
|
|
202
|
+
this.admit(ws, hello.executor, instanceId, hello.takeover === true);
|
|
184
203
|
});
|
|
185
204
|
}
|
|
186
|
-
/**
|
|
187
|
-
|
|
205
|
+
/**
|
|
206
|
+
* Decide whether an authenticated hello becomes the active executor. The
|
|
207
|
+
* incumbent keeps the connection: a newcomer is refused with BUSY unless it
|
|
208
|
+
* requests takeover, or repeats the incumbent's instance id (an executor
|
|
209
|
+
* must never be locked out by its own stale socket). An incumbent whose
|
|
210
|
+
* socket is not open is dead and gets dropped first; the heartbeat is what
|
|
211
|
+
* clears a crashed incumbent that still looks open.
|
|
212
|
+
*/
|
|
213
|
+
admit(ws, executor, instanceId, takeover) {
|
|
214
|
+
const incumbent = this.conn;
|
|
215
|
+
if (!incumbent || incumbent.readyState !== WebSocket.OPEN) {
|
|
216
|
+
if (incumbent)
|
|
217
|
+
this.dropConnection("dropping a dead executor connection");
|
|
218
|
+
this.adopt(ws, executor, instanceId);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (takeover || (instanceId !== "" && instanceId === this.connInstanceId)) {
|
|
222
|
+
this.adopt(ws, executor, instanceId);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
log.info("extension", `Refusing ${executor} with BUSY: ${this.connExecutor} holds the connection`);
|
|
226
|
+
ws.close(CLOSE_CODES.BUSY, "another executor holds the connection");
|
|
227
|
+
}
|
|
228
|
+
/** Promote an authenticated socket to the active connection. Replacing a
|
|
229
|
+
* live incumbent (takeover or same instance id) closes it with 4003. */
|
|
230
|
+
adopt(ws, executor, instanceId) {
|
|
188
231
|
if (this.conn && this.conn !== ws) {
|
|
189
232
|
log.info("extension", `Replacing ${this.connExecutor} with ${executor}`);
|
|
190
233
|
this.conn.close(CLOSE_CODES.REPLACED, "replaced by newer connection");
|
|
234
|
+
// The replaced executor's state must not leak into the new one: its
|
|
235
|
+
// cached export could be served from the previous browser, its
|
|
236
|
+
// unanswered requests would hang until the 60s timeout, and a pong the
|
|
237
|
+
// old executor never sent must not drop the new one at the next
|
|
238
|
+
// heartbeat tick. The new socket and the heartbeat stay as they are.
|
|
239
|
+
this.exportCache = null;
|
|
240
|
+
this.awaitingPong = false;
|
|
241
|
+
this.abandonRequests("executor was replaced");
|
|
191
242
|
}
|
|
192
243
|
this.conn = ws;
|
|
193
244
|
this.connExecutor = executor;
|
|
245
|
+
this.connInstanceId = instanceId;
|
|
194
246
|
log.info("extension", `Executor connected: ${executor}`);
|
|
195
|
-
ws.send(JSON.stringify({
|
|
247
|
+
ws.send(JSON.stringify({
|
|
248
|
+
type: "helloAck",
|
|
249
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
250
|
+
serverVersion: VERSION,
|
|
251
|
+
minExtensionVersion: MIN_EXTENSION_VERSION,
|
|
252
|
+
}));
|
|
196
253
|
ws.on("message", (raw) => this.onFrame(ws, raw));
|
|
197
254
|
ws.on("close", () => {
|
|
198
255
|
if (this.conn === ws) {
|
|
@@ -208,11 +265,8 @@ export class ExtensionBridge {
|
|
|
208
265
|
onFrame(ws, raw) {
|
|
209
266
|
if (this.conn !== ws)
|
|
210
267
|
return;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
frame = JSON.parse(String(raw));
|
|
214
|
-
}
|
|
215
|
-
catch {
|
|
268
|
+
const frame = parseFrame(raw);
|
|
269
|
+
if (!frame) {
|
|
216
270
|
log.warn("extension", "Dropping malformed frame");
|
|
217
271
|
return;
|
|
218
272
|
}
|
|
@@ -271,6 +325,14 @@ export class ExtensionBridge {
|
|
|
271
325
|
this.conn.send(JSON.stringify({ type: "ping" }));
|
|
272
326
|
}, HEARTBEAT_INTERVAL_MS);
|
|
273
327
|
}
|
|
328
|
+
/** Reject every in-flight request; the executor that was sent to is gone. */
|
|
329
|
+
abandonRequests(reason) {
|
|
330
|
+
for (const [id, pending] of this.pending) {
|
|
331
|
+
clearTimeout(pending.timer);
|
|
332
|
+
pending.reject(new ProjectionLabError("EXTENSION_NOT_CONNECTED", `Request ${id} aborted: ${reason}`, "The browser-side executor disconnected mid-request. Check the browser and retry."));
|
|
333
|
+
}
|
|
334
|
+
this.pending.clear();
|
|
335
|
+
}
|
|
274
336
|
dropConnection(reason) {
|
|
275
337
|
// Close the socket if it's still live - wss.close() waits for all
|
|
276
338
|
// clients, so leaving it open would hang shutdown.
|
|
@@ -282,17 +344,14 @@ export class ExtensionBridge {
|
|
|
282
344
|
}
|
|
283
345
|
this.conn = null;
|
|
284
346
|
this.connExecutor = "";
|
|
347
|
+
this.connInstanceId = "";
|
|
285
348
|
this.awaitingPong = false;
|
|
286
349
|
this.exportCache = null;
|
|
287
350
|
if (this.heartbeat) {
|
|
288
351
|
clearInterval(this.heartbeat);
|
|
289
352
|
this.heartbeat = null;
|
|
290
353
|
}
|
|
291
|
-
|
|
292
|
-
clearTimeout(pending.timer);
|
|
293
|
-
pending.reject(new ProjectionLabError("EXTENSION_NOT_CONNECTED", `Request ${id} aborted: ${reason}`, "The browser-side executor disconnected mid-request. Check the browser and retry."));
|
|
294
|
-
}
|
|
295
|
-
this.pending.clear();
|
|
354
|
+
this.abandonRequests(reason);
|
|
296
355
|
}
|
|
297
356
|
serialize(fn) {
|
|
298
357
|
const next = this.opChain.then(fn, fn);
|
|
@@ -362,6 +421,7 @@ export class ExtensionBridge {
|
|
|
362
421
|
return result;
|
|
363
422
|
}
|
|
364
423
|
result.browser = true;
|
|
424
|
+
result.executor = this.connExecutor || undefined;
|
|
365
425
|
try {
|
|
366
426
|
await this.request("waitForApi", [config.apiReadyTimeoutMs], config.apiReadyTimeoutMs + 5_000);
|
|
367
427
|
result.pageLoaded = true;
|