dsh-any-deepseek 0.0.31 → 0.0.32
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 +30 -0
- package/lib/index.js +34 -4
- package/package.json +1 -1
package/lib/adapter.d.ts
CHANGED
|
@@ -232,6 +232,36 @@ export declare function toStreamChunks(events: AsyncIterable<AssistantMessageEve
|
|
|
232
232
|
*
|
|
233
233
|
* The harness routes retries on these codes, so the mapping matters more than the message. A
|
|
234
234
|
* relay's own wording is preserved in the message; only the class is normalized here.
|
|
235
|
+
*
|
|
236
|
+
* ## 🔴 Why this delegates overflow detection instead of writing its own rule
|
|
237
|
+
*
|
|
238
|
+
* This used to be `text.includes('context') && (… includes('exceed'))`. That is a CROSS-WORD test:
|
|
239
|
+
* any sentence containing both words matches, and `CONTEXT_WINDOW_EXCEEDED` is not an ordinary
|
|
240
|
+
* error code — the harness treats it as proof that the request genuinely overflowed and answers
|
|
241
|
+
* with the destructive recovery path (`compactIfNeeded(…, 'context-overflow')`, which compacts
|
|
242
|
+
* the whole range with retain=0 and SKIPS the context threshold). Measured consequence
|
|
243
|
+
* (2026-11-10, reported by S142): an upstream `503 … context deadline exceeded (Client.Timeout
|
|
244
|
+
* exceeded while awaiting headers)` — a Go HTTP timeout, unrelated to context — was classified as
|
|
245
|
+
* overflow, and the host compacted a ~119K-token conversation three times in one turn against a
|
|
246
|
+
* 1M window and an 800K threshold.
|
|
247
|
+
*
|
|
248
|
+
* ⇒ The rule is NOT "tighten the substring" but **use the authority**. The host already ships
|
|
249
|
+
* `isContextWindowExceededError` (`@deepseek-ai/dsh-llm`), which recognises only wording that
|
|
250
|
+
* names a context bound (`context length exceeded`, `maximum context window`, `too large for the
|
|
251
|
+
* model context`, …) and is the same predicate the official adapters route on. Re-implementing it
|
|
252
|
+
* here would drift from the harness on the next upstream wording — and drift in THIS direction
|
|
253
|
+
* deletes conversation history rather than costing a retry.
|
|
254
|
+
*
|
|
255
|
+
* ## The asymmetry that orders the checks
|
|
256
|
+
*
|
|
257
|
+
* Classifying too much as `SERVER` costs a retry. Classifying too much as
|
|
258
|
+
* `CONTEXT_WINDOW_EXCEEDED` costs data. So every other test runs FIRST and overflow is last: a
|
|
259
|
+
* credential/quota/rate-limit sentence never reaches it, and an unrecognised 5xx lands on `SERVER`.
|
|
260
|
+
*
|
|
261
|
+
* The host's own adapter orders them the other way (`status >= 500` checked last, after the
|
|
262
|
+
* wording test — `dsh-llm-deepseek/lib/index.js:1779-1781`). We deliberately invert that: for the
|
|
263
|
+
* official adapter the wording rule is precise enough to be safe; ours used to be a substring, so
|
|
264
|
+
* the cheap-first ordering is what makes the failure mode one retry instead of one deletion.
|
|
235
265
|
* @param message - the terminal pi-ai message.
|
|
236
266
|
* @returns a harness failure code.
|
|
237
267
|
*/
|
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";
|
|
@@ -1328,16 +1328,46 @@ function finishReason(reason) {
|
|
|
1328
1328
|
*
|
|
1329
1329
|
* The harness routes retries on these codes, so the mapping matters more than the message. A
|
|
1330
1330
|
* relay's own wording is preserved in the message; only the class is normalized here.
|
|
1331
|
+
*
|
|
1332
|
+
* ## 🔴 Why this delegates overflow detection instead of writing its own rule
|
|
1333
|
+
*
|
|
1334
|
+
* This used to be `text.includes('context') && (… includes('exceed'))`. That is a CROSS-WORD test:
|
|
1335
|
+
* any sentence containing both words matches, and `CONTEXT_WINDOW_EXCEEDED` is not an ordinary
|
|
1336
|
+
* error code — the harness treats it as proof that the request genuinely overflowed and answers
|
|
1337
|
+
* with the destructive recovery path (`compactIfNeeded(…, 'context-overflow')`, which compacts
|
|
1338
|
+
* the whole range with retain=0 and SKIPS the context threshold). Measured consequence
|
|
1339
|
+
* (2026-11-10, reported by S142): an upstream `503 … context deadline exceeded (Client.Timeout
|
|
1340
|
+
* exceeded while awaiting headers)` — a Go HTTP timeout, unrelated to context — was classified as
|
|
1341
|
+
* overflow, and the host compacted a ~119K-token conversation three times in one turn against a
|
|
1342
|
+
* 1M window and an 800K threshold.
|
|
1343
|
+
*
|
|
1344
|
+
* ⇒ The rule is NOT "tighten the substring" but **use the authority**. The host already ships
|
|
1345
|
+
* `isContextWindowExceededError` (`@deepseek-ai/dsh-llm`), which recognises only wording that
|
|
1346
|
+
* names a context bound (`context length exceeded`, `maximum context window`, `too large for the
|
|
1347
|
+
* model context`, …) and is the same predicate the official adapters route on. Re-implementing it
|
|
1348
|
+
* here would drift from the harness on the next upstream wording — and drift in THIS direction
|
|
1349
|
+
* deletes conversation history rather than costing a retry.
|
|
1350
|
+
*
|
|
1351
|
+
* ## The asymmetry that orders the checks
|
|
1352
|
+
*
|
|
1353
|
+
* Classifying too much as `SERVER` costs a retry. Classifying too much as
|
|
1354
|
+
* `CONTEXT_WINDOW_EXCEEDED` costs data. So every other test runs FIRST and overflow is last: a
|
|
1355
|
+
* credential/quota/rate-limit sentence never reaches it, and an unrecognised 5xx lands on `SERVER`.
|
|
1356
|
+
*
|
|
1357
|
+
* The host's own adapter orders them the other way (`status >= 500` checked last, after the
|
|
1358
|
+
* wording test — `dsh-llm-deepseek/lib/index.js:1779-1781`). We deliberately invert that: for the
|
|
1359
|
+
* official adapter the wording rule is precise enough to be safe; ours used to be a substring, so
|
|
1360
|
+
* the cheap-first ordering is what makes the failure mode one retry instead of one deletion.
|
|
1331
1361
|
* @param message - the terminal pi-ai message.
|
|
1332
1362
|
* @returns a harness failure code.
|
|
1333
1363
|
*/
|
|
1334
1364
|
function classifyFailure(message) {
|
|
1335
|
-
const text = `${message.errorMessage ?? ""} ${message.rawStopReason ?? ""}`.toLowerCase();
|
|
1336
1365
|
if (message.stopReason === "aborted") return "ABORTED";
|
|
1337
|
-
|
|
1366
|
+
const text = `${message.errorMessage ?? ""} ${message.rawStopReason ?? ""}`.toLowerCase();
|
|
1367
|
+
if (text.includes("401") || text.includes("403") || text.includes("unauthor") || text.includes("invalid api key")) return "AUTH";
|
|
1338
1368
|
if (text.includes("rate") && text.includes("limit")) return "RATE_LIMIT";
|
|
1339
1369
|
if (text.includes("quota") || text.includes("balance") || text.includes("credit")) return "QUOTA";
|
|
1340
|
-
if (
|
|
1370
|
+
if (isContextWindowExceededError(text)) return "CONTEXT_WINDOW_EXCEEDED";
|
|
1341
1371
|
return "SERVER";
|
|
1342
1372
|
}
|
|
1343
1373
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-any-deepseek",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
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": {
|