@chosengeneration/light-code 0.201.0 → 0.203.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +116 -113
- package/dist/server.cjs +111 -108
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -437,7 +437,7 @@ var require_util = __commonJS({
|
|
|
437
437
|
var { kDestroyed, kBodyUsed } = require_symbols();
|
|
438
438
|
var { IncomingMessage } = require("http");
|
|
439
439
|
var stream = require("stream");
|
|
440
|
-
var
|
|
440
|
+
var net = require("net");
|
|
441
441
|
var { InvalidArgumentError } = require_errors();
|
|
442
442
|
var { Blob: Blob2 } = require("buffer");
|
|
443
443
|
var nodeUtil = require("util");
|
|
@@ -528,7 +528,7 @@ var require_util = __commonJS({
|
|
|
528
528
|
}
|
|
529
529
|
assert2.strictEqual(typeof host, "string");
|
|
530
530
|
const servername = getHostname(host);
|
|
531
|
-
if (
|
|
531
|
+
if (net.isIP(servername)) {
|
|
532
532
|
return "";
|
|
533
533
|
}
|
|
534
534
|
return servername;
|
|
@@ -3278,7 +3278,7 @@ var require_util2 = __commonJS({
|
|
|
3278
3278
|
}
|
|
3279
3279
|
break;
|
|
3280
3280
|
case "same-origin":
|
|
3281
|
-
if (!
|
|
3281
|
+
if (!sameOrigin2(request2, requestCurrentURL(request2))) {
|
|
3282
3282
|
serializedOrigin = null;
|
|
3283
3283
|
}
|
|
3284
3284
|
break;
|
|
@@ -3335,7 +3335,7 @@ var require_util2 = __commonJS({
|
|
|
3335
3335
|
if (referrerURL.toString().length > 4096) {
|
|
3336
3336
|
referrerURL = referrerOrigin;
|
|
3337
3337
|
}
|
|
3338
|
-
const areSameOrigin =
|
|
3338
|
+
const areSameOrigin = sameOrigin2(request2, referrerURL);
|
|
3339
3339
|
const isNonPotentiallyTrustWorthy = isURLPotentiallyTrustworthy(referrerURL) && !isURLPotentiallyTrustworthy(request2.url);
|
|
3340
3340
|
switch (policy) {
|
|
3341
3341
|
case "origin":
|
|
@@ -3348,7 +3348,7 @@ var require_util2 = __commonJS({
|
|
|
3348
3348
|
return areSameOrigin ? referrerURL : referrerOrigin;
|
|
3349
3349
|
case "strict-origin-when-cross-origin": {
|
|
3350
3350
|
const currentURL = requestCurrentURL(request2);
|
|
3351
|
-
if (
|
|
3351
|
+
if (sameOrigin2(referrerURL, currentURL)) {
|
|
3352
3352
|
return referrerURL;
|
|
3353
3353
|
}
|
|
3354
3354
|
if (isURLPotentiallyTrustworthy(referrerURL) && !isURLPotentiallyTrustworthy(currentURL)) {
|
|
@@ -3509,7 +3509,7 @@ var require_util2 = __commonJS({
|
|
|
3509
3509
|
}
|
|
3510
3510
|
function tryUpgradeRequestToAPotentiallyTrustworthyURL(request2) {
|
|
3511
3511
|
}
|
|
3512
|
-
function
|
|
3512
|
+
function sameOrigin2(A, B) {
|
|
3513
3513
|
if (A.origin === B.origin && A.origin === "null") {
|
|
3514
3514
|
return true;
|
|
3515
3515
|
}
|
|
@@ -3712,7 +3712,7 @@ var require_util2 = __commonJS({
|
|
|
3712
3712
|
isBlobLike,
|
|
3713
3713
|
isURLPotentiallyTrustworthy,
|
|
3714
3714
|
isValidReasonPhrase,
|
|
3715
|
-
sameOrigin,
|
|
3715
|
+
sameOrigin: sameOrigin2,
|
|
3716
3716
|
normalizeMethod,
|
|
3717
3717
|
serializeJavascriptValueToJSONString,
|
|
3718
3718
|
makeIterator,
|
|
@@ -5682,7 +5682,7 @@ var require_dispatcher_base = __commonJS({
|
|
|
5682
5682
|
var require_connect = __commonJS({
|
|
5683
5683
|
"../../node_modules/.pnpm/undici@5.29.0/node_modules/undici/lib/core/connect.js"(exports2, module2) {
|
|
5684
5684
|
"use strict";
|
|
5685
|
-
var
|
|
5685
|
+
var net = require("net");
|
|
5686
5686
|
var assert2 = require("assert");
|
|
5687
5687
|
var util = require_util();
|
|
5688
5688
|
var { InvalidArgumentError, ConnectTimeoutError } = require_errors();
|
|
@@ -5773,7 +5773,7 @@ var require_connect = __commonJS({
|
|
|
5773
5773
|
});
|
|
5774
5774
|
} else {
|
|
5775
5775
|
assert2(!httpSocket, "httpSocket can only be sent on TLS update");
|
|
5776
|
-
socket =
|
|
5776
|
+
socket = net.connect({
|
|
5777
5777
|
highWaterMark: 64 * 1024,
|
|
5778
5778
|
// Same as nodejs fs streams.
|
|
5779
5779
|
...options,
|
|
@@ -6366,7 +6366,7 @@ var require_client = __commonJS({
|
|
|
6366
6366
|
"../../node_modules/.pnpm/undici@5.29.0/node_modules/undici/lib/client.js"(exports2, module2) {
|
|
6367
6367
|
"use strict";
|
|
6368
6368
|
var assert2 = require("assert");
|
|
6369
|
-
var
|
|
6369
|
+
var net = require("net");
|
|
6370
6370
|
var http = require("http");
|
|
6371
6371
|
var { pipeline } = require("stream");
|
|
6372
6372
|
var util = require_util();
|
|
@@ -6558,7 +6558,7 @@ var require_client = __commonJS({
|
|
|
6558
6558
|
if (maxRequestsPerClient != null && (!Number.isInteger(maxRequestsPerClient) || maxRequestsPerClient < 0)) {
|
|
6559
6559
|
throw new InvalidArgumentError("maxRequestsPerClient must be a positive number");
|
|
6560
6560
|
}
|
|
6561
|
-
if (localAddress != null && (typeof localAddress !== "string" ||
|
|
6561
|
+
if (localAddress != null && (typeof localAddress !== "string" || net.isIP(localAddress) === 0)) {
|
|
6562
6562
|
throw new InvalidArgumentError("localAddress must be valid string IP address");
|
|
6563
6563
|
}
|
|
6564
6564
|
if (maxResponseSize != null && (!Number.isInteger(maxResponseSize) || maxResponseSize < -1)) {
|
|
@@ -7248,7 +7248,7 @@ var require_client = __commonJS({
|
|
|
7248
7248
|
const idx = hostname3.indexOf("]");
|
|
7249
7249
|
assert2(idx !== -1);
|
|
7250
7250
|
const ip = hostname3.substring(1, idx);
|
|
7251
|
-
assert2(
|
|
7251
|
+
assert2(net.isIP(ip));
|
|
7252
7252
|
hostname3 = ip;
|
|
7253
7253
|
}
|
|
7254
7254
|
client[kConnecting] = true;
|
|
@@ -11822,7 +11822,7 @@ var require_request2 = __commonJS({
|
|
|
11822
11822
|
var util = require_util();
|
|
11823
11823
|
var {
|
|
11824
11824
|
isValidHTTPToken,
|
|
11825
|
-
sameOrigin,
|
|
11825
|
+
sameOrigin: sameOrigin2,
|
|
11826
11826
|
normalizeMethod,
|
|
11827
11827
|
makePolicyContainer,
|
|
11828
11828
|
normalizeMethodRecord
|
|
@@ -11893,7 +11893,7 @@ var require_request2 = __commonJS({
|
|
|
11893
11893
|
}
|
|
11894
11894
|
const origin = this[kRealm].settingsObject.origin;
|
|
11895
11895
|
let window = "client";
|
|
11896
|
-
if (request2.window?.constructor?.name === "EnvironmentSettingsObject" &&
|
|
11896
|
+
if (request2.window?.constructor?.name === "EnvironmentSettingsObject" && sameOrigin2(request2.window, origin)) {
|
|
11897
11897
|
window = request2.window;
|
|
11898
11898
|
}
|
|
11899
11899
|
if (init.window != null) {
|
|
@@ -11969,7 +11969,7 @@ var require_request2 = __commonJS({
|
|
|
11969
11969
|
} catch (err) {
|
|
11970
11970
|
throw new TypeError(`Referrer "${referrer}" is not a valid URL.`, { cause: err });
|
|
11971
11971
|
}
|
|
11972
|
-
if (parsedReferrer.protocol === "about:" && parsedReferrer.hostname === "client" || origin && !
|
|
11972
|
+
if (parsedReferrer.protocol === "about:" && parsedReferrer.hostname === "client" || origin && !sameOrigin2(parsedReferrer, this[kRealm].settingsObject.baseUrl)) {
|
|
11973
11973
|
request2.referrer = "client";
|
|
11974
11974
|
} else {
|
|
11975
11975
|
request2.referrer = parsedReferrer;
|
|
@@ -12484,7 +12484,7 @@ var require_fetch = __commonJS({
|
|
|
12484
12484
|
coarsenedSharedCurrentTime,
|
|
12485
12485
|
createDeferredPromise,
|
|
12486
12486
|
isBlobLike,
|
|
12487
|
-
sameOrigin,
|
|
12487
|
+
sameOrigin: sameOrigin2,
|
|
12488
12488
|
isCancelled,
|
|
12489
12489
|
isAborted,
|
|
12490
12490
|
isErrorLike,
|
|
@@ -12763,7 +12763,7 @@ var require_fetch = __commonJS({
|
|
|
12763
12763
|
if (
|
|
12764
12764
|
// - request’s current URL’s origin is same origin with request’s origin,
|
|
12765
12765
|
// and request’s response tainting is "basic"
|
|
12766
|
-
|
|
12766
|
+
sameOrigin2(currentURL, request2.url) && request2.responseTainting === "basic" || // request’s current URL’s scheme is "data"
|
|
12767
12767
|
currentURL.protocol === "data:" || // - request’s mode is "navigate" or "websocket"
|
|
12768
12768
|
(request2.mode === "navigate" || request2.mode === "websocket")
|
|
12769
12769
|
) {
|
|
@@ -13022,7 +13022,7 @@ var require_fetch = __commonJS({
|
|
|
13022
13022
|
return Promise.resolve(makeNetworkError("redirect count exceeded"));
|
|
13023
13023
|
}
|
|
13024
13024
|
request2.redirectCount += 1;
|
|
13025
|
-
if (request2.mode === "cors" && (locationURL.username || locationURL.password) && !
|
|
13025
|
+
if (request2.mode === "cors" && (locationURL.username || locationURL.password) && !sameOrigin2(request2, locationURL)) {
|
|
13026
13026
|
return Promise.resolve(makeNetworkError('cross origin not allowed for request mode "cors"'));
|
|
13027
13027
|
}
|
|
13028
13028
|
if (request2.responseTainting === "cors" && (locationURL.username || locationURL.password)) {
|
|
@@ -13040,7 +13040,7 @@ var require_fetch = __commonJS({
|
|
|
13040
13040
|
request2.headersList.delete(headerName);
|
|
13041
13041
|
}
|
|
13042
13042
|
}
|
|
13043
|
-
if (!
|
|
13043
|
+
if (!sameOrigin2(requestCurrentURL(request2), locationURL)) {
|
|
13044
13044
|
request2.headersList.delete("authorization");
|
|
13045
13045
|
request2.headersList.delete("proxy-authorization", true);
|
|
13046
13046
|
request2.headersList.delete("cookie");
|
|
@@ -67124,8 +67124,6 @@ function fillBody(setup, question) {
|
|
|
67124
67124
|
}
|
|
67125
67125
|
|
|
67126
67126
|
// ../../packages/core/dist/webchat/guard.js
|
|
67127
|
-
var import_node_dns = require("node:dns");
|
|
67128
|
-
var import_node_net2 = __toESM(require("node:net"), 1);
|
|
67129
67127
|
var REQUIRED_CHROME_FLAGS = ["--no-usage-statistics", "--no-performance-crux"];
|
|
67130
67128
|
function npxPackage(args) {
|
|
67131
67129
|
for (let i = 0; i < args.length; i += 1) {
|
|
@@ -67143,7 +67141,7 @@ function npxPackage(args) {
|
|
|
67143
67141
|
function isPinned(spec) {
|
|
67144
67142
|
return /^(@[^/\s]+\/)?[^@\s]+@\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(spec);
|
|
67145
67143
|
}
|
|
67146
|
-
function chromeServerProblems(config2
|
|
67144
|
+
function chromeServerProblems(config2) {
|
|
67147
67145
|
if (config2 === void 0)
|
|
67148
67146
|
return ["No Chrome DevTools MCP server is configured."];
|
|
67149
67147
|
const record2 = config2;
|
|
@@ -67159,10 +67157,6 @@ function chromeServerProblems(config2, npmRegistry) {
|
|
|
67159
67157
|
if (spec === void 0 || !isPinned(spec)) {
|
|
67160
67158
|
problems.push(`With npx the version must be pinned (e.g. chrome-devtools-mcp@1.13.0, not ${spec ?? "no version"}), so an unreviewed new version is never run.`);
|
|
67161
67159
|
}
|
|
67162
|
-
if (npmRegistry === void 0)
|
|
67163
|
-
problems.push("npm's registry could not be checked, so npx cannot be confirmed to stay inside the network.");
|
|
67164
|
-
else if (npmRegistry.problem !== void 0)
|
|
67165
|
-
problems.push(`npx downloads from npm's registry ${npmRegistry.registry}: ${npmRegistry.problem}`);
|
|
67166
67160
|
} else if (isPackageRunnerCommand(command)) {
|
|
67167
67161
|
problems.push(`It is started with ${command}, which downloads the package each start. Use npx (with a pinned version and the organisation's registry) or an installed copy.`);
|
|
67168
67162
|
}
|
|
@@ -67194,23 +67188,7 @@ function commandWords(line) {
|
|
|
67194
67188
|
function isLoopback2(host) {
|
|
67195
67189
|
return host === "localhost" || host === "::1" || /^127\./.test(host);
|
|
67196
67190
|
}
|
|
67197
|
-
function
|
|
67198
|
-
if (import_node_net2.default.isIPv4(address)) {
|
|
67199
|
-
const [a = 0, b = 0] = address.split(".").map(Number);
|
|
67200
|
-
return a === 10 || a === 127 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254;
|
|
67201
|
-
}
|
|
67202
|
-
if (import_node_net2.default.isIPv6(address)) {
|
|
67203
|
-
const lower = address.toLowerCase();
|
|
67204
|
-
if (lower === "::1")
|
|
67205
|
-
return true;
|
|
67206
|
-
const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(lower);
|
|
67207
|
-
if (mapped !== null)
|
|
67208
|
-
return isPrivateAddress(mapped[1] ?? "");
|
|
67209
|
-
return /^f[cd][0-9a-f]{2}:/.test(lower) || /^fe[89ab][0-9a-f]:/.test(lower);
|
|
67210
|
-
}
|
|
67211
|
-
return false;
|
|
67212
|
-
}
|
|
67213
|
-
async function webChatHostProblem(pageUrl, lookup = lookupAll) {
|
|
67191
|
+
function webChatAddressProblem(pageUrl) {
|
|
67214
67192
|
let url2;
|
|
67215
67193
|
try {
|
|
67216
67194
|
url2 = new URL(pageUrl);
|
|
@@ -67219,24 +67197,8 @@ async function webChatHostProblem(pageUrl, lookup = lookupAll) {
|
|
|
67219
67197
|
}
|
|
67220
67198
|
if (url2.protocol !== "https:" && url2.protocol !== "http:")
|
|
67221
67199
|
return "The web chat address must start with https:// (or http://).";
|
|
67222
|
-
const host = url2.hostname.replace(/^\[|\]$/g, "");
|
|
67223
|
-
let addresses2;
|
|
67224
|
-
try {
|
|
67225
|
-
addresses2 = import_node_net2.default.isIP(host) !== 0 ? [host] : await lookup(host);
|
|
67226
|
-
} catch (error51) {
|
|
67227
|
-
return `${host} could not be looked up (${error51 instanceof Error ? error51.message : String(error51)}), so it cannot be confirmed to be inside the network.`;
|
|
67228
|
-
}
|
|
67229
|
-
if (addresses2.length === 0)
|
|
67230
|
-
return `${host} has no address.`;
|
|
67231
|
-
const outside = addresses2.filter((address) => !isPrivateAddress(address));
|
|
67232
|
-
if (outside.length > 0)
|
|
67233
|
-
return `${host} resolves to ${outside.join(", ")}, which is on the public internet - the web chat must be inside the bank's network, so nothing is sent.`;
|
|
67234
67200
|
return void 0;
|
|
67235
67201
|
}
|
|
67236
|
-
async function lookupAll(host) {
|
|
67237
|
-
const found2 = await import_node_dns.promises.lookup(host, { all: true });
|
|
67238
|
-
return found2.map((entry) => entry.address);
|
|
67239
|
-
}
|
|
67240
67202
|
|
|
67241
67203
|
// ../../packages/core/dist/webchat/answer.js
|
|
67242
67204
|
function leaves(value, path70, out) {
|
|
@@ -67278,7 +67240,7 @@ function sseEvents(text2) {
|
|
|
67278
67240
|
return events;
|
|
67279
67241
|
}
|
|
67280
67242
|
function findAnswer(responseText, contentType2, exclude) {
|
|
67281
|
-
const notQuestion = (text2) => text2.trim().length > 0 &&
|
|
67243
|
+
const notQuestion = (text2) => text2.trim().length > 0 && text2.split(exclude).join("").replace(/[\s"'`.,:;!?()[\]{}-]/g, "").length >= 3;
|
|
67282
67244
|
const events = (contentType2 ?? "").includes("event-stream") || /^data:/m.test(responseText) ? sseEvents(responseText) : void 0;
|
|
67283
67245
|
if (events !== void 0 && events.length > 0) {
|
|
67284
67246
|
const byPath = /* @__PURE__ */ new Map();
|
|
@@ -67471,52 +67433,80 @@ function propertyNames(schema13) {
|
|
|
67471
67433
|
const properties = schema13?.["properties"];
|
|
67472
67434
|
return properties !== null && typeof properties === "object" ? Object.keys(properties) : [];
|
|
67473
67435
|
}
|
|
67474
|
-
|
|
67475
|
-
const
|
|
67476
|
-
|
|
67477
|
-
|
|
67478
|
-
|
|
67479
|
-
|
|
67480
|
-
|
|
67481
|
-
|
|
67482
|
-
|
|
67483
|
-
|
|
67436
|
+
function pagesIn(text2) {
|
|
67437
|
+
const pages = [];
|
|
67438
|
+
for (const line of text2.split(/\r?\n/)) {
|
|
67439
|
+
const match = /^\s*(\d+)\s*:\s*(.+?)\s*$/.exec(line);
|
|
67440
|
+
if (match === null)
|
|
67441
|
+
continue;
|
|
67442
|
+
const rest = match[2] ?? "";
|
|
67443
|
+
const inBrackets = [...rest.matchAll(/\((https?:\/\/[^\s)]+)\)/g)].at(-1)?.[1];
|
|
67444
|
+
const url2 = inBrackets ?? /^(https?:\/\/\S+)/.exec(rest)?.[1];
|
|
67445
|
+
if (url2 === void 0)
|
|
67446
|
+
continue;
|
|
67447
|
+
pages.push({ id: Number(match[1]), url: url2, selected: /\[selected\]/i.test(rest) });
|
|
67448
|
+
}
|
|
67449
|
+
return pages;
|
|
67450
|
+
}
|
|
67451
|
+
function sameOrigin(url2, origin) {
|
|
67452
|
+
try {
|
|
67453
|
+
return new URL(url2).origin === origin;
|
|
67454
|
+
} catch {
|
|
67455
|
+
return false;
|
|
67456
|
+
}
|
|
67484
67457
|
}
|
|
67485
67458
|
async function selectWebChatPage(chrome, pageUrl) {
|
|
67486
67459
|
const origin = new URL(pageUrl).origin;
|
|
67487
67460
|
const listed = await chrome.call("list_pages", {});
|
|
67488
|
-
|
|
67489
|
-
|
|
67490
|
-
|
|
67491
|
-
|
|
67492
|
-
continue;
|
|
67493
|
-
try {
|
|
67494
|
-
if (new URL(match[2] ?? "").origin !== origin)
|
|
67495
|
-
continue;
|
|
67496
|
-
} catch {
|
|
67497
|
-
continue;
|
|
67498
|
-
}
|
|
67499
|
-
if (/\[selected\]/i.test(line))
|
|
67500
|
-
return;
|
|
67461
|
+
const existing = listed.isError ? [] : pagesIn(listed.text).filter((page) => sameOrigin(page.url, origin));
|
|
67462
|
+
const chosen = existing.find((page) => page.selected) ?? existing[0];
|
|
67463
|
+
if (chosen !== void 0) {
|
|
67464
|
+
if (!chosen.selected && chrome.schema("select_page") !== void 0) {
|
|
67501
67465
|
const names = propertyNames(chrome.schema("select_page"));
|
|
67502
|
-
const key4 = names.find((name) => /idx|index|id/i.test(name)) ?? "
|
|
67503
|
-
const selected = await chrome.call("select_page", { [key4]:
|
|
67466
|
+
const key4 = names.includes("pageId") ? "pageId" : names.find((name) => /idx|index|id/i.test(name)) ?? "pageId";
|
|
67467
|
+
const selected = await chrome.call("select_page", { [key4]: chosen.id });
|
|
67504
67468
|
if (selected.isError)
|
|
67505
67469
|
throw new Error(`Chrome could not select the web chat tab: ${selected.text.slice(0, 300)}`);
|
|
67506
|
-
return;
|
|
67507
67470
|
}
|
|
67471
|
+
return chosen.id;
|
|
67508
67472
|
}
|
|
67509
67473
|
const opened = await chrome.call("new_page", { url: pageUrl });
|
|
67510
67474
|
if (opened.isError)
|
|
67511
67475
|
throw new Error(`Chrome could not open ${pageUrl}: ${opened.text.slice(0, 300)}`);
|
|
67476
|
+
const now = pagesIn(opened.text).filter((page) => sameOrigin(page.url, origin));
|
|
67477
|
+
const fresh = now.find((page) => page.selected) ?? now.at(-1);
|
|
67478
|
+
if (fresh !== void 0)
|
|
67479
|
+
return fresh.id;
|
|
67480
|
+
const again = await chrome.call("list_pages", {});
|
|
67481
|
+
const found2 = again.isError ? [] : pagesIn(again.text).filter((page) => sameOrigin(page.url, origin));
|
|
67482
|
+
return (found2.find((page) => page.selected) ?? found2.at(-1))?.id;
|
|
67483
|
+
}
|
|
67484
|
+
async function runScript(chrome, source, pageId) {
|
|
67485
|
+
const names = propertyNames(chrome.schema("evaluate_script"));
|
|
67486
|
+
const key4 = names.includes("function") ? "function" : names.includes("expression") ? "expression" : names[0] ?? "function";
|
|
67487
|
+
const args = { [key4]: source };
|
|
67488
|
+
if (names.includes("pageId")) {
|
|
67489
|
+
if (pageId === void 0)
|
|
67490
|
+
throw new Error("Chrome needs the web chat tab's id, and none was found in its list of tabs.");
|
|
67491
|
+
args["pageId"] = pageId;
|
|
67492
|
+
}
|
|
67493
|
+
if (names.includes("waitForStableDom"))
|
|
67494
|
+
args["waitForStableDom"] = false;
|
|
67495
|
+
const result = await chrome.call("evaluate_script", args);
|
|
67496
|
+
if (result.isError)
|
|
67497
|
+
throw new Error(`Chrome could not run the script: ${result.text.slice(0, 400)}`);
|
|
67498
|
+
const value = result.structured ?? scriptResult(result.text);
|
|
67499
|
+
if (value === null || typeof value !== "object")
|
|
67500
|
+
throw new Error(`Chrome returned something unexpected: ${result.text.slice(0, 300)}`);
|
|
67501
|
+
return value;
|
|
67512
67502
|
}
|
|
67513
67503
|
async function askWebChat(chrome, setup, question) {
|
|
67514
67504
|
const origin = new URL(setup.pageUrl).origin;
|
|
67515
|
-
await selectWebChatPage(chrome, setup.pageUrl);
|
|
67516
|
-
const watched = await runScript(chrome, watchScript(origin, void 0));
|
|
67505
|
+
const pageId = await selectWebChatPage(chrome, setup.pageUrl);
|
|
67506
|
+
const watched = await runScript(chrome, watchScript(origin, void 0), pageId);
|
|
67517
67507
|
if (watched["ok"] !== true)
|
|
67518
67508
|
throw new Error(String(watched["error"] ?? "The web chat page could not be prepared."));
|
|
67519
|
-
const sent = await runScript(chrome, askScript(setup, question));
|
|
67509
|
+
const sent = await runScript(chrome, askScript(setup, question), pageId);
|
|
67520
67510
|
if (Array.isArray(sent["needsActivity"])) {
|
|
67521
67511
|
throw new Error(`The web chat signs its requests with ${sent["needsActivity"].join(", ")}, which Light Code takes from the page and never stores. Send any message in the web chat tab once (or reload it), then ask again.`);
|
|
67522
67512
|
}
|
|
@@ -91342,7 +91332,7 @@ ${error51.stack.split("\n").slice(1, 6).join("\n")}`;
|
|
|
91342
91332
|
child.on("close", (code) => resolve(code === 0 ? out.trim() : void 0));
|
|
91343
91333
|
setTimeout(() => child.kill(), 15e3).unref?.();
|
|
91344
91334
|
});
|
|
91345
|
-
const value = registry2 === void 0 || registry2.length === 0 ? void 0 :
|
|
91335
|
+
const value = registry2 === void 0 || registry2.length === 0 ? void 0 : registry2;
|
|
91346
91336
|
npmRegistryCheck = { at: Date.now(), value };
|
|
91347
91337
|
return value;
|
|
91348
91338
|
}
|
|
@@ -91350,13 +91340,21 @@ ${error51.stack.split("\n").slice(1, 6).join("\n")}`;
|
|
|
91350
91340
|
const config2 = mcp.serverConfig(server);
|
|
91351
91341
|
const command = config2?.command ?? "";
|
|
91352
91342
|
const npx = /(^|[\\/])npx(\.cmd)?$/i.test(command);
|
|
91353
|
-
|
|
91343
|
+
void npx;
|
|
91344
|
+
return chromeServerProblems(config2);
|
|
91345
|
+
}
|
|
91346
|
+
async function npxRegistryFor(server) {
|
|
91347
|
+
const command = mcp.serverConfig(server)?.command ?? "";
|
|
91348
|
+
if (!/(^|[\\/\s])npx(\.cmd)?(\s|$)/i.test(command))
|
|
91349
|
+
return {};
|
|
91350
|
+
const registry2 = await npmRegistry();
|
|
91351
|
+
return registry2 !== void 0 ? { registry: registry2 } : {};
|
|
91354
91352
|
}
|
|
91355
91353
|
async function hostProblem(pageUrl) {
|
|
91356
91354
|
const known = webChatHostChecks.get(pageUrl);
|
|
91357
91355
|
if (known !== void 0 && Date.now() - known.at < 6e5)
|
|
91358
91356
|
return known.problem;
|
|
91359
|
-
const problem =
|
|
91357
|
+
const problem = webChatAddressProblem(pageUrl);
|
|
91360
91358
|
webChatHostChecks.set(pageUrl, { at: Date.now(), problem });
|
|
91361
91359
|
return problem;
|
|
91362
91360
|
}
|
|
@@ -91407,7 +91405,7 @@ ${error51.stack.split("\n").slice(1, 6).join("\n")}`;
|
|
|
91407
91405
|
}
|
|
91408
91406
|
} : {},
|
|
91409
91407
|
chrome: {
|
|
91410
|
-
servers: await Promise.all(servers.map(async (name) => ({ name, problems: await chromeProblems(name) }))),
|
|
91408
|
+
servers: await Promise.all(servers.map(async (name) => ({ name, problems: await chromeProblems(name), ...await npxRegistryFor(name) }))),
|
|
91411
91409
|
...setup?.server !== void 0 ? { chosen: setup.server } : {}
|
|
91412
91410
|
},
|
|
91413
91411
|
...setup !== void 0 ? { hostProblem: await hostProblem(setup.pageUrl).catch((error51) => String(error51)) ?? "" } : {},
|
|
@@ -91431,16 +91429,17 @@ ${error51.stack.split("\n").slice(1, 6).join("\n")}`;
|
|
|
91431
91429
|
const origin = new URL(pageUrl).origin;
|
|
91432
91430
|
const phrase = capturePhrase();
|
|
91433
91431
|
mcp.reserve([server]);
|
|
91434
|
-
await selectWebChatPage(chrome, pageUrl);
|
|
91435
|
-
const installed = await runScript(chrome, watchScript(origin, phrase));
|
|
91432
|
+
const pageId = await selectWebChatPage(chrome, pageUrl);
|
|
91433
|
+
const installed = await runScript(chrome, watchScript(origin, phrase), pageId);
|
|
91436
91434
|
if (installed["ok"] !== true) {
|
|
91437
91435
|
post({ type: "webChatCapture", phase: "failed", message: String(installed["error"] ?? "The page could not be watched.") });
|
|
91438
91436
|
return;
|
|
91439
91437
|
}
|
|
91440
|
-
webChatCapture = { pageUrl, server, phrase, startedAt: Date.now(), candidates: [] };
|
|
91438
|
+
webChatCapture = { pageUrl, server, pageId, phrase, startedAt: Date.now(), candidates: [] };
|
|
91441
91439
|
post({ type: "webChatCapture", phase: "waiting", phrase });
|
|
91442
91440
|
const capture = webChatCapture;
|
|
91443
91441
|
let polling = false;
|
|
91442
|
+
let failures = 0;
|
|
91444
91443
|
capture.timer = setInterval(() => {
|
|
91445
91444
|
if (polling || webChatCapture !== capture)
|
|
91446
91445
|
return;
|
|
@@ -91452,9 +91451,10 @@ ${error51.stack.split("\n").slice(1, 6).join("\n")}`;
|
|
|
91452
91451
|
post({ type: "webChatCapture", phase: "failed", message: "Nothing carrying the phrase was seen in three minutes. Send it in the web chat tab Light Code opened (a new chat), then capture again." });
|
|
91453
91452
|
return;
|
|
91454
91453
|
}
|
|
91455
|
-
const read = await runScript(chrome, readCaptureScript(origin));
|
|
91454
|
+
const read = await runScript(chrome, readCaptureScript(origin), capture.pageId);
|
|
91455
|
+
failures = 0;
|
|
91456
91456
|
if (read["ok"] !== true) {
|
|
91457
|
-
await selectWebChatPage(chrome, pageUrl);
|
|
91457
|
+
capture.pageId = await selectWebChatPage(chrome, pageUrl);
|
|
91458
91458
|
return;
|
|
91459
91459
|
}
|
|
91460
91460
|
if (read["ws"] === true) {
|
|
@@ -91487,7 +91487,13 @@ ${error51.stack.split("\n").slice(1, 6).join("\n")}`;
|
|
|
91487
91487
|
refused
|
|
91488
91488
|
});
|
|
91489
91489
|
} catch (error51) {
|
|
91490
|
-
|
|
91490
|
+
const message6 = error51 instanceof Error ? error51.message : String(error51);
|
|
91491
|
+
logger.warn(`web chat capture: ${message6}`);
|
|
91492
|
+
failures += 1;
|
|
91493
|
+
if (failures >= 3 && webChatCapture === capture) {
|
|
91494
|
+
stopWebChatCapture();
|
|
91495
|
+
post({ type: "webChatCapture", phase: "failed", message: message6 });
|
|
91496
|
+
}
|
|
91491
91497
|
} finally {
|
|
91492
91498
|
polling = false;
|
|
91493
91499
|
}
|
|
@@ -99702,7 +99708,7 @@ ${answer.slice(0, 16e3)}` } }, (d) => d.best !== void 0 && d.best.probability >=
|
|
|
99702
99708
|
const capture = webChatCapture;
|
|
99703
99709
|
const server = capture?.server;
|
|
99704
99710
|
if (capture !== void 0 && server !== void 0) {
|
|
99705
|
-
void runScript(chromeAccess(server), typePhraseScript(new URL(capture.pageUrl).origin, capture.phrase)).then((done) => {
|
|
99711
|
+
void runScript(chromeAccess(server), typePhraseScript(new URL(capture.pageUrl).origin, capture.phrase), capture.pageId).then((done) => {
|
|
99706
99712
|
if (done["ok"] !== true)
|
|
99707
99713
|
post({ type: "webChatCapture", phase: "waiting", phrase: capture.phrase, message: String(done["error"] ?? "It could not be typed - paste it by hand.") });
|
|
99708
99714
|
}).catch((error51) => post({ type: "webChatCapture", phase: "waiting", phrase: capture.phrase, message: error51 instanceof Error ? error51.message : String(error51) }));
|
|
@@ -106064,9 +106070,9 @@ DevTools MCP server is connected, and never on a shared server.
|
|
|
106064
106070
|
(e.g. chrome-webchat), so any Chrome server you already use is left exactly as it is - and choose it in the Web chat
|
|
106065
106071
|
panel. Add it with \`--autoConnect\`, \`--no-usage-statistics\` and
|
|
106066
106072
|
\`--no-performance-crux\` (the panel shows the entry to paste), and allow it in Chrome at
|
|
106067
|
-
chrome://inspect/#remote-debugging. Either installed once (\`npm i -g chrome-devtools-mcp\`), or run with **npx**
|
|
106068
|
-
|
|
106069
|
-
\`npm config get registry\`
|
|
106073
|
+
chrome://inspect/#remote-debugging. Either installed once (\`npm i -g chrome-devtools-mcp\`), or run with **npx**
|
|
106074
|
+
and a pinned version (\`chrome-devtools-mcp@1.13.0\`, not \`@latest\`); the panel shows where npx downloads it from
|
|
106075
|
+
(\`npm config get registry\` - it should be your organisation's registry).
|
|
106070
106076
|
2. Type the web chat page's address and press **Capture**. In the tab Light Code selects, start a new chat, choose the
|
|
106071
106077
|
model, and send the phrase shown (or press **Send it for me**).
|
|
106072
106078
|
3. Light Code shows the request that carried it: **the backend address**, the model, and the start of the answer it read.
|
|
@@ -106076,11 +106082,8 @@ DevTools MCP server is connected, and never on a shared server.
|
|
|
106076
106082
|
- Light Code opens no connection itself: the request runs inside the chat page, in your Chrome, to the approved
|
|
106077
106083
|
backend address on the chat's own site only, with redirects refused; a reply from another site is not used. Your session
|
|
106078
106084
|
never reaches Light Code - a header that carries a credential is taken from the page each time, never stored.
|
|
106079
|
-
- The
|
|
106080
|
-
|
|
106081
|
-
- The Chrome DevTools MCP server must run on this PC (not a remote server) - installed, or through npx only when npm's
|
|
106082
|
-
registry is inside the network and the version is pinned - with its reporting to Google off (both flags above),
|
|
106083
|
-
attached to this PC's Chrome only.
|
|
106085
|
+
- The Chrome DevTools MCP server must run on this PC (not a remote server) - installed, or through npx with a pinned
|
|
106086
|
+
version - with its reporting to Google off (both flags above), attached to this PC's Chrome only.
|
|
106084
106087
|
- **The assistant never gets the web chat's Chrome server's tools**: it cannot open a page, click or run anything
|
|
106085
106088
|
through it - \`ask_web_chat\` and its one approved request are the only way in. Its tools are replaced by that one
|
|
106086
106089
|
tool, so the assistant is given fewer tools, not more. Any other Chrome server you have is untouched - and with it the
|