@yanglaofish/dsh-proxy-pro 1.0.10 → 2.0.1
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/docs/LESSONS.md +1217 -905
- package/lib/client.js +149 -25
- package/lib/index.js +901 -774
- package/lib/proxy-core.js +79 -0
- package/package.json +5 -5
package/lib/proxy-core.js
CHANGED
|
@@ -15,6 +15,85 @@
|
|
|
15
15
|
const PROXY_REG_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'
|
|
16
16
|
const LOCAL_ENTRIES = ['localhost', '127.0.0.1', '::1']
|
|
17
17
|
|
|
18
|
+
/** Bundle row id (cordis.patch.yml) — also the settings namespace on dsh >= 0.2,
|
|
19
|
+
* where a plugin's OWN composition entry is its settings form (LESSONS §33). */
|
|
20
|
+
export const DEFAULT_ENTRY_ID = 'dsh-proxy-pro'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resolve this plugin's composition entry id — the settings namespace on
|
|
24
|
+
* dsh >= 0.2 (LESSONS §33). Core plugins read it straight off the fiber
|
|
25
|
+
* (`ctx.fiber.entry?.options.id`, e.g. dsh-experimental-speech-to-text); the
|
|
26
|
+
* config-editor row match is the fallback, then the known bundle id.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveEntryId(ctx, configEditor, fallback = DEFAULT_ENTRY_ID) {
|
|
29
|
+
const direct = ctx?.fiber?.entry?.options?.id
|
|
30
|
+
if (typeof direct === 'string' && direct.length > 0) return direct
|
|
31
|
+
try {
|
|
32
|
+
const rows = configEditor?.configuration?.() ?? []
|
|
33
|
+
const own = rows.find((row) => row?.entry?.fiber === ctx?.fiber)
|
|
34
|
+
?? rows.find((row) => row?.entry?.options?.id === fallback)
|
|
35
|
+
const id = own?.entry?.options?.id
|
|
36
|
+
return typeof id === 'string' && id.length > 0 ? id : fallback
|
|
37
|
+
} catch {
|
|
38
|
+
return fallback
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Read one resolved Config field.
|
|
44
|
+
*
|
|
45
|
+
* Cordis' documented volatile contract (vendor loader README, LESSONS §36):
|
|
46
|
+
* a field declared `.volatile()` resolves to a `Volatile<T>` **reference**
|
|
47
|
+
* whose live value is read with `.get()`; Loader commits volatile-only edits
|
|
48
|
+
* into that same reference. Older cores (and our `.volatile()` guard on old
|
|
49
|
+
* schemastery) hand back a plain value, so both shapes are accepted.
|
|
50
|
+
*/
|
|
51
|
+
export function readConfigField(config, field, fallback) {
|
|
52
|
+
const value = config?.[field]
|
|
53
|
+
if (value !== null && typeof value === 'object' && typeof value.get === 'function') {
|
|
54
|
+
try {
|
|
55
|
+
const live = value.get()
|
|
56
|
+
return live === undefined ? fallback : live
|
|
57
|
+
} catch {
|
|
58
|
+
return fallback
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return value === undefined ? fallback : value
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The plain, serializable configuration the tools/client/API consume. */
|
|
65
|
+
export function readProxyConfig(config) {
|
|
66
|
+
return {
|
|
67
|
+
enabled: readConfigField(config, 'enabled', false) === true,
|
|
68
|
+
mode: readConfigField(config, 'mode', 'none'),
|
|
69
|
+
customUrl: readConfigField(config, 'customUrl', ''),
|
|
70
|
+
noProxy: readConfigField(config, 'noProxy', ''),
|
|
71
|
+
systemPollMs: readConfigField(config, 'systemPollMs', 0),
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Editable configuration payload for the client panel (`/config` API). The
|
|
77
|
+
* browser cannot reach the settings transport on dsh >= 0.2, so the host hands
|
|
78
|
+
* the panel exactly the fields it edits (LESSONS §33).
|
|
79
|
+
*
|
|
80
|
+
* @param resolved - the live configuration (see {@link readProxyConfig}).
|
|
81
|
+
* @param writable - whether this composition can persist a write at all; a
|
|
82
|
+
* read-only composition must not offer enabled controls (review fix).
|
|
83
|
+
*/
|
|
84
|
+
export function configPayload(resolved, writable = true) {
|
|
85
|
+
return {
|
|
86
|
+
config: {
|
|
87
|
+
enabled: resolved?.enabled === true,
|
|
88
|
+
mode: resolved?.mode ?? 'none',
|
|
89
|
+
customUrl: resolved?.customUrl ?? '',
|
|
90
|
+
noProxy: resolved?.noProxy ?? '',
|
|
91
|
+
systemPollMs: resolved?.systemPollMs ?? 0,
|
|
92
|
+
},
|
|
93
|
+
writable: writable === true,
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
18
97
|
/** Normalize a bare `host:port` or already-schemed URL into an http(s) URL. */
|
|
19
98
|
export function normalizeProxyUrl(value) {
|
|
20
99
|
if (typeof value !== 'string') return null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanglaofish/dsh-proxy-pro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "DSH proxy manager: route model requests, web fetches and spawned tools through the Windows system proxy or a custom address; per-URL route diagnosis, one-click toggle from the conversation header, a dedicated Settings page, and keepalive-aware 407 hints.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@deepseek-ai/cordis": "^4.0.0",
|
|
43
|
-
"@deepseek-ai/dsh-http-proxy": "
|
|
44
|
-
"@deepseek-ai/dsh-settings": "
|
|
45
|
-
"@deepseek-ai/dsh-system-prompt": "
|
|
46
|
-
"@deepseek-ai/dsh-tools": "
|
|
43
|
+
"@deepseek-ai/dsh-http-proxy": ">=0.2.0-rc.2 <0.3.0",
|
|
44
|
+
"@deepseek-ai/dsh-settings": ">=0.2.0-rc.2 <0.3.0",
|
|
45
|
+
"@deepseek-ai/dsh-system-prompt": ">=0.2.0-rc.2 <0.3.0",
|
|
46
|
+
"@deepseek-ai/dsh-tools": ">=0.2.0-rc.2 <0.3.0",
|
|
47
47
|
"@deepseek-ai/schemastery": "^3.18.0"
|
|
48
48
|
},
|
|
49
49
|
"dsh": {
|