feat(frontend): replace standalone search page with global command palette

Reworks search from a siloed /platform/knowledge-search page into a
universal ⌘K palette plus natural, in-context entry points.

Why the old page felt out of place:
- "Search" was an action pinned next to entity routes (knowledge base,
  agent, organization), mixing noun- and verb-level navigation items.
- Its two tabs (knowledge vs. chat messages) forced users to pick a
  mental model before they knew what they wanted.
- It was also the only way to search at all — no global shortcut, no
  context-aware entry.

What this replaces it with:
- A new ⌘K/Ctrl+K command palette (GlobalCommandPalette.vue) mounted
  once in views/platform/index.vue. Results are grouped by type
  (files, messages, knowledge bases, agents, chat titles, commands)
  so users never need to pre-filter. Debounced, identity-keyed
  selection survives async arrivals (slow KB results no longer yank
  the highlight off the user's current row). ⌘1-9 jump shortcuts are
  rendered inline on each row for discoverability.
- Sidebar gets a visible "Search" entry at the top — clicking it
  opens the palette (no route change), with a platform-aware kbd hint
  (⌘K on Mac, Ctrl K elsewhere).
- KB detail page: opening ⌘K there auto-scopes the search to the
  current KB via a removable chip (Backspace in empty input also
  clears it); no separate embedded search bar needed.
- The legacy route /platform/knowledge-search now redirects to the KB
  list with ?cmdk= set, so existing bookmarks still work.
- KnowledgeBase.vue now handles both route-query changes and a
  window event (weknora:open-knowledge) for intra-KB navigation,
  fixing the silent-no-op when the palette jumps to a chunk in the
  already-open KB.

Dropped:
- frontend/src/views/knowledge/KnowledgeSearch.vue (1163 lines).
- The exploratory SessionSearchBar mode-switching widget in the chat
  submenu; ⌘K covers its use cases without a two-mode UI.

i18n: zh-CN / en-US / ko-KR / ru-RU updated together — new
commandPalette.*, kb.*, and menu.search keys; obsolete session.search.*
and menu.knowledgeSearch removed.
This commit is contained in:
wizardchen
2026-05-06 16:20:50 +08:00
committed by lyingbug
parent 0be4572bd5
commit 2d3f32de5c
18 changed files with 2229 additions and 1197 deletions
+31 -1
View File
@@ -788,7 +788,12 @@ const handleOpenURLImportDialog = (event: CustomEvent) => {
}
};
// Auto-open document detail when navigated with ?knowledge_id=xxx
// Auto-open document detail when navigated with ?knowledge_id=xxx.
// Note: this runs both when the KB page mounts with a query param AND when a
// subsequent in-page navigation (e.g. from the global command palette) only
// changes the query without re-mounting the component — in that case kbId is
// the same and cardList may already be populated, so relying solely on the
// cardList watcher misses the trigger.
const pendingKnowledgeId = ref<string | null>(
(route.query.knowledge_id as string) || null
);
@@ -807,6 +812,29 @@ const tryAutoOpenDocument = () => {
}
};
// React to later ?knowledge_id= changes on the same KB route (no remount).
watch(
() => route.query.knowledge_id,
(newId) => {
if (typeof newId !== 'string' || !newId) return;
pendingKnowledgeId.value = newId;
// cardList is almost always already loaded at this point; if not, the
// cardList watcher below will pick it up.
tryAutoOpenDocument();
},
);
// Dispatched by the global command palette when the user picks a chunk that
// lives in the KB they are already viewing — vue-router dedupes identical
// navigations, so we rely on this event instead of a URL change.
const handleOpenKnowledgeEvent = (e: Event) => {
const detail = (e as CustomEvent<{ kbId: string; knowledgeId: string }>).detail;
if (!detail || !detail.knowledgeId) return;
if (detail.kbId && detail.kbId !== kbId.value) return;
pendingKnowledgeId.value = detail.knowledgeId;
tryAutoOpenDocument();
};
onMounted(() => {
loadKnowledgeBaseInfo(kbId.value);
loadKnowledgeList();
@@ -818,11 +846,13 @@ onMounted(() => {
window.addEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
window.addEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);
window.addEventListener('weknora:open-knowledge', handleOpenKnowledgeEvent as EventListener);
});
onUnmounted(() => {
window.removeEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
window.removeEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);
window.removeEventListener('weknora:open-knowledge', handleOpenKnowledgeEvent as EventListener);
stopMovePoll();
if (timeout !== null) {
clearTimeout(timeout);
File diff suppressed because it is too large Load Diff
+26 -2
View File
@@ -10,21 +10,27 @@
</div>
<!-- 全局设置模态框,供所有 platform 子路由使用 -->
<Settings />
<!-- 全局命令面板 (⌘K),随 platform 路由存活 -->
<GlobalCommandPalette />
</div>
</template>
<script setup lang="ts">
import Menu from '@/components/menu.vue'
import { ref, onMounted, onUnmounted, nextTick, provide } from 'vue';
import { useRoute } from 'vue-router'
import { ref, onMounted, onUnmounted, nextTick, provide, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router'
import useKnowledgeBase from '@/hooks/useKnowledgeBase'
import UploadMask from '@/components/upload-mask.vue'
import Settings from '@/views/settings/Settings.vue'
import GlobalCommandPalette from '@/components/GlobalCommandPalette.vue'
import { useCommandPaletteStore } from '@/stores/commandPalette'
import { getKnowledgeBaseById } from '@/api/knowledge-base/index'
import { MessagePlugin } from 'tdesign-vue-next'
import { useI18n } from 'vue-i18n'
let { requestMethod } = useKnowledgeBase()
const route = useRoute();
const router = useRouter();
const commandPaletteStore = useCommandPaletteStore();
let ismask = ref(false)
let uploadInput = ref();
const { t } = useI18n();
@@ -186,8 +192,26 @@ onMounted(() => {
reloadApp()
})
}
// 支持通过 URL 查询参数打开全局命令面板,例如旧路径
// /platform/knowledge-search?q=foo 重定向后携带 ?cmdk=foo
maybeOpenCmdkFromRoute()
});
// 监听路由变化,兼容 SPA 内部跳转时的 ?cmdk= 参数
watch(() => route.query.cmdk, () => {
maybeOpenCmdkFromRoute()
})
function maybeOpenCmdkFromRoute() {
if (!('cmdk' in route.query)) return
const q = String(route.query.cmdk ?? '')
commandPaletteStore.openPalette(q)
// 清除 query,避免回退/刷新时反复触发
const newQuery = { ...route.query }
delete (newQuery as any).cmdk
router.replace({ path: route.path, query: newQuery, hash: route.hash })
}
// 组件卸载时移除全局事件监听器
onUnmounted(() => {
document.removeEventListener('dragenter', handleGlobalDragEnter, true);