Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
feat(integrations): polish embed/IM channel editors and agent rebind
wizardchen635d7c9643f3
diff --git a/frontend/src/api/embed/index.ts b/frontend/src/api/embed/index.tsindex 2a75354a5..8607199a5 100644--- a/frontend/src/api/embed/index.ts+++ b/frontend/src/api/embed/index.ts@@ -61,6 +61,39 @@ export type WidgetPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top/** Prefix of short-lived embed session tokens minted by the backend. */export const EMBED_SESSION_TOKEN_PREFIX = 'ems_'+/** localStorage key prefix for persisted embed chat sessions (per channel). */+export const EMBED_CHAT_SESSION_STORAGE_PREFIX = 'weknora-embed-session:'++export function embedChatSessionStorageKey(channelId: string): string {+ return `${EMBED_CHAT_SESSION_STORAGE_PREFIX}${channelId}`+}++/** Drop a persisted embed chat session so the next load starts fresh. */+export function clearEmbedStoredChatSession(channelId: string): void {+ if (typeof localStorage === 'undefined') return+ try {+ localStorage.removeItem(embedChatSessionStorageKey(channelId))+ } catch {+ // localStorage may be unavailable in private mode.+ }+}++/** Clear a stored chat session when it was created under a different agent binding. */+export function clearEmbedStoredChatSessionIfAgentMismatch(channelId: string, agentId: string): void {+ if (typeof localStorage === 'undefined' || !channelId || !agentId) return+ try {+ const raw = localStorage.getItem(embedChatSessionStorageKey(channelId))+ if (!raw) return+ const parsed = JSON.parse(raw) as { agentId?: string }+ if (parsed?.agentId && parsed.agentId !== agentId) {+ localStorage.removeItem(embedChatSessionStorageKey(channelId))+ }+ } catch {+ // Malformed entry — remove so bootstrap can recover.+ localStorage.removeItem(embedChatSessionStorageKey(channelId))+ }+}+/** Whether a token is already a short-lived session token (secure mode). */export function isEmbedSessionToken(token: string): boolean {return typeof token === 'string' && token.trim().startsWith(EMBED_SESSION_TOKEN_PREFIX)diff --git a/frontend/src/components/AgentEmbedChannelPanel.vue b/frontend/src/components/AgentEmbedChannelPanel.vueindex 5a3f9bff6..8e2e2edcd 100644--- a/frontend/src/components/AgentEmbedChannelPanel.vue+++ b/frontend/src/components/AgentEmbedChannelPanel.vue@@ -24,24 +24,22 @@</div><div class="channel-card__body"><div class="channel-card__header">- <h3 class="channel-card__title">{{ ch.name || $t('embedPublish.unnamed') }}</h3>+ <h3 class="channel-card__title">{{ channelDisplayName(ch) }}</h3><t-tag v-if="!ch.enabled" size="small" variant="light" theme="warning">{{ $t('embedPublish.disabled') }}</t-tag></div>- <p class="channel-card__subtitle">{{ channelSummary(ch) }}</p>+ <span v-if="tenantMode && agentDisplayName(ch)" class="channel-card__agent-name">+ {{ agentDisplayName(ch) }}+ </span></div><div v-if="authStore.hasRole('admin')" class="channel-card__actions" @click.stop>- <t-switch- :value="ch.enabled"- size="small"- @change="(v: boolean) => toggleEnabled(ch, v)"- /><t-dropdowntrigger="click"placement="bottom-right"- :options="channelMenuOptions"- @click="(data) => data.value === 'delete' && confirmRemoveChannel(ch.id)"+ attach="body"+ :options="channelMenuOptions(ch)"+ @click="(data) => handleChannelMenuClick(data, ch)"><t-buttonvariant="text"@@ -62,10 +60,15 @@class="channel-card channel-card--add"@click="openCreate">- <span class="channel-card--add__icon" aria-hidden="true">+ <span class="channel-card__badge" aria-hidden="true"><t-icon name="add" /></span>- <span class="channel-card--add__label">{{ $t('embedPublish.create') }}</span>+ <div class="channel-card__body">+ <div class="channel-card__header">+ <span class="channel-card__title">{{ $t('embedPublish.create') }}</span>+ </div>+ </div>+ <span class="channel-card__actions channel-card__actions--spacer" aria-hidden="true" /></button></div></t-loading>@@ -73,31 +76,62 @@<SettingDrawerv-model:visible="showDrawer"+ class="embed-channel-drawer":title="drawerTitle"- :description="drawerDescription"+ :description="drawerStepDescription"icon="code"storage-key="setting-drawer:embed-channel"+ width="560px":confirm-loading="saving"+ :confirm-text="drawerConfirmText":hide-footer="!isAdmin"- @confirm="saveForm"+ @confirm="handleDrawerConfirm"@cancel="closeDrawer">+ <template v-if="wizardStep > 0" #footer-left>+ <t-button variant="outline" @click="prevWizardStep">+ {{ $t('datasource.back') }}+ </t-button>+ </template>++ <div class="im-steps">+ <button+ v-for="(title, i) in stepTitles"+ :key="i"+ type="button"+ :class="['im-step', { active: wizardStep === i, done: wizardStep > i }]"+ @click="goToWizardStep(i)"+ >+ <span class="im-step-num">+ <t-icon v-if="wizardStep > i" name="check" class="im-step-check" />+ <template v-else>{{ i + 1 }}</template>+ </span>+ <span class="im-step-title">{{ title }}</span>+ </button>+ </div>++ <!-- Step 1: Channel -->+ <div v-if="wizardStep === 0" class="im-step-body"><section class="setting-drawer__section embed-drawer__section"><h4 class="setting-drawer__section-title">{{ $t('embedPublish.sectionChannel') }}</h4>- <div v-if="tenantMode && !editingId" class="form-item">- <label class="form-label">{{ $t('integrations.selectAgent') }}</label>- <t-select- v-model="createAgentId"- :options="agentOptions"- filterable- :placeholder="$t('integrations.selectAgentPlaceholder')"- />+ <div v-if="tenantMode" class="form-item">+ <label class="form-label required">{{ $t('integrations.boundAgent') }}</label>+ <div class="agent-field-row">+ <t-select+ v-model="createAgentId"+ :options="agentOptions"+ filterable+ :placeholder="$t('integrations.selectAgentPlaceholder')"+ />+ </div></div>- <div v-if="editingId && isAdmin" class="form-item">- <div class="enable-row">- <span class="form-label form-label--inline">{{ $t('embedPublish.enabled') }}</span>+ <div v-if="editingId && isAdmin" class="setting-row setting-row--last">+ <div class="setting-info">+ <label>{{ $t('embedPublish.enabled') }}</label>+ </div>+ <div class="setting-control"><t-switch v-model="editingEnabled" size="small" /></div></div>@@ -108,22 +142,17 @@v-model="form.name":disabled="!isAdmin":placeholder="$t('embedPublish.namePlaceholder')"+ @focus="channelNameTouched = true"/>- <p class="form-desc">{{ $t('embedPublish.nameDesc') }}</p>- </div>-- <div class="form-item">- <label class="form-label">{{ $t('embedPublish.welcomeMessage') }}</label>- <t-textarea- v-model="form.welcome_message"- :disabled="!isAdmin"- :placeholder="$t('embedPublish.welcomePlaceholder')"- :autosize="{ minRows: 2, maxRows: 4 }"- />+ <p v-if="!editingId" class="form-desc">{{ $t('embedPublish.nameDefaultHint') }}</p>+ <p v-else class="form-desc">{{ $t('embedPublish.nameDesc') }}</p></div></section>+ </div>+ <!-- Step 2: Security -->+ <div v-else-if="wizardStep === 1" class="im-step-body"><section class="setting-drawer__section embed-drawer__section"><h4 class="setting-drawer__section-title">{{ $t('embedPublish.sectionSecurity') }}</h4>@@ -141,38 +170,50 @@<p v-else class="form-desc">{{ $t('embedPublish.originsHint') }}</p></div>- <div class="form-grid form-grid--2">- <div class="form-item">- <label class="form-label">{{ $t('embedPublish.rateLimitLabel') }}</label>- <t-input-number- v-model="form.rate_limit_per_minute"- :disabled="!isAdmin"- :min="1"- :max="600"- theme="column"- class="form-number"- />- <p class="form-desc">{{ $t('embedPublish.rateLimitDesc') }}</p>- </div>+ <div class="form-item">+ <label class="form-label">{{ $t('embedPublish.rateLimitLabel') }}</label>+ <t-input-number+ v-model="form.rate_limit_per_minute"+ :disabled="!isAdmin"+ :min="1"+ :max="600"+ theme="column"+ class="form-number"+ />+ <p class="form-desc">{{ $t('embedPublish.rateLimitDesc') }}</p>+ </div>- <div class="form-item">- <label class="form-label">{{ $t('embedPublish.rateLimitDayLabel') }}</label>- <t-input-number- v-model="form.rate_limit_per_day"- :disabled="!isAdmin"- :min="1"- :max="1000000"- theme="column"- class="form-number"- />- <p class="form-desc">{{ $t('embedPublish.rateLimitDayDesc') }}</p>- </div>+ <div class="form-item">+ <label class="form-label">{{ $t('embedPublish.rateLimitDayLabel') }}</label>+ <t-input-number+ v-model="form.rate_limit_per_day"+ :disabled="!isAdmin"+ :min="1"+ :max="1000000"+ theme="column"+ class="form-number"+ />+ <p class="form-desc">{{ $t('embedPublish.rateLimitDayDesc') }}</p></div></section>+ </div>+ <!-- Step 3: Capabilities -->+ <div v-else-if="wizardStep === 2" class="im-step-body"><section class="setting-drawer__section embed-drawer__section"><h4 class="setting-drawer__section-title">{{ $t('embedPublish.sectionCapabilities') }}</h4>+ <div class="form-item">+ <label class="form-label">{{ $t('embedPublish.welcomeMessage') }}</label>+ <t-textarea+ v-model="form.welcome_message"+ :disabled="!isAdmin"+ :placeholder="$t('embedPublish.welcomePlaceholder')"+ :autosize="{ minRows: 2, maxRows: 4 }"+ />+ <p class="form-desc">{{ $t('embedPublish.welcomeMessageDesc') }}</p>+ </div>+<div class="settings-group"><div class="setting-row"><div class="setting-info">@@ -223,7 +264,10 @@</div></div></section>+ </div>+ <!-- Step 4: Appearance -->+ <div v-else-if="wizardStep === 3" class="im-step-body"><section class="setting-drawer__section embed-drawer__section"><h4 class="setting-drawer__section-title">{{ $t('embedPublish.sectionAppearance') }}</h4>@@ -237,47 +281,43 @@<p class="form-desc">{{ $t('embedPublish.pageTitleDesc') }}</p></div>- <div class="form-grid form-grid--2">- <div class="form-item">- <label class="form-label">{{ $t('embedPublish.headerTitleMode') }}</label>- <t-select- v-model="form.header_title_mode"- :disabled="!isAdmin"- :options="headerTitleModeOptions"- />- <p class="form-desc">{{ $t('embedPublish.headerTitleModeDesc') }}</p>- </div>+ <div class="form-item">+ <label class="form-label">{{ $t('embedPublish.headerTitleMode') }}</label>+ <t-select+ v-model="form.header_title_mode"+ :disabled="!isAdmin"+ :options="headerTitleModeOptions"+ />+ <p class="form-desc">{{ $t('embedPublish.headerTitleModeDesc') }}</p>+ </div>- <div class="form-item">- <label class="form-label">{{ $t('embedPublish.widgetPosition') }}</label>- <t-select- v-model="form.widget_position"- :disabled="!isAdmin"- :options="positionOptions"- />- </div>+ <div class="form-item">+ <label class="form-label">{{ $t('embedPublish.widgetPosition') }}</label>+ <t-select+ v-model="form.widget_position"+ :disabled="!isAdmin"+ :options="positionOptions"+ /></div>- <div class="form-grid form-grid--2">- <div class="form-item">- <label class="form-label">{{ $t('embedPublish.defaultLocale') }}</label>- <t-select- v-model="form.default_locale"- :disabled="!isAdmin"- :options="defaultLocaleOptions"- />- <p class="form-desc">{{ $t('embedPublish.defaultLocaleDesc') }}</p>- </div>+ <div class="form-item">+ <label class="form-label">{{ $t('embedPublish.defaultLocale') }}</label>+ <t-select+ v-model="form.default_locale"+ :disabled="!isAdmin"+ :options="defaultLocaleOptions"+ />+ <p class="form-desc">{{ $t('embedPublish.defaultLocaleDesc') }}</p>+ </div>- <div class="form-item">- <label class="form-label">{{ $t('embedPublish.primaryColor') }}</label>- <t-color-picker- v-model="form.primary_color"- :disabled="!isAdmin"- format="HEX"- :color-modes="['monochrome']"- />- </div>+ <div class="form-item">+ <label class="form-label">{{ $t('embedPublish.primaryColor') }}</label>+ <t-color-picker+ v-model="form.primary_color"+ :disabled="!isAdmin"+ format="HEX"+ :color-modes="['monochrome']"+ /></div><div class="form-item">@@ -296,7 +336,10 @@</div></div></section>+ </div>+ <!-- Step 5: Webhook -->+ <div v-else-if="wizardStep === 4" class="im-step-body"><section class="setting-drawer__section embed-drawer__section"><h4 class="setting-drawer__section-title">{{ $t('embedPublish.sectionWebhook') }}</h4>@@ -306,6 +349,7 @@<t-inputv-model="form.webhook_url":disabled="!isAdmin"+ autocomplete="off":placeholder="$t('embedPublish.webhookUrlPlaceholder')"/><p class="form-desc">{{ $t('embedPublish.webhookUrlDesc') }}</p>@@ -317,6 +361,7 @@v-model="form.webhook_secret":disabled="!isAdmin"type="password"+ autocomplete="new-password":placeholder="webhookSecretPlaceholder"/><p class="form-desc">{{ $t('embedPublish.webhookSecretDesc') }}</p>@@ -328,73 +373,17 @@<t-icon name="info-circle" class="deploy-hint__icon" /><p>{{ $t('embedPublish.deployAfterSaveHint') }}</p></div>+ </div>- <section v-if="editingId" class="setting-drawer__section embed-drawer__section">+ <!-- Step 6: Deploy (edit only) -->+ <div v-else-if="editingId" class="im-step-body">+ <section class="setting-drawer__section embed-drawer__section"><h4 class="setting-drawer__section-title">{{ $t('embedPublish.sectionDeploy') }}</h4><p class="form-desc form-desc--block">{{ $t('embedPublish.deployIntro') }}</p>- <div class="deploy-step">- <span class="deploy-step__index" aria-hidden="true">1</span>- <div class="deploy-step__content">- <h5 class="deploy-step__title">{{ $t('embedPublish.channelKey') }}</h5>- <p class="deploy-step__desc">{{ $t('embedPublish.channelKeyDesc') }}</p>-- <div v-if="drawerChannel" class="channel-key-control">- <t-input- :model-value="displayChannelKey(editingId)"- readonly- type="text"- class="mono-text-input channel-key-input"- :placeholder="tokenFor(drawerChannel) ? '' : $t('embedPublish.channelKeyUnavailable')"- />- <template v-if="tokenFor(drawerChannel)">- <t-button- size="small"- variant="text"- :title="revealedTokens[editingId] ? $t('embedPublish.hideKey') : $t('embedPublish.revealKey')"- @click="toggleReveal(editingId)"- >- <t-icon :name="revealedTokens[editingId] ? 'browse-off' : 'browse'" />- </t-button>- <t-button- size="small"- variant="text"- :title="$t('embedPublish.copyChannelKeyTitle')"- @click="copyToken(drawerChannel)"- >- <t-icon name="file-copy" />- </t-button>- </template>- <t-popconfirm- v-if="isAdmin"- theme="warning"- :content="$t('embedPublish.resetKeyConfirmBody')"- :confirm-btn="{ content: $t('embedPublish.resetKeyConfirmOk'), theme: 'danger' }"- :cancel-btn="{ content: $t('common.cancel') }"- @confirm="performRotate(editingId)"- >- <t-button- size="small"- variant="text"- theme="danger"- :loading="rotating"- :title="$t('embedPublish.resetKeyTitle')"- >- <t-icon name="refresh" />- </t-button>- </t-popconfirm>- </div>- <p v-if="drawerChannel && !tokenFor(drawerChannel)" class="form-desc">- {{ $t('embedPublish.channelKeyHint') }}- </p>- </div>- </div>-- <div class="deploy-step">- <span class="deploy-step__index" aria-hidden="true">2</span>- <div class="deploy-step__content">- <h5 class="deploy-step__title">{{ $t('embedPublish.deployStepEmbed') }}</h5>- <p class="deploy-step__desc">{{ $t('embedPublish.deployStepEmbedDesc') }}</p>+ <div class="deploy-block">+ <h5 class="deploy-block__title">{{ $t('embedPublish.deployStepEmbed') }}</h5>+ <p class="deploy-block__desc">{{ $t('embedPublish.deployStepEmbedDesc') }}</p><t-tabs v-model="drawerSnippetTab" class="snippet-tabs"><t-tab-panel value="iframe" :label="$t('embedPublish.tabIframe')" />@@ -458,10 +447,64 @@<pre class="code-panel__pre">{{ secureServerExample }}</pre></div></template>+ </div>++ <div class="deploy-block">+ <h5 class="deploy-block__title">{{ $t('embedPublish.channelKey') }}</h5>+ <p class="deploy-block__desc">{{ $t('embedPublish.channelKeyDesc') }}</p>++ <div v-if="drawerChannel" class="channel-key-control">+ <t-input+ :model-value="displayChannelKey(editingId)"+ readonly+ type="text"+ class="mono-text-input channel-key-input"+ :placeholder="tokenFor(drawerChannel) ? '' : $t('embedPublish.channelKeyUnavailable')"+ />+ <template v-if="tokenFor(drawerChannel)">+ <t-button+ size="small"+ variant="text"+ :title="revealedTokens[editingId] ? $t('embedPublish.hideKey') : $t('embedPublish.revealKey')"+ @click="toggleReveal(editingId)"+ >+ <t-icon :name="revealedTokens[editingId] ? 'browse-off' : 'browse'" />+ </t-button>+ <t-button+ size="small"+ variant="text"+ :title="$t('embedPublish.copyChannelKeyTitle')"+ @click="copyToken(drawerChannel)"+ >+ <t-icon name="file-copy" />+ </t-button>+ </template>+ <t-popconfirm+ v-if="isAdmin"+ theme="warning"+ :content="$t('embedPublish.resetKeyConfirmBody')"+ :confirm-btn="{ content: $t('embedPublish.resetKeyConfirmOk'), theme: 'danger' }"+ :cancel-btn="{ content: $t('common.cancel') }"+ @confirm="performRotate(editingId)"+ >+ <t-button+ size="small"+ variant="text"+ theme="danger"+ :loading="rotating"+ :title="$t('embedPublish.resetKeyTitle')"+ >+ <t-icon name="refresh" />+ </t-button>+ </t-popconfirm></div>+ <p v-if="drawerChannel && !tokenFor(drawerChannel)" class="form-desc">+ {{ $t('embedPublish.channelKeyHint') }}+ </p></div></section>+ </div></SettingDrawer><EmbedChannelPreview@@ -499,6 +542,8 @@ import {buildSecureServerNodeExample,buildSecureServerGoExample,getEmbedChannelStats,+ clearEmbedStoredChatSession,+ clearEmbedStoredChatSessionIfAgentMismatch,type EmbedChannel,type EmbedLocaleTag,type HeaderTitleMode,@@ -541,6 +586,7 @@ const rotating = ref(false)const showDrawer = ref(false)const editingId = ref('')const editingEnabled = ref(true)+const wizardStep = ref(0)const originsText = ref('')const originsError = ref('')const drawerSnippetTab = ref<'iframe' | 'widget' | 'secure'>('iframe')@@ -548,6 +594,7 @@ const secureServerLangTab = ref<'node' | 'go'>('node')const sessionStats = ref<Record<string, number>>({})const agents = ref<CustomAgent[]>([])const createAgentId = ref('')+const channelNameTouched = ref(false)const agentOptions = computed(() =>agents.value.map((agent) => ({ label: agent.name, value: agent.id })),@@ -632,52 +679,141 @@ const defaultLocaleOptions = computed(() => ([{ label: 'Русский', value: 'ru-RU' },]))-const channelMenuOptions = computed(() => ([- { content: t('common.delete'), value: 'delete', theme: 'error' },-]))+const channelMenuOptions = (ch: EmbedChannel) => {+ const items: Array<{ content: string; value: string; theme?: 'error' }> = []+ if (isAdmin.value) {+ items.push({ content: t('embedPublish.preview'), value: 'preview' })+ }+ items.push({+ content: ch.enabled ? t('common.off') : t('common.on'),+ value: 'toggle',+ })+ if (isAdmin.value) {+ items.push({ content: t('common.delete'), value: 'delete', theme: 'error' })+ }+ return items+}-const drawerChannel = computed(() =>- editingId.value ? channels.value.find((ch) => ch.id === editingId.value) : null)+function handleChannelMenuClick(data: { value?: string }, ch: EmbedChannel) {+ if (data.value === 'preview') {+ void openPreviewForChannel(ch)+ return+ }+ if (data.value === 'toggle') {+ void toggleEnabled(ch, !ch.enabled)+ return+ }+ if (data.value === 'delete') {+ confirmRemoveChannel(ch.id)+ }+}const drawerTitle = computed(() => {if (!editingId.value) return t('embedPublish.createTitle')- return form.value.name?.trim() || t('embedPublish.unnamed')+ const ch = drawerChannel.value+ const agentId = props.tenantMode+ ? (createAgentId.value || ch?.agent_id || '')+ : (ch?.agent_id || props.agentId || '')+ return channelDisplayName({+ id: editingId.value,+ name: form.value.name,+ agent_id: agentId,+ } as EmbedChannel)})-const drawerDescription = computed(() => {- if (!editingId.value) return ''- const ch = drawerChannel.value- if (!ch) return ''- const parts: string[] = []- if (!ch.enabled) parts.push(t('embedPublish.disabled'))- const limit = ch.rate_limit_per_minute || 30- parts.push(`${t('embedPublish.rateLimit')} ${limit}${t('embedPublish.rateLimitUnit')}`)- const count = sessionStats.value[ch.id]- if (typeof count === 'number') {- parts.push(t('embedPublish.sessionCountLabel', { n: count }))+function defaultEmbedChannelName(agentId = props.tenantMode ? createAgentId.value : props.agentId): string {+ const agent = agentId ? agents.value.find((item) => item.id === agentId) : undefined+ if (agent?.name?.trim()) {+ return t('embedPublish.defaultChannelNameWithAgent', { agent: agent.name.trim() })}- return parts.join(' · ')-})+ return t('embedPublish.defaultChannelName')+}-const previewPosition = computed((): WidgetPosition =>- (previewChannel.value?.widget_position as WidgetPosition) || 'bottom-right')+function resolvedEmbedChannelName(): string {+ return form.value.name.trim() || defaultEmbedChannelName()+}-const channelSummary = (ch: EmbedChannel) => {- const parts = [- `${t('embedPublish.rateLimit')} ${ch.rate_limit_per_minute || 30}${t('embedPublish.rateLimitUnit')}`,+function channelDisplayName(ch: EmbedChannel): string {+ if (ch.name?.trim()) return ch.name.trim()+ return defaultEmbedChannelName(ch.agent_id)+}++function applyDefaultChannelNameIfNeeded() {+ if (!editingId.value && !channelNameTouched.value) {+ form.value.name = defaultEmbedChannelName()+ }+}++const stepTitles = computed(() => {+ const steps = [+ t('embedPublish.stepChannel'),+ t('embedPublish.stepSecurity'),+ t('embedPublish.stepCapabilities'),+ t('embedPublish.stepAppearance'),+ t('embedPublish.stepWebhook'),]- if (props.tenantMode) {- const agentName = agents.value.find((agent) => agent.id === ch.agent_id)?.name- if (agentName) parts.unshift(agentName)+ if (editingId.value) steps.push(t('embedPublish.stepDeploy'))+ return steps+})++const drawerStepDescription = computed(() => stepTitles.value[wizardStep.value] ?? '')++const drawerConfirmText = computed(() =>+ wizardStep.value < stepTitles.value.length - 1 ? t('common.next') : t('common.save'),+)++function validateWizardStep(step: number): boolean {+ if (step === 0 && props.tenantMode && !createAgentId.value) {+ MessagePlugin.warning(t('integrations.selectAgentHint'))+ return false}- if (ch.allowed_origins?.length) {- parts.push(t('embedPublish.originsCount', { n: ch.allowed_origins.length }))+ if (step === 1) {+ const originsValidation = validateAllowedOrigins(parseOrigins())+ if (!originsValidation.ok) {+ originsError.value = originsValidationMessage(originsValidation.error)+ MessagePlugin.warning(originsError.value)+ return false+ }+ originsError.value = ''}- const count = sessionStats.value[ch.id]- if (typeof count === 'number') {- parts.push(t('embedPublish.sessionCountLabel', { n: count }))+ return true+}++function prevWizardStep() {+ if (wizardStep.value > 0) wizardStep.value -= 1+}++function goToWizardStep(step: number) {+ if (step < 0 || step >= stepTitles.value.length) return+ wizardStep.value = step+}++function goToDeployStep() {+ if (!editingId.value) return+ wizardStep.value = stepTitles.value.length - 1+}++async function handleDrawerConfirm() {+ if (wizardStep.value < stepTitles.value.length - 1) {+ if (!validateWizardStep(wizardStep.value)) return+ wizardStep.value += 1+ return}- return parts.join(' · ')+ await saveForm()+}++const drawerChannel = computed(() =>+ editingId.value ? channels.value.find((ch) => ch.id === editingId.value) : null)++const previewPosition = computed((): WidgetPosition =>+ (previewChannel.value?.widget_position as WidgetPosition) || 'bottom-right')++function agentDisplayName(ch: EmbedChannel): string {+ return agentForChannel(ch)?.name || ''+}++function agentForChannel(ch: EmbedChannel): CustomAgent | undefined {+ return agents.value.find((agent) => agent.id === ch.agent_id)}const loadStoredTokens = (): Record<string, string> => {@@ -730,6 +866,24 @@ watch(() => [props.tenantMode, props.agentId], () => {if (props.tenantMode || props.agentId) load()}, { immediate: true })+watch(stepTitles, (titles) => {+ if (wizardStep.value >= titles.length) {+ wizardStep.value = Math.max(0, titles.length - 1)+ }+})++watch([createAgentId, () => agents.value.length], () => {+ applyDefaultChannelNameIfNeeded()+})++watch(createAgentId, (agentId, prev) => {+ if (!editingId.value || !agentId || agentId === prev || !previewVisible.value) return+ const ch = drawerChannel.value+ if (!ch) return+ clearEmbedStoredChatSessionIfAgentMismatch(ch.id, agentId)+ previewNonce.value += 1+})+const tokenFor = (ch: EmbedChannel) => tokenByChannel.value[ch.id] || ch.publish_tokenconst displayChannelKey = (channelId: string) => {@@ -815,6 +969,7 @@ const snippetScenarioHint = computed(() => {const fillFormFromChannel = (ch: EmbedChannel) => {editingId.value = ch.ideditingEnabled.value = ch.enabled+ createAgentId.value = ch.agent_idform.value = {name: ch.name,welcome_message: ch.welcome_message,@@ -838,10 +993,13 @@ const fillFormFromChannel = (ch: EmbedChannel) => {}const openCreate = () => {+ wizardStep.value = 0+ channelNameTouched.value = falseeditingId.value = ''editingEnabled.value = truecreateAgentId.value = props.tenantMode ? (props.initialAgentId || '') : ''form.value = defaultForm()+ applyDefaultChannelNameIfNeeded()originsText.value = ''originsError.value = ''drawerSnippetTab.value = 'iframe'@@ -850,12 +1008,15 @@ const openCreate = () => {}const openDrawer = (ch: EmbedChannel) => {+ channelNameTouched.value = truefillFormFromChannel(ch)+ goToDeployStep()showDrawer.value = true}const closeDrawer = () => {showDrawer.value = false+ wizardStep.value = 0}const parseOrigins = () => parseAllowedOrigins(originsText.value)@@ -882,6 +1043,10 @@ const mapOriginsApiError = (message: string): string | null => {const saveForm = async () => {if (!isAdmin.value) return+ if (props.tenantMode && !createAgentId.value) {+ MessagePlugin.warning(t('integrations.selectAgentHint'))+ return+ }const originsValidation = validateAllowedOrigins(parseOrigins())if (!originsValidation.ok) {originsError.value = originsValidationMessage(originsValidation.error)@@ -892,7 +1057,7 @@ const saveForm = async () => {saving.value = truetry {const payload = {- name: form.value.name,+ name: resolvedEmbedChannelName(),welcome_message: form.value.welcome_message,allowed_origins: originsValidation.origins,rate_limit_per_minute: form.value.rate_limit_per_minute,@@ -908,13 +1073,25 @@ const saveForm = async () => {webhook_url: form.value.webhook_url || '',webhook_secret: form.value.webhook_secret || undefined,enabled: editingId.value ? editingEnabled.value : true,+ ...(props.tenantMode ? { agent_id: createAgentId.value } : {}),}if (editingId.value) {+ const previousAgentId = drawerChannel.value?.agent_idconst res = await updateEmbedChannel(editingId.value, payload)MessagePlugin.success(t('embedPublish.updated'))+ const saved = res?.dataawait load()- const updated = channels.value.find((ch) => ch.id === editingId.value) ?? res?.data- if (updated) fillFormFromChannel(updated)+ const updated = saved ?? channels.value.find((ch) => ch.id === editingId.value)+ if (updated) {+ fillFormFromChannel(updated)+ if (previousAgentId && updated.agent_id !== previousAgentId) {+ clearEmbedStoredChatSession(updated.id)+ if (previewVisible.value) {+ previewChannel.value = updated+ previewNonce.value += 1+ }+ }+ }} else {const targetAgentId = props.tenantMode ? createAgentId.value : props.agentIdif (!targetAgentId) {@@ -931,8 +1108,11 @@ const saveForm = async () => {}await load()if (res?.data?.id) {- const created = channels.value.find((ch) => ch.id === res.data.id)- if (created) fillFormFromChannel(created)+ const created = channels.value.find((ch) => ch.id === res.data.id) ?? res.data+ if (created) {+ fillFormFromChannel(created)+ wizardStep.value = stepTitles.value.length - 1+ }}}} catch (err: any) {@@ -952,8 +1132,24 @@ const saveForm = async () => {const openPreviewFromDrawer = async () => {const ch = drawerChannel.valueif (!ch) return+ const mode = drawerSnippetTab.value === 'secure' || drawerSnippetTab.value === 'widget'+ ? 'widget'+ : 'iframe'+ await openPreviewForChannel(ch, { useDraft: true, mode })+}++async function openPreviewForChannel(+ ch: EmbedChannel,+ opts?: { useDraft?: boolean; mode?: 'iframe' | 'widget' },+) {previewLoading.value = truetry {+ const agentId = props.tenantMode+ ? ((opts?.useDraft ? createAgentId.value : '') || ch.agent_id)+ : ch.agent_id+ if (agentId) {+ clearEmbedStoredChatSessionIfAgentMismatch(ch.id, agentId)+ }let token = tokenFor(ch)if (!token) {const res = await issueEmbedPreviewSession(ch.id)@@ -963,12 +1159,17 @@ const openPreviewFromDrawer = async () => {return}}- previewMode.value = drawerSnippetTab.value === 'iframe' ? 'iframe' : 'widget'- previewChannel.value = ch+ previewMode.value = opts?.mode ?? 'iframe'+ previewChannel.value = {+ ...ch,+ agent_id: agentId || ch.agent_id,+ primary_color: opts?.useDraft ? form.value.primary_color : ch.primary_color,+ widget_position: (opts?.useDraft ? form.value.widget_position : ch.widget_position) as WidgetPosition,+ default_locale: opts?.useDraft ? (form.value.default_locale || ch.default_locale) : ch.default_locale,+ }previewToken.value = token- previewLocale.value = form.value.default_locale || ch.default_locale || ''+ previewLocale.value = (opts?.useDraft ? form.value.default_locale : '') || ch.default_locale || ''previewNonce.value += 1- // Avoid TDesign textarea autosize recalculating on a blurred/hidden element.if (document.activeElement instanceof HTMLElement) {document.activeElement.blur()}@@ -1058,190 +1259,93 @@ const toggleEnabled = async (ch: EmbedChannel, enabled: boolean) => {</script><style scoped lang="less">+@import './css/channel-panel-list.less';+.embed-panel {display: flex;flex-direction: column;}-.channels-header {+.im-steps {display: flex;- align-items: center;gap: 8px;- margin-bottom: 12px;+ margin-bottom: 16px;+ border-bottom: 1px solid var(--td-component-stroke);+ padding-bottom: 12px;+}- .channels-title {- font-size: 14px;- font-weight: 500;- color: var(--td-text-color-primary);- }+.im-step {+ display: flex;+ align-items: center;+ gap: 6px;+ flex: 1;+ min-width: 0;+ font-size: 12px;+ color: var(--td-text-color-placeholder);+ padding: 0;+ border: none;+ background: transparent;+ font-family: inherit;+ text-align: left;+ cursor: pointer;- .channels-count {- padding: 2px 8px;- background: var(--td-bg-color-secondarycontainer);- border-radius: 10px;- font-size: 12px;- color: var(--td-text-color-disabled);+ &:hover {+ color: var(--td-text-color-secondary);}}-.channels-loading-wrap {- min-height: 80px;+.im-step-title {+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;}-.channels-empty {- padding: 32px 0;+.im-step.active {+ color: var(--td-brand-color);+ font-weight: 500;}-.channel-grid {- display: grid;- grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));- gap: 12px;+.im-step.done {+ color: var(--td-text-color-secondary);+ font-weight: 500;}-.channel-card {- position: relative;+.im-step-num {+ flex-shrink: 0;+ width: 20px;+ height: 20px;+ border-radius: 50%;display: flex;- align-items: flex-start;- gap: 12px;- padding: 14px 16px;+ align-items: center;+ justify-content: center;+ font-size: 11px;+ font-weight: 600;border: 1px solid var(--td-component-stroke);- border-radius: 10px;- background: var(--td-bg-color-container);- text-align: left;- font: inherit;- color: inherit;- transition: border-color 0.18s ease, box-shadow 0.18s ease;-- &--clickable {- cursor: pointer;- width: 100%;-- &:hover,- &:focus-visible {- border-color: var(--td-brand-color-3, var(--td-brand-color));- box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);- outline: none;- }-- &:focus-visible {- outline: 2px solid var(--td-brand-color);- outline-offset: 2px;- }- }-- &--add {- flex-direction: column;- align-items: center;- justify-content: center;- gap: 8px;- min-height: 68px;- border-style: dashed;- background: transparent;- color: var(--td-text-color-placeholder);- cursor: pointer;- width: 100%;-- &:hover,- &:focus-visible {- color: var(--td-brand-color);- border-color: var(--td-brand-color);- background: color-mix(in srgb, var(--td-brand-color) 6%, transparent);- box-shadow: none;- }-- &__icon {- display: flex;- align-items: center;- justify-content: center;- width: 32px;- height: 32px;- border-radius: 8px;- background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);- color: var(--td-brand-color);- font-size: 18px;- }-- &__label {- font-size: 13px;- font-weight: 500;- line-height: 1.4;- }- }-- &__badge {- flex-shrink: 0;- width: 36px;- height: 36px;- border-radius: 9px;- display: flex;- align-items: center;- justify-content: center;- background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);- color: var(--td-brand-color);- }-- &__body {- flex: 1;- min-width: 0;- }-- &__header {- display: flex;- align-items: center;- gap: 6px;- min-width: 0;- }-- &__title {- flex: 1;- min-width: 0;- margin: 0;- font-size: 14px;- font-weight: 600;- line-height: 1.4;- color: var(--td-text-color-primary);- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;- }-- &__subtitle {- margin: 2px 0 0;- font-size: 12px;- line-height: 1.5;- color: var(--td-text-color-secondary);- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;- }+ color: var(--td-text-color-placeholder);+ background: transparent;+}- &__actions {- flex-shrink: 0;- display: flex;- align-items: center;- gap: 2px;- padding-top: 2px;- }+.im-step.active .im-step-num {+ background: var(--td-brand-color);+ color: #fff;+ border-color: var(--td-brand-color);+}- &__more {- flex-shrink: 0;- padding: 2px;- opacity: 0;- color: var(--td-text-color-placeholder);- transition: opacity 0.15s ease;+.im-step.done .im-step-num {+ background: var(--td-bg-color-secondarycontainer);+ color: var(--td-brand-color);+ border-color: var(--td-component-stroke);+}- &:hover,- &:focus-visible {- background: var(--td-bg-color-secondarycontainer);- color: var(--td-text-color-primary);- }- }+.im-step-check {+ font-size: 12px;+}- &:hover .channel-card__more,- &:focus-within .channel-card__more,- &__actions:focus-within .channel-card__more {- opacity: 1;- }+.im-step-body {+ display: flex;+ flex-direction: column;+ gap: 0;}/* ---------- Drawer form (matches ModelEditorDialog rhythm) ---------- */@@ -1287,24 +1391,9 @@ const toggleEnabled = async (ch: EmbedChannel, enabled: boolean) => {}}-.form-grid {- display: grid;- gap: 10px 16px;- align-items: start;-- &--2 {- grid-template-columns: repeat(2, minmax(0, 1fr));- }-- @media (max-width: 520px) {- &--2 {- grid-template-columns: 1fr;- }- }-}-.form-number {width: 100%;+ max-width: 200px;}.enable-row {@@ -1441,36 +1530,19 @@ const toggleEnabled = async (ch: EmbedChannel, enabled: boolean) => {}}-.deploy-step {- display: flex;- gap: 12px;- padding: 14px 0;+.deploy-block {+ padding: 16px 0;border-bottom: 1px solid var(--td-component-stroke);+ &:first-of-type {+ padding-top: 4px;+ }+&:last-child {border-bottom: none;padding-bottom: 0;}- &__index {- flex-shrink: 0;- display: inline-flex;- align-items: center;- justify-content: center;- width: 24px;- height: 24px;- border-radius: 50%;- font-size: 12px;- font-weight: 600;- color: var(--td-brand-color);- background: color-mix(in srgb, var(--td-brand-color) 12%, transparent);- }-- &__content {- flex: 1;- min-width: 0;- }-&__title {margin: 0 0 4px;font-size: 14px;diff --git a/frontend/src/components/IMChannelPanel.vue b/frontend/src/components/IMChannelPanel.vueindex 6635a4f37..5a24a6935 100644--- a/frontend/src/components/IMChannelPanel.vue+++ b/frontend/src/components/IMChannelPanel.vue@@ -35,19 +35,17 @@{{ $t('agentEditor.im.disabled') }}</t-tag></div>- <p class="channel-card__subtitle">{{ channelSummary(channel) }}</p>+ <span v-if="tenantMode && agentDisplayName(channel)" class="channel-card__agent-name">+ {{ agentDisplayName(channel) }}+ </span></div><div v-if="authStore.hasRole('admin')" class="channel-card__actions" @click.stop>- <t-switch- :value="channel.enabled"- size="small"- @change="() => handleToggle(channel)"- /><t-dropdowntrigger="click"placement="bottom-right"- :options="channelMenuOptions"- @click="(data) => data.value === 'delete' && confirmDelete(channel.id)"+ attach="body"+ :options="channelMenuOptions(channel)"+ @click="(data) => handleChannelMenuClick(data, channel)"><t-buttonvariant="text"@@ -68,10 +66,15 @@class="channel-card channel-card--add"@click="openCreate">- <span class="channel-card--add__icon" aria-hidden="true">+ <span class="channel-card__badge" aria-hidden="true"><t-icon name="add" /></span>- <span class="channel-card--add__label">{{ $t('agentEditor.im.addChannel') }}</span>+ <div class="channel-card__body">+ <div class="channel-card__header">+ <span class="channel-card__title">{{ $t('agentEditor.im.addChannel') }}</span>+ </div>+ </div>+ <span class="channel-card__actions channel-card__actions--spacer" aria-hidden="true" /></button></div></t-loading>@@ -125,14 +128,16 @@<section class="setting-drawer__section im-drawer__section"><h4 class="setting-drawer__section-title">{{ $t('agentEditor.im.sectionChannel') }}</h4>- <div v-if="tenantMode && !editingChannel" class="form-item">- <label class="form-label required">{{ $t('integrations.selectAgent') }}</label>- <t-select- v-model="formData.target_agent_id"- :options="agentOptions"- filterable- :placeholder="$t('integrations.selectAgentPlaceholder')"- />+ <div v-if="tenantMode" class="form-item">+ <label class="form-label required">{{ $t('integrations.boundAgent') }}</label>+ <div class="agent-field-row">+ <t-select+ v-model="formData.target_agent_id"+ :options="agentOptions"+ filterable+ :placeholder="$t('integrations.selectAgentPlaceholder')"+ />+ </div></div><div class="form-item">@@ -173,11 +178,8 @@/><p v-if="!editingChannel" class="form-desc">{{ $t('agentEditor.im.channelNameDefaultHint') }}</p></div>- </section>- <section v-if="editingChannel && authStore.hasRole('admin')" class="setting-drawer__section im-drawer__section">- <h4 class="setting-drawer__section-title">{{ $t('agentEditor.im.sectionStatus') }}</h4>- <div class="setting-row setting-row--last">+ <div v-if="editingChannel && authStore.hasRole('admin')" class="setting-row setting-row--last"><div class="setting-info"><label>{{ $t('agentEditor.im.enabled') }}</label></div>@@ -651,7 +653,7 @@ const drawerTitle = computed(() => {});function validateWizardStep(step: number): boolean {- if (step === 0 && props.tenantMode && !editingChannel.value && !formData.value.target_agent_id) {+ if (step === 0 && props.tenantMode && !formData.value.target_agent_id) {MessagePlugin.warning(t('integrations.selectAgentHint'));return false;}@@ -696,29 +698,42 @@ const formData = ref({credentials: defaultCredentials(),});-const channelMenuOptions = computed(() => ([- { content: t('common.delete'), value: 'delete', theme: 'error' },-]));+const channelMenuOptions = (channel: IMChannel | IMChannelOverview) => ([+ {+ content: channel.enabled ? t('common.off') : t('common.on'),+ value: 'toggle',+ },+ { content: t('common.delete'), value: 'delete', theme: 'error' as const },+]);-const channelSummary = (channel: IMChannel | IMChannelOverview) => {- const parts = [- platformLabel(channel.platform),- channel.mode,- channel.output_mode === 'stream' ? t('agentEditor.im.outputStream') : t('agentEditor.im.outputFull'),- ];- if (channel.session_mode === 'thread') {- parts.push(t('agentEditor.im.sessionModeThread'));+function handleChannelMenuClick(+ data: { value?: string },+ channel: IMChannel | IMChannelOverview,+) {+ if (data.value === 'toggle') {+ void handleToggle(channel);+ return;}- if (props.tenantMode) {- const agentName = agentLabel(channel.agent_id, (channel as IMChannelOverview).agent_name);- if (agentName) parts.unshift(agentName);+ if (data.value === 'delete') {+ confirmDelete(channel.id);}- return parts.join(' · ');-};+}++function agentDisplayName(channel: IMChannel | IMChannelOverview): string {+ return agentForChannel(channel)?.name || '';+}-function agentLabel(agentId: string, overviewName?: string): string {- if (overviewName) return overviewName;- return agents.value.find((agent) => agent.id === agentId)?.name || '';+function agentForChannel(channel: IMChannel | IMChannelOverview): CustomAgent | undefined {+ const found = agents.value.find((agent) => agent.id === channel.agent_id);+ if (found) return found;+ const overviewName = (channel as IMChannelOverview).agent_name;+ if (!overviewName) return undefined;+ return {+ id: channel.agent_id,+ name: overviewName,+ is_builtin: false,+ config: {},+ };}function platformLabel(platform: string): string {@@ -1007,6 +1022,9 @@ async function handleSave() {knowledge_base_id: formData.value.knowledge_base_id,credentials: formData.value.credentials,enabled: editingEnabled.value,+ ...(props.tenantMode && formData.value.target_agent_id+ ? { agent_id: formData.value.target_agent_id }+ : {}),});MessagePlugin.success(t('common.updateSuccess'));} else {@@ -1077,198 +1095,13 @@ onUnmounted(() => {</script><style scoped lang="less">+@import './css/channel-panel-list.less';+.im-panel {display: flex;flex-direction: column;}-.channels-header {- display: flex;- align-items: center;- gap: 8px;- margin-bottom: 12px;-- .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-wrap {- min-height: 80px;-}--.channels-empty {- padding: 32px 0;-}--.channel-grid {- display: grid;- grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));- gap: 12px;-}--.channel-card {- position: relative;- display: flex;- align-items: flex-start;- gap: 12px;- padding: 14px 16px;- border: 1px solid var(--td-component-stroke);- border-radius: 10px;- background: var(--td-bg-color-container);- text-align: left;- font: inherit;- color: inherit;- transition: border-color 0.18s ease, box-shadow 0.18s ease;-- &--clickable {- cursor: pointer;- width: 100%;-- &:hover,- &:focus-visible {- border-color: var(--td-brand-color-3, var(--td-brand-color));- box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);- outline: none;- }-- &:focus-visible {- outline: 2px solid var(--td-brand-color);- outline-offset: 2px;- }- }-- &--add {- flex-direction: column;- align-items: center;- justify-content: center;- gap: 8px;- min-height: 68px;- border-style: dashed;- background: transparent;- color: var(--td-text-color-placeholder);- cursor: pointer;- width: 100%;-- &:hover,- &:focus-visible {- color: var(--td-brand-color);- border-color: var(--td-brand-color);- background: color-mix(in srgb, var(--td-brand-color) 6%, transparent);- box-shadow: none;- }-- &__icon {- display: flex;- align-items: center;- justify-content: center;- width: 32px;- height: 32px;- border-radius: 8px;- background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);- color: var(--td-brand-color);- font-size: 18px;- }-- &__label {- font-size: 13px;- font-weight: 500;- line-height: 1.4;- }- }-- &__badge {- flex-shrink: 0;- width: 28px;- height: 28px;- border-radius: 7px;- display: flex;- align-items: center;- justify-content: center;- background: var(--td-bg-color-secondarycontainer);- overflow: hidden;- }-- &__logo {- width: 16px;- height: 16px;- object-fit: contain;- }-- &__body {- flex: 1;- min-width: 0;- }-- &__header {- display: flex;- align-items: center;- gap: 6px;- min-width: 0;- }-- &__title {- flex: 1;- min-width: 0;- margin: 0;- font-size: 14px;- font-weight: 600;- line-height: 1.4;- color: var(--td-text-color-primary);- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;- }-- &__subtitle {- margin: 2px 0 0;- font-size: 12px;- line-height: 1.5;- color: var(--td-text-color-secondary);- overflow: hidden;- text-overflow: ellipsis;- white-space: nowrap;- }-- &__actions {- flex-shrink: 0;- display: flex;- align-items: center;- gap: 2px;- padding-top: 2px;- }-- &__more {- flex-shrink: 0;- padding: 2px;- opacity: 0;- color: var(--td-text-color-placeholder);- transition: opacity 0.15s ease;-- &:hover,- &:focus-visible {- background: var(--td-bg-color-secondarycontainer);- color: var(--td-text-color-primary);- }- }-- &:hover .channel-card__more,- &:focus-within .channel-card__more,- &__actions:focus-within .channel-card__more {- opacity: 1;- }-}-.drawer-platform-icon {width: 16px;height: 16px;diff --git a/frontend/src/components/css/channel-panel-list.less b/frontend/src/components/css/channel-panel-list.lessnew file mode 100644index 000000000..fbf7069ed--- /dev/null+++ b/frontend/src/components/css/channel-panel-list.less@@ -0,0 +1,192 @@+.channels-header {+ display: flex;+ align-items: center;+ gap: 8px;+ margin-bottom: 12px;++ .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-wrap {+ min-height: 80px;+}++.channels-empty {+ padding: 32px 0;+}++.channel-grid {+ display: grid;+ grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));+ gap: 12px;+ align-items: stretch;+}++.channel-card {+ position: relative;+ display: flex;+ align-items: center;+ gap: 12px;+ height: 100%;+ box-sizing: border-box;+ padding: 10px 12px;+ border: 1px solid var(--td-component-stroke);+ border-radius: 10px;+ background: var(--td-bg-color-container);+ text-align: left;+ font: inherit;+ color: inherit;+ transition: border-color 0.18s ease, box-shadow 0.18s ease;++ &--clickable {+ cursor: pointer;+ width: 100%;++ &:hover,+ &:focus-visible {+ border-color: var(--td-brand-color-3, var(--td-brand-color));+ box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);+ outline: none;+ }++ &:focus-visible {+ outline: 2px solid var(--td-brand-color);+ outline-offset: 2px;+ }+ }++ &--add {+ align-items: center;+ justify-content: flex-start;+ border-style: dashed;+ background: transparent;+ color: var(--td-text-color-placeholder);+ cursor: pointer;+ width: 100%;++ &:hover,+ &:focus-visible {+ color: var(--td-brand-color);+ border-color: var(--td-brand-color);+ background: color-mix(in srgb, var(--td-brand-color) 6%, transparent);+ box-shadow: none;+ }++ .channel-card__badge {+ background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);+ color: var(--td-brand-color);+ font-size: 16px;+ }++ .channel-card__title {+ font-size: 13px;+ font-weight: 500;+ color: inherit;+ }+ }++ &__badge {+ flex-shrink: 0;+ width: 28px;+ height: 28px;+ border-radius: 7px;+ display: flex;+ align-items: center;+ justify-content: center;+ background: var(--td-bg-color-secondarycontainer);+ color: var(--td-text-color-secondary);+ overflow: hidden;+ }++ &__logo {+ width: 16px;+ height: 16px;+ object-fit: contain;+ }++ &__body {+ flex: 1;+ min-width: 0;+ }++ &__header {+ display: flex;+ align-items: center;+ gap: 6px;+ min-width: 0;+ }++ &__title {+ flex: 1;+ min-width: 0;+ margin: 0;+ font-size: 14px;+ font-weight: 600;+ line-height: 1.4;+ color: var(--td-text-color-primary);+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ }++ &__agent-name {+ display: block;+ margin-top: 4px;+ font-size: 12px;+ line-height: 1.4;+ color: var(--td-text-color-placeholder);+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ }++ &__actions {+ flex-shrink: 0;+ display: flex;+ align-items: center;+ gap: 2px;+ margin-left: auto;++ &--spacer {+ width: 24px;+ height: 24px;+ }+ }++ &__more {+ flex-shrink: 0;+ padding: 2px;+ color: var(--td-text-color-placeholder);+ transition: color 0.15s ease, background 0.15s ease;++ &:hover,+ &:focus-visible {+ background: var(--td-bg-color-secondarycontainer);+ color: var(--td-text-color-primary);+ }+ }+}++.agent-field-row {+ display: flex;+ align-items: center;+ gap: 8px;+ min-width: 0;++ :deep(.t-select) {+ flex: 1;+ min-width: 0;+ }+}diff --git a/frontend/src/composables/useEmbedBridge.ts b/frontend/src/composables/useEmbedBridge.tsindex e59310502..5da91d4ae 100644--- a/frontend/src/composables/useEmbedBridge.ts+++ b/frontend/src/composables/useEmbedBridge.ts@@ -3,6 +3,7 @@ import { useRoute } from 'vue-router'import { useI18n } from 'vue-i18n'import {createEmbedSession,+ embedChatSessionStorageKey,exchangeEmbedSession,getEmbedConfig,getEmbedMessageList,@@ -19,18 +20,16 @@ import { applyEmbedLocale, readEmbedLocaleFromUrl, syncEmbedLocaleFromUrl } from// Persist the chat session id per channel so a page refresh resumes the same// conversation (and its history) instead of silently starting a new session.-const EMBED_SESSION_STORAGE_PREFIX = 'weknora-embed-session:'--const sessionStorageKey = (channelId: string) => `${EMBED_SESSION_STORAGE_PREFIX}${channelId}`-interface StoredSession {id: stringsig: string+ /** Agent bound when the session was created; mismatch forces a new session. */+ agentId?: string}function readStoredSession(channelId: string): StoredSession | null {try {- const raw = window.localStorage.getItem(sessionStorageKey(channelId))+ const raw = window.localStorage.getItem(embedChatSessionStorageKey(channelId))if (!raw) return nullconst parsed = JSON.parse(raw)if (parsed && typeof parsed.id === 'string' && typeof parsed.sig === 'string' && parsed.id) {@@ -46,9 +45,9 @@ function readStoredSession(channelId: string): StoredSession | null {function writeStoredSession(channelId: string, session: StoredSession | null) {try {if (session?.id) {- window.localStorage.setItem(sessionStorageKey(channelId), JSON.stringify(session))+ window.localStorage.setItem(embedChatSessionStorageKey(channelId), JSON.stringify(session))} else {- window.localStorage.removeItem(sessionStorageKey(channelId))+ window.localStorage.removeItem(embedChatSessionStorageKey(channelId))}} catch {// localStorage may be unavailable (private mode / disabled cookies).@@ -141,15 +140,20 @@ export function useEmbedBridge(channelId: Ref<string>) {applyEmbedLocale(res.data.default_locale, activeLocale)}- // Resume a persisted session when still valid; otherwise create a fresh one.+ // Resume a persisted session when still valid and still bound to the same+ // agent; otherwise create a fresh one (e.g. after rebinding the channel).+ const configAgentId = String(res.data.agent_id || '').trim()let resolved: StoredSession | null = nullconst stored = readStoredSession(id)- if (stored && (await isStoredSessionValid(id, apiToken, stored))) {- resolved = stored+ const agentMatches = !stored?.agentId || !configAgentId || stored.agentId === configAgentId+ if (stored && agentMatches && (await isStoredSessionValid(id, apiToken, stored))) {+ resolved = { ...stored, agentId: configAgentId || stored.agentId }} else {const sessionRes = await createEmbedSession(id, apiToken)const newId = sessionRes?.data?.id || ''- if (newId) resolved = { id: newId, sig: sessionRes?.data?.sig || '' }+ if (newId) {+ resolved = { id: newId, sig: sessionRes?.data?.sig || '', agentId: configAgentId }+ }}if (!resolved) {loadError.value = t('embedPublish.sessionFailed')@@ -185,7 +189,8 @@ export function useEmbedBridge(channelId: Ref<string>) {const sessionRes = await createEmbedSession(id, apiToken)const newId = sessionRes?.data?.id || ''if (!newId) return- const next: StoredSession = { id: newId, sig: sessionRes?.data?.sig || '' }+ const agentId = String(config.value?.agent_id || '').trim()+ const next: StoredSession = { id: newId, sig: sessionRes?.data?.sig || '', agentId }sessionSig.value = next.sigsessionId.value = next.idwriteStoredSession(id, next)diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.tsindex 80351ea68..9c7994eeb 100755--- a/frontend/src/i18n/locales/en-US.ts+++ b/frontend/src/i18n/locales/en-US.ts@@ -2320,8 +2320,12 @@ export default {name: 'Name',nameDesc: 'For admin lists and channel identification',namePlaceholder: 'e.g. Website support',+ nameDefaultHint: 'Defaults to "{agent} · Web Embed" when an agent is selected. Leave blank on save to use the default name.',+ defaultChannelName: 'Web Embed',+ defaultChannelNameWithAgent: '{agent} · Web Embed',welcomeMessage: 'Welcome message',welcomePlaceholder: 'Hi! How can I help you?',+ welcomeMessageDesc: 'Shown in the embed chat before the visitor sends their first message; leave blank to hide',showSuggestedQuestions: 'Suggested questions',showSuggestedQuestionsDesc: 'Show starter prompts before the first visitor message, from agent config and linked knowledge bases',originsLabel: 'Allowed origins (one per line, at least one required)',@@ -2329,7 +2333,7 @@ export default {originsRequired: 'At least one allowed origin is required',originsInvalid: 'Invalid origin: {origin}',originsWildcardProd: "Wildcard origin '*' is not allowed in production",- originsCount: '{n} allowed origins',+ originsCount: '{n} origins',originsPlaceholder: 'https://shop.example.com',rateLimitLabel: 'Requests per minute',rateLimitDesc: 'Per visitor IP, max embed API requests per minute; excess requests are temporarily rejected. Default 30.',@@ -2409,7 +2413,13 @@ export default {sectionAppearance: 'Appearance',sectionDeploy: 'Deploy to site',sectionWebhook: 'Event callbacks',- deployIntro: 'After saving, follow these two steps to embed chat on your website.',+ stepChannel: 'Channel info',+ stepSecurity: 'Security',+ stepCapabilities: 'Capabilities',+ stepAppearance: 'Appearance',+ stepWebhook: 'Webhooks',+ stepDeploy: 'Deploy',+ deployIntro: 'Choose an embed style and copy the snippet below into your site. View or rotate the channel key at the bottom when you need credentials.',deployStepToken: 'Channel key',deployStepTokenDesc: 'Long-lived secret (em_…), like an API key. Shown on this page only when created or reset—store it safely.',deployStepEmbed: 'Copy embed code',@@ -5604,6 +5614,7 @@ export default {selectAgentDesc: 'Each integration channel is bound to one agent. Choose the agent to configure.',selectAgentPlaceholder: 'Choose an agent',selectAgentHint: 'Please select an agent first',+ boundAgent: 'Bound agent',manageChannel: 'Manage channel',goToCenter: 'Open Integrations',imOverview: {diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.tsindex 3366d4f0a..1d0a1afd4 100755--- a/frontend/src/i18n/locales/ko-KR.ts+++ b/frontend/src/i18n/locales/ko-KR.ts@@ -3205,8 +3205,12 @@ export default {name: '이름',nameDesc: '관리 목록 및 채널 식별용',namePlaceholder: '예: 웹사이트 고객센터',+ nameDefaultHint: '기본값은 「에이전트명 · 웹 페이지 임베드」입니다. 직접 수정할 수 있으며, 비워 두고 저장해도 기본 이름이 사용됩니다.',+ defaultChannelName: '웹 페이지 임베드',+ defaultChannelNameWithAgent: '{agent} · 웹 페이지 임베드',welcomeMessage: '환영 메시지',welcomePlaceholder: '안녕하세요! 무엇을 도와드릴까요?',+ welcomeMessageDesc: '방문자가 임베드 채팅을 열고 첫 메시지를 보내기 전에 표시됩니다. 비우면 표시하지 않습니다',showSuggestedQuestions: '추천 질문',showSuggestedQuestionsDesc: '방문자 첫 메시지 전에 빠른 질문을 표시합니다(에이전트 설정 및 연결된 지식베이스에서 가져옴)',originsLabel: '허용 도메인(한 줄에 하나, 최소 1개)',@@ -3214,7 +3218,7 @@ export default {originsRequired: '허용 도메인을 최소 1개 입력하세요',originsInvalid: '잘못된 도메인: {origin}',originsWildcardProd: "프로덕션에서는 와일드카드 '*'를 사용할 수 없습니다",- originsCount: '허용 도메인 {n}개',+ originsCount: '도메인 {n}개',originsPlaceholder: 'https://shop.example.com',rateLimitLabel: '분당 요청 상한',rateLimitDesc: '방문자 IP 기준, 분당 최대 임베드 API 요청 수; 초과 시 일시 거부. 기본 30.',@@ -3285,7 +3289,13 @@ export default {agentImageUploadDisabledHint: '현재 에이전트에서 이미지 업로드가 활성화되지 않았습니다. 방문자에게 업로드 버튼이 표시되지 않습니다. 에이전트 설정에서 이미지 업로드를 먼저 활성화하세요.',sectionAppearance: '외관 및 표시',sectionDeploy: '사이트에 배포',- deployIntro: '저장 후 다음 두 단계로 웹사이트에 채팅을 임베드하세요.',+ stepChannel: '채널 정보',+ stepSecurity: '보안·제한',+ stepCapabilities: '대화 기능',+ stepAppearance: '외관·표시',+ stepWebhook: '이벤트',+ stepDeploy: '배포',+ deployIntro: '임베드 방식을 선택하고 아래 코드를 사이트에 붙여넣으세요. 인증이 필요하면 하단의 채널 키 영역에서 확인하거나 재설정하세요.',deployStepToken: '채널 키',deployStepTokenDesc: '장기 비밀키(em_…), API Key와 유사. 생성 또는 재설정 시 이 페이지에서만 표시 — 안전하게 보관하세요.',deployStepEmbed: '임베드 코드 복사',@@ -5615,6 +5625,7 @@ export default {selectAgentDesc: "각 통합 채널은 하나의 에이전트에 연결됩니다. 구성할 에이전트를 선택하세요",selectAgentPlaceholder: "에이전트를 선택하세요",selectAgentHint: "먼저 에이전트를 선택하세요",+ boundAgent: "연결된 에이전트",manageChannel: "채널 관리",goToCenter: "통합 센터로 이동",imOverview: {diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.tsindex c6d3f4456..ca90f62b1 100755--- a/frontend/src/i18n/locales/ru-RU.ts+++ b/frontend/src/i18n/locales/ru-RU.ts@@ -2706,8 +2706,12 @@ export default {name: 'Название',nameDesc: 'Для админ-списков и идентификации канала',namePlaceholder: 'напр. Поддержка на сайте',+ nameDefaultHint: 'По умолчанию «{agent} · Встраивание на сайт». Можно изменить; при пустом поле при сохранении используется имя по умолчанию.',+ defaultChannelName: 'Встраивание на сайт',+ defaultChannelNameWithAgent: '{agent} · Встраивание на сайт',welcomeMessage: 'Приветствие',welcomePlaceholder: 'Здравствуйте! Чем могу помочь?',+ welcomeMessageDesc: 'Показывается во встроенном чате до первого сообщения посетителя; оставьте пустым, чтобы скрыть',showSuggestedQuestions: 'Рекомендуемые вопросы',showSuggestedQuestionsDesc: 'Показывать быстрые вопросы до первого сообщения посетителя — из настроек агента и связанных баз знаний',originsLabel: 'Разрешённые домены (по одному в строке, минимум один)',@@ -2715,7 +2719,7 @@ export default {originsRequired: 'Укажите хотя бы один разрешённый домен',originsInvalid: 'Неверный домен: {origin}',originsWildcardProd: "В production запрещён wildcard '*'",- originsCount: '{n} разрешённых доменов',+ originsCount: '{n} дом.',originsPlaceholder: 'https://shop.example.com',rateLimitLabel: 'Запросов в минуту',rateLimitDesc: 'На IP посетителя, макс. запросов к API встраивания в минуту; избыток временно отклоняется. По умолчанию 30.',@@ -2786,7 +2790,13 @@ export default {agentImageUploadDisabledHint: 'У этого агента не включена загрузка изображений. Посетители не увидят кнопку загрузки, пока вы не включите её в настройках агента.',sectionAppearance: 'Внешний вид',sectionDeploy: 'Развернуть на сайте',- deployIntro: 'После сохранения выполните два шага для встраивания чата на сайт.',+ stepChannel: 'Канал',+ stepSecurity: 'Безопасность',+ stepCapabilities: 'Возможности',+ stepAppearance: 'Внешний вид',+ stepWebhook: 'Webhook',+ stepDeploy: 'Развёртывание',+ deployIntro: 'Выберите способ встраивания и скопируйте код ниже на сайт. Ключ канала внизу — для аутентификации и сброса.',deployStepToken: 'Ключ канала',deployStepTokenDesc: 'Долгоживущий секрет (em_…), как API Key. Только на этой странице при создании/сбросе — храните надёжно.',deployStepEmbed: 'Копировать код встраивания',@@ -5437,6 +5447,7 @@ export default {selectAgentDesc: 'Каждый канал интеграции привязан к одному агенту. Выберите агента для настройки.',selectAgentPlaceholder: 'Выберите агента',selectAgentHint: 'Сначала выберите агента',+ boundAgent: 'Привязанный агент',manageChannel: 'Управлять каналом',goToCenter: 'Открыть интеграции',imOverview: {diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.tsindex 03ebc660c..380712391 100755--- a/frontend/src/i18n/locales/zh-CN.ts+++ b/frontend/src/i18n/locales/zh-CN.ts@@ -3223,8 +3223,12 @@ export default {name: "名称",nameDesc: "后台管理用,用于列表与渠道识别",namePlaceholder: "例如:官网客服",+ nameDefaultHint: "默认为「智能体名 · 网页嵌入」,可自行修改;留空保存时也会使用该名称",+ defaultChannelName: "网页嵌入",+ defaultChannelNameWithAgent: "{agent} · 网页嵌入",welcomeMessage: "欢迎语",welcomePlaceholder: "你好,有什么可以帮您?",+ welcomeMessageDesc: "访客打开嵌入聊天后、尚未发言时展示;留空则不显示",showSuggestedQuestions: "推荐问题",showSuggestedQuestionsDesc: "访客未发言前展示快捷提问,内容来自智能体配置与关联知识库",originsLabel: "域名白名单(每行一个,至少填写一个)",@@ -3232,7 +3236,7 @@ export default {originsRequired: "请至少填写一个域名白名单",originsInvalid: "域名格式无效:{origin}",originsWildcardProd: "生产环境不允许使用通配符 *",- originsCount: "白名单 {n} 个",+ originsCount: "{n} 个域名",originsPlaceholder: "https://shop.example.com",rateLimitLabel: "每分钟请求上限",rateLimitDesc: "按访客 IP 统计,每分钟最多允许的嵌入接口请求次数;超出后暂时拒绝访问,默认 30。",@@ -3312,7 +3316,13 @@ export default {sectionAppearance: "外观与展示",sectionDeploy: "嵌入到网页",sectionWebhook: "事件回调",- deployIntro: "保存设置后,按以下两步将聊天嵌入到您的网站。",+ stepChannel: "渠道信息",+ stepSecurity: "安全限流",+ stepCapabilities: "对话能力",+ stepAppearance: "外观展示",+ stepWebhook: "事件回调",+ stepDeploy: "网页嵌入",+ deployIntro: "选择嵌入方式并复制下方代码到您的网页;需要鉴权或轮换密钥时,可在页面底部的「渠道密钥」区域操作。",deployStepToken: "渠道密钥",deployStepTokenDesc: "长期密钥(em_…),相当于 API Key。创建或重置时仅在本页显示,请妥善保存。",deployStepEmbed: "复制嵌入代码",@@ -5622,6 +5632,7 @@ export default {selectAgentDesc: "每个集成渠道绑定一个智能体,请先选择要配置的智能体",selectAgentPlaceholder: "请选择智能体",selectAgentHint: "请先选择一个智能体",+ boundAgent: "绑定智能体",manageChannel: "管理渠道",goToCenter: "前往集成中心",imOverview: {diff --git a/frontend/src/main.ts b/frontend/src/main.tsindex 36d734d7d..9b87ece0b 100644--- a/frontend/src/main.ts+++ b/frontend/src/main.ts@@ -17,6 +17,7 @@ import i18n from "./i18n";import { initTheme } from "@/composables/useTheme";import { initFont } from "@/composables/useFont";import { installTDesignIconOfflineGuard } from "@/utils/tdesign-icon-offline";+import { installAutofillGuard } from "@/utils/disable-autofill";// 必须在 Vue 组件挂载之前执行,避免 tdesign-icons 运行时请求 tdesign.gtimg.cominstallTDesignIconOfflineGuard();@@ -34,4 +35,5 @@ app.use(i18n);// 等首屏路由(含导航守卫、Lite 自动登录)完成后再挂载,避免先闪默认页再跳转router.isReady().finally(() => {app.mount("#app");+ installAutofillGuard();});diff --git a/frontend/src/utils/disable-autofill.ts b/frontend/src/utils/disable-autofill.tsnew file mode 100644index 000000000..3d7e1acd0--- /dev/null+++ b/frontend/src/utils/disable-autofill.ts@@ -0,0 +1,52 @@+/**+ * Globally discourage browser/password-manager autofill on app inputs.+ * Skips elements that already declare autocomplete (e.g. login email).+ */+function guardElement(el: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement) {+ const explicit = el.getAttribute('autocomplete');+ if (explicit !== null && explicit !== '') return;+ if (el.closest('[data-allow-autofill]')) return;++ if (el instanceof HTMLInputElement && el.type === 'password') {+ el.setAttribute('autocomplete', 'new-password');+ } else {+ el.setAttribute('autocomplete', 'off');+ }+}++function guardTree(root: ParentNode) {+ if (root instanceof HTMLInputElement || root instanceof HTMLTextAreaElement || root instanceof HTMLSelectElement) {+ guardElement(root);+ }++ root.querySelectorAll?.('input, textarea, select').forEach((node) => {+ guardElement(node as HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement);+ });++ root.querySelectorAll?.('form').forEach((form) => {+ if (!form.hasAttribute('autocomplete')) {+ form.setAttribute('autocomplete', 'off');+ }+ });+}++let installed = false;++export function installAutofillGuard() {+ if (installed || typeof document === 'undefined') return;+ installed = true;++ guardTree(document);++ const observer = new MutationObserver((mutations) => {+ for (const mutation of mutations) {+ mutation.addedNodes.forEach((node) => {+ if (node instanceof HTMLElement) {+ guardTree(node);+ }+ });+ }+ });++ observer.observe(document.body, { childList: true, subtree: true });+}diff --git a/frontend/src/views/auth/Login.vue b/frontend/src/views/auth/Login.vueindex e9be217f8..6e5dccd6c 100755--- a/frontend/src/views/auth/Login.vue+++ b/frontend/src/views/auth/Login.vue@@ -192,7 +192,7 @@<t-form-item :label="$t('auth.password')" name="password"><t-input v-model="formData.password" :placeholder="$t('auth.passwordPlaceholder')" type="password"- size="large" :disabled="loading" @enter="handleLogin" />+ autocomplete="current-password" size="large" :disabled="loading" @enter="handleLogin" /></t-form-item><t-button type="submit" theme="primary" size="large" block :loading="loading" class="submit-button">@@ -280,12 +280,12 @@<t-form-item :label="$t('auth.password')" name="password"><t-input v-model="registerData.password" :placeholder="$t('auth.passwordPlaceholder')" type="password"- size="large" :disabled="loading" />+ autocomplete="new-password" size="large" :disabled="loading" /></t-form-item><t-form-item :label="$t('auth.confirmPassword')" name="confirmPassword"><t-input v-model="registerData.confirmPassword" :placeholder="$t('auth.confirmPasswordPlaceholder')"- type="password" size="large" :disabled="loading" @enter="handleRegister" />+ type="password" autocomplete="new-password" size="large" :disabled="loading" @enter="handleRegister" /></t-form-item><t-button type="submit" theme="primary" size="large" block :loading="loading" class="submit-button">diff --git a/internal/application/service/embed_channel.go b/internal/application/service/embed_channel.goindex 601ada015..f70f54e5d 100644--- a/internal/application/service/embed_channel.go+++ b/internal/application/service/embed_channel.go@@ -177,6 +177,12 @@ func (s *embedChannelService) Update(ch.AllowedOrigins = req.AllowedOrigins}}+ if trimmed := strings.TrimSpace(req.AgentID); trimmed != "" && trimmed != ch.AgentID {+ if _, err := s.ensureAgentOwned(ctx, tenantID, trimmed); err != nil {+ return nil, err+ }+ ch.AgentID = trimmed+ }if err := s.repo.Update(ctx, ch); err != nil {return nil, err}diff --git a/internal/application/service/embed_channel_update_test.go b/internal/application/service/embed_channel_update_test.gonew file mode 100644index 000000000..6acea6455--- /dev/null+++ b/internal/application/service/embed_channel_update_test.go@@ -0,0 +1,62 @@+package service++import (+ "context"+ "testing"++ "github.com/Tencent/WeKnora/internal/types"+ "github.com/Tencent/WeKnora/internal/types/interfaces"+)++type stubEmbedChannelRepo struct {+ interfaces.EmbedChannelRepository+ ch *types.EmbedChannel+}++func (r *stubEmbedChannelRepo) GetByID(_ context.Context, id string) (*types.EmbedChannel, error) {+ if r.ch == nil || r.ch.ID != id {+ return nil, nil+ }+ cp := *r.ch+ return &cp, nil+}++func (r *stubEmbedChannelRepo) Update(_ context.Context, ch *types.EmbedChannel) error {+ cp := *ch+ r.ch = &cp+ return nil+}++func TestEmbedChannelUpdateAgentID(t *testing.T) {+ repo := &stubEmbedChannelRepo{+ ch: &types.EmbedChannel{+ ID: "ch-1",+ TenantID: 42,+ AgentID: "agent-old",+ Name: "Support",+ },+ }+ svc := &embedChannelService{+ repo: repo,+ agentService: &stubAgentForEmbed{+ agent: &types.CustomAgent{ID: "agent-new", TenantID: 42},+ },+ }+ enabled := true+ updated, err := svc.Update(+ context.Background(),+ 42,+ "ch-1",+ &types.EmbedChannel{AgentID: "agent-new"},+ &enabled, nil, nil, nil, nil, nil, nil, nil,+ )+ if err != nil {+ t.Fatalf("Update() error = %v", err)+ }+ if updated.AgentID != "agent-new" {+ t.Fatalf("updated.AgentID = %q, want agent-new", updated.AgentID)+ }+ if repo.ch.AgentID != "agent-new" {+ t.Fatalf("persisted AgentID = %q, want agent-new", repo.ch.AgentID)+ }+}diff --git a/internal/handler/embed_channel.go b/internal/handler/embed_channel.goindex 4714ddb01..770ca23b5 100644--- a/internal/handler/embed_channel.go+++ b/internal/handler/embed_channel.go@@ -67,6 +67,7 @@ type embedChannelRequest struct {DefaultLocale *string `json:"default_locale"`WebhookURL *string `json:"webhook_url"`WebhookSecret *string `json:"webhook_secret"`+ AgentID *string `json:"agent_id"`}// isProductionMode reports whether the server runs in a hardened (release) mode.@@ -242,6 +243,9 @@ func (h *EmbedChannelHandler) UpdateEmbedChannel(c *gin.Context) {HeaderTitleMode: req.HeaderTitleMode,WidgetPosition: req.WidgetPosition,}+ if req.AgentID != nil {+ update.AgentID = strings.TrimSpace(*req.AgentID)+ }ch, err := h.embedSvc.Update(c.Request.Context(), tenantID, channelID, update, req.Enabled, req.ShowSuggestedQuestions, req.AllowWebSearch, req.AllowMemory, req.AllowFileUpload, req.DefaultLocale, req.WebhookURL, req.WebhookSecret)if err != nil {writeEmbedMgmtError(c, err)diff --git a/internal/handler/im.go b/internal/handler/im.goindex f9a24321f..f85e1ece7 100644--- a/internal/handler/im.go+++ b/internal/handler/im.go@@ -196,6 +196,7 @@ func (h *IMHandler) UpdateIMChannel(c *gin.Context) {KnowledgeBaseID *string `json:"knowledge_base_id"`Credentials types.JSON `json:"credentials"`Enabled *bool `json:"enabled"`+ AgentID *string `json:"agent_id"`}if err := c.ShouldBindJSON(&req); err != nil {c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})@@ -220,6 +221,16 @@ func (h *IMHandler) UpdateIMChannel(c *gin.Context) {if req.Enabled != nil {channel.Enabled = *req.Enabled}+ if req.AgentID != nil {+ newAgentID := strings.TrimSpace(*req.AgentID)+ if newAgentID != "" && newAgentID != channel.AgentID {+ if err := h.imService.SetChannelAgentID(c.Request.Context(), channel, newAgentID); err != nil {+ logger.Errorf(c.Request.Context(), "[IM] Update channel agent failed: %v", err)+ c.JSON(http.StatusBadRequest, gin.H{"error": "agent not found"})+ return+ }+ }+ }if err := h.imService.UpdateChannel(channel); err != nil {logger.Errorf(c.Request.Context(), "[IM] Update channel failed: %v", err)diff --git a/internal/im/service.go b/internal/im/service.goindex 5b11991a6..73567d7ed 100644--- a/internal/im/service.go+++ b/internal/im/service.go@@ -2501,6 +2501,23 @@ func (s *Service) CreateChannel(channel *IMChannel) error {return nil}+// SetChannelAgentID validates and assigns a new agent for an existing channel.+func (s *Service) SetChannelAgentID(ctx context.Context, channel *IMChannel, agentID string) error {+ agentID = strings.TrimSpace(agentID)+ if agentID == "" {+ return fmt.Errorf("agent_id is required")+ }+ agent, err := s.agentService.GetAgentByID(ctx, agentID)+ if err != nil {+ return err+ }+ if agent == nil || agent.TenantID != channel.TenantID {+ return fmt.Errorf("agent not found")+ }+ channel.AgentID = agentID+ return nil+}+// UpdateChannel updates a channel and restarts it if needed.// Returns a duplicate_bot error if the bot identity is already used by another channel.func (s *Service) UpdateChannel(channel *IMChannel) error {