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
@@ -262,6 +262,28 @@ export function listIMChannels(agentId: string) {
|
||||
return get<{ data: IMChannel[] }>(`/api/v1/agents/${agentId}/im-channels`);
|
||||
}
|
||||
|
||||
// Tenant-wide overview row. Credentials are intentionally omitted — use
|
||||
// listIMChannels(agentId) when you need to edit a specific channel.
|
||||
export interface IMChannelOverview {
|
||||
id: string;
|
||||
tenant_id: number;
|
||||
agent_id: string;
|
||||
agent_name: string; // empty string for built-in agents
|
||||
platform: IMChannel['platform'];
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
mode: IMChannel['mode'];
|
||||
output_mode: IMChannel['output_mode'];
|
||||
session_mode?: IMChannel['session_mode'];
|
||||
bot_identity: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export function listAllIMChannels() {
|
||||
return get<{ data: IMChannelOverview[] }>('/api/v1/im-channels');
|
||||
}
|
||||
|
||||
export function createIMChannel(agentId: string, data: Partial<IMChannel>) {
|
||||
return post<{ data: IMChannel }>(`/api/v1/agents/${agentId}/im-channels`, data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="#1677ff" d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10s10-4.477 10-10S17.523 2 12 2m4.49 9.04l-.006.014c-.42.898-1.516 2.66-1.516 2.66l-.005-.012l-.32.558h1.543l-2.948 3.919l.67-2.666h-1.215l.422-1.763a17 17 0 0 0-1.223.349s-.646.378-1.862-.729c0 0-.82-.722-.344-.902c.202-.077.981-.175 1.595-.257a80 80 0 0 1 1.338-.172s-2.555.039-3.161-.057c-.606-.095-1.375-1.107-1.539-1.996c0 0-.253-.488.545-.257s4.101.9 4.101.9S8.27 9.312 7.983 8.99c-.286-.32-.841-1.754-.769-2.634c0 0 .031-.22.257-.16c0 0 3.176 1.45 5.347 2.245s4.06 1.199 3.816 2.228c-.02.087-.072.216-.144.37"/></svg>
|
||||
|
After Width: | Height: | Size: 672 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 48 48"><g fill="#00d6b9" fill-rule="evenodd" clip-rule="evenodd"><path d="M41.0716 5.99409L3.31071 16.5187L12.3856 25.8126L20.7998 25.9594L30.4827 16.5187C30.2266 15.9943 30.0985 15.5552 30.0985 15.2013C30.0985 14.4074 30.4104 13.7786 30.8947 13.333C31.7241 12.57 32.7222 12.4558 33.8889 12.9905L41.0716 5.99409Z"/><path d="M42.1021 6.72842L31.5775 44.4893L22.2836 35.4144L22.1367 27.0002L31.5115 17.4816C32.0195 17.8454 32.5743 18.0105 33.1759 17.9769C34.0784 17.9264 34.6614 17.3813 34.9349 17.0602C35.2083 16.7392 35.5293 16.2051 35.5025 15.4113C35.4847 14.8821 35.3109 14.3941 34.9812 13.9472L42.1021 6.72842Z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 705 B |
|
After Width: | Height: | Size: 6.3 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256"><path fill="#e01e5a" d="M53.841 161.32c0 14.832-11.987 26.82-26.819 26.82S.203 176.152.203 161.32c0-14.831 11.987-26.818 26.82-26.818H53.84zm13.41 0c0-14.831 11.987-26.818 26.819-26.818s26.819 11.987 26.819 26.819v67.047c0 14.832-11.987 26.82-26.82 26.82c-14.83 0-26.818-11.988-26.818-26.82z"/><path fill="#36c5f0" d="M94.07 53.638c-14.832 0-26.82-11.987-26.82-26.819S79.239 0 94.07 0s26.819 11.987 26.819 26.819v26.82zm0 13.613c14.832 0 26.819 11.987 26.819 26.819s-11.987 26.819-26.82 26.819H26.82C11.987 120.889 0 108.902 0 94.069c0-14.83 11.987-26.818 26.819-26.818z"/><path fill="#2eb67d" d="M201.55 94.07c0-14.832 11.987-26.82 26.818-26.82s26.82 11.988 26.82 26.82s-11.988 26.819-26.82 26.819H201.55zm-13.41 0c0 14.832-11.988 26.819-26.82 26.819c-14.831 0-26.818-11.987-26.818-26.82V26.82C134.502 11.987 146.489 0 161.32 0s26.819 11.987 26.819 26.819z"/><path fill="#ecb22e" d="M161.32 201.55c14.832 0 26.82 11.987 26.82 26.818s-11.988 26.82-26.82 26.82c-14.831 0-26.818-11.988-26.818-26.82V201.55zm0-13.41c-14.831 0-26.818-11.988-26.818-26.82c0-14.831 11.987-26.818 26.819-26.818h67.25c14.832 0 26.82 11.987 26.82 26.819s-11.988 26.819-26.82 26.819z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256"><defs><linearGradient id="SVG6DaOZcwt" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0%" stop-color="#2aabee"/><stop offset="100%" stop-color="#229ed9"/></linearGradient></defs><path fill="url(#SVG6DaOZcwt)" d="M128 0C94.06 0 61.48 13.494 37.5 37.49A128.04 128.04 0 0 0 0 128c0 33.934 13.5 66.514 37.5 90.51C61.48 242.506 94.06 256 128 256s66.52-13.494 90.5-37.49c24-23.996 37.5-56.576 37.5-90.51s-13.5-66.514-37.5-90.51C194.52 13.494 161.94 0 128 0"/><path fill="#fff" d="M57.94 126.648q55.98-24.384 74.64-32.152c35.56-14.786 42.94-17.354 47.76-17.441c1.06-.017 3.42.245 4.96 1.49c1.28 1.05 1.64 2.47 1.82 3.467c.16.996.38 3.266.2 5.038c-1.92 20.24-10.26 69.356-14.5 92.026c-1.78 9.592-5.32 12.808-8.74 13.122c-7.44.684-13.08-4.912-20.28-9.63c-11.26-7.386-17.62-11.982-28.56-19.188c-12.64-8.328-4.44-12.906 2.76-20.386c1.88-1.958 34.64-31.748 35.26-34.45c.08-.338.16-1.598-.6-2.262c-.74-.666-1.84-.438-2.64-.258c-1.14.256-19.12 12.152-54 35.686c-5.1 3.508-9.72 5.218-13.88 5.128c-4.56-.098-13.36-2.584-19.9-4.708c-8-2.606-14.38-3.984-13.82-8.41c.28-2.304 3.46-4.662 9.52-7.072"/></svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="#07c160" d="M15.85 8.14c.39 0 .77.03 1.14.08C16.31 5.25 13.19 3 9.44 3c-4.25 0-7.7 2.88-7.7 6.43c0 2.05 1.15 3.86 2.94 5.04L3.67 16.5l2.76-1.19c.59.21 1.21.38 1.87.47c-.09-.39-.14-.79-.14-1.21c-.01-3.54 3.44-6.43 7.69-6.43M12 5.89a.96.96 0 1 1 0 1.92a.96.96 0 0 1 0-1.92M6.87 7.82a.96.96 0 1 1 0-1.92a.96.96 0 0 1 0 1.92"/><path fill="#07c160" d="M22.26 14.57c0-2.84-2.87-5.14-6.41-5.14s-6.41 2.3-6.41 5.14s2.87 5.14 6.41 5.14c.58 0 1.14-.08 1.67-.2L20.98 21l-1.2-2.4c1.5-.94 2.48-2.38 2.48-4.03m-8.34-.32a.96.96 0 1 1 .96-.96c.01.53-.43.96-.96.96m3.85 0a.96.96 0 1 1 0-1.92a.96.96 0 0 1 0 1.92"/></svg>
|
||||
|
After Width: | Height: | Size: 700 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="#07c160" d="M12 1c6.075 0 11 4.925 11 11s-4.925 11-11 11S1 18.075 1 12S5.925 1 12 1m3.52 15.49a.35.35 0 0 0-.24.1c-.14.13-.16.34.02.53l.07.07c.44.44.74.99.85 1.57c0 .02.04.23.04.23c.05.19.15.37.29.5c.21.21.51.34.82.34c.3 0 .59-.12.8-.33c.44-.44.44-1.16 0-1.61c-.15-.15-.34-.26-.53-.3l-.15-.03c-.61-.11-1.17-.41-1.62-.86c-.03-.03-.07-.07-.1-.11c-.06-.074-.16-.1-.25-.1M11 4.75c-2.117 0-4.264.77-5.75 2.31C4.111 8.246 3.5 9.72 3.5 11.24c0 1.06.3 2.12.88 3.06c.47.695.993 1.371 1.66 1.89l-.384 1.624a.6.6 0 0 0 .856.673L8.64 17.41c.53.166 1.08.234 1.63.3a8.3 8.3 0 0 0 1.7-.03l.38-.05q.283-.046.564-.112a2.33 2.33 0 0 1-.92-1.605l-.254.037c-.62.067-1.232.03-1.85-.04c-.43-.057-.838-.185-1.25-.31l-1.02.5l.23-.67l-.74-.6c-.513-.401-.917-.934-1.28-1.47c-.4-.65-.61-1.38-.61-2.11c0-1.08.456-2.119 1.26-2.97c1.158-1.198 2.854-1.78 4.5-1.78c1.54 0 3.108.513 4.24 1.58c.365.365.707.75.95 1.21c.177.354.338.722.424 1.107a2.34 2.34 0 0 1 1.811.123c-.075-.716-.33-1.4-.665-2.04c-.329-.62-.776-1.155-1.27-1.65c-1.468-1.38-3.471-2.08-5.47-2.08m9.37 9.77a1.136 1.136 0 0 0-1.1.86l-.03.15a3.1 3.1 0 0 1-.86 1.63c-.04.03-.07.07-.11.1c-.14.13-.14.35 0 .49c.07.06.17.1.26.1h.01c.07 0 .15-.02.26-.13l.07-.07c.44-.44.99-.74 1.57-.85c.023 0 .227-.04.23-.04c.2-.06.37-.16.5-.3c.44-.44.44-1.17 0-1.61c-.21-.21-.5-.33-.8-.33m-4.21-1.07c-.08 0-.16.03-.27.14l-.07.07c-.44.44-.99.74-1.57.85c-.02 0-.23.04-.23.04c-.2.06-.37.16-.5.3c-.44.44-.44 1.17 0 1.61c.21.21.51.34.82.34c.3 0 .59-.12.8-.33c.15-.16.25-.34.29-.53a.4.4 0 0 0 .03-.16c.11-.61.41-1.18.86-1.63c.03-.03.06-.06.1-.09c.146-.115.13-.36 0-.49a.34.34 0 0 0-.26-.12m1.18-1.97c-.3 0-.59.12-.8.33c-.44.44-.44 1.16 0 1.61c.15.15.34.26.53.3c.054.006.144.029.15.03c.61.12 1.17.41 1.62.86c.03.03.07.07.1.11c.08.08.16.1.25.1c.1 0 .16-.04.23-.11c.12-.13.14-.32-.02-.52l-.08-.08c-.44-.44-.74-.99-.85-1.57c0-.02-.04-.23-.04-.23c-.05-.19-.15-.37-.29-.5c-.21-.21-.5-.33-.8-.33"/></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1,393 @@
|
||||
<template>
|
||||
<div class="im-submenu" @click.stop>
|
||||
<div class="submenu-header">
|
||||
<div class="titles">
|
||||
<h4 class="title">{{ $t('imOverview.pageTitle') }}</h4>
|
||||
<p class="subtitle">{{ $t('imOverview.subtitle') }}</p>
|
||||
</div>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
:loading="loading"
|
||||
@click="loadAll"
|
||||
>
|
||||
<template #icon><t-icon name="refresh" /></template>
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<div class="submenu-body">
|
||||
<div v-if="loading && channels.length === 0" class="state-placeholder">
|
||||
<t-loading size="small" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="channels.length === 0" class="state-placeholder">
|
||||
<span class="empty-text">{{ $t('imOverview.empty') }}</span>
|
||||
</div>
|
||||
|
||||
<div v-else class="channels-list">
|
||||
<div
|
||||
v-for="ch in channels"
|
||||
:key="ch.id"
|
||||
class="channel-item"
|
||||
:class="{ 'is-disabled': !ch.enabled }"
|
||||
role="button"
|
||||
:tabindex="0"
|
||||
:title="$t('imOverview.gotoAgentEditor')"
|
||||
@click="gotoAgentEditor(ch)"
|
||||
@keydown.enter="gotoAgentEditor(ch)"
|
||||
@keydown.space.prevent="gotoAgentEditor(ch)"
|
||||
>
|
||||
<!-- Stacked rows: agent on top, IM channel below. Same avatar size
|
||||
and typography → both read as co-equal identities of the row. -->
|
||||
<div class="stack">
|
||||
<div class="stack-row">
|
||||
<span class="row-avatar">
|
||||
<span
|
||||
v-if="agentMeta(ch.agent_id)?.is_builtin"
|
||||
class="builtin-avatar"
|
||||
:class="agentMeta(ch.agent_id)?.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'"
|
||||
>
|
||||
<t-icon
|
||||
:name="agentMeta(ch.agent_id)?.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'"
|
||||
size="12px"
|
||||
/>
|
||||
</span>
|
||||
<span
|
||||
v-else-if="agentMeta(ch.agent_id)?.avatar"
|
||||
class="builtin-avatar agent-emoji"
|
||||
>{{ agentMeta(ch.agent_id)!.avatar }}</span>
|
||||
<AgentAvatar
|
||||
v-else
|
||||
:name="ch.agent_name || ch.agent_id"
|
||||
size="small"
|
||||
/>
|
||||
</span>
|
||||
<span class="row-label" :title="ch.agent_name || agentMeta(ch.agent_id)?.name || ''">
|
||||
{{ ch.agent_name || agentMeta(ch.agent_id)?.name || $t('imOverview.builtinAgent') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="stack-row">
|
||||
<img
|
||||
class="row-avatar platform-logo"
|
||||
:src="platformLogo(ch.platform)"
|
||||
:alt="platformLabel(ch.platform)"
|
||||
/>
|
||||
<span class="row-label" :title="ch.name || platformLabel(ch.platform)">
|
||||
{{ ch.name || platformLabel(ch.platform) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="item-actions" @click.stop>
|
||||
<t-switch
|
||||
:value="ch.enabled"
|
||||
size="small"
|
||||
:loading="togglingId === ch.id"
|
||||
@change="handleToggle(ch)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { MessagePlugin } from 'tdesign-vue-next';
|
||||
import {
|
||||
listAllIMChannels,
|
||||
listAgents,
|
||||
toggleIMChannel,
|
||||
type IMChannelOverview,
|
||||
type CustomAgent,
|
||||
} from '@/api/agent';
|
||||
import AgentAvatar from '@/components/AgentAvatar.vue';
|
||||
|
||||
// Platform logos sourced from iconify (simple-icons / logos / tdesign / remix icon).
|
||||
// Bundled as static assets so they share the app's caching story.
|
||||
import wecomLogo from '@/assets/img/im/wecom.svg';
|
||||
import feishuLogo from '@/assets/img/im/feishu.svg';
|
||||
import slackLogo from '@/assets/img/im/slack.svg';
|
||||
import telegramLogo from '@/assets/img/im/telegram.svg';
|
||||
import dingtalkLogo from '@/assets/img/im/dingtalk.svg';
|
||||
import mattermostLogo from '@/assets/img/im/mattermost.svg';
|
||||
import wechatLogo from '@/assets/img/im/wechat.svg';
|
||||
|
||||
const PLATFORM_LOGO: Record<string, string> = {
|
||||
wecom: wecomLogo,
|
||||
feishu: feishuLogo,
|
||||
slack: slackLogo,
|
||||
telegram: telegramLogo,
|
||||
dingtalk: dingtalkLogo,
|
||||
mattermost: mattermostLogo,
|
||||
wechat: wechatLogo,
|
||||
};
|
||||
|
||||
const props = defineProps<{
|
||||
active: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'close'): void;
|
||||
(e: 'channels-changed', channels: IMChannelOverview[]): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
|
||||
const channels = ref<IMChannelOverview[]>([]);
|
||||
const agentMap = ref<Map<string, CustomAgent>>(new Map());
|
||||
const loading = ref(false);
|
||||
const togglingId = ref<string>('');
|
||||
|
||||
// Parent tells us when the submenu is active (hover/click-open). Reload only
|
||||
// when transitioning into active so we don't refetch on every re-render.
|
||||
watch(
|
||||
() => props.active,
|
||||
(v, old) => {
|
||||
if (v && !old) loadAll();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
function platformLogo(p: string): string {
|
||||
return PLATFORM_LOGO[p] || '';
|
||||
}
|
||||
|
||||
function platformLabel(p: string): string {
|
||||
return t(`agentEditor.im.${p}`);
|
||||
}
|
||||
|
||||
function agentMeta(agentId: string): CustomAgent | undefined {
|
||||
return agentMap.value.get(agentId);
|
||||
}
|
||||
|
||||
async function loadAll() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const [chanResp, agentResp] = await Promise.all([
|
||||
listAllIMChannels(),
|
||||
listAgents(),
|
||||
]);
|
||||
channels.value = chanResp?.data || [];
|
||||
const m = new Map<string, CustomAgent>();
|
||||
(agentResp?.data || []).forEach((a) => m.set(a.id, a));
|
||||
agentMap.value = m;
|
||||
emit('channels-changed', channels.value);
|
||||
} catch (err) {
|
||||
console.error('Failed to load IM overview:', err);
|
||||
MessagePlugin.error(t('imOverview.loadFailed'));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleToggle(ch: IMChannelOverview) {
|
||||
if (togglingId.value) return;
|
||||
togglingId.value = ch.id;
|
||||
try {
|
||||
await toggleIMChannel(ch.id);
|
||||
const resp = await listAllIMChannels();
|
||||
channels.value = resp?.data || [];
|
||||
emit('channels-changed', channels.value);
|
||||
} catch (err: any) {
|
||||
console.error('Failed to toggle IM channel:', err);
|
||||
MessagePlugin.error(err?.message || t('common.operationFailed'));
|
||||
} finally {
|
||||
togglingId.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
function gotoAgentEditor(ch: IMChannelOverview) {
|
||||
emit('close');
|
||||
router.push({
|
||||
path: '/platform/agents',
|
||||
query: { edit: ch.agent_id, section: 'im' },
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.im-submenu {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 300px;
|
||||
max-height: 520px;
|
||||
background: var(--td-bg-color-container);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.submenu-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 12px 14px;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
|
||||
.titles {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin: 0 0 2px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
margin: 0;
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-secondary);
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.submenu-body {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 6px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.state-placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
padding: 40px 0;
|
||||
color: var(--td-text-color-placeholder);
|
||||
|
||||
.empty-text {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.channels-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.channel-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 10px;
|
||||
background: transparent;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
transition: background 0.15s;
|
||||
|
||||
&:hover,
|
||||
&:focus-visible {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
&.is-disabled {
|
||||
opacity: 0.55;
|
||||
}
|
||||
}
|
||||
|
||||
// Stacked rows: agent on top, channel below. Both lines share identical
|
||||
// typography and avatar size so neither dominates — they read as two facets
|
||||
// of the same row rather than a headline + caption.
|
||||
.stack {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.stack-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.row-avatar {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 4px;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.platform-logo {
|
||||
object-fit: contain;
|
||||
background: transparent;
|
||||
padding: 1px;
|
||||
}
|
||||
}
|
||||
|
||||
.row-label {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-primary);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
min-width: 0;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
// Switch stays right-anchored, separated from the stack by the natural row gap.
|
||||
.item-actions {
|
||||
margin-left: 8px;
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.builtin-avatar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 4px;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.agent-emoji {
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
&.normal {
|
||||
background: linear-gradient(135deg, rgba(7, 192, 95, 0.15) 0%, rgba(7, 192, 95, 0.08) 100%);
|
||||
color: var(--td-brand-color-active);
|
||||
}
|
||||
&.agent {
|
||||
background: linear-gradient(135deg, rgba(124, 77, 255, 0.15) 0%, rgba(124, 77, 255, 0.08) 100%);
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
|
||||
// Size the generated AgentAvatar (hash-based gradient + letter) to match the
|
||||
// builtin-avatar and platform-logo so all three rows align perfectly.
|
||||
.stack-row {
|
||||
:deep(.agent-avatar),
|
||||
:deep(.agent-avatar-small) {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
:deep(.agent-avatar-letter) {
|
||||
font-size: 10px !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -47,6 +47,25 @@
|
||||
<t-icon name="secured" class="menu-icon" />
|
||||
<span>{{ $t('settings.apiInfo') }}</span>
|
||||
</div>
|
||||
<div
|
||||
ref="imMenuItemRef"
|
||||
class="menu-item menu-item--submenu"
|
||||
:class="{ 'is-open': imSubmenuOpen }"
|
||||
@mouseenter="showIMSubmenu"
|
||||
@mouseleave="scheduleHideIMSubmenu"
|
||||
>
|
||||
<t-icon name="link" class="menu-icon" />
|
||||
<span class="menu-item-label">{{ $t('imOverview.menuTitle') }}</span>
|
||||
<span
|
||||
v-if="hasActiveIMChannels"
|
||||
class="live-indicator"
|
||||
:title="$t('imOverview.liveIndicator')"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<span class="live-indicator-dot"></span>
|
||||
</span>
|
||||
<t-icon name="chevron-right" class="menu-chevron" />
|
||||
</div>
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item" @click="handleSettings">
|
||||
<t-icon name="setting" class="menu-icon" />
|
||||
@@ -105,6 +124,25 @@
|
||||
</template>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
<!-- IM submenu is teleported to body because the sidebar (.aside_box) has
|
||||
overflow:hidden, which would otherwise clip any absolutely-positioned
|
||||
child that reaches past its bounds. -->
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="imSubmenuOpen"
|
||||
class="im-submenu-floating"
|
||||
:style="imSubmenuStyle"
|
||||
@mouseenter="showIMSubmenu"
|
||||
@mouseleave="scheduleHideIMSubmenu"
|
||||
>
|
||||
<IMChannelsOverviewPanel
|
||||
:active="imSubmenuOpen"
|
||||
@close="closeAll"
|
||||
@channels-changed="onChannelsChanged"
|
||||
/>
|
||||
</div>
|
||||
</Teleport>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -116,6 +154,8 @@ import { useAuthStore } from '@/stores/auth'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { getCurrentUser, logout as logoutApi } from '@/api/auth'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import IMChannelsOverviewPanel from '@/components/IMChannelsOverviewPanel.vue'
|
||||
import { listAllIMChannels, type IMChannelOverview } from '@/api/agent'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -124,7 +164,12 @@ const uiStore = useUIStore()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const menuRef = ref<HTMLElement>()
|
||||
const imMenuItemRef = ref<HTMLElement>()
|
||||
const menuVisible = ref(false)
|
||||
const imSubmenuOpen = ref(false)
|
||||
const imSubmenuStyle = ref<Record<string, string>>({})
|
||||
const hasActiveIMChannels = ref(false)
|
||||
let imSubmenuHideTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
// 用户信息
|
||||
const userInfo = ref({
|
||||
@@ -168,6 +213,81 @@ const handleSettings = () => {
|
||||
router.push('/platform/settings')
|
||||
}
|
||||
|
||||
// Hover-driven submenu controls. A small hide delay tolerates the pointer
|
||||
// slipping off briefly onto the gap between menu item and submenu pane.
|
||||
const showIMSubmenu = () => {
|
||||
if (imSubmenuHideTimer) {
|
||||
clearTimeout(imSubmenuHideTimer)
|
||||
imSubmenuHideTimer = null
|
||||
}
|
||||
// Compute panel position based on the menu item's rect — the panel is
|
||||
// teleported to body so we can't rely on CSS `left: 100%`.
|
||||
positionIMSubmenu()
|
||||
imSubmenuOpen.value = true
|
||||
}
|
||||
|
||||
const scheduleHideIMSubmenu = () => {
|
||||
if (imSubmenuHideTimer) clearTimeout(imSubmenuHideTimer)
|
||||
imSubmenuHideTimer = setTimeout(() => {
|
||||
imSubmenuOpen.value = false
|
||||
imSubmenuHideTimer = null
|
||||
}, 180)
|
||||
}
|
||||
|
||||
const closeAll = () => {
|
||||
imSubmenuOpen.value = false
|
||||
menuVisible.value = false
|
||||
}
|
||||
|
||||
// Silent prefetch so the "live" indicator on the IM menu item reflects reality
|
||||
// as soon as the user sees the avatar area. Errors are swallowed — the
|
||||
// indicator just stays off if the request fails, which is the conservative
|
||||
// default. The panel component emits channels-changed after toggle/refresh so
|
||||
// we stay in sync without re-polling.
|
||||
const refreshIMStatus = async () => {
|
||||
try {
|
||||
const resp = await listAllIMChannels()
|
||||
const data: IMChannelOverview[] = resp?.data || []
|
||||
hasActiveIMChannels.value = data.some((c) => c.enabled)
|
||||
} catch {
|
||||
// Intentionally ignored — indicator just stays off.
|
||||
}
|
||||
}
|
||||
|
||||
const onChannelsChanged = (channels: IMChannelOverview[]) => {
|
||||
hasActiveIMChannels.value = channels.some((c) => c.enabled)
|
||||
}
|
||||
|
||||
// Anchor the floating submenu just to the right of the hovered menu item,
|
||||
// clamped to the viewport so it stays visible near the screen edge.
|
||||
const positionIMSubmenu = () => {
|
||||
const el = imMenuItemRef.value
|
||||
if (!el) return
|
||||
const rect = el.getBoundingClientRect()
|
||||
const PANEL_WIDTH = 300
|
||||
const PANEL_MAX_HEIGHT = 520
|
||||
const GAP = 8
|
||||
const MARGIN = 8
|
||||
|
||||
let left = rect.right + GAP
|
||||
// If the panel would overflow the right edge, flip to the left side.
|
||||
if (left + PANEL_WIDTH + MARGIN > window.innerWidth) {
|
||||
left = Math.max(MARGIN, rect.left - PANEL_WIDTH - GAP)
|
||||
}
|
||||
|
||||
// Align the panel's top with the menu item, then clamp so it doesn't
|
||||
// spill past the bottom of the viewport.
|
||||
let top = rect.top - 4
|
||||
const maxTop = window.innerHeight - Math.min(PANEL_MAX_HEIGHT, window.innerHeight - MARGIN * 2) - MARGIN
|
||||
if (top > maxTop) top = maxTop
|
||||
if (top < MARGIN) top = MARGIN
|
||||
|
||||
imSubmenuStyle.value = {
|
||||
left: `${left}px`,
|
||||
top: `${top}px`,
|
||||
}
|
||||
}
|
||||
|
||||
const CHROME_EXTENSION_URL =
|
||||
'https://chromewebstore.google.com/detail/jpemjbopikggjlmikmclgbmkhhopjdgd?utm_source=item-share-cb'
|
||||
|
||||
@@ -252,14 +372,20 @@ const loadUserInfo = async () => {
|
||||
|
||||
// 点击外部关闭菜单
|
||||
const handleClickOutside = (e: MouseEvent) => {
|
||||
if (menuRef.value && !menuRef.value.contains(e.target as Node)) {
|
||||
menuVisible.value = false
|
||||
}
|
||||
const target = e.target as Node
|
||||
if (menuRef.value && menuRef.value.contains(target)) return
|
||||
// The submenu is teleported to body, so it's not inside menuRef — check it
|
||||
// separately to avoid closing the dropdown when the user clicks the submenu.
|
||||
const floating = document.querySelector('.im-submenu-floating')
|
||||
if (floating && floating.contains(target)) return
|
||||
menuVisible.value = false
|
||||
imSubmenuOpen.value = false
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', handleClickOutside)
|
||||
loadUserInfo()
|
||||
refreshIMStatus()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -411,6 +537,69 @@ onUnmounted(() => {
|
||||
}
|
||||
}
|
||||
|
||||
// 包含右弹子菜单的菜单项
|
||||
&--submenu {
|
||||
position: relative;
|
||||
|
||||
.menu-item-label {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.menu-chevron {
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
flex-shrink: 0;
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
|
||||
&.is-open {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
|
||||
.menu-chevron {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
// "Live" indicator — shown when at least one IM channel is enabled.
|
||||
// A small green dot with a halo that pulses to signal active connections.
|
||||
.live-indicator {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
margin-right: 2px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.live-indicator-dot {
|
||||
position: relative;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--td-success-color, #07c160);
|
||||
|
||||
// Pulsing halo around the dot. Prefers-reduced-motion disables it.
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: -3px;
|
||||
border-radius: 50%;
|
||||
background: var(--td-success-color, #07c160);
|
||||
opacity: 0.45;
|
||||
animation: im-live-pulse 1.6s ease-out infinite;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.live-indicator-dot::after {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
font-size: 16px;
|
||||
color: var(--td-text-color-secondary);
|
||||
@@ -506,5 +695,35 @@ onUnmounted(() => {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
// Live indicator halo animation — a soft expanding ring to signal that at
|
||||
// least one IM channel is actively connected.
|
||||
@keyframes im-live-pulse {
|
||||
0% {
|
||||
transform: scale(0.9);
|
||||
opacity: 0.45;
|
||||
}
|
||||
70% {
|
||||
transform: scale(1.8);
|
||||
opacity: 0;
|
||||
}
|
||||
100% {
|
||||
transform: scale(1.8);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
// Non-scoped: the IM submenu is teleported to <body> so scoped styles
|
||||
// from this component won't reach it. The panel component's own CSS is
|
||||
// scoped and self-contained; this rule only positions the wrapper.
|
||||
.im-submenu-floating {
|
||||
position: fixed;
|
||||
z-index: 1100;
|
||||
// Invisible padding forms a pointer bridge from the menu item to the
|
||||
// panel so hovering across the gap doesn't fire mouseleave-hide.
|
||||
padding-left: 2px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -3979,4 +3979,29 @@ export default {
|
||||
syncResultDeleted: '-{n}',
|
||||
moreActions: 'More',
|
||||
},
|
||||
imOverview: {
|
||||
menuTitle: 'Connected IMs',
|
||||
pageTitle: 'Connected IMs',
|
||||
subtitle: 'All IM channels connected to agents in this tenant — toggle state or jump to the owning agent',
|
||||
totalCount: '{count} total',
|
||||
empty: 'This tenant has no IM bots configured yet',
|
||||
loadFailed: 'Failed to load IM bots',
|
||||
builtinAgent: 'Built-in agent',
|
||||
liveIndicator: 'IM channels are live',
|
||||
detailsTitle: 'IM Bot Details',
|
||||
gotoAgentEditor: 'Open in agent editor',
|
||||
outputMode: 'Output mode',
|
||||
sessionMode: 'Session mode',
|
||||
updatedAt: 'Updated at',
|
||||
channelId: 'Channel ID',
|
||||
columns: {
|
||||
platform: 'Platform',
|
||||
name: 'Name',
|
||||
agent: 'Agent',
|
||||
mode: 'Mode',
|
||||
enabled: 'Enabled',
|
||||
botIdentity: 'Bot identity',
|
||||
createdAt: 'Created at',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4047,4 +4047,30 @@ export default {
|
||||
syncResultUpdated: "~{n}",
|
||||
syncResultDeleted: "-{n}",
|
||||
},
|
||||
imOverview: {
|
||||
menuTitle: "연결된 IM",
|
||||
pageTitle: "연결된 IM",
|
||||
subtitle: "이 테넌트의 에이전트에 연결된 모든 IM 채널 — 활성화/비활성화 전환 또는 해당 에이전트로 이동",
|
||||
totalCount: "총 {count}개",
|
||||
empty: "이 테넌트에 구성된 IM 봇이 없습니다",
|
||||
loadFailed: "IM 봇 목록을 불러오지 못했습니다",
|
||||
builtinAgent: "내장 에이전트",
|
||||
liveIndicator: "활성화된 IM 채널이 실행 중입니다",
|
||||
liveIndicator: "활성화된 IM 채널이 실행 중입니다",
|
||||
detailsTitle: "IM 봇 상세",
|
||||
gotoAgentEditor: "에이전트 편집기에서 열기",
|
||||
outputMode: "출력 모드",
|
||||
sessionMode: "세션 모드",
|
||||
updatedAt: "업데이트 시각",
|
||||
channelId: "채널 ID",
|
||||
columns: {
|
||||
platform: "플랫폼",
|
||||
name: "이름",
|
||||
agent: "에이전트",
|
||||
mode: "모드",
|
||||
enabled: "활성화",
|
||||
botIdentity: "봇 식별자",
|
||||
createdAt: "생성 시각",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -3947,4 +3947,29 @@ export default {
|
||||
syncResultUpdated: '~{n}',
|
||||
syncResultDeleted: '-{n}',
|
||||
},
|
||||
imOverview: {
|
||||
menuTitle: 'Подключённые IM',
|
||||
pageTitle: 'Подключённые IM',
|
||||
subtitle: 'Все IM-каналы агентов этого арендатора — переключение состояния или переход к владеющему агенту',
|
||||
totalCount: 'Всего: {count}',
|
||||
empty: 'В этом арендаторе пока не настроены IM-боты',
|
||||
loadFailed: 'Не удалось загрузить список IM-ботов',
|
||||
builtinAgent: 'Встроенный агент',
|
||||
liveIndicator: 'IM-каналы работают',
|
||||
detailsTitle: 'Детали IM-бота',
|
||||
gotoAgentEditor: 'Открыть в редакторе агента',
|
||||
outputMode: 'Режим вывода',
|
||||
sessionMode: 'Режим сессии',
|
||||
updatedAt: 'Обновлено',
|
||||
channelId: 'ID канала',
|
||||
columns: {
|
||||
platform: 'Платформа',
|
||||
name: 'Имя',
|
||||
agent: 'Агент',
|
||||
mode: 'Режим',
|
||||
enabled: 'Включено',
|
||||
botIdentity: 'Идентификатор бота',
|
||||
createdAt: 'Создано',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3976,4 +3976,29 @@ export default {
|
||||
syncResultDeleted: "-{n}",
|
||||
moreActions: "更多",
|
||||
},
|
||||
imOverview: {
|
||||
menuTitle: "已接入的 IM",
|
||||
pageTitle: "已接入的 IM",
|
||||
subtitle: "当前租户下所有智能体已接入的 IM 渠道,可快速启停或跳转到对应智能体",
|
||||
totalCount: "共 {count} 个",
|
||||
empty: "当前租户还没有配置 IM 机器人",
|
||||
loadFailed: "加载 IM 机器人列表失败",
|
||||
builtinAgent: "内置智能体",
|
||||
liveIndicator: "有已启用的 IM 渠道正在运行",
|
||||
detailsTitle: "IM 机器人详情",
|
||||
gotoAgentEditor: "前往 Agent 编辑",
|
||||
outputMode: "输出模式",
|
||||
sessionMode: "会话模式",
|
||||
updatedAt: "更新时间",
|
||||
channelId: "渠道 ID",
|
||||
columns: {
|
||||
platform: "平台",
|
||||
name: "名称",
|
||||
agent: "所属智能体",
|
||||
mode: "模式",
|
||||
enabled: "启用",
|
||||
botIdentity: "Bot 标识",
|
||||
createdAt: "创建时间",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -715,6 +715,19 @@ const checkAndOpenEditModal = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Also re-run when the query mutates while this view is already mounted —
|
||||
// e.g. the IM overview dialog navigating here via router.push lands on the
|
||||
// same route, so onMounted alone never fires and the editor would only open
|
||||
// after a manual refresh.
|
||||
watch(
|
||||
() => route.query.edit,
|
||||
(v) => {
|
||||
if (v && agents.value.length > 0) {
|
||||
checkAndOpenEditModal()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
// 监听菜单创建智能体事件
|
||||
const handleOpenAgentEditor = (event: CustomEvent) => {
|
||||
if (event.detail?.mode === 'create') {
|
||||
|
||||
@@ -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)
|
||||
|
||||