@inetafrica/open-claudia 1.14.2 → 1.14.3
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/bot-agent.js +50 -17
- package/bot.js +50 -17
- package/package.json +1 -1
package/bot-agent.js
CHANGED
|
@@ -724,6 +724,25 @@ function looksLikeClaudeToken(value) {
|
|
|
724
724
|
return /^sk-ant-[A-Za-z0-9._-]+$/.test(text) || text.length >= 80 && /^[A-Za-z0-9._=-]+$/.test(text);
|
|
725
725
|
}
|
|
726
726
|
|
|
727
|
+
|
|
728
|
+
function looksLikeClaudeAuthReply(value) {
|
|
729
|
+
const text = String(value || "").trim();
|
|
730
|
+
if (!text) return false;
|
|
731
|
+
if (looksLikeClaudeToken(text)) return true;
|
|
732
|
+
if (/^https?:\/\//i.test(text) && /claude|anthropic/i.test(text)) return true;
|
|
733
|
+
// OAuth callback/login codes are usually long, dense strings. Do not consume normal chat.
|
|
734
|
+
if (text.length >= 24 && !/\s/.test(text) && /^[A-Za-z0-9._~:/?#[\]@!$&'()*+,;=%-]+$/.test(text)) return true;
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
function clearPendingClaudeAuth() {
|
|
739
|
+
if (pendingClaudeAuthProcess && pendingClaudeAuthProcess.kill) {
|
|
740
|
+
try { pendingClaudeAuthProcess.kill("SIGTERM"); } catch (e) {}
|
|
741
|
+
}
|
|
742
|
+
pendingClaudeAuthProcess = null;
|
|
743
|
+
pendingClaudeAuthLabel = null;
|
|
744
|
+
}
|
|
745
|
+
|
|
727
746
|
function getClaudeOAuthToken() {
|
|
728
747
|
if (config[CLAUDE_OAUTH_TOKEN_KEY]) return { value: config[CLAUDE_OAUTH_TOKEN_KEY], source: ".env" };
|
|
729
748
|
if (process.env.CLAUDE_CODE_OAUTH_TOKEN) return { value: process.env.CLAUDE_CODE_OAUTH_TOKEN, source: "process env" };
|
|
@@ -1691,6 +1710,13 @@ bot.onText(/\/(?:auth_status|auth status)$/, async (msg) => {
|
|
|
1691
1710
|
proc.on("error", async (err) => send(`Claude auth status failed: ${redactSensitive(err.message)}`));
|
|
1692
1711
|
});
|
|
1693
1712
|
|
|
1713
|
+
bot.onText(/\/cancel_auth$/, async (msg) => {
|
|
1714
|
+
if (!isAuthorized(msg)) return;
|
|
1715
|
+
if (!pendingClaudeAuthProcess) return send("No Claude auth flow is pending.");
|
|
1716
|
+
clearPendingClaudeAuth();
|
|
1717
|
+
await send("Claude auth flow cancelled. Normal messages will go to the assistant again.");
|
|
1718
|
+
});
|
|
1719
|
+
|
|
1694
1720
|
bot.onText(/\/login$/, async (msg) => {
|
|
1695
1721
|
if (!isAuthorized(msg)) return;
|
|
1696
1722
|
await runClaudeAuthCommand(["auth", "login", "--claudeai", "--email", "sumeet@inet.africa"], "Claude login");
|
|
@@ -1959,28 +1985,35 @@ bot.on("message", async (msg) => {
|
|
|
1959
1985
|
if (msg.voice || msg.audio || msg.photo || msg.document || msg.video || msg.sticker) return;
|
|
1960
1986
|
if (isDuplicate(msg.message_id)) return;
|
|
1961
1987
|
|
|
1962
|
-
// Handle pending Claude auth/token paste-back
|
|
1988
|
+
// Handle pending Claude auth/token paste-back. Only consume code/token-looking replies;
|
|
1989
|
+
// normal chat must still go to Claude instead of being deleted.
|
|
1963
1990
|
if (pendingClaudeAuthProcess) {
|
|
1964
1991
|
const text = msg.text.trim();
|
|
1965
|
-
await deleteMessage(msg.message_id);
|
|
1966
1992
|
if (pendingClaudeAuthLabel === "manual OAuth token save") {
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1993
|
+
if (looksLikeClaudeToken(text)) {
|
|
1994
|
+
await deleteMessage(msg.message_id);
|
|
1995
|
+
clearPendingClaudeAuth();
|
|
1996
|
+
saveClaudeOAuthToken(text);
|
|
1997
|
+
await send(`Claude OAuth token stored in .env${vault.isUnlocked() ? " and vault" : ""}. Restart the bot so launchd picks it up, or use /restart.`);
|
|
1998
|
+
await sendClaudeAuthStatusSummary("Stored token. Current Claude auth status:");
|
|
1999
|
+
return;
|
|
2000
|
+
}
|
|
2001
|
+
await send("That does not look like a Claude OAuth token, so I did not delete it or store it. Send /cancel_auth to stop token paste mode.");
|
|
2002
|
+
// Fall through and treat the message normally.
|
|
2003
|
+
} else if (looksLikeClaudeAuthReply(text)) {
|
|
2004
|
+
await deleteMessage(msg.message_id);
|
|
2005
|
+
try {
|
|
2006
|
+
pendingClaudeAuthProcess.stdin.write(text + "\n");
|
|
2007
|
+
await send("Sent to Claude auth process. I’ll confirm when Claude finishes the auth check.");
|
|
2008
|
+
} catch (e) {
|
|
2009
|
+
clearPendingClaudeAuth();
|
|
2010
|
+
await send(`Could not send to Claude auth process: ${redactSensitive(e.message)}`);
|
|
2011
|
+
}
|
|
1973
2012
|
return;
|
|
2013
|
+
} else {
|
|
2014
|
+
await send("Claude auth is still waiting for a login code/token. I left your message visible and will handle it normally. Send /cancel_auth to cancel the auth flow.");
|
|
2015
|
+
// Fall through and treat the message normally.
|
|
1974
2016
|
}
|
|
1975
|
-
try {
|
|
1976
|
-
pendingClaudeAuthProcess.stdin.write(text + "\n");
|
|
1977
|
-
await send("Sent to Claude auth process. I’ll confirm when Claude finishes the auth check.");
|
|
1978
|
-
} catch (e) {
|
|
1979
|
-
pendingClaudeAuthProcess = null;
|
|
1980
|
-
pendingClaudeAuthLabel = null;
|
|
1981
|
-
await send(`Could not send to Claude auth process: ${redactSensitive(e.message)}`);
|
|
1982
|
-
}
|
|
1983
|
-
return;
|
|
1984
2017
|
}
|
|
1985
2018
|
|
|
1986
2019
|
// Handle onboarding
|
package/bot.js
CHANGED
|
@@ -786,6 +786,25 @@ function looksLikeClaudeToken(value) {
|
|
|
786
786
|
return /^sk-ant-[A-Za-z0-9._-]+$/.test(text) || text.length >= 80 && /^[A-Za-z0-9._=-]+$/.test(text);
|
|
787
787
|
}
|
|
788
788
|
|
|
789
|
+
|
|
790
|
+
function looksLikeClaudeAuthReply(value) {
|
|
791
|
+
const text = String(value || "").trim();
|
|
792
|
+
if (!text) return false;
|
|
793
|
+
if (looksLikeClaudeToken(text)) return true;
|
|
794
|
+
if (/^https?:\/\//i.test(text) && /claude|anthropic/i.test(text)) return true;
|
|
795
|
+
// OAuth callback/login codes are usually long, dense strings. Do not consume normal chat.
|
|
796
|
+
if (text.length >= 24 && !/\s/.test(text) && /^[A-Za-z0-9._~:/?#[\]@!$&'()*+,;=%-]+$/.test(text)) return true;
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
function clearPendingClaudeAuth() {
|
|
801
|
+
if (pendingClaudeAuthProcess && pendingClaudeAuthProcess.kill) {
|
|
802
|
+
try { pendingClaudeAuthProcess.kill("SIGTERM"); } catch (e) {}
|
|
803
|
+
}
|
|
804
|
+
pendingClaudeAuthProcess = null;
|
|
805
|
+
pendingClaudeAuthLabel = null;
|
|
806
|
+
}
|
|
807
|
+
|
|
789
808
|
function getClaudeOAuthToken() {
|
|
790
809
|
if (config[CLAUDE_OAUTH_TOKEN_KEY]) return { value: config[CLAUDE_OAUTH_TOKEN_KEY], source: ".env" };
|
|
791
810
|
if (process.env.CLAUDE_CODE_OAUTH_TOKEN) return { value: process.env.CLAUDE_CODE_OAUTH_TOKEN, source: "process env" };
|
|
@@ -1722,6 +1741,13 @@ bot.onText(/\/(?:auth_status|auth status)$/, async (msg) => {
|
|
|
1722
1741
|
proc.on("error", async (err) => send(`Claude auth status failed: ${redactSensitive(err.message)}`));
|
|
1723
1742
|
});
|
|
1724
1743
|
|
|
1744
|
+
bot.onText(/\/cancel_auth$/, async (msg) => {
|
|
1745
|
+
if (!isAuthorized(msg)) return;
|
|
1746
|
+
if (!pendingClaudeAuthProcess) return send("No Claude auth flow is pending.");
|
|
1747
|
+
clearPendingClaudeAuth();
|
|
1748
|
+
await send("Claude auth flow cancelled. Normal messages will go to the assistant again.");
|
|
1749
|
+
});
|
|
1750
|
+
|
|
1725
1751
|
bot.onText(/\/login$/, async (msg) => {
|
|
1726
1752
|
if (!isAuthorized(msg)) return;
|
|
1727
1753
|
await runClaudeAuthCommand(["auth", "login", "--claudeai", "--email", "sumeet@inet.africa"], "Claude login");
|
|
@@ -1998,28 +2024,35 @@ bot.on("message", async (msg) => {
|
|
|
1998
2024
|
if (msg.voice || msg.audio || msg.photo || msg.document || msg.video || msg.sticker) return;
|
|
1999
2025
|
if (isDuplicate(msg.message_id)) return;
|
|
2000
2026
|
|
|
2001
|
-
// Handle pending Claude auth/token paste-back
|
|
2027
|
+
// Handle pending Claude auth/token paste-back. Only consume code/token-looking replies;
|
|
2028
|
+
// normal chat must still go to Claude instead of being deleted.
|
|
2002
2029
|
if (pendingClaudeAuthProcess) {
|
|
2003
2030
|
const text = msg.text.trim();
|
|
2004
|
-
await deleteMessage(msg.message_id);
|
|
2005
2031
|
if (pendingClaudeAuthLabel === "manual OAuth token save") {
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2032
|
+
if (looksLikeClaudeToken(text)) {
|
|
2033
|
+
await deleteMessage(msg.message_id);
|
|
2034
|
+
clearPendingClaudeAuth();
|
|
2035
|
+
saveClaudeOAuthToken(text);
|
|
2036
|
+
await send(`Claude OAuth token stored in .env${vault.isUnlocked() ? " and vault" : ""}. Restart the bot so launchd picks it up, or use /restart.`);
|
|
2037
|
+
await sendClaudeAuthStatusSummary("Stored token. Current Claude auth status:");
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
await send("That does not look like a Claude OAuth token, so I did not delete it or store it. Send /cancel_auth to stop token paste mode.");
|
|
2041
|
+
// Fall through and treat the message normally.
|
|
2042
|
+
} else if (looksLikeClaudeAuthReply(text)) {
|
|
2043
|
+
await deleteMessage(msg.message_id);
|
|
2044
|
+
try {
|
|
2045
|
+
pendingClaudeAuthProcess.stdin.write(text + "\n");
|
|
2046
|
+
await send("Sent to Claude auth process. I’ll confirm when Claude finishes the auth check.");
|
|
2047
|
+
} catch (e) {
|
|
2048
|
+
clearPendingClaudeAuth();
|
|
2049
|
+
await send(`Could not send to Claude auth process: ${redactSensitive(e.message)}`);
|
|
2050
|
+
}
|
|
2012
2051
|
return;
|
|
2052
|
+
} else {
|
|
2053
|
+
await send("Claude auth is still waiting for a login code/token. I left your message visible and will handle it normally. Send /cancel_auth to cancel the auth flow.");
|
|
2054
|
+
// Fall through and treat the message normally.
|
|
2013
2055
|
}
|
|
2014
|
-
try {
|
|
2015
|
-
pendingClaudeAuthProcess.stdin.write(text + "\n");
|
|
2016
|
-
await send("Sent to Claude auth process. I’ll confirm when Claude finishes the auth check.");
|
|
2017
|
-
} catch (e) {
|
|
2018
|
-
pendingClaudeAuthProcess = null;
|
|
2019
|
-
pendingClaudeAuthLabel = null;
|
|
2020
|
-
await send(`Could not send to Claude auth process: ${redactSensitive(e.message)}`);
|
|
2021
|
-
}
|
|
2022
|
-
return;
|
|
2023
2056
|
}
|
|
2024
2057
|
|
|
2025
2058
|
// Handle onboarding
|