@kenkaiiii/gg-ai 5.90.0 → 5.91.1

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.d.cts CHANGED
@@ -241,6 +241,8 @@ interface StreamOptions {
241
241
  topP?: number;
242
242
  stop?: string[];
243
243
  thinking?: ThinkingLevel;
244
+ /** Effort rungs the endpoint itself declared for this model (synced gateway catalogs). */
245
+ thinkingLevels?: readonly ThinkingLevel[];
244
246
  apiKey?: string;
245
247
  baseUrl?: string;
246
248
  signal?: AbortSignal;
package/dist/index.d.ts CHANGED
@@ -241,6 +241,8 @@ interface StreamOptions {
241
241
  topP?: number;
242
242
  stop?: string[];
243
243
  thinking?: ThinkingLevel;
244
+ /** Effort rungs the endpoint itself declared for this model (synced gateway catalogs). */
245
+ thinkingLevels?: readonly ThinkingLevel[];
244
246
  apiKey?: string;
245
247
  baseUrl?: string;
246
248
  signal?: AbortSignal;
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)) {
@@ -1933,6 +1974,14 @@ function toCodexReasoningEffort(level, model) {
1933
1974
  if (level !== "ultra") return level;
1934
1975
  return model === "gpt-6-astra" || model === "gpt-6.1-sol" ? "xhigh" : "max";
1935
1976
  }
1977
+ var DECLARED_EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"];
1978
+ function effortForRequest(level, model, declared) {
1979
+ const rungs = DECLARED_EFFORT_ORDER.filter((rung) => declared?.includes(rung));
1980
+ if (rungs.length === 0) return toOpenAIReasoningEffort(level, model);
1981
+ const wanted = level === "ultra" ? DECLARED_EFFORT_ORDER.length - 1 : DECLARED_EFFORT_ORDER.indexOf(level);
1982
+ const atOrBelow = rungs.filter((rung) => DECLARED_EFFORT_ORDER.indexOf(rung) <= wanted);
1983
+ return atOrBelow[atOrBelow.length - 1] ?? rungs[0];
1984
+ }
1936
1985
  function toOpenAIReasoningEffort(level, model) {
1937
1986
  const effort = level === "max" || level === "ultra" ? "xhigh" : level;
1938
1987
  if (model.startsWith("fugu") && (effort === "low" || effort === "medium")) {
@@ -2245,8 +2294,7 @@ async function* runStream(options) {
2245
2294
  ...system ? { system } : {},
2246
2295
  ...thinking ? { thinking } : {},
2247
2296
  ...outputConfig ? { output_config: outputConfig } : {},
2248
- ...options.temperature != null && !thinking ? { temperature: options.temperature } : {},
2249
- ...options.topP != null ? { top_p: options.topP } : {},
2297
+ // API version 2026-10-21 (SDK 1.x) rejects temperature/top_p/top_k with a 400.
2250
2298
  ...options.stop ? { stop_sequences: options.stop } : {},
2251
2299
  ...(deferredPlan?.live ?? options.tools)?.length || options.serverTools?.length || options.webSearch ? (() => {
2252
2300
  const reservedServerNames = /* @__PURE__ */ new Set();
@@ -2347,7 +2395,7 @@ async function* runStream(options) {
2347
2395
  yield* synthesizeEventsFromMessage(message);
2348
2396
  return messageToResponse(message);
2349
2397
  } catch (err) {
2350
- throw toError(err, { fastMode: useFastMode });
2398
+ throw toError(err, { fastMode: useFastMode, provider: options.provider });
2351
2399
  }
2352
2400
  }
2353
2401
  const contentParts = [];
@@ -2463,7 +2511,7 @@ async function* runStream(options) {
2463
2511
  const rawPartial = accum.argsJson;
2464
2512
  const snippet = rawPartial.length > 200 ? `${rawPartial.slice(0, 200)}\u2026` : rawPartial;
2465
2513
  throw new ProviderError(
2466
- "anthropic",
2514
+ options.provider,
2467
2515
  `Tool "${accum.toolName}" input JSON was truncated in the stream (${rawPartial.length} bytes): ${snippet}; ${parseErr.message}`,
2468
2516
  { cause: parseErr }
2469
2517
  );
@@ -2566,15 +2614,15 @@ async function* runStream(options) {
2566
2614
  }
2567
2615
  }
2568
2616
  } catch (err) {
2569
- throw toError(err, { fastMode: useFastMode });
2617
+ throw toError(err, { fastMode: useFastMode, provider: options.provider });
2570
2618
  }
2571
2619
  if (!receivedAnyEvent) {
2572
- throw new ProviderError("anthropic", "Stream ended without producing any events.", {
2620
+ throw new ProviderError(options.provider, "Stream ended without producing any events.", {
2573
2621
  statusCode: 504
2574
2622
  });
2575
2623
  }
2576
2624
  if (stopReason === null) {
2577
- throw new ProviderError("anthropic", "Stream ended before completion (no stop_reason).", {
2625
+ throw new ProviderError(options.provider, "Stream ended before completion (no stop_reason).", {
2578
2626
  statusCode: 504,
2579
2627
  cause: { partialContent: contentParts, outputTokens }
2580
2628
  });
@@ -2716,6 +2764,7 @@ function readUnifiedRateLimit(headers) {
2716
2764
  return { rejected: status === "rejected", ...resetsAt ? { resetsAt } : {} };
2717
2765
  }
2718
2766
  function toError(err, context) {
2767
+ const provider = context?.provider ?? "anthropic";
2719
2768
  if (err instanceof ProviderError) return err;
2720
2769
  if (err instanceof Anthropic.APIError) {
2721
2770
  const errorBody = err.error;
@@ -2749,22 +2798,22 @@ function toError(err, context) {
2749
2798
  }
2750
2799
  if (isHardBillingMessage(message)) {
2751
2800
  const usageMessage = /usage limit reached/i.test(message) ? message : `usage limit reached: ${message}`;
2752
- return new ProviderError("anthropic", usageMessage, {
2801
+ return new ProviderError(provider, usageMessage, {
2753
2802
  statusCode: err.status,
2754
2803
  ...requestId ? { requestId } : {},
2755
2804
  cause: err
2756
2805
  });
2757
2806
  }
2758
- return new ProviderError("anthropic", message, {
2807
+ return new ProviderError(provider, message, {
2759
2808
  statusCode: err.status,
2760
2809
  ...requestId ? { requestId } : {},
2761
2810
  cause: err
2762
2811
  });
2763
2812
  }
2764
2813
  if (err instanceof Error) {
2765
- return new ProviderError("anthropic", err.message, { cause: err });
2814
+ return new ProviderError(provider, err.message, { cause: err });
2766
2815
  }
2767
- return new ProviderError("anthropic", String(err));
2816
+ return new ProviderError(provider, String(err));
2768
2817
  }
2769
2818
 
2770
2819
  // src/providers/openai.ts
@@ -2968,7 +3017,13 @@ async function* runStream2(options) {
2968
3017
  ...effectiveTemp != null && !options.thinking && !hasFixedKimiSampling ? { temperature: effectiveTemp } : {},
2969
3018
  ...options.topP != null && !hasFixedKimiSampling ? { top_p: options.topP } : {},
2970
3019
  ...options.stop ? { stop: options.stop } : {},
2971
- ...options.thinking && !usesThinkingParam && !isKimiK3 && !isKimiK27 && !isLocal ? { reasoning_effort: toOpenAIReasoningEffort(options.thinking, options.model) } : {},
3020
+ ...options.thinking && !usesThinkingParam && !isKimiK3 && !isKimiK27 && !isLocal ? {
3021
+ reasoning_effort: effortForRequest(
3022
+ options.thinking,
3023
+ options.model,
3024
+ options.thinkingLevels
3025
+ )
3026
+ } : {},
2972
3027
  ...options.tools?.length ? {
2973
3028
  tools: toOpenAITools(options.tools, {
2974
3029
  strict: supportsStrictToolSampling(options.provider) && (options.strictTools ?? true)