@kenkaiiii/gg-core 5.94.0 → 5.95.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/README.md +11 -11
- package/dist/{chunk-JLEBGMG4.js → chunk-J7W5HS6X.js} +622 -1105
- package/dist/chunk-J7W5HS6X.js.map +1 -0
- package/dist/index.cjs +816 -1310
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +165 -157
- package/dist/index.d.ts +165 -157
- package/dist/index.js +153 -160
- package/dist/index.js.map +1 -1
- package/dist/model-registry.cjs +57 -75
- package/dist/model-registry.cjs.map +1 -1
- package/dist/model-registry.d.cts +11 -15
- package/dist/model-registry.d.ts +11 -15
- package/dist/model-registry.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-JLEBGMG4.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthStorage,
|
|
3
|
+
CHATGPT_PLAN_BASE_URL,
|
|
4
|
+
CHATGPT_PLAN_NOT_ENABLED_MESSAGE,
|
|
5
|
+
CHATGPT_PLAN_SCOPE,
|
|
6
|
+
CHATGPT_USAGE_URL,
|
|
3
7
|
CLAUDE_CODE_AUTH_KEY,
|
|
4
8
|
CLAUDE_CODE_AUTH_MARKER,
|
|
5
9
|
CLAUDE_CODE_MANIFEST,
|
|
10
|
+
ChatGPTPlanNotEnabledError,
|
|
6
11
|
DEFAULT_MAX_VIDEO_BYTES,
|
|
7
12
|
GEMINI_API_KEY,
|
|
8
13
|
GEMINI_API_KEY_BASE_URL,
|
|
9
14
|
HIDDEN_PROVIDERS,
|
|
15
|
+
KIMI_CODE_DEFAULT_BASE_URL,
|
|
16
|
+
KIMI_CODE_KEY,
|
|
17
|
+
KIMI_CODE_OVERSEAS_BASE_URL,
|
|
10
18
|
LOCAL_AUTH_KEY_PREFIX,
|
|
11
19
|
MINIMAX_CN_BASE_URL,
|
|
12
20
|
MINIMAX_GLOBAL_BASE_URL,
|
|
13
21
|
MODELS,
|
|
14
|
-
MOONSHOT_OAUTH_KEY,
|
|
15
22
|
NotLoggedInError,
|
|
16
|
-
|
|
23
|
+
OPENAI_CHATGPT_KEY,
|
|
24
|
+
RETIRED_SIGN_INS,
|
|
17
25
|
XIAOMI_CREDITS_KEY,
|
|
18
26
|
XIAOMI_TOKEN_PLAN_BASE_URLS,
|
|
27
|
+
apiKeyStorageKeys,
|
|
19
28
|
claudeCodeAuthStatus,
|
|
20
29
|
claudeCodeBinaryPath,
|
|
21
30
|
claudeCodeCallbackUrl,
|
|
@@ -25,16 +34,19 @@ import {
|
|
|
25
34
|
claudeCodePlatformKey,
|
|
26
35
|
clearRuntimeModels,
|
|
27
36
|
closeLogger,
|
|
37
|
+
detectKimiCodeBaseUrl,
|
|
28
38
|
detectMiniMaxBaseUrl,
|
|
29
39
|
detectXiaomiTokenPlanBaseUrl,
|
|
30
40
|
dualAuthProvider,
|
|
31
41
|
dualAuthProviderByOAuthKey,
|
|
32
42
|
ensureClaudeCodeBinary,
|
|
43
|
+
fetchChatGPTPlanModels,
|
|
33
44
|
formatClaudeCodeInstallProgress,
|
|
34
45
|
generatePKCE,
|
|
35
46
|
getAllModels,
|
|
36
47
|
getAuthStorageKey,
|
|
37
48
|
getAuthStorageKeys,
|
|
49
|
+
getChatGPTHostId,
|
|
38
50
|
getContextWindow,
|
|
39
51
|
getDefaultModel,
|
|
40
52
|
getDefaultThinkingLevel,
|
|
@@ -47,40 +59,33 @@ import {
|
|
|
47
59
|
getSummaryModel,
|
|
48
60
|
getToolResultCharLimit,
|
|
49
61
|
getVideoByteLimit,
|
|
50
|
-
grokCliBaseUrl,
|
|
51
|
-
grokCliHeaders,
|
|
52
62
|
isClaudeCodeAuthMarker,
|
|
53
|
-
isGrokCliEndpoint,
|
|
54
63
|
isHiddenProvider,
|
|
55
64
|
isKimiCodingEndpoint,
|
|
56
65
|
isLegacyClaudeOAuth,
|
|
57
66
|
isLoggerOpen,
|
|
58
67
|
isPaidModel,
|
|
59
|
-
kimiCodeBaseUrl,
|
|
60
|
-
kimiCodingHeaders,
|
|
61
68
|
log,
|
|
69
|
+
loginChatGPT,
|
|
62
70
|
loginClaudeCode,
|
|
63
|
-
loginGemini,
|
|
64
|
-
loginKimi,
|
|
65
|
-
loginOpenAI,
|
|
66
|
-
loginXai,
|
|
67
71
|
logoutClaudeCode,
|
|
68
72
|
oauthStorageKey,
|
|
69
73
|
openLog,
|
|
74
|
+
parseCallbackInput,
|
|
70
75
|
providerStorageKeys,
|
|
71
76
|
readStoredBaseUrlSync,
|
|
72
|
-
|
|
73
|
-
refreshKimiToken,
|
|
74
|
-
refreshOpenAIToken,
|
|
75
|
-
refreshXaiToken,
|
|
77
|
+
refreshChatGPTToken,
|
|
76
78
|
registerLogCleanup,
|
|
77
79
|
registerRuntimeModels,
|
|
78
80
|
resolveClaudeCodeBinary,
|
|
81
|
+
revokeChatGPTSignIn,
|
|
79
82
|
setProviderCatalog,
|
|
83
|
+
storageKeyProvider,
|
|
80
84
|
usesOpenAICodexTransport,
|
|
85
|
+
verifyIdToken,
|
|
81
86
|
withFileLock,
|
|
82
87
|
withoutPaidTier
|
|
83
|
-
} from "./chunk-
|
|
88
|
+
} from "./chunk-J7W5HS6X.js";
|
|
84
89
|
import {
|
|
85
90
|
getAppPaths
|
|
86
91
|
} from "./chunk-GXOFTHM5.js";
|
|
@@ -704,6 +709,9 @@ async function signOutOfClaudeCode(auth, opts = {}) {
|
|
|
704
709
|
}
|
|
705
710
|
|
|
706
711
|
// src/auth-providers.ts
|
|
712
|
+
function apiKeyDetails(label, billing, when = "") {
|
|
713
|
+
return { apikey: { method: "apikey", label, billing, when } };
|
|
714
|
+
}
|
|
707
715
|
var ALL_AUTH_PROVIDERS = [
|
|
708
716
|
{
|
|
709
717
|
value: "anthropic",
|
|
@@ -731,89 +739,103 @@ var ALL_AUTH_PROVIDERS = [
|
|
|
731
739
|
value: "openai",
|
|
732
740
|
label: "OpenAI",
|
|
733
741
|
description: "GPT-6 Astra, GPT-6 Astra Fast, GPT-6.1 Sol, GPT-6.1 Sol Fast, GPT-6.1 Terra, GPT-6.1 Terra Fast, GPT-6 Luna, GPT-6 Luna Fast",
|
|
734
|
-
methods: ["oauth"]
|
|
742
|
+
methods: ["oauth", "apikey"],
|
|
743
|
+
apiKeyLabel: "OpenAI",
|
|
744
|
+
methodDetails: {
|
|
745
|
+
oauth: {
|
|
746
|
+
method: "oauth",
|
|
747
|
+
label: "Continue with ChatGPT",
|
|
748
|
+
billing: "Uses your ChatGPT plan.",
|
|
749
|
+
when: "Signs in through OpenAI. Manage what GG Coder may use at chatgpt.com/settings/usage.",
|
|
750
|
+
requires: "A ChatGPT plan."
|
|
751
|
+
},
|
|
752
|
+
apikey: {
|
|
753
|
+
method: "apikey",
|
|
754
|
+
label: "OpenAI API key",
|
|
755
|
+
billing: "Pay-per-token from an OpenAI Platform key.",
|
|
756
|
+
when: "No subscription needed. Covers you while your ChatGPT plan's usage is out."
|
|
757
|
+
}
|
|
758
|
+
}
|
|
735
759
|
},
|
|
736
760
|
{
|
|
737
761
|
value: "gemini",
|
|
738
762
|
label: "Gemini",
|
|
739
763
|
description: "Gemini 3.8 Flash, 3.5 Flash Lite, 3.1 Flash Lite, 3.5 Flash, 3.1 Pro (Preview)",
|
|
740
|
-
methods: ["
|
|
764
|
+
methods: ["apikey"],
|
|
741
765
|
apiKeyLabel: "Gemini",
|
|
742
766
|
apiKeyBaseUrl: GEMINI_API_KEY_BASE_URL,
|
|
743
|
-
// Stored under its own key
|
|
767
|
+
// Stored under its own key: `gemini` held the retired Google sign-in.
|
|
744
768
|
apiKeyVariants: [
|
|
745
|
-
{
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
method: "oauth",
|
|
750
|
-
label: "Sign in with Google",
|
|
751
|
-
billing: "Gemini Code Assist Standard or Enterprise licence.",
|
|
752
|
-
when: "Personal Google accounts are no longer served here (Google ended it on June 18, 2026)."
|
|
753
|
-
},
|
|
754
|
-
apikey: {
|
|
755
|
-
method: "apikey",
|
|
756
|
-
label: "Gemini API key",
|
|
769
|
+
{
|
|
770
|
+
key: GEMINI_API_KEY,
|
|
771
|
+
label: "Google AI Studio",
|
|
772
|
+
kind: "payg",
|
|
757
773
|
billing: "Pay-per-token from a Google AI Studio key.",
|
|
758
|
-
|
|
774
|
+
baseUrl: GEMINI_API_KEY_BASE_URL
|
|
759
775
|
}
|
|
760
|
-
|
|
776
|
+
],
|
|
777
|
+
methodDetails: apiKeyDetails("Gemini API key", "Pay-per-token from a Google AI Studio key.")
|
|
761
778
|
},
|
|
762
779
|
{
|
|
763
780
|
value: "xai",
|
|
764
781
|
label: "xAI (Grok)",
|
|
765
|
-
description: "Grok 4.7
|
|
766
|
-
methods: ["
|
|
782
|
+
description: "Grok 4.7",
|
|
783
|
+
methods: ["apikey"],
|
|
767
784
|
apiKeyLabel: "xAI",
|
|
768
|
-
methodDetails:
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
when: ""
|
|
774
|
-
},
|
|
775
|
-
apikey: {
|
|
776
|
-
method: "apikey",
|
|
777
|
-
label: "xAI API key",
|
|
778
|
-
billing: "Pay-per-token on console.x.ai credits.",
|
|
779
|
-
when: ""
|
|
780
|
-
}
|
|
781
|
-
}
|
|
785
|
+
methodDetails: apiKeyDetails(
|
|
786
|
+
"xAI API key",
|
|
787
|
+
"Pay-per-token from console.x.ai credits.",
|
|
788
|
+
"SuperGrok and X Premium usage is only offered in apps xAI partners with."
|
|
789
|
+
)
|
|
782
790
|
},
|
|
783
791
|
{
|
|
784
792
|
value: "moonshot",
|
|
785
|
-
label: "Moonshot",
|
|
786
|
-
description: "Kimi K3, K2.8 Preview (Kimi
|
|
787
|
-
methods: ["
|
|
788
|
-
apiKeyLabel: "
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
label: "
|
|
793
|
-
|
|
794
|
-
|
|
793
|
+
label: "Kimi (Moonshot)",
|
|
794
|
+
description: "Kimi K3, K2.8 Preview (Kimi Code plan), K2.7 Code, K2.7 Code HighSpeed",
|
|
795
|
+
methods: ["apikey"],
|
|
796
|
+
apiKeyLabel: "Kimi",
|
|
797
|
+
apiKeyVariants: [
|
|
798
|
+
{
|
|
799
|
+
key: KIMI_CODE_KEY,
|
|
800
|
+
label: "Kimi Code plan",
|
|
801
|
+
kind: "plan",
|
|
802
|
+
billing: "Uses your Kimi Code plan. Create the key in the Kimi Code Console."
|
|
795
803
|
},
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
label: "Moonshot API
|
|
799
|
-
|
|
800
|
-
|
|
804
|
+
{
|
|
805
|
+
key: "moonshot",
|
|
806
|
+
label: "Moonshot API",
|
|
807
|
+
kind: "payg",
|
|
808
|
+
billing: "Pay-per-token from platform.moonshot.ai."
|
|
801
809
|
}
|
|
802
|
-
|
|
810
|
+
],
|
|
811
|
+
methodDetails: apiKeyDetails(
|
|
812
|
+
"Kimi API key",
|
|
813
|
+
"A Kimi Code plan key uses your plan; a Moonshot key is pay-per-token."
|
|
814
|
+
)
|
|
803
815
|
},
|
|
804
816
|
{
|
|
805
817
|
value: "glm",
|
|
806
818
|
label: "Z.AI (GLM)",
|
|
807
819
|
description: "GLM-5.3, GLM-5.3-Flash",
|
|
808
820
|
methods: ["apikey"],
|
|
809
|
-
apiKeyLabel: "Z.AI"
|
|
821
|
+
apiKeyLabel: "Z.AI",
|
|
822
|
+
methodDetails: apiKeyDetails(
|
|
823
|
+
"Z.AI API key",
|
|
824
|
+
"Pay-per-token from your Z.AI account balance.",
|
|
825
|
+
"GLM Coding Plan quota can't be used here: Z.AI limits the plan to the tools it lists."
|
|
826
|
+
)
|
|
810
827
|
},
|
|
811
828
|
{
|
|
812
829
|
value: "minimax",
|
|
813
830
|
label: "MiniMax",
|
|
814
831
|
description: "MiniMax M3.1 Flash, M3",
|
|
815
832
|
methods: ["apikey"],
|
|
816
|
-
apiKeyLabel: "MiniMax"
|
|
833
|
+
apiKeyLabel: "MiniMax",
|
|
834
|
+
methodDetails: apiKeyDetails(
|
|
835
|
+
"MiniMax API key",
|
|
836
|
+
"An M Plan key uses your plan; a pay-as-you-go key is pay-per-token.",
|
|
837
|
+
"The key you paste decides which one is billed."
|
|
838
|
+
)
|
|
817
839
|
},
|
|
818
840
|
{
|
|
819
841
|
value: "xiaomi",
|
|
@@ -826,44 +848,66 @@ var ALL_AUTH_PROVIDERS = [
|
|
|
826
848
|
{
|
|
827
849
|
key: "xiaomi",
|
|
828
850
|
label: "Token Plan",
|
|
851
|
+
kind: "plan",
|
|
852
|
+
billing: "Uses your MiMo Token Plan.",
|
|
829
853
|
baseUrl: "https://token-plan-sgp.xiaomimimo.com/v1"
|
|
830
854
|
},
|
|
831
855
|
{
|
|
832
856
|
key: XIAOMI_CREDITS_KEY,
|
|
833
|
-
label: "API Credits
|
|
857
|
+
label: "API Credits",
|
|
858
|
+
kind: "payg",
|
|
859
|
+
billing: "Pay-per-token from MiMo API Credits. Required for UltraSpeed.",
|
|
834
860
|
baseUrl: "https://api.xiaomimimo.com/v1"
|
|
835
861
|
}
|
|
836
|
-
]
|
|
862
|
+
],
|
|
863
|
+
methodDetails: apiKeyDetails(
|
|
864
|
+
"Xiaomi MiMo API key",
|
|
865
|
+
"A Token Plan key uses your plan; an API Credits key is pay-per-token."
|
|
866
|
+
)
|
|
837
867
|
},
|
|
838
868
|
{
|
|
839
869
|
value: "deepseek",
|
|
840
870
|
label: "DeepSeek",
|
|
841
871
|
description: "DeepSeek V4 Pro, V4.1 Flash",
|
|
842
872
|
methods: ["apikey"],
|
|
843
|
-
apiKeyLabel: "DeepSeek"
|
|
873
|
+
apiKeyLabel: "DeepSeek",
|
|
874
|
+
methodDetails: apiKeyDetails("DeepSeek API key", "Pay-per-token from platform.deepseek.com.")
|
|
844
875
|
},
|
|
845
876
|
{
|
|
846
877
|
value: "sakana",
|
|
847
878
|
label: "Sakana (Fugu)",
|
|
848
879
|
description: "Fugu, Fugu Max, Fugu Ultra",
|
|
849
880
|
methods: ["apikey"],
|
|
850
|
-
apiKeyLabel: "Sakana"
|
|
881
|
+
apiKeyLabel: "Sakana",
|
|
882
|
+
methodDetails: apiKeyDetails("Sakana API key", "Pay-per-token from your Sakana API account.")
|
|
851
883
|
},
|
|
852
884
|
{
|
|
853
885
|
value: "openrouter",
|
|
854
886
|
label: "OpenRouter",
|
|
855
887
|
description: "Qwen3.8 Max \xB7 multi-provider gateway",
|
|
856
888
|
methods: ["apikey"],
|
|
857
|
-
apiKeyLabel: "OpenRouter"
|
|
889
|
+
apiKeyLabel: "OpenRouter",
|
|
890
|
+
methodDetails: apiKeyDetails("OpenRouter API key", "Pay-per-token from OpenRouter credits.")
|
|
858
891
|
},
|
|
859
892
|
{
|
|
860
893
|
value: "huggingface",
|
|
861
894
|
label: "Hugging Face",
|
|
862
895
|
description: "Kimi K2.7 Code, DeepSeek V4.1 Flash, GPT-OSS 120B",
|
|
863
896
|
methods: ["apikey"],
|
|
864
|
-
apiKeyLabel: "Hugging Face"
|
|
897
|
+
apiKeyLabel: "Hugging Face",
|
|
898
|
+
methodDetails: apiKeyDetails(
|
|
899
|
+
"Hugging Face token",
|
|
900
|
+
"Pay-per-token from Hugging Face Inference Providers credits."
|
|
901
|
+
)
|
|
865
902
|
}
|
|
866
903
|
];
|
|
904
|
+
function requiredKeyLabel(provider, storageKeys) {
|
|
905
|
+
const variants = ALL_AUTH_PROVIDERS.find((p) => p.value === provider)?.apiKeyVariants ?? [];
|
|
906
|
+
const needed = variants.filter((v) => storageKeys.includes(v.key));
|
|
907
|
+
if (needed.length === 0 || needed.length === variants.length) return void 0;
|
|
908
|
+
const names = needed.map((v) => v.label).join(" or ");
|
|
909
|
+
return `Needs ${/^[aeiou]/i.test(names) ? "an" : "a"} ${names} key`;
|
|
910
|
+
}
|
|
867
911
|
var AUTH_PROVIDERS = ALL_AUTH_PROVIDERS.filter(
|
|
868
912
|
(p) => !isHiddenProvider(p.value)
|
|
869
913
|
);
|
|
@@ -890,18 +934,24 @@ function describeAuthMethods(provider) {
|
|
|
890
934
|
});
|
|
891
935
|
}
|
|
892
936
|
function authPriorityNote(provider) {
|
|
893
|
-
if (provider === "gemini") {
|
|
894
|
-
return "Uses the Gemini API key first when one is set; otherwise the Google sign-in.";
|
|
895
|
-
}
|
|
896
937
|
if (provider === "anthropic") {
|
|
897
938
|
return "Uses Sign in with Claude while you are signed in; otherwise the Anthropic API key.";
|
|
898
939
|
}
|
|
899
940
|
const dual = dualAuthProvider(provider);
|
|
900
|
-
if (
|
|
901
|
-
|
|
941
|
+
if (dual) {
|
|
942
|
+
return `Uses your ${dual.oauthLabel} first; the ${dual.apiKeyLabel} takes over while its usage is out, then switches back.`;
|
|
943
|
+
}
|
|
944
|
+
const variants = getAuthProvider(provider)?.apiKeyVariants;
|
|
945
|
+
const plan = variants?.find((v) => v.kind === "plan");
|
|
946
|
+
const payg = variants?.find((v) => v.kind === "payg");
|
|
947
|
+
if (plan && payg) {
|
|
948
|
+
return `Uses the ${plan.label} key first when both are set; the ${payg.label} key covers models the plan doesn't include.`;
|
|
949
|
+
}
|
|
950
|
+
return void 0;
|
|
902
951
|
}
|
|
903
952
|
|
|
904
953
|
// src/provider-usage.ts
|
|
954
|
+
import { GG_CODER_USER_AGENT } from "@kenkaiiii/gg-ai";
|
|
905
955
|
var SubscriptionUsageError = class extends Error {
|
|
906
956
|
constructor(message, status, retryAfterMs2) {
|
|
907
957
|
super(message);
|
|
@@ -910,51 +960,14 @@ var SubscriptionUsageError = class extends Error {
|
|
|
910
960
|
this.name = "SubscriptionUsageError";
|
|
911
961
|
}
|
|
912
962
|
};
|
|
913
|
-
var CODEX_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
|
|
914
963
|
function finiteNumber(value) {
|
|
915
964
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
916
965
|
}
|
|
917
|
-
function clampPercent(value) {
|
|
918
|
-
const number = finiteNumber(value);
|
|
919
|
-
return number === void 0 ? void 0 : Math.min(100, Math.max(0, number));
|
|
920
|
-
}
|
|
921
966
|
function isoTimestamp(value) {
|
|
922
967
|
if (typeof value !== "string" || !value.trim()) return void 0;
|
|
923
968
|
const timestamp = Date.parse(value);
|
|
924
969
|
return Number.isFinite(timestamp) ? timestamp : void 0;
|
|
925
970
|
}
|
|
926
|
-
function unixTimestamp(value) {
|
|
927
|
-
const seconds = finiteNumber(value);
|
|
928
|
-
return seconds === void 0 ? void 0 : seconds * 1e3;
|
|
929
|
-
}
|
|
930
|
-
function codexResetAt(window, now) {
|
|
931
|
-
const absolute = unixTimestamp(window.reset_at);
|
|
932
|
-
if (absolute !== void 0) return absolute;
|
|
933
|
-
const afterSeconds = finiteNumber(window.reset_after_seconds);
|
|
934
|
-
return afterSeconds === void 0 ? void 0 : now + afterSeconds * 1e3;
|
|
935
|
-
}
|
|
936
|
-
function currentWindowLabel(seconds, fallbackHours) {
|
|
937
|
-
const duration = finiteNumber(seconds);
|
|
938
|
-
const hours = Math.max(1, Math.round((duration ?? fallbackHours * 3600) / 3600));
|
|
939
|
-
return `${hours}-hour`;
|
|
940
|
-
}
|
|
941
|
-
function codexWindowKind(window, fallback) {
|
|
942
|
-
const duration = finiteNumber(window.limit_window_seconds);
|
|
943
|
-
if (duration === void 0) return fallback;
|
|
944
|
-
return duration >= 6 * 24 * 60 * 60 ? "weekly" : "current";
|
|
945
|
-
}
|
|
946
|
-
function normalizedCodexWindow(window, fallbackKind, now) {
|
|
947
|
-
if (!window) return null;
|
|
948
|
-
const usedPercent = clampPercent(window.used_percent);
|
|
949
|
-
if (usedPercent === void 0) return null;
|
|
950
|
-
const kind = codexWindowKind(window, fallbackKind);
|
|
951
|
-
return {
|
|
952
|
-
kind,
|
|
953
|
-
label: kind === "weekly" ? "Weekly" : currentWindowLabel(window.limit_window_seconds, 5),
|
|
954
|
-
usedPercent,
|
|
955
|
-
resetsAt: codexResetAt(window, now)
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
971
|
function retryAfterMs(response, now) {
|
|
959
972
|
const value = response.headers.get("retry-after")?.trim();
|
|
960
973
|
if (!value) return void 0;
|
|
@@ -977,31 +990,6 @@ async function readUsageResponse(response, now) {
|
|
|
977
990
|
throw new SubscriptionUsageError("Subscription usage response was not valid JSON");
|
|
978
991
|
}
|
|
979
992
|
}
|
|
980
|
-
async function fetchCodexUsage(credentials, fetchFn, signal, now) {
|
|
981
|
-
const headers = {
|
|
982
|
-
Authorization: `Bearer ${credentials.accessToken}`,
|
|
983
|
-
Accept: "application/json",
|
|
984
|
-
originator: "ggcoder",
|
|
985
|
-
"User-Agent": "ggcoder"
|
|
986
|
-
};
|
|
987
|
-
if (credentials.accountId) headers["ChatGPT-Account-Id"] = credentials.accountId;
|
|
988
|
-
const response = await fetchFn(CODEX_USAGE_URL, { method: "GET", signal, headers });
|
|
989
|
-
const data = await readUsageResponse(response, now());
|
|
990
|
-
const windows = [
|
|
991
|
-
normalizedCodexWindow(data.rate_limit?.primary_window, "current", now()),
|
|
992
|
-
normalizedCodexWindow(data.rate_limit?.secondary_window, "weekly", now())
|
|
993
|
-
].filter((window) => window !== null);
|
|
994
|
-
windows.sort((left, right) => {
|
|
995
|
-
if (left.kind === right.kind) return 0;
|
|
996
|
-
return left.kind === "current" ? -1 : 1;
|
|
997
|
-
});
|
|
998
|
-
return {
|
|
999
|
-
provider: "openai",
|
|
1000
|
-
displayName: "Codex",
|
|
1001
|
-
windows,
|
|
1002
|
-
fetchedAt: now()
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
993
|
function kimiNumber(value) {
|
|
1006
994
|
if (typeof value === "string" && value.trim()) {
|
|
1007
995
|
const parsed = Number(value);
|
|
@@ -1032,15 +1020,14 @@ function kimiWindowMinutes(window) {
|
|
|
1032
1020
|
}
|
|
1033
1021
|
}
|
|
1034
1022
|
async function fetchKimiUsage(credentials, fetchFn, signal, now) {
|
|
1035
|
-
const
|
|
1023
|
+
const baseUrl = (credentials.baseUrl ?? KIMI_CODE_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1024
|
+
const response = await fetchFn(`${baseUrl}/usages`, {
|
|
1036
1025
|
method: "GET",
|
|
1037
1026
|
signal,
|
|
1038
1027
|
headers: {
|
|
1039
1028
|
Authorization: "Bearer " + credentials.accessToken,
|
|
1040
1029
|
Accept: "application/json",
|
|
1041
|
-
|
|
1042
|
-
// same as model requests.
|
|
1043
|
-
...kimiCodingHeaders()
|
|
1030
|
+
"User-Agent": GG_CODER_USER_AGENT
|
|
1044
1031
|
}
|
|
1045
1032
|
});
|
|
1046
1033
|
const data = await readUsageResponse(response, now());
|
|
@@ -1092,7 +1079,7 @@ async function fetchSubscriptionUsage(provider, credentials, options = {}) {
|
|
|
1092
1079
|
const now = options.now ?? Date.now;
|
|
1093
1080
|
const signal = AbortSignal.timeout(options.timeoutMs ?? 8e3);
|
|
1094
1081
|
try {
|
|
1095
|
-
return
|
|
1082
|
+
return await fetchKimiUsage(credentials, fetchFn, signal, now);
|
|
1096
1083
|
} catch (error) {
|
|
1097
1084
|
if (error instanceof SubscriptionUsageError) throw error;
|
|
1098
1085
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1598,29 +1585,38 @@ function createAutoUpdater(config) {
|
|
|
1598
1585
|
export {
|
|
1599
1586
|
AUTH_PROVIDERS,
|
|
1600
1587
|
AuthStorage,
|
|
1588
|
+
CHATGPT_PLAN_BASE_URL,
|
|
1589
|
+
CHATGPT_PLAN_NOT_ENABLED_MESSAGE,
|
|
1590
|
+
CHATGPT_PLAN_SCOPE,
|
|
1591
|
+
CHATGPT_USAGE_URL,
|
|
1601
1592
|
CLAUDE_CODE_AUTH_KEY,
|
|
1602
1593
|
CLAUDE_CODE_AUTH_MARKER,
|
|
1603
1594
|
CLAUDE_CODE_MANIFEST,
|
|
1595
|
+
ChatGPTPlanNotEnabledError,
|
|
1604
1596
|
DEFAULT_LOCAL_ENDPOINTS,
|
|
1605
1597
|
DEFAULT_MAX_VIDEO_BYTES,
|
|
1606
1598
|
FALLBACK_CONTEXT_WINDOW,
|
|
1607
1599
|
GEMINI_API_KEY,
|
|
1608
1600
|
GEMINI_API_KEY_BASE_URL,
|
|
1609
1601
|
HIDDEN_PROVIDERS,
|
|
1602
|
+
KIMI_CODE_DEFAULT_BASE_URL,
|
|
1603
|
+
KIMI_CODE_KEY,
|
|
1604
|
+
KIMI_CODE_OVERSEAS_BASE_URL,
|
|
1610
1605
|
LOCAL_API_KEY_PLACEHOLDER,
|
|
1611
1606
|
LOCAL_AUTH_KEY_PREFIX,
|
|
1612
1607
|
MINIMAX_CN_BASE_URL,
|
|
1613
1608
|
MINIMAX_GLOBAL_BASE_URL,
|
|
1614
1609
|
MODELS,
|
|
1615
|
-
MOONSHOT_OAUTH_KEY,
|
|
1616
1610
|
NotLoggedInError,
|
|
1611
|
+
OPENAI_CHATGPT_KEY,
|
|
1617
1612
|
OPENROUTER_DEFAULT_BASE_URL,
|
|
1618
1613
|
PLAN_MODE_THINKING_CAP,
|
|
1614
|
+
RETIRED_SIGN_INS,
|
|
1619
1615
|
SubscriptionUsageError,
|
|
1620
1616
|
TelegramBot,
|
|
1621
|
-
XAI_OAUTH_KEY,
|
|
1622
1617
|
XIAOMI_CREDITS_KEY,
|
|
1623
1618
|
XIAOMI_TOKEN_PLAN_BASE_URLS,
|
|
1619
|
+
apiKeyStorageKeys,
|
|
1624
1620
|
authPriorityNote,
|
|
1625
1621
|
clampThinkingForPlanMode,
|
|
1626
1622
|
claudeCodeAuthStatus,
|
|
@@ -1637,6 +1633,7 @@ export {
|
|
|
1637
1633
|
createAutoUpdater,
|
|
1638
1634
|
decodeOggOpus,
|
|
1639
1635
|
describeAuthMethods,
|
|
1636
|
+
detectKimiCodeBaseUrl,
|
|
1640
1637
|
detectMiniMaxBaseUrl,
|
|
1641
1638
|
detectXiaomiTokenPlanBaseUrl,
|
|
1642
1639
|
discoverLocalModels,
|
|
@@ -1645,6 +1642,7 @@ export {
|
|
|
1645
1642
|
dualAuthProviderByOAuthKey,
|
|
1646
1643
|
endpointRoot,
|
|
1647
1644
|
ensureClaudeCodeBinary,
|
|
1645
|
+
fetchChatGPTPlanModels,
|
|
1648
1646
|
fetchSubscriptionUsage,
|
|
1649
1647
|
findProbedModel,
|
|
1650
1648
|
formatClaudeCodeInstallProgress,
|
|
@@ -1655,6 +1653,7 @@ export {
|
|
|
1655
1653
|
getAuthProvider,
|
|
1656
1654
|
getAuthStorageKey,
|
|
1657
1655
|
getAuthStorageKeys,
|
|
1656
|
+
getChatGPTHostId,
|
|
1658
1657
|
getContextWindow,
|
|
1659
1658
|
getDefaultModel,
|
|
1660
1659
|
getDefaultThinkingLevel,
|
|
@@ -1670,10 +1669,7 @@ export {
|
|
|
1670
1669
|
getSupportedThinkingLevels,
|
|
1671
1670
|
getToolResultCharLimit,
|
|
1672
1671
|
getVideoByteLimit,
|
|
1673
|
-
grokCliBaseUrl,
|
|
1674
|
-
grokCliHeaders,
|
|
1675
1672
|
isClaudeCodeAuthMarker,
|
|
1676
|
-
isGrokCliEndpoint,
|
|
1677
1673
|
isHiddenProvider,
|
|
1678
1674
|
isKimiCodingEndpoint,
|
|
1679
1675
|
isLegacyClaudeOAuth,
|
|
@@ -1682,21 +1678,17 @@ export {
|
|
|
1682
1678
|
isModelLoaded,
|
|
1683
1679
|
isPaidModel,
|
|
1684
1680
|
isThinkingLevelSupported,
|
|
1685
|
-
kimiCodeBaseUrl,
|
|
1686
|
-
kimiCodingHeaders,
|
|
1687
1681
|
localAuthStorageKey,
|
|
1688
1682
|
localModelShortName,
|
|
1689
1683
|
log,
|
|
1684
|
+
loginChatGPT,
|
|
1690
1685
|
loginClaudeCode,
|
|
1691
|
-
loginGemini,
|
|
1692
|
-
loginKimi,
|
|
1693
|
-
loginOpenAI,
|
|
1694
|
-
loginXai,
|
|
1695
1686
|
logoutClaudeCode,
|
|
1696
1687
|
mergeClaudeCodeRateLimit,
|
|
1697
1688
|
oauthStorageKey,
|
|
1698
1689
|
ollamaServedContext,
|
|
1699
1690
|
openLog,
|
|
1691
|
+
parseCallbackInput,
|
|
1700
1692
|
parseLocalModelId,
|
|
1701
1693
|
parseOpenRouterCatalog,
|
|
1702
1694
|
probeEndpoint,
|
|
@@ -1704,21 +1696,22 @@ export {
|
|
|
1704
1696
|
readClaudeCodeUsage,
|
|
1705
1697
|
readStoredBaseUrlSync,
|
|
1706
1698
|
recordClaudeCodeRateLimit,
|
|
1707
|
-
|
|
1708
|
-
refreshKimiToken,
|
|
1709
|
-
refreshOpenAIToken,
|
|
1710
|
-
refreshXaiToken,
|
|
1699
|
+
refreshChatGPTToken,
|
|
1711
1700
|
registerLogCleanup,
|
|
1712
1701
|
registerRuntimeModels,
|
|
1702
|
+
requiredKeyLabel,
|
|
1713
1703
|
resample,
|
|
1714
1704
|
resolveClaudeCodeBinary,
|
|
1705
|
+
revokeChatGPTSignIn,
|
|
1715
1706
|
setProgressCallback,
|
|
1716
1707
|
setProviderCatalog,
|
|
1717
1708
|
signInWithClaudeCode,
|
|
1718
1709
|
signOutOfClaudeCode,
|
|
1710
|
+
storageKeyProvider,
|
|
1719
1711
|
toModelInfo,
|
|
1720
1712
|
transcribeVoice,
|
|
1721
1713
|
usesOpenAICodexTransport,
|
|
1714
|
+
verifyIdToken,
|
|
1722
1715
|
withFileLock,
|
|
1723
1716
|
withoutPaidTier
|
|
1724
1717
|
};
|