dsh-provider-qoder 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.
- package/LICENSE +21 -0
- package/README.md +115 -0
- package/README_CN.md +115 -0
- package/cordis.patch.yml +4 -0
- package/lib/client.js +944 -0
- package/lib/index.d.ts +398 -0
- package/lib/index.js +1778 -0
- package/lib/invariant.d.ts +15 -0
- package/lib/invariant.js +15 -0
- package/package.json +103 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
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
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
5
|
+
|
|
6
|
+
//#region src/cosy.d.ts
|
|
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
|
|
82
|
+
interface QoderCatalogModel {
|
|
83
|
+
id: string;
|
|
84
|
+
name: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
contextWindow?: number;
|
|
87
|
+
maxTokens?: number;
|
|
88
|
+
source?: string;
|
|
89
|
+
isReasoning?: boolean;
|
|
90
|
+
supportsEffort?: boolean;
|
|
91
|
+
reasoningEfforts?: Array<{
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
}>;
|
|
96
|
+
defaultReasoningEffort?: string;
|
|
97
|
+
priceFactor?: number;
|
|
98
|
+
contextOptions?: Record<string, {
|
|
99
|
+
tokenCount?: number;
|
|
100
|
+
isDefault?: boolean;
|
|
101
|
+
}>;
|
|
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;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/credential-contract.d.ts
|
|
137
|
+
/** Shared Host/browser contract for the one managed Qoder credential. */
|
|
138
|
+
declare const qoderCredentialRef = "QODER_MANAGED_CREDENTIAL";
|
|
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;
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/errors.d.ts
|
|
159
|
+
declare class QoderLlmError extends LlmError {
|
|
160
|
+
constructor(message: string, code?: string, options?: LlmErrorOptions);
|
|
161
|
+
}
|
|
162
|
+
declare function qoderHttpError(message: string, response: {
|
|
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;
|
|
183
|
+
region?: QoderRegion;
|
|
184
|
+
logger?: QoderLogger;
|
|
185
|
+
}
|
|
186
|
+
declare function fetchQoderModels(credentials: CosyCredentials, options?: FetchQoderModelsOptions): Promise<QoderCatalogModel[]>;
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/types.d.ts
|
|
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;
|
|
324
|
+
}
|
|
325
|
+
declare function parseQoderSse(stream: ReadableStream<Uint8Array>, options?: QoderSseOptions): AsyncGenerator<StreamChunk>;
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/translate.d.ts
|
|
328
|
+
declare function translateTools(tools: readonly ToolSchema[] | undefined): QoderWireTool[];
|
|
329
|
+
declare function validateAndTranslateMessages(messages: readonly Message[], systemPrompt?: string): QoderWireMessage[];
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/usage.d.ts
|
|
332
|
+
interface QoderSubscriberProfile {
|
|
333
|
+
id: string;
|
|
334
|
+
name: string;
|
|
335
|
+
email: string;
|
|
336
|
+
}
|
|
337
|
+
interface QoderQuota {
|
|
338
|
+
total: number;
|
|
339
|
+
used: number;
|
|
340
|
+
remaining: number;
|
|
341
|
+
percentage: number;
|
|
342
|
+
unit: string;
|
|
343
|
+
}
|
|
344
|
+
interface QoderQuotaUsage {
|
|
345
|
+
userQuota?: QoderQuota;
|
|
346
|
+
orgResourcePackage?: QoderQuota;
|
|
347
|
+
totalUsagePercentage?: number;
|
|
348
|
+
isQuotaExceeded?: boolean;
|
|
349
|
+
expiresAt?: string;
|
|
350
|
+
raw?: unknown;
|
|
351
|
+
}
|
|
352
|
+
interface QoderAccountInfo {
|
|
353
|
+
profile: QoderSubscriberProfile;
|
|
354
|
+
usage?: QoderQuotaUsage;
|
|
355
|
+
updatedAt: string;
|
|
356
|
+
}
|
|
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
|
+
//#endregion
|
|
398
|
+
export { Config, CosyCredentials, FetchQoderModelsOptions, QoderAccountInfo, QoderAdapter, QoderAdapterOptions, QoderAuthService, QoderAuthServiceOptions, QoderBusiness, QoderCatalogModel, QoderChatContext, QoderInnerChunk, QoderLlmError, QoderLogger, QoderModelConfig, QoderQuota, QoderQuotaUsage, QoderRegion, QoderRegionEndpoints, QoderSseEnvelope, QoderSseOptions, QoderSubscriberProfile, QoderUsageReader, QoderUsageReaderOptions, QoderWireMessage, QoderWireRequest, QoderWireTool, QoderWireToolCall, apply, buildAuthHeaders, buildQoderRequestBody, computeSigPath, defaultMaxTokens, defaultModels, defaultStreamIdleTimeoutMs, fetchQoderModels, getMachineId, getQoderChatUrl, getQoderExchangeUrl, getQoderModelListUrl, getQoderUsageUrl, getQoderUserInfoUrl, hasSameQoderDiscoveryMetadata, inject, isEnvironmentCredentialSource, managedQoderCredentialRef, mergeQoderDiscoveryMetadata, name, normalizeQoderModels, parseQoderSse, qoderCredentialRef, qoderEncodeBody, qoderGlobalBaseUrl, qoderGlobalOpenApiUrl, qoderHttpError, qoderRegionEndpoints, redactLogPayload, redactLogValue, resolveManagedQoderPat, resolveQoderEndpoints, retryAfterMs, translateTools, validateAndTranslateMessages, validateQoderRequest };
|