mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
fix(channel): create new message when tool calling
This commit is contained in:
@@ -70,11 +70,20 @@ func (s *feishuOutboundStream) Push(ctx context.Context, event channel.StreamEve
|
||||
}
|
||||
return s.patchCard(ctx, s.textBuffer.String())
|
||||
case channel.StreamEventToolCallStart:
|
||||
if err := s.ensureCard(ctx, feishuStreamToolHintText); err != nil {
|
||||
return err
|
||||
bufText := strings.TrimSpace(s.textBuffer.String())
|
||||
if s.cardMessageID != "" && bufText != "" {
|
||||
_ = s.patchCard(ctx, bufText)
|
||||
}
|
||||
return s.patchCard(ctx, feishuStreamToolHintText)
|
||||
s.cardMessageID = ""
|
||||
s.lastPatched = ""
|
||||
s.lastPatchedAt = time.Time{}
|
||||
s.textBuffer.Reset()
|
||||
return nil
|
||||
case channel.StreamEventToolCallEnd:
|
||||
s.cardMessageID = ""
|
||||
s.lastPatched = ""
|
||||
s.lastPatchedAt = time.Time{}
|
||||
s.textBuffer.Reset()
|
||||
return nil
|
||||
case channel.StreamEventAttachment:
|
||||
if len(event.Attachments) == 0 {
|
||||
@@ -94,9 +103,10 @@ func (s *feishuOutboundStream) Push(ctx context.Context, event channel.StreamEve
|
||||
return nil
|
||||
}
|
||||
msg := event.Final.Message
|
||||
finalText := strings.TrimSpace(msg.PlainText())
|
||||
bufText := strings.TrimSpace(s.textBuffer.String())
|
||||
finalText := bufText
|
||||
if finalText == "" {
|
||||
finalText = strings.TrimSpace(s.textBuffer.String())
|
||||
finalText = strings.TrimSpace(msg.PlainText())
|
||||
}
|
||||
if finalText != "" {
|
||||
if err := s.ensureCard(ctx, feishuStreamThinkingText); err != nil {
|
||||
|
||||
@@ -217,11 +217,29 @@ func (s *telegramOutboundStream) Push(ctx context.Context, event channel.StreamE
|
||||
case channel.StreamEventStatus:
|
||||
return nil
|
||||
case channel.StreamEventToolCallStart:
|
||||
if err := s.ensureStreamMessage(ctx, telegramStreamToolHintText); err != nil {
|
||||
return err
|
||||
s.mu.Lock()
|
||||
bufText := strings.TrimSpace(s.buf.String())
|
||||
hasMsg := s.streamMsgID != 0
|
||||
s.mu.Unlock()
|
||||
if hasMsg && bufText != "" {
|
||||
_ = s.editStreamMessageFinal(ctx, bufText)
|
||||
}
|
||||
return s.editStreamMessageFinal(ctx, telegramStreamToolHintText)
|
||||
s.mu.Lock()
|
||||
s.streamMsgID = 0
|
||||
s.streamChatID = 0
|
||||
s.lastEdited = ""
|
||||
s.lastEditedAt = time.Time{}
|
||||
s.buf.Reset()
|
||||
s.mu.Unlock()
|
||||
return nil
|
||||
case channel.StreamEventToolCallEnd:
|
||||
s.mu.Lock()
|
||||
s.streamMsgID = 0
|
||||
s.streamChatID = 0
|
||||
s.lastEdited = ""
|
||||
s.lastEditedAt = time.Time{}
|
||||
s.buf.Reset()
|
||||
s.mu.Unlock()
|
||||
return nil
|
||||
case channel.StreamEventAttachment:
|
||||
if len(event.Attachments) == 0 {
|
||||
@@ -271,12 +289,13 @@ func (s *telegramOutboundStream) Push(ctx context.Context, event channel.StreamE
|
||||
return nil
|
||||
}
|
||||
msg := event.Final.Message
|
||||
finalText := strings.TrimSpace(msg.PlainText())
|
||||
s.mu.Lock()
|
||||
if finalText == "" {
|
||||
finalText = strings.TrimSpace(s.buf.String())
|
||||
}
|
||||
bufText := strings.TrimSpace(s.buf.String())
|
||||
s.mu.Unlock()
|
||||
finalText := bufText
|
||||
if finalText == "" {
|
||||
finalText = strings.TrimSpace(msg.PlainText())
|
||||
}
|
||||
// Convert markdown to Telegram HTML for the final message.
|
||||
formatted, pm := formatTelegramOutput(finalText, msg.Format)
|
||||
if pm != "" {
|
||||
|
||||
Reference in New Issue
Block a user