Browse the knowledge base from a single side panel menu
Add a read-only view of backend/knowledge_base/**.md so the files that get injected into the system prompt can be inspected from the GUI: - GET /api/kb/files lists the Markdown files (title, preview, size, mtime and whether the file is already embedded), GET /api/kb/file returns one in full. Paths are resolved against the knowledge base directory and rejected unless they stay inside it and end in .md. - KnowledgeBasePanel.vue groups the files by folder (collapsible, so web_search can be folded away), filters by title/path/preview and renders the selected file with MarkdownContent. The header had grown to four side panel toggles, so collapse them into one menu: panels.ts now holds the list of panels along with the component each one renders, App.vue picks it with <component :is>, and SidePanelMenu.vue shows the active panel on its button. Re-picking the open panel (or "パネルを閉じる") closes it; a click outside or Esc closes just the menu. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { SIDE_PANELS, type PanelId } from '../panels'
|
||||
|
||||
const props = defineProps<{ active: PanelId | null }>()
|
||||
const emit = defineEmits<{ (e: 'select', panel: PanelId | null): void }>()
|
||||
|
||||
const open = ref(false)
|
||||
const root = ref<HTMLElement | null>(null)
|
||||
|
||||
const activePanel = computed(() => SIDE_PANELS.find((p) => p.id === props.active) ?? null)
|
||||
|
||||
/** 項目を選ぶ。開いているパネルをもう一度選んだら閉じる(従来のトグルと同じ操作感)。 */
|
||||
function select(id: PanelId) {
|
||||
emit('select', props.active === id ? null : id)
|
||||
open.value = false
|
||||
}
|
||||
|
||||
function close() {
|
||||
emit('select', null)
|
||||
open.value = false
|
||||
}
|
||||
|
||||
function onDocumentPointerDown(e: PointerEvent) {
|
||||
if (open.value && !root.value?.contains(e.target as Node)) open.value = false
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape') open.value = false
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('pointerdown', onDocumentPointerDown)
|
||||
document.addEventListener('keydown', onKeydown)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('pointerdown', onDocumentPointerDown)
|
||||
document.removeEventListener('keydown', onKeydown)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="root" class="panel-menu">
|
||||
<button
|
||||
class="menu-btn"
|
||||
:class="{ active: activePanel !== null, open }"
|
||||
:title="activePanel ? `${activePanel.label}を表示中` : 'パネルを開く'"
|
||||
@click="open = !open"
|
||||
>
|
||||
<span class="menu-icon">{{ activePanel ? activePanel.icon : '☰' }}</span>
|
||||
<span class="menu-label">{{ activePanel ? activePanel.label : 'パネル' }}</span>
|
||||
<span class="caret">▾</span>
|
||||
</button>
|
||||
|
||||
<div v-if="open" class="dropdown">
|
||||
<button
|
||||
v-for="panel in SIDE_PANELS"
|
||||
:key="panel.id"
|
||||
class="item"
|
||||
:class="{ current: panel.id === active }"
|
||||
@click="select(panel.id)"
|
||||
>
|
||||
<span class="item-icon">{{ panel.icon }}</span>
|
||||
<span class="item-text">
|
||||
<span class="item-label">{{ panel.label }}</span>
|
||||
<span class="item-desc">{{ panel.description }}</span>
|
||||
</span>
|
||||
<span class="check">{{ panel.id === active ? '✓' : '' }}</span>
|
||||
</button>
|
||||
<button v-if="activePanel" class="item close-item" @click="close">
|
||||
<span class="item-icon">✕</span>
|
||||
<span class="item-text"><span class="item-label">パネルを閉じる</span></span>
|
||||
<span class="check" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.panel-menu { position: relative; }
|
||||
.menu-btn {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
background: #2a2a2a; color: #aaa; border: 1px solid #444;
|
||||
border-radius: 6px; padding: 4px 12px; font-size: 13px; cursor: pointer;
|
||||
}
|
||||
.menu-btn:hover { color: #ddd; }
|
||||
.menu-btn.active { background: #1d3557; color: #93c5fd; border-color: #2563eb; }
|
||||
.menu-btn.open { border-color: #666; }
|
||||
.menu-btn.active.open { border-color: #3b82f6; }
|
||||
.menu-icon { font-size: 13px; line-height: 1; }
|
||||
.menu-label { white-space: nowrap; }
|
||||
.caret { font-size: 9px; color: #777; }
|
||||
|
||||
.dropdown {
|
||||
position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
|
||||
min-width: 260px;
|
||||
background: #1c1c1c; border: 1px solid #3a3a3a; border-radius: 8px;
|
||||
padding: 4px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.item {
|
||||
display: flex; align-items: center; gap: 10px; width: 100%;
|
||||
background: none; border: none; border-radius: 6px;
|
||||
padding: 7px 9px; cursor: pointer; text-align: left;
|
||||
}
|
||||
.item:hover { background: #262626; }
|
||||
.item.current { background: #1d3557; }
|
||||
.item-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }
|
||||
.item-text { flex: 1; display: flex; flex-direction: column; gap: 1px; overflow: hidden; }
|
||||
.item-label { color: #ddd; font-size: 13px; }
|
||||
.item.current .item-label { color: #93c5fd; }
|
||||
.item-desc {
|
||||
color: #6b7280; font-size: 11px;
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
.check { color: #93c5fd; font-size: 11px; width: 10px; flex-shrink: 0; }
|
||||
.close-item { border-top: 1px solid #2a2a2a; border-radius: 0 0 6px 6px; margin-top: 2px; }
|
||||
.close-item .item-label { color: #888; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user