dsh-web-fetch-playwright 0.2.7 → 0.2.8
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 +70 -30
- 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/index.d.ts +29 -11
- 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/index.ts +51 -30
package/src/config.ts
CHANGED
|
@@ -4,9 +4,16 @@
|
|
|
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
|
*/
|
|
9
15
|
|
|
16
|
+
import type { Volatile } from '@deepseek-ai/cordis'
|
|
10
17
|
import z from '@deepseek-ai/schemastery'
|
|
11
18
|
|
|
12
19
|
/** Default CDP endpoint when the settings section leaves it blank. */
|
|
@@ -99,23 +106,98 @@ export interface Config {
|
|
|
99
106
|
maxConcurrency?: number
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
// union-of-consts rather than z.enum: the profile's published schemastery
|
|
110
|
+
// build does not expose `.enum`, and this schema executes at runtime
|
|
111
|
+
// against that copy. Every field is `.volatile()`: the whole section is
|
|
112
|
+
// live-editable from the Plugins page and a commit reaches the running
|
|
113
|
+
// provider without a remount.
|
|
114
|
+
export const Config = z.object({
|
|
115
|
+
backend: z.union([z.const('local'), z.const('cdp')]).default('local').volatile(),
|
|
116
|
+
playwrightPath: z.string().default('').volatile(),
|
|
117
|
+
cdpEndpoint: z.string().default('').volatile(),
|
|
118
|
+
shareBrowserContext: z.boolean().default(true).volatile(),
|
|
119
|
+
denoise: z.boolean().default(true).volatile(),
|
|
111
120
|
// Optional on purpose: the effective default depends on `backend`, which a
|
|
112
121
|
// static schema default cannot express.
|
|
113
|
-
maxConcurrency: z.number().step(1).min(1).max(MAX_CONCURRENCY_CEILING),
|
|
122
|
+
maxConcurrency: z.number().step(1).min(1).max(MAX_CONCURRENCY_CEILING).volatile(),
|
|
114
123
|
// The bounded natural-wait knobs; 0 disables the whole challenge path.
|
|
115
|
-
challengeWaitMs: z.number().step(100).min(0).max(MAX_CHALLENGE_WAIT_MS).default(DEFAULT_CHALLENGE_WAIT_MS),
|
|
116
|
-
challengeRetries: z.number().step(1).min(0).max(MAX_CHALLENGE_RETRIES).default(DEFAULT_CHALLENGE_RETRIES),
|
|
124
|
+
challengeWaitMs: z.number().step(100).min(0).max(MAX_CHALLENGE_WAIT_MS).default(DEFAULT_CHALLENGE_WAIT_MS).volatile(),
|
|
125
|
+
challengeRetries: z.number().step(1).min(0).max(MAX_CHALLENGE_RETRIES).default(DEFAULT_CHALLENGE_RETRIES).volatile(),
|
|
117
126
|
})
|
|
118
127
|
|
|
128
|
+
/**
|
|
129
|
+
* The config `apply` receives once the schema resolves: every volatile field
|
|
130
|
+
* arrives as a live reference whose snapshot a settings commit replaces in
|
|
131
|
+
* place, so the provider re-reads them per fetch (the plugin never remounts
|
|
132
|
+
* for an edit).
|
|
133
|
+
*/
|
|
134
|
+
export interface PlaywrightPluginConfig {
|
|
135
|
+
/** Backend selector as a live reference. */
|
|
136
|
+
backend: Volatile<PlaywrightBackend>
|
|
137
|
+
/** Local backend executable path as a live reference. */
|
|
138
|
+
playwrightPath: Volatile<string>
|
|
139
|
+
/** CDP endpoint as a live reference. */
|
|
140
|
+
cdpEndpoint: Volatile<string>
|
|
141
|
+
/** Shared-context toggle as a live reference. */
|
|
142
|
+
shareBrowserContext: Volatile<boolean>
|
|
143
|
+
/** Denoise toggle as a live reference. */
|
|
144
|
+
denoise: Volatile<boolean>
|
|
145
|
+
/**
|
|
146
|
+
* Concurrency limit as a live reference; `undefined` while unset (the
|
|
147
|
+
* field owns no default — the backend resolves one).
|
|
148
|
+
*/
|
|
149
|
+
maxConcurrency: Volatile<number | undefined>
|
|
150
|
+
/** Challenge wait budget (ms) as a live reference. */
|
|
151
|
+
challengeWaitMs: Volatile<number>
|
|
152
|
+
/** Challenge retry count as a live reference. */
|
|
153
|
+
challengeRetries: Volatile<number>
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Read the live references `apply` holds into one plain input for
|
|
158
|
+
* {@link resolveConfig}; a settings commit has usually replaced the
|
|
159
|
+
* snapshots since the last call, which is the whole point.
|
|
160
|
+
*
|
|
161
|
+
* @param config - the plugin config as the loader resolved it.
|
|
162
|
+
* @returns the current snapshots, ready for resolution.
|
|
163
|
+
*/
|
|
164
|
+
export function snapshotsOf(config: PlaywrightPluginConfig): Config {
|
|
165
|
+
return {
|
|
166
|
+
backend: config.backend.get(),
|
|
167
|
+
playwrightPath: config.playwrightPath.get(),
|
|
168
|
+
cdpEndpoint: config.cdpEndpoint.get(),
|
|
169
|
+
shareBrowserContext: config.shareBrowserContext.get(),
|
|
170
|
+
denoise: config.denoise.get(),
|
|
171
|
+
maxConcurrency: config.maxConcurrency.get(),
|
|
172
|
+
challengeWaitMs: config.challengeWaitMs.get(),
|
|
173
|
+
challengeRetries: config.challengeRetries.get(),
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Resolve any accepted config input into the fully-defaulted, plain form the
|
|
179
|
+
* provider consumes per fetch. Validation goes through the schema, so the
|
|
180
|
+
* volatile wrappers that produces are unwrapped immediately — the provider
|
|
181
|
+
* consumes plain values. The input face is `Partial` by design (composition
|
|
182
|
+
* entries and volatile snapshots both omit fields; defaults supply them).
|
|
183
|
+
*
|
|
184
|
+
* @param config - composition entry, settings-section value, or volatile snapshots.
|
|
185
|
+
* @returns the resolved config.
|
|
186
|
+
*/
|
|
187
|
+
export function resolveConfig(config: Partial<Config>): ResolvedConfig {
|
|
188
|
+
const resolved = Config(config as never) as PlaywrightPluginConfig
|
|
189
|
+
return {
|
|
190
|
+
backend: resolved.backend.get(),
|
|
191
|
+
playwrightPath: resolved.playwrightPath.get(),
|
|
192
|
+
cdpEndpoint: resolved.cdpEndpoint.get(),
|
|
193
|
+
shareBrowserContext: resolved.shareBrowserContext.get(),
|
|
194
|
+
denoise: resolved.denoise.get(),
|
|
195
|
+
maxConcurrency: resolved.maxConcurrency.get(),
|
|
196
|
+
challengeWaitMs: resolved.challengeWaitMs.get(),
|
|
197
|
+
challengeRetries: resolved.challengeRetries.get(),
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
119
201
|
/**
|
|
120
202
|
* Complete config after schemastery applies the field defaults it owns.
|
|
121
203
|
* `maxConcurrency` stays optional — {@link effectiveMaxConcurrency} resolves
|
package/src/index.ts
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `dsh-web-fetch-playwright`: registers the Playwright/CDP
|
|
3
|
-
* {@link PlaywrightFetchProvider} with `ctx.web
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* {@link PlaywrightFetchProvider} with `ctx.web`.
|
|
4
|
+
*
|
|
5
|
+
* The `web-fetch-playwright` settings section is derived from this plugin's
|
|
6
|
+
* `Config` schema (dsh ≥ 0.1.7): its volatile fields are editable live on
|
|
7
|
+
* the Plugins page, and a committed change is pushed into the running
|
|
8
|
+
* config's volatile references — the provider re-reads them per fetch, so an
|
|
9
|
+
* edit reaches the next request without a restart or re-registration.
|
|
6
10
|
*
|
|
7
11
|
* A function plugin (NOT a default-export service): like the shipped search
|
|
8
|
-
* providers, it registers INTO the seam's fetch registry.
|
|
12
|
+
* providers, it registers INTO the web seam's fetch registry.
|
|
9
13
|
*
|
|
10
14
|
* @module dsh-web-fetch-playwright
|
|
11
15
|
*/
|
|
12
16
|
|
|
13
17
|
import type { Context } from '@deepseek-ai/cordis'
|
|
14
|
-
import type {} from '@deepseek-ai/dsh-settings'
|
|
15
18
|
import type {} from '@deepseek-ai/dsh-web'
|
|
16
|
-
import {
|
|
17
|
-
import type {
|
|
19
|
+
import { resolveConfig, snapshotsOf } from './config.ts'
|
|
20
|
+
import type { PlaywrightPluginConfig } from './config.ts'
|
|
18
21
|
import { PlaywrightFetchProvider } from './provider.ts'
|
|
19
22
|
|
|
20
|
-
export {
|
|
21
|
-
|
|
23
|
+
export {
|
|
24
|
+
Config,
|
|
25
|
+
DEFAULT_CDP_ENDPOINT,
|
|
26
|
+
DEFAULT_CHALLENGE_RETRIES,
|
|
27
|
+
DEFAULT_CHALLENGE_WAIT_MS,
|
|
28
|
+
effectiveChallengeRetries,
|
|
29
|
+
effectiveChallengeWaitMs,
|
|
30
|
+
effectiveContextMode,
|
|
31
|
+
normalizeCdpEndpoint,
|
|
32
|
+
resolveConfig,
|
|
33
|
+
snapshotsOf,
|
|
34
|
+
} from './config.ts'
|
|
35
|
+
export type {
|
|
36
|
+
Config as PlaywrightFetchConfig,
|
|
37
|
+
CdpContextMode,
|
|
38
|
+
PlaywrightBackend,
|
|
39
|
+
PlaywrightPluginConfig,
|
|
40
|
+
ResolvedConfig,
|
|
41
|
+
} from './config.ts'
|
|
22
42
|
export { CdpConnectionPool } from './cdp-pool.ts'
|
|
23
43
|
export type { CdpAcquireMode, CdpConnect, CdpLease } from './cdp-pool.ts'
|
|
24
44
|
export { CHALLENGE_DOM_PROBE, CHALLENGE_FINISH_RESERVE_MS, CHALLENGE_POLL_INTERVAL_MS, CHALLENGE_TITLE_RE, classifyChallengeHtml, classifyChallengeResponse, isChallengeCompatibleResponse } from './challenge.ts'
|
|
@@ -30,33 +50,34 @@ export type { DenoiseMode, DenoiseResult } from './markdown.ts'
|
|
|
30
50
|
/** Cordis plugin name used by loader diagnostics. */
|
|
31
51
|
export const name = 'dsh-web-fetch-playwright'
|
|
32
52
|
|
|
33
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* The capability seam this plugin registers into. The settings section
|
|
55
|
+
* needs no inject: the host's settings service derives it from the entry's
|
|
56
|
+
* `Config` schema (its volatile fields) by entry id.
|
|
57
|
+
*/
|
|
34
58
|
export const inject = ['web']
|
|
35
59
|
|
|
36
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Settings namespace carrying this provider's configuration page: the
|
|
62
|
+
* composition entry id, which is what the settings service keys the
|
|
63
|
+
* derived section by.
|
|
64
|
+
*/
|
|
37
65
|
export const WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE = 'web-fetch-playwright'
|
|
38
66
|
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
// The provider projects the section per fetch, so a committed change
|
|
53
|
-
// needs no re-registration.
|
|
54
|
-
onChange: () => {},
|
|
55
|
-
})
|
|
56
|
-
})
|
|
67
|
+
/**
|
|
68
|
+
* Register the Playwright fetch provider with `ctx.web`.
|
|
69
|
+
*
|
|
70
|
+
* @param ctx - plugin context supplying the web seam.
|
|
71
|
+
* @param config - the loader-resolved plugin config; its volatile fields are
|
|
72
|
+
* live references a settings commit updates in place.
|
|
73
|
+
*/
|
|
74
|
+
export function apply(ctx: Context, config: PlaywrightPluginConfig): void {
|
|
75
|
+
// Re-read AND re-resolve per fetch: `snapshotsOf` dereferences the volatile
|
|
76
|
+
// references each time, so a section committed from the settings page
|
|
77
|
+
// between two fetches serves the second one.
|
|
78
|
+
const provider = new PlaywrightFetchProvider(() => resolveConfig(snapshotsOf(config)))
|
|
57
79
|
// The CDP backend holds one shared connection for the provider's lifetime;
|
|
58
80
|
// drop it when this plugin unloads so restarts don't strand sockets.
|
|
59
|
-
const provider = new PlaywrightFetchProvider(() => current())
|
|
60
81
|
ctx.effect(() => () => { void provider.dispose() }, 'dsh-web-fetch-playwright: shared CDP connection')
|
|
61
82
|
ctx.web.registerFetchProvider(provider)
|
|
62
83
|
}
|