krnell 3.0.6 → 3.0.7
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/bin/krnell.mjs +2 -2
- package/bridge.py +126 -19
- package/dashboard_web.py +1 -1
- package/iniciar.sh +1 -1
- package/opencode_sync.py +100 -21
- package/package.json +1 -1
- package/painel.py +131 -23
- package/plugins/system-prompt/index.ts +617 -16
- package/plugins/system-prompt/package.json +1 -1
- package/plugins/system-prompt/tui.tsx +592 -79
- package/provedores/kimi/bridge.mjs +68 -23
- package/tui_core.py +15 -6
|
@@ -58,11 +58,11 @@ const CFG = {
|
|
|
58
58
|
// Otimizacao NVIDIA/hCaptcha:
|
|
59
59
|
// - captchaWorkers: quantidade de contextos isolados (cada um com cookie jar proprio)
|
|
60
60
|
// - captchaWidgetsPerWorker: widgets hCaptcha paralelos por contexto
|
|
61
|
-
// - captchaPoolSize: buffer de tokens frescos pre-mintados
|
|
61
|
+
// - captchaPoolSize: buffer de tokens frescos pre-mintados (sobe sob rajada ate burstPool)
|
|
62
62
|
// - browserIdleCloseMs: fecha o browser apos ocioso (0 MB RAM sem uso NVIDIA)
|
|
63
|
-
captchaWorkers:
|
|
63
|
+
captchaWorkers: 3,
|
|
64
64
|
captchaWidgetsPerWorker: 2,
|
|
65
|
-
captchaPoolSize:
|
|
65
|
+
captchaPoolSize: 6,
|
|
66
66
|
browserIdleCloseMs: 120000,
|
|
67
67
|
locale: 'en-US',
|
|
68
68
|
answerMarker: '**[ENI]**',
|
|
@@ -830,11 +830,11 @@ async function installAutostart() {
|
|
|
830
830
|
// - buffer de tokens frescos + fila com respeito a AbortSignal;
|
|
831
831
|
// - fecha o browser automaticamente apos browserIdleCloseMs sem uso NVIDIA
|
|
832
832
|
// (0 MB de RAM quando voce so esta usando Antigravity ou parado).
|
|
833
|
-
const CAPTCHA_WORKERS = Math.max(1, Math.min(8, Number(CFG.captchaWorkers) ||
|
|
833
|
+
const CAPTCHA_WORKERS = Math.max(1, Math.min(8, Number(CFG.captchaWorkers) || 3));
|
|
834
834
|
const CAPTCHA_WIDGETS_PER_WORKER = Math.max(1, Math.min(4, Number(CFG.captchaWidgetsPerWorker) || 2));
|
|
835
|
-
const CAPTCHA_POOL_TARGET = Math.max(1, Math.min(
|
|
836
|
-
const CAPTCHA_TOKEN_TTL_MS =
|
|
837
|
-
const CAPTCHA_ROTATE_AFTER =
|
|
835
|
+
const CAPTCHA_POOL_TARGET = Math.max(1, Math.min(16, Number(CFG.captchaPoolSize) || 6));
|
|
836
|
+
const CAPTCHA_TOKEN_TTL_MS = 85000;
|
|
837
|
+
const CAPTCHA_ROTATE_AFTER = 12; // gira o BrowserContext (cookies novos + libera RAM) a cada 12 mints
|
|
838
838
|
const BROWSER_IDLE_CLOSE_MS = Math.max(30000, Number(CFG.browserIdleCloseMs) || 120000);
|
|
839
839
|
|
|
840
840
|
const state = {
|
|
@@ -1909,15 +1909,12 @@ function agBootstrapHeaders(accessToken) {
|
|
|
1909
1909
|
|
|
1910
1910
|
function agFormatDuration(sec) {
|
|
1911
1911
|
if (sec === null || sec === undefined || !Number.isFinite(sec)) return null;
|
|
1912
|
-
if (sec <= 0) return '
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
if (h > 0) return `${h}h ${m}m`;
|
|
1919
|
-
if (m > 0) return `${m}m ${s}s`;
|
|
1920
|
-
return `${s}s`;
|
|
1912
|
+
if (sec <= 0) return '0s';
|
|
1913
|
+
// Unidade principal única: dias (>=24h), horas (<24h), minutos (<1h), segundos (<1m).
|
|
1914
|
+
if (sec >= 86400) return `${Math.floor(sec / 86400)}d`;
|
|
1915
|
+
if (sec >= 3600) return `${Math.floor(sec / 3600)}h`;
|
|
1916
|
+
if (sec >= 60) return `${Math.floor(sec / 60)}m`;
|
|
1917
|
+
return `${Math.max(1, Math.floor(sec))}s`;
|
|
1921
1918
|
}
|
|
1922
1919
|
|
|
1923
1920
|
function agQuotaBucketKey(modelOrWire) {
|
|
@@ -1978,6 +1975,54 @@ function agMarkCooldown(acct, model, wire, untilMs, reason = 'quota') {
|
|
|
1978
1975
|
}
|
|
1979
1976
|
}
|
|
1980
1977
|
|
|
1978
|
+
function agQuotaWindowLabel(acct, bucket, reason = '', untilMs = 0) {
|
|
1979
|
+
const rt = acct ? agRuntime(acct) : null;
|
|
1980
|
+
const now = Date.now();
|
|
1981
|
+
const isFree = /free/i.test(String(acct?.paidTier || '')) || (!acct?.paidTier && /free/i.test(String(acct?.tier || '')));
|
|
1982
|
+
if (rt) {
|
|
1983
|
+
for (const g of rt.quota.groups || []) {
|
|
1984
|
+
if (!agGroupMatchesBucket(g.displayName, bucket)) continue;
|
|
1985
|
+
for (const b of g.buckets || []) {
|
|
1986
|
+
const frac = typeof b.remainingFraction === 'number' ? b.remainingFraction : (b.resetTime ? 0 : null);
|
|
1987
|
+
if (frac !== null && frac <= 0) {
|
|
1988
|
+
const w = String(b.window || b.bucketId || '').toLowerCase();
|
|
1989
|
+
if (w.includes('week')) return 'semanal';
|
|
1990
|
+
if (w.includes('5h')) return 'diária (5h)';
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
const r = String(reason || '').toLowerCase();
|
|
1996
|
+
if (r.includes('week')) return 'semanal';
|
|
1997
|
+
if (r.includes('5h')) return 'diária (5h)';
|
|
1998
|
+
if (isFree) return 'semanal';
|
|
1999
|
+
if (untilMs && untilMs - now > 6 * 3600 * 1000) return 'semanal';
|
|
2000
|
+
return 'diária (5h)';
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
function agFormatExhaustedMessage(modelOrWire, exhaustedList) {
|
|
2004
|
+
const now = Date.now();
|
|
2005
|
+
const list = Array.isArray(exhaustedList) ? exhaustedList.slice() : [];
|
|
2006
|
+
list.sort((a, b) => (a.until || Infinity) - (b.until || Infinity));
|
|
2007
|
+
const earliest = list[0];
|
|
2008
|
+
const bucket = agQuotaBucketKey(modelOrWire);
|
|
2009
|
+
const tipo = earliest ? agQuotaWindowLabel(earliest.acct, bucket, earliest.reason, earliest.until) : 'diária (5h)';
|
|
2010
|
+
const sec = earliest && earliest.until ? Math.max(0, Math.round((earliest.until - now) / 1000)) : null;
|
|
2011
|
+
const falta = sec !== null ? agFormatDuration(sec) : null;
|
|
2012
|
+
const prefixo = tipo === 'semanal'
|
|
2013
|
+
? 'Sua quota semanal acabou'
|
|
2014
|
+
: 'Sua quota diária (5h) acabou';
|
|
2015
|
+
if (agStore.accounts.length <= 1) {
|
|
2016
|
+
return falta
|
|
2017
|
+
? `${prefixo} para ${modelOrWire}. Reseta em ${falta}.`
|
|
2018
|
+
: `${prefixo} para ${modelOrWire}. Aguarde o reset da janela.`;
|
|
2019
|
+
}
|
|
2020
|
+
const conta = earliest?.acct?.email || earliest?.acct?.id || '';
|
|
2021
|
+
return falta
|
|
2022
|
+
? `${prefixo} em todas as ${agStore.accounts.length} contas Antigravity para ${modelOrWire}. Reseta em ${falta}${conta ? ` (${conta})` : ''}.`
|
|
2023
|
+
: `${prefixo} em todas as ${agStore.accounts.length} contas Antigravity para ${modelOrWire}.`;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
1981
2026
|
function agAccountAvailability(acct, model, wire) {
|
|
1982
2027
|
const now = Date.now();
|
|
1983
2028
|
const rt = agRuntime(acct);
|
|
@@ -3219,13 +3264,7 @@ async function handleAntigravityChat(body, model, res, reqAbort, preferredHint =
|
|
|
3219
3264
|
}
|
|
3220
3265
|
|
|
3221
3266
|
if (!available.length) {
|
|
3222
|
-
|
|
3223
|
-
const earliest = exhausted[0];
|
|
3224
|
-
const sec = earliest && earliest.until ? Math.max(0, Math.round((earliest.until - Date.now()) / 1000)) : null;
|
|
3225
|
-
const when = earliest && earliest.until
|
|
3226
|
-
? `${earliest.acct.email || earliest.acct.id} em ${agFormatDuration(sec)} (${new Date(earliest.until).toISOString()})`
|
|
3227
|
-
: 'aguarde o reset da janela';
|
|
3228
|
-
const msg = `Todas as ${agStore.accounts.length} conta(s) Antigravity estao sem quota para ${wire}. Proximo reset: ${when}.`;
|
|
3267
|
+
const msg = agFormatExhaustedMessage(wire, exhausted);
|
|
3229
3268
|
log(`antigravity: ${msg}`);
|
|
3230
3269
|
return sendJson(429, { error: { message: msg, type: 'antigravity_quota_exhausted', code: 429 } });
|
|
3231
3270
|
}
|
|
@@ -3295,6 +3334,12 @@ async function handleAntigravityChat(body, model, res, reqAbort, preferredHint =
|
|
|
3295
3334
|
continue;
|
|
3296
3335
|
}
|
|
3297
3336
|
log(`req ${id}: erro upstream`, String(up.errorText || '').slice(0, 400));
|
|
3337
|
+
if (up.status === 429) {
|
|
3338
|
+
const msg = agFormatExhaustedMessage(envelope.model, [{ acct, until: up.resetUntil, reason: 'hard_429' }]);
|
|
3339
|
+
return sendJson(429, {
|
|
3340
|
+
error: { message: msg, type: 'antigravity_quota_exhausted', code: 429 },
|
|
3341
|
+
});
|
|
3342
|
+
}
|
|
3298
3343
|
return sendJson(up.status || 400, {
|
|
3299
3344
|
error: { message: String(up.errorText || 'upstream error').slice(0, 1200), type: 'upstream_error', code: up.status || 400 },
|
|
3300
3345
|
});
|
package/tui_core.py
CHANGED
|
@@ -453,12 +453,21 @@ def desenhar_overlay_centrado(
|
|
|
453
453
|
for offset, linha_box in enumerate(caixa_linhas):
|
|
454
454
|
y = top + offset
|
|
455
455
|
if 0 <= y < len(linhas):
|
|
456
|
-
#
|
|
457
|
-
#
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
456
|
+
# Composição em uma única passada sem CSI G sobreposto: evita
|
|
457
|
+
# vazamento de linha do fundo atravessando o diálogo no Termux.
|
|
458
|
+
# Não usa truncate_vis porque ele coloca "…" quando corta espaços em branco.
|
|
459
|
+
fundo_limpo = strip_ansi(linhas[y])
|
|
460
|
+
pedacos, cols = [], 0
|
|
461
|
+
for ch in fundo_limpo:
|
|
462
|
+
w_ch = vis_len(ch)
|
|
463
|
+
if cols + w_ch > left:
|
|
464
|
+
break
|
|
465
|
+
pedacos.append(ch)
|
|
466
|
+
cols += w_ch
|
|
467
|
+
esq = ''.join(pedacos)
|
|
468
|
+
pad_esq = ' ' * max(0, left - cols)
|
|
469
|
+
prefixo = f'\x1b[2m{esq}{pad_esq}\x1b[0m' if esmaecer_fundo else f'{esq}{pad_esq}'
|
|
470
|
+
linhas[y] = f'{prefixo}{cor_fundo_ansi}{linha_box}\x1b[0m'
|
|
462
471
|
return linhas, top, left
|
|
463
472
|
|
|
464
473
|
|