feat: stream tool activity to Telegram in real time#113
Open
williamlmao wants to merge 1 commit intoTinyAGI:mainfrom
Open
feat: stream tool activity to Telegram in real time#113williamlmao wants to merge 1 commit intoTinyAGI:mainfrom
williamlmao wants to merge 1 commit intoTinyAGI:mainfrom
Conversation
When an agent uses tools (Read, Write, Bash, Grep, etc.), Telegram users now see live updates like "Read /src/index.ts" and "Ran npm test" as the agent works, instead of waiting silently for the final response. How it works: - invoke.ts: Claude CLI now runs with --output-format stream-json and streams stdout line-by-line. Each tool_use event is parsed into a human-readable summary via summarizeToolUse(), and an onActivity callback fires immediately. - queue-processor.ts: For Telegram messages, an activity emitter writes partial responses (partial: true, updateType: 'activity') to the outgoing queue as tools are called. - telegram-client.ts: Partial responses are sent immediately but keep the message in pending state. Only the final response clears pending. - types.ts: ResponseData gains sessionId, partial, and updateType fields. Also extracts Claude session IDs from streaming events for conversation continuity tracking. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--output-format stream-jsonand stdout is parsed line-by-line in real time to detecttool_useeventsChanges
src/lib/invoke.ts(main change)runClaudeCommand()which spawns the Claude CLI and streams JSONL events in real timesummarizeToolUse()to turn raw tool calls into readable strings (e.g.Read /src/index.ts,Ran npm test,Searched for "handleClick")processClaudeEvent()to parse streaming events and detect tool_use/tool_result blocksinvokeAgent()now accepts anonActivitycallback, returnsAgentInvokeResult(text + sessionId) instead of a plain stringsrc/queue-processor.tswriteResponse()helper that supportspartial,updateType, andsessionIdfieldsactivityEmitterForAgent()— creates a callback that writes partial activity responses to the outgoing queue when tools firestreamActivitiesEnabled = channel === 'telegram')src/channels/telegram-client.tsResponseDatainterface extended withsessionId,partial,updateTypesrc/lib/types.tsResponseData: addedsessionId?,partial?,updateType?fieldsChainStep: addedsessionId?fieldTest plan
🤖 Generated with Claude Code