kafox-cli 0.9.5 → 0.9.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/package.json +1 -1
- package/src/auth.js +1 -0
- package/src/gateway.js +6 -0
- package/src/storage.js +6 -1
package/package.json
CHANGED
package/src/auth.js
CHANGED
|
@@ -80,6 +80,7 @@ async function pollDevice(data) {
|
|
|
80
80
|
if (poll.status === 200 && pd.status === "approved") {
|
|
81
81
|
const previous = storage.getToken() || {};
|
|
82
82
|
storage.setToken({ session: pd.session, csrf: previous.csrf });
|
|
83
|
+
storage.clearApiKey();
|
|
83
84
|
return { ok: true, stop: true };
|
|
84
85
|
}
|
|
85
86
|
if (pd.status === "denied" || poll.status === 403) {
|
package/src/gateway.js
CHANGED
|
@@ -258,12 +258,18 @@ async function chat({ messages, model, tools, onDelta, onReasoning, onRetry, sig
|
|
|
258
258
|
const maxAttempts = Math.max(1, Number(retries) || RETRY_MAX);
|
|
259
259
|
let attempt = 0;
|
|
260
260
|
let last = null;
|
|
261
|
+
let clearedKey = false;
|
|
261
262
|
|
|
262
263
|
while (attempt < maxAttempts) {
|
|
263
264
|
attempt += 1;
|
|
264
265
|
const result = await attemptChat({ messages, model, tools, onDelta, onReasoning, signal });
|
|
265
266
|
|
|
266
267
|
if (result.ok || result.code === "aborted") return result;
|
|
268
|
+
if (result.code === "invalid_api_key" && !clearedKey) {
|
|
269
|
+
clearedKey = true;
|
|
270
|
+
storage.clearApiKey();
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
267
273
|
// Ja saiu texto: repetir duplicaria a resposta na tela.
|
|
268
274
|
if (!result.retryable || result.text) return result;
|
|
269
275
|
last = result;
|
package/src/storage.js
CHANGED
|
@@ -45,6 +45,11 @@ function setToken(data) {
|
|
|
45
45
|
function clearToken() {
|
|
46
46
|
try { fs.unlinkSync(TOKEN_FILE); } catch {}
|
|
47
47
|
}
|
|
48
|
+
function clearApiKey() {
|
|
49
|
+
const cfg = readJSON(CONFIG_FILE, {});
|
|
50
|
+
delete cfg.api_key;
|
|
51
|
+
writeJSON(CONFIG_FILE, cfg);
|
|
52
|
+
}
|
|
48
53
|
|
|
49
54
|
function getConfig() {
|
|
50
55
|
return readJSON(CONFIG_FILE, {});
|
|
@@ -93,5 +98,5 @@ module.exports = {
|
|
|
93
98
|
DIR, TOKEN_FILE, CONFIG_FILE,
|
|
94
99
|
ensureDir, readJSON, writeJSON,
|
|
95
100
|
getApiUrl, getWebUrl, getToken, setToken, clearToken,
|
|
96
|
-
getConfig, setConfig, getAuthHeaders, parseCookies,
|
|
101
|
+
getConfig, setConfig, clearApiKey, getAuthHeaders, parseCookies,
|
|
97
102
|
};
|