@molecule/api-ai-deepseek 1.1.1 → 1.1.2
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/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +57 -2
- package/package.json +2 -2
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EACV,UAAU,EAIV,SAAS,EAET,UAAU,EAEV,cAAc,EACd,uBAAuB,EAGxB,MAAM,kBAAkB,CAAA;AASzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EACV,UAAU,EAIV,SAAS,EAET,UAAU,EAEV,cAAc,EACd,uBAAuB,EAGxB,MAAM,kBAAkB,CAAA;AASzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AA2IhD,8DAA8D;AAC9D,eAAO,MAAM,8BAA8B,QAAS,CAAA;AA8MpD;;;;GAIG;AACH,cAAM,sBAAuB,YAAW,UAAU;IAChD,QAAQ,CAAC,IAAI,cAAa;IAC1B,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,WAAW,CAAC,CAAqB;IACzC,OAAO,CAAC,aAAa,CAAC,CAAuB;IAC7C,OAAO,CAAC,mBAAmB,CAAQ;IACnC,OAAO,CAAC,sBAAsB,CAAQ;gBAE1B,MAAM,GAAE,cAAmB;IAwBvC;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC;IA4TzD;;;;;;;;;;;;;;;;;;OAkBG;IACH,wBAAwB,CAAC,KAAK,EAAE,cAAc,GAAG,uBAAuB;IAQxE;;;;;;;;;OASG;YACW,2BAA2B;IAiIzC;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IA2BzB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,cAAc;IA8FtB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAWnB;;;;;OAKG;IACH,OAAO,CAAE,yBAAyB;IA+ElC;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU;IAUlB;;;;;;;;;;;;OAYG;YACY,sBAAsB;IA2GrC;;;;;;;;;;OAUG;IACH,OAAO,CAAE,eAAe;CAwOzB;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,+BAAyB,CAAA;AAExD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,UAAU,CAElE"}
|
package/dist/provider.js
CHANGED
|
@@ -30,6 +30,33 @@ import './secrets.js';
|
|
|
30
30
|
function budgetToEffort(budgetTokens) {
|
|
31
31
|
return budgetTokens >= 12_000 ? 'max' : 'high';
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Read the upstream's explanation from a rejected response body: its error
|
|
35
|
+
* `type` (or `code`) and `message`, the message bounded to 500 characters.
|
|
36
|
+
*
|
|
37
|
+
* @param text - The rejected response's body text.
|
|
38
|
+
* @returns The upstream error, or `undefined` when the body carried neither field.
|
|
39
|
+
*/
|
|
40
|
+
function parseUpstreamError(text) {
|
|
41
|
+
let error;
|
|
42
|
+
try {
|
|
43
|
+
error = JSON.parse(text)?.error;
|
|
44
|
+
}
|
|
45
|
+
catch (_error) {
|
|
46
|
+
// Not JSON (a proxy's error page, plain text): a short body is the message itself.
|
|
47
|
+
const trimmed = text.trim();
|
|
48
|
+
return trimmed && trimmed.length <= 500 ? { message: trimmed } : undefined;
|
|
49
|
+
}
|
|
50
|
+
const type = typeof error?.type === 'string'
|
|
51
|
+
? error.type
|
|
52
|
+
: typeof error?.code === 'string'
|
|
53
|
+
? error.code
|
|
54
|
+
: undefined;
|
|
55
|
+
const message = typeof error?.message === 'string' ? error.message.slice(0, 500) : undefined;
|
|
56
|
+
if (!type && !message)
|
|
57
|
+
return undefined;
|
|
58
|
+
return { ...(type ? { type } : {}), ...(message ? { message } : {}) };
|
|
59
|
+
}
|
|
33
60
|
/** How long a stream may wait for its first content event. */
|
|
34
61
|
export const DEFAULT_FIRST_TOKEN_TIMEOUT_MS = 45_000;
|
|
35
62
|
/** How long a stream that HAS started may go without a single byte. */
|
|
@@ -387,6 +414,9 @@ class DeepseekAIProviderImpl {
|
|
|
387
414
|
try {
|
|
388
415
|
let response;
|
|
389
416
|
let requestSentAt = 0;
|
|
417
|
+
// Set when the dispatch's retry loop already read the rejected 429/503
|
|
418
|
+
// body; the `!response.ok` path reuses it instead of a second read.
|
|
419
|
+
let rejectedBody;
|
|
390
420
|
try {
|
|
391
421
|
const dispatched = await this.requestWithRateLimitRetries({
|
|
392
422
|
body,
|
|
@@ -403,6 +433,7 @@ class DeepseekAIProviderImpl {
|
|
|
403
433
|
});
|
|
404
434
|
response = dispatched.response;
|
|
405
435
|
requestSentAt = dispatched.sentAt;
|
|
436
|
+
rejectedBody = dispatched.rejectedBody;
|
|
406
437
|
}
|
|
407
438
|
catch (error) {
|
|
408
439
|
if (!(error instanceof FirstTokenHeaderTimeoutError) || params.signal?.aborted)
|
|
@@ -436,7 +467,9 @@ class DeepseekAIProviderImpl {
|
|
|
436
467
|
if (traceId)
|
|
437
468
|
call.meta.traceId = traceId;
|
|
438
469
|
if (!response.ok) {
|
|
439
|
-
|
|
470
|
+
// A 429/503 body was already read by the retry loop inside the
|
|
471
|
+
// dispatch; a body reads only once, so reuse that text.
|
|
472
|
+
const errorBody = rejectedBody ?? (await response.text());
|
|
440
473
|
let detail = `HTTP ${response.status}`;
|
|
441
474
|
try {
|
|
442
475
|
const parsed = JSON.parse(errorBody);
|
|
@@ -604,7 +637,13 @@ class DeepseekAIProviderImpl {
|
|
|
604
637
|
const MAX_RETRIES = 3;
|
|
605
638
|
let response = null;
|
|
606
639
|
let sentAt = 0;
|
|
640
|
+
// The rejected body already read by this loop, when the final attempt ended
|
|
641
|
+
// on a 429/503: a body reads only once, so the caller must reuse this text
|
|
642
|
+
// instead of asking the response for it a second time (which throws).
|
|
643
|
+
let rejectedBody;
|
|
607
644
|
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
645
|
+
// Reset per attempt: only THIS attempt's rejection has been read.
|
|
646
|
+
rejectedBody = undefined;
|
|
608
647
|
// Bound THIS dispatch, not the retry loop: a deliberate backoff sleep is
|
|
609
648
|
// this provider's own wait, so no window is running while it is spent.
|
|
610
649
|
let headerDeadline = null;
|
|
@@ -628,6 +667,20 @@ class DeepseekAIProviderImpl {
|
|
|
628
667
|
clearTimeout(headerDeadline);
|
|
629
668
|
}
|
|
630
669
|
if (response.status === 429 || response.status === 503) {
|
|
670
|
+
// Read the body once: an unread body pins its connection, and only the
|
|
671
|
+
// body says what the upstream actually refused the request for.
|
|
672
|
+
try {
|
|
673
|
+
rejectedBody = await response.text();
|
|
674
|
+
}
|
|
675
|
+
catch (error) {
|
|
676
|
+
// Caller cancellation still ends the request; any other read failure
|
|
677
|
+
// only loses the reason, so the body counts as read and the retry
|
|
678
|
+
// policy goes on (the same guard the moonshot bond applies).
|
|
679
|
+
signal.throwIfAborted();
|
|
680
|
+
logger.debug('DeepSeek rejected response body could not be read', { error });
|
|
681
|
+
rejectedBody = '';
|
|
682
|
+
}
|
|
683
|
+
const upstreamError = parseUpstreamError(rejectedBody);
|
|
631
684
|
const willRetry = attempt < MAX_RETRIES;
|
|
632
685
|
// Retry-After is equally-valid as delta-seconds or an HTTP-date;
|
|
633
686
|
// parseInt on the date form yields NaN, degrading the backoff to a
|
|
@@ -651,6 +704,7 @@ class DeepseekAIProviderImpl {
|
|
|
651
704
|
willRetry,
|
|
652
705
|
retryInMs: delayMs,
|
|
653
706
|
...(hasRetryAfter ? { retryAfterSeconds: parsedRetryAfterSeconds } : {}),
|
|
707
|
+
...(upstreamError ? { upstreamError } : {}),
|
|
654
708
|
});
|
|
655
709
|
}
|
|
656
710
|
catch (error) {
|
|
@@ -662,6 +716,7 @@ class DeepseekAIProviderImpl {
|
|
|
662
716
|
status: response.status,
|
|
663
717
|
attempt: attempt + 1,
|
|
664
718
|
delayMs,
|
|
719
|
+
...(upstreamError ? { upstreamError } : {}),
|
|
665
720
|
});
|
|
666
721
|
// A host may cancel inside onRateLimit, before a backoff listener exists.
|
|
667
722
|
signal.throwIfAborted();
|
|
@@ -680,7 +735,7 @@ class DeepseekAIProviderImpl {
|
|
|
680
735
|
}
|
|
681
736
|
break;
|
|
682
737
|
}
|
|
683
|
-
return { response: response, sentAt };
|
|
738
|
+
return { response: response, sentAt, ...(rejectedBody !== undefined ? { rejectedBody } : {}) };
|
|
684
739
|
}
|
|
685
740
|
/**
|
|
686
741
|
* Record one stalled attempt: a warn line always, plus the host's
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-ai-deepseek",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "DeepSeek AI provider for molecule.dev",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/api-ai-deepseek",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"directory": "packages/api/bonds/ai/deepseek"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@molecule/api-ai": "1.
|
|
36
|
+
"@molecule/api-ai": "1.5.0",
|
|
37
37
|
"@molecule/api-bond": "1.0.4",
|
|
38
38
|
"@types/node": "26.6.5",
|
|
39
39
|
"typescript": "6.0.3",
|