feat(telegram): display tool execution status messages
Telegram bot now shows tool status during execution: - Sends status message when tool starts (tool name + args snippet) - Edits status message with result on completion - Keeps typing indicator active during tool execution - Adds setOnToolUse() to NativeAgent for per-message callback control
This commit is contained in:
@@ -190,4 +190,8 @@ export class NativeAgent {
|
|||||||
getModelTier(): ModelTier {
|
getModelTier(): ModelTier {
|
||||||
return this.currentTier;
|
return this.currentTier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOnToolUse(callback: ((event: ToolUseEvent) => void) | undefined): void {
|
||||||
|
this.onToolUse = callback;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,44 @@ export function createTelegramBot(config: TelegramBotConfig): Bot {
|
|||||||
// Show typing indicator
|
// Show typing indicator
|
||||||
await ctx.replyWithChatAction('typing');
|
await ctx.replyWithChatAction('typing');
|
||||||
|
|
||||||
|
// Set up tool status display for this message
|
||||||
|
let statusMsgId: number | undefined;
|
||||||
|
config.agent.setOnToolUse(async (event) => {
|
||||||
|
try {
|
||||||
|
if (event.type === 'start') {
|
||||||
|
const argsSnippet = event.args ? ` ${JSON.stringify(event.args).slice(0, 100)}` : '';
|
||||||
|
const statusText = `⚡ ${event.tool}${argsSnippet}`;
|
||||||
|
const msg = await ctx.reply(statusText);
|
||||||
|
statusMsgId = msg.message_id;
|
||||||
|
// Keep typing indicator active
|
||||||
|
await ctx.replyWithChatAction('typing');
|
||||||
|
} else if (event.type === 'end' && event.result && statusMsgId) {
|
||||||
|
const icon = event.result.success ? '✓' : '✗';
|
||||||
|
const detail = event.result.success
|
||||||
|
? `${event.result.output.split('\n').length} lines`
|
||||||
|
: (event.result.error ?? 'error');
|
||||||
|
try {
|
||||||
|
await ctx.api.editMessageText(
|
||||||
|
ctx.chat.id,
|
||||||
|
statusMsgId,
|
||||||
|
`${icon} ${event.tool}: ${detail}`,
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
// Edit may fail if message was deleted; ignore
|
||||||
|
}
|
||||||
|
statusMsgId = undefined;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Don't let status display errors break the tool loop
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await handleMessage(text);
|
const response = await handleMessage(text);
|
||||||
|
|
||||||
|
// Clear tool use callback
|
||||||
|
config.agent.setOnToolUse(undefined);
|
||||||
|
|
||||||
// Telegram has a 4096 character limit per message
|
// Telegram has a 4096 character limit per message
|
||||||
if (response.length <= 4096) {
|
if (response.length <= 4096) {
|
||||||
await ctx.reply(response, { parse_mode: 'Markdown' });
|
await ctx.reply(response, { parse_mode: 'Markdown' });
|
||||||
@@ -111,6 +146,7 @@ export function createTelegramBot(config: TelegramBotConfig): Bot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
config.agent.setOnToolUse(undefined);
|
||||||
console.error('Error processing message:', error);
|
console.error('Error processing message:', error);
|
||||||
await ctx.reply('Sorry, an error occurred while processing your message.');
|
await ctx.reply('Sorry, an error occurred while processing your message.');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user