@kenkaiiii/gg-ai 4.3.3 → 4.3.5

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
@@ -472,22 +472,37 @@ function normalizeOpenAIStopReason(reason) {
472
472
  }
473
473
 
474
474
  // src/providers/anthropic.ts
475
+ var clientCache = /* @__PURE__ */ new Map();
476
+ function getOrCreateClient(options) {
477
+ const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
478
+ const key = `${options.apiKey ?? ""}|${options.baseUrl ?? ""}|${isOAuth}`;
479
+ let client = clientCache.get(key);
480
+ if (!client) {
481
+ client = new import_sdk.default({
482
+ ...isOAuth ? { apiKey: null, authToken: options.apiKey } : { apiKey: options.apiKey },
483
+ ...options.baseUrl ? { baseURL: options.baseUrl } : {},
484
+ ...options.fetch ? { fetch: options.fetch } : {},
485
+ // Disable SDK-level retries — the agent loop handles retries itself with
486
+ // stall detection and context compaction. SDK retries on abort just cycle
487
+ // through the already-aborted signal, wasting time.
488
+ maxRetries: 0,
489
+ ...isOAuth ? {
490
+ defaultHeaders: {
491
+ "user-agent": "claude-cli/2.1.75",
492
+ "x-app": "cli"
493
+ }
494
+ } : {}
495
+ });
496
+ clientCache.set(key, client);
497
+ }
498
+ return client;
499
+ }
475
500
  function streamAnthropic(options) {
476
501
  return new StreamResult(runStream(options));
477
502
  }
478
503
  async function* runStream(options) {
504
+ const client = getOrCreateClient(options);
479
505
  const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
480
- const client = new import_sdk.default({
481
- ...isOAuth ? { apiKey: null, authToken: options.apiKey } : { apiKey: options.apiKey },
482
- ...options.baseUrl ? { baseURL: options.baseUrl } : {},
483
- ...options.fetch ? { fetch: options.fetch } : {},
484
- ...isOAuth ? {
485
- defaultHeaders: {
486
- "user-agent": "claude-cli/2.1.75",
487
- "x-app": "cli"
488
- }
489
- } : {}
490
- });
491
506
  const cacheControl = toAnthropicCacheControl(options.cacheRetention, options.baseUrl);
492
507
  const { system: rawSystem, messages } = toAnthropicMessages(options.messages, cacheControl);
493
508
  const system = isOAuth ? [
@@ -751,16 +766,26 @@ function toError(err) {
751
766
 
752
767
  // src/providers/openai.ts
753
768
  var import_openai = __toESM(require("openai"), 1);
769
+ var clientCache2 = /* @__PURE__ */ new Map();
770
+ function getOrCreateClient2(options) {
771
+ const key = `${options.apiKey ?? ""}|${options.baseUrl ?? ""}`;
772
+ let client = clientCache2.get(key);
773
+ if (!client) {
774
+ client = new import_openai.default({
775
+ apiKey: options.apiKey,
776
+ ...options.baseUrl ? { baseURL: options.baseUrl } : {},
777
+ ...options.fetch ? { fetch: options.fetch } : {}
778
+ });
779
+ clientCache2.set(key, client);
780
+ }
781
+ return client;
782
+ }
754
783
  function streamOpenAI(options) {
755
784
  return new StreamResult(runStream2(options));
756
785
  }
757
786
  async function* runStream2(options) {
758
787
  const providerName = options.provider ?? "openai";
759
- const client = new import_openai.default({
760
- apiKey: options.apiKey,
761
- ...options.baseUrl ? { baseURL: options.baseUrl } : {},
762
- ...options.fetch ? { fetch: options.fetch } : {}
763
- });
788
+ const client = getOrCreateClient2(options);
764
789
  const usesThinkingParam = options.provider === "glm" || options.provider === "moonshot" || options.provider === "xiaomi";
765
790
  const messages = toOpenAIMessages(options.messages, { provider: options.provider });
766
791
  const defaultTemp = options.provider === "glm" ? 0.6 : void 0;
@@ -769,7 +794,7 @@ async function* runStream2(options) {
769
794
  model: options.model,
770
795
  messages,
771
796
  stream: true,
772
- ...options.maxTokens ? options.provider === "xiaomi" ? { max_completion_tokens: options.maxTokens } : { max_tokens: options.maxTokens } : {},
797
+ ...options.maxTokens ? { max_tokens: options.maxTokens } : {},
773
798
  ...effectiveTemp != null && !options.thinking ? { temperature: effectiveTemp } : {},
774
799
  ...options.topP != null ? { top_p: options.topP } : {},
775
800
  ...options.stop ? { stop: options.stop } : {},
@@ -789,7 +814,7 @@ async function* runStream2(options) {
789
814
  if (usesThinkingParam) {
790
815
  if (options.thinking) {
791
816
  params.thinking = { type: "enabled" };
792
- } else if (options.provider !== "xiaomi") {
817
+ } else {
793
818
  params.thinking = { type: "disabled" };
794
819
  }
795
820
  }
@@ -838,7 +863,9 @@ async function* runStream2(options) {
838
863
  const reasoningContent = delta.reasoning_content;
839
864
  if (typeof reasoningContent === "string" && reasoningContent) {
840
865
  thinkingAccum += reasoningContent;
841
- yield { type: "thinking_delta", text: reasoningContent };
866
+ if (options.thinking) {
867
+ yield { type: "thinking_delta", text: reasoningContent };
868
+ }
842
869
  }
843
870
  if (delta.content) {
844
871
  textAccum += delta.content;
@@ -1292,6 +1319,18 @@ providerRegistry.register("moonshot", {
1292
1319
  baseUrl: options.baseUrl ?? "https://api.moonshot.ai/v1"
1293
1320
  })
1294
1321
  });
1322
+ providerRegistry.register("minimax", {
1323
+ stream: (options) => streamAnthropic({
1324
+ ...options,
1325
+ baseUrl: options.baseUrl ?? "https://api.minimax.io/anthropic",
1326
+ // MiniMax's Anthropic-compatible API does not support Anthropic-specific
1327
+ // server tools (web_search), context_management, or server-side tools.
1328
+ webSearch: false,
1329
+ compaction: false,
1330
+ clearToolUses: false,
1331
+ serverTools: void 0
1332
+ })
1333
+ });
1295
1334
  function stream(options) {
1296
1335
  const entry = providerRegistry.get(options.provider);
1297
1336
  if (!entry) {