dsh-any-deepseek 0.0.31 → 0.0.33
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/lib/adapter.d.ts +85 -1
- package/lib/index.js +74 -4
- package/package.json +1 -1
package/lib/adapter.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* single point of failure for model traffic.
|
|
25
25
|
*/
|
|
26
26
|
import { LlmAdapter } from '@deepseek-ai/dsh-llm';
|
|
27
|
-
import type { GenerateOptions, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, PreparedAdapterCall, StreamChunk, TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
27
|
+
import type { GenerateOptions, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, PreparedAdapterCall, ResolvedRetryPolicy, StreamChunk, TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
28
28
|
import { credentialRef } from '@deepseek-ai/dsh-credentials';
|
|
29
29
|
import { type Api, type AssistantMessage, type AssistantMessageEvent, type Context as PiContext, type Model } from '@earendil-works/pi-ai';
|
|
30
30
|
import { openAICompletionsApi } from '@earendil-works/pi-ai/api/openai-completions.lazy';
|
|
@@ -55,6 +55,51 @@ export declare const PROVIDER_NAME = "Any DeepSeek";
|
|
|
55
55
|
* model's.
|
|
56
56
|
*/
|
|
57
57
|
export declare const MODEL_INPUT_MODALITIES: readonly ChannelModality[];
|
|
58
|
+
/**
|
|
59
|
+
* Retry budget this provider asks the harness to use, per request.
|
|
60
|
+
*
|
|
61
|
+
* ## Why the provider owns this number at all
|
|
62
|
+
*
|
|
63
|
+
* The harness stores one retry policy **per registered route**, captured at registration
|
|
64
|
+
* (`dsh-llm/lib/index.js:1876`: `adapter.providerRetryPolicy(provider) ?? resolveRetryPolicy(undefined, …)`),
|
|
65
|
+
* and hands it to the `agent/request-error` waterfall on every failed attempt
|
|
66
|
+
* (`dsh-agent-loop/lib/index.js:934`). The `dsh-llm-retry` plugin is the consumer that acts on it.
|
|
67
|
+
* An adapter that does not override `providerRetryPolicy` gets the host default —
|
|
68
|
+
* **5 retries** (`dsh-llm/lib/types/retry-policy.js:12`).
|
|
69
|
+
*
|
|
70
|
+
* Owner request (2026-11-10): 「把 dsh 的模型调用重试 patch 到 100」. Behind a relay that returns
|
|
71
|
+
* intermittent 5xx (e.g. the upstream `workspace_billing_scope_unavailable` that motivated 0.0.32),
|
|
72
|
+
* five attempts can all land inside one outage window and the turn dies. A larger budget costs
|
|
73
|
+
* nothing when the relay is healthy — the policy is only consulted after a failure.
|
|
74
|
+
*
|
|
75
|
+
* ## What this deliberately does NOT change
|
|
76
|
+
*
|
|
77
|
+
* `retryableCodes`, `backoff` and `mode` stay at the host's values. Raising only the COUNT keeps
|
|
78
|
+
* the failure taxonomy exactly as the host defines it: auth and quota are still not retried, and
|
|
79
|
+
* `CONTEXT_WINDOW_EXCEEDED` still never retries (0.0.32's whole point). A policy that widened the
|
|
80
|
+
* code set would be this plugin deciding which failures are recoverable — it does not get to.
|
|
81
|
+
*
|
|
82
|
+
* ⚠️ **This is a request, not a guarantee**: the policy reaches `dsh-llm-retry` through the host's
|
|
83
|
+
* registration, so an installation without that plugin simply ignores it (still one attempt per
|
|
84
|
+
* stream, as `dsh-llm` documents).
|
|
85
|
+
*/
|
|
86
|
+
export declare const PROVIDER_MAX_RETRIES = 100;
|
|
87
|
+
/**
|
|
88
|
+
* The resolved retry policy this route registers.
|
|
89
|
+
*
|
|
90
|
+
* ⚠️ **The backoff fields are FLAT here, not nested under `backoff`.** The host's INPUT shape
|
|
91
|
+
* (`RetryPolicyConfig`) nests them, but its RESOLVED shape does not:
|
|
92
|
+
* `ResolvedNormalRetryPolicy extends ResolvedRetryBackoff` (`dsh-llm/lib/types/retry-policy.d.ts:46-50`),
|
|
93
|
+
* so the policy a `providerRetryPolicy()` implementation returns carries
|
|
94
|
+
* `initialDelayMs` / `maxDelayMs` / `jitterRatio` as siblings of `mode` and `maxRetries`. The
|
|
95
|
+
* distinction is only visible because TypeScript rejected the nested form — worth pinning here so
|
|
96
|
+
* the next reader does not "tidy" it back into a nested object that silently fails to typecheck
|
|
97
|
+
* (and, in a JavaScript build, would silently fall back to defaults instead).
|
|
98
|
+
*
|
|
99
|
+
* Values mirror `dsh-llm/lib/types/retry-policy.js:13-22` exactly; if the host changes those
|
|
100
|
+
* defaults, this stays pinned to what it says rather than silently following.
|
|
101
|
+
*/
|
|
102
|
+
export declare const PROVIDER_RETRY_POLICY: ResolvedRetryPolicy;
|
|
58
103
|
/**
|
|
59
104
|
* The reasoning levels in force for one channel.
|
|
60
105
|
*
|
|
@@ -232,6 +277,36 @@ export declare function toStreamChunks(events: AsyncIterable<AssistantMessageEve
|
|
|
232
277
|
*
|
|
233
278
|
* The harness routes retries on these codes, so the mapping matters more than the message. A
|
|
234
279
|
* relay's own wording is preserved in the message; only the class is normalized here.
|
|
280
|
+
*
|
|
281
|
+
* ## 🔴 Why this delegates overflow detection instead of writing its own rule
|
|
282
|
+
*
|
|
283
|
+
* This used to be `text.includes('context') && (… includes('exceed'))`. That is a CROSS-WORD test:
|
|
284
|
+
* any sentence containing both words matches, and `CONTEXT_WINDOW_EXCEEDED` is not an ordinary
|
|
285
|
+
* error code — the harness treats it as proof that the request genuinely overflowed and answers
|
|
286
|
+
* with the destructive recovery path (`compactIfNeeded(…, 'context-overflow')`, which compacts
|
|
287
|
+
* the whole range with retain=0 and SKIPS the context threshold). Measured consequence
|
|
288
|
+
* (2026-11-10, reported by S142): an upstream `503 … context deadline exceeded (Client.Timeout
|
|
289
|
+
* exceeded while awaiting headers)` — a Go HTTP timeout, unrelated to context — was classified as
|
|
290
|
+
* overflow, and the host compacted a ~119K-token conversation three times in one turn against a
|
|
291
|
+
* 1M window and an 800K threshold.
|
|
292
|
+
*
|
|
293
|
+
* ⇒ The rule is NOT "tighten the substring" but **use the authority**. The host already ships
|
|
294
|
+
* `isContextWindowExceededError` (`@deepseek-ai/dsh-llm`), which recognises only wording that
|
|
295
|
+
* names a context bound (`context length exceeded`, `maximum context window`, `too large for the
|
|
296
|
+
* model context`, …) and is the same predicate the official adapters route on. Re-implementing it
|
|
297
|
+
* here would drift from the harness on the next upstream wording — and drift in THIS direction
|
|
298
|
+
* deletes conversation history rather than costing a retry.
|
|
299
|
+
*
|
|
300
|
+
* ## The asymmetry that orders the checks
|
|
301
|
+
*
|
|
302
|
+
* Classifying too much as `SERVER` costs a retry. Classifying too much as
|
|
303
|
+
* `CONTEXT_WINDOW_EXCEEDED` costs data. So every other test runs FIRST and overflow is last: a
|
|
304
|
+
* credential/quota/rate-limit sentence never reaches it, and an unrecognised 5xx lands on `SERVER`.
|
|
305
|
+
*
|
|
306
|
+
* The host's own adapter orders them the other way (`status >= 500` checked last, after the
|
|
307
|
+
* wording test — `dsh-llm-deepseek/lib/index.js:1779-1781`). We deliberately invert that: for the
|
|
308
|
+
* official adapter the wording rule is precise enough to be safe; ours used to be a substring, so
|
|
309
|
+
* the cheap-first ordering is what makes the failure mode one retry instead of one deletion.
|
|
235
310
|
* @param message - the terminal pi-ai message.
|
|
236
311
|
* @returns a harness failure code.
|
|
237
312
|
*/
|
|
@@ -243,6 +318,15 @@ export declare class AnyDeepSeekAdapter extends LlmAdapter {
|
|
|
243
318
|
private readonly deps;
|
|
244
319
|
constructor(deps: AdapterDeps);
|
|
245
320
|
providerInfo(provider: string): LlmProviderInfo;
|
|
321
|
+
/**
|
|
322
|
+
* The retry budget this route asks the harness to use.
|
|
323
|
+
*
|
|
324
|
+
* 🔴 Without this override the host substitutes its own default (5 retries) — and the failure is
|
|
325
|
+
* completely silent: requests still work, they just give up sooner. See
|
|
326
|
+
* {@link PROVIDER_RETRY_POLICY} for why 100 and what is deliberately left untouched.
|
|
327
|
+
* @returns the frozen policy captured at registration.
|
|
328
|
+
*/
|
|
329
|
+
providerRetryPolicy(_provider: string): ResolvedRetryPolicy;
|
|
246
330
|
/**
|
|
247
331
|
* Advertise exactly one model — **unconditionally**.
|
|
248
332
|
*
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
|
-
import { LlmAdapter, ReasoningEffortId, ToolCallId } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { LlmAdapter, ReasoningEffortId, ToolCallId, isContextWindowExceededError } from "@deepseek-ai/dsh-llm";
|
|
4
4
|
import "@deepseek-ai/dsh-credentials";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { createModels, createProvider } from "@earendil-works/pi-ai";
|
|
@@ -804,6 +804,35 @@ const PROVIDER_NAME = "Any DeepSeek";
|
|
|
804
804
|
*/
|
|
805
805
|
const MODEL_INPUT_MODALITIES = V41_FLASH_CAPS.input;
|
|
806
806
|
/**
|
|
807
|
+
* The resolved retry policy this route registers.
|
|
808
|
+
*
|
|
809
|
+
* ⚠️ **The backoff fields are FLAT here, not nested under `backoff`.** The host's INPUT shape
|
|
810
|
+
* (`RetryPolicyConfig`) nests them, but its RESOLVED shape does not:
|
|
811
|
+
* `ResolvedNormalRetryPolicy extends ResolvedRetryBackoff` (`dsh-llm/lib/types/retry-policy.d.ts:46-50`),
|
|
812
|
+
* so the policy a `providerRetryPolicy()` implementation returns carries
|
|
813
|
+
* `initialDelayMs` / `maxDelayMs` / `jitterRatio` as siblings of `mode` and `maxRetries`. The
|
|
814
|
+
* distinction is only visible because TypeScript rejected the nested form — worth pinning here so
|
|
815
|
+
* the next reader does not "tidy" it back into a nested object that silently fails to typecheck
|
|
816
|
+
* (and, in a JavaScript build, would silently fall back to defaults instead).
|
|
817
|
+
*
|
|
818
|
+
* Values mirror `dsh-llm/lib/types/retry-policy.js:13-22` exactly; if the host changes those
|
|
819
|
+
* defaults, this stays pinned to what it says rather than silently following.
|
|
820
|
+
*/
|
|
821
|
+
const PROVIDER_RETRY_POLICY = Object.freeze({
|
|
822
|
+
mode: "normal",
|
|
823
|
+
maxRetries: 100,
|
|
824
|
+
retryableCodes: Object.freeze([
|
|
825
|
+
"EMPTY_RESPONSE",
|
|
826
|
+
"RATE_LIMIT",
|
|
827
|
+
"SERVER",
|
|
828
|
+
"TIMEOUT",
|
|
829
|
+
"TRANSPORT"
|
|
830
|
+
]),
|
|
831
|
+
initialDelayMs: 500,
|
|
832
|
+
maxDelayMs: 1e4,
|
|
833
|
+
jitterRatio: .1
|
|
834
|
+
});
|
|
835
|
+
/**
|
|
807
836
|
* The reasoning levels in force for one channel.
|
|
808
837
|
*
|
|
809
838
|
* 🔴 **A channel that says nothing inherits the model's table, and that is the whole fix for the
|
|
@@ -1328,16 +1357,46 @@ function finishReason(reason) {
|
|
|
1328
1357
|
*
|
|
1329
1358
|
* The harness routes retries on these codes, so the mapping matters more than the message. A
|
|
1330
1359
|
* relay's own wording is preserved in the message; only the class is normalized here.
|
|
1360
|
+
*
|
|
1361
|
+
* ## 🔴 Why this delegates overflow detection instead of writing its own rule
|
|
1362
|
+
*
|
|
1363
|
+
* This used to be `text.includes('context') && (… includes('exceed'))`. That is a CROSS-WORD test:
|
|
1364
|
+
* any sentence containing both words matches, and `CONTEXT_WINDOW_EXCEEDED` is not an ordinary
|
|
1365
|
+
* error code — the harness treats it as proof that the request genuinely overflowed and answers
|
|
1366
|
+
* with the destructive recovery path (`compactIfNeeded(…, 'context-overflow')`, which compacts
|
|
1367
|
+
* the whole range with retain=0 and SKIPS the context threshold). Measured consequence
|
|
1368
|
+
* (2026-11-10, reported by S142): an upstream `503 … context deadline exceeded (Client.Timeout
|
|
1369
|
+
* exceeded while awaiting headers)` — a Go HTTP timeout, unrelated to context — was classified as
|
|
1370
|
+
* overflow, and the host compacted a ~119K-token conversation three times in one turn against a
|
|
1371
|
+
* 1M window and an 800K threshold.
|
|
1372
|
+
*
|
|
1373
|
+
* ⇒ The rule is NOT "tighten the substring" but **use the authority**. The host already ships
|
|
1374
|
+
* `isContextWindowExceededError` (`@deepseek-ai/dsh-llm`), which recognises only wording that
|
|
1375
|
+
* names a context bound (`context length exceeded`, `maximum context window`, `too large for the
|
|
1376
|
+
* model context`, …) and is the same predicate the official adapters route on. Re-implementing it
|
|
1377
|
+
* here would drift from the harness on the next upstream wording — and drift in THIS direction
|
|
1378
|
+
* deletes conversation history rather than costing a retry.
|
|
1379
|
+
*
|
|
1380
|
+
* ## The asymmetry that orders the checks
|
|
1381
|
+
*
|
|
1382
|
+
* Classifying too much as `SERVER` costs a retry. Classifying too much as
|
|
1383
|
+
* `CONTEXT_WINDOW_EXCEEDED` costs data. So every other test runs FIRST and overflow is last: a
|
|
1384
|
+
* credential/quota/rate-limit sentence never reaches it, and an unrecognised 5xx lands on `SERVER`.
|
|
1385
|
+
*
|
|
1386
|
+
* The host's own adapter orders them the other way (`status >= 500` checked last, after the
|
|
1387
|
+
* wording test — `dsh-llm-deepseek/lib/index.js:1779-1781`). We deliberately invert that: for the
|
|
1388
|
+
* official adapter the wording rule is precise enough to be safe; ours used to be a substring, so
|
|
1389
|
+
* the cheap-first ordering is what makes the failure mode one retry instead of one deletion.
|
|
1331
1390
|
* @param message - the terminal pi-ai message.
|
|
1332
1391
|
* @returns a harness failure code.
|
|
1333
1392
|
*/
|
|
1334
1393
|
function classifyFailure(message) {
|
|
1335
|
-
const text = `${message.errorMessage ?? ""} ${message.rawStopReason ?? ""}`.toLowerCase();
|
|
1336
1394
|
if (message.stopReason === "aborted") return "ABORTED";
|
|
1337
|
-
|
|
1395
|
+
const text = `${message.errorMessage ?? ""} ${message.rawStopReason ?? ""}`.toLowerCase();
|
|
1396
|
+
if (text.includes("401") || text.includes("403") || text.includes("unauthor") || text.includes("invalid api key")) return "AUTH";
|
|
1338
1397
|
if (text.includes("rate") && text.includes("limit")) return "RATE_LIMIT";
|
|
1339
1398
|
if (text.includes("quota") || text.includes("balance") || text.includes("credit")) return "QUOTA";
|
|
1340
|
-
if (
|
|
1399
|
+
if (isContextWindowExceededError(text)) return "CONTEXT_WINDOW_EXCEEDED";
|
|
1341
1400
|
return "SERVER";
|
|
1342
1401
|
}
|
|
1343
1402
|
/**
|
|
@@ -1356,6 +1415,17 @@ var AnyDeepSeekAdapter = class extends LlmAdapter {
|
|
|
1356
1415
|
};
|
|
1357
1416
|
}
|
|
1358
1417
|
/**
|
|
1418
|
+
* The retry budget this route asks the harness to use.
|
|
1419
|
+
*
|
|
1420
|
+
* 🔴 Without this override the host substitutes its own default (5 retries) — and the failure is
|
|
1421
|
+
* completely silent: requests still work, they just give up sooner. See
|
|
1422
|
+
* {@link PROVIDER_RETRY_POLICY} for why 100 and what is deliberately left untouched.
|
|
1423
|
+
* @returns the frozen policy captured at registration.
|
|
1424
|
+
*/
|
|
1425
|
+
providerRetryPolicy(_provider) {
|
|
1426
|
+
return PROVIDER_RETRY_POLICY;
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1359
1429
|
* Advertise exactly one model — **unconditionally**.
|
|
1360
1430
|
*
|
|
1361
1431
|
* 🔴 **This used to require a resolvable key, and that was wrong.**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-any-deepseek",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "One DeepSeek V4.1 Flash provider for DeepSeek Harness: paste a key per channel, switch channels manually, token usage booked per real upstream.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|