dsh-provider-qoder 0.1.0 → 0.2.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/README.md +10 -5
- package/README_CN.md +10 -5
- package/lib/client.js +189 -84
- package/lib/index.d.ts +61 -341
- package/lib/index.js +1691 -837
- package/package.json +3 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,89 +1,16 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
|
-
import { GenerateOptions, LlmAdapter, LlmError, LlmErrorOptions, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, Message, StreamChunk, ToolSchema } from "@deepseek-ai/dsh-llm";
|
|
3
|
-
import { CredentialProvider } from "@deepseek-ai/dsh-credentials";
|
|
4
2
|
import { Context } from "@deepseek-ai/cordis";
|
|
5
3
|
|
|
6
|
-
//#region src/
|
|
7
|
-
/**
|
|
8
|
-
* COSY authentication headers and signature algorithm for Qoder services.
|
|
9
|
-
*
|
|
10
|
-
* Implements RSA + AES + MD5 signature generation required by the upstream
|
|
11
|
-
* Qoder gateway.
|
|
12
|
-
*
|
|
13
|
-
* @module dsh-provider-qoder/cosy
|
|
14
|
-
*/
|
|
15
|
-
interface CosyCredentials {
|
|
16
|
-
userID: string;
|
|
17
|
-
authToken: string;
|
|
18
|
-
name: string;
|
|
19
|
-
email: string;
|
|
20
|
-
machineID?: string;
|
|
21
|
-
}
|
|
22
|
-
declare function computeSigPath(urlStr: string): string;
|
|
23
|
-
declare function buildAuthHeaders(body: Buffer | string | null, requestURL: string, creds: CosyCredentials): Record<string, string>;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/endpoints.d.ts
|
|
26
|
-
/** Qoder transport endpoints for Global and China service regions. */
|
|
27
|
-
type QoderRegion = 'global' | 'china';
|
|
28
|
-
interface QoderRegionEndpoints {
|
|
29
|
-
baseUrl: string;
|
|
30
|
-
openApiUrl: string;
|
|
31
|
-
}
|
|
32
|
-
declare const qoderRegionEndpoints: Record<QoderRegion, QoderRegionEndpoints>;
|
|
33
|
-
declare const qoderGlobalBaseUrl: string;
|
|
34
|
-
declare const qoderGlobalOpenApiUrl: string;
|
|
35
|
-
declare function resolveQoderEndpoints(region?: QoderRegion): QoderRegionEndpoints;
|
|
36
|
-
declare function getQoderChatUrl(region?: QoderRegion): string;
|
|
37
|
-
declare function getQoderModelListUrl(region?: QoderRegion): string;
|
|
38
|
-
declare function getQoderExchangeUrl(region?: QoderRegion): string;
|
|
39
|
-
declare function getQoderUserInfoUrl(region?: QoderRegion): string;
|
|
40
|
-
declare function getQoderUsageUrl(region?: QoderRegion): string;
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/logging.d.ts
|
|
43
|
-
/** Bounded, redacted diagnostics shared by Qoder host services. */
|
|
44
|
-
interface QoderLogger {
|
|
45
|
-
debug?(message: string, ...details: unknown[]): void;
|
|
46
|
-
warn?(message: string, ...details: unknown[]): void;
|
|
47
|
-
error?(message: string, ...details: unknown[]): void;
|
|
48
|
-
}
|
|
49
|
-
/** Redact credentials and bound arbitrary provider values before logging them. */
|
|
50
|
-
declare function redactLogValue(value: unknown, depth?: number): unknown;
|
|
51
|
-
/** Parse JSON-shaped diagnostics when possible, then apply the same redaction boundary. */
|
|
52
|
-
declare function redactLogPayload(text: string): unknown;
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/auth.d.ts
|
|
55
|
-
interface QoderAuthServiceOptions {
|
|
56
|
-
fetch?: typeof fetch;
|
|
57
|
-
timeoutMs?: number;
|
|
58
|
-
resolveMachineId?: () => string;
|
|
59
|
-
resolveRegion?: () => QoderRegion;
|
|
60
|
-
region?: QoderRegion;
|
|
61
|
-
logger?: QoderLogger;
|
|
62
|
-
}
|
|
63
|
-
declare class QoderAuthService {
|
|
64
|
-
private readonly cache;
|
|
65
|
-
private readonly inFlight;
|
|
66
|
-
private readonly fetchImpl;
|
|
67
|
-
private readonly timeoutMs;
|
|
68
|
-
private readonly resolveMachineId;
|
|
69
|
-
private readonly resolveRegion?;
|
|
70
|
-
private region?;
|
|
71
|
-
private readonly logger?;
|
|
72
|
-
constructor(options?: QoderAuthServiceOptions);
|
|
73
|
-
setRegion(region: QoderRegion): void;
|
|
74
|
-
currentRegion(): QoderRegion;
|
|
75
|
-
clear(pat?: string): void;
|
|
76
|
-
getCredentials(pat: string, signal?: AbortSignal, region?: QoderRegion): Promise<CosyCredentials>;
|
|
77
|
-
private exchangeAndResolve;
|
|
78
|
-
private fetchUserInfo;
|
|
79
|
-
}
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/adapter.d.ts
|
|
4
|
+
//#region src/qoder/catalog.d.ts
|
|
5
|
+
/** Browser-safe Qoder model catalog types and built-in fallback entries. */
|
|
82
6
|
interface QoderCatalogModel {
|
|
83
7
|
id: string;
|
|
84
8
|
name: string;
|
|
85
9
|
description?: string;
|
|
10
|
+
/** Effective DSH input budget, which may be smaller than the provider default tier. */
|
|
86
11
|
contextWindow?: number;
|
|
12
|
+
/** Largest known capacity, independent of the effective input budget. */
|
|
13
|
+
maxContextWindow?: number;
|
|
87
14
|
maxTokens?: number;
|
|
88
15
|
source?: string;
|
|
89
16
|
isReasoning?: boolean;
|
|
@@ -99,236 +26,35 @@ interface QoderCatalogModel {
|
|
|
99
26
|
tokenCount?: number;
|
|
100
27
|
isDefault?: boolean;
|
|
101
28
|
}>;
|
|
102
|
-
|
|
103
|
-
declare const defaultMaxTokens = 32768;
|
|
104
|
-
declare const defaultStreamIdleTimeoutMs: number;
|
|
105
|
-
declare const defaultModels: QoderCatalogModel[];
|
|
106
|
-
interface QoderAdapterOptions {
|
|
107
|
-
resolvePat: () => Promise<string>;
|
|
108
|
-
models?: readonly QoderCatalogModel[];
|
|
109
|
-
providerId?: string;
|
|
110
|
-
providerName?: string;
|
|
111
|
-
authService?: QoderAuthService;
|
|
112
|
-
fetch?: typeof fetch;
|
|
113
|
-
logger?: QoderLogger;
|
|
114
|
-
streamIdleTimeoutMs?: number;
|
|
115
|
-
region?: QoderRegion;
|
|
116
|
-
}
|
|
117
|
-
declare class QoderAdapter extends LlmAdapter {
|
|
118
|
-
private readonly resolvePat;
|
|
119
|
-
private catalogModels;
|
|
120
|
-
private readonly authService;
|
|
121
|
-
private readonly fetchImpl;
|
|
122
|
-
private readonly logger?;
|
|
123
|
-
private streamIdleTimeoutMs;
|
|
124
|
-
private readonly providerId;
|
|
125
|
-
private readonly providerName;
|
|
126
|
-
private region;
|
|
127
|
-
constructor(options: QoderAdapterOptions);
|
|
128
|
-
providerInfo(provider: string): LlmProviderInfo;
|
|
129
|
-
listModels(provider: string): Promise<readonly LlmModelInfo[]>;
|
|
130
|
-
replaceConfig(models: readonly QoderCatalogModel[], streamIdleTimeoutMs: number, region?: QoderRegion): void;
|
|
131
|
-
resolveModel(provider: string, modelId: string, signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
|
|
132
|
-
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
133
|
-
private generate;
|
|
29
|
+
supportsImages?: boolean;
|
|
134
30
|
}
|
|
135
31
|
//#endregion
|
|
136
|
-
//#region src/
|
|
137
|
-
/**
|
|
138
|
-
|
|
139
|
-
/** DSH's local provider uses `env` and `*-env` for ambient credential layers. */
|
|
140
|
-
declare function isEnvironmentCredentialSource(source: string | undefined): boolean;
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/credential.d.ts
|
|
143
|
-
declare const managedQoderCredentialRef: import("@deepseek-ai/dsh-credentials").CredentialRef;
|
|
144
|
-
/** Resolve only provider-managed storage; ambient environment layers are intentionally unsupported. */
|
|
145
|
-
declare function resolveManagedQoderPat(credentials: CredentialProvider): Promise<string>;
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region src/encoding.d.ts
|
|
148
|
-
/**
|
|
149
|
-
* Qoder WAF Body encoding algorithm.
|
|
150
|
-
*
|
|
151
|
-
* Re-arranges standard Base64 chunks and translates characters against
|
|
152
|
-
* a custom alphabet to satisfy Qoder upstream WAF requirements.
|
|
153
|
-
*
|
|
154
|
-
* @module dsh-provider-qoder/encoding
|
|
155
|
-
*/
|
|
156
|
-
declare function qoderEncodeBody(plaintext: string | Buffer): string;
|
|
32
|
+
//#region src/qoder/region.d.ts
|
|
33
|
+
/** Qoder upstream deployment selected for one immutable transport instance. */
|
|
34
|
+
type QoderRegion = 'global' | 'china';
|
|
157
35
|
//#endregion
|
|
158
|
-
//#region src/
|
|
159
|
-
|
|
160
|
-
|
|
36
|
+
//#region src/dsh/config.d.ts
|
|
37
|
+
interface QoderModelsByRegion {
|
|
38
|
+
global?: QoderCatalogModel[];
|
|
39
|
+
china?: QoderCatalogModel[];
|
|
161
40
|
}
|
|
162
|
-
|
|
163
|
-
status: number;
|
|
164
|
-
headers?: Pick<Headers, 'get'>;
|
|
165
|
-
}): QoderLlmError;
|
|
166
|
-
declare function retryAfterMs(value: string | null, nowMs?: number): number | undefined;
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/machine-id.d.ts
|
|
169
|
-
/** Read Qoder's machine id or create the DSH-owned fallback. */
|
|
170
|
-
declare function getMachineId(paths?: readonly string[]): string;
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/models.d.ts
|
|
173
|
-
declare function normalizeQoderModels(payload: unknown): QoderCatalogModel[];
|
|
174
|
-
/**
|
|
175
|
-
* Restore Qoder-only metadata after DSH's provider-neutral discovery contract
|
|
176
|
-
* has retained only id, name, and token limits.
|
|
177
|
-
*/
|
|
178
|
-
declare function mergeQoderDiscoveryMetadata(configured: readonly QoderCatalogModel[], discovered: readonly QoderCatalogModel[]): QoderCatalogModel[];
|
|
179
|
-
declare function hasSameQoderDiscoveryMetadata(left: readonly QoderCatalogModel[] | undefined, right: readonly QoderCatalogModel[]): boolean;
|
|
180
|
-
interface FetchQoderModelsOptions {
|
|
181
|
-
fetch?: typeof fetch;
|
|
182
|
-
signal?: AbortSignal;
|
|
41
|
+
interface Config {
|
|
183
42
|
region?: QoderRegion;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Qoder protocol wire types and definitions.
|
|
191
|
-
*
|
|
192
|
-
* @module dsh-provider-qoder/types
|
|
193
|
-
*/
|
|
194
|
-
interface QoderWireToolCall {
|
|
195
|
-
id: string;
|
|
196
|
-
type: 'function';
|
|
197
|
-
function: {
|
|
198
|
-
name: string;
|
|
199
|
-
arguments: string;
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
interface QoderWireTool {
|
|
203
|
-
type: 'function';
|
|
204
|
-
function: {
|
|
205
|
-
name: string;
|
|
206
|
-
description: string;
|
|
207
|
-
parameters: Record<string, unknown>;
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
interface QoderWireMessage {
|
|
211
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
212
|
-
content: string | null;
|
|
213
|
-
tool_calls?: QoderWireToolCall[];
|
|
214
|
-
tool_call_id?: string;
|
|
215
|
-
}
|
|
216
|
-
interface QoderModelConfig {
|
|
217
|
-
key: string;
|
|
218
|
-
is_reasoning: boolean;
|
|
219
|
-
max_output_tokens: number;
|
|
220
|
-
source: string;
|
|
221
|
-
context_config?: Record<string, {
|
|
222
|
-
token_count?: number;
|
|
223
|
-
is_default?: boolean;
|
|
224
|
-
}>;
|
|
225
|
-
}
|
|
226
|
-
interface QoderChatContext {
|
|
227
|
-
chatPrompt: string;
|
|
228
|
-
imageUrls: null | string[];
|
|
229
|
-
extra: {
|
|
230
|
-
context: unknown[];
|
|
231
|
-
modelConfig: {
|
|
232
|
-
key: string;
|
|
233
|
-
is_reasoning: boolean;
|
|
234
|
-
};
|
|
235
|
-
originalContent: string;
|
|
236
|
-
};
|
|
237
|
-
features: unknown[];
|
|
238
|
-
text: string;
|
|
239
|
-
}
|
|
240
|
-
interface QoderBusiness {
|
|
241
|
-
product: string;
|
|
242
|
-
version: string;
|
|
243
|
-
type: string;
|
|
244
|
-
stage: string;
|
|
245
|
-
id: string;
|
|
246
|
-
name: string;
|
|
247
|
-
begin_at: number;
|
|
248
|
-
}
|
|
249
|
-
interface QoderWireRequest {
|
|
250
|
-
request_id: string;
|
|
251
|
-
request_set_id: string;
|
|
252
|
-
chat_record_id: string;
|
|
253
|
-
session_id: string;
|
|
254
|
-
stream: true;
|
|
255
|
-
chat_task: string;
|
|
256
|
-
is_reply: boolean;
|
|
257
|
-
is_retry: boolean;
|
|
258
|
-
source: number;
|
|
259
|
-
version: string;
|
|
260
|
-
session_type: string;
|
|
261
|
-
agent_id: string;
|
|
262
|
-
task_id: string;
|
|
263
|
-
code_language: string;
|
|
264
|
-
chat_prompt: string;
|
|
265
|
-
image_urls: null;
|
|
266
|
-
aliyun_user_type: string;
|
|
267
|
-
system: string;
|
|
268
|
-
messages: QoderWireMessage[];
|
|
269
|
-
tools: QoderWireTool[];
|
|
270
|
-
parameters: {
|
|
271
|
-
max_tokens: number;
|
|
272
|
-
reasoning_effort?: string;
|
|
273
|
-
};
|
|
274
|
-
chat_context: QoderChatContext;
|
|
275
|
-
model_config: QoderModelConfig;
|
|
276
|
-
business: QoderBusiness;
|
|
277
|
-
}
|
|
278
|
-
interface QoderSseEnvelope {
|
|
279
|
-
statusCodeValue?: number;
|
|
280
|
-
body?: string;
|
|
281
|
-
}
|
|
282
|
-
interface QoderInnerChunk {
|
|
283
|
-
id?: string;
|
|
284
|
-
model?: string;
|
|
285
|
-
choices?: Array<{
|
|
286
|
-
index?: number;
|
|
287
|
-
delta?: {
|
|
288
|
-
content?: string;
|
|
289
|
-
role?: string;
|
|
290
|
-
reasoning_content?: string;
|
|
291
|
-
tool_calls?: Array<{
|
|
292
|
-
index?: number;
|
|
293
|
-
id?: string;
|
|
294
|
-
type?: string;
|
|
295
|
-
function?: {
|
|
296
|
-
name?: string;
|
|
297
|
-
arguments?: string;
|
|
298
|
-
};
|
|
299
|
-
}>;
|
|
300
|
-
};
|
|
301
|
-
finish_reason?: string | null;
|
|
302
|
-
}>;
|
|
303
|
-
usage?: {
|
|
304
|
-
prompt_tokens?: number;
|
|
305
|
-
completion_tokens?: number;
|
|
306
|
-
total_tokens?: number;
|
|
307
|
-
prompt_tokens_details?: {
|
|
308
|
-
cached_tokens?: number;
|
|
309
|
-
cache_write_tokens?: number;
|
|
310
|
-
};
|
|
311
|
-
completion_tokens_details?: {
|
|
312
|
-
reasoning_tokens?: number;
|
|
313
|
-
};
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
//#endregion
|
|
317
|
-
//#region src/serialize.d.ts
|
|
318
|
-
declare function validateQoderRequest(options: GenerateOptions, model?: QoderCatalogModel): QoderWireMessage[];
|
|
319
|
-
declare function buildQoderRequestBody(options: GenerateOptions, userId: string, translatedMessages?: QoderWireMessage[], model?: QoderCatalogModel): QoderWireRequest;
|
|
320
|
-
//#endregion
|
|
321
|
-
//#region src/sse.d.ts
|
|
322
|
-
interface QoderSseOptions {
|
|
323
|
-
onActivity?: () => void;
|
|
43
|
+
modelsByRegion?: QoderModelsByRegion;
|
|
44
|
+
/** @deprecated Migrated to modelsByRegion for the selected region. */
|
|
45
|
+
models?: QoderCatalogModel[];
|
|
46
|
+
streamIdleTimeoutMs?: number;
|
|
47
|
+
preserveThinking?: boolean;
|
|
324
48
|
}
|
|
325
|
-
declare
|
|
49
|
+
declare const Config: z<Config>;
|
|
326
50
|
//#endregion
|
|
327
|
-
//#region src/
|
|
328
|
-
declare
|
|
329
|
-
declare
|
|
51
|
+
//#region src/dsh/plugin.d.ts
|
|
52
|
+
declare const name = "provider-qoder";
|
|
53
|
+
declare const inject: string[];
|
|
54
|
+
declare function apply(ctx: Context, config?: Config): void;
|
|
330
55
|
//#endregion
|
|
331
|
-
//#region src/
|
|
56
|
+
//#region src/qoder/account.d.ts
|
|
57
|
+
/** Browser-safe Qoder subscriber account and quota types. */
|
|
332
58
|
interface QoderSubscriberProfile {
|
|
333
59
|
id: string;
|
|
334
60
|
name: string;
|
|
@@ -349,50 +75,44 @@ interface QoderQuotaUsage {
|
|
|
349
75
|
expiresAt?: string;
|
|
350
76
|
raw?: unknown;
|
|
351
77
|
}
|
|
78
|
+
interface QoderSubscriberOrganization {
|
|
79
|
+
orgId: string;
|
|
80
|
+
orgName: string;
|
|
81
|
+
roleName?: string;
|
|
82
|
+
isSuspended?: boolean;
|
|
83
|
+
canManageSubscriptions?: boolean;
|
|
84
|
+
resourcePackageFeatureEnabled?: boolean;
|
|
85
|
+
}
|
|
86
|
+
interface QoderSubscriberFeatureAllowed {
|
|
87
|
+
quest?: boolean;
|
|
88
|
+
wiki?: boolean;
|
|
89
|
+
codeReview?: boolean;
|
|
90
|
+
}
|
|
91
|
+
interface QoderSubscriberPlan {
|
|
92
|
+
userType: string;
|
|
93
|
+
planTierName: string;
|
|
94
|
+
planTier?: string;
|
|
95
|
+
isPersonalVersion: boolean;
|
|
96
|
+
isHighestTier?: boolean;
|
|
97
|
+
isRenewed?: boolean;
|
|
98
|
+
startDate?: string;
|
|
99
|
+
endDate?: string;
|
|
100
|
+
organization?: QoderSubscriberOrganization;
|
|
101
|
+
featureAllowed?: QoderSubscriberFeatureAllowed;
|
|
102
|
+
raw?: unknown;
|
|
103
|
+
}
|
|
104
|
+
interface QoderSubscriberStatus {
|
|
105
|
+
allowByok: number;
|
|
106
|
+
teamAllowByok?: number;
|
|
107
|
+
isPrivacyPolicyModifiable?: boolean;
|
|
108
|
+
raw?: unknown;
|
|
109
|
+
}
|
|
352
110
|
interface QoderAccountInfo {
|
|
353
111
|
profile: QoderSubscriberProfile;
|
|
354
112
|
usage?: QoderQuotaUsage;
|
|
113
|
+
plan?: QoderSubscriberPlan;
|
|
114
|
+
status?: QoderSubscriberStatus;
|
|
355
115
|
updatedAt: string;
|
|
356
116
|
}
|
|
357
|
-
interface QoderUsageReaderOptions {
|
|
358
|
-
authService: QoderAuthService;
|
|
359
|
-
fetch?: typeof fetch;
|
|
360
|
-
ttlMs?: number;
|
|
361
|
-
timeoutMs?: number;
|
|
362
|
-
resolveRegion?: () => QoderRegion;
|
|
363
|
-
region?: QoderRegion;
|
|
364
|
-
logger?: QoderLogger;
|
|
365
|
-
}
|
|
366
|
-
declare class QoderUsageReader {
|
|
367
|
-
private readonly authService;
|
|
368
|
-
private readonly fetchImpl;
|
|
369
|
-
private readonly ttlMs;
|
|
370
|
-
private readonly timeoutMs;
|
|
371
|
-
private readonly resolveRegion?;
|
|
372
|
-
private region?;
|
|
373
|
-
private readonly logger?;
|
|
374
|
-
private readonly cache;
|
|
375
|
-
constructor(options: QoderUsageReaderOptions);
|
|
376
|
-
setRegion(region: QoderRegion): void;
|
|
377
|
-
currentRegion(): QoderRegion;
|
|
378
|
-
readAccount(pat: string, options?: {
|
|
379
|
-
force?: boolean;
|
|
380
|
-
signal?: AbortSignal;
|
|
381
|
-
region?: QoderRegion;
|
|
382
|
-
}): Promise<QoderAccountInfo>;
|
|
383
|
-
clear(pat?: string): void;
|
|
384
|
-
private fetchUsage;
|
|
385
|
-
}
|
|
386
|
-
//#endregion
|
|
387
|
-
//#region src/index.d.ts
|
|
388
|
-
declare const name = "provider-qoder";
|
|
389
|
-
declare const inject: string[];
|
|
390
|
-
interface Config {
|
|
391
|
-
region?: QoderRegion;
|
|
392
|
-
models?: QoderCatalogModel[];
|
|
393
|
-
streamIdleTimeoutMs?: number;
|
|
394
|
-
}
|
|
395
|
-
declare const Config: z<Config>;
|
|
396
|
-
declare function apply(ctx: Context, config?: Config): void;
|
|
397
117
|
//#endregion
|
|
398
|
-
export { Config,
|
|
118
|
+
export { Config, type QoderAccountInfo, type QoderCatalogModel, type QoderModelsByRegion, type QoderRegion, apply, inject, name };
|