@gonzih/cc-tg 0.1.3 → 0.1.4
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/bot.d.ts +1 -0
- package/dist/bot.js +38 -7
- package/package.json +1 -1
package/dist/bot.d.ts
CHANGED
package/dist/bot.js
CHANGED
|
@@ -68,20 +68,41 @@ export class CcTgBot {
|
|
|
68
68
|
flushTimer: null,
|
|
69
69
|
typingTimer: null,
|
|
70
70
|
};
|
|
71
|
-
claude.on("message", (msg) =>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
claude.on("message", (msg) => {
|
|
72
|
+
// Verbose logging — log every message type and subtype
|
|
73
|
+
const subtype = msg.payload.subtype ?? "";
|
|
74
|
+
const toolName = this.extractToolName(msg);
|
|
75
|
+
const logParts = [`[claude:${chatId}] msg=${msg.type}`];
|
|
76
|
+
if (subtype)
|
|
77
|
+
logParts.push(`subtype=${subtype}`);
|
|
78
|
+
if (toolName)
|
|
79
|
+
logParts.push(`tool=${toolName}`);
|
|
80
|
+
console.log(logParts.join(" "));
|
|
81
|
+
// Surface tool activity to Telegram as a status line
|
|
82
|
+
if (msg.type === "assistant" && toolName) {
|
|
83
|
+
this.bot.sendMessage(chatId, `⚙️ ${toolName}...`).catch(() => { });
|
|
84
|
+
}
|
|
85
|
+
if (msg.type === "system" && subtype === "task_progress") {
|
|
86
|
+
const desc = msg.payload.description ?? "";
|
|
87
|
+
if (desc)
|
|
88
|
+
this.bot.sendMessage(chatId, `🔍 ${desc}`).catch(() => { });
|
|
76
89
|
}
|
|
90
|
+
this.handleClaudeMessage(chatId, session, msg);
|
|
91
|
+
});
|
|
92
|
+
claude.on("stderr", (data) => {
|
|
93
|
+
const line = data.trim();
|
|
94
|
+
if (line)
|
|
95
|
+
console.error(`[claude:${chatId}:stderr]`, line);
|
|
77
96
|
});
|
|
78
97
|
claude.on("exit", (code) => {
|
|
79
|
-
console.log(`[claude:${chatId}] exited
|
|
98
|
+
console.log(`[claude:${chatId}] exited code=${code}`);
|
|
99
|
+
this.stopTyping(session);
|
|
80
100
|
this.sessions.delete(chatId);
|
|
81
101
|
});
|
|
82
102
|
claude.on("error", (err) => {
|
|
83
|
-
console.error(`[claude:${chatId}] process error
|
|
103
|
+
console.error(`[claude:${chatId}] process error: ${err.message}`);
|
|
84
104
|
this.bot.sendMessage(chatId, `Claude process error: ${err.message}`).catch(() => { });
|
|
105
|
+
this.stopTyping(session);
|
|
85
106
|
this.sessions.delete(chatId);
|
|
86
107
|
});
|
|
87
108
|
this.sessions.set(chatId, session);
|
|
@@ -131,6 +152,16 @@ export class CcTgBot {
|
|
|
131
152
|
});
|
|
132
153
|
}
|
|
133
154
|
}
|
|
155
|
+
extractToolName(msg) {
|
|
156
|
+
const message = msg.payload.message;
|
|
157
|
+
if (!message)
|
|
158
|
+
return "";
|
|
159
|
+
const content = message.content;
|
|
160
|
+
if (!Array.isArray(content))
|
|
161
|
+
return "";
|
|
162
|
+
const toolUse = content.find((b) => b.type === "tool_use");
|
|
163
|
+
return toolUse?.name ?? "";
|
|
164
|
+
}
|
|
134
165
|
killSession(chatId) {
|
|
135
166
|
const session = this.sessions.get(chatId);
|
|
136
167
|
if (session) {
|