feat(im): tenant-wide IM channels overview under the user menu
Until now the IM channels a tenant has connected were only visible from
inside each agent's editor (AgentEditorModal → IMChannelPanel). Finding
out which bots are live across all agents meant clicking through every
one of them. Add a tenant-scoped overview so the set of connected IMs is
always one hop away from the avatar.
Backend
- im.Service.ListChannelsByTenant(tenantID) returns all non-deleted
channels in the tenant, LEFT JOIN'd with custom_agents.name so
built-in agents (which don't have rows in custom_agents) still show
up with an empty agent_name; the frontend substitutes a localized
"built-in agent" label.
- Credentials are intentionally stripped from this response — the list
view is read-only and the editor route (GET /agents/:id/im-channels)
remains the only source for secrets.
- New ChannelWithAgent DTO + IMHandler.ListAllIMChannels wired at
GET /api/v1/im-channels under the existing RegisterIMChannelRoutes
group, so auth middleware is inherited.
Frontend
- IMChannelsOverviewPanel.vue: floating submenu pane, stacked rows
(agent on top, channel below) with identical 20px avatars and 12px
labels so neither identity dominates. Each row is the whole click
target (jumps to the agent editor); the switch uses @click.stop to
toggle in place without triggering navigation.
- UserMenu.vue: new hover-driven submenu entry ("已接入的 IM" + link
icon). The pane is teleported to <body> because the sidebar container
has overflow:hidden that would otherwise clip right-flying content.
Position is computed from the menu item's rect and clamps/flips
against the viewport edges.
- "Live" indicator: a pulsing green dot on the menu item when at least
one channel is enabled. UserMenu prefetches the list once on mount;
the panel re-emits channels-changed after every load/toggle so the
dot stays in sync. Respects prefers-reduced-motion.
- AgentList.vue: supplement the existing onMounted-only
checkAndOpenEditModal with a watch(route.query.edit) so
router.push({ path: '/platform/agents', query: { edit, section } })
from an already-mounted AgentList (the common case when navigating
from the overview) opens the editor immediately instead of only
after a hard refresh.
Assets
- Seven platform SVGs under assets/img/im/, pulled from iconify
(simple-icons / logos / tdesign / icon-park / remix icon) and baked
with brand colors so monochrome sources (wecom/wechat/dingtalk/
feishu) don't render black.
i18n
- New imOverview namespace in zh-CN / en-US / ko-KR / ru-RU covering
the menu label, panel title/subtitle, column headers, builtin-agent
fallback, and the live-indicator tooltip.
Tested
- go build ./...
- go test ./internal/im/...
- vue-tsc --noEmit
- npm run build
This commit is contained in:
@@ -134,6 +134,26 @@ func (h *IMHandler) ListIMChannels(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"data": channels})
|
||||
}
|
||||
|
||||
// ListAllIMChannels lists every IM channel in the current tenant, across
|
||||
// agents, for the cross-agent overview page. Credentials are intentionally
|
||||
// NOT included in the response — callers that need credentials must use the
|
||||
// per-agent endpoint (GET /agents/:id/im-channels).
|
||||
func (h *IMHandler) ListAllIMChannels(c *gin.Context) {
|
||||
tenantID, ok := c.Request.Context().Value(types.TenantIDContextKey).(uint64)
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
||||
return
|
||||
}
|
||||
|
||||
channels, err := h.imService.ListChannelsByTenant(tenantID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list channels"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"data": channels})
|
||||
}
|
||||
|
||||
// UpdateIMChannel updates an IM channel.
|
||||
func (h *IMHandler) UpdateIMChannel(c *gin.Context) {
|
||||
channelID := c.Param("id")
|
||||
|
||||
@@ -2058,6 +2058,48 @@ func (s *Service) ListChannelsByAgent(agentID string, tenantID uint64) ([]IMChan
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
// ChannelWithAgent augments an IMChannel summary with its owning agent's display name.
|
||||
// Credentials are intentionally omitted so this type is safe to return from a
|
||||
// tenant-scoped list endpoint; callers that need credentials must use the
|
||||
// per-agent endpoint which enforces the same tenant scope anyway.
|
||||
type ChannelWithAgent struct {
|
||||
ID string `json:"id"`
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
AgentID string `json:"agent_id"`
|
||||
AgentName string `json:"agent_name"`
|
||||
Platform string `json:"platform"`
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Mode string `json:"mode"`
|
||||
OutputMode string `json:"output_mode"`
|
||||
SessionMode string `json:"session_mode"`
|
||||
BotIdentity string `json:"bot_identity"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// ListChannelsByTenant returns all non-deleted IM channels in the given tenant,
|
||||
// joined with custom_agents.name. Built-in agent IDs (whose rows may not exist
|
||||
// in custom_agents) produce an empty AgentName — the frontend can substitute a
|
||||
// localized "builtin agent" label in that case.
|
||||
func (s *Service) ListChannelsByTenant(tenantID uint64) ([]ChannelWithAgent, error) {
|
||||
var rows []ChannelWithAgent
|
||||
err := s.db.Table("im_channels AS c").
|
||||
Select(`c.id, c.tenant_id, c.agent_id,
|
||||
COALESCE(a.name, '') AS agent_name,
|
||||
c.platform, c.name, c.enabled, c.mode, c.output_mode,
|
||||
c.session_mode, c.bot_identity, c.created_at, c.updated_at`).
|
||||
Joins(`LEFT JOIN custom_agents AS a
|
||||
ON a.id = c.agent_id AND a.tenant_id = c.tenant_id`).
|
||||
Where("c.tenant_id = ? AND c.deleted_at IS NULL", tenantID).
|
||||
Order("c.created_at DESC").
|
||||
Scan(&rows).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
// CreateChannel creates a new IM channel and optionally starts it.
|
||||
// Returns a duplicate_bot error if the bot identity is already used by another channel.
|
||||
func (s *Service) CreateChannel(channel *IMChannel) error {
|
||||
|
||||
@@ -676,6 +676,7 @@ func RegisterIMChannelRoutes(r *gin.RouterGroup, imHandler *handler.IMHandler) {
|
||||
// Channel operations by channel ID
|
||||
channels := r.Group("/im-channels")
|
||||
{
|
||||
channels.GET("", imHandler.ListAllIMChannels)
|
||||
channels.PUT("/:id", imHandler.UpdateIMChannel)
|
||||
channels.DELETE("/:id", imHandler.DeleteIMChannel)
|
||||
channels.POST("/:id/toggle", imHandler.ToggleIMChannel)
|
||||
|
||||
Reference in New Issue
Block a user