@mangoc/dsh-sub2api-sync 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +149 -2
- package/README.zh.md +120 -0
- package/cordis.patch.yml +10 -0
- package/data/models-dev.snapshot.json +1 -0
- package/lib/client.cjs +2416 -0
- package/lib/client.d.ts +49 -0
- package/lib/client.js +2425 -0
- package/lib/config.d.ts +111 -0
- package/lib/engine.d.ts +128 -0
- package/lib/enrich.d.ts +104 -0
- package/lib/icon.d.ts +50 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +2872 -0
- package/lib/oauth.d.ts +128 -0
- package/lib/panel.d.ts +203 -0
- package/lib/protocols.d.ts +125 -0
- package/lib/routes.d.ts +256 -0
- package/lib/types.d.ts +151 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +124 -3
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gateway-side HTTP client for sub2api: model discovery under a relay key.
|
|
3
|
+
* No DSH dependencies, so it unit-tests against an injected fetch. Phase 2
|
|
4
|
+
* adds the panel half (login / keys / groups) beside this module.
|
|
5
|
+
*
|
|
6
|
+
* @module sub2api-sync/client
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The `/v1` API root for OpenAI-style gateway endpoints (`/models`,
|
|
10
|
+
* `/chat/completions`, `/responses`, …). A URL already ending in `/v1`
|
|
11
|
+
* passes through; anything else gets `/v1` appended.
|
|
12
|
+
*/
|
|
13
|
+
export declare function gatewayApiRoot(baseURL: string): string;
|
|
14
|
+
export interface Sub2apiClientOptions {
|
|
15
|
+
/** sub2api instance address, with or without a trailing `/v1`. */
|
|
16
|
+
baseURL: string;
|
|
17
|
+
/** Fetch implementation override (tests); defaults to globalThis.fetch. */
|
|
18
|
+
fetchImpl?: typeof fetch;
|
|
19
|
+
}
|
|
20
|
+
/** One model entry as the gateway answers it — the shape varies per platform. */
|
|
21
|
+
export interface GatewayModelEntry {
|
|
22
|
+
id: string;
|
|
23
|
+
displayName?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare class Sub2apiClient {
|
|
26
|
+
private readonly root;
|
|
27
|
+
private readonly fetchImpl;
|
|
28
|
+
constructor(options: Sub2apiClientOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Discover the model ids one relay key can serve (`GET /v1/models`). The
|
|
31
|
+
* gateway answers an OpenAI-style list whose element shape varies per
|
|
32
|
+
* platform — grok embeds reasoning fields, a `client_version` query
|
|
33
|
+
* switches to the Codex manifest — so the reader takes `id` and tolerates
|
|
34
|
+
* everything else (verified: `handler/gateway_handler.go`).
|
|
35
|
+
*/
|
|
36
|
+
listModels(relayKey: string, options?: {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}): Promise<GatewayModelEntry[]>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extract the gateway's own refusal reason from an error body so the sync
|
|
42
|
+
* report can say WHY a key was rejected (balance / expiry / subscription /
|
|
43
|
+
* IP allow-list), not just the HTTP status. sub2api writes two shapes:
|
|
44
|
+
* flat `{code, message}` (middleware ErrorResponse) and OpenAI-style
|
|
45
|
+
* `{error: {message, code}}`; anything else degrades to "".
|
|
46
|
+
*/
|
|
47
|
+
export declare function refusalDetail(response: Response): Promise<string>;
|
|
48
|
+
/** Tolerant reader for the `/models` payload; unknown shapes fail loudly. */
|
|
49
|
+
export declare function readModelList(payload: unknown): GatewayModelEntry[];
|