@mars-sea/dsh-commandcode-provider 0.11.1 → 0.11.3
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 +32 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/client.js +360 -319
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +80 -2
- package/lib/index.js +658 -29
- package/lib/index.js.map +1 -1
- package/package.json +42 -38
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
|
-
import { GenerateOptions, LlmAdapter, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, ResolvedRetryPolicy, StreamChunk } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import { GenerateOptions, LlmAdapter, LlmImageRequestPricing, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, Message, ResolvedRetryPolicy, StreamChunk } from "@deepseek-ai/dsh-llm";
|
|
3
3
|
import { CredentialRef } from "@deepseek-ai/dsh-credentials";
|
|
4
4
|
import { TypertRemoteService, TypertSchema } from "@deepseek-ai/dsh-typert-protocol";
|
|
5
5
|
import { WebRuntime, WebSearchProvider, WebSearchRequest, WebSearchResult } from "@deepseek-ai/dsh-web";
|
|
6
6
|
import { Context } from "@deepseek-ai/cordis";
|
|
7
|
-
import { AttachmentStore } from "@deepseek-ai/dsh-attachment";
|
|
7
|
+
import { AttachmentStore, ImageAttachmentRef } from "@deepseek-ai/dsh-attachment";
|
|
8
8
|
import { CommandDefinition } from "@deepseek-ai/dsh-commands";
|
|
9
9
|
//#region src/adapter.d.ts
|
|
10
10
|
declare const COMMAND_CODE_CLI_VERSION = "1.54.0";
|
|
@@ -22,6 +22,27 @@ declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
|
22
22
|
declare function projectSlugFromPath(pathName: string): string;
|
|
23
23
|
/** Read a usable Command Code credential from the official CLI auth file. */
|
|
24
24
|
declare function resolveAuthFileApiKey(): string | undefined;
|
|
25
|
+
/** One occurrence's exact request-version byte length, as the core counter wants it. */
|
|
26
|
+
type ImageVersionBytes = (block: {
|
|
27
|
+
attachment: ImageAttachmentRef;
|
|
28
|
+
}) => number;
|
|
29
|
+
/**
|
|
30
|
+
* The installed engine's request-image policy, whichever generation it is.
|
|
31
|
+
*
|
|
32
|
+
* Every member is optional because the two generations never coexist: a
|
|
33
|
+
* ≤0.1.5 engine has only `offloadRequestImagesWithPolicy`, a ≥0.1.6 engine has
|
|
34
|
+
* only the other two. `CORE_IMAGE_POLICY` is the namespace object viewed
|
|
35
|
+
* through this shape, and `surfaceImagePolicy()` is the ONE place that decides
|
|
36
|
+
* which contract this process speaks.
|
|
37
|
+
*/
|
|
38
|
+
interface CoreImagePolicy {
|
|
39
|
+
/** ≤0.1.5: project history under a byte/count budget, adapter-owned and transient. */
|
|
40
|
+
offloadRequestImagesWithPolicy?: (messages: readonly Message[], policy: Record<string, unknown>) => readonly Message[];
|
|
41
|
+
/** ≥0.1.6: render the surface's durable offload marks as placeholder text. */
|
|
42
|
+
projectOffloadedImages?: (messages: readonly Message[], placeholder: (ref: ImageAttachmentRef) => string) => readonly Message[];
|
|
43
|
+
/** ≥0.1.6: how many more leading retained occurrences must be offloaded. */
|
|
44
|
+
requiredImageOffload?: (messages: readonly Message[], budget: Record<string, unknown>, versionBytes: ImageVersionBytes) => number;
|
|
45
|
+
}
|
|
25
46
|
/** Connection facts resolved fresh per request by the plugin entry. */
|
|
26
47
|
interface CommandCodeConnectionOptions {
|
|
27
48
|
/** API base; the Provider API lives under it (`/alpha/generate`, `/provider/v1/chat/completions`, `/provider/v1/models`). */
|
|
@@ -102,6 +123,13 @@ interface CommandCodeAdapterDeps<C extends CommandCodeConnectionOptions = Comman
|
|
|
102
123
|
fetchImpl?: typeof fetch;
|
|
103
124
|
/** Resolve the optional durable attachment service for image input (tests); defaults to none. */
|
|
104
125
|
resolveAttachments?: ResolveAttachments;
|
|
126
|
+
/**
|
|
127
|
+
* Request-image policy override (tests); defaults to the installed engine's
|
|
128
|
+
* own helpers, whichever generation they belong to. Injecting it is the only
|
|
129
|
+
* way to exercise the ≥0.1.6 durable-offload contract while this checkout
|
|
130
|
+
* still compiles against the 0.1.2 peers.
|
|
131
|
+
*/
|
|
132
|
+
imageOffload?: CoreImagePolicy;
|
|
105
133
|
}
|
|
106
134
|
/** Account identity from `/alpha/whoami`. */
|
|
107
135
|
interface CommandCodeAccount {
|
|
@@ -202,6 +230,15 @@ declare class CommandCodeAdapter<C extends CommandCodeConnectionOptions = Comman
|
|
|
202
230
|
private catalog;
|
|
203
231
|
private readonly fetchImpl;
|
|
204
232
|
private readonly resolveAttachments;
|
|
233
|
+
/** The engine's request-image policy, resolved once (tests may inject one). */
|
|
234
|
+
private readonly imagePolicy;
|
|
235
|
+
/**
|
|
236
|
+
* The ≥0.1.6 durable contract, or `undefined` on a ≤0.1.5 engine — where the
|
|
237
|
+
* adapter must evict its own history. Resolved once: the contract a process
|
|
238
|
+
* speaks cannot change while it runs, and resolving here keeps every request
|
|
239
|
+
* on the same branch (see {@link surfaceImagePolicy}).
|
|
240
|
+
*/
|
|
241
|
+
private readonly surfaceOffload;
|
|
205
242
|
private readonly billingAccess;
|
|
206
243
|
private readonly billingAccessInflight;
|
|
207
244
|
private readonly protocolCache;
|
|
@@ -232,6 +269,22 @@ declare class CommandCodeAdapter<C extends CommandCodeConnectionOptions = Comman
|
|
|
232
269
|
* future config knob for it would apply on profile restart, not per request.
|
|
233
270
|
*/
|
|
234
271
|
providerRetryPolicy(_provider: string): ResolvedRetryPolicy;
|
|
272
|
+
/**
|
|
273
|
+
* Visual-token pricing for one exact model route (see `./image-tokens.ts`).
|
|
274
|
+
*
|
|
275
|
+
* Without this the token meter prices EVERY image with its structural
|
|
276
|
+
* heuristic — a handful of tokens for a full screenshot — so an image-heavy
|
|
277
|
+
* session reports far less context than it is actually carrying. The price is
|
|
278
|
+
* computed at the dimensions this route would send (the same request target
|
|
279
|
+
* `readImageRequest` encodes to), so the estimate tracks the wire rather than
|
|
280
|
+
* the stored original.
|
|
281
|
+
*
|
|
282
|
+
* Both payload generations are handled, because they disagree: ≤0.1.5 hands
|
|
283
|
+
* over bare `ImageAttachmentRef`s, ≥0.1.6 hands over `ImageBlock`s that also
|
|
284
|
+
* carry the surface's `offloaded` mark. Returning a price per occurrence, in
|
|
285
|
+
* order, is a hard requirement — the meter throws when the counts differ.
|
|
286
|
+
*/
|
|
287
|
+
imageRequestPricing(_provider: string, model: string): LlmImageRequestPricing | undefined;
|
|
235
288
|
/** Refresh the catalog (live fetch, cache fallback) and return it. */
|
|
236
289
|
private loadCatalog;
|
|
237
290
|
listModels(provider: string, opts?: {
|
|
@@ -274,6 +327,19 @@ declare class CommandCodeAdapter<C extends CommandCodeConnectionOptions = Comman
|
|
|
274
327
|
* wins; otherwise a cached (not network-fetched) billing tier of Go is
|
|
275
328
|
* treated as CLI-only. Unknown accounts default to Provider API and fall
|
|
276
329
|
* back only after an `upgrade_required` rejection.
|
|
330
|
+
*
|
|
331
|
+
* Models the Provider API serves ONLY through `/provider/v1/messages` (the
|
|
332
|
+
* Claude family — `requiresMessagesEndpoint()`) always take the CLI
|
|
333
|
+
* transport, on any tier and even under a forced `'openai'` preference:
|
|
334
|
+
* that option is documented as "prefer the Provider API, still fall back",
|
|
335
|
+
* and the 400 these models answer with is not a preference to be honoured
|
|
336
|
+
* but a hard refusal. `/alpha/generate` routes every one of them, so this
|
|
337
|
+
* costs nothing.
|
|
338
|
+
*
|
|
339
|
+
* That decision is deliberately NOT written to `protocolCache`. The cache is
|
|
340
|
+
* keyed by API key alone, so remembering it would pin the whole ACCOUNT to
|
|
341
|
+
* the CLI transport and drag every other model — DeepSeek, GLM, Qwen, all of
|
|
342
|
+
* which the Provider API serves correctly — off it until the entry expired.
|
|
277
343
|
*/
|
|
278
344
|
private resolveProtocol;
|
|
279
345
|
/**
|
|
@@ -1491,6 +1557,18 @@ interface Config {
|
|
|
1491
1557
|
requestTimeoutMs?: number;
|
|
1492
1558
|
/** Milliseconds a stream may stall before being treated as a dead connection; defaults to 300s. */
|
|
1493
1559
|
streamIdleTimeoutMs?: number;
|
|
1560
|
+
/**
|
|
1561
|
+
* Transport failures one request absorbs before the failure is surfaced;
|
|
1562
|
+
* defaults to 5. The route's retry policy is near-unbounded on purpose (1000
|
|
1563
|
+
* attempts, waits doubling to 15 minutes) because that shape is for the
|
|
1564
|
+
* failures a provider asks to have retried — an exhausted rate-limit window,
|
|
1565
|
+
* a gateway 520. A transport failure is not one of those: the first attempts
|
|
1566
|
+
* recover an ordinary blip (the default 5 retries are scheduled 0.5/1/2/4/8 s
|
|
1567
|
+
* after the failures before them, so ~15.5 s of grace), and after that the
|
|
1568
|
+
* wait is pure stall, so the retries are capped here. Raise it on a genuinely
|
|
1569
|
+
* flaky link; 0 surfaces every transport failure immediately.
|
|
1570
|
+
*/
|
|
1571
|
+
transportMaxRetries?: number;
|
|
1494
1572
|
/**
|
|
1495
1573
|
* Whether the model picker hides models above the account's subscription
|
|
1496
1574
|
* tier; defaults to true. The filter fails open (unknown plan, billing
|