@eddyskywalker/dsh-chatgpt-subscription 0.30.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.
Files changed (110) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +64 -1
  3. package/lib/client.js +34034 -2768
  4. package/lib/client.js.map +1 -1
  5. package/lib/index.js +33214 -24259
  6. package/lib/types/client/cline-pass/ClinePassComposerQuota.d.ts +20 -0
  7. package/lib/types/client/cline-pass/ClinePassComposerQuota.d.ts.map +1 -0
  8. package/lib/types/client/cline-pass/ClinePassSection.d.ts +17 -0
  9. package/lib/types/client/cline-pass/ClinePassSection.d.ts.map +1 -0
  10. package/lib/types/client/cline-pass/api.d.ts +84 -0
  11. package/lib/types/client/cline-pass/api.d.ts.map +1 -0
  12. package/lib/types/client/cline-pass/locales.d.ts +1025 -0
  13. package/lib/types/client/cline-pass/locales.d.ts.map +1 -0
  14. package/lib/types/client/cline-pass/styles.d.ts +7 -0
  15. package/lib/types/client/cline-pass/styles.d.ts.map +1 -0
  16. package/lib/types/client/hub/brand-icons.d.ts +2 -2
  17. package/lib/types/client/hub/brand-icons.d.ts.map +1 -1
  18. package/lib/types/client/hub/providers.d.ts.map +1 -1
  19. package/lib/types/client/index.d.ts +2 -0
  20. package/lib/types/client/index.d.ts.map +1 -1
  21. package/lib/types/client/mermaid/renderer.d.ts +23 -0
  22. package/lib/types/client/mermaid/renderer.d.ts.map +1 -1
  23. package/lib/types/client/minimax-code/MinimaxCodeSection.d.ts.map +1 -1
  24. package/lib/types/client/minimax-code/MinimaxVideoDocumentBody.d.ts +86 -0
  25. package/lib/types/client/minimax-code/MinimaxVideoDocumentBody.d.ts.map +1 -0
  26. package/lib/types/client/minimax-code/MinimaxVideoToolView.d.ts +83 -0
  27. package/lib/types/client/minimax-code/MinimaxVideoToolView.d.ts.map +1 -0
  28. package/lib/types/client/minimax-code/VideoFormDialog.d.ts +90 -0
  29. package/lib/types/client/minimax-code/VideoFormDialog.d.ts.map +1 -0
  30. package/lib/types/client/minimax-code/VideoSettingsSections.d.ts +73 -0
  31. package/lib/types/client/minimax-code/VideoSettingsSections.d.ts.map +1 -0
  32. package/lib/types/client/minimax-code/commands-contract.d.ts +35 -0
  33. package/lib/types/client/minimax-code/commands-contract.d.ts.map +1 -0
  34. package/lib/types/client/minimax-code/document-preview.d.ts +45 -0
  35. package/lib/types/client/minimax-code/document-preview.d.ts.map +1 -0
  36. package/lib/types/client/minimax-code/locales.d.ts +206 -2
  37. package/lib/types/client/minimax-code/locales.d.ts.map +1 -1
  38. package/lib/types/client/minimax-code/styles.d.ts.map +1 -1
  39. package/lib/types/client/minimax-code/video-command-host.d.ts +61 -0
  40. package/lib/types/client/minimax-code/video-command-host.d.ts.map +1 -0
  41. package/lib/types/client/minimax-code/video-command.d.ts +126 -0
  42. package/lib/types/client/minimax-code/video-command.d.ts.map +1 -0
  43. package/lib/types/client/minimax-code/video-contract.d.ts +208 -0
  44. package/lib/types/client/minimax-code/video-contract.d.ts.map +1 -0
  45. package/lib/types/client/minimax-code/video-defaults-store.d.ts +61 -0
  46. package/lib/types/client/minimax-code/video-defaults-store.d.ts.map +1 -0
  47. package/lib/types/client/minimax-code/video-form-rules.d.ts +288 -0
  48. package/lib/types/client/minimax-code/video-form-rules.d.ts.map +1 -0
  49. package/lib/types/client/minimax-code/video-media.d.ts +61 -0
  50. package/lib/types/client/minimax-code/video-media.d.ts.map +1 -0
  51. package/lib/types/client/minimax-code/video-slots.d.ts +140 -0
  52. package/lib/types/client/minimax-code/video-slots.d.ts.map +1 -0
  53. package/lib/types/client/progress-updates/markdown-lite.d.ts +19 -6
  54. package/lib/types/client/progress-updates/markdown-lite.d.ts.map +1 -1
  55. package/lib/types/host/antigravity/adapter.d.ts.map +1 -1
  56. package/lib/types/host/cline-pass/account-pool.d.ts +63 -0
  57. package/lib/types/host/cline-pass/account-pool.d.ts.map +1 -0
  58. package/lib/types/host/cline-pass/adapter.d.ts +49 -0
  59. package/lib/types/host/cline-pass/adapter.d.ts.map +1 -0
  60. package/lib/types/host/cline-pass/catalog.d.ts +49 -0
  61. package/lib/types/host/cline-pass/catalog.d.ts.map +1 -0
  62. package/lib/types/host/cline-pass/client.d.ts +118 -0
  63. package/lib/types/host/cline-pass/client.d.ts.map +1 -0
  64. package/lib/types/host/cline-pass/engine.d.ts +223 -0
  65. package/lib/types/host/cline-pass/engine.d.ts.map +1 -0
  66. package/lib/types/host/cline-pass/line.d.ts +55 -0
  67. package/lib/types/host/cline-pass/line.d.ts.map +1 -0
  68. package/lib/types/host/cline-pass/mapper.d.ts +112 -0
  69. package/lib/types/host/cline-pass/mapper.d.ts.map +1 -0
  70. package/lib/types/host/cline-pass/oauth.d.ts +134 -0
  71. package/lib/types/host/cline-pass/oauth.d.ts.map +1 -0
  72. package/lib/types/host/cline-pass/protocol.d.ts +186 -0
  73. package/lib/types/host/cline-pass/protocol.d.ts.map +1 -0
  74. package/lib/types/host/cline-pass/routes.d.ts +71 -0
  75. package/lib/types/host/cline-pass/routes.d.ts.map +1 -0
  76. package/lib/types/host/cline-pass/store.d.ts +97 -0
  77. package/lib/types/host/cline-pass/store.d.ts.map +1 -0
  78. package/lib/types/host/cline-pass/token-store.d.ts +168 -0
  79. package/lib/types/host/cline-pass/token-store.d.ts.map +1 -0
  80. package/lib/types/host/cline-pass/tools.d.ts +21 -0
  81. package/lib/types/host/cline-pass/tools.d.ts.map +1 -0
  82. package/lib/types/host/cline-pass/types.d.ts +168 -0
  83. package/lib/types/host/cline-pass/types.d.ts.map +1 -0
  84. package/lib/types/host/common/model-request-control.d.ts +1 -1
  85. package/lib/types/host/common/model-request-control.d.ts.map +1 -1
  86. package/lib/types/host/common/request-diagnostics.d.ts +1 -1
  87. package/lib/types/host/common/request-diagnostics.d.ts.map +1 -1
  88. package/lib/types/host/minimax-code/client.d.ts.map +1 -1
  89. package/lib/types/host/minimax-code/iso-bmff-duration.d.ts +84 -0
  90. package/lib/types/host/minimax-code/iso-bmff-duration.d.ts.map +1 -0
  91. package/lib/types/host/minimax-code/matrix-client.d.ts +168 -0
  92. package/lib/types/host/minimax-code/matrix-client.d.ts.map +1 -0
  93. package/lib/types/host/minimax-code/media-store.d.ts +153 -0
  94. package/lib/types/host/minimax-code/media-store.d.ts.map +1 -0
  95. package/lib/types/host/minimax-code/routes.d.ts.map +1 -1
  96. package/lib/types/host/minimax-code/video-history.d.ts +240 -0
  97. package/lib/types/host/minimax-code/video-history.d.ts.map +1 -0
  98. package/lib/types/host/minimax-code/video-submit-rules.d.ts +40 -0
  99. package/lib/types/host/minimax-code/video-submit-rules.d.ts.map +1 -0
  100. package/lib/types/host/minimax-code/video-tool.d.ts +757 -0
  101. package/lib/types/host/minimax-code/video-tool.d.ts.map +1 -0
  102. package/lib/types/host/progress-updates/index.d.ts +6 -0
  103. package/lib/types/host/progress-updates/index.d.ts.map +1 -1
  104. package/lib/types/host/progress-updates/projection.d.ts +214 -0
  105. package/lib/types/host/progress-updates/projection.d.ts.map +1 -0
  106. package/lib/types/index.d.ts +12 -0
  107. package/lib/types/index.d.ts.map +1 -1
  108. package/lib/types/shared/cline-pass-contracts.d.ts +267 -0
  109. package/lib/types/shared/cline-pass-contracts.d.ts.map +1 -0
  110. package/package.json +14 -4
@@ -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,EA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zB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,CAAC;IAUpB,iFAAiF;IACjF,cAAc,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,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAAkD,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/F,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AACtE,OAAO,EAAE,2BAA2B,EAAE,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAG3F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,OAAO,EAAE,OAAO,KAAK,CAAA;IACrB,2FAA2F;IAC3F,YAAY,CAAC,EAAE,OAAO,KAAK,CAAA;IAC3B,mDAAmD;IACnD,WAAW,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,kBAAkB,CAAC,CAAA;IACrE,wEAAwE;IACxE,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,gBAAgB,CAAA;IACzB,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,cAAc,CAAA;IACrB,aAAa,EAAE,2BAA2B,CAAA;IAC1C,WAAW,EAAE,oBAAoB,CAAA;IACjC,KAAK,EAAE,kBAAkB,CAAA;IACzB,aAAa,EAAE,MAAM,IAAI,CAAA;IACzB,kEAAkE;IAClE,SAAS,EAAE,gBAAgB,CAAA;IAC3B,iDAAiD;IACjD,OAAO,IAAI,IAAI,CAAA;CAChB;AAED,2EAA2E;AAC3E,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,sBAAsB,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAKhH;AAED,8CAA8C;AAC9C,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,sBAAsB,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAIlH;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,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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C,CA2CjH;AAcD;;;;;;;GAOG;AACH,wBAAuB,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,cAAc,CAAC,WAAW,CAAC,CAgGzG"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Cline account sign-in: WorkOS device authorization followed by Cline's token
3
+ * registration, plus the refresh chain.
4
+ *
5
+ * The official clients implement exactly this sequence (Cline repo
6
+ * `sdk/packages/core/src/auth/cline.ts` + `auth/provider-auth-registry.ts`):
7
+ *
8
+ * 1. `POST https://api.workos.com/user_management/authorize/device` with the
9
+ * public client id → `device_code`, `user_code`, `verification_uri_complete`;
10
+ * 2. the user confirms the code in a browser;
11
+ * 3. `POST https://api.workos.com/user_management/authenticate` polls the device
12
+ * grant → WorkOS `access_token` / `refresh_token`;
13
+ * 4. `POST {cline}/api/v1/auth/register` exchanges those for Cline's own session
14
+ * (access, rotating refresh, expiry, user info);
15
+ * 5. later, `POST {cline}/api/v1/auth/refresh` renews it.
16
+ *
17
+ * The chat bearer is `workos:<access>` — the prefix is part of the token the
18
+ * official clients send, not a display detail. See `formatClineApiKey` in the
19
+ * same repo.
20
+ *
21
+ * The constants below are transcribed from
22
+ * `sdk/packages/shared/src/runtime/cline-environment.ts` (production entry).
23
+ *
24
+ * @module dsh-chatgpt-subscription/cline-pass-oauth
25
+ */
26
+ import { type ClinePassOAuthCredentials } from './token-store.ts';
27
+ export declare const CLINE_WORKOS_CLIENT_ID = "client_01K3A541FN8TA3EPPHTD2325AR";
28
+ export declare const CLINE_WORKOS_API_BASE = "https://api.workos.com";
29
+ export declare const CLINE_WORKOS_DEVICE_PATH = "/user_management/authorize/device";
30
+ export declare const CLINE_WORKOS_AUTHENTICATE_PATH = "/user_management/authenticate";
31
+ /** One WorkOS device authorization, as the card renders it. */
32
+ export interface ClinePassDeviceAuthorization {
33
+ deviceCode: string;
34
+ userCode: string;
35
+ verificationUri: string;
36
+ verificationUriComplete?: string;
37
+ expiresInSeconds: number;
38
+ pollIntervalSeconds: number;
39
+ }
40
+ /** A token/refresh failure with the HTTP facts a caller can judge. */
41
+ export declare class ClinePassOAuthError extends Error {
42
+ readonly status?: number;
43
+ readonly code?: string;
44
+ constructor(message: string, options?: {
45
+ status?: number;
46
+ code?: string;
47
+ cause?: unknown;
48
+ });
49
+ }
50
+ /** Whether a refresh failure means the session is gone and a sign-in is needed. */
51
+ export declare function isClinePassInvalidGrant(error: unknown): boolean;
52
+ /** The auth root for one chat base URL. */
53
+ export declare function clineAuthBaseURL(chatBaseURL: string): string;
54
+ /** One auth sub-path under the chat base. */
55
+ export declare function clineAuthURL(chatBaseURL: string, path: string): string;
56
+ /** Step 1: ask WorkOS for a device code. */
57
+ export declare function startClinePassDeviceAuth(fetchFn: typeof fetch, { signal, timeoutMs }?: {
58
+ signal?: AbortSignal;
59
+ timeoutMs?: number;
60
+ }): Promise<ClinePassDeviceAuthorization>;
61
+ /** Step 4: exchange WorkOS tokens for a Cline session. */
62
+ export declare function registerClinePassTokens(fetchFn: typeof fetch, { baseURL, accessToken, refreshToken, signal, timeoutMs, base, }: {
63
+ baseURL: string;
64
+ accessToken: string;
65
+ refreshToken: string;
66
+ signal?: AbortSignal;
67
+ timeoutMs?: number;
68
+ base?: Partial<ClinePassOAuthCredentials>;
69
+ }): Promise<ClinePassOAuthCredentials>;
70
+ /** Renew one Cline session. The refresh token rotates, so persist the result. */
71
+ export declare function refreshClinePassCredentials(fetchFn: typeof fetch, credentials: ClinePassOAuthCredentials, { baseURL, signal, timeoutMs, }: {
72
+ baseURL: string;
73
+ signal?: AbortSignal;
74
+ timeoutMs?: number;
75
+ }): Promise<ClinePassOAuthCredentials>;
76
+ /** Whether one session should be refreshed before its next use. */
77
+ export declare function clinePassNeedsRefresh(credentials: ClinePassOAuthCredentials, now: number): boolean;
78
+ /** One login flow, as the settings card renders it. */
79
+ export type ClinePassLoginStatus = 'idle' | 'pending' | 'complete' | 'failed' | 'cancelled';
80
+ export interface ClinePassLoginFlow {
81
+ id: string;
82
+ status: ClinePassLoginStatus;
83
+ userCode: string;
84
+ verificationUri: string;
85
+ expiresAt: number;
86
+ intervalSeconds: number;
87
+ error: string;
88
+ accountAlias: string;
89
+ }
90
+ export interface ClinePassLoginOptions {
91
+ fetchFn: typeof fetch;
92
+ /** The line's current chat base URL. */
93
+ baseURL(): string;
94
+ /** Persist a newly signed-in account; throws make the flow fail. */
95
+ onLogin(credentials: ClinePassOAuthCredentials): Promise<void>;
96
+ logger?: {
97
+ warn(message: string, ...args: unknown[]): void;
98
+ };
99
+ }
100
+ /**
101
+ * One device-code sign-in at a time.
102
+ *
103
+ * Polling is driven by the card (`GET /login/status`): each request makes at
104
+ * most one WorkOS call, and only after the advertised interval has elapsed. A
105
+ * host restart therefore loses the pending flow rather than keeping a poll loop
106
+ * alive with no reader — the same contract the Step Code line uses.
107
+ */
108
+ export declare class ClinePassLoginManager {
109
+ private readonly options;
110
+ private flow;
111
+ private sequence;
112
+ constructor(options: ClinePassLoginOptions);
113
+ /** Start a new flow, cancelling any previous one. */
114
+ begin({ signal }?: {
115
+ signal?: AbortSignal;
116
+ }): Promise<ClinePassLoginFlow>;
117
+ /** The latest flow, or null when this process never started one. */
118
+ current(): ClinePassLoginFlow | null;
119
+ /**
120
+ * Advance one flow and return its state.
121
+ *
122
+ * A flow the caller does not name is not advanced: two cards (or a stale one)
123
+ * cannot spend each other's polls.
124
+ */
125
+ status(id: string, { signal, timeoutMs }?: {
126
+ signal?: AbortSignal;
127
+ timeoutMs?: number;
128
+ }): Promise<ClinePassLoginFlow>;
129
+ /** Abandon one flow; a late browser confirmation is then ignored. */
130
+ cancel(id: string): boolean;
131
+ /** Mark every flow cancelled for teardown. */
132
+ dispose(): void;
133
+ }
134
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/host/cline-pass/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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