@kenkaiiii/gg-core 5.106.1 → 5.107.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
@@ -156,6 +156,7 @@ __export(index_exports, {
156
156
  resample: () => resample,
157
157
  resolveClaudeCodeBinary: () => resolveClaudeCodeBinary,
158
158
  revokeChatGPTSignIn: () => revokeChatGPTSignIn,
159
+ savedChatGPTAccounts: () => savedChatGPTAccounts,
159
160
  setProgressCallback: () => setProgressCallback,
160
161
  setProviderCatalog: () => setProviderCatalog,
161
162
  signInWithClaudeCode: () => signInWithClaudeCode,
@@ -851,21 +852,48 @@ async function getChatGPTHostId(file = defaultHostIdFile()) {
851
852
  await writePrivateFile(file, `urn:uuid:${import_node_crypto2.default.randomUUID()}`);
852
853
  return (await import_promises3.default.readFile(file, "utf-8")).trim();
853
854
  }
854
- async function readRegistration(file) {
855
+ function asRegistration(value) {
856
+ const v = value;
857
+ if (!v || typeof v.clientId !== "string" || typeof v.subject !== "string") return void 0;
858
+ return {
859
+ clientId: v.clientId,
860
+ subject: v.subject,
861
+ ...typeof v.email === "string" && v.email ? { email: v.email } : {},
862
+ ...typeof v.usedAt === "number" ? { usedAt: v.usedAt } : {}
863
+ };
864
+ }
865
+ async function readRegistrations(file) {
855
866
  try {
856
867
  const value = JSON.parse(await import_promises3.default.readFile(file, "utf-8"));
857
- if (typeof value.clientId === "string" && typeof value.subject === "string") {
858
- return { clientId: value.clientId, subject: value.subject };
859
- }
868
+ const list = Array.isArray(value.registrations) ? value.registrations.map(asRegistration) : [asRegistration(value)];
869
+ return list.filter((r) => r !== void 0).sort((a, b) => (b.usedAt ?? 0) - (a.usedAt ?? 0));
860
870
  } catch {
871
+ return [];
861
872
  }
862
- return void 0;
873
+ }
874
+ async function writeRegistrations(file, list) {
875
+ if (list.length === 0) {
876
+ await import_promises3.default.unlink(file).catch(() => {
877
+ });
878
+ return;
879
+ }
880
+ await writePrivateFile(file, JSON.stringify({ registrations: list }));
881
+ }
882
+ async function savedChatGPTAccounts(file = defaultRegistrationFile()) {
883
+ return (await readRegistrations(file)).map((r) => r.email ?? "a ChatGPT account");
884
+ }
885
+ function chooseRegistration(saved, options) {
886
+ if (options.newAccount) return { current: false };
887
+ const own = options.previous?.clientId ? saved.find((r) => r.clientId === options.previous?.clientId) : void 0;
888
+ if (own) return { registration: own, current: true };
889
+ return { registration: saved[0], current: false };
863
890
  }
864
891
  async function loginChatGPT(callbacks, options = {}) {
865
892
  const { signal } = options;
866
893
  const hostId = await getChatGPTHostId(options.hostIdFile);
867
894
  const registrationFile = options.registrationFile ?? defaultRegistrationFile();
868
- const registration = await readRegistration(registrationFile);
895
+ const saved = await readRegistrations(registrationFile);
896
+ const { registration, current } = chooseRegistration(saved, options);
869
897
  let issuedClientId;
870
898
  const signIn = async (status) => {
871
899
  if (signal?.aborted) throw cancelled();
@@ -880,9 +908,10 @@ async function loginChatGPT(callbacks, options = {}) {
880
908
  url.searchParams.set("client_id", knownClientId ?? REGISTRATION_CLIENT_ID);
881
909
  if (!knownClientId) url.searchParams.set("agent_name_hint", AGENT_NAME);
882
910
  url.searchParams.set("ext_agent_host_id", hostId);
883
- if (registration && options.previous?.idToken) {
911
+ if (registration && current && options.previous?.idToken) {
884
912
  url.searchParams.set("id_token_hint", options.previous.idToken);
885
913
  }
914
+ if (registration?.email) url.searchParams.set("login_hint", registration.email);
886
915
  url.searchParams.set("response_type", "code");
887
916
  url.searchParams.set("redirect_uri", redirectUri);
888
917
  url.searchParams.set("scope", SCOPES);
@@ -928,20 +957,24 @@ async function loginChatGPT(callbacks, options = {}) {
928
957
  const subject = String(claims.sub ?? "");
929
958
  if (!subject) throw new Error("ChatGPT ID token has no subject.");
930
959
  if (registration && registration.subject !== subject) {
931
- await import_promises3.default.unlink(registrationFile).catch(() => {
932
- });
960
+ await writeRegistrations(
961
+ registrationFile,
962
+ saved.filter((r) => r.clientId !== registration.clientId)
963
+ );
933
964
  await revokeChatGPTSignIn({ refreshToken: tokens.refreshToken, clientId });
934
965
  throw new Error(
935
- "That was a different ChatGPT account. Continue with ChatGPT again to connect it."
966
+ "That was a different ChatGPT account. Choose Use a different account or workspace to connect it."
936
967
  );
937
968
  }
938
969
  if (!tokens.scopes.includes(CHATGPT_PLAN_SCOPE)) {
939
970
  await revokeChatGPTSignIn({ refreshToken: tokens.refreshToken, clientId });
940
971
  throw new ChatGPTPlanNotEnabledError();
941
972
  }
942
- if (!registration) {
943
- await writePrivateFile(registrationFile, JSON.stringify({ clientId, subject }));
944
- }
973
+ const email = typeof claims.email === "string" ? claims.email : void 0;
974
+ await writeRegistrations(registrationFile, [
975
+ { clientId, subject, ...email ? { email } : {}, usedAt: Date.now() },
976
+ ...saved.filter((r) => r.clientId !== clientId)
977
+ ]);
945
978
  return {
946
979
  accessToken: tokens.accessToken,
947
980
  refreshToken: tokens.refreshToken,
@@ -2342,8 +2375,8 @@ var CLAUDE_FABLE_FAST_BILLING = {
2342
2375
  standardModel: "claude-fable-5-2"
2343
2376
  };
2344
2377
  var XIAOMI_ULTRASPEED_BILLING = {
2345
- label: "bills API Credits",
2346
- detail: "UltraSpeed runs only on your Xiaomi API Credits, billed per token at a higher rate than MiMo-V2.6-Pro, never on the Token Plan.",
2378
+ label: "10x credits",
2379
+ detail: "UltraSpeed uses your Token Plan credits at 10x MiMo-V2.6-Pro's rate (Pro and Max plans only), or bills your API Credits per token at a higher rate.",
2347
2380
  paid: true,
2348
2381
  standardModel: "mimo-v2.6-pro"
2349
2382
  };
@@ -3054,9 +3087,8 @@ var MODELS = [
3054
3087
  authStorageKeys: ["xiaomi", XIAOMI_CREDITS_KEY]
3055
3088
  },
3056
3089
  // UltraSpeed: lower-latency sibling of the Pro flagship, same full-modal
3057
- // capability surface, premium-priced for the throughput gain. API-only —
3058
- // not served over the Token Plan endpoint, so credentials resolve from the
3059
- // distinct API Credits key only (see authStorageKeys doc).
3090
+ // capability surface, premium-priced for the throughput gain. On the Token
3091
+ // Plan (Pro and Max tiers) since 2026-11 at 10x Pro's credit rate.
3060
3092
  {
3061
3093
  id: "mimo-v2.6-pro-ultraspeed",
3062
3094
  name: "MiMo-V2.6-Pro-UltraSpeed",
@@ -3069,7 +3101,7 @@ var MODELS = [
3069
3101
  maxVideoBytes: 36 * 1024 * 1024,
3070
3102
  costTier: "high",
3071
3103
  maxThinkingLevel: "high",
3072
- authStorageKeys: [XIAOMI_CREDITS_KEY],
3104
+ authStorageKeys: ["xiaomi", XIAOMI_CREDITS_KEY],
3073
3105
  billing: XIAOMI_ULTRASPEED_BILLING
3074
3106
  },
3075
3107
  // ── DeepSeek ───────────────────────────────────────────
@@ -4280,7 +4312,7 @@ var ALL_AUTH_PROVIDERS = [
4280
4312
  key: XIAOMI_CREDITS_KEY,
4281
4313
  label: "API Credits",
4282
4314
  kind: "payg",
4283
- billing: "Pay-per-token from MiMo API Credits. Required for UltraSpeed.",
4315
+ billing: "Pay-per-token from MiMo API Credits.",
4284
4316
  baseUrl: "https://api.xiaomimimo.com/v1"
4285
4317
  }
4286
4318
  ],
@@ -5160,6 +5192,7 @@ function createAutoUpdater(config) {
5160
5192
  resample,
5161
5193
  resolveClaudeCodeBinary,
5162
5194
  revokeChatGPTSignIn,
5195
+ savedChatGPTAccounts,
5163
5196
  setProgressCallback,
5164
5197
  setProviderCatalog,
5165
5198
  signInWithClaudeCode,