kafox-cli 0.9.5 → 0.9.6
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 +4 -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
|
@@ -264,6 +264,10 @@ async function chat({ messages, model, tools, onDelta, onReasoning, onRetry, sig
|
|
|
264
264
|
const result = await attemptChat({ messages, model, tools, onDelta, onReasoning, signal });
|
|
265
265
|
|
|
266
266
|
if (result.ok || result.code === "aborted") return result;
|
|
267
|
+
if (result.code === "invalid_api_key") {
|
|
268
|
+
storage.clearApiKey();
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
267
271
|
// Ja saiu texto: repetir duplicaria a resposta na tela.
|
|
268
272
|
if (!result.retryable || result.text) return result;
|
|
269
273
|
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
|
};
|