@kenkaiiii/gg-ai 4.3.6 → 4.3.8
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.cjs
CHANGED
|
@@ -472,36 +472,29 @@ function normalizeOpenAIStopReason(reason) {
|
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
// src/providers/anthropic.ts
|
|
475
|
-
|
|
476
|
-
function getOrCreateClient(options) {
|
|
475
|
+
function createClient(options) {
|
|
477
476
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
} : {}
|
|
495
|
-
});
|
|
496
|
-
clientCache.set(key, client);
|
|
497
|
-
}
|
|
498
|
-
return client;
|
|
477
|
+
return new import_sdk.default({
|
|
478
|
+
...isOAuth ? { apiKey: null, authToken: options.apiKey } : { apiKey: options.apiKey },
|
|
479
|
+
...options.baseUrl ? { baseURL: options.baseUrl } : {},
|
|
480
|
+
...options.fetch ? { fetch: options.fetch } : {},
|
|
481
|
+
// Allow SDK retries for connection-level failures (socket hang up, 500s,
|
|
482
|
+
// connection refused). Our stall detection handles abort-initiated retries
|
|
483
|
+
// separately — SDK retries only fire on genuine transport errors.
|
|
484
|
+
maxRetries: 2,
|
|
485
|
+
...isOAuth ? {
|
|
486
|
+
defaultHeaders: {
|
|
487
|
+
"user-agent": "claude-cli/2.1.75",
|
|
488
|
+
"x-app": "cli"
|
|
489
|
+
}
|
|
490
|
+
} : {}
|
|
491
|
+
});
|
|
499
492
|
}
|
|
500
493
|
function streamAnthropic(options) {
|
|
501
494
|
return new StreamResult(runStream(options));
|
|
502
495
|
}
|
|
503
496
|
async function* runStream(options) {
|
|
504
|
-
const client =
|
|
497
|
+
const client = createClient(options);
|
|
505
498
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
506
499
|
const cacheControl = toAnthropicCacheControl(options.cacheRetention, options.baseUrl);
|
|
507
500
|
const { system: rawSystem, messages } = toAnthropicMessages(options.messages, cacheControl);
|
|
@@ -550,10 +543,13 @@ async function* runStream(options) {
|
|
|
550
543
|
})(),
|
|
551
544
|
stream: true
|
|
552
545
|
};
|
|
546
|
+
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");
|
|
553
547
|
const betaHeaders = [
|
|
554
548
|
...isOAuth ? ["claude-code-20250219", "oauth-2025-04-20"] : [],
|
|
555
549
|
...options.compaction ? ["compact-2026-01-12"] : [],
|
|
556
|
-
...options.clearToolUses ? ["context-management-2025-06-27"] : []
|
|
550
|
+
...options.clearToolUses ? ["context-management-2025-06-27"] : [],
|
|
551
|
+
"fine-grained-tool-streaming-2025-05-14",
|
|
552
|
+
...!hasAdaptiveThinking ? ["interleaved-thinking-2025-05-14"] : []
|
|
557
553
|
];
|
|
558
554
|
const stream2 = client.messages.stream(params, {
|
|
559
555
|
signal: options.signal ?? void 0,
|
|
@@ -766,26 +762,19 @@ function toError(err) {
|
|
|
766
762
|
|
|
767
763
|
// src/providers/openai.ts
|
|
768
764
|
var import_openai = __toESM(require("openai"), 1);
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
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;
|
|
765
|
+
function createClient2(options) {
|
|
766
|
+
return new import_openai.default({
|
|
767
|
+
apiKey: options.apiKey,
|
|
768
|
+
...options.baseUrl ? { baseURL: options.baseUrl } : {},
|
|
769
|
+
...options.fetch ? { fetch: options.fetch } : {}
|
|
770
|
+
});
|
|
782
771
|
}
|
|
783
772
|
function streamOpenAI(options) {
|
|
784
773
|
return new StreamResult(runStream2(options));
|
|
785
774
|
}
|
|
786
775
|
async function* runStream2(options) {
|
|
787
776
|
const providerName = options.provider ?? "openai";
|
|
788
|
-
const client =
|
|
777
|
+
const client = createClient2(options);
|
|
789
778
|
const usesThinkingParam = options.provider === "glm" || options.provider === "moonshot" || options.provider === "xiaomi";
|
|
790
779
|
const messages = toOpenAIMessages(options.messages, { provider: options.provider });
|
|
791
780
|
const defaultTemp = options.provider === "glm" ? 0.6 : void 0;
|
|
@@ -794,7 +783,7 @@ async function* runStream2(options) {
|
|
|
794
783
|
model: options.model,
|
|
795
784
|
messages,
|
|
796
785
|
stream: true,
|
|
797
|
-
...options.maxTokens ? {
|
|
786
|
+
...options.maxTokens ? { max_completion_tokens: options.maxTokens } : {},
|
|
798
787
|
...effectiveTemp != null && !options.thinking ? { temperature: effectiveTemp } : {},
|
|
799
788
|
...options.topP != null ? { top_p: options.topP } : {},
|
|
800
789
|
...options.stop ? { stop: options.stop } : {},
|
|
@@ -939,6 +928,12 @@ function toError2(err, provider = "openai") {
|
|
|
939
928
|
let msg = err.message;
|
|
940
929
|
const body = err.error;
|
|
941
930
|
if (body) {
|
|
931
|
+
const modelName = body.model || "";
|
|
932
|
+
const _code = body.code || "";
|
|
933
|
+
const message = body.message || "";
|
|
934
|
+
if (modelName === "codex-mini-latest" || message.includes("codex-mini-latest")) {
|
|
935
|
+
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.`;
|
|
936
|
+
}
|
|
942
937
|
msg += ` | body: ${JSON.stringify(body)}`;
|
|
943
938
|
}
|
|
944
939
|
return new ProviderError(provider, msg, {
|
|
@@ -1008,6 +1003,11 @@ async function* runStream3(options) {
|
|
|
1008
1003
|
message += `
|
|
1009
1004
|
|
|
1010
1005
|
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`;
|
|
1006
|
+
}
|
|
1007
|
+
if (response.status === 404 && text.includes("does not exist")) {
|
|
1008
|
+
message += `
|
|
1009
|
+
|
|
1010
|
+
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.`;
|
|
1011
1011
|
}
|
|
1012
1012
|
throw new ProviderError("openai", message, {
|
|
1013
1013
|
statusCode: response.status
|