@kenkaiiii/gg-ai 5.81.0 → 5.82.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
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  EventStream: () => EventStream,
34
+ FAST_MODE_SUFFIX: () => FAST_MODE_SUFFIX,
34
35
  GGAIError: () => GGAIError,
35
36
  ProviderError: () => ProviderError,
36
37
  REDACTION_MARKER: () => REDACTED,
@@ -63,6 +64,7 @@ __export(index_exports, {
63
64
  redactValue: () => redactValue,
64
65
  registerPalsuProvider: () => registerPalsuProvider,
65
66
  rerank: () => rerank,
67
+ resolveFastModeModel: () => resolveFastModeModel,
66
68
  resolveToolSchema: () => resolveToolSchema,
67
69
  sanitizeMessagesForWire: () => sanitizeMessagesForWire,
68
70
  setProviderDiagnostic: () => setProviderDiagnostic,
@@ -156,7 +158,8 @@ function isUsageLimitError(err) {
156
158
  }
157
159
  function isHardBillingMessage(message) {
158
160
  const lower = message.toLowerCase();
159
- return lower.includes("insufficient balance") || lower.includes("insufficient credits") || lower.includes("more credits") || lower.includes("insufficient_quota") || lower.includes("exceeded your current quota") || lower.includes("quota exceeded") || lower.includes("no resource package") || lower.includes("recharge") || lower.includes("balance is too low") || lower.includes("out of credits") || lower.includes("arrears") || lower.includes("arrearage") || lower.includes("token quota") || lower.includes("exceeded_current_quota_error") || lower.includes("check your account balance") || lower.includes("does not yet include access") || lower.includes("subscription plan") || lower.includes("billing");
161
+ return lower.includes("insufficient balance") || lower.includes("insufficient credits") || lower.includes("more credits") || lower.includes("insufficient_quota") || lower.includes("exceeded your current quota") || lower.includes("quota exceeded") || lower.includes("no resource package") || lower.includes("recharge") || lower.includes("balance is too low") || lower.includes("out of credits") || // Anthropic fast mode on a subscription without usage credits turned on.
162
+ lower.includes("usage credits are required") || lower.includes("arrears") || lower.includes("arrearage") || lower.includes("token quota") || lower.includes("exceeded_current_quota_error") || lower.includes("check your account balance") || lower.includes("does not yet include access") || lower.includes("subscription plan") || lower.includes("billing");
160
163
  }
161
164
  function formatResetTime(resetsAt) {
162
165
  const when = new Date(resetsAt * 1e3);
@@ -1653,6 +1656,7 @@ function fineGrainedToolStreamingEnabled() {
1653
1656
  return v === "1" || v === "true" || v === "yes" || v === "on";
1654
1657
  }
1655
1658
  var SERVER_FALLBACK_BETA = "server-side-fallback-2026-07-01";
1659
+ var FAST_MODE_BETA = "fast-mode-2026-02-01";
1656
1660
  var anthropicServerFallback = {
1657
1661
  disabled: /* @__PURE__ */ new Set(),
1658
1662
  reset() {
@@ -1795,6 +1799,7 @@ async function* runStream(options) {
1795
1799
  const { system: rawSystem, messages } = toAnthropicMessages(downgradedMessages, cacheControl, {
1796
1800
  fallbackBlocks: useServerFallback
1797
1801
  });
1802
+ const useFastMode = options.speed === "fast" && options.provider === "anthropic" && isDirectAnthropicApi(options.baseUrl);
1798
1803
  const system = isOAuth ? [
1799
1804
  {
1800
1805
  type: "text",
@@ -1865,6 +1870,7 @@ async function* runStream(options) {
1865
1870
  return contextEdits.length ? { context_management: { edits: contextEdits } } : {};
1866
1871
  })(),
1867
1872
  ...useServerFallback ? { fallbacks: "default" } : {},
1873
+ ...useFastMode ? { speed: "fast" } : {},
1868
1874
  stream: useStreaming
1869
1875
  };
1870
1876
  const params = mergeProviderOptions(baseParams, options.providerOptions);
@@ -1883,7 +1889,8 @@ async function* runStream(options) {
1883
1889
  // so a pre-warmed cache expires before the user's first turn. cacheControl.ttl
1884
1890
  // is only "1h" on the first-party endpoint (see toAnthropicCacheControl).
1885
1891
  ...cacheControl?.ttl === "1h" ? ["extended-cache-ttl-2025-04-11"] : [],
1886
- ...useServerFallback ? [SERVER_FALLBACK_BETA] : []
1892
+ ...useServerFallback ? [SERVER_FALLBACK_BETA] : [],
1893
+ ...useFastMode ? [FAST_MODE_BETA] : []
1887
1894
  ];
1888
1895
  const toRequestOptions = (betas) => ({
1889
1896
  signal: options.signal ?? void 0,
@@ -2268,6 +2275,9 @@ function messageToResponse(message) {
2268
2275
  }
2269
2276
  };
2270
2277
  }
2278
+ function isFastModeCreditsMessage(message) {
2279
+ return /usage credits are required for fast mode/i.test(message);
2280
+ }
2271
2281
  function readUnifiedRateLimit(headers) {
2272
2282
  const status = readHeader(headers, "anthropic-ratelimit-unified-status");
2273
2283
  const resetRaw = readHeader(
@@ -2291,6 +2301,14 @@ function toError(err) {
2291
2301
  const fallbackMessage = isRawJsonErrorEcho(err.message) ? emptyProviderErrorMessage(err.status) : err.message;
2292
2302
  const messageCandidate = bodyMessage ?? err.message;
2293
2303
  const message = isRawHtmlErrorEcho(messageCandidate) ? providerHtmlErrorMessage(err.status) : bodyType && bodyMessage ? `${bodyType}: ${bodyMessage}` : bodyMessage ?? fallbackMessage;
2304
+ if (isFastModeCreditsMessage(message)) {
2305
+ return new ProviderError("anthropic", message, {
2306
+ statusCode: err.status,
2307
+ ...requestId ? { requestId } : {},
2308
+ hint: "Fast mode bills Claude usage credits, not your plan. Turn them on at claude.ai/settings/usage, or switch to Claude Opus 5.5 (standard speed) in the model selector.",
2309
+ cause: err
2310
+ });
2311
+ }
2294
2312
  if (err.status === 429) {
2295
2313
  const limit = readUnifiedRateLimit(err.headers);
2296
2314
  const farOff = limit.resetsAt != null && limit.resetsAt * 1e3 - Date.now() > 6e4;
@@ -2546,8 +2564,9 @@ async function* runStream2(options) {
2546
2564
  if (options.provider === "sakana" && options.model === "fugu-ultra" && (options.thinking === "max" || options.thinking === "ultra")) {
2547
2565
  params.reasoning_effort = "max";
2548
2566
  }
2549
- if (options.provider === "openai" && options.serviceTier) {
2550
- params.service_tier = options.serviceTier;
2567
+ const serviceTier = options.serviceTier ?? (options.speed === "fast" ? "priority" : void 0);
2568
+ if (options.provider === "openai" && serviceTier) {
2569
+ params.service_tier = serviceTier;
2551
2570
  }
2552
2571
  if (isKimiK3) {
2553
2572
  const paramsAny = params;
@@ -3057,6 +3076,9 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
3057
3076
  if (options.temperature != null && !options.thinking) {
3058
3077
  body.temperature = options.temperature;
3059
3078
  }
3079
+ if (options.speed === "fast") {
3080
+ body.service_tier = "priority";
3081
+ }
3060
3082
  body.reasoning = {
3061
3083
  // GPT-5.6/6 require at least low; older models still support thinking off.
3062
3084
  // Apply the floor here for every caller, including one-off prompt rewrites.
@@ -4792,6 +4814,18 @@ function observePreparedContext(before, after, tools) {
4792
4814
  };
4793
4815
  }
4794
4816
 
4817
+ // src/fast-mode.ts
4818
+ var FAST_MODE_SUFFIX = "-fast";
4819
+ var FAST_MODE_BASE_MODELS = {
4820
+ anthropic: ["claude-opus-5-5"],
4821
+ openai: ["gpt-6-astra", "gpt-6.1-sol", "gpt-6-luna"]
4822
+ };
4823
+ function resolveFastModeModel(provider, model) {
4824
+ if (!model.endsWith(FAST_MODE_SUFFIX)) return { model, fast: false };
4825
+ const base = model.slice(0, -FAST_MODE_SUFFIX.length);
4826
+ return FAST_MODE_BASE_MODELS[provider]?.includes(base) ? { model: base, fast: true } : { model, fast: false };
4827
+ }
4828
+
4795
4829
  // src/stream.ts
4796
4830
  var OPENAI_EMBED_BATCH_SIZE = 2048;
4797
4831
  var OPENROUTER_EMBED_BATCH_SIZE = 64;
@@ -4966,7 +5000,9 @@ function requireLocalBaseUrl(baseUrl) {
4966
5000
  }
4967
5001
  return baseUrl;
4968
5002
  }
4969
- function stream(options) {
5003
+ function stream(requested) {
5004
+ const fastMode = resolveFastModeModel(requested.provider, requested.model);
5005
+ const options = fastMode.fast ? { ...requested, model: fastMode.model, speed: "fast" } : requested;
4970
5006
  const entry = providerRegistry.get(options.provider);
4971
5007
  if (!entry) {
4972
5008
  throw new GGAIError(
@@ -5598,6 +5634,7 @@ function palsuRerankScore(query, document) {
5598
5634
  // Annotate the CommonJS export names for ESM import in node:
5599
5635
  0 && (module.exports = {
5600
5636
  EventStream,
5637
+ FAST_MODE_SUFFIX,
5601
5638
  GGAIError,
5602
5639
  ProviderError,
5603
5640
  REDACTION_MARKER,
@@ -5630,6 +5667,7 @@ function palsuRerankScore(query, document) {
5630
5667
  redactValue,
5631
5668
  registerPalsuProvider,
5632
5669
  rerank,
5670
+ resolveFastModeModel,
5633
5671
  resolveToolSchema,
5634
5672
  sanitizeMessagesForWire,
5635
5673
  setProviderDiagnostic,