dsh-browser-cdp 0.18.19 → 1.1.5
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/README.md +29 -0
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/bin/cdp-cast-worker.mjs +93 -11
- package/dsh-plugin.json +148 -148
- package/lib/client.js +296 -25
- package/lib/index.js +542 -61
- package/lib/{launcher-DBaxfIsF.js → launcher-BadIUjAx.js} +160 -28
- package/lib/launcher-h0Ca5NV1.js +3 -0
- package/package.json +27 -15
- package/lib/launcher-CQyI8-By.js +0 -3
package/lib/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as stopLocalBrowser, l as launchLocalBrowser } from "./launcher-BadIUjAx.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
3
4
|
import { constants, createReadStream, createWriteStream, existsSync, readdirSync } from "node:fs";
|
|
4
5
|
import { homedir, tmpdir } from "node:os";
|
|
@@ -792,6 +793,60 @@ async function discoverWebSocketUrl(raw, options = {}) {
|
|
|
792
793
|
}
|
|
793
794
|
}
|
|
794
795
|
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region src/cdp/capabilities.ts
|
|
798
|
+
/**
|
|
799
|
+
* Recognize the engine from `/json/version`'s `Browser` field
|
|
800
|
+
* (`"Lightpanda/0.4.1"`, `"Chrome/153.0.0.0"`, `"Edg/153.0.0.0"`, …).
|
|
801
|
+
* Empty or unrecognized → `'unknown'` (never guesses).
|
|
802
|
+
*/
|
|
803
|
+
function engineOf(browserField) {
|
|
804
|
+
const value = typeof browserField === "string" ? browserField.trim() : "";
|
|
805
|
+
if (value === "") return "unknown";
|
|
806
|
+
if (value.startsWith("Lightpanda/")) return "lightpanda";
|
|
807
|
+
if (value.startsWith("Chrome/") || value.startsWith("Chromium")) return "chrome";
|
|
808
|
+
if (value.startsWith("Edg/") || value.startsWith("Microsoft Edge ")) return "chrome";
|
|
809
|
+
return "unknown";
|
|
810
|
+
}
|
|
811
|
+
const FULL = {
|
|
812
|
+
engine: "chrome",
|
|
813
|
+
screencast: true,
|
|
814
|
+
overlay: true,
|
|
815
|
+
bindingCalled: true,
|
|
816
|
+
imageFormat: "jpeg",
|
|
817
|
+
loadEvent: true,
|
|
818
|
+
downloadEvents: true,
|
|
819
|
+
browserClose: true
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* The capability projection per engine. `chrome` / `unknown` → full
|
|
823
|
+
* capabilities (bit-for-bit today's behavior); `lightpanda` → the analysis
|
|
824
|
+
* (docs/plans/2026-10-04-lightpanda-backend-analysis.md §7) projection.
|
|
825
|
+
*/
|
|
826
|
+
function capabilitiesFor(engine) {
|
|
827
|
+
if (engine === "lightpanda") return {
|
|
828
|
+
engine: "lightpanda",
|
|
829
|
+
screencast: false,
|
|
830
|
+
overlay: false,
|
|
831
|
+
bindingCalled: false,
|
|
832
|
+
imageFormat: "png",
|
|
833
|
+
loadEvent: false,
|
|
834
|
+
downloadEvents: false,
|
|
835
|
+
browserClose: false
|
|
836
|
+
};
|
|
837
|
+
return {
|
|
838
|
+
...FULL,
|
|
839
|
+
engine
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Env key the host half sets when spawning the cast / render workers
|
|
844
|
+
* (mirrors `EGO_LINUX_CDP_URL`'s injection pattern in cast-server). The child
|
|
845
|
+
* processes cannot see the host's attach cache, so the projected engine id
|
|
846
|
+
* travels as data — the host decides once, children only read.
|
|
847
|
+
*/
|
|
848
|
+
const BCDP_CDP_ENGINE = "BCDP_CDP_ENGINE";
|
|
849
|
+
|
|
795
850
|
//#endregion
|
|
796
851
|
//#region src/cdp/cli-link.ts
|
|
797
852
|
/** Upstream's own macOS location for the real CLI (verbatim, from its e2e runner). */
|
|
@@ -1102,6 +1157,14 @@ const EGO_CLI_KIND = "ego-cli";
|
|
|
1102
1157
|
/** Default panel label for an ego-cli link (no endpoint to fall back to). */
|
|
1103
1158
|
const EGO_CLI_LABEL = "本机 ego CLI";
|
|
1104
1159
|
/**
|
|
1160
|
+
* Lightpanda backend — the managed-serve link kind (headless quick-trial
|
|
1161
|
+
* engine; headed kinds are the manual-fallback backstop). Local-only
|
|
1162
|
+
* singleton, same rules as `ego-cli`.
|
|
1163
|
+
*/
|
|
1164
|
+
const LP_KIND = "lightpanda";
|
|
1165
|
+
/** Default panel label for a lightpanda link. */
|
|
1166
|
+
const LP_LABEL = "Lightpanda(受管)";
|
|
1167
|
+
/**
|
|
1105
1168
|
* Build a stable target id. `randomUUID` is available on every supported
|
|
1106
1169
|
* host (Node >= 22); the fallback exists only because cheap and steady beats
|
|
1107
1170
|
* clever in a hot path that also runs inside tests.
|
|
@@ -1131,6 +1194,15 @@ function coerceLink(raw) {
|
|
|
1131
1194
|
...rec.useSdkPath === void 0 ? {} : { useSdkPath: Boolean(rec.useSdkPath) }
|
|
1132
1195
|
};
|
|
1133
1196
|
}
|
|
1197
|
+
if (rec.kind === LP_KIND) {
|
|
1198
|
+
const servePath = typeof rec.servePath === "string" ? rec.servePath.trim() : "";
|
|
1199
|
+
return {
|
|
1200
|
+
...base,
|
|
1201
|
+
kind: LP_KIND,
|
|
1202
|
+
label: label === "" ? LP_LABEL : label,
|
|
1203
|
+
servePath
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1134
1206
|
const endpoint = normalizeEndpoint(rec.endpoint);
|
|
1135
1207
|
if (!endpoint.ok) return null;
|
|
1136
1208
|
return {
|
|
@@ -1144,21 +1216,24 @@ function coerceLink(raw) {
|
|
|
1144
1216
|
* Sanitize the persisted sequence. Dirty data is expected here (a hand-edited
|
|
1145
1217
|
* profile config on the settings page, older schema, unknown keys) so the rule
|
|
1146
1218
|
* is DROP, never throw: every surviving entry is usable, duplicate ids get
|
|
1147
|
-
* fresh ones so ordering/activation stay unambiguous, and the `ego-cli`
|
|
1148
|
-
*
|
|
1149
|
-
* doctor).
|
|
1219
|
+
* fresh ones so ordering/activation stay unambiguous, and the `ego-cli` /
|
|
1220
|
+
* `lightpanda` singletons keep the FIRST entry of their kind (dropping the
|
|
1221
|
+
* rest and counting them for the doctor).
|
|
1150
1222
|
*/
|
|
1151
1223
|
function sanitizeLinks(raw, max = MAX_TARGETS) {
|
|
1152
1224
|
if (!Array.isArray(raw)) return {
|
|
1153
1225
|
links: [],
|
|
1154
1226
|
droppedEgoCli: 0,
|
|
1227
|
+
droppedLightpanda: 0,
|
|
1155
1228
|
droppedInvalid: 0
|
|
1156
1229
|
};
|
|
1157
1230
|
const out = [];
|
|
1158
1231
|
const seen = /* @__PURE__ */ new Set();
|
|
1159
1232
|
let droppedEgoCli = 0;
|
|
1233
|
+
let droppedLightpanda = 0;
|
|
1160
1234
|
let droppedInvalid = 0;
|
|
1161
1235
|
let sawEgoCli = false;
|
|
1236
|
+
let sawLightpanda = false;
|
|
1162
1237
|
for (const entry of raw) {
|
|
1163
1238
|
const link = coerceLink(entry);
|
|
1164
1239
|
if (!link) {
|
|
@@ -1172,6 +1247,13 @@ function sanitizeLinks(raw, max = MAX_TARGETS) {
|
|
|
1172
1247
|
}
|
|
1173
1248
|
sawEgoCli = true;
|
|
1174
1249
|
}
|
|
1250
|
+
if (link.kind === LP_KIND) {
|
|
1251
|
+
if (sawLightpanda) {
|
|
1252
|
+
droppedLightpanda += 1;
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
sawLightpanda = true;
|
|
1256
|
+
}
|
|
1175
1257
|
if (seen.has(link.id)) link.id = newTargetId();
|
|
1176
1258
|
seen.add(link.id);
|
|
1177
1259
|
out.push(link);
|
|
@@ -1180,6 +1262,7 @@ function sanitizeLinks(raw, max = MAX_TARGETS) {
|
|
|
1180
1262
|
return {
|
|
1181
1263
|
links: out,
|
|
1182
1264
|
droppedEgoCli,
|
|
1265
|
+
droppedLightpanda,
|
|
1183
1266
|
droppedInvalid
|
|
1184
1267
|
};
|
|
1185
1268
|
}
|
|
@@ -1221,6 +1304,7 @@ async function probeEndpoint(endpoint, options = {}) {
|
|
|
1221
1304
|
code: "ok",
|
|
1222
1305
|
message: "",
|
|
1223
1306
|
wsUrl: result.wsUrl,
|
|
1307
|
+
engine: engineOf(result.browser),
|
|
1224
1308
|
latencyMs: result.latencyMs
|
|
1225
1309
|
};
|
|
1226
1310
|
}
|
|
@@ -1254,10 +1338,10 @@ function decideAttach(input) {
|
|
|
1254
1338
|
kind: "local",
|
|
1255
1339
|
message: "local mode: using local browser control"
|
|
1256
1340
|
};
|
|
1257
|
-
if (input.mode === "remote" && input.linkKind === EGO_CLI_KIND) return {
|
|
1341
|
+
if (input.mode === "remote" && (input.linkKind === EGO_CLI_KIND || input.linkKind === LP_KIND)) return {
|
|
1258
1342
|
kind: "error",
|
|
1259
1343
|
code: "mode-kind-mismatch",
|
|
1260
|
-
message: "cdpMode=remote requires a CDP endpoint link, but the activated link is the local ego CLI. Activate a CDP link, or switch cdpMode to auto."
|
|
1344
|
+
message: input.linkKind === LP_KIND ? "cdpMode=remote requires a CDP endpoint link, but the activated link is the local Lightpanda serve. Activate a CDP link, or switch cdpMode to auto." : "cdpMode=remote requires a CDP endpoint link, but the activated link is the local ego CLI. Activate a CDP link, or switch cdpMode to auto."
|
|
1261
1345
|
};
|
|
1262
1346
|
if (input.hasActive && input.linkKind === EGO_CLI_KIND) {
|
|
1263
1347
|
if (input.status === "ready") return {
|
|
@@ -1275,6 +1359,24 @@ function decideAttach(input) {
|
|
|
1275
1359
|
message: input.message === "" ? "the local ego CLI is not available" : input.message
|
|
1276
1360
|
};
|
|
1277
1361
|
}
|
|
1362
|
+
if (input.hasActive && input.linkKind === LP_KIND) {
|
|
1363
|
+
if (input.status === "ready" && input.wsUrl !== "") return {
|
|
1364
|
+
kind: "inject",
|
|
1365
|
+
wsUrl: input.wsUrl,
|
|
1366
|
+
targetId: "",
|
|
1367
|
+
source: "remote"
|
|
1368
|
+
};
|
|
1369
|
+
if (input.status === "idle" || input.status === "probing") return {
|
|
1370
|
+
kind: "error",
|
|
1371
|
+
code: "endpoint-unresolved",
|
|
1372
|
+
message: "The Lightpanda serve has not been probed yet. Wait for the probe to finish and retry the call."
|
|
1373
|
+
};
|
|
1374
|
+
return {
|
|
1375
|
+
kind: "error",
|
|
1376
|
+
code: input.code === "" ? "lightpanda-not-ready" : input.code,
|
|
1377
|
+
message: input.message === "" ? "the managed Lightpanda serve is not available" : input.message
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1278
1380
|
if (input.remoteDisabled) return {
|
|
1279
1381
|
kind: "error",
|
|
1280
1382
|
code: "remote-disabled",
|
|
@@ -1383,6 +1485,50 @@ async function refreshCliAttach(input, cache, suggested, link, now) {
|
|
|
1383
1485
|
});
|
|
1384
1486
|
}
|
|
1385
1487
|
/**
|
|
1488
|
+
* Lightpanda backend — ensure the managed serve for an activated `lightpanda`
|
|
1489
|
+
* row, then probe its endpoint. The launcher owns launch/reuse/exclusivity
|
|
1490
|
+
* (a live managed Chrome loses the singleton slot to the serve and vice
|
|
1491
|
+
* versa); `engine` is stamped from the ROW — the source the user picked — and
|
|
1492
|
+
* `/json/version`'s `Browser: Lightpanda/…` merely re-confirms it.
|
|
1493
|
+
*/
|
|
1494
|
+
async function refreshLightpandaAttach(input, cache, suggested, link, now) {
|
|
1495
|
+
const base = {
|
|
1496
|
+
...suggested,
|
|
1497
|
+
targetId: link.id,
|
|
1498
|
+
endpoint: "",
|
|
1499
|
+
wsUrl: "",
|
|
1500
|
+
linkKind: LP_KIND
|
|
1501
|
+
};
|
|
1502
|
+
const launch = await launchLocalBrowser({
|
|
1503
|
+
engine: "lightpanda",
|
|
1504
|
+
lightpandaPath: link.servePath ?? "",
|
|
1505
|
+
lightpandaArgs: input.lightpandaArgs
|
|
1506
|
+
}, input.launcherIo);
|
|
1507
|
+
if (!launch.ok) return cache.patch({
|
|
1508
|
+
...base,
|
|
1509
|
+
status: "unreachable",
|
|
1510
|
+
code: launch.code,
|
|
1511
|
+
message: launch.message,
|
|
1512
|
+
resolvedAt: now()
|
|
1513
|
+
});
|
|
1514
|
+
const probe = await probeEndpoint(launch.endpoint, {
|
|
1515
|
+
timeoutMs: input.timeoutMs,
|
|
1516
|
+
now
|
|
1517
|
+
});
|
|
1518
|
+
return cache.patch({
|
|
1519
|
+
...base,
|
|
1520
|
+
status: probe.ok && probe.wsUrl ? "ready" : "unreachable",
|
|
1521
|
+
endpoint: launch.endpoint,
|
|
1522
|
+
wsUrl: probe.wsUrl ?? "",
|
|
1523
|
+
engine: "lightpanda",
|
|
1524
|
+
code: probe.ok ? "" : probe.code,
|
|
1525
|
+
message: probe.ok ? launch.reused ? "lightpanda serve reused" : "lightpanda serve launched" : `lightpanda serve is up but its endpoint did not answer: ${probe.message}`,
|
|
1526
|
+
latencyMs: probe.latencyMs,
|
|
1527
|
+
resolvedAt: now(),
|
|
1528
|
+
endpointSource: launch.reused ? "local" : "local-launch"
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
/**
|
|
1386
1532
|
* Re-probe the activated target and publish the outcome into the cache.
|
|
1387
1533
|
*
|
|
1388
1534
|
* `local` mode short-circuits: there is nothing to probe and nothing to write,
|
|
@@ -1422,6 +1568,7 @@ async function refreshAttach(input) {
|
|
|
1422
1568
|
status: "ready",
|
|
1423
1569
|
endpoint: launch.endpoint,
|
|
1424
1570
|
wsUrl: localProbe.wsUrl,
|
|
1571
|
+
engine: localProbe.engine,
|
|
1425
1572
|
code: "",
|
|
1426
1573
|
message: launch.reused ? "local mode: reused managed browser" : "local mode: managed browser launched",
|
|
1427
1574
|
latencyMs: localProbe.latencyMs,
|
|
@@ -1430,6 +1577,7 @@ async function refreshAttach(input) {
|
|
|
1430
1577
|
return cache.patch({
|
|
1431
1578
|
...suggested,
|
|
1432
1579
|
status: "unreachable",
|
|
1580
|
+
engine: void 0,
|
|
1433
1581
|
code: "local-launch-not-ready",
|
|
1434
1582
|
message: `managed local browser launched but its endpoint did not answer: ${localProbe.message}`
|
|
1435
1583
|
});
|
|
@@ -1437,6 +1585,7 @@ async function refreshAttach(input) {
|
|
|
1437
1585
|
return cache.patch({
|
|
1438
1586
|
...suggested,
|
|
1439
1587
|
status: "unreachable",
|
|
1588
|
+
engine: void 0,
|
|
1440
1589
|
code: `local-${launch.code}`,
|
|
1441
1590
|
message: launch.message
|
|
1442
1591
|
});
|
|
@@ -1454,7 +1603,7 @@ async function refreshAttach(input) {
|
|
|
1454
1603
|
message: input.remoteEnabled === false ? "remote CDP is disabled by the remoteEnabled switch; the target sequence is preserved and can be re-enabled at any time" : "no activated target in the sequence",
|
|
1455
1604
|
resolvedAt: now()
|
|
1456
1605
|
});
|
|
1457
|
-
if (input.remoteEnabled === false && target.kind !== EGO_CLI_KIND) return cache.patch({
|
|
1606
|
+
if (input.remoteEnabled === false && target.kind !== EGO_CLI_KIND && target.kind !== LP_KIND) return cache.patch({
|
|
1458
1607
|
...suggested,
|
|
1459
1608
|
status: "no-active",
|
|
1460
1609
|
targetId: input.activeTargetId,
|
|
@@ -1465,6 +1614,7 @@ async function refreshAttach(input) {
|
|
|
1465
1614
|
resolvedAt: now()
|
|
1466
1615
|
});
|
|
1467
1616
|
if (target.kind === EGO_CLI_KIND) return refreshCliAttach(input, cache, suggested, target, now);
|
|
1617
|
+
if (target.kind === LP_KIND) return refreshLightpandaAttach(input, cache, suggested, target, now);
|
|
1468
1618
|
const sameTarget = previous.targetId === target.id && previous.endpoint === target.endpoint;
|
|
1469
1619
|
const suggestedProbe = {
|
|
1470
1620
|
...suggested,
|
|
@@ -1485,6 +1635,7 @@ async function refreshAttach(input) {
|
|
|
1485
1635
|
if (outcome.ok && outcome.wsUrl) return cache.patch({
|
|
1486
1636
|
status: "ready",
|
|
1487
1637
|
wsUrl: outcome.wsUrl,
|
|
1638
|
+
engine: outcome.engine,
|
|
1488
1639
|
code: "",
|
|
1489
1640
|
message: "",
|
|
1490
1641
|
latencyMs: outcome.latencyMs,
|
|
@@ -1505,6 +1656,7 @@ async function refreshAttach(input) {
|
|
|
1505
1656
|
if (localProbe.ok && localProbe.wsUrl) return cache.patch({
|
|
1506
1657
|
status: "ready",
|
|
1507
1658
|
wsUrl: localProbe.wsUrl,
|
|
1659
|
+
engine: localProbe.engine,
|
|
1508
1660
|
endpoint: launch.endpoint,
|
|
1509
1661
|
code: "",
|
|
1510
1662
|
message: "local fallback launched (activated endpoint unreachable)",
|
|
@@ -1516,6 +1668,7 @@ async function refreshAttach(input) {
|
|
|
1516
1668
|
return cache.patch({
|
|
1517
1669
|
status: "unreachable",
|
|
1518
1670
|
wsUrl: "",
|
|
1671
|
+
engine: void 0,
|
|
1519
1672
|
code: "local-launch-not-ready",
|
|
1520
1673
|
message: `local fallback browser launched but its endpoint did not answer: ${localProbe.message}`,
|
|
1521
1674
|
latencyMs: outcome.latencyMs,
|
|
@@ -1534,6 +1687,7 @@ async function refreshAttach(input) {
|
|
|
1534
1687
|
return cache.patch({
|
|
1535
1688
|
status: "unreachable",
|
|
1536
1689
|
wsUrl: "",
|
|
1690
|
+
engine: outcome.ok ? outcome.engine : void 0,
|
|
1537
1691
|
code: outcome.code,
|
|
1538
1692
|
message: outcome.message,
|
|
1539
1693
|
latencyMs: outcome.latencyMs,
|
|
@@ -1545,6 +1699,8 @@ async function refreshAttach(input) {
|
|
|
1545
1699
|
//#region src/cast-server.ts
|
|
1546
1700
|
const WORKER_BIN = fileURLToPath(new URL("../bin/cdp-cast-worker.mjs", import.meta.url));
|
|
1547
1701
|
let attachWsUrl = null;
|
|
1702
|
+
/** Lightpanda backend — engine of the attached endpoint, published next to it. */
|
|
1703
|
+
let attachEngine = null;
|
|
1548
1704
|
/** Logger captured in initCastServer so module-level helpers can report. */
|
|
1549
1705
|
let castLogger;
|
|
1550
1706
|
/**
|
|
@@ -1552,17 +1708,25 @@ let castLogger;
|
|
|
1552
1708
|
* half whenever the ACTIVATED target changes (new target, new endpoint, or
|
|
1553
1709
|
* mode switching away from remote). Returns true when the value actually
|
|
1554
1710
|
* changed, which is the caller's signal that the worker must be recycled.
|
|
1711
|
+
* The engine rides along so a spawned worker gets its capability projection
|
|
1712
|
+
* via env (`BCDP_CDP_ENGINE`) instead of re-deriving it.
|
|
1555
1713
|
*/
|
|
1556
|
-
function setAttachEndpoint(wsUrl) {
|
|
1714
|
+
function setAttachEndpoint(wsUrl, engine = null) {
|
|
1557
1715
|
const next = wsUrl && wsUrl !== "" ? wsUrl : null;
|
|
1558
|
-
|
|
1716
|
+
const nextEngine = next === null ? null : engine;
|
|
1717
|
+
if (next === attachWsUrl && nextEngine === attachEngine) return false;
|
|
1559
1718
|
attachWsUrl = next;
|
|
1719
|
+
attachEngine = nextEngine;
|
|
1560
1720
|
return true;
|
|
1561
1721
|
}
|
|
1562
1722
|
/** The endpoint the worker should attach to right now (null = none). */
|
|
1563
1723
|
function getAttachEndpoint() {
|
|
1564
1724
|
return attachWsUrl;
|
|
1565
1725
|
}
|
|
1726
|
+
/** The engine of the attached endpoint (null = none attached). */
|
|
1727
|
+
function getAttachEngine() {
|
|
1728
|
+
return attachEngine;
|
|
1729
|
+
}
|
|
1566
1730
|
/**
|
|
1567
1731
|
* Stop a running worker so the next request respawns it with the new argv
|
|
1568
1732
|
* seed (T2.4: an activation change must take effect on a live panel, not only
|
|
@@ -1898,6 +2062,9 @@ function workerEnv() {
|
|
|
1898
2062
|
const ws = getAttachEndpoint();
|
|
1899
2063
|
if (ws) base[EGO_LINUX_CDP_URL] = ws;
|
|
1900
2064
|
else delete base[EGO_LINUX_CDP_URL];
|
|
2065
|
+
const engine = getAttachEngine();
|
|
2066
|
+
if (engine) base[BCDP_CDP_ENGINE] = engine;
|
|
2067
|
+
else delete base[BCDP_CDP_ENGINE];
|
|
1901
2068
|
return base;
|
|
1902
2069
|
}
|
|
1903
2070
|
/** Ensure a single ego-cast worker is running (idempotent). Launches it via
|
|
@@ -2398,40 +2565,75 @@ const Config$1 = z.object({
|
|
|
2398
2565
|
githubMirror: z.string().description("HTTPS base replacing https://github.com for managed downloads.").volatile(),
|
|
2399
2566
|
runtimeArgs: z.string().description("Extra args appended to the vendored runtime argv. Takes effect on the next bcdp_* call.").volatile(),
|
|
2400
2567
|
chromeArgs: z.string().description("Extra args appended to the Chrome launch argv. Takes effect on the next browser cold start (the browser is a singleton).").volatile(),
|
|
2401
|
-
links: z.array(z.union([
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2568
|
+
links: z.array(z.union([
|
|
2569
|
+
z.object({
|
|
2570
|
+
kind: z.string(),
|
|
2571
|
+
id: z.string(),
|
|
2572
|
+
label: z.string(),
|
|
2573
|
+
endpoint: z.string(),
|
|
2574
|
+
enabled: z.boolean(),
|
|
2575
|
+
note: z.string(),
|
|
2576
|
+
probeStatus: z.union([
|
|
2577
|
+
"unknown",
|
|
2578
|
+
"ok",
|
|
2579
|
+
"error"
|
|
2580
|
+
]),
|
|
2581
|
+
probeLatencyMs: z.number(),
|
|
2582
|
+
probeError: z.string(),
|
|
2583
|
+
probeCode: z.string(),
|
|
2584
|
+
probeAt: z.number(),
|
|
2585
|
+
probeEngine: z.union([
|
|
2586
|
+
"chrome",
|
|
2587
|
+
"lightpanda",
|
|
2588
|
+
"unknown"
|
|
2589
|
+
])
|
|
2590
|
+
}),
|
|
2591
|
+
z.object({
|
|
2592
|
+
kind: z.string(),
|
|
2593
|
+
id: z.string(),
|
|
2594
|
+
label: z.string(),
|
|
2595
|
+
cliPath: z.string(),
|
|
2596
|
+
useSdkPath: z.boolean(),
|
|
2597
|
+
enabled: z.boolean(),
|
|
2598
|
+
note: z.string(),
|
|
2599
|
+
probeStatus: z.union([
|
|
2600
|
+
"unknown",
|
|
2601
|
+
"ok",
|
|
2602
|
+
"error"
|
|
2603
|
+
]),
|
|
2604
|
+
probeLatencyMs: z.number(),
|
|
2605
|
+
probeError: z.string(),
|
|
2606
|
+
probeCode: z.string(),
|
|
2607
|
+
probeAt: z.number(),
|
|
2608
|
+
probeEngine: z.union([
|
|
2609
|
+
"chrome",
|
|
2610
|
+
"lightpanda",
|
|
2611
|
+
"unknown"
|
|
2612
|
+
])
|
|
2613
|
+
}),
|
|
2614
|
+
z.object({
|
|
2615
|
+
kind: z.string(),
|
|
2616
|
+
id: z.string(),
|
|
2617
|
+
label: z.string(),
|
|
2618
|
+
servePath: z.string(),
|
|
2619
|
+
enabled: z.boolean(),
|
|
2620
|
+
note: z.string(),
|
|
2621
|
+
probeStatus: z.union([
|
|
2622
|
+
"unknown",
|
|
2623
|
+
"ok",
|
|
2624
|
+
"error"
|
|
2625
|
+
]),
|
|
2626
|
+
probeLatencyMs: z.number(),
|
|
2627
|
+
probeError: z.string(),
|
|
2628
|
+
probeCode: z.string(),
|
|
2629
|
+
probeAt: z.number(),
|
|
2630
|
+
probeEngine: z.union([
|
|
2631
|
+
"chrome",
|
|
2632
|
+
"lightpanda",
|
|
2633
|
+
"unknown"
|
|
2634
|
+
])
|
|
2635
|
+
})
|
|
2636
|
+
])).description("Ordered connection sequence: CDP endpoints and (at most one) local ego CLI link. Only the ACTIVATED and enabled entry receives every bcdp_* call. Order IS the priority order.").volatile(),
|
|
2435
2637
|
activeTargetId: z.string().description("Id of the activated entry in links. Empty = nothing activated.").volatile(),
|
|
2436
2638
|
cdpMode: cdpMode.description("auto = use the activated target and never start a local browser silently; remote = only ever connect to the activated target; local = always use local browser control.").volatile(),
|
|
2437
2639
|
cdpProbeTimeoutMs: z.number().min(200).max(3e4).step(100).description("Timeout for one CDP endpoint probe (http endpoints answer /json/version)."),
|
|
@@ -2442,6 +2644,7 @@ const Config$1 = z.object({
|
|
|
2442
2644
|
localHeadless: z.boolean().description("Run the locally launched browser headless."),
|
|
2443
2645
|
remoteEnabled: z.boolean().description("Master switch for REMOTE attach. Off = the configured target sequence is preserved but inert (nothing probes or connects remotely); flip back on any time. Does not affect cdpMode=local.").volatile(),
|
|
2444
2646
|
localUserDataDir: z.string().description("Profile dir for the locally launched browser. Empty = managed dir; never point at your daily Chrome profile."),
|
|
2647
|
+
lightpandaArgs: z.string().description("Extra args appended to a managed `lightpanda serve` argv. --host/--port are managed and cannot be overridden.").volatile(),
|
|
2445
2648
|
castFpsCap: z.number().min(0).max(60).step(1),
|
|
2446
2649
|
screencastQuality: z.number().min(1).max(100).step(1),
|
|
2447
2650
|
screencastMaxWidth: z.number().min(320).max(1920).step(40),
|
|
@@ -2695,6 +2898,7 @@ function resolveConfig(config = {}) {
|
|
|
2695
2898
|
legacyEgoToolNames: Boolean(config.legacyEgoToolNames),
|
|
2696
2899
|
localHeadless: config.localHeadless === void 0 ? false : Boolean(config.localHeadless),
|
|
2697
2900
|
localUserDataDir: typeof config.localUserDataDir === "string" ? config.localUserDataDir : "",
|
|
2901
|
+
lightpandaArgs: trimmed(config.lightpandaArgs),
|
|
2698
2902
|
remoteEnabled: config.remoteEnabled === void 0 ? true : Boolean(config.remoteEnabled),
|
|
2699
2903
|
jevUrl: trimmed(config.jevUrl),
|
|
2700
2904
|
jevKey: trimmed(config.jevKey),
|
|
@@ -2724,7 +2928,8 @@ function normalizeProbeState(link) {
|
|
|
2724
2928
|
probeLatencyMs: typeof link.probeLatencyMs === "number" && Number.isFinite(link.probeLatencyMs) ? link.probeLatencyMs : 0,
|
|
2725
2929
|
probeError: typeof link.probeError === "string" ? link.probeError : "",
|
|
2726
2930
|
probeCode: typeof link.probeCode === "string" ? link.probeCode : "",
|
|
2727
|
-
probeAt: typeof link.probeAt === "number" && Number.isFinite(link.probeAt) ? link.probeAt : 0
|
|
2931
|
+
probeAt: typeof link.probeAt === "number" && Number.isFinite(link.probeAt) ? link.probeAt : 0,
|
|
2932
|
+
probeEngine: link.probeEngine === "chrome" || link.probeEngine === "lightpanda" ? link.probeEngine : "unknown"
|
|
2728
2933
|
};
|
|
2729
2934
|
}
|
|
2730
2935
|
|
|
@@ -2823,9 +3028,10 @@ function registerEgoBrowserGateway(ctx, bridge, ffmpegManager, picks) {
|
|
|
2823
3028
|
cache: defaultAttachCache,
|
|
2824
3029
|
cliIo: createSubprocessCliIo(ctx.subprocess),
|
|
2825
3030
|
sdkPath: fileURLToPath(new URL("../runtime/ego-browser/dist/out/index.js", import.meta.url)),
|
|
2826
|
-
bundledCli: fileURLToPath(new URL("../runtime/ego-linux/bin/ego-browser.mjs", import.meta.url))
|
|
3031
|
+
bundledCli: fileURLToPath(new URL("../runtime/ego-linux/bin/ego-browser.mjs", import.meta.url)),
|
|
3032
|
+
lightpandaArgs: cfg.lightpandaArgs
|
|
2827
3033
|
});
|
|
2828
|
-
if (setAttachEndpoint(attach.status === "ready" && attach.wsUrl !== "" ? attach.wsUrl : null)) recycleWorker("cdp manual refresh").catch(() => null);
|
|
3034
|
+
if (setAttachEndpoint(attach.status === "ready" && attach.wsUrl !== "" ? attach.wsUrl : null, attach.status === "ready" ? attach.engine ?? "unknown" : null)) recycleWorker("cdp manual refresh").catch(() => null);
|
|
2829
3035
|
writeJson(res, 200, envelopeOk({ attach }));
|
|
2830
3036
|
} else if (method === "cdp-probe") {
|
|
2831
3037
|
const endpoint = typeof body.endpoint === "string" ? body.endpoint : "";
|
|
@@ -2935,8 +3141,8 @@ function envelopeError(code, message) {
|
|
|
2935
3141
|
* add/change a tool, remember to sync an entry here or bcdp_help won't find it.
|
|
2936
3142
|
*/
|
|
2937
3143
|
const EGO_HELP_INDEX = {
|
|
2938
|
-
overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、bcdp_cli/bcdp_script(自由脚本逃生舱)。连接与激活见 topic=links。分类见: tools / navigate / observe / input / keyboard-mouse / form / wait / network / login / script / doctor。用 `topic` 查询,或直接给工具名。",
|
|
2939
|
-
tools: "工具清单: bcdp_status, bcdp_space_open, bcdp_space_close, bcdp_snapshot, bcdp_navigate, bcdp_click(+double), bcdp_fill, bcdp_js, bcdp_cdp, bcdp_screenshot(+selector), bcdp_page_info, bcdp_wait, bcdp_wait_for_selector, bcdp_wait_for_url, bcdp_wait_for_response, bcdp_key(+text/type), bcdp_hover, bcdp_read_element, bcdp_select, bcdp_drag, bcdp_scroll, bcdp_upload, bcdp_check, bcdp_dialog, bcdp_download, bcdp_http, bcdp_captcha, bcdp_auth_flush, bcdp_login_import, bcdp_help, bcdp_doctor, bcdp_cli, bcdp_script, bcdp_jev_status, bcdp_jev_frame, bcdp_jev_ask, bcdp_jev_run。",
|
|
3144
|
+
overview: "CDP 浏览器代理:结构化浏览器工具。导航/交互/观察/表单/网络/等待/键鼠皆有专项工具,另提供 bcdp_help(本索引)、bcdp_doctor(体检)、bcdp_cli/bcdp_script(自由脚本逃生舱)。连接与激活见 topic=links。分类见: tools / navigate / observe / input / keyboard-mouse / form / wait / network / login / script / doctor / lightpanda。用 `topic` 查询,或直接给工具名。",
|
|
3145
|
+
tools: "工具清单: bcdp_status, bcdp_space_open, bcdp_space_close, bcdp_snapshot, bcdp_navigate, bcdp_click(+double), bcdp_fill, bcdp_js, bcdp_cdp, bcdp_screenshot(+selector), bcdp_page_info, bcdp_wait, bcdp_wait_for_selector, bcdp_wait_for_url, bcdp_wait_for_response, bcdp_key(+text/type), bcdp_hover, bcdp_read_element, bcdp_select, bcdp_drag, bcdp_scroll, bcdp_upload, bcdp_check, bcdp_dialog, bcdp_download, bcdp_http, bcdp_captcha, bcdp_auth_flush, bcdp_login_import, bcdp_help, bcdp_doctor, bcdp_cli, bcdp_script, bcdp_jev_status, bcdp_jev_frame, bcdp_jev_attempt, bcdp_jev_ask, bcdp_jev_run。",
|
|
2940
3146
|
links: "连接序列(设置面板):有序列表,顺序即优先级,被激活的一项驱动每一次 bcdp_* 调用。两种类型——CDP 端点(注入 EGO_LINUX_CDP_URL,指向已开调试端口的浏览器)与 本机 ego CLI(不注入端点,由本机 ego CLI 直接驱动 ego-lite 浏览器;仅限本机,全局至多一条)。cdpMode: auto=按激活项;remote=仅接受 CDP 端点;local=受管本地启动器。cdpMode=remote 与「本机 ego CLI」组合会显式报 mode-kind-mismatch。remoteEnabled 只管远端 CDP,不影响本机 CLI 连接。",
|
|
2941
3147
|
navigate: "bcdp_navigate: 打开URL或切tab(同任务复用当前tab)。bcdp_wait_for_url: 等跳转(登录/分页)。",
|
|
2942
3148
|
observe: "bcdp_snapshot: 整页语义树(带[ref]/loc供点击); bcdp_page_info: url/标题/视口/滚动/对话框/人机验证; bcdp_read_element: 读单元素文本/HTML/值/属性/可见性/计数; bcdp_screenshot(+selector): 整页或元素截图。",
|
|
@@ -2949,7 +3155,8 @@ const EGO_HELP_INDEX = {
|
|
|
2949
3155
|
captcha: "bcdp_captcha: 检测页面人机验证(CAPTCHA)并返回{detected,kind}; 检测到请让用户去 ego 浏览器完成; bcdp_page_info 也附带 humanCheck。",
|
|
2950
3156
|
login: "bcdp_auth_flush: 把登录cookie落盘到ego profile; 观察窗登录引导条+『已登录,保存』按钮触发同一动作。bcdp_login_import: 从系统浏览器(Chrome/Edge/Brave)按域名导入登录cookie(source/domains/dryRun; 先dryRun看可导入项; ego浏览器须已在运行)。",
|
|
2951
3157
|
script: "bcdp_cli / bcdp_script: 原样运行任意内置运行时 heredoc 脚本(page/browser/taskSpaces/site/fetch/cdp预载)。bcdp_script额外返回 duration/timedOut。",
|
|
2952
|
-
doctor: "bcdp_doctor: 体检环境(浏览器候选、vendored runtime、状态目录、CDP
|
|
3158
|
+
doctor: "bcdp_doctor: 体检环境(浏览器候选、vendored runtime、状态目录、CDP端口、任务空间、引擎与降级清单)。",
|
|
3159
|
+
lightpanda: "Lightpanda 作为后端(无头文本渲染引擎,beta):设置面板「添加 Lightpanda(受管)」——受管 serve 行(本机单例,插件负责拉起/复用/停止;win32 经 WSL2,linux/mac 本机直装),激活后 probe 自动识别 engine 并全链降级;也可用普通 CDP 端点接已自起的 serve(http://127.0.0.1:9222)。**有头/无头与顺序语义**:CDP 端点/本机 Chrome/ego CLI 是有头类型——可人工兜底(手动输账号、过验证码),是兜底主力;Lightpanda 是无头类型——无法人工介入,只适合快速试验。顺序即优先级:把 Lightpanda 排在前面 = 快速场景优先用它;排在有头类型后面 = 有头兜底优先,Lightpanda 实际不会被启用。安装——linux/macOS:`curl -fsSL https://pkg.lightpanda.io/install.sh | bash`(装入 ~/.local/bin,确保 PATH 含它),`lightpanda serve --host 127.0.0.1 --port 9222`;Windows:无原生版,用 WSL2(管理员 `wsl --install`,WSL 内同上;WSL2 自动把端口映射到宿主 localhost)或 Docker(`docker run -d -p 127.0.0.1:9222:9222 lightpanda/browser:nightly`)。可用:navigate/js/click/fill/key/snapshot(AX树)/http/login_import 等;降级:截图=PNG 文本渲染(jev 输出带 engine/rendering 元数据);关闭:观察窗实时画面、面板点选、bcdp_download(调用即结构化报错)、auth_flush(返回 degraded)",
|
|
2953
3160
|
judge: "JEV/Laya 判定(阶段 10):机械采集「截图 + 编号 DOM + 意图 + 操作进度」→ 组装问题 → 取选择 → 执行 → 验证。判定器只能回传编号,绝不给选择器(幻觉选择器在结构上不可能)。四件套:bcdp_jev_status(先跑这个:判定链可用性 + 配置体检,不发任何请求)/ bcdp_jev_frame(采一帧,看判定器会看到什么)/bcdp_jev_ask(组装请求体;dryRun 默认 true,可指定 round=control|chapter|pick|evaluate 逐级看)/ bcdp_jev_run(跑循环,返回逐步 trace)。bcdp_jev_attempt(平的尝试循环):给 url + goal,开页后每轮选项 = DOM 候选 + end 项,判定模型在 maxActions(默认 5)预算内行动或自选 end 结束,回执含每步 anchor;判定上下文只走 DOM 树文本(模型不读截图),完成后你用 bcdp_cdp/bcdp_screenshot 按 targetId 自行核验——回执是报告不是证明。**三级缩小**:control(要不要动手,固定 5 项)→ chapter(哪个章节,按 AX 容器聚簇)→ pick(章节内哪个编号 + 风险度)。分章节不是装饰:阈值按候选数分桶,把 20 选 1 拆成「几选 1 × 几选 1」会让两轮都落在更严的桶里。单章节时不问章节轮。**判定上下文是隔离的**:只允许 INTENT / PROGRESS / FRAME / HISTORY 四段,**绝不带 agent 会话 session 前缀**;多出任何一段都会在组装时直接抛错(不靠约定,靠断言)。PROGRESS 由循环自己机械生成,不让模型写(模型写的进度是第二个人幻觉通道)。**评估开关 jevEvaluate(默认开)**:每步执行后判定器再判进度 inprogress/done/fail;fail 或「未验真的 done」不猜下一步,直接 escalate——带有序 RecoveryOption(reload 排第一,因陈旧渲染会藏住已写入的确认),交回你来恢复或停手。被操作元素会保留 class 等定位特征(只剥离检视器外壳 token)随 escalate 回传,便于恢复。**默认链路是 laya -> rule**:JEV 目前无法注册,所以默认不写它;将来可用时把 jev 加回跳序并填 URL 即可。不可用的跳**跳过不调用**(laya-api 强制鉴权无匿名分支,缺 key 必然 401),每一跳的跳过与失败都记进 trace,绝不静默回落;refuse 是结果不是异常。阈值一律用选中项概率 top(不是 confidence:后者是归一化熵,2 选 1 与 20 选 1 不可比)。设置面板键:layaUrl/layaKey/layaModel(laya 端口 8000,不是 7789)、judgePrefer、jevChunkSize、jevMaxImageBytes、jevHistoryLimit、jevArchiveImage、jevStepBudget、jevWallMs;jevUrl/jevKey/jevModel 留空即可(JEV 未开放注册)。"
|
|
2954
3161
|
};
|
|
2955
3162
|
|
|
@@ -3020,6 +3227,236 @@ function installEgoBrowserSettings(ctx, config) {
|
|
|
3020
3227
|
}
|
|
3021
3228
|
};
|
|
3022
3229
|
}
|
|
3230
|
+
function installSettingsAuto(ctx, config) {
|
|
3231
|
+
const legacySettings = ctx.settings;
|
|
3232
|
+
const legacyModule = (() => {
|
|
3233
|
+
try {
|
|
3234
|
+
return createRequire(import.meta.url)("@deepseek-ai/dsh-settings");
|
|
3235
|
+
} catch {
|
|
3236
|
+
return;
|
|
3237
|
+
}
|
|
3238
|
+
})();
|
|
3239
|
+
if (typeof legacyModule.installSettingsSection === "function" && typeof legacyModule.settingsNamespace === "function") {
|
|
3240
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3241
|
+
let current = derefVolatileConfig(config);
|
|
3242
|
+
const notify = () => {
|
|
3243
|
+
for (const listener of [...listeners]) listener();
|
|
3244
|
+
};
|
|
3245
|
+
const ns = legacyModule.settingsNamespace("dsh-browser-cdp");
|
|
3246
|
+
legacyModule.installSettingsSection(ctx, ns, Config$1, current, {
|
|
3247
|
+
setSource: (source) => {
|
|
3248
|
+
current = derefVolatileConfig((typeof source === "function" ? source() : source) ?? {});
|
|
3249
|
+
},
|
|
3250
|
+
onChange: () => {
|
|
3251
|
+
notify();
|
|
3252
|
+
}
|
|
3253
|
+
});
|
|
3254
|
+
return {
|
|
3255
|
+
source: () => current,
|
|
3256
|
+
onChange: (cb) => {
|
|
3257
|
+
listeners.add(cb);
|
|
3258
|
+
return () => {
|
|
3259
|
+
listeners.delete(cb);
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
};
|
|
3263
|
+
}
|
|
3264
|
+
if (legacySettings && typeof legacySettings.installSection === "function") {
|
|
3265
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3266
|
+
let current = derefVolatileConfig(config);
|
|
3267
|
+
const notify = () => {
|
|
3268
|
+
for (const listener of [...listeners]) listener();
|
|
3269
|
+
};
|
|
3270
|
+
legacySettings.installSection(ctx, "dsh-browser-cdp", Config$1, current, {
|
|
3271
|
+
setSource: (source) => {
|
|
3272
|
+
current = derefVolatileConfig((typeof source === "function" ? source() : source) ?? {});
|
|
3273
|
+
},
|
|
3274
|
+
onChange: () => {
|
|
3275
|
+
notify();
|
|
3276
|
+
}
|
|
3277
|
+
});
|
|
3278
|
+
return {
|
|
3279
|
+
source: () => current,
|
|
3280
|
+
onChange: (cb) => {
|
|
3281
|
+
listeners.add(cb);
|
|
3282
|
+
return () => {
|
|
3283
|
+
listeners.delete(cb);
|
|
3284
|
+
};
|
|
3285
|
+
}
|
|
3286
|
+
};
|
|
3287
|
+
}
|
|
3288
|
+
return installEgoBrowserSettings(ctx, config);
|
|
3289
|
+
}
|
|
3290
|
+
const SETTINGS_BRIDGE_NS = "dsh-browser-cdp";
|
|
3291
|
+
function bridgeSendJson(res, code, body) {
|
|
3292
|
+
res.writeHead(code, {
|
|
3293
|
+
"content-type": "application/json; charset=utf-8",
|
|
3294
|
+
"cache-control": "no-cache"
|
|
3295
|
+
});
|
|
3296
|
+
res.end(JSON.stringify(body));
|
|
3297
|
+
}
|
|
3298
|
+
function bridgeReadJson(req) {
|
|
3299
|
+
return new Promise((resolve$1, reject) => {
|
|
3300
|
+
const chunks = [];
|
|
3301
|
+
let size = 0;
|
|
3302
|
+
req.on("data", (chunk) => {
|
|
3303
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
3304
|
+
size += buf.length;
|
|
3305
|
+
if (size > 256 * 1024) {
|
|
3306
|
+
reject(/* @__PURE__ */ new Error("bridge body too large"));
|
|
3307
|
+
if (typeof req.resume === "function") req.resume();
|
|
3308
|
+
return;
|
|
3309
|
+
}
|
|
3310
|
+
chunks.push(buf);
|
|
3311
|
+
});
|
|
3312
|
+
req.on("end", () => {
|
|
3313
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
3314
|
+
if (raw === "") {
|
|
3315
|
+
resolve$1({});
|
|
3316
|
+
return;
|
|
3317
|
+
}
|
|
3318
|
+
try {
|
|
3319
|
+
resolve$1(JSON.parse(raw));
|
|
3320
|
+
} catch (e) {
|
|
3321
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
3322
|
+
}
|
|
3323
|
+
});
|
|
3324
|
+
req.on("error", reject);
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
function bridgeDescribeNs(svc, ns) {
|
|
3328
|
+
return svc.describe({ redactSecrets: true }).find((d) => d.ns === ns);
|
|
3329
|
+
}
|
|
3330
|
+
/**
|
|
3331
|
+
* 注册 /api/dsh-browser-cdp/settings/{describe,mutate} 两端点(kind:'exact')。
|
|
3332
|
+
* 宿主 settings 服务经惰性 ctx.get 取(cordis get 永不 throw;服务未解析时
|
|
3333
|
+
* describe 回 settings-unavailable,client 桥按瞬态重试)。webServer 缺席的
|
|
3334
|
+
* 宿主(TUI/headless)整段 no-op。
|
|
3335
|
+
*/
|
|
3336
|
+
function registerSettingsBridge(wctx, ctx) {
|
|
3337
|
+
const ws = wctx;
|
|
3338
|
+
if (!ws || typeof ws.register !== "function") return;
|
|
3339
|
+
const c = ctx;
|
|
3340
|
+
const getSettingsSvc = () => {
|
|
3341
|
+
try {
|
|
3342
|
+
return typeof c?.get === "function" ? c.get("settings") : void 0;
|
|
3343
|
+
} catch {
|
|
3344
|
+
return;
|
|
3345
|
+
}
|
|
3346
|
+
};
|
|
3347
|
+
ws.register({
|
|
3348
|
+
kind: "exact",
|
|
3349
|
+
path: `/api/${SETTINGS_BRIDGE_NS}/settings/describe`,
|
|
3350
|
+
handler: (req, res) => {
|
|
3351
|
+
if (req.method !== "POST") {
|
|
3352
|
+
bridgeSendJson(res, 405, {
|
|
3353
|
+
ok: false,
|
|
3354
|
+
code: "method-not-allowed"
|
|
3355
|
+
});
|
|
3356
|
+
return;
|
|
3357
|
+
}
|
|
3358
|
+
const svc = getSettingsSvc();
|
|
3359
|
+
if (!svc || typeof svc.describe !== "function") {
|
|
3360
|
+
bridgeSendJson(res, 200, {
|
|
3361
|
+
ok: false,
|
|
3362
|
+
code: "settings-unavailable",
|
|
3363
|
+
message: "settings service not resolved yet"
|
|
3364
|
+
});
|
|
3365
|
+
return;
|
|
3366
|
+
}
|
|
3367
|
+
try {
|
|
3368
|
+
const descriptor = bridgeDescribeNs(svc, SETTINGS_BRIDGE_NS);
|
|
3369
|
+
if (descriptor === void 0) {
|
|
3370
|
+
bridgeSendJson(res, 200, {
|
|
3371
|
+
ok: false,
|
|
3372
|
+
code: "ns-not-registered",
|
|
3373
|
+
message: `settings namespace "${SETTINGS_BRIDGE_NS}" is not registered`
|
|
3374
|
+
});
|
|
3375
|
+
return;
|
|
3376
|
+
}
|
|
3377
|
+
bridgeSendJson(res, 200, {
|
|
3378
|
+
ok: true,
|
|
3379
|
+
value: {
|
|
3380
|
+
descriptor,
|
|
3381
|
+
writable: svc.writable !== false
|
|
3382
|
+
}
|
|
3383
|
+
});
|
|
3384
|
+
} catch (e) {
|
|
3385
|
+
bridgeSendJson(res, 200, {
|
|
3386
|
+
ok: false,
|
|
3387
|
+
code: "internal",
|
|
3388
|
+
message: e instanceof Error ? e.message : String(e)
|
|
3389
|
+
});
|
|
3390
|
+
}
|
|
3391
|
+
}
|
|
3392
|
+
});
|
|
3393
|
+
ws.register({
|
|
3394
|
+
kind: "exact",
|
|
3395
|
+
path: `/api/${SETTINGS_BRIDGE_NS}/settings/mutate`,
|
|
3396
|
+
handler: (req, res) => {
|
|
3397
|
+
if (req.method !== "POST") {
|
|
3398
|
+
bridgeSendJson(res, 405, {
|
|
3399
|
+
ok: false,
|
|
3400
|
+
code: "method-not-allowed"
|
|
3401
|
+
});
|
|
3402
|
+
return;
|
|
3403
|
+
}
|
|
3404
|
+
const svc = getSettingsSvc();
|
|
3405
|
+
if (!svc || typeof svc.mutate !== "function") {
|
|
3406
|
+
bridgeSendJson(res, 200, {
|
|
3407
|
+
ok: false,
|
|
3408
|
+
code: "settings-unavailable",
|
|
3409
|
+
message: "settings service mutate not available"
|
|
3410
|
+
});
|
|
3411
|
+
return;
|
|
3412
|
+
}
|
|
3413
|
+
bridgeReadJson(req).then((body) => {
|
|
3414
|
+
const ops = body?.ops;
|
|
3415
|
+
if (!(Array.isArray(ops) && ops.every((op) => op !== null && typeof op === "object" && (op.op === "set" || op.op === "unset")))) {
|
|
3416
|
+
bridgeSendJson(res, 200, {
|
|
3417
|
+
ok: false,
|
|
3418
|
+
code: "settings-rejected",
|
|
3419
|
+
message: "malformed bridge mutate ops"
|
|
3420
|
+
});
|
|
3421
|
+
return;
|
|
3422
|
+
}
|
|
3423
|
+
const expectedRevision = typeof body.expectedRevision === "number" ? body.expectedRevision : void 0;
|
|
3424
|
+
Promise.resolve(svc.mutate(SETTINGS_BRIDGE_NS, ops, expectedRevision)).then(() => {
|
|
3425
|
+
const descriptor = bridgeDescribeNs(svc, SETTINGS_BRIDGE_NS);
|
|
3426
|
+
if (descriptor === void 0) {
|
|
3427
|
+
bridgeSendJson(res, 200, {
|
|
3428
|
+
ok: false,
|
|
3429
|
+
code: "internal",
|
|
3430
|
+
message: `namespace "${SETTINGS_BRIDGE_NS}" disposed after mutate`
|
|
3431
|
+
});
|
|
3432
|
+
return;
|
|
3433
|
+
}
|
|
3434
|
+
bridgeSendJson(res, 200, {
|
|
3435
|
+
ok: true,
|
|
3436
|
+
value: { descriptor }
|
|
3437
|
+
});
|
|
3438
|
+
}).catch((e) => {
|
|
3439
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
3440
|
+
bridgeSendJson(res, 200, e instanceof Error && /conflict|revision/i.test(msg) ? {
|
|
3441
|
+
ok: false,
|
|
3442
|
+
code: "settings-conflict",
|
|
3443
|
+
message: msg
|
|
3444
|
+
} : {
|
|
3445
|
+
ok: false,
|
|
3446
|
+
code: "internal",
|
|
3447
|
+
message: msg
|
|
3448
|
+
});
|
|
3449
|
+
});
|
|
3450
|
+
}).catch((e) => {
|
|
3451
|
+
bridgeSendJson(res, 200, {
|
|
3452
|
+
ok: false,
|
|
3453
|
+
code: "bad-request",
|
|
3454
|
+
message: e instanceof Error ? e.message : String(e)
|
|
3455
|
+
});
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
});
|
|
3459
|
+
}
|
|
3023
3460
|
|
|
3024
3461
|
//#endregion
|
|
3025
3462
|
//#region src/ffmpeg-manifest.ts
|
|
@@ -5014,6 +5451,7 @@ function readAll$1(reader) {
|
|
|
5014
5451
|
function makeJudgeEffects(deps) {
|
|
5015
5452
|
const frames = [];
|
|
5016
5453
|
let sequence = 0;
|
|
5454
|
+
const caps = capabilitiesFor(deps.engine ?? "unknown");
|
|
5017
5455
|
let numbering = /* @__PURE__ */ new Map();
|
|
5018
5456
|
let error = "";
|
|
5019
5457
|
const captureWithWorker = async () => {
|
|
@@ -5024,8 +5462,8 @@ function makeJudgeEffects(deps) {
|
|
|
5024
5462
|
steps: [{
|
|
5025
5463
|
method: "capture",
|
|
5026
5464
|
params: {
|
|
5027
|
-
format:
|
|
5028
|
-
quality: 72,
|
|
5465
|
+
format: caps.imageFormat,
|
|
5466
|
+
...caps.imageFormat === "jpeg" ? { quality: 72 } : {},
|
|
5029
5467
|
maxBytes: deps.maxImageBytes,
|
|
5030
5468
|
limit: deps.candidateLimit,
|
|
5031
5469
|
marks: true
|
|
@@ -5062,7 +5500,7 @@ function makeJudgeEffects(deps) {
|
|
|
5062
5500
|
target,
|
|
5063
5501
|
viewport: reply.viewport,
|
|
5064
5502
|
image: {
|
|
5065
|
-
format:
|
|
5503
|
+
format: caps.imageFormat,
|
|
5066
5504
|
bytes: reply.bytes,
|
|
5067
5505
|
dataBase64: reply.data,
|
|
5068
5506
|
quality: reply.quality,
|
|
@@ -6386,7 +6824,11 @@ const messageOf = (error) => error instanceof Error ? error.message : String(err
|
|
|
6386
6824
|
//#endregion
|
|
6387
6825
|
//#region src/index.ts
|
|
6388
6826
|
const name = "dsh-browser-cdp";
|
|
6389
|
-
const inject = [
|
|
6827
|
+
const inject = [
|
|
6828
|
+
"tools",
|
|
6829
|
+
"subprocess",
|
|
6830
|
+
"settings"
|
|
6831
|
+
];
|
|
6390
6832
|
const Config = Config$1;
|
|
6391
6833
|
/** Vendored ego-linux CLI shipped inside this plugin (runtime/ego-linux/bin/). */
|
|
6392
6834
|
const VENDORED_EGO_BIN = fileURLToPath(new URL("../runtime/ego-linux/bin/ego-browser.mjs", import.meta.url));
|
|
@@ -6854,6 +7296,13 @@ function defineEgoTool(ctx, cfg, opts) {
|
|
|
6854
7296
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
6855
7297
|
execute: async (args, exec) => withEgoLock(async () => {
|
|
6856
7298
|
markEgoToolCall(callingSessionId(exec));
|
|
7299
|
+
if (typeof opts.gate === "function") {
|
|
7300
|
+
const blocked = opts.gate(args);
|
|
7301
|
+
if (blocked !== null && blocked !== "") return {
|
|
7302
|
+
ok: false,
|
|
7303
|
+
text: blocked
|
|
7304
|
+
};
|
|
7305
|
+
}
|
|
6857
7306
|
const result = await runWithStaleSpaceRetry(ctx, cfg, exec, () => opts.buildScript(args));
|
|
6858
7307
|
if (!result.ok) throw new Error(result.error);
|
|
6859
7308
|
if (typeof opts.afterExecute === "function") opts.afterExecute(args, result.value);
|
|
@@ -6868,7 +7317,7 @@ function defineEgoTool(ctx, cfg, opts) {
|
|
|
6868
7317
|
});
|
|
6869
7318
|
}
|
|
6870
7319
|
function apply(ctx, config = {}) {
|
|
6871
|
-
const bridge =
|
|
7320
|
+
const bridge = installSettingsAuto(ctx, config);
|
|
6872
7321
|
const ffmpegManager = getSharedFfmpegInstallationManager();
|
|
6873
7322
|
const initialFfmpegConfig = resolveConfig(bridge.source());
|
|
6874
7323
|
ffmpegManager.check({
|
|
@@ -6978,6 +7427,9 @@ function apply(ctx, config = {}) {
|
|
|
6978
7427
|
get localUserDataDir() {
|
|
6979
7428
|
return resolveConfig(bridge.source()).localUserDataDir;
|
|
6980
7429
|
},
|
|
7430
|
+
get lightpandaArgs() {
|
|
7431
|
+
return resolveConfig(bridge.source()).lightpandaArgs;
|
|
7432
|
+
},
|
|
6981
7433
|
get jevUrl() {
|
|
6982
7434
|
return judgeSettingsOf(resolveConfig(bridge.source())).jevUrl;
|
|
6983
7435
|
},
|
|
@@ -7068,11 +7520,12 @@ function apply(ctx, config = {}) {
|
|
|
7068
7520
|
},
|
|
7069
7521
|
remoteEnabled: resolved.remoteEnabled,
|
|
7070
7522
|
useLauncher: true,
|
|
7523
|
+
lightpandaArgs: resolved.lightpandaArgs,
|
|
7071
7524
|
cliIo: createSubprocessCliIo(ctx.subprocess),
|
|
7072
7525
|
sdkPath: fileURLToPath(new URL("../runtime/ego-browser/dist/out/index.js", import.meta.url)),
|
|
7073
7526
|
bundledCli: VENDORED_EGO_BIN
|
|
7074
7527
|
});
|
|
7075
|
-
if (setAttachEndpoint(attach.status === "ready" && attach.wsUrl !== "" ? attach.wsUrl : null)) recycleWorker("cdp activation change").catch(() => null);
|
|
7528
|
+
if (setAttachEndpoint(attach.status === "ready" && attach.wsUrl !== "" ? attach.wsUrl : null, attach.status === "ready" ? attach.engine ?? "unknown" : null)) recycleWorker("cdp activation change").catch(() => null);
|
|
7076
7529
|
} catch {} finally {
|
|
7077
7530
|
inFlight = false;
|
|
7078
7531
|
if (pending) {
|
|
@@ -7115,6 +7568,11 @@ function apply(ctx, config = {}) {
|
|
|
7115
7568
|
} catch (err) {
|
|
7116
7569
|
ctx.logger?.warn?.(`dsh-browser-cdp: capability gateway init failed: ${err?.message ?? err}`);
|
|
7117
7570
|
}
|
|
7571
|
+
try {
|
|
7572
|
+
registerSettingsBridge(wctx, ctx);
|
|
7573
|
+
} catch (err) {
|
|
7574
|
+
ctx.logger?.warn?.(`dsh-browser-cdp: settings bridge init failed: ${err?.message ?? err}`);
|
|
7575
|
+
}
|
|
7118
7576
|
});
|
|
7119
7577
|
ctx.effect?.(() => {
|
|
7120
7578
|
if (cfg.idleTimeoutMin <= 0) return;
|
|
@@ -7126,7 +7584,7 @@ function apply(ctx, config = {}) {
|
|
|
7126
7584
|
if (!shouldReapBrowser(Date.now(), last, cfg.idleTimeoutMin)) return;
|
|
7127
7585
|
if (last <= reapedFor) return;
|
|
7128
7586
|
try {
|
|
7129
|
-
const { localBrowserInfo, stopLocalBrowser: stopLocalBrowser$1 } = await import("./launcher-
|
|
7587
|
+
const { localBrowserInfo, stopLocalBrowser: stopLocalBrowser$1 } = await import("./launcher-h0Ca5NV1.js");
|
|
7130
7588
|
if (localBrowserInfo()) {
|
|
7131
7589
|
await stopLocalBrowser$1();
|
|
7132
7590
|
ctx.logger?.info?.("dsh-browser-cdp: idle reaper stopped the locally launched browser");
|
|
@@ -7267,6 +7725,7 @@ function registerAuthFlush(ctx, cfg, reg) {
|
|
|
7267
7725
|
},
|
|
7268
7726
|
total: { type: "integer" },
|
|
7269
7727
|
flushed: { type: "integer" },
|
|
7728
|
+
degraded: { type: "boolean" },
|
|
7270
7729
|
error: { type: "string" }
|
|
7271
7730
|
}
|
|
7272
7731
|
},
|
|
@@ -7297,11 +7756,16 @@ function registerAuthFlush(ctx, cfg, reg) {
|
|
|
7297
7756
|
body: "{}",
|
|
7298
7757
|
signal: AbortSignal.timeout(8e3)
|
|
7299
7758
|
})).json();
|
|
7759
|
+
const degraded = defaultAttachCache.get().engine === "lightpanda";
|
|
7300
7760
|
return {
|
|
7301
|
-
ok: !!jbody.ok,
|
|
7761
|
+
ok: !!jbody.ok && !degraded,
|
|
7302
7762
|
total: jbody.total ?? 0,
|
|
7303
7763
|
flushed: jbody.flushed ?? 0,
|
|
7304
|
-
|
|
7764
|
+
...degraded ? {
|
|
7765
|
+
degraded: true,
|
|
7766
|
+
error: "engine-unsupported: Lightpanda has no Storage.flushCookies — cookies persist only while the engine process is alive"
|
|
7767
|
+
} : {},
|
|
7768
|
+
...!degraded && jbody.error !== void 0 ? { error: jbody.error } : {}
|
|
7305
7769
|
};
|
|
7306
7770
|
} catch (err) {
|
|
7307
7771
|
return {
|
|
@@ -7899,6 +8363,7 @@ function registerActionTools(ctx, cfg, reg) {
|
|
|
7899
8363
|
},
|
|
7900
8364
|
space: spaceParam
|
|
7901
8365
|
},
|
|
8366
|
+
gate: () => defaultAttachCache.get().engine === "lightpanda" ? "engine-unsupported: the attached browser is Lightpanda, which has no Page download events — bcdp_download cannot capture files on this engine. Trigger the download another way (e.g. fetch() the URL in-page and return the bytes)." : null,
|
|
7902
8367
|
buildScript: (args) => {
|
|
7903
8368
|
const sel = str(args.triggerSelector, "");
|
|
7904
8369
|
const script = str(args.triggerScript, "");
|
|
@@ -8065,7 +8530,9 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
|
8065
8530
|
type: "boolean",
|
|
8066
8531
|
required: true
|
|
8067
8532
|
},
|
|
8068
|
-
kind: { oneOf: [{ type: "string" }, { type: "null" }] }
|
|
8533
|
+
kind: { oneOf: [{ type: "string" }, { type: "null" }] },
|
|
8534
|
+
engine: { type: "string" },
|
|
8535
|
+
rendering: { type: "string" }
|
|
8069
8536
|
}
|
|
8070
8537
|
},
|
|
8071
8538
|
render: renderText
|
|
@@ -8084,7 +8551,11 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
|
8084
8551
|
return {
|
|
8085
8552
|
ok: true,
|
|
8086
8553
|
detected: !!hc?.detected,
|
|
8087
|
-
kind: hc?.kind ?? null
|
|
8554
|
+
kind: hc?.kind ?? null,
|
|
8555
|
+
...defaultAttachCache.get().engine === "lightpanda" ? {
|
|
8556
|
+
engine: "lightpanda",
|
|
8557
|
+
rendering: "text"
|
|
8558
|
+
} : {}
|
|
8088
8559
|
};
|
|
8089
8560
|
}),
|
|
8090
8561
|
presentCall: () => ({
|
|
@@ -8180,9 +8651,16 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
|
8180
8651
|
const attachNow = defaultAttachCache.get();
|
|
8181
8652
|
lines.push(`remote CDP: ${cfg.remoteEnabled === false ? "DISABLED by switch (sequence preserved)" : "enabled"}`);
|
|
8182
8653
|
lines.push(`attach: ${attachNow.status}${attachNow.endpointSource ? ` (source: ${attachNow.endpointSource})` : ""}${attachNow.endpoint ? ` @ ${attachNow.endpoint}` : ""}`);
|
|
8654
|
+
if (attachNow.engine !== void 0) lines.push(`engine: ${attachNow.engine}`);
|
|
8655
|
+
if (attachNow.engine === "lightpanda") lines.push("degraded on this engine: live view (no screencast) · panel pick (no Overlay/bindingCalled) · bcdp_download (no Page download events) · screenshots are PNG text-renders · auth_flush is a no-op");
|
|
8656
|
+
if (attachNow.engine === "lightpanda" || process.platform === "win32") lines.push(process.platform === "win32" ? "lightpanda on win32: no native build — use WSL2: `wsl --install` (admin), then inside WSL: `curl -fsSL https://pkg.lightpanda.io/install.sh | bash` + `lightpanda serve --host 127.0.0.1 --port 9222`; WSL2 maps the port to Windows localhost, then add http://127.0.0.1:9222 as a CDP endpoint. Docker alternative: `docker run -d -p 127.0.0.1:9222:9222 lightpanda/browser:nightly`." : "lightpanda (linux/macOS): `curl -fsSL https://pkg.lightpanda.io/install.sh | bash` (installs to ~/.local/bin) then `lightpanda serve --host 127.0.0.1 --port 9222`.");
|
|
8183
8657
|
const kindCount = (kind) => cfg.links.filter((link) => link.kind === kind).length;
|
|
8184
8658
|
const dropped = cfg.droppedEgoCli;
|
|
8185
|
-
lines.push(`links: ${cfg.links.length} (cdp ${kindCount("cdp")}, ego-cli ${kindCount(EGO_CLI_KIND)})${dropped > 0 ? ` — ${dropped} extra ego-cli row(s) dropped (local-only singleton)` : ""}`);
|
|
8659
|
+
lines.push(`links: ${cfg.links.length} (cdp ${kindCount("cdp")}, ego-cli ${kindCount(EGO_CLI_KIND)}, lightpanda ${kindCount(LP_KIND)})${dropped > 0 ? ` — ${dropped} extra ego-cli row(s) dropped (local-only singleton)` : ""}`);
|
|
8660
|
+
if (kindCount(LP_KIND) > 0) {
|
|
8661
|
+
const lpRow = cfg.links.find((link) => link.kind === LP_KIND);
|
|
8662
|
+
lines.push(`lightpanda row: servePath=${lpRow?.servePath === void 0 || lpRow.servePath === "" ? "(auto: PATH → ~/.local/bin; win32 via WSL2)" : lpRow.servePath} — headless quick-trial engine; headed kinds (CDP / local Chrome / ego CLI) are the manual-fallback backstop`);
|
|
8663
|
+
}
|
|
8186
8664
|
const cliLink = cfg.links.find((link) => link.kind === EGO_CLI_KIND);
|
|
8187
8665
|
if (cliLink && cliLink.kind === EGO_CLI_KIND) {
|
|
8188
8666
|
const resolved = resolveCliBinary({
|
|
@@ -8374,6 +8852,7 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
|
8374
8852
|
workerPath: RENDER_WORKER_BIN,
|
|
8375
8853
|
wsUrl: attach.wsUrl,
|
|
8376
8854
|
targetId: attach.targetId,
|
|
8855
|
+
...attach.engine === void 0 ? {} : { engine: attach.engine },
|
|
8377
8856
|
judge,
|
|
8378
8857
|
maxImageBytes: cfg.jevMaxImageBytes,
|
|
8379
8858
|
candidateLimit: cfg.jevChunkSize,
|
|
@@ -8662,6 +9141,7 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
|
8662
9141
|
workerPath: RENDER_WORKER_BIN,
|
|
8663
9142
|
wsUrl: defaultAttachCache.get().wsUrl,
|
|
8664
9143
|
targetId: defaultAttachCache.get().targetId,
|
|
9144
|
+
engine: defaultAttachCache.get().engine,
|
|
8665
9145
|
judge: judgeRuntimeOf(),
|
|
8666
9146
|
maxImageBytes: num(args.maxBytes, judge.maxImageBytes),
|
|
8667
9147
|
candidateLimit: num(args.limit, judge.chunkSize),
|
|
@@ -8686,6 +9166,7 @@ function registerHelpAndDoctor(ctx, cfg, reg) {
|
|
|
8686
9166
|
`budget : ${frame.image === null || frame.image.maxBytes === 0 ? "unbounded" : frame.image.maxBytes + " B"}${frame.image?.overBudget === true ? " *** OVER BUDGET ***" : ""}`,
|
|
8687
9167
|
`candidates : ${frame.dom.nodes.length} of ${frame.dom.total}${frame.dom.truncated ? " (TRUNCATED)" : ""}`
|
|
8688
9168
|
];
|
|
9169
|
+
if (defaultAttachCache.get().engine === "lightpanda") lines.push(`engine : lightpanda (rendering: text — screenshot fidelity differs from Chrome)`);
|
|
8689
9170
|
if (frame.image?.overBudget === true) lines.push("", "The image exceeded the byte budget even at floor quality. Raise jevMaxImageBytes, or accept it and let the count drive chunking.");
|
|
8690
9171
|
if (bool(args.showCandidates, true)) {
|
|
8691
9172
|
lines.push("", "── candidates (the judge answers with these numbers) ──");
|