@kenkaiiii/gg-ai 4.3.5 → 4.3.7
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 +40 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -426,36 +426,29 @@ function normalizeOpenAIStopReason(reason) {
|
|
|
426
426
|
}
|
|
427
427
|
|
|
428
428
|
// src/providers/anthropic.ts
|
|
429
|
-
|
|
430
|
-
function getOrCreateClient(options) {
|
|
429
|
+
function createClient(options) {
|
|
431
430
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
} : {}
|
|
449
|
-
});
|
|
450
|
-
clientCache.set(key, client);
|
|
451
|
-
}
|
|
452
|
-
return client;
|
|
431
|
+
return new Anthropic({
|
|
432
|
+
...isOAuth ? { apiKey: null, authToken: options.apiKey } : { apiKey: options.apiKey },
|
|
433
|
+
...options.baseUrl ? { baseURL: options.baseUrl } : {},
|
|
434
|
+
...options.fetch ? { fetch: options.fetch } : {},
|
|
435
|
+
// Allow SDK retries for connection-level failures (socket hang up, 500s,
|
|
436
|
+
// connection refused). Our stall detection handles abort-initiated retries
|
|
437
|
+
// separately — SDK retries only fire on genuine transport errors.
|
|
438
|
+
maxRetries: 2,
|
|
439
|
+
...isOAuth ? {
|
|
440
|
+
defaultHeaders: {
|
|
441
|
+
"user-agent": "claude-cli/2.1.75",
|
|
442
|
+
"x-app": "cli"
|
|
443
|
+
}
|
|
444
|
+
} : {}
|
|
445
|
+
});
|
|
453
446
|
}
|
|
454
447
|
function streamAnthropic(options) {
|
|
455
448
|
return new StreamResult(runStream(options));
|
|
456
449
|
}
|
|
457
450
|
async function* runStream(options) {
|
|
458
|
-
const client =
|
|
451
|
+
const client = createClient(options);
|
|
459
452
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
460
453
|
const cacheControl = toAnthropicCacheControl(options.cacheRetention, options.baseUrl);
|
|
461
454
|
const { system: rawSystem, messages } = toAnthropicMessages(options.messages, cacheControl);
|
|
@@ -504,10 +497,13 @@ async function* runStream(options) {
|
|
|
504
497
|
})(),
|
|
505
498
|
stream: true
|
|
506
499
|
};
|
|
500
|
+
const hasAdaptiveThinking = options.model.includes("opus-4-6") || options.model.includes("opus-4.6") || options.model.includes("sonnet-4-6") || options.model.includes("sonnet-4.6");
|
|
507
501
|
const betaHeaders = [
|
|
508
502
|
...isOAuth ? ["claude-code-20250219", "oauth-2025-04-20"] : [],
|
|
509
503
|
...options.compaction ? ["compact-2026-01-12"] : [],
|
|
510
|
-
...options.clearToolUses ? ["context-management-2025-06-27"] : []
|
|
504
|
+
...options.clearToolUses ? ["context-management-2025-06-27"] : [],
|
|
505
|
+
"fine-grained-tool-streaming-2025-05-14",
|
|
506
|
+
...!hasAdaptiveThinking ? ["interleaved-thinking-2025-05-14"] : []
|
|
511
507
|
];
|
|
512
508
|
const stream2 = client.messages.stream(params, {
|
|
513
509
|
signal: options.signal ?? void 0,
|
|
@@ -720,26 +716,19 @@ function toError(err) {
|
|
|
720
716
|
|
|
721
717
|
// src/providers/openai.ts
|
|
722
718
|
import OpenAI from "openai";
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
apiKey: options.apiKey,
|
|
730
|
-
...options.baseUrl ? { baseURL: options.baseUrl } : {},
|
|
731
|
-
...options.fetch ? { fetch: options.fetch } : {}
|
|
732
|
-
});
|
|
733
|
-
clientCache2.set(key, client);
|
|
734
|
-
}
|
|
735
|
-
return client;
|
|
719
|
+
function createClient2(options) {
|
|
720
|
+
return new OpenAI({
|
|
721
|
+
apiKey: options.apiKey,
|
|
722
|
+
...options.baseUrl ? { baseURL: options.baseUrl } : {},
|
|
723
|
+
...options.fetch ? { fetch: options.fetch } : {}
|
|
724
|
+
});
|
|
736
725
|
}
|
|
737
726
|
function streamOpenAI(options) {
|
|
738
727
|
return new StreamResult(runStream2(options));
|
|
739
728
|
}
|
|
740
729
|
async function* runStream2(options) {
|
|
741
730
|
const providerName = options.provider ?? "openai";
|
|
742
|
-
const client =
|
|
731
|
+
const client = createClient2(options);
|
|
743
732
|
const usesThinkingParam = options.provider === "glm" || options.provider === "moonshot" || options.provider === "xiaomi";
|
|
744
733
|
const messages = toOpenAIMessages(options.messages, { provider: options.provider });
|
|
745
734
|
const defaultTemp = options.provider === "glm" ? 0.6 : void 0;
|
|
@@ -748,7 +737,7 @@ async function* runStream2(options) {
|
|
|
748
737
|
model: options.model,
|
|
749
738
|
messages,
|
|
750
739
|
stream: true,
|
|
751
|
-
...options.maxTokens ? {
|
|
740
|
+
...options.maxTokens ? { max_completion_tokens: options.maxTokens } : {},
|
|
752
741
|
...effectiveTemp != null && !options.thinking ? { temperature: effectiveTemp } : {},
|
|
753
742
|
...options.topP != null ? { top_p: options.topP } : {},
|
|
754
743
|
...options.stop ? { stop: options.stop } : {},
|
|
@@ -893,6 +882,12 @@ function toError2(err, provider = "openai") {
|
|
|
893
882
|
let msg = err.message;
|
|
894
883
|
const body = err.error;
|
|
895
884
|
if (body) {
|
|
885
|
+
const modelName = body.model || "";
|
|
886
|
+
const _code = body.code || "";
|
|
887
|
+
const message = body.message || "";
|
|
888
|
+
if (modelName === "codex-mini-latest" || message.includes("codex-mini-latest")) {
|
|
889
|
+
msg = `codex-mini-latest requires an OpenAI Pro or Max subscription. You currently have access to GPT-5.4 and GPT-5.4 Mini with your account.`;
|
|
890
|
+
}
|
|
896
891
|
msg += ` | body: ${JSON.stringify(body)}`;
|
|
897
892
|
}
|
|
898
893
|
return new ProviderError(provider, msg, {
|
|
@@ -962,6 +957,11 @@ async function* runStream3(options) {
|
|
|
962
957
|
message += `
|
|
963
958
|
|
|
964
959
|
Hint: Codex models require a ChatGPT Plus ($20/mo) or Pro ($200/mo) subscription. The "codex-spark" variants require ChatGPT Pro. Ensure your account has an active subscription at https://chatgpt.com/settings`;
|
|
960
|
+
}
|
|
961
|
+
if (response.status === 404 && text.includes("does not exist")) {
|
|
962
|
+
message += `
|
|
963
|
+
|
|
964
|
+
Hint: codex-mini-latest requires an OpenAI Pro ($200/mo) or Max subscription. GPT-5.4 and GPT-5.4 Mini work with any active ChatGPT plan.`;
|
|
965
965
|
}
|
|
966
966
|
throw new ProviderError("openai", message, {
|
|
967
967
|
statusCode: response.status
|