@kenkaiiii/gg-ai 5.90.0 → 5.91.0

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/index.js CHANGED
@@ -241,6 +241,8 @@ function formatError(err) {
241
241
  guidance: fastRejection.guidance
242
242
  };
243
243
  }
244
+ const miniMax = err.provider === "minimax" ? formatMiniMaxError(err, cleanMessage) : void 0;
245
+ if (miniMax) return miniMax;
244
246
  if (isUsageLimitError(err)) {
245
247
  const resetClause = err.resetsAt ? ` It resets at ${formatResetTime(err.resetsAt)}.` : "";
246
248
  return {
@@ -347,6 +349,38 @@ function inferSource(err) {
347
349
  }
348
350
  return "ggcoder";
349
351
  }
352
+ function formatMiniMaxError(err, cleanMessage) {
353
+ const code = /\((\d{4,5})\)/.exec(err.message)?.[1];
354
+ const base = {
355
+ source: "provider",
356
+ message: cleanMessage,
357
+ provider: err.provider,
358
+ statusCode: err.statusCode,
359
+ ...err.requestId ? { requestId: err.requestId } : {}
360
+ };
361
+ if (code === "2049" || code === "1004") {
362
+ return {
363
+ ...base,
364
+ headline: "MiniMax didn't accept this API key.",
365
+ guidance: "A MiniMax key only works in the region that issued it (Global: platform.minimax.io, Mainland China: platform.minimaxi.com). Connect MiniMax again with the key so GG Coder can detect its region, and check the key is active."
366
+ };
367
+ }
368
+ if (code === "2061") {
369
+ return {
370
+ ...base,
371
+ headline: "Your MiniMax plan doesn't include this model.",
372
+ guidance: "Switch to MiniMax M3.1 Flash in the model selector \u2014 it's the model M Plan and Token Plan cover. MiniMax M3 needs a pay-as-you-go key."
373
+ };
374
+ }
375
+ if (code === "1008") {
376
+ return {
377
+ ...base,
378
+ headline: "MiniMax has no balance for this request.",
379
+ guidance: "Check this key's plan is active, or its pay-as-you-go balance, at platform.minimax.io (platform.minimaxi.com for Mainland China keys). Plan keys only cover MiniMax M3.1 Flash. Not a GG Coder issue."
380
+ };
381
+ }
382
+ return void 0;
383
+ }
350
384
  function providerGuidance(provider, message, statusCode) {
351
385
  const name = provider ? providerDisplayName(provider) : "the provider";
352
386
  const status = provider ? PROVIDER_STATUS_URL[provider] : void 0;
@@ -1724,6 +1758,13 @@ function isAdaptiveThinkingModel(model) {
1724
1758
  return /opus-5|opus-4[-.]8|opus-4[-.]7|opus-4[-.]6|sonnet-5|haiku-5|fable-5|mythos-5/.test(model);
1725
1759
  }
1726
1760
  function toAnthropicThinking(level, maxTokens, model) {
1761
+ if (model.startsWith("MiniMax-M3.1")) {
1762
+ return {
1763
+ thinking: { type: "adaptive" },
1764
+ maxTokens,
1765
+ outputConfig: { effort: level === "ultra" ? "max" : level }
1766
+ };
1767
+ }
1727
1768
  if (isAdaptiveThinkingModel(model)) {
1728
1769
  let effort = level;
1729
1770
  if (effort === "xhigh" && !/fable-5|mythos-5|opus-5|opus-4-8|opus-4-7|sonnet-5[-.]5|haiku-5[-.]5/.test(model)) {
@@ -2245,8 +2286,7 @@ async function* runStream(options) {
2245
2286
  ...system ? { system } : {},
2246
2287
  ...thinking ? { thinking } : {},
2247
2288
  ...outputConfig ? { output_config: outputConfig } : {},
2248
- ...options.temperature != null && !thinking ? { temperature: options.temperature } : {},
2249
- ...options.topP != null ? { top_p: options.topP } : {},
2289
+ // API version 2026-10-21 (SDK 1.x) rejects temperature/top_p/top_k with a 400.
2250
2290
  ...options.stop ? { stop_sequences: options.stop } : {},
2251
2291
  ...(deferredPlan?.live ?? options.tools)?.length || options.serverTools?.length || options.webSearch ? (() => {
2252
2292
  const reservedServerNames = /* @__PURE__ */ new Set();
@@ -2347,7 +2387,7 @@ async function* runStream(options) {
2347
2387
  yield* synthesizeEventsFromMessage(message);
2348
2388
  return messageToResponse(message);
2349
2389
  } catch (err) {
2350
- throw toError(err, { fastMode: useFastMode });
2390
+ throw toError(err, { fastMode: useFastMode, provider: options.provider });
2351
2391
  }
2352
2392
  }
2353
2393
  const contentParts = [];
@@ -2463,7 +2503,7 @@ async function* runStream(options) {
2463
2503
  const rawPartial = accum.argsJson;
2464
2504
  const snippet = rawPartial.length > 200 ? `${rawPartial.slice(0, 200)}\u2026` : rawPartial;
2465
2505
  throw new ProviderError(
2466
- "anthropic",
2506
+ options.provider,
2467
2507
  `Tool "${accum.toolName}" input JSON was truncated in the stream (${rawPartial.length} bytes): ${snippet}; ${parseErr.message}`,
2468
2508
  { cause: parseErr }
2469
2509
  );
@@ -2566,15 +2606,15 @@ async function* runStream(options) {
2566
2606
  }
2567
2607
  }
2568
2608
  } catch (err) {
2569
- throw toError(err, { fastMode: useFastMode });
2609
+ throw toError(err, { fastMode: useFastMode, provider: options.provider });
2570
2610
  }
2571
2611
  if (!receivedAnyEvent) {
2572
- throw new ProviderError("anthropic", "Stream ended without producing any events.", {
2612
+ throw new ProviderError(options.provider, "Stream ended without producing any events.", {
2573
2613
  statusCode: 504
2574
2614
  });
2575
2615
  }
2576
2616
  if (stopReason === null) {
2577
- throw new ProviderError("anthropic", "Stream ended before completion (no stop_reason).", {
2617
+ throw new ProviderError(options.provider, "Stream ended before completion (no stop_reason).", {
2578
2618
  statusCode: 504,
2579
2619
  cause: { partialContent: contentParts, outputTokens }
2580
2620
  });
@@ -2716,6 +2756,7 @@ function readUnifiedRateLimit(headers) {
2716
2756
  return { rejected: status === "rejected", ...resetsAt ? { resetsAt } : {} };
2717
2757
  }
2718
2758
  function toError(err, context) {
2759
+ const provider = context?.provider ?? "anthropic";
2719
2760
  if (err instanceof ProviderError) return err;
2720
2761
  if (err instanceof Anthropic.APIError) {
2721
2762
  const errorBody = err.error;
@@ -2749,22 +2790,22 @@ function toError(err, context) {
2749
2790
  }
2750
2791
  if (isHardBillingMessage(message)) {
2751
2792
  const usageMessage = /usage limit reached/i.test(message) ? message : `usage limit reached: ${message}`;
2752
- return new ProviderError("anthropic", usageMessage, {
2793
+ return new ProviderError(provider, usageMessage, {
2753
2794
  statusCode: err.status,
2754
2795
  ...requestId ? { requestId } : {},
2755
2796
  cause: err
2756
2797
  });
2757
2798
  }
2758
- return new ProviderError("anthropic", message, {
2799
+ return new ProviderError(provider, message, {
2759
2800
  statusCode: err.status,
2760
2801
  ...requestId ? { requestId } : {},
2761
2802
  cause: err
2762
2803
  });
2763
2804
  }
2764
2805
  if (err instanceof Error) {
2765
- return new ProviderError("anthropic", err.message, { cause: err });
2806
+ return new ProviderError(provider, err.message, { cause: err });
2766
2807
  }
2767
- return new ProviderError("anthropic", String(err));
2808
+ return new ProviderError(provider, String(err));
2768
2809
  }
2769
2810
 
2770
2811
  // src/providers/openai.ts