dsh-web-fetch-playwright 0.1.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.
@@ -0,0 +1,337 @@
1
+ /**
2
+ * The staged-form model behind the Playwright card — a faithful subset of the
3
+ * shipped `ui-settings-plugins` CardForm (same staging semantics: edits stay
4
+ * local until the card's save, presence in the user layer — not value
5
+ * equality — marks a field overridden), plus the two field kinds this card
6
+ * adds: a radio group (backend) and a checkbox (denoise), staged through the
7
+ * same draft mechanism as text.
8
+ *
9
+ * Bundled locally because external client bundles cannot value-import
10
+ * `@deepseek-ai/*` packages; the snapshot store is a local structural clone
11
+ * of the runtime contract.
12
+ *
13
+ * @module dsh-web-fetch-playwright/client/form
14
+ */
15
+
16
+ import type { SettingsScope, SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-runtime/client'
17
+
18
+ /** The write one field's staged draft performs when the card is saved. */
19
+ export type FieldWrite =
20
+ | { kind: 'set'; value: unknown }
21
+ | { kind: 'clear' }
22
+
23
+ /** How one section field converts between its stored value and its draft. */
24
+ export interface CardFieldSpec {
25
+ /** Field name inside the namespace section. */
26
+ field: string
27
+ /** Render a stored value as a draft string; empty when the section carries none. */
28
+ format: (value: unknown) => string
29
+ /**
30
+ * The write this draft stages, or undefined when the draft is not a value
31
+ * this field accepts — which blocks the save rather than discarding it.
32
+ */
33
+ parse: (text: string) => FieldWrite | undefined
34
+ }
35
+
36
+ /** One field as the card renders it. */
37
+ export interface CardFieldState {
38
+ /** Draft string the control renders. */
39
+ text: string
40
+ /** Whether saving would leave a user-layer entry for this field. */
41
+ overridden: boolean
42
+ /** Whether the draft is not a value this field accepts, which blocks saving. */
43
+ invalid: boolean
44
+ }
45
+
46
+ /** Form state every plugin card shares. */
47
+ export interface CardShell {
48
+ /** False while the namespace is not served to this client; the card renders nothing. */
49
+ available: boolean
50
+ /** Whether the Host document accepts writes. */
51
+ writable: boolean
52
+ /** Whether the form holds edits that a save would write. */
53
+ dirty: boolean
54
+ /** Whether any staged draft is invalid, which blocks the save. */
55
+ invalid: boolean
56
+ /** Whether a save is crossing the wire. */
57
+ saving: boolean
58
+ /** Whether the last save did not land as staged; cleared by the next edit or save. */
59
+ failed: boolean
60
+ }
61
+
62
+ /** The write actions the card's slot entry injects. */
63
+ export interface CardActions {
64
+ /** Stage a draft for one field. */
65
+ edit: (field: string, text: string) => void
66
+ /** Stage a clear, so saving lets the field re-inherit the composition layer. */
67
+ resetField: (field: string) => void
68
+ /** Write every staged edit, then re-seed from what the Host accepted. */
69
+ save: () => void
70
+ /** Drop every staged edit. */
71
+ discard: () => void
72
+ }
73
+
74
+ /** Minimal observable snapshot source (structural clone of the runtime contract). */
75
+ export interface SnapshotStore<T> {
76
+ getSnapshot(): T
77
+ subscribe(listener: () => void): () => void
78
+ set(next: T): void
79
+ }
80
+
81
+ /** One staged edit. */
82
+ interface StagedEdit {
83
+ /** Draft string the control renders. */
84
+ text: string
85
+ /** True when this edit clears the field whatever draft it shows. */
86
+ clear: boolean
87
+ }
88
+
89
+ /** One staged edit resolved into the write a save performs. */
90
+ interface PlannedWrite {
91
+ /** Field this entry writes. */
92
+ field: string
93
+ /** Perform the write and report whether the Host holds the staged value. */
94
+ run: (() => Promise<boolean>) | undefined
95
+ }
96
+
97
+ /**
98
+ * A free-text field. An empty draft clears the field, so emptying the control
99
+ * and saving is the same gesture as resetting it.
100
+ * @param field - field name inside the namespace section.
101
+ * @returns the field's conversion spec.
102
+ */
103
+ export function textField(field: string): CardFieldSpec {
104
+ return {
105
+ field,
106
+ format: value => typeof value === 'string' ? value : '',
107
+ parse: (text) => {
108
+ const trimmed = text.trim()
109
+ return trimmed === '' ? { kind: 'clear' } : { kind: 'set', value: trimmed }
110
+ },
111
+ }
112
+ }
113
+
114
+ /**
115
+ * A radio-group field over a fixed option set.
116
+ * @param field - field name inside the namespace section.
117
+ * @param values - the accepted option values.
118
+ * @returns the field's conversion spec.
119
+ */
120
+ export function radioField(field: string, values: readonly string[]): CardFieldSpec {
121
+ const set = new Set(values)
122
+ return {
123
+ field,
124
+ format: value => typeof value === 'string' && set.has(value) ? value : '',
125
+ parse: text => set.has(text) ? { kind: 'set', value: text } : undefined,
126
+ }
127
+ }
128
+
129
+ /**
130
+ * A checkbox field. The draft carries 'true'/'false'; an absent stored value
131
+ * formats as '' so the control can fall back to the schema default.
132
+ * @param field - field name inside the namespace section.
133
+ * @returns the field's conversion spec.
134
+ */
135
+ export function checkboxField(field: string): CardFieldSpec {
136
+ return {
137
+ field,
138
+ format: value => typeof value === 'boolean' ? (value ? 'true' : 'false') : '',
139
+ parse: text => text === 'true' ? { kind: 'set', value: true } : text === 'false' ? { kind: 'set', value: false } : undefined,
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Stages the Playwright card's edits over one settings namespace and writes
145
+ * them on save. Publishes through a snapshot store because slot components
146
+ * read through a selector while both the scope and the drafts change below.
147
+ */
148
+ export class CardForm<T> {
149
+ private readonly specs: Map<string, CardFieldSpec>
150
+ private readonly staged = new Map<string, StagedEdit>()
151
+ private readonly listeners = new Set<() => void>()
152
+ private saving = false
153
+ private failed = false
154
+
155
+ /**
156
+ * @param scope - the bound settings scope for this card's namespace.
157
+ * @param specs - the section fields this card edits.
158
+ */
159
+ constructor(
160
+ private readonly scope: SettingsScope<T>,
161
+ specs: CardFieldSpec[],
162
+ ) {
163
+ this.specs = new Map(specs.map(spec => [spec.field, spec]))
164
+ scope.subscribe(() => { this.publish() })
165
+ }
166
+
167
+ /**
168
+ * Publish a projection of this form, rebuilt whenever the scope or a draft
169
+ * changes.
170
+ * @param project - build the card's state from the form's current reads.
171
+ * @returns the store the card's component reads through its bound selector.
172
+ */
173
+ bind<S>(project: () => S): SnapshotStore<S> {
174
+ let last = project()
175
+ const listeners = new Set<() => void>()
176
+ const store: SnapshotStore<S> = {
177
+ getSnapshot: () => last,
178
+ subscribe: (listener) => {
179
+ listeners.add(listener)
180
+ return () => { listeners.delete(listener) }
181
+ },
182
+ set: (next) => {
183
+ last = next
184
+ for (const listener of listeners) listener()
185
+ },
186
+ }
187
+ this.listeners.add(() => { store.set(project()) })
188
+ return store
189
+ }
190
+
191
+ /**
192
+ * Read the card-level state: what the Host serves, and what a save would do.
193
+ * @returns the form state every card shares.
194
+ */
195
+ shell(): CardShell {
196
+ const snapshot = this.scope.getSnapshot()
197
+ const plan = this.plan()
198
+ return {
199
+ available: snapshot.status === 'ready',
200
+ writable: snapshot.writable,
201
+ dirty: plan.length > 0,
202
+ invalid: plan.some(item => item.run === undefined),
203
+ saving: this.saving,
204
+ failed: this.failed,
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Read one control's state.
210
+ * @param field - field name of a section field.
211
+ * @returns the draft string, whether a save would leave an override, and whether it is invalid.
212
+ */
213
+ field(field: string): CardFieldState {
214
+ const staged = this.staged.get(field)
215
+ const spec = this.spec(field)
216
+ if (staged === undefined) {
217
+ return { text: spec.format(this.sectionValue(field)), overridden: this.stored(field), invalid: false }
218
+ }
219
+ const write = staged.clear ? { kind: 'clear' as const } : spec.parse(staged.text)
220
+ return {
221
+ text: staged.text,
222
+ overridden: write?.kind === 'set',
223
+ invalid: write === undefined,
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Build the edit, reset, save, and discard actions bound to this form.
229
+ * @returns the actions the card's slot entry injects.
230
+ */
231
+ actions(): CardActions {
232
+ return {
233
+ edit: (field, text) => { this.stage(field, { text, clear: false }) },
234
+ resetField: (field) => {
235
+ this.stage(field, { text: this.spec(field).format(this.baseValue(field)), clear: true })
236
+ },
237
+ save: () => { void this.save() },
238
+ discard: () => {
239
+ if (this.staged.size === 0 && !this.failed) return
240
+ this.staged.clear()
241
+ this.failed = false
242
+ this.publish()
243
+ },
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Write every staged edit, then re-seed from what the Host accepted. A save
249
+ * that did not land keeps its drafts, so the user corrects them instead of
250
+ * retyping.
251
+ */
252
+ async save(): Promise<void> {
253
+ const plan = this.plan()
254
+ const writes = plan.flatMap(item => item.run === undefined ? [] : [item.run])
255
+ if (plan.length === 0 || this.saving || writes.length !== plan.length) return
256
+ this.saving = true
257
+ this.failed = false
258
+ this.publish()
259
+ let landed = true
260
+ for (const write of writes) {
261
+ landed = await write() && landed
262
+ }
263
+ if (landed) this.staged.clear()
264
+ this.saving = false
265
+ this.failed = !landed
266
+ this.publish()
267
+ }
268
+
269
+ /**
270
+ * Every staged edit a save would write. An entry whose draft is not a value
271
+ * its field accepts carries no write: the form stays dirty and the save
272
+ * refuses rather than dropping the edit.
273
+ */
274
+ private plan(): PlannedWrite[] {
275
+ const plan: PlannedWrite[] = []
276
+ for (const [field, staged] of this.staged) {
277
+ const spec = this.spec(field)
278
+ if (staged.clear) {
279
+ if (this.stored(field)) plan.push({ field, run: () => this.clear(field) })
280
+ continue
281
+ }
282
+ if (staged.text === spec.format(this.sectionValue(field))) continue
283
+ const write = spec.parse(staged.text)
284
+ if (write === undefined) plan.push({ field, run: undefined })
285
+ else if (write.kind === 'clear') plan.push({ field, run: () => this.clear(field) })
286
+ else plan.push({ field, run: () => this.store(field, write.value) })
287
+ }
288
+ return plan
289
+ }
290
+
291
+ private async clear(field: string): Promise<boolean> {
292
+ await this.scope.unset(field)
293
+ return !this.stored(field)
294
+ }
295
+
296
+ private async store(field: string, value: unknown): Promise<boolean> {
297
+ await this.scope.set(field, value)
298
+ return this.userLayer()?.[field] === value
299
+ }
300
+
301
+ private stage(field: string, edit: StagedEdit): void {
302
+ this.staged.set(field, edit)
303
+ this.failed = false
304
+ this.publish()
305
+ }
306
+
307
+ private spec(field: string): CardFieldSpec {
308
+ const spec = this.specs.get(field)
309
+ if (spec === undefined) throw new Error(`plugin card has no field ${field}`)
310
+ return spec
311
+ }
312
+
313
+ private snapshotOf(): SettingsScopeSnapshot<T> {
314
+ return this.scope.getSnapshot()
315
+ }
316
+
317
+ private sectionValue(field: string): unknown {
318
+ return (this.snapshotOf().value as Record<string, unknown> | undefined)?.[field]
319
+ }
320
+
321
+ private baseValue(field: string): unknown {
322
+ return (this.snapshotOf().base as Record<string, unknown> | undefined)?.[field]
323
+ }
324
+
325
+ private userLayer(): Record<string, unknown> | undefined {
326
+ return this.snapshotOf().user as Record<string, unknown> | undefined
327
+ }
328
+
329
+ private stored(field: string): boolean {
330
+ const user = this.userLayer()
331
+ return user !== undefined && Object.hasOwn(user, field)
332
+ }
333
+
334
+ private publish(): void {
335
+ for (const listener of this.listeners) listener()
336
+ }
337
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Browser half of `dsh-web-fetch-playwright`: registers the locale dictionary
3
+ * and the plugin-configuration card keyed by the `web-fetch-playwright`
4
+ * settings namespace, so the card pairs with the Host section the plugin half
5
+ * registers — the shipped configurable-plugins tab dispatches it with no
6
+ * changes.
7
+ *
8
+ * @module dsh-web-fetch-playwright/client
9
+ */
10
+
11
+ import type { Context } from 'cordis'
12
+ // Type-only: pulls the ctx.locale / ctx.slots / ctx.settingsScope Context
13
+ // merges, and the 'settings.plugin.item' SlotMap declaration from the
14
+ // ui-settings-plugins package that owns the slot contract.
15
+ import type {} from '@deepseek-ai/dsh-client-locale/client'
16
+ import type {} from '@deepseek-ai/dsh-client-ui-slots'
17
+ import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
18
+ import type {} from '@deepseek-ai/dsh-client-ui-settings-plugins/client'
19
+ import { PlaywrightCardController, WEB_FETCH_PLAYWRIGHT_NS } from './controller.ts'
20
+ import { PlaywrightCard } from './card.tsx'
21
+ import { en, zh } from './locales.ts'
22
+
23
+ /** Dictionary namespace owned by this plugin. */
24
+ const NS = 'web-fetch-playwright'
25
+
26
+ /** Required services (cordis fiber inject). */
27
+ export const inject = ['slots', 'locale', 'settingsScope']
28
+
29
+ /**
30
+ * Mount the Playwright plugin-configuration card.
31
+ * @param ctx - the browser plugin context.
32
+ */
33
+ export function apply(ctx: Context): void {
34
+ ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'web-fetch-playwright: card dictionary')
35
+
36
+ const controller = new PlaywrightCardController(
37
+ ctx.settingsScope.bind({ namespace: WEB_FETCH_PLAYWRIGHT_NS }),
38
+ )
39
+ ctx.slots.inject('settings.plugin.item', () => ctx.slots.register({
40
+ name: 'settings.plugin.item',
41
+ key: WEB_FETCH_PLAYWRIGHT_NS,
42
+ locale: NS,
43
+ inject: () => controller.inject(),
44
+ }, PlaywrightCard))
45
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Locale bundles for the Playwright card (the plugin's own dictionary
3
+ * namespace, registered with the client locale service).
4
+ *
5
+ * @module dsh-web-fetch-playwright/client/locales
6
+ */
7
+
8
+ /** Locale keys this card renders. */
9
+ export type PlaywrightCardLocaleKey =
10
+ | 'title' | 'description'
11
+ | 'backendLabel' | 'backendLocal' | 'backendLocalHint' | 'backendCdp' | 'backendCdpHint'
12
+ | 'playwrightPath' | 'playwrightPathHint' | 'playwrightPathPlaceholder'
13
+ | 'cdpEndpoint' | 'cdpEndpointHint'
14
+ | 'denoise' | 'denoiseHint'
15
+ | 'overridden' | 'reset' | 'readOnly' | 'expand' | 'collapse'
16
+ | 'save' | 'saving' | 'discard' | 'unsaved' | 'saveFailed' | 'invalidText'
17
+
18
+ /** This plugin's dictionary namespace, merged into the locale key map. */
19
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
20
+ interface LocaleNamespaceMap {
21
+ 'web-fetch-playwright': PlaywrightCardLocaleKey
22
+ }
23
+ }
24
+
25
+ /** English copy. */
26
+ export const en: Record<PlaywrightCardLocaleKey, string> = {
27
+ title: 'Playwright web fetch',
28
+ description: 'Fetches pages with a real browser (local Playwright or CDP) and returns denoised markdown.',
29
+ backendLabel: 'Playwright backend',
30
+ backendLocal: 'Local Playwright',
31
+ backendLocalHint: 'Launch a browser through the local playwright installation.',
32
+ backendCdp: 'Remote CDP endpoint',
33
+ backendCdpHint: 'Drive an already-running browser over its DevTools Protocol port.',
34
+ playwrightPath: 'Playwright executable path',
35
+ playwrightPathHint: 'Leave blank to find playwright on $PATH; a browser executable path also works.',
36
+ playwrightPathPlaceholder: '(auto: playwright from $PATH)',
37
+ cdpEndpoint: 'CDP endpoint',
38
+ cdpEndpointHint: 'host:port or http(s)/ws URL. Leave blank for 127.0.0.1:9222.',
39
+ denoise: 'Enable the denoise algorithm',
40
+ denoiseHint: 'Readability + DOMPurify strip nav bars, sidebars, footers, and ads before converting to markdown.',
41
+ overridden: 'Overridden',
42
+ reset: 'Reset to default',
43
+ readOnly: 'This deployment stores settings read-only.',
44
+ expand: 'Show settings',
45
+ collapse: 'Hide settings',
46
+ save: 'Save',
47
+ saving: 'Saving…',
48
+ discard: 'Discard',
49
+ unsaved: 'Unsaved',
50
+ saveFailed: 'The deployment did not accept these values; they were left for you to correct.',
51
+ invalidText: 'This value is not accepted here.',
52
+ }
53
+
54
+ /** Simplified Chinese copy. */
55
+ export const zh: Record<PlaywrightCardLocaleKey, string> = {
56
+ title: 'Playwright 网页爬取',
57
+ description: '用真实浏览器(本地 Playwright 或 CDP)抓取网页,降噪后转为 Markdown。',
58
+ backendLabel: 'Playwright 后端',
59
+ backendLocal: '本地 Playwright',
60
+ backendLocalHint: '通过本机的 playwright 安装启动浏览器。',
61
+ backendCdp: '远端 CDP 地址',
62
+ backendCdpHint: '连接一个已在运行的浏览器的 DevTools 协议端口。',
63
+ playwrightPath: 'Playwright 可执行文件路径',
64
+ playwrightPathHint: '留空则按系统 $PATH 查找 playwright;也支持填浏览器可执行文件路径。',
65
+ playwrightPathPlaceholder: '(自动:按 $PATH 查找 playwright)',
66
+ cdpEndpoint: 'CDP 地址',
67
+ cdpEndpointHint: 'host:port 或 http(s)/ws 地址;留空默认 127.0.0.1:9222。',
68
+ denoise: '启用降噪算法',
69
+ denoiseHint: '使用 Readability + DOMPurify 清洗导航栏、侧边栏、页脚与贴片广告后再转为 Markdown。',
70
+ overridden: '已覆盖',
71
+ reset: '恢复默认',
72
+ readOnly: '本部署的设置为只读。',
73
+ expand: '展开设置',
74
+ collapse: '收起设置',
75
+ save: '保存',
76
+ saving: '保存中…',
77
+ discard: '放弃修改',
78
+ unsaved: '未保存',
79
+ saveFailed: '本部署没有接受这些值,已保留供你修改。',
80
+ invalidText: '该值不被此设置项接受。',
81
+ }
@@ -0,0 +1,4 @@
1
+ declare module '*.module.css' {
2
+ const classes: Record<string, string>
3
+ export default classes
4
+ }
package/src/config.ts ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Settings/config surface for the Playwright fetch provider: the schemastery
3
+ * schema the loader validates the row against, the settings namespace's
4
+ * resolved shape, and the small pure normalizers the provider applies per
5
+ * fetch (CDP endpoint shaping) — kept network-free for unit tests.
6
+ *
7
+ * @module dsh-web-fetch-playwright/config
8
+ */
9
+
10
+ import z from '@deepseek-ai/schemastery'
11
+
12
+ /** Default CDP endpoint when the settings section leaves it blank. */
13
+ export const DEFAULT_CDP_ENDPOINT = '127.0.0.1:9222'
14
+
15
+ /** Which browser backend serves a fetch. */
16
+ export type PlaywrightBackend = 'local' | 'cdp'
17
+
18
+ /** Plugin config: everything optional — the schema fills the defaults. */
19
+ export interface Config {
20
+ /** Backend selector: local Playwright launch or a remote CDP endpoint. */
21
+ backend?: PlaywrightBackend
22
+ /**
23
+ * Local backend: path to a `playwright` executable (Node CLI) or to a
24
+ * Chromium-family browser executable. Empty = discover `playwright` on
25
+ * `$PATH`, then fall back to the plugin's bundled `playwright-core`.
26
+ */
27
+ playwrightPath?: string
28
+ /** CDP backend: `host:port`, `http(s)://…`, or `ws(s)://…`. Empty = default. */
29
+ cdpEndpoint?: string
30
+ /** Whether the Readability + DOMPurify denoise pipeline runs before markdown. */
31
+ denoise?: boolean
32
+ }
33
+
34
+ export const Config: z<Config> = z.object({
35
+ // union-of-consts rather than z.enum: the profile's published schemastery
36
+ // build does not expose `.enum`, and this schema executes at runtime
37
+ // against that copy.
38
+ backend: z.union([z.const('local'), z.const('cdp')]).default('local'),
39
+ playwrightPath: z.string().default(''),
40
+ cdpEndpoint: z.string().default(''),
41
+ denoise: z.boolean().default(true),
42
+ })
43
+
44
+ /** Complete config after schemastery applies every field default. */
45
+ export type ResolvedConfig = Required<Config>
46
+
47
+ /**
48
+ * Normalize a configured CDP endpoint for `chromium.connectOverCDP`:
49
+ * blank becomes the default loopback endpoint; `wss?://` and `https?://`
50
+ * pass through; a bare `host:port` gains the `http://` scheme Playwright's
51
+ * CDP discovery (`GET /json/version`) expects.
52
+ *
53
+ * @param input - the raw configured endpoint.
54
+ * @returns the endpoint string to hand to Playwright.
55
+ * @throws {Error} when the normalized value is not a parseable URL.
56
+ */
57
+ export function normalizeCdpEndpoint(input: string): string {
58
+ const trimmed = input.trim()
59
+ const value = trimmed === '' ? DEFAULT_CDP_ENDPOINT : trimmed
60
+ const candidate = /^wss?:\/\//i.test(value) || /^https?:\/\//i.test(value)
61
+ ? value
62
+ : `http://${value}`
63
+ // Surface garbage early with a plain Error; the provider wraps it in a
64
+ // structured WebError with the configured value for context.
65
+ new URL(candidate)
66
+ return candidate
67
+ }
package/src/gfm.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Ambient declaration for `@joplin/turndown-plugin-gfm` (untyped on npm).
3
+ * Only the `gfm` plugin function is consumed.
4
+ */
5
+ declare module '@joplin/turndown-plugin-gfm' {
6
+ import type TurndownService from 'turndown'
7
+ /** Register GFM tables/strikethrough/deletion rules on a TurndownService. */
8
+ export function gfm(service: TurndownService): void
9
+ }
package/src/index.ts ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * `dsh-web-fetch-playwright`: registers the Playwright/CDP
3
+ * {@link PlaywrightFetchProvider} with `ctx.web` and exposes its settings
4
+ * section ('web-fetch-playwright') so the web client's plugin-configuration
5
+ * card can edit it live.
6
+ *
7
+ * A function plugin (NOT a default-export service): like the shipped search
8
+ * providers, it registers INTO the seam's fetch registry.
9
+ *
10
+ * @module dsh-web-fetch-playwright
11
+ */
12
+
13
+ import type { Context } from '@deepseek-ai/cordis'
14
+ import { installSettingsSection, settingsNamespace } from '@deepseek-ai/dsh-settings'
15
+ import type {} from '@deepseek-ai/dsh-web'
16
+ import { Config } from './config.ts'
17
+ import type { ResolvedConfig } from './config.ts'
18
+ import { PlaywrightFetchProvider } from './provider.ts'
19
+
20
+ export { Config, DEFAULT_CDP_ENDPOINT, normalizeCdpEndpoint } from './config.ts'
21
+ export type { Config as PlaywrightFetchConfig, PlaywrightBackend, ResolvedConfig } from './config.ts'
22
+ export { PLAYWRIGHT_FETCH_PROVIDER_ID, PlaywrightFetchProvider } from './provider.ts'
23
+ export { htmlToMarkdown } from './markdown.ts'
24
+ export type { DenoiseMode, DenoiseResult } from './markdown.ts'
25
+
26
+ /** Cordis plugin name used by loader diagnostics. */
27
+ export const name = 'dsh-web-fetch-playwright'
28
+
29
+ /** The web seam this provider registers into. */
30
+ export const inject = ['web']
31
+
32
+ /** Settings namespace carrying this provider's configuration card. */
33
+ export const WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE = settingsNamespace('web-fetch-playwright')
34
+
35
+ /** Register the Playwright fetch provider with `ctx.web`. */
36
+ export function apply(ctx: Context, config: Config): void {
37
+ // `current` is REASSIGNED by setSource when the settings scope attaches
38
+ // (possibly after this function returns), so the provider must receive an
39
+ // indirection — `() => current()` — never the thunk's value at this moment.
40
+ // Passing `current` directly would pin the composition entry forever (the
41
+ // web-search-deepseek provider uses the same wrapper idiom).
42
+ let current: () => ResolvedConfig = () => config as ResolvedConfig
43
+ installSettingsSection(ctx, WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE, Config, config, {
44
+ setSource: (source) => {
45
+ current = source as () => ResolvedConfig
46
+ },
47
+ // The provider projects the section per fetch, so a committed change
48
+ // needs no re-registration.
49
+ onChange: () => {},
50
+ })
51
+ ctx.web.registerFetchProvider(new PlaywrightFetchProvider(() => current()))
52
+ }