fix: create placeholder after echo so status bubbles appear below

Move placeholder creation from SendCommand to the agent loop, right
after the "via MiniApp" echo is sent.  This ensures the chat bubble
order is: user echo first, then status updates below it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-02-22 16:54:20 +09:00
parent 14333272d4
commit fd32a28524
2 changed files with 10 additions and 13 deletions

View file

@ -233,7 +233,7 @@ func gatewayCmd() {
if webAppURL != "" { if webAppURL != "" {
provider := &agentLoopDataProvider{loop: agentLoop, workspace: cfg.WorkspacePath()} provider := &agentLoopDataProvider{loop: agentLoop, workspace: cfg.WorkspacePath()}
sender := &telegramCommandSender{bus: msgBus, channelManager: channelManager} sender := &telegramCommandSender{bus: msgBus}
miniappNotifier = miniapp.NewStateNotifier() miniappNotifier = miniapp.NewStateNotifier()
handler := miniapp.NewHandler(provider, sender, cfg.Channels.Telegram.Token, miniappNotifier) handler := miniapp.NewHandler(provider, sender, cfg.Channels.Telegram.Token, miniappNotifier)
agentLoop.OnStateChange = miniappNotifier.Notify agentLoop.OnStateChange = miniappNotifier.Notify
@ -508,20 +508,9 @@ func collectGitRepoInfo(gitRoot string) miniapp.GitInfo {
// telegramCommandSender injects Mini App commands into the message bus. // telegramCommandSender injects Mini App commands into the message bus.
type telegramCommandSender struct { type telegramCommandSender struct {
bus *bus.MessageBus bus *bus.MessageBus
channelManager *channels.Manager
} }
func (s *telegramCommandSender) SendCommand(senderID, chatID, command string) { func (s *telegramCommandSender) SendCommand(senderID, chatID, command string) {
// Create a placeholder so status messages (streaming preview, tool progress)
// are visible to the user while the LLM processes the request.
if s.channelManager != nil {
if ch, ok := s.channelManager.GetChannel("telegram"); ok {
if tc, ok := ch.(*channels.TelegramChannel); ok {
tc.CreatePlaceholder(context.Background(), chatID)
}
}
}
s.bus.PublishInbound(bus.InboundMessage{ s.bus.PublishInbound(bus.InboundMessage{
Channel: "telegram", Channel: "telegram",
SenderID: senderID, SenderID: senderID,

View file

@ -259,6 +259,14 @@ func (al *AgentLoop) Run(ctx context.Context) error {
Content: "via MiniApp: " + msg.Content, Content: "via MiniApp: " + msg.Content,
SkipPlaceholder: true, SkipPlaceholder: true,
}) })
// Create a placeholder AFTER the echo so status updates appear below it.
if al.channelManager != nil {
if ch, ok := al.channelManager.GetChannel(msg.Channel); ok {
if tc, ok := ch.(*channels.TelegramChannel); ok {
tc.CreatePlaceholder(ctx, msg.ChatID)
}
}
}
} }
// Fast path: handle slash commands immediately without blocking the LLM worker. // Fast path: handle slash commands immediately without blocking the LLM worker.