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:
BBQ
2026-04-09 14:36:11 +08:00
committed by GitHub
parent fffe5ac34f
commit d3bf6bc90a
76 changed files with 4851 additions and 1185 deletions
+34 -10
View File
@@ -31,6 +31,7 @@ import (
"github.com/memohai/memoh/internal/bots"
"github.com/memohai/memoh/internal/browsercontexts"
"github.com/memohai/memoh/internal/channel"
"github.com/memohai/memoh/internal/channel/adapters/dingtalk"
"github.com/memohai/memoh/internal/channel/adapters/discord"
"github.com/memohai/memoh/internal/channel/adapters/feishu"
"github.com/memohai/memoh/internal/channel/adapters/local"
@@ -444,6 +445,8 @@ func provideChannelRegistry(log *slog.Logger, hub *local.RouteHub, mediaService
feishuAdapter.SetAssetOpener(mediaService)
registry.MustRegister(feishuAdapter)
registry.MustRegister(wecom.NewWeComAdapter(log))
dingTalkAdapter := dingtalk.NewDingTalkAdapter(log)
registry.MustRegister(dingTalkAdapter)
weixinAdapter := weixin.NewWeixinAdapter(log)
weixinAdapter.SetAssetOpener(mediaService)
registry.MustRegister(weixinAdapter)
@@ -493,13 +496,14 @@ func provideChannelRouter(log *slog.Logger, registry *channel.Registry, hub *loc
return processor
}
func provideChannelManager(log *slog.Logger, registry *channel.Registry, channelStore *channel.Store, channelRouter *inbound.ChannelInboundProcessor) *channel.Manager {
func provideChannelManager(log *slog.Logger, registry *channel.Registry, channelStore *channel.Store, channelRouter *inbound.ChannelInboundProcessor, mediaService *media.Service) *channel.Manager {
if adapter, ok := registry.Get(matrix.Type); ok {
if matrixAdapter, ok := adapter.(*matrix.MatrixAdapter); ok {
matrixAdapter.SetSyncStateSaver(channelStore.SaveMatrixSyncSinceToken)
}
}
mgr := channel.NewManager(log, registry, channelStore, channelRouter)
mgr.SetAttachmentStore(mediaService)
if mw := channelRouter.IdentityMiddleware(); mw != nil {
mgr.Use(mw)
}
@@ -1062,26 +1066,46 @@ func (a *skillLoaderAdapter) LoadSkills(ctx context.Context, botID string) ([]fl
type mediaAssetResolverAdapter struct{ media *media.Service }
func (a *mediaAssetResolverAdapter) Stat(ctx context.Context, botID, contentHash string) (media.Asset, error) {
if a == nil || a.media == nil {
return media.Asset{}, errors.New("media service not configured")
}
return a.media.Stat(ctx, botID, contentHash)
}
func (a *mediaAssetResolverAdapter) Open(ctx context.Context, botID, contentHash string) (io.ReadCloser, media.Asset, error) {
if a == nil || a.media == nil {
return nil, media.Asset{}, errors.New("media service not configured")
}
return a.media.Open(ctx, botID, contentHash)
}
func (a *mediaAssetResolverAdapter) Ingest(ctx context.Context, input media.IngestInput) (media.Asset, error) {
if a == nil || a.media == nil {
return media.Asset{}, errors.New("media service not configured")
}
return a.media.Ingest(ctx, input)
}
func (a *mediaAssetResolverAdapter) GetByStorageKey(ctx context.Context, botID, storageKey string) (messaging.AssetMeta, error) {
if a == nil || a.media == nil {
return messaging.AssetMeta{}, errors.New("media service not configured")
}
asset, err := a.media.GetByStorageKey(ctx, botID, storageKey)
if err != nil {
return messaging.AssetMeta{}, err
return a.media.GetByStorageKey(ctx, botID, storageKey)
}
func (a *mediaAssetResolverAdapter) AccessPath(asset media.Asset) string {
if a == nil || a.media == nil {
return ""
}
return messaging.AssetMeta{ContentHash: asset.ContentHash, Mime: asset.Mime, SizeBytes: asset.SizeBytes, StorageKey: asset.StorageKey}, nil
return a.media.AccessPath(asset)
}
func (a *mediaAssetResolverAdapter) IngestContainerFile(ctx context.Context, botID, containerPath string) (messaging.AssetMeta, error) {
if a == nil || a.media == nil {
return messaging.AssetMeta{}, errors.New("media service not configured")
}
asset, err := a.media.IngestContainerFile(ctx, botID, containerPath)
if err != nil {
return messaging.AssetMeta{}, err
}
return messaging.AssetMeta{ContentHash: asset.ContentHash, Mime: asset.Mime, SizeBytes: asset.SizeBytes, StorageKey: asset.StorageKey}, nil
return a.media.IngestContainerFile(ctx, botID, containerPath)
}
type gatewayAssetLoaderAdapter struct{ media *media.Service }