dsh-web-fetch-playwright 0.2.7 → 0.2.9
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 +4 -4
- package/README.zh-CN.md +4 -4
- package/lib/client.js +138 -165
- package/lib/index.js +178 -34
- package/lib/types/client/PluginCard.d.ts +15 -19
- package/lib/types/client/card.d.ts +12 -5
- package/lib/types/client/controller.d.ts +18 -8
- package/lib/types/client/form.d.ts +17 -9
- package/lib/types/client/index.d.ts +17 -6
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/config.d.ts +73 -1
- package/lib/types/host-resolve-compat.d.ts +38 -0
- package/lib/types/index.d.ts +29 -11
- package/lib/types/markdown.d.ts +4 -1
- package/package.json +12 -15
- package/src/client/PluginCard.module.css +6 -86
- package/src/client/PluginCard.tsx +38 -76
- package/src/client/card.tsx +18 -12
- package/src/client/controller.ts +21 -8
- package/src/client/form.ts +35 -15
- package/src/client/index.ts +64 -18
- package/src/client/locales.ts +3 -11
- package/src/config.ts +94 -12
- package/src/host-resolve-compat.ts +102 -0
- package/src/index.ts +51 -30
- package/src/markdown.ts +33 -2
package/lib/index.js
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
1
|
+
import { createRequire, isBuiltin } from "node:module";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { WebError } from "@deepseek-ai/dsh-web";
|
|
4
|
-
import { JSDOM, VirtualConsole } from "jsdom";
|
|
5
4
|
import createDOMPurify from "dompurify";
|
|
6
5
|
import { Readability } from "@mozilla/readability";
|
|
7
6
|
import TurndownService from "turndown";
|
|
8
7
|
import { gfm } from "@joplin/turndown-plugin-gfm";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
9
|
import { accessSync, constants, readFileSync, realpathSync, statSync } from "node:fs";
|
|
10
10
|
import { delimiter, dirname, join } from "node:path";
|
|
11
|
-
import { pathToFileURL } from "node:url";
|
|
12
11
|
//#region src/config.ts
|
|
13
|
-
/**
|
|
14
|
-
* Settings/config surface for the Playwright fetch provider: the schemastery
|
|
15
|
-
* schema the loader validates the row against, the settings namespace's
|
|
16
|
-
* resolved shape, and the small pure normalizers the provider applies per
|
|
17
|
-
* fetch (CDP endpoint shaping) — kept network-free for unit tests.
|
|
18
|
-
*
|
|
19
|
-
* @module dsh-web-fetch-playwright/config
|
|
20
|
-
*/
|
|
21
12
|
/** Default CDP endpoint when the settings section leaves it blank. */
|
|
22
13
|
const DEFAULT_CDP_ENDPOINT = "127.0.0.1:9222";
|
|
23
14
|
/**
|
|
@@ -32,16 +23,59 @@ const MAX_CHALLENGE_WAIT_MS = 6e4;
|
|
|
32
23
|
/** Default same-page re-navigation attempts after a challenge wait runs out. */
|
|
33
24
|
const DEFAULT_CHALLENGE_RETRIES = 1;
|
|
34
25
|
const Config = z.object({
|
|
35
|
-
backend: z.union([z.const("local"), z.const("cdp")]).default("local"),
|
|
36
|
-
playwrightPath: z.string().default(""),
|
|
37
|
-
cdpEndpoint: z.string().default(""),
|
|
38
|
-
shareBrowserContext: z.boolean().default(true),
|
|
39
|
-
denoise: z.boolean().default(true),
|
|
40
|
-
maxConcurrency: z.number().step(1).min(1).max(200),
|
|
41
|
-
challengeWaitMs: z.number().step(100).min(0).max(MAX_CHALLENGE_WAIT_MS).default(DEFAULT_CHALLENGE_WAIT_MS),
|
|
42
|
-
challengeRetries: z.number().step(1).min(0).max(3).default(1)
|
|
26
|
+
backend: z.union([z.const("local"), z.const("cdp")]).default("local").volatile(),
|
|
27
|
+
playwrightPath: z.string().default("").volatile(),
|
|
28
|
+
cdpEndpoint: z.string().default("").volatile(),
|
|
29
|
+
shareBrowserContext: z.boolean().default(true).volatile(),
|
|
30
|
+
denoise: z.boolean().default(true).volatile(),
|
|
31
|
+
maxConcurrency: z.number().step(1).min(1).max(200).volatile(),
|
|
32
|
+
challengeWaitMs: z.number().step(100).min(0).max(MAX_CHALLENGE_WAIT_MS).default(DEFAULT_CHALLENGE_WAIT_MS).volatile(),
|
|
33
|
+
challengeRetries: z.number().step(1).min(0).max(3).default(1).volatile()
|
|
43
34
|
});
|
|
44
35
|
/**
|
|
36
|
+
* Read the live references `apply` holds into one plain input for
|
|
37
|
+
* {@link resolveConfig}; a settings commit has usually replaced the
|
|
38
|
+
* snapshots since the last call, which is the whole point.
|
|
39
|
+
*
|
|
40
|
+
* @param config - the plugin config as the loader resolved it.
|
|
41
|
+
* @returns the current snapshots, ready for resolution.
|
|
42
|
+
*/
|
|
43
|
+
function snapshotsOf(config) {
|
|
44
|
+
return {
|
|
45
|
+
backend: config.backend.get(),
|
|
46
|
+
playwrightPath: config.playwrightPath.get(),
|
|
47
|
+
cdpEndpoint: config.cdpEndpoint.get(),
|
|
48
|
+
shareBrowserContext: config.shareBrowserContext.get(),
|
|
49
|
+
denoise: config.denoise.get(),
|
|
50
|
+
maxConcurrency: config.maxConcurrency.get(),
|
|
51
|
+
challengeWaitMs: config.challengeWaitMs.get(),
|
|
52
|
+
challengeRetries: config.challengeRetries.get()
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Resolve any accepted config input into the fully-defaulted, plain form the
|
|
57
|
+
* provider consumes per fetch. Validation goes through the schema, so the
|
|
58
|
+
* volatile wrappers that produces are unwrapped immediately — the provider
|
|
59
|
+
* consumes plain values. The input face is `Partial` by design (composition
|
|
60
|
+
* entries and volatile snapshots both omit fields; defaults supply them).
|
|
61
|
+
*
|
|
62
|
+
* @param config - composition entry, settings-section value, or volatile snapshots.
|
|
63
|
+
* @returns the resolved config.
|
|
64
|
+
*/
|
|
65
|
+
function resolveConfig(config) {
|
|
66
|
+
const resolved = Config(config);
|
|
67
|
+
return {
|
|
68
|
+
backend: resolved.backend.get(),
|
|
69
|
+
playwrightPath: resolved.playwrightPath.get(),
|
|
70
|
+
cdpEndpoint: resolved.cdpEndpoint.get(),
|
|
71
|
+
shareBrowserContext: resolved.shareBrowserContext.get(),
|
|
72
|
+
denoise: resolved.denoise.get(),
|
|
73
|
+
maxConcurrency: resolved.maxConcurrency.get(),
|
|
74
|
+
challengeWaitMs: resolved.challengeWaitMs.get(),
|
|
75
|
+
challengeRetries: resolved.challengeRetries.get()
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
45
79
|
* The concurrency limit a fetch actually runs with: an explicit setting
|
|
46
80
|
* wins; otherwise the backend default (local launches browsers, CDP only
|
|
47
81
|
* opens tabs, so their budgets differ by an order of magnitude).
|
|
@@ -483,6 +517,87 @@ var CdpConnectionPool = class {
|
|
|
483
517
|
}
|
|
484
518
|
};
|
|
485
519
|
//#endregion
|
|
520
|
+
//#region src/host-resolve-compat.ts
|
|
521
|
+
/**
|
|
522
|
+
* Host resolve compat for the `punycode/` builtin-slash idiom.
|
|
523
|
+
*
|
|
524
|
+
* dsh web (runtime resolution in `dsh-app-boot`) intercepts Node's CommonJS
|
|
525
|
+
* resolver for every package installed in a profile. Its router classifies a
|
|
526
|
+
* bare request by stripping one trailing path segment, which turns tr46's
|
|
527
|
+
* `require("punycode/")` — the standard npm-package-over-deprecated-builtin
|
|
528
|
+
* idiom — into the builtin name `punycode`, and `require.resolve.paths()` of a
|
|
529
|
+
* builtin returns `null`; the unguarded iteration then throws
|
|
530
|
+
* `TypeError: createRequire.resolve.paths is not a function or its return
|
|
531
|
+
* value is not iterable`, killing the whole `jsdom` import chain (jsdom →
|
|
532
|
+
* whatwg-url → tr46) and with it this plugin's activation.
|
|
533
|
+
*
|
|
534
|
+
* The shim below is installed lazily, immediately before the first `jsdom`
|
|
535
|
+
* load, and only when the running resolver actually exhibits the failure
|
|
536
|
+
* (probed with the very request that breaks). It wraps the public
|
|
537
|
+
* `Module._resolveFilename` — whatever it currently is, native or already
|
|
538
|
+
* host-intercepted — and re-dispatches exactly the affected request shape
|
|
539
|
+
* (`<deprecated builtin>/`) with an explicit `paths` list. An explicit
|
|
540
|
+
* `options.paths` is the documented bypass of every resolution interceptor in
|
|
541
|
+
* the chain (the host wrapper delegates straight to the native resolver for
|
|
542
|
+
* it), so the request lands on the real npm package — the same file plain
|
|
543
|
+
* Node would have found. Hosts without the bug never see the wrapper at all;
|
|
544
|
+
* the probe itself changes nothing.
|
|
545
|
+
*
|
|
546
|
+
* The ESM flavor of the same router path exists in theory (`import
|
|
547
|
+
* 'punycode/'`), but nothing in this plugin's tree imports it that way —
|
|
548
|
+
* tr46 is CommonJS — so the CommonJS hook is the complete fix here.
|
|
549
|
+
*
|
|
550
|
+
* @module dsh-web-fetch-playwright/host-resolve-compat
|
|
551
|
+
*/
|
|
552
|
+
/** `createRequire` anchored at this module, wherever the bundle is installed. */
|
|
553
|
+
const require_$1 = createRequire(import.meta.url);
|
|
554
|
+
/** This file's own path, the anchor the probe resolves from. */
|
|
555
|
+
const SELF_FILENAME = fileURLToPath(import.meta.url);
|
|
556
|
+
/**
|
|
557
|
+
* Whether a request is the npm-over-builtin idiom: one bare package name with
|
|
558
|
+
* a single trailing slash, whose stem is a Node builtin (today, in practice:
|
|
559
|
+
* `punycode/`).
|
|
560
|
+
* @param request - the module request seen by `Module._resolveFilename`.
|
|
561
|
+
* @returns `true` for `punycode/`-shaped requests; relative paths, scoped
|
|
562
|
+
* names, subpaths, and ordinary packages all answer `false`.
|
|
563
|
+
*/
|
|
564
|
+
function isBuiltinSlashRequest(request) {
|
|
565
|
+
if (request.length < 2 || !request.endsWith("/")) return false;
|
|
566
|
+
const first = request.charAt(0);
|
|
567
|
+
if (first === "" || "./#@".includes(first)) return false;
|
|
568
|
+
const stem = request.slice(0, -1);
|
|
569
|
+
return stem !== "" && !stem.includes("/") && isBuiltin(stem);
|
|
570
|
+
}
|
|
571
|
+
/** Probe outcome once known: `true` = shim installed or verified unneeded. */
|
|
572
|
+
let settled = false;
|
|
573
|
+
/**
|
|
574
|
+
* Make `require("<deprecated builtin>/")` resolvable under hosts whose
|
|
575
|
+
* profile-scope resolution interceptor mishandles it. Idempotent, synchronous,
|
|
576
|
+
* and a no-op on healthy resolvers (the probe resolves successfully and no
|
|
577
|
+
* wrapper is installed). Must run before the first `require('jsdom')`.
|
|
578
|
+
*/
|
|
579
|
+
function installBuiltinSlashResolveCompat() {
|
|
580
|
+
if (settled) return;
|
|
581
|
+
settled = true;
|
|
582
|
+
const ModuleClass = require_$1("node:module").Module;
|
|
583
|
+
const original = ModuleClass._resolveFilename;
|
|
584
|
+
if (typeof original !== "function") return;
|
|
585
|
+
try {
|
|
586
|
+
original.call(ModuleClass, "punycode/", { filename: SELF_FILENAME });
|
|
587
|
+
return;
|
|
588
|
+
} catch (error) {
|
|
589
|
+
if (!(error instanceof TypeError)) return;
|
|
590
|
+
}
|
|
591
|
+
const searchPaths = require_$1.resolve.paths("jsdom") ?? [];
|
|
592
|
+
ModuleClass._resolveFilename = function patchedResolveFilename(request, parent, main, options) {
|
|
593
|
+
if (options?.paths === void 0 && typeof request === "string" && isBuiltinSlashRequest(request)) return original.call(ModuleClass, request, parent, main, {
|
|
594
|
+
...options,
|
|
595
|
+
paths: searchPaths
|
|
596
|
+
});
|
|
597
|
+
return original.call(ModuleClass, request, parent, main, options);
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
//#endregion
|
|
486
601
|
//#region src/markdown.ts
|
|
487
602
|
/**
|
|
488
603
|
* The denoise pipeline: rendered HTML → sanitized article HTML → markdown.
|
|
@@ -497,10 +612,33 @@ var CdpConnectionPool = class {
|
|
|
497
612
|
* options and span-safe table rules as the shipped `dsh-tool-web` renderer,
|
|
498
613
|
* so output is consistent with what `web_fetch` produces elsewhere.
|
|
499
614
|
*
|
|
500
|
-
*
|
|
615
|
+
* Synchronous for its callers and unit-tested against fixture pages: jsdom
|
|
616
|
+
* itself is loaded lazily on the first call — and, inside a dsh profile, only
|
|
617
|
+
* after `installBuiltinSlashResolveCompat`, so a host resolver that
|
|
618
|
+
* mishandles tr46's `require("punycode/")` cannot take the plugin down.
|
|
501
619
|
*
|
|
502
620
|
* @module dsh-web-fetch-playwright/markdown
|
|
503
621
|
*/
|
|
622
|
+
/** `createRequire` anchored at this module, so jsdom resolves from this install. */
|
|
623
|
+
const require_ = createRequire(import.meta.url);
|
|
624
|
+
/** Loaded jsdom module, cached after the first denoise. */
|
|
625
|
+
let jsdom;
|
|
626
|
+
/**
|
|
627
|
+
* Load jsdom on first use, installing the host resolve compat first.
|
|
628
|
+
*
|
|
629
|
+
* Deferral serves two purposes: plugin activation never depends on jsdom's
|
|
630
|
+
* import chain surviving the host's module-resolution interception, and the
|
|
631
|
+
* compat shim — which must wrap the resolver *before* tr46's
|
|
632
|
+
* `require("punycode/")` runs — gets a guaranteed installation point.
|
|
633
|
+
* @returns the jsdom module exports.
|
|
634
|
+
*/
|
|
635
|
+
function loadJsdom() {
|
|
636
|
+
if (jsdom === void 0) {
|
|
637
|
+
installBuiltinSlashResolveCompat();
|
|
638
|
+
jsdom = require_("jsdom");
|
|
639
|
+
}
|
|
640
|
+
return jsdom;
|
|
641
|
+
}
|
|
504
642
|
/** Layout/noise tags DOMPurify removes outright (with their content). */
|
|
505
643
|
const FORBID_TAGS = [
|
|
506
644
|
"nav",
|
|
@@ -631,6 +769,7 @@ turndown.addRule("tableRowWithoutSpanExpansion", {
|
|
|
631
769
|
* @returns the markdown and the extraction mode used.
|
|
632
770
|
*/
|
|
633
771
|
function htmlToMarkdown(html, url) {
|
|
772
|
+
const { JSDOM, VirtualConsole } = loadJsdom();
|
|
634
773
|
const dom = new JSDOM(html, {
|
|
635
774
|
url,
|
|
636
775
|
virtualConsole: new VirtualConsole()
|
|
@@ -1424,26 +1563,31 @@ function guardPopups(page) {
|
|
|
1424
1563
|
//#region src/index.ts
|
|
1425
1564
|
/** Cordis plugin name used by loader diagnostics. */
|
|
1426
1565
|
const name = "dsh-web-fetch-playwright";
|
|
1427
|
-
/**
|
|
1566
|
+
/**
|
|
1567
|
+
* The capability seam this plugin registers into. The settings section
|
|
1568
|
+
* needs no inject: the host's settings service derives it from the entry's
|
|
1569
|
+
* `Config` schema (its volatile fields) by entry id.
|
|
1570
|
+
*/
|
|
1428
1571
|
const inject = ["web"];
|
|
1429
|
-
/**
|
|
1572
|
+
/**
|
|
1573
|
+
* Settings namespace carrying this provider's configuration page: the
|
|
1574
|
+
* composition entry id, which is what the settings service keys the
|
|
1575
|
+
* derived section by.
|
|
1576
|
+
*/
|
|
1430
1577
|
const WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE = "web-fetch-playwright";
|
|
1431
|
-
/**
|
|
1578
|
+
/**
|
|
1579
|
+
* Register the Playwright fetch provider with `ctx.web`.
|
|
1580
|
+
*
|
|
1581
|
+
* @param ctx - plugin context supplying the web seam.
|
|
1582
|
+
* @param config - the loader-resolved plugin config; its volatile fields are
|
|
1583
|
+
* live references a settings commit updates in place.
|
|
1584
|
+
*/
|
|
1432
1585
|
function apply(ctx, config) {
|
|
1433
|
-
|
|
1434
|
-
ctx.inject(["settings"], (settingsCtx) => {
|
|
1435
|
-
settingsCtx.settings.installSection(ctx, WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE, Config, config, {
|
|
1436
|
-
setSource: (source) => {
|
|
1437
|
-
current = source;
|
|
1438
|
-
},
|
|
1439
|
-
onChange: () => {}
|
|
1440
|
-
});
|
|
1441
|
-
});
|
|
1442
|
-
const provider = new PlaywrightFetchProvider(() => current());
|
|
1586
|
+
const provider = new PlaywrightFetchProvider(() => resolveConfig(snapshotsOf(config)));
|
|
1443
1587
|
ctx.effect(() => () => {
|
|
1444
1588
|
provider.dispose();
|
|
1445
1589
|
}, "dsh-web-fetch-playwright: shared CDP connection");
|
|
1446
1590
|
ctx.web.registerFetchProvider(provider);
|
|
1447
1591
|
}
|
|
1448
1592
|
//#endregion
|
|
1449
|
-
export { CHALLENGE_DOM_PROBE, CHALLENGE_FINISH_RESERVE_MS, CHALLENGE_POLL_INTERVAL_MS, CHALLENGE_TITLE_RE, CdpConnectionPool, Config, DEFAULT_CDP_ENDPOINT, DEFAULT_CHALLENGE_RETRIES, DEFAULT_CHALLENGE_WAIT_MS, PLAYWRIGHT_FETCH_PROVIDER_ID, PlaywrightFetchProvider, WEB_FETCH_CHALLENGE_CODE, WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE, apply, classifyChallengeHtml, classifyChallengeResponse, effectiveChallengeRetries, effectiveChallengeWaitMs, effectiveContextMode, htmlToMarkdown, inject, isChallengeCompatibleResponse, name, normalizeCdpEndpoint };
|
|
1593
|
+
export { CHALLENGE_DOM_PROBE, CHALLENGE_FINISH_RESERVE_MS, CHALLENGE_POLL_INTERVAL_MS, CHALLENGE_TITLE_RE, CdpConnectionPool, Config, DEFAULT_CDP_ENDPOINT, DEFAULT_CHALLENGE_RETRIES, DEFAULT_CHALLENGE_WAIT_MS, PLAYWRIGHT_FETCH_PROVIDER_ID, PlaywrightFetchProvider, WEB_FETCH_CHALLENGE_CODE, WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE, apply, classifyChallengeHtml, classifyChallengeResponse, effectiveChallengeRetries, effectiveChallengeWaitMs, effectiveContextMode, htmlToMarkdown, inject, isChallengeCompatibleResponse, name, normalizeCdpEndpoint, resolveConfig, snapshotsOf };
|
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
* the
|
|
2
|
+
* The form chrome — a page-level container (read-only notice, the staged
|
|
3
|
+
* controls, and the save/discard footer), in the rhythm of the shipped
|
|
4
|
+
* plugin-configuration forms. Since the Plugins page (dsh ≥ 0.1.7) draws the
|
|
5
|
+
* title, description, and navigation around a configuration entry, this is
|
|
6
|
+
* the body only; the disclosure header of the old settings-list card is
|
|
7
|
+
* gone with that seat.
|
|
5
8
|
*
|
|
6
9
|
* @module dsh-web-fetch-playwright/client/PluginCard
|
|
7
10
|
*/
|
|
8
|
-
import {
|
|
11
|
+
import type { ReactNode } from 'react';
|
|
9
12
|
import type { CardShell } from './form.ts';
|
|
10
13
|
/** Copy keys the chrome itself renders (the card's dictionary supplies them). */
|
|
11
|
-
export interface
|
|
12
|
-
expand: string;
|
|
13
|
-
collapse: string;
|
|
14
|
-
unsaved: string;
|
|
14
|
+
export interface CardFormCopy {
|
|
15
15
|
readOnly: string;
|
|
16
16
|
saveFailed: string;
|
|
17
17
|
discard: string;
|
|
18
18
|
save: string;
|
|
19
19
|
saving: string;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
export interface
|
|
21
|
+
/** Form chrome props. */
|
|
22
|
+
export interface CardFormProps {
|
|
23
23
|
/** Chrome copy (a subset of the card's locale keys). */
|
|
24
|
-
copy:
|
|
25
|
-
/** The plugin's display name. */
|
|
26
|
-
title: string;
|
|
27
|
-
/** The line describing what this plugin's settings govern. */
|
|
28
|
-
description: string;
|
|
24
|
+
copy: CardFormCopy;
|
|
29
25
|
/** The card's form state: availability, writability, and what a save would do. */
|
|
30
26
|
state: CardShell;
|
|
31
27
|
/** Write every staged edit. */
|
|
@@ -36,8 +32,8 @@ export interface PluginCardProps {
|
|
|
36
32
|
children: ReactNode;
|
|
37
33
|
}
|
|
38
34
|
/**
|
|
39
|
-
* Render the Playwright
|
|
40
|
-
* @param props - the
|
|
41
|
-
* @returns the
|
|
35
|
+
* Render the Playwright form's chrome.
|
|
36
|
+
* @param props - the form's copy, form state, and controls.
|
|
37
|
+
* @returns the form body with its footer.
|
|
42
38
|
*/
|
|
43
|
-
export declare function
|
|
39
|
+
export declare function CardForm(props: CardFormProps): import("react").JSX.Element;
|
|
@@ -5,15 +5,22 @@
|
|
|
5
5
|
* the denoise checkbox, staged and saved through the card form like the
|
|
6
6
|
* built-in plugin cards.
|
|
7
7
|
*
|
|
8
|
+
* The Plugins page asks for `view: 'summary'` (a row's description
|
|
9
|
+
* fallback) or `view: 'page'` (this form). The same component serves both
|
|
10
|
+
* seats it is registered into: the bundle's own page (between its
|
|
11
|
+
* description and its rows) and the row's page (under the plugin's own
|
|
12
|
+
* title); one controller stages the edits shared by the two.
|
|
13
|
+
*
|
|
8
14
|
* @module dsh-web-fetch-playwright/client/card
|
|
9
15
|
*/
|
|
10
16
|
import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
11
17
|
import type { PlaywrightCardFace } from './controller.ts';
|
|
12
18
|
/** Props the renderer binds for the Playwright card. */
|
|
13
|
-
export type PlaywrightCardProps = PropsRuntime<'
|
|
19
|
+
export type PlaywrightCardProps = (PropsRuntime<'plugins.bundle.config'> | PropsRuntime<'plugins.row.config'>) & PropsLocale<'web-fetch-playwright'> & InjectFace<PlaywrightCardFace>;
|
|
14
20
|
/**
|
|
15
|
-
* Render the Playwright card
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
21
|
+
* Render the Playwright card: its one-liner for the list, or the staged form
|
|
22
|
+
* for the page.
|
|
23
|
+
* @param props - the view asked for, locale copy, the card snapshot, and its form actions.
|
|
24
|
+
* @returns the one-liner, the form, or nothing while the namespace is unavailable.
|
|
18
25
|
*/
|
|
19
|
-
export declare function PlaywrightCard(props: PlaywrightCardProps): import("react").JSX.Element;
|
|
26
|
+
export declare function PlaywrightCard(props: PlaywrightCardProps): string | import("react").JSX.Element | null;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Playwright card's controller: the staged form over the
|
|
3
|
-
* `web-fetch-playwright`
|
|
4
|
-
* card's slot entry injects.
|
|
3
|
+
* `web-fetch-playwright` plugin-entry configuration form, projected into one
|
|
4
|
+
* snapshot the card's slot entry injects.
|
|
5
|
+
*
|
|
6
|
+
* Since dsh 0.1.7 the scope is the shared `configForms` form for the plugin
|
|
7
|
+
* entry — the host's settings service derives the section from the plugin's
|
|
8
|
+
* Config schema (its volatile fields), keyed by the composition entry id.
|
|
5
9
|
*
|
|
6
10
|
* @module dsh-web-fetch-playwright/client/controller
|
|
7
11
|
*/
|
|
8
|
-
import type {
|
|
12
|
+
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
9
13
|
import type { CardShell, CardFieldState, CardActions, SnapshotStore } from './form.ts';
|
|
10
14
|
/**
|
|
11
|
-
* Settings namespace this card edits
|
|
12
|
-
*
|
|
15
|
+
* Settings namespace this card edits: the composition entry id, which is
|
|
16
|
+
* what the host's settings service keys the section derived from the
|
|
17
|
+
* plugin's Config schema by. Spelled here rather than imported: a client
|
|
18
|
+
* package must not depend on a Host package.
|
|
13
19
|
*/
|
|
14
20
|
export declare const WEB_FETCH_PLAYWRIGHT_NS = "web-fetch-playwright";
|
|
15
21
|
/** The section fields this card edits. */
|
|
@@ -60,18 +66,22 @@ export interface PlaywrightCardFace extends CardActions {
|
|
|
60
66
|
playwrightCard: SnapshotStore<PlaywrightCardState>;
|
|
61
67
|
};
|
|
62
68
|
}
|
|
63
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Bridges the `web-fetch-playwright` configuration form onto the card.
|
|
71
|
+
*/
|
|
64
72
|
export declare class PlaywrightCardController {
|
|
65
73
|
private readonly form;
|
|
66
74
|
private readonly store;
|
|
67
75
|
/**
|
|
68
|
-
* @param scope - the
|
|
76
|
+
* @param scope - the shared configuration form for the `web-fetch-playwright` entry.
|
|
69
77
|
*/
|
|
70
|
-
constructor(scope:
|
|
78
|
+
constructor(scope: ConfigForm<PlaywrightSettings>);
|
|
71
79
|
private projection;
|
|
72
80
|
/**
|
|
73
81
|
* Build the face the card's slot registration injects.
|
|
74
82
|
* @returns the card's snapshot and its form actions.
|
|
75
83
|
*/
|
|
76
84
|
inject(): PlaywrightCardFace;
|
|
85
|
+
/** Release the form subscription and every bound stores. */
|
|
86
|
+
dispose(): void;
|
|
77
87
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The staged-form model behind the Playwright card — a faithful subset of the
|
|
3
|
-
* shipped
|
|
3
|
+
* shipped plugin-configuration CardForm (same staging semantics: edits stay
|
|
4
4
|
* local until the card's save, presence in the user layer — not value
|
|
5
5
|
* equality — marks a field overridden), plus the two field kinds this card
|
|
6
6
|
* adds: a radio group (backend) and a checkbox (denoise), staged through the
|
|
7
|
-
* same draft mechanism as text.
|
|
7
|
+
* same draft mechanism as text. Since dsh 0.1.7 the scope is the shared
|
|
8
|
+
* `configForms` form for the plugin entry (reads ride the describe mirror;
|
|
9
|
+
* writes are revision-fenced path mutations).
|
|
8
10
|
*
|
|
9
11
|
* Bundled locally because external client bundles cannot value-import
|
|
10
12
|
* `@deepseek-ai/*` packages; the snapshot store is a local structural clone
|
|
@@ -12,7 +14,7 @@
|
|
|
12
14
|
*
|
|
13
15
|
* @module dsh-web-fetch-playwright/client/form
|
|
14
16
|
*/
|
|
15
|
-
import type {
|
|
17
|
+
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
16
18
|
/** The write one field's staged draft performs when the card is saved. */
|
|
17
19
|
export type FieldWrite = {
|
|
18
20
|
kind: 'set';
|
|
@@ -105,22 +107,26 @@ export declare function checkboxField(field: string): CardFieldSpec;
|
|
|
105
107
|
*/
|
|
106
108
|
export declare function numberField(field: string, min: number, max: number): CardFieldSpec;
|
|
107
109
|
/**
|
|
108
|
-
* Stages the Playwright card's edits over one
|
|
109
|
-
* them on save. Publishes through a snapshot store because
|
|
110
|
-
* read through a selector while both the
|
|
110
|
+
* Stages the Playwright card's edits over one plugin-entry configuration
|
|
111
|
+
* form and writes them on save. Publishes through a snapshot store because
|
|
112
|
+
* slot components read through a selector while both the form and the drafts
|
|
113
|
+
* change below.
|
|
111
114
|
*/
|
|
112
115
|
export declare class CardForm<T> {
|
|
113
116
|
private readonly scope;
|
|
114
117
|
private readonly specs;
|
|
115
118
|
private readonly staged;
|
|
116
119
|
private readonly listeners;
|
|
120
|
+
private readonly unsubscribe;
|
|
117
121
|
private saving;
|
|
118
122
|
private failed;
|
|
119
123
|
/**
|
|
120
|
-
* @param scope - the
|
|
124
|
+
* @param scope - the shared configuration form for this plugin's entry.
|
|
121
125
|
* @param specs - the section fields this card edits.
|
|
122
126
|
*/
|
|
123
|
-
constructor(scope:
|
|
127
|
+
constructor(scope: ConfigForm<T>, specs: CardFieldSpec[]);
|
|
128
|
+
/** Release the form subscription and every bound stores. */
|
|
129
|
+
dispose(): void;
|
|
124
130
|
/**
|
|
125
131
|
* Publish a projection of this form, rebuilt whenever the scope or a draft
|
|
126
132
|
* changes.
|
|
@@ -147,7 +153,9 @@ export declare class CardForm<T> {
|
|
|
147
153
|
/**
|
|
148
154
|
* Write every staged edit, then re-seed from what the Host accepted. A save
|
|
149
155
|
* that did not land keeps its drafts, so the user corrects them instead of
|
|
150
|
-
* retyping.
|
|
156
|
+
* retyping. The shared form reports `false` (and reloads Host state) for a
|
|
157
|
+
* refused revision or validation, and a transport drop rejects — both fold
|
|
158
|
+
* into the same failed-save path.
|
|
151
159
|
*/
|
|
152
160
|
save(): Promise<void>;
|
|
153
161
|
/**
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Browser half of `dsh-web-fetch-playwright`: registers the locale
|
|
3
|
-
* and the plugin-configuration card keyed by the
|
|
4
|
-
* settings namespace
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Browser half of `dsh-web-fetch-playwright`: registers the locale
|
|
3
|
+
* dictionary and the plugin-configuration card keyed by the
|
|
4
|
+
* `web-fetch-playwright` settings namespace (the composition entry id the
|
|
5
|
+
* host's settings service derives from the plugin's Config schema).
|
|
6
|
+
*
|
|
7
|
+
* Since dsh 0.1.7 the Plugins page owns a plugin's configuration, and its
|
|
8
|
+
* slot contract offers a bundle two seats: the bundle's own form on its
|
|
9
|
+
* package page (`plugins.bundle.config`, keyed by package name — what the
|
|
10
|
+
* user opens straight from the plugin list) and one row's page
|
|
11
|
+
* (`plugins.row.config`, keyed `<package name>#<row id>` — the row's
|
|
12
|
+
* configure control). This bundle is one plugin with one config, so BOTH
|
|
13
|
+
* seats inject the SAME card and controller: whichever way the user arrives,
|
|
14
|
+
* the form is on the first page they land on, and one staging area follows
|
|
15
|
+
* them between the two. The mounts ride `configForms.whileServed`, so a
|
|
16
|
+
* deployment that never composed the host entry shows no trace of the card.
|
|
7
17
|
*
|
|
8
18
|
* @module dsh-web-fetch-playwright/client
|
|
9
19
|
*/
|
|
@@ -11,7 +21,8 @@ import type { Context } from 'cordis';
|
|
|
11
21
|
/** Required services (cordis fiber inject). */
|
|
12
22
|
export declare const inject: string[];
|
|
13
23
|
/**
|
|
14
|
-
* Mount the Playwright plugin-configuration card
|
|
24
|
+
* Mount the Playwright plugin-configuration card while the Host serves the
|
|
25
|
+
* `web-fetch-playwright` namespace.
|
|
15
26
|
* @param ctx - the browser plugin context.
|
|
16
27
|
*/
|
|
17
28
|
export declare function apply(ctx: Context): void;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @module dsh-web-fetch-playwright/client/locales
|
|
6
6
|
*/
|
|
7
7
|
/** Locale keys this card renders. */
|
|
8
|
-
export type PlaywrightCardLocaleKey = '
|
|
8
|
+
export type PlaywrightCardLocaleKey = 'description' | 'backendLabel' | 'backendLocal' | 'backendLocalHint' | 'backendCdp' | 'backendCdpHint' | 'playwrightPath' | 'playwrightPathHint' | 'playwrightPathPlaceholder' | 'cdpEndpoint' | 'cdpEndpointHint' | 'shareBrowserContext' | 'shareBrowserContextHint' | 'denoise' | 'denoiseHint' | 'maxConcurrency' | 'maxConcurrencyHint' | 'maxConcurrencyPlaceholder' | 'challengeWaitMs' | 'challengeWaitMsHint' | 'challengeWaitMsPlaceholder' | 'overridden' | 'reset' | 'readOnly' | 'save' | 'saving' | 'discard' | 'saveFailed' | 'invalidText';
|
|
9
9
|
/** This plugin's dictionary namespace, merged into the locale key map. */
|
|
10
10
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
11
11
|
interface LocaleNamespaceMap {
|
package/lib/types/config.d.ts
CHANGED
|
@@ -4,8 +4,15 @@
|
|
|
4
4
|
* resolved shape, and the small pure normalizers the provider applies per
|
|
5
5
|
* fetch (CDP endpoint shaping) — kept network-free for unit tests.
|
|
6
6
|
*
|
|
7
|
+
* Since dsh 0.1.7 the settings service derives a plugin's configuration page
|
|
8
|
+
* from its composition entry's `Config` schema: every field marked
|
|
9
|
+
* `.volatile()` is editable live (Settings → Plugins), and a committed edit
|
|
10
|
+
* is pushed into the running plugin's volatile references without a remount —
|
|
11
|
+
* this schema IS the `web-fetch-playwright` settings section.
|
|
12
|
+
*
|
|
7
13
|
* @module dsh-web-fetch-playwright/config
|
|
8
14
|
*/
|
|
15
|
+
import type { Volatile } from '@deepseek-ai/cordis';
|
|
9
16
|
import z from '@deepseek-ai/schemastery';
|
|
10
17
|
/** Default CDP endpoint when the settings section leaves it blank. */
|
|
11
18
|
export declare const DEFAULT_CDP_ENDPOINT = "127.0.0.1:9222";
|
|
@@ -86,7 +93,72 @@ export interface Config {
|
|
|
86
93
|
*/
|
|
87
94
|
maxConcurrency?: number;
|
|
88
95
|
}
|
|
89
|
-
export declare const Config: z<
|
|
96
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
97
|
+
backend: z<"local" | "cdp", "local" | "cdp", "volatile-defined">;
|
|
98
|
+
playwrightPath: z<string, string, "volatile-defined">;
|
|
99
|
+
cdpEndpoint: z<string, string, "volatile-defined">;
|
|
100
|
+
shareBrowserContext: z<boolean, boolean, "volatile-defined">;
|
|
101
|
+
denoise: z<boolean, boolean, "volatile-defined">;
|
|
102
|
+
maxConcurrency: z<number, number, "volatile">;
|
|
103
|
+
challengeWaitMs: z<number, number, "volatile-defined">;
|
|
104
|
+
challengeRetries: z<number, number, "volatile-defined">;
|
|
105
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
106
|
+
backend: z<"local" | "cdp", "local" | "cdp", "volatile-defined">;
|
|
107
|
+
playwrightPath: z<string, string, "volatile-defined">;
|
|
108
|
+
cdpEndpoint: z<string, string, "volatile-defined">;
|
|
109
|
+
shareBrowserContext: z<boolean, boolean, "volatile-defined">;
|
|
110
|
+
denoise: z<boolean, boolean, "volatile-defined">;
|
|
111
|
+
maxConcurrency: z<number, number, "volatile">;
|
|
112
|
+
challengeWaitMs: z<number, number, "volatile-defined">;
|
|
113
|
+
challengeRetries: z<number, number, "volatile-defined">;
|
|
114
|
+
}>>, "plain">;
|
|
115
|
+
/**
|
|
116
|
+
* The config `apply` receives once the schema resolves: every volatile field
|
|
117
|
+
* arrives as a live reference whose snapshot a settings commit replaces in
|
|
118
|
+
* place, so the provider re-reads them per fetch (the plugin never remounts
|
|
119
|
+
* for an edit).
|
|
120
|
+
*/
|
|
121
|
+
export interface PlaywrightPluginConfig {
|
|
122
|
+
/** Backend selector as a live reference. */
|
|
123
|
+
backend: Volatile<PlaywrightBackend>;
|
|
124
|
+
/** Local backend executable path as a live reference. */
|
|
125
|
+
playwrightPath: Volatile<string>;
|
|
126
|
+
/** CDP endpoint as a live reference. */
|
|
127
|
+
cdpEndpoint: Volatile<string>;
|
|
128
|
+
/** Shared-context toggle as a live reference. */
|
|
129
|
+
shareBrowserContext: Volatile<boolean>;
|
|
130
|
+
/** Denoise toggle as a live reference. */
|
|
131
|
+
denoise: Volatile<boolean>;
|
|
132
|
+
/**
|
|
133
|
+
* Concurrency limit as a live reference; `undefined` while unset (the
|
|
134
|
+
* field owns no default — the backend resolves one).
|
|
135
|
+
*/
|
|
136
|
+
maxConcurrency: Volatile<number | undefined>;
|
|
137
|
+
/** Challenge wait budget (ms) as a live reference. */
|
|
138
|
+
challengeWaitMs: Volatile<number>;
|
|
139
|
+
/** Challenge retry count as a live reference. */
|
|
140
|
+
challengeRetries: Volatile<number>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Read the live references `apply` holds into one plain input for
|
|
144
|
+
* {@link resolveConfig}; a settings commit has usually replaced the
|
|
145
|
+
* snapshots since the last call, which is the whole point.
|
|
146
|
+
*
|
|
147
|
+
* @param config - the plugin config as the loader resolved it.
|
|
148
|
+
* @returns the current snapshots, ready for resolution.
|
|
149
|
+
*/
|
|
150
|
+
export declare function snapshotsOf(config: PlaywrightPluginConfig): Config;
|
|
151
|
+
/**
|
|
152
|
+
* Resolve any accepted config input into the fully-defaulted, plain form the
|
|
153
|
+
* provider consumes per fetch. Validation goes through the schema, so the
|
|
154
|
+
* volatile wrappers that produces are unwrapped immediately — the provider
|
|
155
|
+
* consumes plain values. The input face is `Partial` by design (composition
|
|
156
|
+
* entries and volatile snapshots both omit fields; defaults supply them).
|
|
157
|
+
*
|
|
158
|
+
* @param config - composition entry, settings-section value, or volatile snapshots.
|
|
159
|
+
* @returns the resolved config.
|
|
160
|
+
*/
|
|
161
|
+
export declare function resolveConfig(config: Partial<Config>): ResolvedConfig;
|
|
90
162
|
/**
|
|
91
163
|
* Complete config after schemastery applies the field defaults it owns.
|
|
92
164
|
* `maxConcurrency` stays optional — {@link effectiveMaxConcurrency} resolves
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host resolve compat for the `punycode/` builtin-slash idiom.
|
|
3
|
+
*
|
|
4
|
+
* dsh web (runtime resolution in `dsh-app-boot`) intercepts Node's CommonJS
|
|
5
|
+
* resolver for every package installed in a profile. Its router classifies a
|
|
6
|
+
* bare request by stripping one trailing path segment, which turns tr46's
|
|
7
|
+
* `require("punycode/")` — the standard npm-package-over-deprecated-builtin
|
|
8
|
+
* idiom — into the builtin name `punycode`, and `require.resolve.paths()` of a
|
|
9
|
+
* builtin returns `null`; the unguarded iteration then throws
|
|
10
|
+
* `TypeError: createRequire.resolve.paths is not a function or its return
|
|
11
|
+
* value is not iterable`, killing the whole `jsdom` import chain (jsdom →
|
|
12
|
+
* whatwg-url → tr46) and with it this plugin's activation.
|
|
13
|
+
*
|
|
14
|
+
* The shim below is installed lazily, immediately before the first `jsdom`
|
|
15
|
+
* load, and only when the running resolver actually exhibits the failure
|
|
16
|
+
* (probed with the very request that breaks). It wraps the public
|
|
17
|
+
* `Module._resolveFilename` — whatever it currently is, native or already
|
|
18
|
+
* host-intercepted — and re-dispatches exactly the affected request shape
|
|
19
|
+
* (`<deprecated builtin>/`) with an explicit `paths` list. An explicit
|
|
20
|
+
* `options.paths` is the documented bypass of every resolution interceptor in
|
|
21
|
+
* the chain (the host wrapper delegates straight to the native resolver for
|
|
22
|
+
* it), so the request lands on the real npm package — the same file plain
|
|
23
|
+
* Node would have found. Hosts without the bug never see the wrapper at all;
|
|
24
|
+
* the probe itself changes nothing.
|
|
25
|
+
*
|
|
26
|
+
* The ESM flavor of the same router path exists in theory (`import
|
|
27
|
+
* 'punycode/'`), but nothing in this plugin's tree imports it that way —
|
|
28
|
+
* tr46 is CommonJS — so the CommonJS hook is the complete fix here.
|
|
29
|
+
*
|
|
30
|
+
* @module dsh-web-fetch-playwright/host-resolve-compat
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Make `require("<deprecated builtin>/")` resolvable under hosts whose
|
|
34
|
+
* profile-scope resolution interceptor mishandles it. Idempotent, synchronous,
|
|
35
|
+
* and a no-op on healthy resolvers (the probe resolves successfully and no
|
|
36
|
+
* wrapper is installed). Must run before the first `require('jsdom')`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function installBuiltinSlashResolveCompat(): void;
|