@molecule/api-ai-minimax 1.2.1 → 1.2.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 +47 -1
- package/package.json +3 -3
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EACV,UAAU,EAQX,MAAM,kBAAkB,CAAA;AASzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EACV,UAAU,EAQX,MAAM,kBAAkB,CAAA;AASzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAgyB/C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,UAAU,CAEjE"}
|
package/dist/provider.js
CHANGED
|
@@ -26,6 +26,33 @@ import './secrets.js';
|
|
|
26
26
|
function isM3Family(model) {
|
|
27
27
|
return /^minimax-m3/i.test(model);
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Read the upstream's explanation from a rejected response body: its error
|
|
31
|
+
* `type` (or `code`) and `message`, the message bounded to 500 characters.
|
|
32
|
+
*
|
|
33
|
+
* @param text - The rejected response's body text.
|
|
34
|
+
* @returns The upstream error, or `undefined` when the body carried neither field.
|
|
35
|
+
*/
|
|
36
|
+
function parseUpstreamError(text) {
|
|
37
|
+
let error;
|
|
38
|
+
try {
|
|
39
|
+
error = JSON.parse(text)?.error;
|
|
40
|
+
}
|
|
41
|
+
catch (_error) {
|
|
42
|
+
// Not JSON (a proxy's error page, plain text): a short body is the message itself.
|
|
43
|
+
const trimmed = text.trim();
|
|
44
|
+
return trimmed && trimmed.length <= 500 ? { message: trimmed } : undefined;
|
|
45
|
+
}
|
|
46
|
+
const type = typeof error?.type === 'string'
|
|
47
|
+
? error.type
|
|
48
|
+
: typeof error?.code === 'string'
|
|
49
|
+
? error.code
|
|
50
|
+
: undefined;
|
|
51
|
+
const message = typeof error?.message === 'string' ? error.message.slice(0, 500) : undefined;
|
|
52
|
+
if (!type && !message)
|
|
53
|
+
return undefined;
|
|
54
|
+
return { ...(type ? { type } : {}), ...(message ? { message } : {}) };
|
|
55
|
+
}
|
|
29
56
|
/**
|
|
30
57
|
* Whether a model id is a MiniMax M3.1-Flash-family model. M3.1-Flash ALWAYS
|
|
31
58
|
* thinks: `thinking: {type: "disabled"}` is answered with a 400 ("requires
|
|
@@ -181,7 +208,9 @@ class MiniMaxAIProvider {
|
|
|
181
208
|
// Retry with exponential backoff for rate limits (429) and overloaded (503)
|
|
182
209
|
const MAX_RETRIES = 3;
|
|
183
210
|
let response = null;
|
|
211
|
+
let rejectedBody;
|
|
184
212
|
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
213
|
+
rejectedBody = undefined;
|
|
185
214
|
response = await fetch(`${this.baseUrl}${this.completionsPath}`, {
|
|
186
215
|
method: 'POST',
|
|
187
216
|
headers,
|
|
@@ -189,6 +218,20 @@ class MiniMaxAIProvider {
|
|
|
189
218
|
signal,
|
|
190
219
|
});
|
|
191
220
|
if (response.status === 429 || response.status === 503) {
|
|
221
|
+
// Read the body once: an unread body pins its connection, and only the
|
|
222
|
+
// body says what the upstream actually refused the request for.
|
|
223
|
+
try {
|
|
224
|
+
rejectedBody = await response.text();
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
// Caller cancellation still ends the request; any other read failure
|
|
228
|
+
// only loses the reason, so the body counts as read and the retry
|
|
229
|
+
// policy goes on (the same guard the moonshot bond applies).
|
|
230
|
+
signal.throwIfAborted();
|
|
231
|
+
logger.debug('MiniMax rejected response body could not be read', { error });
|
|
232
|
+
rejectedBody = '';
|
|
233
|
+
}
|
|
234
|
+
const upstreamError = parseUpstreamError(rejectedBody);
|
|
192
235
|
const willRetry = attempt < MAX_RETRIES;
|
|
193
236
|
// Retry-After is equally-valid as delta-seconds or an HTTP-date;
|
|
194
237
|
// parseInt on the date form yields NaN, degrading the backoff to a
|
|
@@ -212,6 +255,7 @@ class MiniMaxAIProvider {
|
|
|
212
255
|
willRetry,
|
|
213
256
|
retryInMs: delayMs,
|
|
214
257
|
...(hasRetryAfter ? { retryAfterSeconds: parsedRetryAfterSeconds } : {}),
|
|
258
|
+
...(upstreamError ? { upstreamError } : {}),
|
|
215
259
|
});
|
|
216
260
|
}
|
|
217
261
|
catch (error) {
|
|
@@ -223,6 +267,7 @@ class MiniMaxAIProvider {
|
|
|
223
267
|
status: response.status,
|
|
224
268
|
attempt: attempt + 1,
|
|
225
269
|
delayMs,
|
|
270
|
+
...(upstreamError ? { upstreamError } : {}),
|
|
226
271
|
});
|
|
227
272
|
await new Promise((resolve) => {
|
|
228
273
|
const timer = setTimeout(resolve, delayMs);
|
|
@@ -239,7 +284,8 @@ class MiniMaxAIProvider {
|
|
|
239
284
|
break;
|
|
240
285
|
}
|
|
241
286
|
if (!response.ok) {
|
|
242
|
-
|
|
287
|
+
// A 429/503 body was already read by the retry loop; a body reads only once.
|
|
288
|
+
const errorBody = rejectedBody ?? (await response.text());
|
|
243
289
|
let detail = `HTTP ${response.status}`;
|
|
244
290
|
try {
|
|
245
291
|
const parsed = JSON.parse(errorBody);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-ai-minimax",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "MiniMax AI provider for molecule.dev",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/api-ai-minimax",
|
|
6
6
|
"type": "module",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"directory": "packages/api/bonds/ai/minimax"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@molecule/api-ai": "1.
|
|
37
|
-
"@molecule/api-bond": "1.0.
|
|
36
|
+
"@molecule/api-ai": "1.5.0",
|
|
37
|
+
"@molecule/api-bond": "1.0.4",
|
|
38
38
|
"@types/node": "26.6.5",
|
|
39
39
|
"typescript": "6.0.3",
|
|
40
40
|
"vitest": "4.1.12"
|