mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
fix(channel,attachment): channel quality refactor & attachment pipeline fixes (#349)
* feat(channel): add DingTalk channel adapter - Add DingTalk channel adapter (`internal/channel/adapters/dingtalk/`) using dingtalk-stream-sdk-go, supporting inbound message receiving and outbound text/markdown reply - Register DingTalk adapter in cmd/agent and cmd/memoh - Add go.mod dependency: github.com/memohai/dingtalk-stream-sdk-go - Add Dingtalk and Wecom SVG icons and Vue components to @memohai/icon - Refactor existing icon components to remove redundant inline wrappers - Add `channelTypeDisplayName` util for consistent channel label resolution - Add DingTalk/WeCom i18n entries (en/zh) for types and typesShort - Extend channel-icon, bot-channels, channel-settings-panel to support dingtalk/wecom - Use channelTypeDisplayName in profile page to replace ad-hoc i18n lookup * fix(channel,attachment): channel quality refactor & attachment pipeline fixes Channel module: - Fix RemoveAdapter not cleaning connectionMeta (stale status leak) - Fix preparedAttachmentTypeFromMime misclassifying image/gif - Fix sleepWithContext time.After goroutine/timer leak - Export IsDataURL/IsHTTPURL/IsDataPath, dedup across packages - Cache OutboundPolicy in managerOutboundStream to avoid repeated lookups - Split OutboundAttachmentStore: extract ContainerAttachmentIngester interface - Add ManagerOption funcs (WithInboundQueueSize, WithInboundWorkers, WithRefreshInterval) - Add thread-safety docs on OutboundStream / managerOutboundStream - Add debug logs on successful send/edit paths - Expand outbound_prepare_test.go with 21 new cases - Convert no-receiver adapter helpers to package-level funcs; drop unused params DingTalk adapter: - Implement AttachmentResolver: download inbound media via /v1.0/robot/messageFiles/download - Fix pure-image inbound messages failing due to missing resolver Attachment pipeline: - Fix images invisible to LLM in pipeline (DCP) path: inject InlineImages into last user message when cfg.Query is empty - Fix public_url fallback: skip direct URL-to-LLM when ContentHash is set, always prefer inlined persisted asset - Inject path: carry ImageParts through agent.InjectMessage; inline persisted attachments in resolver inject goroutine so mid-stream images reach the model - Fix ResolveMime for images: prefer content-sniffed MIME over platform-declared MIME (fixes Feishu sending image/png header for actual JPEG content → API 400)
This commit is contained in:
@@ -40,7 +40,7 @@ type feishuOutboundStream struct {
|
||||
closed atomic.Bool
|
||||
}
|
||||
|
||||
func (s *feishuOutboundStream) Push(ctx context.Context, event channel.StreamEvent) error {
|
||||
func (s *feishuOutboundStream) Push(ctx context.Context, event channel.PreparedStreamEvent) error {
|
||||
if s == nil || s.adapter == nil {
|
||||
return errors.New("feishu stream not configured")
|
||||
}
|
||||
@@ -90,26 +90,28 @@ func (s *feishuOutboundStream) Push(ctx context.Context, event channel.StreamEve
|
||||
if len(event.Attachments) == 0 {
|
||||
return nil
|
||||
}
|
||||
media := channel.Message{
|
||||
Attachments: event.Attachments,
|
||||
}
|
||||
return s.adapter.Send(ctx, s.cfg, channel.OutboundMessage{
|
||||
Target: s.target,
|
||||
Message: media,
|
||||
return s.adapter.Send(ctx, s.cfg, channel.PreparedOutboundMessage{
|
||||
Target: s.target,
|
||||
Message: channel.PreparedMessage{
|
||||
Message: channel.Message{
|
||||
Attachments: feishuLogicalAttachments(event.Attachments),
|
||||
},
|
||||
Attachments: event.Attachments,
|
||||
},
|
||||
})
|
||||
case channel.StreamEventPhaseStart, channel.StreamEventPhaseEnd:
|
||||
return nil
|
||||
case channel.StreamEventAgentStart, channel.StreamEventAgentEnd, channel.StreamEventProcessingStarted, channel.StreamEventProcessingCompleted, channel.StreamEventProcessingFailed:
|
||||
return nil
|
||||
case channel.StreamEventFinal:
|
||||
if event.Final == nil || event.Final.Message.IsEmpty() {
|
||||
if event.Final == nil || event.Final.Message.Message.IsEmpty() {
|
||||
return nil
|
||||
}
|
||||
msg := event.Final.Message
|
||||
bufText := strings.TrimSpace(s.textBuffer.String())
|
||||
finalText := bufText
|
||||
if finalText == "" {
|
||||
finalText = strings.TrimSpace(msg.PlainText())
|
||||
finalText = strings.TrimSpace(msg.Message.PlainText())
|
||||
}
|
||||
if finalText != "" {
|
||||
if err := s.ensureCard(ctx, feishuStreamThinkingText); err != nil {
|
||||
@@ -121,12 +123,13 @@ func (s *feishuOutboundStream) Push(ctx context.Context, event channel.StreamEve
|
||||
}
|
||||
if len(msg.Attachments) > 0 {
|
||||
media := msg
|
||||
media.Format = ""
|
||||
media.Text = ""
|
||||
media.Parts = nil
|
||||
media.Actions = nil
|
||||
media.Reply = nil
|
||||
return s.adapter.Send(ctx, s.cfg, channel.OutboundMessage{
|
||||
media.Message.Format = ""
|
||||
media.Message.Text = ""
|
||||
media.Message.Parts = nil
|
||||
media.Message.Actions = nil
|
||||
media.Message.Reply = nil
|
||||
media.Message.Attachments = feishuLogicalAttachments(media.Attachments)
|
||||
return s.adapter.Send(ctx, s.cfg, channel.PreparedOutboundMessage{
|
||||
Target: s.target,
|
||||
Message: media,
|
||||
})
|
||||
@@ -146,6 +149,17 @@ func (s *feishuOutboundStream) Push(ctx context.Context, event channel.StreamEve
|
||||
}
|
||||
}
|
||||
|
||||
func feishuLogicalAttachments(attachments []channel.PreparedAttachment) []channel.Attachment {
|
||||
if len(attachments) == 0 {
|
||||
return nil
|
||||
}
|
||||
logical := make([]channel.Attachment, 0, len(attachments))
|
||||
for _, att := range attachments {
|
||||
logical = append(logical, att.Logical)
|
||||
}
|
||||
return logical
|
||||
}
|
||||
|
||||
func (s *feishuOutboundStream) Close(ctx context.Context) error {
|
||||
if s == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user