feat(chat): add global search to the @ mention menu and align its styling (#4249)
parent
2511a1f932
commit
9238220867
|
|
@ -1272,9 +1272,14 @@ const updateModelDropdownPosition = () => {
|
|||
|
||||
// Mention Logic
|
||||
let lastMentionQuery = '';
|
||||
// 关键词变化时旧请求可能晚于新请求返回;只采纳最新一次加载的结果
|
||||
let mentionLoadSeq = 0;
|
||||
const loadMentionItems = async (q: string, resetIndex = true, append = false) => {
|
||||
console.log('[Mention] loadMentionItems called with query:', q, 'append:', append);
|
||||
|
||||
const seq = append ? mentionLoadSeq : ++mentionLoadSeq;
|
||||
const isStale = () => seq !== mentionLoadSeq;
|
||||
const nextGroupCounts: Partial<Record<MentionItemType, number>> = append ? mentionGroupCounts.value : {};
|
||||
if (!append) {
|
||||
mentionOffset.value = 0;
|
||||
}
|
||||
|
|
@ -1392,7 +1397,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
|||
orgName: kb.org_name || sharedAgentOrgName.value || undefined
|
||||
};
|
||||
}));
|
||||
mentionGroupCounts.value.kb = kbItems.length;
|
||||
nextGroupCounts.kb = kbItems.length;
|
||||
|
||||
const tagKeyword = q.trim();
|
||||
const tagSources = availableKbs;
|
||||
|
|
@ -1410,7 +1415,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
|||
}));
|
||||
}));
|
||||
tagItems = tagResults.flat();
|
||||
mentionGroupCounts.value.tag = tagItems.length;
|
||||
nextGroupCounts.tag = tagItems.length;
|
||||
} catch (e) {
|
||||
console.error('[Mention] listKnowledgeTags error:', e);
|
||||
tagItems = [];
|
||||
|
|
@ -1488,6 +1493,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
|||
fileTypesParam,
|
||||
searchOptions
|
||||
);
|
||||
if (isStale()) return;
|
||||
console.log('[Mention] searchKnowledge response:', res);
|
||||
if (res.data && Array.isArray(res.data)) {
|
||||
let files = res.data;
|
||||
|
|
@ -1528,24 +1534,28 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) =>
|
|||
if (!append) {
|
||||
const clientFiltered = !!mentionAllowedKbIds.value && fileItems.length < apiPageSize;
|
||||
if (!clientFiltered && rawTotal != null) {
|
||||
mentionGroupCounts.value.file = rawTotal;
|
||||
nextGroupCounts.file = rawTotal;
|
||||
} else {
|
||||
delete mentionGroupCounts.value.file;
|
||||
delete nextGroupCounts.file;
|
||||
}
|
||||
}
|
||||
}
|
||||
mentionHasMore.value = res.has_more || false;
|
||||
mentionOffset.value += fileItems.length;
|
||||
} catch (e) {
|
||||
if (isStale()) return;
|
||||
console.error('[Mention] searchKnowledge error:', e);
|
||||
mentionHasMore.value = false;
|
||||
} finally {
|
||||
mentionLoading.value = false;
|
||||
if (!isStale()) mentionLoading.value = false;
|
||||
}
|
||||
} else {
|
||||
if (isStale()) return;
|
||||
mentionHasMore.value = false;
|
||||
}
|
||||
|
||||
if (isStale()) return;
|
||||
if (!append) mentionGroupCounts.value = nextGroupCounts;
|
||||
if (append) {
|
||||
// Append file items to existing list
|
||||
mentionItems.value = [...mentionItems.value, ...fileItems];
|
||||
|
|
@ -1571,6 +1581,21 @@ const loadMoreMentionItems = () => {
|
|||
}
|
||||
};
|
||||
|
||||
let mentionSearchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
const onMentionSearchInput = (q: string) => {
|
||||
mentionQuery.value = q;
|
||||
if (mentionSearchTimer) clearTimeout(mentionSearchTimer);
|
||||
mentionSearchTimer = setTimeout(() => {
|
||||
mentionSearchTimer = null;
|
||||
loadMentionItems(q, true);
|
||||
}, 180);
|
||||
};
|
||||
|
||||
const closeMentionFromPopup = () => {
|
||||
showMention.value = false;
|
||||
void focusInput();
|
||||
};
|
||||
|
||||
const getTextareaEl = () => {
|
||||
if (!textareaRef.value) return null;
|
||||
// If it's a native element
|
||||
|
|
@ -1631,10 +1656,8 @@ const onInput = (val: string | InputEvent) => {
|
|||
showMention.value = false;
|
||||
return;
|
||||
}
|
||||
// Only reload if query changed
|
||||
if (q !== mentionQuery.value) {
|
||||
mentionQuery.value = q;
|
||||
loadMentionItems(q, true); // Reset index when query changes
|
||||
onMentionSearchInput(q);
|
||||
}
|
||||
} else {
|
||||
if (textBeforeCursor.endsWith('@')) {
|
||||
|
|
@ -1655,7 +1678,7 @@ const onInput = (val: string | InputEvent) => {
|
|||
const rect = rectToCssPx(textarea.getBoundingClientRect(), zoom);
|
||||
const { width: vw, height: vh } = cssViewportSize(zoom);
|
||||
const scrollTop = textarea.scrollTop;
|
||||
const menuHeight = 320; // 预估最大高度
|
||||
const menuHeight = 380; // 预估最大高度
|
||||
|
||||
let left = rect.left + coords.left;
|
||||
// Prevent menu from going off-screen horizontally
|
||||
|
|
@ -1688,6 +1711,7 @@ const onInput = (val: string | InputEvent) => {
|
|||
};
|
||||
}
|
||||
|
||||
if (mentionSearchTimer) clearTimeout(mentionSearchTimer);
|
||||
loadMentionItems("");
|
||||
}
|
||||
}
|
||||
|
|
@ -1734,7 +1758,7 @@ const triggerMention = () => {
|
|||
const zoom = getRootZoom();
|
||||
const rect = rectToCssPx(textarea.getBoundingClientRect(), zoom);
|
||||
const { height: vh } = cssViewportSize(zoom);
|
||||
const menuHeight = 320;
|
||||
const menuHeight = 380;
|
||||
|
||||
// 判断输入框上方空间
|
||||
const spaceAbove = rect.top;
|
||||
|
|
@ -1757,6 +1781,7 @@ const triggerMention = () => {
|
|||
};
|
||||
}
|
||||
|
||||
if (mentionSearchTimer) clearTimeout(mentionSearchTimer);
|
||||
loadMentionItems("");
|
||||
};
|
||||
|
||||
|
|
@ -1967,6 +1992,7 @@ onUnmounted(() => {
|
|||
document.removeEventListener('click', closeAgentModeSelector);
|
||||
document.removeEventListener('click', closeModelSelector);
|
||||
document.removeEventListener('click', closeMentionSelector);
|
||||
if (mentionSearchTimer) clearTimeout(mentionSearchTimer);
|
||||
if (resizeHandler) {
|
||||
window.removeEventListener('resize', resizeHandler);
|
||||
}
|
||||
|
|
@ -2402,6 +2428,10 @@ const onKeydown = (val: string, event: { e: KeyboardEvent }) => {
|
|||
mentionSelectorRef.value?.confirmActive();
|
||||
return;
|
||||
}
|
||||
if (event.e.keyCode === 9 && !event.e.shiftKey) { // Tab
|
||||
if (mentionSelectorRef.value?.enterActiveGroup()) event.e.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (event.e.keyCode === 27) { // Esc
|
||||
if (mentionSelectorRef.value?.leaveGroup()) {
|
||||
return;
|
||||
|
|
@ -3010,7 +3040,9 @@ defineExpose({
|
|||
<!-- Mention Selector -->
|
||||
<Teleport to="body">
|
||||
<MentionSelector ref="mentionSelectorRef" :visible="showMention" :style="mentionStyle" :items="mentionItems" :hasMore="mentionHasMore"
|
||||
:loading="mentionLoading" :emptyHint="mentionEmptyHint" :query="mentionQuery" :group-counts="mentionGroupCounts" v-model:activeIndex="mentionActiveIndex"
|
||||
:loading="mentionLoading" :emptyHint="mentionEmptyHint" :query="mentionQuery" :searchable="isMentionTriggeredByButton"
|
||||
:group-counts="mentionGroupCounts" v-model:activeIndex="mentionActiveIndex"
|
||||
@update:query="onMentionSearchInput" @close="closeMentionFromPopup"
|
||||
@select="onMentionSelect" @loadMore="loadMoreMentionItems" />
|
||||
</Teleport>
|
||||
|
||||
|
|
|
|||
|
|
@ -15,3 +15,24 @@ test('MCP mention hover shows catalog summary instead of a bare name', () => {
|
|||
assert.doesNotMatch(source, /detail-type-badge doc">MCP/)
|
||||
assert.doesNotMatch(source, /t-dialog/)
|
||||
})
|
||||
|
||||
test('mention menu exposes a search box that is editable only when opened from the button', () => {
|
||||
assert.match(source, /class="mention-search__input"/)
|
||||
assert.match(source, /:readonly="!searchable"/)
|
||||
assert.match(source, /emit\('update:query'/)
|
||||
assert.match(source, /emit\('close'\)/)
|
||||
})
|
||||
|
||||
test('global search caps each group and lets the user drill into the full group', () => {
|
||||
assert.match(source, /const FLAT_GROUP_LIMIT = 5/)
|
||||
assert.match(source, /mentionDetail\.viewAll/)
|
||||
assert.match(source, /enterActiveGroup/)
|
||||
// 分组内输入关键词时保持在分组内过滤,而不是跳回全局结果
|
||||
assert.match(source, /isFlatMode = computed\(\(\) => !currentGroupType\.value && trimmedQuery\.value\.length > 0\)/)
|
||||
})
|
||||
|
||||
test('mention menu follows the shared popover look of the other input selectors', () => {
|
||||
assert.match(source, /border-radius: var\(--app-radius-lg\)/)
|
||||
assert.match(source, /box-shadow: var\(--td-shadow-2\)/)
|
||||
assert.doesNotMatch(source, /label: '标签'/)
|
||||
})
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -2807,7 +2807,13 @@ export default {
|
|||
mcpStale: 'Needs resync',
|
||||
belongsToKb: 'Knowledge base: ',
|
||||
belongsToOrg: 'Space: ',
|
||||
noCompatibleKbForAgent: 'This agent\'s tools don\'t match any knowledge base\'s capabilities in scope, so nothing can be referenced.'
|
||||
noCompatibleKbForAgent: 'This agent\'s tools don\'t match any knowledge base\'s capabilities in scope, so nothing can be referenced.',
|
||||
tag: 'Tags',
|
||||
searchPlaceholder: 'Search KBs, files, skills…',
|
||||
searchInGroup: 'Search in {group}…',
|
||||
typeToSearch: "Keep typing after {'@'} to search…",
|
||||
viewAll: 'View all',
|
||||
back: 'Back'
|
||||
},
|
||||
file: {
|
||||
upload: 'Upload File'
|
||||
|
|
|
|||
|
|
@ -2807,7 +2807,13 @@ export default {
|
|||
mcpStale: '再同期が必要',
|
||||
belongsToKb: 'ナレッジベース: ',
|
||||
belongsToOrg: '共有スペース: ',
|
||||
noCompatibleKbForAgent: 'このエージェントのツールはスコープ内のナレッジベースの機能と一致しないため、参照できるナレッジベースがありません。'
|
||||
noCompatibleKbForAgent: 'このエージェントのツールはスコープ内のナレッジベースの機能と一致しないため、参照できるナレッジベースがありません。',
|
||||
tag: 'タグ',
|
||||
searchPlaceholder: 'ナレッジ・ファイル等を検索',
|
||||
searchInGroup: '{group}内を検索…',
|
||||
typeToSearch: "{'@'} の後に入力して検索…",
|
||||
viewAll: 'すべて表示',
|
||||
back: '戻る'
|
||||
},
|
||||
file: {
|
||||
upload: 'ファイルをアップロード'
|
||||
|
|
|
|||
|
|
@ -5342,7 +5342,13 @@ export default {
|
|||
mcpStale: '다시 동기화 필요',
|
||||
belongsToKb: '지식베이스: ',
|
||||
belongsToOrg: '스페이스: ',
|
||||
noCompatibleKbForAgent: '현재 에이전트의 도구와 범위 내 지식베이스의 기능이 일치하지 않아 참조할 수 있는 지식베이스가 없습니다.'
|
||||
noCompatibleKbForAgent: '현재 에이전트의 도구와 범위 내 지식베이스의 기능이 일치하지 않아 참조할 수 있는 지식베이스가 없습니다.',
|
||||
tag: '태그',
|
||||
searchPlaceholder: '지식베이스, 파일 등 검색',
|
||||
searchInGroup: '{group}에서 검색…',
|
||||
typeToSearch: "{'@'} 뒤에 계속 입력하여 검색…",
|
||||
viewAll: '모두 보기',
|
||||
back: '뒤로'
|
||||
},
|
||||
common: {
|
||||
add: '추가',
|
||||
|
|
|
|||
|
|
@ -5342,7 +5342,13 @@ export default {
|
|||
mcpStale: 'Нужна повторная синхронизация',
|
||||
belongsToKb: 'База знаний: ',
|
||||
belongsToOrg: 'Пространство: ',
|
||||
noCompatibleKbForAgent: 'Инструменты текущего агента не соответствуют возможностям ни одной базы знаний в области видимости — нечего упомянуть.'
|
||||
noCompatibleKbForAgent: 'Инструменты текущего агента не соответствуют возможностям ни одной базы знаний в области видимости — нечего упомянуть.',
|
||||
tag: 'Теги',
|
||||
searchPlaceholder: 'Поиск баз, файлов, навыков…',
|
||||
searchInGroup: 'Поиск в разделе «{group}»…',
|
||||
typeToSearch: "Продолжайте ввод после {'@'} для поиска…",
|
||||
viewAll: 'Показать все',
|
||||
back: 'Назад'
|
||||
},
|
||||
common: {
|
||||
add: 'Добавить',
|
||||
|
|
|
|||
|
|
@ -5344,7 +5344,13 @@ export default {
|
|||
mcpStale: '需重新同步',
|
||||
belongsToKb: '所属知识库:',
|
||||
belongsToOrg: '所属空间:',
|
||||
noCompatibleKbForAgent: '当前智能体的工具与作用域内知识库的能力不匹配,暂无可引用的知识库。'
|
||||
noCompatibleKbForAgent: '当前智能体的工具与作用域内知识库的能力不匹配,暂无可引用的知识库。',
|
||||
tag: '标签',
|
||||
searchPlaceholder: '搜索知识库、文件、技能等',
|
||||
searchInGroup: '在{group}中搜索…',
|
||||
typeToSearch: "在 {'@'} 后继续输入以搜索…",
|
||||
viewAll: '查看全部',
|
||||
back: '返回'
|
||||
},
|
||||
common: {
|
||||
add: '添加',
|
||||
|
|
|
|||
|
|
@ -5344,7 +5344,13 @@ export default {
|
|||
mcpStale: '需重新同步',
|
||||
belongsToKb: '所屬知識庫:',
|
||||
belongsToOrg: '所屬空間:',
|
||||
noCompatibleKbForAgent: '當前智慧代理的工具與作用域內知識庫的能力不比對,暫無可引用的知識庫。'
|
||||
noCompatibleKbForAgent: '當前智慧代理的工具與作用域內知識庫的能力不比對,暫無可引用的知識庫。',
|
||||
tag: '標籤',
|
||||
searchPlaceholder: '搜尋知識庫、檔案、技能等',
|
||||
searchInGroup: '在{group}中搜尋…',
|
||||
typeToSearch: "在 {'@'} 後繼續輸入以搜尋…",
|
||||
viewAll: '檢視全部',
|
||||
back: '返回'
|
||||
},
|
||||
common: {
|
||||
add: '新增',
|
||||
|
|
|
|||
Loading…
Reference in New Issue