fix: slash command responses no longer overwrite the ongoing task status bubble
Co-authored-by: dj-oyu <68707227+dj-oyu@users.noreply.github.com>
This commit is contained in:
parent
86b5baccf5
commit
ee47513b4d
4 changed files with 69 additions and 14 deletions
|
|
@ -189,6 +189,7 @@ func (al *AgentLoop) Run(ctx context.Context) error {
|
|||
Channel: msg.Channel,
|
||||
ChatID: msg.ChatID,
|
||||
Content: response,
|
||||
SkipPlaceholder: true,
|
||||
})
|
||||
}
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -798,6 +798,57 @@ func TestResolveProvider_EmptyNameReturnsFallback(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestSlashCommandResponseSkipsPlaceholder verifies that slash command responses
|
||||
// are published with SkipPlaceholder=true so they don't overwrite the ongoing task
|
||||
// status bubble.
|
||||
func TestSlashCommandResponseSkipsPlaceholder(t *testing.T) {
|
||||
tmpDir, err := os.MkdirTemp("", "agent-test-*")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
cfg := &config.Config{
|
||||
Agents: config.AgentsConfig{
|
||||
Defaults: config.AgentDefaults{
|
||||
Workspace: tmpDir,
|
||||
Model: "test-model",
|
||||
MaxTokens: 4096,
|
||||
MaxToolIterations: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
msgBus := bus.NewMessageBus()
|
||||
provider := &mockProvider{}
|
||||
al := NewAgentLoop(cfg, msgBus, provider)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
go func() {
|
||||
_ = al.Run(ctx)
|
||||
}()
|
||||
|
||||
// Send a slash command
|
||||
msgBus.PublishInbound(bus.InboundMessage{
|
||||
Channel: "telegram",
|
||||
SenderID: "user1",
|
||||
ChatID: "chat1",
|
||||
Content: "/todo",
|
||||
})
|
||||
|
||||
// Read the outbound message
|
||||
outMsg, ok := msgBus.SubscribeOutbound(ctx)
|
||||
if !ok {
|
||||
t.Fatal("expected outbound message from slash command")
|
||||
}
|
||||
|
||||
if !outMsg.SkipPlaceholder {
|
||||
t.Errorf("expected SkipPlaceholder=true for slash command response, got false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildTaskReminder_Truncation(t *testing.T) {
|
||||
// Build a long message (1000 runes)
|
||||
longMsg := strings.Repeat("あ", 1000)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ type OutboundMessage struct {
|
|||
ChatID string `json:"chat_id"`
|
||||
Content string `json:"content"`
|
||||
IsStatus bool `json:"is_status,omitempty"`
|
||||
SkipPlaceholder bool `json:"skip_placeholder,omitempty"`
|
||||
}
|
||||
|
||||
type MessageHandler func(InboundMessage) error
|
||||
|
|
|
|||
|
|
@ -201,6 +201,7 @@ func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) err
|
|||
|
||||
// Try to edit placeholder
|
||||
firstChunkSent := false
|
||||
if !msg.SkipPlaceholder {
|
||||
if pID, ok := c.placeholders.Load(msg.ChatID); ok {
|
||||
c.placeholders.Delete(msg.ChatID)
|
||||
editMsg := tu.EditMessageText(tu.ID(chatID), pID.(int), markdownToTelegramHTML(chunks[0]))
|
||||
|
|
@ -211,6 +212,7 @@ func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) err
|
|||
}
|
||||
// Fallback to new message if edit fails
|
||||
}
|
||||
}
|
||||
|
||||
sendChunk := func(text string) error {
|
||||
tgMsg := tu.Message(tu.ID(chatID), markdownToTelegramHTML(text))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue