feat: implement IM channel management in agent editor

- Introduced a new IMChannelPanel component for managing WeCom and Feishu channels.
- Added CRUD operations for IM channels, including create, update, delete, and list functionalities.
- Enhanced the backend with new API endpoints for IM channel management.
- Updated documentation to reflect changes in IM integration and channel management.
- Improved localization support for new IM-related UI elements across multiple languages.
This commit is contained in:
wizardchen
2026-03-16 02:23:22 +08:00
parent e5a397faeb
commit 6159e8e3f7
18 changed files with 1571 additions and 518 deletions
+36
View File
@@ -175,3 +175,39 @@ export interface PlaceholdersResponse {
export function getPlaceholders() {
return get<{ data: PlaceholdersResponse }>('/api/v1/agents/placeholders');
}
// ===== IM渠道 =====
export interface IMChannel {
id: string;
tenant_id?: number;
agent_id: string;
platform: 'wecom' | 'feishu';
name: string;
enabled: boolean;
mode: 'webhook' | 'websocket';
output_mode: 'stream' | 'full';
credentials: Record<string, any>;
created_at?: string;
updated_at?: string;
}
export function listIMChannels(agentId: string) {
return get<{ data: IMChannel[] }>(`/api/v1/agents/${agentId}/im-channels`);
}
export function createIMChannel(agentId: string, data: Partial<IMChannel>) {
return post<{ data: IMChannel }>(`/api/v1/agents/${agentId}/im-channels`, data);
}
export function updateIMChannel(id: string, data: Partial<IMChannel>) {
return put<{ data: IMChannel }>(`/api/v1/im-channels/${id}`, data);
}
export function deleteIMChannel(id: string) {
return del<{ success: boolean }>(`/api/v1/im-channels/${id}`);
}
export function toggleIMChannel(id: string) {
return post<{ data: IMChannel }>(`/api/v1/im-channels/${id}/toggle`);
}
+524
View File
@@ -0,0 +1,524 @@
<template>
<div class="section-content">
<!-- Channel list header -->
<div class="channels-section">
<div class="channels-header">
<span class="channels-title">{{ $t('agentEditor.im.addChannel') }}</span>
<span class="channels-count">{{ channels.length }}</span>
</div>
<div v-if="loading" class="channels-loading">
<t-loading size="small" />
<span>{{ $t('common.loading') }}</span>
</div>
<div v-else-if="channels.length === 0" class="channels-empty">
<t-icon name="chat-message" class="empty-icon" />
<span>{{ $t('agentEditor.im.empty') }}</span>
</div>
<div v-else class="channels-list">
<div v-for="channel in channels" :key="channel.id" class="channel-item">
<div class="channel-info">
<div class="channel-info-top">
<div class="channel-main">
<span class="platform-badge" :class="channel.platform">
{{ channel.platform === 'wecom' ? $t('agentEditor.im.wecom') : $t('agentEditor.im.feishu') }}
</span>
<span class="channel-name">{{ channel.name || $t('agentEditor.im.unnamed') }}</span>
</div>
</div>
<div class="channel-meta">
<span class="meta-tag">
<t-icon name="link" class="meta-icon" />
{{ channel.mode }}
</span>
<span class="meta-tag">
<t-icon name="play-circle" class="meta-icon" />
{{ channel.output_mode === 'stream' ? $t('agentEditor.im.outputStream') : $t('agentEditor.im.outputFull') }}
</span>
</div>
<div v-if="channel.mode === 'webhook'" class="callback-url-row">
<span class="url-label">{{ $t('agentEditor.im.callbackUrl') }}:</span>
<code class="url-value">{{ getCallbackUrl(channel) }}</code>
<t-button theme="default" size="small" variant="text" @click="copyUrl(channel)">
<t-icon name="file-copy" />
</t-button>
</div>
</div>
<div class="channel-actions">
<t-switch
:value="channel.enabled"
size="small"
@change="handleToggle(channel)"
/>
<t-button variant="text" theme="default" size="small" @click="editChannel(channel)">
<t-icon name="edit" />
</t-button>
<t-popconfirm :content="$t('agentEditor.im.deleteConfirm')" @confirm="handleDelete(channel.id)">
<t-button variant="text" theme="danger" size="small">
<t-icon name="delete" />
</t-button>
</t-popconfirm>
</div>
</div>
</div>
</div>
<!-- Add button -->
<t-button theme="default" variant="dashed" block @click="showCreateDialog = true" class="add-btn">
<t-icon name="add" />
{{ $t('agentEditor.im.addChannel') }}
</t-button>
<!-- Create/Edit dialog -->
<t-dialog
v-model:visible="showCreateDialog"
:header="editingChannel ? $t('agentEditor.im.editChannel') : $t('agentEditor.im.addChannel')"
:confirm-btn="$t('common.save')"
:cancel-btn="$t('common.cancel')"
@confirm="handleSave"
@close="resetForm"
width="560px"
>
<div class="dialog-form">
<!-- Platform -->
<div class="form-item">
<label class="form-label">{{ $t('agentEditor.im.platform') }}</label>
<t-radio-group v-model="formData.platform" :disabled="!!editingChannel">
<t-radio-button value="wecom">{{ $t('agentEditor.im.wecom') }}</t-radio-button>
<t-radio-button value="feishu">{{ $t('agentEditor.im.feishu') }}</t-radio-button>
</t-radio-group>
</div>
<!-- Name -->
<div class="form-item">
<label class="form-label">{{ $t('agentEditor.im.channelName') }}</label>
<t-input v-model="formData.name" :placeholder="$t('agentEditor.im.channelNamePlaceholder')" />
</div>
<!-- Mode -->
<div class="form-item">
<label class="form-label">{{ $t('agentEditor.im.mode') }}</label>
<t-radio-group v-model="formData.mode">
<t-radio-button value="websocket">WebSocket</t-radio-button>
<t-radio-button value="webhook">Webhook</t-radio-button>
</t-radio-group>
</div>
<!-- Output mode -->
<div class="form-item">
<label class="form-label">{{ $t('agentEditor.im.outputMode') }}</label>
<t-radio-group v-model="formData.output_mode">
<t-radio-button value="stream">{{ $t('agentEditor.im.outputStream') }}</t-radio-button>
<t-radio-button value="full">{{ $t('agentEditor.im.outputFull') }}</t-radio-button>
</t-radio-group>
</div>
<!-- Credentials divider -->
<div class="form-divider"></div>
<!-- WeCom credentials -->
<template v-if="formData.platform === 'wecom'">
<template v-if="formData.mode === 'websocket'">
<div class="form-item">
<label class="form-label">Bot ID</label>
<t-input v-model="formData.credentials.bot_id" placeholder="Bot ID" />
</div>
<div class="form-item">
<label class="form-label">Bot Secret</label>
<t-input v-model="formData.credentials.bot_secret" type="password" placeholder="Bot Secret" />
</div>
</template>
<template v-else>
<div class="form-item">
<label class="form-label">Corp ID</label>
<t-input v-model="formData.credentials.corp_id" placeholder="Corp ID" />
</div>
<div class="form-item">
<label class="form-label">Agent Secret</label>
<t-input v-model="formData.credentials.agent_secret" type="password" placeholder="Agent Secret" />
</div>
<div class="form-item">
<label class="form-label">Token</label>
<t-input v-model="formData.credentials.token" placeholder="Token" />
</div>
<div class="form-item">
<label class="form-label">EncodingAESKey</label>
<t-input v-model="formData.credentials.encoding_aes_key" placeholder="EncodingAESKey" />
</div>
<div class="form-item">
<label class="form-label">Corp Agent ID</label>
<t-input-number v-model="formData.credentials.corp_agent_id" placeholder="Corp Agent ID" style="width: 100%;" />
</div>
</template>
</template>
<!-- Feishu credentials -->
<template v-if="formData.platform === 'feishu'">
<div class="form-item">
<label class="form-label">App ID</label>
<t-input v-model="formData.credentials.app_id" placeholder="App ID" />
</div>
<div class="form-item">
<label class="form-label">App Secret</label>
<t-input v-model="formData.credentials.app_secret" type="password" placeholder="App Secret" />
</div>
<template v-if="formData.mode === 'webhook'">
<div class="form-item">
<label class="form-label">Verification Token</label>
<t-input v-model="formData.credentials.verification_token" placeholder="Verification Token" />
</div>
<div class="form-item">
<label class="form-label">Encrypt Key</label>
<t-input v-model="formData.credentials.encrypt_key" type="password" placeholder="Encrypt Key" />
</div>
</template>
</template>
</div>
</t-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { MessagePlugin } from 'tdesign-vue-next';
import { listIMChannels, createIMChannel, updateIMChannel, deleteIMChannel, toggleIMChannel } from '@/api/agent';
import type { IMChannel } from '@/api/agent';
const { t } = useI18n();
const props = defineProps<{
agentId: string;
}>();
const channels = ref<IMChannel[]>([]);
const loading = ref(false);
const showCreateDialog = ref(false);
const editingChannel = ref<IMChannel | null>(null);
const defaultCredentials = (): Record<string, any> => ({});
const formData = ref({
platform: 'wecom' as 'wecom' | 'feishu',
name: '',
mode: 'websocket' as 'webhook' | 'websocket',
output_mode: 'stream' as 'stream' | 'full',
credentials: defaultCredentials(),
});
async function loadChannels() {
loading.value = true;
try {
const res = await listIMChannels(props.agentId);
channels.value = res.data || [];
} catch {
channels.value = [];
} finally {
loading.value = false;
}
}
function getCallbackUrl(channel: IMChannel): string {
const base = window.location.origin;
return `${base}/api/v1/im/callback/${channel.id}`;
}
async function copyUrl(channel: IMChannel) {
try {
await navigator.clipboard.writeText(getCallbackUrl(channel));
MessagePlugin.success(t('common.copySuccess'));
} catch {
MessagePlugin.error(t('common.copyFailed'));
}
}
function editChannel(channel: IMChannel) {
editingChannel.value = channel;
formData.value = {
platform: channel.platform,
name: channel.name,
mode: channel.mode,
output_mode: channel.output_mode,
credentials: { ...channel.credentials },
};
showCreateDialog.value = true;
}
function resetForm() {
editingChannel.value = null;
formData.value = {
platform: 'wecom',
name: '',
mode: 'websocket',
output_mode: 'stream',
credentials: defaultCredentials(),
};
}
async function handleSave() {
try {
if (editingChannel.value) {
await updateIMChannel(editingChannel.value.id, {
name: formData.value.name,
mode: formData.value.mode,
output_mode: formData.value.output_mode,
credentials: formData.value.credentials,
});
MessagePlugin.success(t('common.updateSuccess'));
} else {
await createIMChannel(props.agentId, {
platform: formData.value.platform,
name: formData.value.name,
mode: formData.value.mode,
output_mode: formData.value.output_mode,
credentials: formData.value.credentials,
});
MessagePlugin.success(t('common.createSuccess'));
}
showCreateDialog.value = false;
resetForm();
await loadChannels();
} catch (e: any) {
MessagePlugin.error(e?.message || t('common.operationFailed'));
}
}
async function handleToggle(channel: IMChannel) {
try {
await toggleIMChannel(channel.id);
await loadChannels();
} catch (e: any) {
MessagePlugin.error(e?.message || t('common.operationFailed'));
}
}
async function handleDelete(id: string) {
try {
await deleteIMChannel(id);
MessagePlugin.success(t('common.deleteSuccess'));
await loadChannels();
} catch (e: any) {
MessagePlugin.error(e?.message || t('common.operationFailed'));
}
}
onMounted(() => {
loadChannels();
});
</script>
<style scoped lang="less">
.section-content {
display: flex;
flex-direction: column;
gap: 16px;
}
// --- Channel list section (matches AgentShareSettings pattern) ---
.channels-section {
margin-bottom: 8px;
}
.channels-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 16px;
.channels-title {
font-size: 14px;
font-weight: 500;
color: var(--td-text-color-primary);
}
.channels-count {
padding: 2px 8px;
background: var(--td-bg-color-secondarycontainer);
border-radius: 10px;
font-size: 12px;
color: var(--td-text-color-disabled);
}
}
.channels-loading {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 32px;
color: var(--td-text-color-disabled);
font-size: 14px;
}
.channels-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
padding: 40px 20px;
background: var(--td-bg-color-secondarycontainer);
border-radius: 8px;
color: var(--td-text-color-disabled);
.empty-icon {
font-size: 32px;
opacity: 0.5;
}
}
.channels-list {
display: flex;
flex-direction: column;
gap: 10px;
max-height: 400px;
overflow-y: auto;
}
// --- Channel card (matches share-item pattern) ---
.channel-item {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
padding: 14px 16px;
background: var(--td-bg-color-secondarycontainer);
border: 1px solid var(--td-component-stroke);
border-radius: 8px;
transition: background 0.2s ease, border-color 0.2s ease;
&:hover {
border-color: var(--td-brand-color-focus);
}
}
.channel-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 8px;
}
.channel-info-top {
display: flex;
align-items: center;
gap: 12px;
}
.channel-main {
display: flex;
align-items: center;
gap: 8px;
}
.platform-badge {
display: inline-block;
padding: 2px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
line-height: 18px;
&.wecom {
background: rgba(7, 193, 96, 0.08);
color: #07c160;
}
&.feishu {
background: rgba(51, 112, 255, 0.08);
color: #3370ff;
}
}
.channel-name {
font-size: 14px;
font-weight: 500;
color: var(--td-text-color-primary);
}
.channel-meta {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: var(--td-text-color-placeholder);
.meta-tag {
display: inline-flex;
align-items: center;
gap: 3px;
padding: 2px 6px;
background: var(--td-bg-color-secondarycontainer);
border-radius: 4px;
}
.meta-icon {
font-size: 12px;
flex-shrink: 0;
}
}
.callback-url-row {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
padding-top: 4px;
border-top: 1px dashed var(--td-component-stroke);
.url-label {
color: var(--td-text-color-secondary);
white-space: nowrap;
}
.url-value {
background: var(--td-bg-color-container);
padding: 2px 8px;
border-radius: 4px;
font-size: 11px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
min-width: 0;
}
}
.channel-actions {
display: flex;
align-items: center;
gap: 6px;
flex-shrink: 0;
}
// --- Add button ---
.add-btn {
margin-top: 4px;
}
// --- Dialog form (matches share form pattern) ---
.dialog-form {
display: flex;
flex-direction: column;
gap: 16px;
}
.form-item {
.form-label {
display: block;
margin-bottom: 8px;
font-size: 14px;
font-weight: 500;
color: var(--td-text-color-primary);
}
}
.form-divider {
height: 1px;
background: var(--td-component-stroke);
margin: 4px 0;
}
</style>
+19
View File
@@ -3252,6 +3252,25 @@ export default {
dataSchemaDesc: 'Get metadata of tabular files',
requiresKb: '(requires knowledge base configuration)',
},
im: {
title: 'IM Integration',
description: 'Connect agent to instant messaging platforms like WeCom and Feishu',
wecom: 'WeCom',
feishu: 'Feishu',
addChannel: 'Add Channel',
editChannel: 'Edit Channel',
deleteConfirm: 'Are you sure you want to delete this channel? This action cannot be undone.',
channelName: 'Channel Name',
channelNamePlaceholder: 'Enter a name for easy identification',
platform: 'Platform',
mode: 'Connection Mode',
outputMode: 'Output Mode',
outputStream: 'Streaming',
outputFull: 'Full Response',
callbackUrl: 'Callback URL',
empty: 'No IM channels yet. Click the button below to add one.',
unnamed: 'Unnamed Channel',
},
mcp: {
label: 'MCP Services',
desc: 'Select MCP services available to the Agent',
+20 -1
View File
@@ -3052,7 +3052,7 @@ export default {
permissionEditable: "편집 가능",
sharedKBs: "지식베이스",
sharedAgents: "에이전트",
},
}
},
preview: {
tab: '미리보기',
@@ -3282,6 +3282,25 @@ export default {
fallbackResponse: '응답할 수 없을 때 반환할 고정 텍스트',
fallbackPrompt: '지식베이스에서 답변을 찾을 수 없을 때 모델 응답을 유도하는 프롬프트',
},
im: {
title: "IM 통합",
description: "에이전트를 WeCom, Feishu 등 인스턴트 메시징 플랫폼에 연결",
wecom: "WeCom",
feishu: "Feishu",
addChannel: "채널 추가",
editChannel: "채널 편집",
deleteConfirm: "이 채널을 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다.",
channelName: "채널 이름",
channelNamePlaceholder: "식별하기 쉬운 이름을 입력하세요",
platform: "플랫폼",
mode: "연결 모드",
outputMode: "출력 모드",
outputStream: "스트리밍",
outputFull: "전체 응답",
callbackUrl: "콜백 URL",
empty: "IM 채널이 없습니다. 아래 버튼을 클릭하여 추가하세요.",
unnamed: "이름 없는 채널",
},
tools: {
thinking: '사고',
thinkingDesc: '동적이고 반성적인 문제 해결 사고 도구',
+19
View File
@@ -2835,6 +2835,25 @@ export default {
dataSchemaDesc: 'Получение метаинформации табличных файлов',
requiresKb: '(требуется настройка базы знаний)'
},
im: {
title: 'Интеграция IM',
description: 'Подключите агента к платформам мгновенных сообщений, таким как WeCom и Feishu',
wecom: 'WeCom',
feishu: 'Feishu',
addChannel: 'Добавить канал',
editChannel: 'Редактировать канал',
deleteConfirm: 'Вы уверены, что хотите удалить этот канал? Это действие не может быть отменено.',
channelName: 'Имя канала',
channelNamePlaceholder: 'Введите имя для легкой идентификации',
platform: 'Платформа',
mode: 'Режим подключения',
outputMode: 'Режим вывода',
outputStream: 'Стриминг',
outputFull: 'Полное выходное значение',
callbackUrl: 'URL обратного вызова',
empty: 'Нет IM каналов. Нажмите кнопку ниже, чтобы добавить один.',
unnamed: 'Неименованный канал'
},
mcp: {
label: 'MCP-сервисы',
desc: 'Выберите MCP-сервисы, доступные агенту',
+19
View File
@@ -3227,6 +3227,25 @@ export default {
fallbackResponse: "当无法回答时返回的固定文本",
fallbackPrompt: "当无法从知识库找到答案时,引导模型生成回复的提示词",
},
im: {
title: "IM 集成",
description: "将智能体接入即时通讯平台,支持企业微信和飞书",
wecom: "企业微信",
feishu: "飞书",
addChannel: "添加渠道",
editChannel: "编辑渠道",
deleteConfirm: "确定删除该渠道?删除后无法恢复。",
channelName: "渠道名称",
channelNamePlaceholder: "输入渠道名称,方便辨识",
platform: "平台",
mode: "接入模式",
outputMode: "输出模式",
outputStream: "流式输出",
outputFull: "完整输出",
callbackUrl: "回调地址",
empty: "暂无 IM 渠道,点击下方按钮添加",
unnamed: "未命名渠道",
},
tools: {
thinking: "思考",
thinkingDesc: "动态和反思性的问题解决思考工具",
@@ -1115,6 +1115,17 @@
<div v-if="props.mode === 'edit' && props.agent?.id && !props.agent?.is_builtin" v-show="currentSection === 'share'" class="section">
<AgentShareSettings :agent-id="props.agent.id" :agent="props.agent" />
</div>
<!-- IM集成(仅编辑模式) -->
<div v-if="props.mode === 'edit' && props.agent?.id" v-show="currentSection === 'im'" class="section">
<div class="section-header">
<h2>{{ $t('agentEditor.im.title') }}</h2>
<p class="section-description">{{ $t('agentEditor.im.description') }}</p>
</div>
<div class="settings-group">
<IMChannelPanel :agent-id="props.agent.id" />
</div>
</div>
</div>
<!-- 底部操作栏 -->
@@ -1146,6 +1157,7 @@ import AgentAvatar from '@/components/AgentAvatar.vue';
import PromptTemplateSelector from '@/components/PromptTemplateSelector.vue';
import ModelSelector from '@/components/ModelSelector.vue';
import AgentShareSettings from '@/components/AgentShareSettings.vue';
import IMChannelPanel from '@/components/IMChannelPanel.vue';
const uiStore = useUIStore();
const orgStore = useOrganizationStore();
@@ -1378,6 +1390,10 @@ const navItems = computed(() => {
if (props.mode === 'edit' && props.agent?.id && !props.agent?.is_builtin) {
items.push({ key: 'share', icon: 'share', label: t('knowledgeEditor.sidebar.share') });
}
// IM集成(仅编辑模式,创建时Agent还没有ID)
if (props.mode === 'edit' && props.agent?.id) {
items.push({ key: 'im', icon: 'chat-message', label: t('agentEditor.im.title') });
}
return items;
});