Add Telegram typing indicator via WIT on-status callback

Thread message metadata through Channel::send_status so WASM channels
can route status updates (like typing indicators) to the correct chat.
The WasmChannel spawns a background task that repeats on_status every
4 seconds to keep Telegram's typing bubble alive until the response
is sent.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
Illia Polosukhin
2026-02-05 19:44:43 -08:00
co-authored by Claude Opus 4.6
parent f3c85f57fc
commit e0016a95e8
8 changed files with 635 additions and 19 deletions
+38 -3
View File
@@ -16,9 +16,9 @@
// │ ▼ │
// │ ┌──────────────────┬──────────────────┐ │
// │ ▼ ▼ ▼ │
// │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
// │ │ on-http-req │ │ on-poll │ │ on-respond │ WASM Exports │
// │ └─────────────┘ └─────────────┘ └─────────────┘ │
// │ ┌─────────── ┌────────┐ ┌──────────┐ ┌──────────┐
// │ │on-http-req│ │on-poll │ │on-respond│ │on-status WASM Exports │
// │ └─────────── └────────┘ └──────────┘ └──────────┘
// │ │ │ │ │
// │ └──────────────────┴──────────────────┘ │
// │ │ │
@@ -215,6 +215,32 @@ interface channel {
metadata-json: string,
}
// ==================== Status Types ====================
/// Types of status updates the agent can send to channels.
enum status-type {
/// Agent is thinking/processing a response.
thinking,
/// Agent finished processing (response sent or about to be sent).
done,
/// Agent processing was interrupted.
interrupted,
/// A tool execution started.
tool-started,
/// A tool execution completed.
tool-completed,
}
/// A status update from the agent.
record status-update {
/// The type of status change.
status: status-type,
/// Human-readable description of the status.
message: string,
/// Channel-specific metadata as JSON string (e.g., contains chat_id for routing).
metadata-json: string,
}
// ==================== Lifecycle Callbacks ====================
/// Initialize the channel.
@@ -261,6 +287,15 @@ interface channel {
/// - Err(string): Delivery failure message
on-respond: func(response: agent-response) -> result<_, string>;
/// Notify the channel of agent status changes.
///
/// Called when the agent starts thinking, finishes, or changes state.
/// Channels can use this to show typing indicators or status messages.
///
/// Arguments:
/// - update: The status update
on-status: func(update: status-update);
/// Clean up channel resources.
///
/// Called when the channel is being unloaded.