dsh-plugin-model-proxy 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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -0
  3. package/cordis.patch.yml +15 -0
  4. package/lib/client/ModelProxyCard.d.ts +14 -0
  5. package/lib/client/ModelProxyCard.d.ts.map +1 -0
  6. package/lib/client/catalog.d.ts +140 -0
  7. package/lib/client/catalog.d.ts.map +1 -0
  8. package/lib/client/controller.d.ts +107 -0
  9. package/lib/client/controller.d.ts.map +1 -0
  10. package/lib/client/index.d.ts +8 -0
  11. package/lib/client/index.d.ts.map +1 -0
  12. package/lib/client/locales.d.ts +106 -0
  13. package/lib/client/locales.d.ts.map +1 -0
  14. package/lib/client.js +1129 -0
  15. package/lib/client.js.map +7 -0
  16. package/lib/host/config.d.ts +47 -0
  17. package/lib/host/config.d.ts.map +1 -0
  18. package/lib/host/config.js +153 -0
  19. package/lib/host/config.js.map +1 -0
  20. package/lib/host/credentials.d.ts +24 -0
  21. package/lib/host/credentials.d.ts.map +1 -0
  22. package/lib/host/credentials.js +45 -0
  23. package/lib/host/credentials.js.map +1 -0
  24. package/lib/host/dispatcher.d.ts +30 -0
  25. package/lib/host/dispatcher.d.ts.map +1 -0
  26. package/lib/host/dispatcher.js +167 -0
  27. package/lib/host/dispatcher.js.map +1 -0
  28. package/lib/host/fetch-wrap.d.ts +45 -0
  29. package/lib/host/fetch-wrap.d.ts.map +1 -0
  30. package/lib/host/fetch-wrap.js +100 -0
  31. package/lib/host/fetch-wrap.js.map +1 -0
  32. package/lib/host/index.d.ts +18 -0
  33. package/lib/host/index.d.ts.map +1 -0
  34. package/lib/host/index.js +262 -0
  35. package/lib/host/index.js.map +1 -0
  36. package/lib/host/probe.d.ts +30 -0
  37. package/lib/host/probe.d.ts.map +1 -0
  38. package/lib/host/probe.js +43 -0
  39. package/lib/host/probe.js.map +1 -0
  40. package/lib/invariant.d.ts +5 -0
  41. package/lib/invariant.d.ts.map +1 -0
  42. package/lib/invariant.js +7 -0
  43. package/lib/invariant.js.map +1 -0
  44. package/package.json +95 -0
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Connectivity probe for configured proxies: exercises the real dispatcher
3
+ * (CONNECT tunnel / socks handshake) against a lightweight endpoint without
4
+ * consuming any model quota.
5
+ *
6
+ * Default endpoint is Cloudflare's `cdn-cgi/trace`, whose body contains an
7
+ * `ip=` line — proof the tunnel terminated at a working egress. Tests inject
8
+ * `endpoint` + `fetchImpl` to stay fully offline.
9
+ */
10
+ export interface ProbeResult {
11
+ ok: boolean;
12
+ latencyMs: number;
13
+ detail: string;
14
+ }
15
+ export interface ProbeOptions {
16
+ /** Trace-style endpoint; body must contain "ip=" on success. */
17
+ endpoint?: string;
18
+ timeoutMs?: number;
19
+ /** Test seam: override undici's fetch. */
20
+ fetchImpl?: (url: string, init?: Record<string, unknown>) => Promise<{
21
+ ok: boolean;
22
+ status: number;
23
+ text(): Promise<string>;
24
+ }>;
25
+ }
26
+ export declare const DEFAULT_PROBE_ENDPOINT = "https://1.1.1.1/cdn-cgi/trace";
27
+ export declare function probeProxy(proxyUrl: string, opts?: ProbeOptions): Promise<ProbeResult>;
28
+ /** Log-friendly label; never leaks credentials. */
29
+ export declare function describeProbeTarget(proxyUrl: string): string;
30
+ //# sourceMappingURL=probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.d.ts","sourceRoot":"","sources":["../../src/host/probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC,CAAA;CAC/H;AAED,eAAO,MAAM,sBAAsB,kCAAkC,CAAA;AAErE,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAqBhG;AAED,mDAAmD;AACnD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Connectivity probe for configured proxies: exercises the real dispatcher
3
+ * (CONNECT tunnel / socks handshake) against a lightweight endpoint without
4
+ * consuming any model quota.
5
+ *
6
+ * Default endpoint is Cloudflare's `cdn-cgi/trace`, whose body contains an
7
+ * `ip=` line — proof the tunnel terminated at a working egress. Tests inject
8
+ * `endpoint` + `fetchImpl` to stay fully offline.
9
+ */
10
+ import { fetch as undiciFetch } from 'undici';
11
+ import { getOrCreateDispatcher } from './dispatcher.js';
12
+ import { redactProxyUrl } from './config.js';
13
+ export const DEFAULT_PROBE_ENDPOINT = 'https://1.1.1.1/cdn-cgi/trace';
14
+ export async function probeProxy(proxyUrl, opts = {}) {
15
+ const endpoint = opts.endpoint ?? DEFAULT_PROBE_ENDPOINT;
16
+ const started = Date.now();
17
+ try {
18
+ // May throw synchronously for unsupported schemes — reported as failure.
19
+ const dispatcher = getOrCreateDispatcher(proxyUrl);
20
+ const fetchImpl = opts.fetchImpl ?? undiciFetch;
21
+ const res = await fetchImpl(endpoint, {
22
+ dispatcher,
23
+ signal: AbortSignal.timeout(opts.timeoutMs ?? 5000),
24
+ });
25
+ const latencyMs = Date.now() - started;
26
+ if (!res.ok)
27
+ return { ok: false, latencyMs, detail: `HTTP ${res.status}` };
28
+ const text = await res.text();
29
+ if (!text.includes('ip='))
30
+ return { ok: false, latencyMs, detail: 'unexpected probe response body' };
31
+ return { ok: true, latencyMs, detail: `HTTP ${res.status}` };
32
+ }
33
+ catch (err) {
34
+ const cause = err?.cause?.message;
35
+ const detail = cause ?? err?.message ?? String(err);
36
+ return { ok: false, latencyMs: Date.now() - started, detail };
37
+ }
38
+ }
39
+ /** Log-friendly label; never leaks credentials. */
40
+ export function describeProbeTarget(proxyUrl) {
41
+ return redactProxyUrl(proxyUrl);
42
+ }
43
+ //# sourceMappingURL=probe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.js","sourceRoot":"","sources":["../../src/host/probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAgB5C,MAAM,CAAC,MAAM,sBAAsB,GAAG,+BAA+B,CAAA;AAErE,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB,EAAE,OAAqB,EAAE;IACxE,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,sBAAsB,CAAA;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAC1B,IAAI,CAAC;QACH,yEAAyE;QACzE,MAAM,UAAU,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAA;QAClD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAK,WAAiE,CAAA;QACtG,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE;YACpC,UAAU;YACV,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC;SACpD,CAAC,CAAA;QACF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAA;QACtC,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE,CAAA;QAC1E,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;QAC7B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,gCAAgC,EAAE,CAAA;QACpG,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE,CAAA;IAC9D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,KAAK,GAAI,GAAwC,EAAE,KAAK,EAAE,OAAO,CAAA;QACvE,MAAM,MAAM,GAAG,KAAK,IAAK,GAAa,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAA;QAC9D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAA;IAC/D,CAAC;AACH,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAA;AACjC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ export declare const name = "dsh-plugin-model-proxy-invariant";
3
+ export declare const inject: string[];
4
+ export declare const apply: (ctx: Context) => Promise<() => void>;
5
+ //# sourceMappingURL=invariant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,eAAO,MAAM,IAAI,qCAAqC,CAAA;AACtD,eAAO,MAAM,MAAM,UAAiB,CAAA;AAIpC,eAAO,MAAM,KAAK,GAAI,KAAK,OAAO,KAAG,OAAO,CAAC,MAAM,IAAI,CACU,CAAA"}
@@ -0,0 +1,7 @@
1
+ const PACKAGE_NAME = 'dsh-plugin-model-proxy';
2
+ export const name = 'dsh-plugin-model-proxy-invariant';
3
+ export const inject = ['invariants'];
4
+ const install = () => { };
5
+ export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
6
+ /* jscpd:ignore-end */
7
+ //# sourceMappingURL=invariant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.js","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAIA,MAAM,YAAY,GAAG,wBAAwB,CAAA;AAE7C,MAAM,CAAC,MAAM,IAAI,GAAG,kCAAkC,CAAA;AACtD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAAY,CAAC,CAAA;AAEpC,MAAM,OAAO,GAAuB,GAAG,EAAE,GAAE,CAAC,CAAA;AAE5C,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAY,EAAuB,EAAE,CACzD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;AACjE,sBAAsB"}
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "dsh-plugin-model-proxy",
3
+ "version": "0.1.0",
4
+ "description": "DSH community plugin: per-provider per-model proxy (http/https/socks5) with UI configuration",
5
+ "type": "module",
6
+ "keywords": [
7
+ "dsh-plugin"
8
+ ],
9
+ "license": "MIT",
10
+ "publishConfig": {
11
+ "registry": "https://registry.npmjs.org/"
12
+ },
13
+ "main": "lib/host/index.js",
14
+ "types": "lib/host/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./lib/host/index.d.ts",
18
+ "default": "./lib/host/index.js"
19
+ },
20
+ "./client": {
21
+ "types": "./lib/client/index.d.ts",
22
+ "default": "./lib/client.js"
23
+ },
24
+ "./invariant": {
25
+ "types": "./lib/invariant.d.ts",
26
+ "default": "./lib/invariant.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "lib/",
32
+ "cordis.patch.yml",
33
+ "README.md"
34
+ ],
35
+ "dsh": {
36
+ "bundle": {
37
+ "patch": "./cordis.patch.yml"
38
+ },
39
+ "client": {
40
+ "platform": "web",
41
+ "inject": [
42
+ "@deepseek-ai/dsh-client-ui-settings-plugins"
43
+ ]
44
+ }
45
+ },
46
+ "scripts": {
47
+ "build": "npm run build:host && npm run build:client",
48
+ "build:host": "tsc -p tsconfig.host.json",
49
+ "build:client": "tsc -p tsconfig.client.json && node scripts/build-client.mjs",
50
+ "prepare": "npm run build",
51
+ "test": "npm run build && node --test \"tests/*.test.mjs\"",
52
+ "typecheck": "tsc --noEmit -p tsconfig.host.json && tsc --noEmit -p tsconfig.client.json",
53
+ "clean": "rm -rf lib",
54
+ "prepublishOnly": "npm run test"
55
+ },
56
+ "engines": {
57
+ "node": ">=20"
58
+ },
59
+ "dependencies": {
60
+ "undici": "^6.19.0"
61
+ },
62
+ "optionalDependencies": {
63
+ "socks": "^2.8.3"
64
+ },
65
+ "peerDependencies": {
66
+ "@deepseek-ai/cordis": ">=4.0.0",
67
+ "@deepseek-ai/dsh-llm": ">=0.1.0-rc.6",
68
+ "@deepseek-ai/dsh-settings": ">=0.1.0-rc.6",
69
+ "@deepseek-ai/schemastery": ">=3.0.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@deepseek-ai/cordis": {
73
+ "optional": false
74
+ },
75
+ "@deepseek-ai/dsh-llm": {
76
+ "optional": false
77
+ },
78
+ "@deepseek-ai/dsh-settings": {
79
+ "optional": false
80
+ },
81
+ "@deepseek-ai/schemastery": {
82
+ "optional": true
83
+ }
84
+ },
85
+ "devDependencies": {
86
+ "@deepseek-ai/cordis": "^4.0.1",
87
+ "@deepseek-ai/dsh-llm": "0.1.0-rc.8",
88
+ "@deepseek-ai/dsh-settings": "0.1.0-rc.8",
89
+ "@types/node": "^22.20.1",
90
+ "@types/react": "^19.2.18",
91
+ "esbuild": "^0.28.2",
92
+ "react": "^19.2.8",
93
+ "typescript": "^6.0.3"
94
+ }
95
+ }