@kenkaiiii/gg-core 5.69.0 → 5.71.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-7WTRAERP.js → chunk-Y3AHAB37.js} +39 -25
- package/dist/chunk-Y3AHAB37.js.map +1 -0
- package/dist/index.cjs +70 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +35 -12
- package/dist/index.js.map +1 -1
- package/dist/model-registry.cjs +11 -17
- package/dist/model-registry.cjs.map +1 -1
- package/dist/model-registry.d.cts +11 -19
- package/dist/model-registry.d.ts +11 -19
- package/dist/model-registry.js +1 -3
- package/package.json +2 -2
- package/dist/chunk-7WTRAERP.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -68,7 +68,7 @@ __export(index_exports, {
|
|
|
68
68
|
getContextWindow: () => getContextWindow,
|
|
69
69
|
getDefaultModel: () => getDefaultModel,
|
|
70
70
|
getDefaultThinkingLevel: () => getDefaultThinkingLevel,
|
|
71
|
-
|
|
71
|
+
getLowestThinkingLevel: () => getLowestThinkingLevel,
|
|
72
72
|
getMaxThinkingLevel: () => getMaxThinkingLevel,
|
|
73
73
|
getModel: () => getModel,
|
|
74
74
|
getModelsForProvider: () => getModelsForProvider,
|
|
@@ -150,6 +150,12 @@ function getAppPaths() {
|
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
// src/oauth/request-timeout.ts
|
|
154
|
+
var OAUTH_REQUEST_TIMEOUT_MS = 3e4;
|
|
155
|
+
function oauthRequestSignal() {
|
|
156
|
+
return AbortSignal.timeout(OAUTH_REQUEST_TIMEOUT_MS);
|
|
157
|
+
}
|
|
158
|
+
|
|
153
159
|
// src/oauth/kimi.ts
|
|
154
160
|
var CLIENT_ID = "17e5f671-d194-4dfb-9706-5516cb48c098";
|
|
155
161
|
var DEFAULT_OAUTH_HOST = "https://auth.kimi.com";
|
|
@@ -237,7 +243,8 @@ async function postForm(endpoint, params) {
|
|
|
237
243
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
238
244
|
Accept: "application/json"
|
|
239
245
|
},
|
|
240
|
-
body: new URLSearchParams(params).toString()
|
|
246
|
+
body: new URLSearchParams(params).toString(),
|
|
247
|
+
signal: oauthRequestSignal()
|
|
241
248
|
});
|
|
242
249
|
let data = {};
|
|
243
250
|
try {
|
|
@@ -625,7 +632,12 @@ async function postTokenRequest(body, label) {
|
|
|
625
632
|
for (const url of TOKEN_URLS) {
|
|
626
633
|
let response;
|
|
627
634
|
try {
|
|
628
|
-
response = await fetch(url, {
|
|
635
|
+
response = await fetch(url, {
|
|
636
|
+
method: "POST",
|
|
637
|
+
headers,
|
|
638
|
+
body: encoded,
|
|
639
|
+
signal: oauthRequestSignal()
|
|
640
|
+
});
|
|
629
641
|
} catch (err) {
|
|
630
642
|
lastError = err instanceof Error ? err : new Error(String(err));
|
|
631
643
|
continue;
|
|
@@ -874,7 +886,8 @@ async function exchangeOpenAICode(code, verifier) {
|
|
|
874
886
|
code,
|
|
875
887
|
redirect_uri: REDIRECT_URI2,
|
|
876
888
|
code_verifier: verifier
|
|
877
|
-
})
|
|
889
|
+
}),
|
|
890
|
+
signal: oauthRequestSignal()
|
|
878
891
|
});
|
|
879
892
|
if (!response.ok) {
|
|
880
893
|
const text = await response.text();
|
|
@@ -895,7 +908,8 @@ async function refreshOpenAIToken(refreshToken) {
|
|
|
895
908
|
grant_type: "refresh_token",
|
|
896
909
|
refresh_token: refreshToken,
|
|
897
910
|
client_id: CLIENT_ID3
|
|
898
|
-
})
|
|
911
|
+
}),
|
|
912
|
+
signal: oauthRequestSignal()
|
|
899
913
|
});
|
|
900
914
|
if (!response.ok) {
|
|
901
915
|
const text = await response.text();
|
|
@@ -1105,7 +1119,8 @@ async function postTokenRequest2(body) {
|
|
|
1105
1119
|
const response = await fetch(TOKEN_URL2, {
|
|
1106
1120
|
method: "POST",
|
|
1107
1121
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1108
|
-
body: new URLSearchParams(body)
|
|
1122
|
+
body: new URLSearchParams(body),
|
|
1123
|
+
signal: oauthRequestSignal()
|
|
1109
1124
|
});
|
|
1110
1125
|
if (!response.ok) {
|
|
1111
1126
|
const text = await response.text();
|
|
@@ -1234,7 +1249,8 @@ async function codeAssistGet(accessToken, operationName) {
|
|
|
1234
1249
|
async function codeAssistRequest(url, accessToken, label, init) {
|
|
1235
1250
|
const response = await fetch(url, {
|
|
1236
1251
|
...init,
|
|
1237
|
-
headers: codeAssistHeaders(accessToken)
|
|
1252
|
+
headers: codeAssistHeaders(accessToken),
|
|
1253
|
+
signal: oauthRequestSignal()
|
|
1238
1254
|
});
|
|
1239
1255
|
if (!response.ok) {
|
|
1240
1256
|
const text = await response.text();
|
|
@@ -1320,7 +1336,8 @@ async function postForm2(endpoint, params) {
|
|
|
1320
1336
|
Accept: "application/json",
|
|
1321
1337
|
"User-Agent": `grok-cli/${grokCliVersion()}`
|
|
1322
1338
|
},
|
|
1323
|
-
body: new URLSearchParams(params).toString()
|
|
1339
|
+
body: new URLSearchParams(params).toString(),
|
|
1340
|
+
signal: oauthRequestSignal()
|
|
1324
1341
|
});
|
|
1325
1342
|
let data = {};
|
|
1326
1343
|
try {
|
|
@@ -2315,9 +2332,7 @@ var MODELS = [
|
|
|
2315
2332
|
// Sent over our Code Assist (OAuth) transport ahead of gemini-cli — upstream
|
|
2316
2333
|
// hasn't listed 3.7 yet (google-gemini/gemini-cli#28802, still open) — so
|
|
2317
2334
|
// free/personal accounts 404 (entitlement-gated) while Code Assist
|
|
2318
|
-
// Standard/Enterprise accounts get it.
|
|
2319
|
-
// getFastModel picks the first low-tier entry, and flash-lite is the one
|
|
2320
|
-
// that works on every account.
|
|
2335
|
+
// Standard/Enterprise accounts get it.
|
|
2321
2336
|
id: "gemini-3.7-flash",
|
|
2322
2337
|
name: "Gemini 3.7 Flash",
|
|
2323
2338
|
provider: "gemini",
|
|
@@ -2712,19 +2727,17 @@ function getDefaultThinkingLevel(modelId, options) {
|
|
|
2712
2727
|
if (model?.id === "kimi-k3" && isKimiCodingEndpoint(options?.baseUrl)) return "high";
|
|
2713
2728
|
return model?.defaultThinkingLevel ?? model?.maxThinkingLevel ?? "high";
|
|
2714
2729
|
}
|
|
2730
|
+
var SUMMARY_COST_TIER = {
|
|
2731
|
+
anthropic: "medium",
|
|
2732
|
+
openai: "low",
|
|
2733
|
+
glm: "low",
|
|
2734
|
+
deepseek: "low",
|
|
2735
|
+
huggingface: "low"
|
|
2736
|
+
};
|
|
2715
2737
|
function getSummaryModel(provider, currentModelId) {
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
if (provider === "openai" || provider === "glm" || provider === "deepseek" || provider === "huggingface") {
|
|
2720
|
-
const low = getModelsForProvider(provider).find((m) => m.costTier === "low");
|
|
2721
|
-
if (low) return low;
|
|
2722
|
-
}
|
|
2723
|
-
return getModel(currentModelId) ?? getDefaultModel(provider);
|
|
2724
|
-
}
|
|
2725
|
-
function getFastModel(provider, currentModelId) {
|
|
2726
|
-
const low = getModelsForProvider(provider).find((m) => m.costTier === "low");
|
|
2727
|
-
return low ?? getModel(currentModelId) ?? getDefaultModel(provider);
|
|
2738
|
+
const tier = SUMMARY_COST_TIER[provider];
|
|
2739
|
+
const tagged = tier ? getModelsForProvider(provider).find((m) => m.costTier === tier) : void 0;
|
|
2740
|
+
return tagged ?? getModel(currentModelId) ?? getDefaultModel(provider);
|
|
2728
2741
|
}
|
|
2729
2742
|
|
|
2730
2743
|
// src/thinking-level.ts
|
|
@@ -2814,6 +2827,10 @@ function getSupportedThinkingLevels(provider, model) {
|
|
|
2814
2827
|
if (maxIndex === -1) return ["medium"];
|
|
2815
2828
|
return levels.slice(0, maxIndex + 1);
|
|
2816
2829
|
}
|
|
2830
|
+
function getLowestThinkingLevel(provider, model) {
|
|
2831
|
+
if (getModel(model)?.supportsThinking === false) return void 0;
|
|
2832
|
+
return getSupportedThinkingLevels(provider, model)[0];
|
|
2833
|
+
}
|
|
2817
2834
|
function isThinkingLevelSupported(provider, model, level) {
|
|
2818
2835
|
return getSupportedThinkingLevels(provider, model).includes(level);
|
|
2819
2836
|
}
|
|
@@ -3361,12 +3378,16 @@ async function fetchSubscriptionUsage(provider, credentials, options = {}) {
|
|
|
3361
3378
|
|
|
3362
3379
|
// src/telegram.ts
|
|
3363
3380
|
var TELEGRAM_API = "https://api.telegram.org";
|
|
3381
|
+
var LONG_POLL_SECONDS = 30;
|
|
3382
|
+
var API_TIMEOUT_MS = 3e4;
|
|
3364
3383
|
var MAX_MESSAGE_LENGTH = 4096;
|
|
3365
3384
|
var TelegramBot = class {
|
|
3366
3385
|
token;
|
|
3367
3386
|
allowedUserId;
|
|
3368
3387
|
offset = 0;
|
|
3369
3388
|
running = false;
|
|
3389
|
+
/** Aborts the in-flight long poll so stop() takes effect immediately. */
|
|
3390
|
+
pollAbort = null;
|
|
3370
3391
|
onMessage = null;
|
|
3371
3392
|
onVoiceMessage = null;
|
|
3372
3393
|
onCallback = null;
|
|
@@ -3419,6 +3440,7 @@ var TelegramBot = class {
|
|
|
3419
3440
|
/** Stop long polling. */
|
|
3420
3441
|
stop() {
|
|
3421
3442
|
this.running = false;
|
|
3443
|
+
this.pollAbort?.abort();
|
|
3422
3444
|
}
|
|
3423
3445
|
/** Send a text message to a specific chat. Converts markdown and splits long messages. */
|
|
3424
3446
|
async send(chatId, text, buttons) {
|
|
@@ -3465,12 +3487,26 @@ var TelegramBot = class {
|
|
|
3465
3487
|
}
|
|
3466
3488
|
// ── Private ───────────────────────────────────────────
|
|
3467
3489
|
async getUpdates() {
|
|
3468
|
-
const
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3490
|
+
const poll = new AbortController();
|
|
3491
|
+
this.pollAbort = poll;
|
|
3492
|
+
let result;
|
|
3493
|
+
try {
|
|
3494
|
+
result = await this.apiCall(
|
|
3495
|
+
"getUpdates",
|
|
3496
|
+
{
|
|
3497
|
+
offset: this.offset,
|
|
3498
|
+
timeout: LONG_POLL_SECONDS,
|
|
3499
|
+
allowed_updates: ["message", "callback_query", "my_chat_member"]
|
|
3500
|
+
},
|
|
3501
|
+
// A half-open socket would otherwise hang the poll forever.
|
|
3502
|
+
AbortSignal.any([poll.signal, AbortSignal.timeout((LONG_POLL_SECONDS + 15) * 1e3)])
|
|
3503
|
+
);
|
|
3504
|
+
} finally {
|
|
3505
|
+
if (this.pollAbort === poll) this.pollAbort = null;
|
|
3506
|
+
}
|
|
3507
|
+
if (!result.ok || !Array.isArray(result.result)) {
|
|
3508
|
+
throw new Error(`getUpdates failed: ${JSON.stringify(result)}`);
|
|
3509
|
+
}
|
|
3474
3510
|
const updates = result.result;
|
|
3475
3511
|
if (updates.length > 0) {
|
|
3476
3512
|
this.offset = updates[updates.length - 1].update_id + 1;
|
|
@@ -3518,12 +3554,13 @@ var TelegramBot = class {
|
|
|
3518
3554
|
}
|
|
3519
3555
|
}
|
|
3520
3556
|
}
|
|
3521
|
-
async apiCall(method, body) {
|
|
3557
|
+
async apiCall(method, body, signal = AbortSignal.timeout(API_TIMEOUT_MS)) {
|
|
3522
3558
|
const url = `${TELEGRAM_API}/bot${this.token}/${method}`;
|
|
3523
3559
|
const response = await fetch(url, {
|
|
3524
3560
|
method: "POST",
|
|
3525
3561
|
headers: { "Content-Type": "application/json" },
|
|
3526
|
-
body: body ? JSON.stringify(body) : void 0
|
|
3562
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
3563
|
+
signal
|
|
3527
3564
|
});
|
|
3528
3565
|
if (!response.ok) {
|
|
3529
3566
|
return { ok: false };
|
|
@@ -3656,7 +3693,7 @@ function isModelLoaded() {
|
|
|
3656
3693
|
return transcriber !== null;
|
|
3657
3694
|
}
|
|
3658
3695
|
async function transcribeVoice(fileUrl) {
|
|
3659
|
-
const response = await fetch(fileUrl);
|
|
3696
|
+
const response = await fetch(fileUrl, { signal: AbortSignal.timeout(6e4) });
|
|
3660
3697
|
if (!response.ok) throw new Error(`Failed to download voice file: ${response.status}`);
|
|
3661
3698
|
const buffer = new Uint8Array(await response.arrayBuffer());
|
|
3662
3699
|
const pcm = await decodeOggOpus(buffer);
|
|
@@ -3874,7 +3911,7 @@ function createAutoUpdater(config) {
|
|
|
3874
3911
|
getContextWindow,
|
|
3875
3912
|
getDefaultModel,
|
|
3876
3913
|
getDefaultThinkingLevel,
|
|
3877
|
-
|
|
3914
|
+
getLowestThinkingLevel,
|
|
3878
3915
|
getMaxThinkingLevel,
|
|
3879
3916
|
getModel,
|
|
3880
3917
|
getModelsForProvider,
|