@kenkaiiii/gg-core 4.9.0 → 4.10.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/{chunk-227IRQAU.js → chunk-RBR3MTVM.js} +4 -4
- package/dist/chunk-RBR3MTVM.js.map +1 -0
- package/dist/index.cjs +19 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/model-registry.cjs +3 -3
- package/dist/model-registry.cjs.map +1 -1
- package/dist/model-registry.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-227IRQAU.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
getSummaryModel,
|
|
10
10
|
getVideoByteLimit,
|
|
11
11
|
usesOpenAICodexTransport
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-RBR3MTVM.js";
|
|
13
13
|
import {
|
|
14
14
|
getAppPaths
|
|
15
15
|
} from "./chunk-TZNVRILI.js";
|
|
@@ -1060,14 +1060,15 @@ function errorDetail(data) {
|
|
|
1060
1060
|
const desc = data.error_description ?? data.message ?? data.error;
|
|
1061
1061
|
return typeof desc === "string" && desc.length > 0 ? desc : "unknown error";
|
|
1062
1062
|
}
|
|
1063
|
-
function credsFromTokenResponse(data) {
|
|
1063
|
+
function credsFromTokenResponse(data, opts) {
|
|
1064
1064
|
const accessToken = data.access_token;
|
|
1065
|
-
const
|
|
1065
|
+
const responseRefreshToken = data.refresh_token;
|
|
1066
1066
|
const expiresIn = Number(data.expires_in);
|
|
1067
1067
|
if (typeof accessToken !== "string" || accessToken.length === 0) {
|
|
1068
1068
|
throw new Error("Kimi OAuth response missing access_token.");
|
|
1069
1069
|
}
|
|
1070
|
-
|
|
1070
|
+
const refreshToken = typeof responseRefreshToken === "string" && responseRefreshToken.length > 0 ? responseRefreshToken : opts?.fallbackRefreshToken ?? "";
|
|
1071
|
+
if (refreshToken.length === 0) {
|
|
1071
1072
|
throw new Error("Kimi OAuth response missing refresh_token.");
|
|
1072
1073
|
}
|
|
1073
1074
|
if (!Number.isFinite(expiresIn) || expiresIn <= 0) {
|
|
@@ -1164,7 +1165,7 @@ async function refreshKimiToken(refreshToken) {
|
|
|
1164
1165
|
refresh_token: refreshToken
|
|
1165
1166
|
});
|
|
1166
1167
|
if (status === 200 && typeof data.access_token === "string") {
|
|
1167
|
-
return credsFromTokenResponse(data);
|
|
1168
|
+
return credsFromTokenResponse(data, { fallbackRefreshToken: refreshToken });
|
|
1168
1169
|
}
|
|
1169
1170
|
const errorCode = typeof data.error === "string" ? data.error : "";
|
|
1170
1171
|
throw new Error(`Kimi token refresh failed (${status}): ${errorCode || errorDetail(data)}`);
|
|
@@ -1172,6 +1173,7 @@ async function refreshKimiToken(refreshToken) {
|
|
|
1172
1173
|
|
|
1173
1174
|
// src/auth-storage.ts
|
|
1174
1175
|
var MOONSHOT_OAUTH_KEY = "moonshot-oauth";
|
|
1176
|
+
var REFRESH_SKEW_MS = 6e4;
|
|
1175
1177
|
var STATIC_API_KEY_PROVIDERS = /* @__PURE__ */ new Set([
|
|
1176
1178
|
"glm",
|
|
1177
1179
|
"moonshot",
|
|
@@ -1286,6 +1288,11 @@ var AuthStorage = class {
|
|
|
1286
1288
|
return await this.resolveCredentials(MOONSHOT_OAUTH_KEY, opts);
|
|
1287
1289
|
} catch (err) {
|
|
1288
1290
|
if (err instanceof NotLoggedInError && this.data["moonshot"]) {
|
|
1291
|
+
log(
|
|
1292
|
+
"WARN",
|
|
1293
|
+
"auth",
|
|
1294
|
+
'Kimi OAuth credential is no longer valid \u2014 falling back to the Moonshot API key. Run "ggcoder login" and choose Kimi OAuth to restore OAuth auth.'
|
|
1295
|
+
);
|
|
1289
1296
|
return this.data["moonshot"];
|
|
1290
1297
|
}
|
|
1291
1298
|
throw err;
|
|
@@ -1298,7 +1305,7 @@ var AuthStorage = class {
|
|
|
1298
1305
|
if (STATIC_API_KEY_PROVIDERS.has(provider)) {
|
|
1299
1306
|
return creds;
|
|
1300
1307
|
}
|
|
1301
|
-
if (!opts?.forceRefresh && Date.now() < creds.expiresAt) {
|
|
1308
|
+
if (!opts?.forceRefresh && Date.now() < creds.expiresAt - REFRESH_SKEW_MS) {
|
|
1302
1309
|
return creds;
|
|
1303
1310
|
}
|
|
1304
1311
|
const existing = this.refreshLocks.get(provider);
|
|
@@ -1308,7 +1315,7 @@ var AuthStorage = class {
|
|
|
1308
1315
|
const content = await fs4.readFile(this.filePath, "utf-8");
|
|
1309
1316
|
const freshData = JSON.parse(content);
|
|
1310
1317
|
const freshCreds = freshData[provider];
|
|
1311
|
-
if (freshCreds && !opts?.forceRefresh && Date.now() < freshCreds.expiresAt) {
|
|
1318
|
+
if (freshCreds && !opts?.forceRefresh && Date.now() < freshCreds.expiresAt - REFRESH_SKEW_MS) {
|
|
1312
1319
|
this.data[provider] = freshCreds;
|
|
1313
1320
|
return freshCreds;
|
|
1314
1321
|
}
|
|
@@ -1334,6 +1341,9 @@ var AuthStorage = class {
|
|
|
1334
1341
|
if (!refreshed.projectId && creds.projectId) {
|
|
1335
1342
|
refreshed.projectId = creds.projectId;
|
|
1336
1343
|
}
|
|
1344
|
+
if (!refreshed.baseUrl && creds.baseUrl) {
|
|
1345
|
+
refreshed.baseUrl = creds.baseUrl;
|
|
1346
|
+
}
|
|
1337
1347
|
this.data[provider] = refreshed;
|
|
1338
1348
|
await atomicWriteFile(this.filePath, JSON.stringify(this.data, null, 2));
|
|
1339
1349
|
return refreshed;
|