mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
fix: strip agent tags from IM/WebUI output and fix attachment display after refresh
Three independent bugs fixed: 1. IM channels were sending raw <attachments>/<reactions>/<speech> tag blocks alongside file attachments. Now ExtractAssistantOutputs strips these tags before building the outbound channel message. 2. WebUI rendered these tags as markdown after page refresh. Now extractMessageText strips agent tags for non-user messages. 3. WebUI lost attachment blocks after refresh because convertMessagesToChats did not call buildAssetBlocks when merging assistant messages into a pending tool-call group. Also made LinkOutboundAssets session-aware so assets are linked to the correct assistant message.
This commit is contained in:
@@ -3,6 +3,7 @@ package flow
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/memohai/memoh/internal/agent"
|
||||
"github.com/memohai/memoh/internal/conversation"
|
||||
)
|
||||
|
||||
@@ -28,6 +29,7 @@ func ExtractAssistantOutputs(messages []conversation.ModelMessage) []conversatio
|
||||
if content == "" && len(parts) == 0 {
|
||||
continue
|
||||
}
|
||||
content = agent.StripAgentTags(content)
|
||||
outputs = append(outputs, conversation.AssistantOutput{Content: content, Parts: parts})
|
||||
}
|
||||
return outputs
|
||||
|
||||
@@ -200,14 +200,23 @@ func (r *Resolver) resolvePersistSenderIDs(ctx context.Context, req conversation
|
||||
}
|
||||
|
||||
// LinkOutboundAssets links bot-generated assets to the latest assistant
|
||||
// message for the given bot. Used by the WebSocket path where attachment
|
||||
// ingestion happens after message persistence.
|
||||
func (r *Resolver) LinkOutboundAssets(ctx context.Context, botID string, assets []messagepkg.AssetRef) {
|
||||
// message. When sessionID is provided, the search is scoped to that session;
|
||||
// otherwise it falls back to a bot-wide search.
|
||||
// Used by the WebSocket path where attachment ingestion happens after message
|
||||
// persistence.
|
||||
func (r *Resolver) LinkOutboundAssets(ctx context.Context, botID, sessionID string, assets []messagepkg.AssetRef) {
|
||||
if r.messageService == nil || len(assets) == 0 || strings.TrimSpace(botID) == "" {
|
||||
return
|
||||
}
|
||||
// ListLatest returns messages in DESC order (newest first).
|
||||
msgs, err := r.messageService.ListLatest(ctx, botID, 5)
|
||||
var (
|
||||
msgs []messagepkg.Message
|
||||
err error
|
||||
)
|
||||
if strings.TrimSpace(sessionID) != "" {
|
||||
msgs, err = r.messageService.ListLatestBySession(ctx, sessionID, 5)
|
||||
} else {
|
||||
msgs, err = r.messageService.ListLatest(ctx, botID, 5)
|
||||
}
|
||||
if err != nil {
|
||||
r.logger.Warn("LinkOutboundAssets: list latest failed", slog.Any("error", err))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user