@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.cjs CHANGED
@@ -335,6 +335,8 @@ function formatError(err) {
335
335
  guidance: fastRejection.guidance
336
336
  };
337
337
  }
338
+ const miniMax = err.provider === "minimax" ? formatMiniMaxError(err, cleanMessage) : void 0;
339
+ if (miniMax) return miniMax;
338
340
  if (isUsageLimitError(err)) {
339
341
  const resetClause = err.resetsAt ? ` It resets at ${formatResetTime(err.resetsAt)}.` : "";
340
342
  return {
@@ -441,6 +443,38 @@ function inferSource(err) {
441
443
  }
442
444
  return "ggcoder";
443
445
  }
446
+ function formatMiniMaxError(err, cleanMessage) {
447
+ const code = /\((\d{4,5})\)/.exec(err.message)?.[1];
448
+ const base = {
449
+ source: "provider",
450
+ message: cleanMessage,
451
+ provider: err.provider,
452
+ statusCode: err.statusCode,
453
+ ...err.requestId ? { requestId: err.requestId } : {}
454
+ };
455
+ if (code === "2049" || code === "1004") {
456
+ return {
457
+ ...base,
458
+ headline: "MiniMax didn't accept this API key.",
459
+ 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."
460
+ };
461
+ }
462
+ if (code === "2061") {
463
+ return {
464
+ ...base,
465
+ headline: "Your MiniMax plan doesn't include this model.",
466
+ 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."
467
+ };
468
+ }
469
+ if (code === "1008") {
470
+ return {
471
+ ...base,
472
+ headline: "MiniMax has no balance for this request.",
473
+ 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."
474
+ };
475
+ }
476
+ return void 0;
477
+ }
444
478
  function providerGuidance(provider, message, statusCode) {
445
479
  const name = provider ? providerDisplayName(provider) : "the provider";
446
480
  const status = provider ? PROVIDER_STATUS_URL[provider] : void 0;
@@ -1818,6 +1852,13 @@ function isAdaptiveThinkingModel(model) {
1818
1852
  return /opus-5|opus-4[-.]8|opus-4[-.]7|opus-4[-.]6|sonnet-5|haiku-5|fable-5|mythos-5/.test(model);
1819
1853
  }
1820
1854
  function toAnthropicThinking(level, maxTokens, model) {
1855
+ if (model.startsWith("MiniMax-M3.1")) {
1856
+ return {
1857
+ thinking: { type: "adaptive" },
1858
+ maxTokens,
1859
+ outputConfig: { effort: level === "ultra" ? "max" : level }
1860
+ };
1861
+ }
1821
1862
  if (isAdaptiveThinkingModel(model)) {
1822
1863
  let effort = level;
1823
1864
  if (effort === "xhigh" && !/fable-5|mythos-5|opus-5|opus-4-8|opus-4-7|sonnet-5[-.]5|haiku-5[-.]5/.test(model)) {
@@ -2339,8 +2380,7 @@ async function* runStream(options) {
2339
2380
  ...system ? { system } : {},
2340
2381
  ...thinking ? { thinking } : {},
2341
2382
  ...outputConfig ? { output_config: outputConfig } : {},
2342
- ...options.temperature != null && !thinking ? { temperature: options.temperature } : {},
2343
- ...options.topP != null ? { top_p: options.topP } : {},
2383
+ // API version 2026-10-21 (SDK 1.x) rejects temperature/top_p/top_k with a 400.
2344
2384
  ...options.stop ? { stop_sequences: options.stop } : {},
2345
2385
  ...(deferredPlan?.live ?? options.tools)?.length || options.serverTools?.length || options.webSearch ? (() => {
2346
2386
  const reservedServerNames = /* @__PURE__ */ new Set();
@@ -2441,7 +2481,7 @@ async function* runStream(options) {
2441
2481
  yield* synthesizeEventsFromMessage(message);
2442
2482
  return messageToResponse(message);
2443
2483
  } catch (err) {
2444
- throw toError(err, { fastMode: useFastMode });
2484
+ throw toError(err, { fastMode: useFastMode, provider: options.provider });
2445
2485
  }
2446
2486
  }
2447
2487
  const contentParts = [];
@@ -2557,7 +2597,7 @@ async function* runStream(options) {
2557
2597
  const rawPartial = accum.argsJson;
2558
2598
  const snippet = rawPartial.length > 200 ? `${rawPartial.slice(0, 200)}\u2026` : rawPartial;
2559
2599
  throw new ProviderError(
2560
- "anthropic",
2600
+ options.provider,
2561
2601
  `Tool "${accum.toolName}" input JSON was truncated in the stream (${rawPartial.length} bytes): ${snippet}; ${parseErr.message}`,
2562
2602
  { cause: parseErr }
2563
2603
  );
@@ -2660,15 +2700,15 @@ async function* runStream(options) {
2660
2700
  }
2661
2701
  }
2662
2702
  } catch (err) {
2663
- throw toError(err, { fastMode: useFastMode });
2703
+ throw toError(err, { fastMode: useFastMode, provider: options.provider });
2664
2704
  }
2665
2705
  if (!receivedAnyEvent) {
2666
- throw new ProviderError("anthropic", "Stream ended without producing any events.", {
2706
+ throw new ProviderError(options.provider, "Stream ended without producing any events.", {
2667
2707
  statusCode: 504
2668
2708
  });
2669
2709
  }
2670
2710
  if (stopReason === null) {
2671
- throw new ProviderError("anthropic", "Stream ended before completion (no stop_reason).", {
2711
+ throw new ProviderError(options.provider, "Stream ended before completion (no stop_reason).", {
2672
2712
  statusCode: 504,
2673
2713
  cause: { partialContent: contentParts, outputTokens }
2674
2714
  });
@@ -2810,6 +2850,7 @@ function readUnifiedRateLimit(headers) {
2810
2850
  return { rejected: status === "rejected", ...resetsAt ? { resetsAt } : {} };
2811
2851
  }
2812
2852
  function toError(err, context) {
2853
+ const provider = context?.provider ?? "anthropic";
2813
2854
  if (err instanceof ProviderError) return err;
2814
2855
  if (err instanceof import_sdk.default.APIError) {
2815
2856
  const errorBody = err.error;
@@ -2843,22 +2884,22 @@ function toError(err, context) {
2843
2884
  }
2844
2885
  if (isHardBillingMessage(message)) {
2845
2886
  const usageMessage = /usage limit reached/i.test(message) ? message : `usage limit reached: ${message}`;
2846
- return new ProviderError("anthropic", usageMessage, {
2887
+ return new ProviderError(provider, usageMessage, {
2847
2888
  statusCode: err.status,
2848
2889
  ...requestId ? { requestId } : {},
2849
2890
  cause: err
2850
2891
  });
2851
2892
  }
2852
- return new ProviderError("anthropic", message, {
2893
+ return new ProviderError(provider, message, {
2853
2894
  statusCode: err.status,
2854
2895
  ...requestId ? { requestId } : {},
2855
2896
  cause: err
2856
2897
  });
2857
2898
  }
2858
2899
  if (err instanceof Error) {
2859
- return new ProviderError("anthropic", err.message, { cause: err });
2900
+ return new ProviderError(provider, err.message, { cause: err });
2860
2901
  }
2861
- return new ProviderError("anthropic", String(err));
2902
+ return new ProviderError(provider, String(err));
2862
2903
  }
2863
2904
 
2864
2905
  // src/providers/openai.ts