@eddyskywalker/dsh-chatgpt-subscription 0.31.0 → 0.32.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/CHANGELOG.md +34 -0
- package/README.md +64 -1
- package/lib/client.js +29654 -1099
- package/lib/client.js.map +1 -1
- package/lib/index.js +7163 -1484
- package/lib/types/client/cline-pass/ClinePassComposerQuota.d.ts +20 -0
- package/lib/types/client/cline-pass/ClinePassComposerQuota.d.ts.map +1 -0
- package/lib/types/client/cline-pass/ClinePassSection.d.ts +17 -0
- package/lib/types/client/cline-pass/ClinePassSection.d.ts.map +1 -0
- package/lib/types/client/cline-pass/api.d.ts +84 -0
- package/lib/types/client/cline-pass/api.d.ts.map +1 -0
- package/lib/types/client/cline-pass/locales.d.ts +1025 -0
- package/lib/types/client/cline-pass/locales.d.ts.map +1 -0
- package/lib/types/client/cline-pass/styles.d.ts +7 -0
- package/lib/types/client/cline-pass/styles.d.ts.map +1 -0
- package/lib/types/client/hub/brand-icons.d.ts +2 -2
- package/lib/types/client/hub/brand-icons.d.ts.map +1 -1
- package/lib/types/client/hub/providers.d.ts.map +1 -1
- package/lib/types/client/index.d.ts +2 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/mermaid/renderer.d.ts +23 -0
- package/lib/types/client/mermaid/renderer.d.ts.map +1 -1
- package/lib/types/client/minimax-code/MinimaxVideoDocumentBody.d.ts +31 -14
- package/lib/types/client/minimax-code/MinimaxVideoDocumentBody.d.ts.map +1 -1
- package/lib/types/client/minimax-code/MinimaxVideoToolView.d.ts.map +1 -1
- package/lib/types/client/minimax-code/video-contract.d.ts +36 -0
- package/lib/types/client/minimax-code/video-contract.d.ts.map +1 -1
- package/lib/types/client/minimax-code/video-slots.d.ts +58 -5
- package/lib/types/client/minimax-code/video-slots.d.ts.map +1 -1
- package/lib/types/client/progress-updates/markdown-lite.d.ts +19 -6
- package/lib/types/client/progress-updates/markdown-lite.d.ts.map +1 -1
- package/lib/types/host/antigravity/adapter.d.ts.map +1 -1
- package/lib/types/host/cline-pass/account-pool.d.ts +63 -0
- package/lib/types/host/cline-pass/account-pool.d.ts.map +1 -0
- package/lib/types/host/cline-pass/adapter.d.ts +49 -0
- package/lib/types/host/cline-pass/adapter.d.ts.map +1 -0
- package/lib/types/host/cline-pass/catalog.d.ts +49 -0
- package/lib/types/host/cline-pass/catalog.d.ts.map +1 -0
- package/lib/types/host/cline-pass/client.d.ts +118 -0
- package/lib/types/host/cline-pass/client.d.ts.map +1 -0
- package/lib/types/host/cline-pass/engine.d.ts +223 -0
- package/lib/types/host/cline-pass/engine.d.ts.map +1 -0
- package/lib/types/host/cline-pass/line.d.ts +55 -0
- package/lib/types/host/cline-pass/line.d.ts.map +1 -0
- package/lib/types/host/cline-pass/mapper.d.ts +112 -0
- package/lib/types/host/cline-pass/mapper.d.ts.map +1 -0
- package/lib/types/host/cline-pass/oauth.d.ts +134 -0
- package/lib/types/host/cline-pass/oauth.d.ts.map +1 -0
- package/lib/types/host/cline-pass/protocol.d.ts +186 -0
- package/lib/types/host/cline-pass/protocol.d.ts.map +1 -0
- package/lib/types/host/cline-pass/routes.d.ts +71 -0
- package/lib/types/host/cline-pass/routes.d.ts.map +1 -0
- package/lib/types/host/cline-pass/store.d.ts +97 -0
- package/lib/types/host/cline-pass/store.d.ts.map +1 -0
- package/lib/types/host/cline-pass/token-store.d.ts +168 -0
- package/lib/types/host/cline-pass/token-store.d.ts.map +1 -0
- package/lib/types/host/cline-pass/tools.d.ts +21 -0
- package/lib/types/host/cline-pass/tools.d.ts.map +1 -0
- package/lib/types/host/cline-pass/types.d.ts +168 -0
- package/lib/types/host/cline-pass/types.d.ts.map +1 -0
- package/lib/types/host/common/model-request-control.d.ts +1 -1
- package/lib/types/host/common/model-request-control.d.ts.map +1 -1
- package/lib/types/host/common/request-diagnostics.d.ts +1 -1
- package/lib/types/host/common/request-diagnostics.d.ts.map +1 -1
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/cline-pass-contracts.d.ts +267 -0
- package/lib/types/shared/cline-pass-contracts.d.ts.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport for the Cline gateway and its public catalogs. Transport only: no
|
|
3
|
+
* pinning, retry, or failover policy lives here (see `adapter.ts`).
|
|
4
|
+
*
|
|
5
|
+
* - `POST {baseURL}/chat/completions` — the gateway
|
|
6
|
+
* - `GET {baseURL}/models` — the gateway's own catalog
|
|
7
|
+
* - `GET {baseURL}/users/me/plan/usage-limits` — the account's quota windows
|
|
8
|
+
* - `GET api.cline.bot/…/recommended-models` — official subscription list
|
|
9
|
+
* - `GET models.dev/api.json` — community registry, a metadata backstop
|
|
10
|
+
* - `GET ai-gateway.vercel.sh/v1/models` — the upstream's own catalog
|
|
11
|
+
* - `GET openrouter.ai/api/v1/…` — endpoint detail for direct-pipeline models
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-chatgpt-subscription/cline-pass-client
|
|
14
|
+
*/
|
|
15
|
+
import { type ClinePassCatalogScan } from './types.ts';
|
|
16
|
+
export interface ClinePassHttpResult {
|
|
17
|
+
status: number;
|
|
18
|
+
ok: boolean;
|
|
19
|
+
json: unknown;
|
|
20
|
+
text: string;
|
|
21
|
+
}
|
|
22
|
+
/** Combine a caller signal with a timeout signal. */
|
|
23
|
+
export declare function withTimeout(signal: AbortSignal | undefined, timeoutMs: number | undefined): AbortSignal | undefined;
|
|
24
|
+
/** Strip a trailing slash so paths can be appended literally. */
|
|
25
|
+
export declare function trimBase(baseURL: string): string;
|
|
26
|
+
/** The gateway's own chat-completions endpoint for one base URL. */
|
|
27
|
+
export declare function chatURL(baseURL: string): string;
|
|
28
|
+
/** Send one JSON request and decode whatever comes back; never throws for HTTP errors. */
|
|
29
|
+
export declare function sendJSON(fetchFn: typeof fetch, url: string, { method, apiKey, body, signal, timeoutMs, headers, }?: {
|
|
30
|
+
method?: string;
|
|
31
|
+
apiKey?: string;
|
|
32
|
+
body?: unknown;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
headers?: Record<string, string>;
|
|
36
|
+
}): Promise<ClinePassHttpResult>;
|
|
37
|
+
/** Send one chat completion, non-streaming. */
|
|
38
|
+
export declare function chatCompletion({ fetchFn, baseURL, apiKey, body, signal, timeoutMs, }: {
|
|
39
|
+
fetchFn: typeof fetch;
|
|
40
|
+
baseURL: string;
|
|
41
|
+
apiKey: string;
|
|
42
|
+
body: unknown;
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}): Promise<ClinePassHttpResult>;
|
|
46
|
+
/** Open a streaming chat completion and hand back the live response. */
|
|
47
|
+
export declare function openChatStream({ fetchFn, baseURL, apiKey, body, signal, headers, }: {
|
|
48
|
+
fetchFn: typeof fetch;
|
|
49
|
+
baseURL: string;
|
|
50
|
+
apiKey: string;
|
|
51
|
+
body: unknown;
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
headers?: Record<string, string>;
|
|
54
|
+
}): Promise<Response>;
|
|
55
|
+
/** List the gateway's own catalog ids; an empty array when the call fails. */
|
|
56
|
+
export declare function fetchGatewayCatalog({ fetchFn, baseURL, apiKey, signal, timeoutMs, }: {
|
|
57
|
+
fetchFn: typeof fetch;
|
|
58
|
+
baseURL: string;
|
|
59
|
+
apiKey: string;
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
timeoutMs?: number;
|
|
62
|
+
}): Promise<string[]>;
|
|
63
|
+
/** One quota window as the gateway reports it. */
|
|
64
|
+
export interface ClinePassRawUsageLimit {
|
|
65
|
+
type: string;
|
|
66
|
+
percentUsed: number;
|
|
67
|
+
resetsAt: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Read the account's official quota consumption.
|
|
71
|
+
*
|
|
72
|
+
* The gateway answers with `{ success, data: { limits: [{ type, percentUsed,
|
|
73
|
+
* resetsAt }] } }`, where `type` is `five_hour`, `weekly` or `monthly`. A refusal
|
|
74
|
+
* is reported as data, never thrown: the card shows quota beside controls that
|
|
75
|
+
* keep working without it.
|
|
76
|
+
*/
|
|
77
|
+
export declare function fetchUsageLimits({ fetchFn, baseURL, apiKey, signal, timeoutMs, }: {
|
|
78
|
+
fetchFn: typeof fetch;
|
|
79
|
+
baseURL: string;
|
|
80
|
+
apiKey: string;
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
timeoutMs?: number;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
ok: boolean;
|
|
85
|
+
limits: ClinePassRawUsageLimit[];
|
|
86
|
+
error: string;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Collect `cline-pass/*` ids and metadata from the official endpoints and the
|
|
90
|
+
* community registry. Additive by design: a source that fails is skipped.
|
|
91
|
+
*/
|
|
92
|
+
export declare function fetchOfficialModels({ fetchFn, signal, timeoutMs, }: {
|
|
93
|
+
fetchFn: typeof fetch;
|
|
94
|
+
signal?: AbortSignal;
|
|
95
|
+
timeoutMs?: number;
|
|
96
|
+
}): Promise<ClinePassCatalogScan>;
|
|
97
|
+
/** Resolve a canonical slug against OpenRouter's public catalog. */
|
|
98
|
+
export declare function resolveOpenRouterSlug(fetchFn: typeof fetch, slug: string, { signal, timeoutMs }?: {
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
timeoutMs?: number;
|
|
101
|
+
}): Promise<string | null>;
|
|
102
|
+
/** One upstream endpoint detail, as OpenRouter reports it. */
|
|
103
|
+
export interface ClinePassEndpointDetail {
|
|
104
|
+
slug: string;
|
|
105
|
+
name: string;
|
|
106
|
+
endpoints: number;
|
|
107
|
+
context: number;
|
|
108
|
+
uptime: number;
|
|
109
|
+
}
|
|
110
|
+
/** Per-upstream endpoint detail (context length, recent uptime) for one model. */
|
|
111
|
+
export declare function openRouterEndpoints(fetchFn: typeof fetch, slug: string, { signal, timeoutMs }?: {
|
|
112
|
+
signal?: AbortSignal;
|
|
113
|
+
timeoutMs?: number;
|
|
114
|
+
}): Promise<{
|
|
115
|
+
slug: string;
|
|
116
|
+
endpoints: ClinePassEndpointDetail[];
|
|
117
|
+
}>;
|
|
118
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/host/cline-pass/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAOL,KAAK,oBAAoB,EAE1B,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,OAAO,CAAA;IACX,IAAI,EAAE,OAAO,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACb;AAED,qDAAqD;AACrD,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAMnH;AAED,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,oEAAoE;AACpE,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,0FAA0F;AAC1F,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,OAAO,KAAK,EACrB,GAAG,EAAE,MAAM,EACX,EACE,MAAc,EACd,MAAW,EACX,IAAI,EACJ,MAAM,EACN,SAAkB,EAClB,OAAY,GACb,GAAE;IACD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC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AM,EACZ,EAAE,MAAM,EAAE,SAAkB,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAChF,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,uBAAuB,EAAE,CAAA;CAAE,CAAC,CA4BjE"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cline Pass engine: pinned request chains with pre-first-token failover,
|
|
3
|
+
* probing, validation, and account verification. It owns every probe network
|
|
4
|
+
* call, so the adapter, the settings routes and the management tools apply
|
|
5
|
+
* identical pinning semantics.
|
|
6
|
+
*
|
|
7
|
+
* Failover contract: a candidate is abandoned only while nothing has been
|
|
8
|
+
* delivered yet. A non-2xx, a transport failure, or an error payload before the
|
|
9
|
+
* first content delta moves to the next candidate; once a chunk has been
|
|
10
|
+
* produced the stream is the answer, and a later failure is reported as such.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-chatgpt-subscription/cline-pass-engine
|
|
13
|
+
*/
|
|
14
|
+
import { LlmError } from '@deepseek-ai/dsh-llm';
|
|
15
|
+
import { parseRouting, pinAdherence, type PinAttempt, type PinConfig } from './protocol.ts';
|
|
16
|
+
import { type ClinePassCatalogScan, type ClinePassPinSettings } from './types.ts';
|
|
17
|
+
import type { ClinePassStore } from './store.ts';
|
|
18
|
+
import type { ClinePassAccountPool } from './account-pool.ts';
|
|
19
|
+
/** One resolved account, as the engine hands it to a request or a probe. */
|
|
20
|
+
export interface ClinePassAccount {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
key: string;
|
|
24
|
+
baseURL: string;
|
|
25
|
+
}
|
|
26
|
+
/** One pinned request's outcome. */
|
|
27
|
+
export interface ClinePassAttemptOutcome {
|
|
28
|
+
attempt: PinAttempt;
|
|
29
|
+
account: ClinePassAccount;
|
|
30
|
+
status: number;
|
|
31
|
+
ok: boolean;
|
|
32
|
+
json: Record<string, unknown>;
|
|
33
|
+
text: string;
|
|
34
|
+
ms: number;
|
|
35
|
+
routing: ReturnType<typeof parseRouting>;
|
|
36
|
+
adherence: ReturnType<typeof pinAdherence> | null;
|
|
37
|
+
warnings: string[];
|
|
38
|
+
error: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ClinePassEngineOptions {
|
|
41
|
+
fetchFn: typeof fetch;
|
|
42
|
+
/** Controlled/diagnostic fetch used only for live chat streams; defaults to fetchFn. */
|
|
43
|
+
streamFetchFn?: typeof fetch;
|
|
44
|
+
accountPool: ClinePassAccountPool;
|
|
45
|
+
store: ClinePassStore;
|
|
46
|
+
/** The stored pin plus the route-wide spelling policy. */
|
|
47
|
+
pinFor(model: string): PinConfig;
|
|
48
|
+
/** The route's default gateway, used when an account names none. */
|
|
49
|
+
baseURL(): string;
|
|
50
|
+
logger?: {
|
|
51
|
+
warn(message: string, ...args: unknown[]): void;
|
|
52
|
+
};
|
|
53
|
+
attemptTimeoutMs?: number;
|
|
54
|
+
probeTimeoutMs?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The engine. All methods are safe to call while the pool is serving live
|
|
58
|
+
* traffic; probes take an account through the same rotation as a request.
|
|
59
|
+
*/
|
|
60
|
+
export declare class ClinePassEngine {
|
|
61
|
+
private readonly options;
|
|
62
|
+
constructor(options: ClinePassEngineOptions);
|
|
63
|
+
private get fetchFn();
|
|
64
|
+
private get store();
|
|
65
|
+
/** The account a request would use right now, without consuming a rotation slot. */
|
|
66
|
+
resolveAccount(exclude?: ReadonlySet<string>): Promise<ClinePassAccount>;
|
|
67
|
+
/** The pin plus the route-wide spelling policy, as a request will send it. */
|
|
68
|
+
pinConfigFor(model: string): PinConfig;
|
|
69
|
+
/** The configured pin for one model, read through the live settings file. */
|
|
70
|
+
pinOf(model: string): ClinePassPinSettings;
|
|
71
|
+
/**
|
|
72
|
+
* One pinned request, non-streaming.
|
|
73
|
+
* @returns the decoded payload plus the facts the pin was judged on.
|
|
74
|
+
*/
|
|
75
|
+
attemptChat(model: string, body: Record<string, unknown>, attempt: PinAttempt, { signal, timeoutMs }?: {
|
|
76
|
+
signal?: AbortSignal;
|
|
77
|
+
timeoutMs?: number;
|
|
78
|
+
}): Promise<ClinePassAttemptOutcome>;
|
|
79
|
+
/**
|
|
80
|
+
* Run one model's ordered candidate chain until an attempt is both answered
|
|
81
|
+
* and served by the channel the pin asked for.
|
|
82
|
+
*
|
|
83
|
+
* This is the diagnostic path (`cline_pass_test`), so it keeps looking past a
|
|
84
|
+
* candidate the router quietly ignored: the point of the call is to find out
|
|
85
|
+
* whether the pin works.
|
|
86
|
+
*/
|
|
87
|
+
runChain(model: string, body: Record<string, unknown>, pinConfig: PinConfig, { signal, timeoutMs }?: {
|
|
88
|
+
signal?: AbortSignal;
|
|
89
|
+
timeoutMs?: number;
|
|
90
|
+
}): Promise<{
|
|
91
|
+
ok: boolean;
|
|
92
|
+
result: ClinePassAttemptOutcome | null;
|
|
93
|
+
trace: Array<{
|
|
94
|
+
upstream: string;
|
|
95
|
+
status: number;
|
|
96
|
+
ms: number;
|
|
97
|
+
note: string;
|
|
98
|
+
}>;
|
|
99
|
+
error: string;
|
|
100
|
+
warnings: string[];
|
|
101
|
+
}>;
|
|
102
|
+
/** Merge a gateway error's own provider list into the model's channel list. */
|
|
103
|
+
learnFromError(model: string, message: string): void;
|
|
104
|
+
/**
|
|
105
|
+
* Probe one model: detect its pipeline, read back the upstream it used, and
|
|
106
|
+
* harvest the channel list each pipeline publishes. Costs two tiny requests.
|
|
107
|
+
*/
|
|
108
|
+
probe(model: string, { signal, timeoutMs }?: {
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
timeoutMs?: number;
|
|
111
|
+
}): Promise<{
|
|
112
|
+
ok: boolean;
|
|
113
|
+
ms: number;
|
|
114
|
+
model: string;
|
|
115
|
+
error: string;
|
|
116
|
+
pipeline: string;
|
|
117
|
+
pinnable: boolean;
|
|
118
|
+
canonicalSlug: string;
|
|
119
|
+
lastProvider: string;
|
|
120
|
+
upstreams: string[];
|
|
121
|
+
availableProviders: string[];
|
|
122
|
+
tier0: string[];
|
|
123
|
+
}>;
|
|
124
|
+
/**
|
|
125
|
+
* Harvest the exact channel list for one pipeline by pinning a channel that
|
|
126
|
+
* cannot exist: the router fails before spending a token and names every
|
|
127
|
+
* provider it could have used.
|
|
128
|
+
*/
|
|
129
|
+
private harvest;
|
|
130
|
+
/**
|
|
131
|
+
* Test every known channel of a model once and record the verdicts.
|
|
132
|
+
*
|
|
133
|
+
* A channel counts as usable only when the response names it as the one that
|
|
134
|
+
* served the request; a payload carrying `choices` alone is not evidence the
|
|
135
|
+
* pin was honored.
|
|
136
|
+
*/
|
|
137
|
+
validate(model: string, { signal, timeoutMs }?: {
|
|
138
|
+
signal?: AbortSignal;
|
|
139
|
+
timeoutMs?: number;
|
|
140
|
+
}): Promise<{
|
|
141
|
+
results: Array<{
|
|
142
|
+
upstream: string;
|
|
143
|
+
status: string;
|
|
144
|
+
ms: number;
|
|
145
|
+
note: string;
|
|
146
|
+
}>;
|
|
147
|
+
summary: {
|
|
148
|
+
ok: number;
|
|
149
|
+
limited: number;
|
|
150
|
+
bad: number;
|
|
151
|
+
auth: number;
|
|
152
|
+
unknown: number;
|
|
153
|
+
};
|
|
154
|
+
cancelled: boolean;
|
|
155
|
+
}>;
|
|
156
|
+
/**
|
|
157
|
+
* Send one small chat through a (possibly temporary) pin configuration and
|
|
158
|
+
* report what served it. Nothing is persisted.
|
|
159
|
+
*/
|
|
160
|
+
test(model: string, { upstreams, exclude, signal }?: {
|
|
161
|
+
upstreams?: string[];
|
|
162
|
+
exclude?: string[];
|
|
163
|
+
signal?: AbortSignal;
|
|
164
|
+
}): Promise<{
|
|
165
|
+
ok: boolean;
|
|
166
|
+
ms: number;
|
|
167
|
+
model: string;
|
|
168
|
+
error: string;
|
|
169
|
+
targets: string[];
|
|
170
|
+
excluded: string[];
|
|
171
|
+
trace: Array<{
|
|
172
|
+
upstream: string;
|
|
173
|
+
status: number;
|
|
174
|
+
ms: number;
|
|
175
|
+
note: string;
|
|
176
|
+
}>;
|
|
177
|
+
actual: string;
|
|
178
|
+
actualName: string;
|
|
179
|
+
pipeline: string;
|
|
180
|
+
pinnable: boolean;
|
|
181
|
+
canonicalSlug: string;
|
|
182
|
+
account: string;
|
|
183
|
+
content: string;
|
|
184
|
+
adopted: boolean;
|
|
185
|
+
adherence: string;
|
|
186
|
+
plan: string;
|
|
187
|
+
warnings: string[];
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* Check one account key against the gateway with a single small request.
|
|
191
|
+
*
|
|
192
|
+
* A key that authenticates but whose model still errors (a reasoning model
|
|
193
|
+
* burning `max_tokens` into an empty completion, for example) counts as
|
|
194
|
+
* authorized: only a real authentication failure is reported as one.
|
|
195
|
+
*/
|
|
196
|
+
testAccount({ key, baseURL, model, signal, timeoutMs, }: {
|
|
197
|
+
key: string;
|
|
198
|
+
baseURL?: string;
|
|
199
|
+
model: string;
|
|
200
|
+
signal?: AbortSignal;
|
|
201
|
+
timeoutMs?: number;
|
|
202
|
+
}): Promise<{
|
|
203
|
+
ok: boolean;
|
|
204
|
+
authorized: boolean;
|
|
205
|
+
ms: number;
|
|
206
|
+
model: string;
|
|
207
|
+
error: string;
|
|
208
|
+
}>;
|
|
209
|
+
/** Refresh the gateway's own catalog ids. */
|
|
210
|
+
gatewayCatalog({ signal, timeoutMs }?: {
|
|
211
|
+
signal?: AbortSignal;
|
|
212
|
+
timeoutMs?: number;
|
|
213
|
+
}): Promise<string[]>;
|
|
214
|
+
/** Refresh the official subscription model list. */
|
|
215
|
+
officialModels({ signal }?: {
|
|
216
|
+
signal?: AbortSignal;
|
|
217
|
+
}): Promise<ClinePassCatalogScan>;
|
|
218
|
+
/** Open one chat stream for the adapter; transport only. */
|
|
219
|
+
openStream(account: ClinePassAccount, body: Record<string, unknown>, signal?: AbortSignal): Promise<Response>;
|
|
220
|
+
/** Raise the engine's own error for a request that never reached a candidate. */
|
|
221
|
+
noAccountError(error: unknown): LlmError;
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../../src/host/cline-pass/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAQ/C,OAAO,EAUL,YAAY,EAEZ,YAAY,EAGZ,KAAK,UAAU,EACf,KAAK,SAAS,EAEf,MAAM,eAAe,CAAA;AACtB,OAAO,EAA0C,KAAK,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACzH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAG7D,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,oCAAoC;AACpC,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,UAAU,CAAA;IACnB,OAAO,EAAE,gBAAgB,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,OAAO,CAAA;IACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAA;IACxC,SAAS,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,IAAI,CAAA;IACjD,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,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,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ;CAKzC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cline Pass line, assembled in one place.
|
|
3
|
+
*
|
|
4
|
+
* `src/index.ts` calls {@link createClinePassLine} beside the other lines and
|
|
5
|
+
* appends the returned claim, route disposer, hub source and exports. Everything
|
|
6
|
+
* this line owns — stores, pool, engine, adapter, routes, optional tools — is
|
|
7
|
+
* constructed here, so the integration touches no sibling line's behaviour.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-chatgpt-subscription/cline-pass-line
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
import type { AttachmentStore } from '@deepseek-ai/dsh-attachment';
|
|
13
|
+
import { type ProviderRouteClaim } from '../common/provider-route.ts';
|
|
14
|
+
import { ClinePassAccountPool } from './account-pool.ts';
|
|
15
|
+
import { ClinePassAdapter } from './adapter.ts';
|
|
16
|
+
import { ClinePassEngine } from './engine.ts';
|
|
17
|
+
import { CLINE_PASS_ROUTES } from './routes.ts';
|
|
18
|
+
import { type ClinePassStore } from './store.ts';
|
|
19
|
+
import { ClinePassModelSettingsStore, type ClinePassModelSettings } from './token-store.ts';
|
|
20
|
+
import type { HubSummarySource } from '../hub-overview.ts';
|
|
21
|
+
export interface ClinePassLineOptions {
|
|
22
|
+
/** Proxy-aware fetch that routes, OAuth, quota reads and catalog sync use. */
|
|
23
|
+
fetchFn: typeof fetch;
|
|
24
|
+
/** Controlled/diagnostic fetch that live adapter chat streams use; defaults to fetchFn. */
|
|
25
|
+
modelFetchFn?: typeof fetch;
|
|
26
|
+
/** Durable attachment service, for image input. */
|
|
27
|
+
attachments?: Pick<AttachmentStore, 'readImage' | 'readImageRequest'>;
|
|
28
|
+
/** Test seam: skip tools even when the stored settings ask for them. */
|
|
29
|
+
disableTools?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ClinePassLine {
|
|
32
|
+
adapter: ClinePassAdapter;
|
|
33
|
+
engine: ClinePassEngine;
|
|
34
|
+
store: ClinePassStore;
|
|
35
|
+
modelSettings: ClinePassModelSettingsStore;
|
|
36
|
+
accountPool: ClinePassAccountPool;
|
|
37
|
+
claim: ProviderRouteClaim;
|
|
38
|
+
disposeRoutes: () => void;
|
|
39
|
+
/** Owner overview card source, read from local snapshots only. */
|
|
40
|
+
hubSource: HubSummarySource;
|
|
41
|
+
/** Release every registration this line made. */
|
|
42
|
+
dispose(): void;
|
|
43
|
+
}
|
|
44
|
+
/** Every id the line knows, before the visibility selection is applied. */
|
|
45
|
+
export declare function clinePassKnownModelIds(settings: ClinePassModelSettings, catalogIds: readonly string[]): string[];
|
|
46
|
+
/** Every id the line advertises right now. */
|
|
47
|
+
export declare function clinePassVisibleModelIds(settings: ClinePassModelSettings, catalogIds: readonly string[]): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Build the line.
|
|
50
|
+
* @param ctx - host plugin context (owns `llm`, `webServer` and `tools`).
|
|
51
|
+
* @param options - the proxy-aware fetch and the attachment reader.
|
|
52
|
+
*/
|
|
53
|
+
export declare function createClinePassLine(ctx: Context, options: ClinePassLineOptions): ClinePassLine;
|
|
54
|
+
export { CLINE_PASS_ROUTES };
|
|
55
|
+
//# sourceMappingURL=line.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line.d.ts","sourceRoot":"","sources":["../../../../src/host/cline-pass/line.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAGzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,eA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AO,EAAE,oBAAoB,GAAG,aAAa,CAgI9F;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cline Pass wire mapping: the harness conversation in, an OpenAI-compatible
|
|
3
|
+
* `chat/completions` body out; decoded SSE frames in, harness stream chunks out.
|
|
4
|
+
*
|
|
5
|
+
* The request order rules matter more than they look: an assistant message
|
|
6
|
+
* carrying `tool_calls` must be followed immediately by one `tool` message per
|
|
7
|
+
* call id, or a validating gateway rejects the whole request with "insufficient
|
|
8
|
+
* tool messages following tool_calls message". Everything that would otherwise
|
|
9
|
+
* land inside that run is held back until the group closes.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-chatgpt-subscription/cline-pass-mapper
|
|
12
|
+
*/
|
|
13
|
+
import { type StreamChunk, type TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
14
|
+
import type { GenerateOptions, Message } from '../common/llm-compat.ts';
|
|
15
|
+
import { type ResolvedRequestImages } from '../common/request-images.ts';
|
|
16
|
+
/** One OpenAI wire message. */
|
|
17
|
+
export interface ClinePassWireMessage {
|
|
18
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
19
|
+
content: string | Array<Record<string, unknown>>;
|
|
20
|
+
reasoning_content?: string;
|
|
21
|
+
tool_calls?: Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
type: 'function';
|
|
24
|
+
function: {
|
|
25
|
+
name: string;
|
|
26
|
+
arguments: string;
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
29
|
+
tool_call_id?: string;
|
|
30
|
+
}
|
|
31
|
+
/** One request body, as sent after pin injection. */
|
|
32
|
+
export interface ClinePassWireBody {
|
|
33
|
+
model: string;
|
|
34
|
+
messages: ClinePassWireMessage[];
|
|
35
|
+
stream: true;
|
|
36
|
+
stream_options: {
|
|
37
|
+
include_usage: true;
|
|
38
|
+
};
|
|
39
|
+
tools?: Array<{
|
|
40
|
+
type: 'function';
|
|
41
|
+
function: {
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
parameters: Record<string, unknown>;
|
|
45
|
+
};
|
|
46
|
+
}>;
|
|
47
|
+
temperature?: number;
|
|
48
|
+
max_tokens?: number;
|
|
49
|
+
stop?: readonly string[];
|
|
50
|
+
reasoning_effort?: string;
|
|
51
|
+
provider?: Record<string, unknown>;
|
|
52
|
+
providerOptions?: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Convert the harness conversation to wire messages.
|
|
56
|
+
*
|
|
57
|
+
* Tool results become standalone `role: 'tool'` messages. A user message
|
|
58
|
+
* carrying an image switches to the OpenAI content-part array; a text-only one
|
|
59
|
+
* keeps the plain-string form. An image nested in a tool result has no OpenAI
|
|
60
|
+
* `tool` wire spelling, so it rides a following user message instead — the same
|
|
61
|
+
* shape the shipped adapters use. Deferring that message until the next non-tool
|
|
62
|
+
* message keeps a parallel group's answers contiguous.
|
|
63
|
+
*
|
|
64
|
+
* `developer` becomes `system`: the newer OpenAI spelling is not accepted by
|
|
65
|
+
* every OpenAI-compatible gateway, while `system` is.
|
|
66
|
+
*/
|
|
67
|
+
export declare function serializeMessages(messages: readonly Message[], images: ResolvedRequestImages): ClinePassWireMessage[];
|
|
68
|
+
/**
|
|
69
|
+
* Build the wire request for one harness call, before pinning.
|
|
70
|
+
* @param options - the harness request (model, system, history, tools, sampling).
|
|
71
|
+
* @param connection - resolved connection facts (default output budget).
|
|
72
|
+
* @param images - attachmentId → prepared request version.
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildClinePassBody(options: GenerateOptions, connection: {
|
|
75
|
+
maxTokens: number;
|
|
76
|
+
}, images: ResolvedRequestImages): ClinePassWireBody;
|
|
77
|
+
/** Map an OpenAI `finish_reason` to the harness finish reason. */
|
|
78
|
+
export declare function mapFinishReason(reason: string): StreamChunk & {
|
|
79
|
+
type: 'finish';
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Map OpenAI usage fields to disjoint harness counts.
|
|
83
|
+
*
|
|
84
|
+
* `prompt_tokens` includes cache hits per the OpenAI convention, and the harness
|
|
85
|
+
* counts are disjoint, so cached tokens are subtracted out of `inputTokens`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function mapUsage(usage: Record<string, unknown> | null | undefined): TokenUsage;
|
|
88
|
+
/**
|
|
89
|
+
* Read one delta's reasoning text, tolerating both wire spellings.
|
|
90
|
+
*
|
|
91
|
+
* Prefers the string field, and falls back to joining the `reasoning_details`
|
|
92
|
+
* parts, which is where a gateway that omits the flat field puts the same text.
|
|
93
|
+
*/
|
|
94
|
+
export declare function reasoningOf(delta: Record<string, unknown>): string | undefined;
|
|
95
|
+
/** Map a gateway error payload to a stable harness code. */
|
|
96
|
+
export declare function streamErrorCode(message: string, status?: number): string;
|
|
97
|
+
/**
|
|
98
|
+
* Parse an SSE body into decoded JSON frames.
|
|
99
|
+
* @param body - a web ReadableStream of UTF-8 bytes.
|
|
100
|
+
* @returns every `data:` payload up to `[DONE]`.
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseServerSentEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<unknown | '[DONE]'>;
|
|
103
|
+
/**
|
|
104
|
+
* Translate decoded SSE payloads into harness stream chunks.
|
|
105
|
+
*
|
|
106
|
+
* Deltas stream through as they arrive; block ends, usage and the finish reason
|
|
107
|
+
* are all deferred to the `[DONE]` sentinel, so no chunk ever follows `finish`.
|
|
108
|
+
* A completion with no content at all becomes an `EMPTY_RESPONSE` error finish
|
|
109
|
+
* rather than a silent empty message.
|
|
110
|
+
*/
|
|
111
|
+
export declare function translate(payloads: AsyncIterable<unknown | '[DONE]'>): AsyncGenerator<StreamChunk>;
|
|
112
|
+
//# sourceMappingURL=mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../../../src/host/cline-pass/mapper.ts"],"names":[],"mappings":"AAAA;;;;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