refactor(ui): Phase 7 — strip chat/voice/journal/workspace/home surfaces
Frontend deletion phase of the MCP-first pivot. All in-app
conversational surfaces are gone — Claude/MCP is the assistant now.
Deleted views:
ChatView, JournalView, WorkspaceView, HomeView
Deleted components:
ChatPanel, ChatInputBar, ChatMessage, ChatStreamingBubble,
ToolCallCard, ToolConfirmCard, WorkspaceChatWidget
Deleted composables + store:
useVoiceRecorder, useVoiceAudio, useStreamingTts, stores/chat
Router changes:
- / now redirects to /knowledge (was /journal)
- dropped /chat, /chat/:id, /journal, /workspace/:projectId
- /tasks still redirects to / (→ /knowledge)
- /notes still redirects to /knowledge
KnowledgeView:
- removed ChatPanel + ChatInputBar embeds
- removed minichat floating widget + state + handlers
- removed Chat link from today bar
- removed `chatStore` driven auto-refresh-on-tool-call watch
App.vue:
- removed useChatStore + startStatusPolling/stopStatusPolling
- removed VAD ONNX preloader (voice subsystem dead)
- removed visibilitychange listener (only did voice status re-check)
- removed `c` single-key shortcut (focus chat / goto chat)
- removed `g+c` two-key sequence (goto chat)
- removed Chat section from shortcuts overlay
- removed `.chat-page` / `.workspace-root` CSS overflow rule
AppHeader.vue:
- removed useChatStore + status indicator (Ollama model status)
- removed Chat / Journal nav links (desktop + mobile)
SettingsView.vue (4598 → 4079 lines):
- removed Voice tab entirely
- Notifications tab: dropped Push Notifications + Chat History
+ About sections (kept Email Notifications)
- General tab: dropped Assistant (name + model pickers) +
Model Management sections (kept Tasks + Timezone)
- Profile tab: dropped Journal + Observations sections
- VALID_TABS + tab list array no longer include "voice"
- removed `loadVoiceTab()` activation trigger
Service worker (frontend/public/sw.js):
- dropped push and notificationclick handlers (push subsystem
only fired on internal generation completion, which is gone)
- kept empty fetch handler as PWA installability shell
Script-level dead code (state refs, helper functions referencing
removed APIs) remains in SettingsView and stores/push.ts and
stores/settings.ts for now — Phase 8 backend deletion will clean
those up alongside the matching backend route removals.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+8
-42
@@ -1,45 +1,11 @@
|
||||
// Service Worker for push notifications and PWA support
|
||||
self.addEventListener('push', event => {
|
||||
if (!event.data) return;
|
||||
const data = event.data.json();
|
||||
const notifUrl = data.url || '/';
|
||||
// Service Worker — PWA installability shell only.
|
||||
//
|
||||
// The push and notificationclick listeners were removed alongside the chat
|
||||
// generation pipeline (they only fired when the internal LLM finished a
|
||||
// response). The empty fetch handler is preserved as the installability
|
||||
// surface required for "Add to Home Screen" in some browsers; offline
|
||||
// caching is intentionally not implemented yet.
|
||||
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(clientList => {
|
||||
// Suppress notification if the user already has the relevant page focused
|
||||
for (const client of clientList) {
|
||||
if (client.visibilityState === 'visible' && client.url.includes(notifUrl)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return self.registration.showNotification(data.title || 'Scribe', {
|
||||
body: data.body || '',
|
||||
icon: '/favicon.ico',
|
||||
badge: '/favicon.ico',
|
||||
data: { url: notifUrl },
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', event => {
|
||||
event.notification.close();
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(clientList => {
|
||||
const url = event.notification.data.url;
|
||||
for (const client of clientList) {
|
||||
if (client.url.includes(url) && 'focus' in client) {
|
||||
return client.focus();
|
||||
}
|
||||
}
|
||||
if (clients.openWindow) {
|
||||
return clients.openWindow(url);
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// PWA: serve cached assets for offline support (minimal)
|
||||
self.addEventListener('fetch', event => {
|
||||
self.addEventListener('fetch', () => {
|
||||
// Pass-through — no offline caching in v1
|
||||
});
|
||||
|
||||
+1
-52
@@ -5,43 +5,26 @@ import AppHeader from "@/components/AppHeader.vue";
|
||||
import ToastNotification from "@/components/ToastNotification.vue";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { useShortcuts } from "@/composables/useShortcuts";
|
||||
import { useOnnxPreloader } from "@/composables/useOnnxPreloader";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useChatStore } from "@/stores/chat";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import { apiGet, apiPut } from "@/api/client";
|
||||
|
||||
useTheme();
|
||||
|
||||
const { schedulePreload: scheduleVadPreload } = useOnnxPreloader();
|
||||
scheduleVadPreload();
|
||||
|
||||
const router = useRouter();
|
||||
const appVersion = ref("dev");
|
||||
const authStore = useAuthStore();
|
||||
const chatStore = useChatStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const { showShortcuts, toggleShortcuts, closeShortcuts } = useShortcuts();
|
||||
|
||||
function startAppServices() {
|
||||
chatStore.startStatusPolling();
|
||||
settingsStore.fetchSettings();
|
||||
settingsStore.checkVoiceStatus();
|
||||
// Sync browser timezone to the server on every login/page load.
|
||||
apiPut("/api/settings", { user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone }).catch(() => {});
|
||||
// Re-check voice status when the tab becomes visible again (model may
|
||||
// have finished loading while the user was away).
|
||||
document.addEventListener("visibilitychange", onVisibilityChange);
|
||||
}
|
||||
|
||||
function onVisibilityChange() {
|
||||
if (document.visibilityState === "visible" && authStore.isAuthenticated) {
|
||||
settingsStore.checkVoiceStatus();
|
||||
}
|
||||
}
|
||||
|
||||
function stopAppServices() {
|
||||
chatStore.stopStatusPolling();
|
||||
// no-op for now; kept as a hook for future per-session teardown
|
||||
}
|
||||
|
||||
function isInputActive(): boolean {
|
||||
@@ -96,7 +79,6 @@ function onGlobalKeydown(e: KeyboardEvent) {
|
||||
case "n": router.push("/notes"); break;
|
||||
case "t": router.push("/"); break;
|
||||
case "p": router.push("/projects"); break;
|
||||
case "c": router.push("/chat"); break;
|
||||
case "g": router.push("/graph"); break;
|
||||
case "l": router.push("/calendar"); break;
|
||||
}
|
||||
@@ -126,13 +108,6 @@ function onGlobalKeydown(e: KeyboardEvent) {
|
||||
e.preventDefault();
|
||||
document.dispatchEvent(new CustomEvent("shortcut:focus-search"));
|
||||
break;
|
||||
case "c":
|
||||
if (router.currentRoute.value.name === "home") {
|
||||
document.dispatchEvent(new CustomEvent("shortcut:focus-chat"));
|
||||
} else {
|
||||
router.push("/chat");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +138,6 @@ watch(
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener("keydown", onGlobalKeydown);
|
||||
document.removeEventListener("visibilitychange", onVisibilityChange);
|
||||
stopAppServices();
|
||||
});
|
||||
</script>
|
||||
@@ -214,12 +188,6 @@ onUnmounted(() => {
|
||||
<kbd class="shortcut-key">p</kbd>
|
||||
<span class="shortcut-desc">Projects</span>
|
||||
</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd class="shortcut-key">g</kbd>
|
||||
<span class="shortcut-key-sep">+</span>
|
||||
<kbd class="shortcut-key">c</kbd>
|
||||
<span class="shortcut-desc">Chat</span>
|
||||
</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd class="shortcut-key">g</kbd>
|
||||
<span class="shortcut-key-sep">+</span>
|
||||
@@ -267,23 +235,6 @@ onUnmounted(() => {
|
||||
<span class="shortcut-desc">Edit current item (viewer)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shortcuts-section">
|
||||
<div class="shortcuts-section-title">Chat</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd class="shortcut-key">c</kbd>
|
||||
<span class="shortcut-desc">Focus chat (home) / go to chat</span>
|
||||
</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd class="shortcut-key">Enter</kbd>
|
||||
<span class="shortcut-desc">Send message</span>
|
||||
</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd class="shortcut-key">Shift</kbd>
|
||||
<span class="shortcut-key-sep">+</span>
|
||||
<kbd class="shortcut-key">Enter</kbd>
|
||||
<span class="shortcut-desc">New line</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -328,8 +279,6 @@ onUnmounted(() => {
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.app-content:has(.workspace-root),
|
||||
.app-content:has(.chat-page),
|
||||
.app-content:has(.knowledge-root) {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import { useRouter, useRoute } from "vue-router";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { useShortcuts } from "@/composables/useShortcuts";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useChatStore } from "@/stores/chat";
|
||||
import AppLogo from "@/components/AppLogo.vue";
|
||||
import NotificationBell from "@/components/NotificationBell.vue";
|
||||
import { Sun, Moon, Settings } from "lucide-vue-next";
|
||||
@@ -12,42 +11,13 @@ import { Sun, Moon, Settings } from "lucide-vue-next";
|
||||
const { theme, toggleTheme } = useTheme();
|
||||
const { toggleShortcuts } = useShortcuts();
|
||||
const authStore = useAuthStore();
|
||||
const chatStore = useChatStore();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
const isChatActive = computed(() => route.path.startsWith("/chat"))
|
||||
const isKnowledgeActive = computed(() => route.path === "/knowledge");
|
||||
|
||||
const mobileMenuOpen = ref(false);
|
||||
|
||||
const statusShortLabel = computed(() => {
|
||||
if (chatStore.ollamaStatus === "unavailable") return "Offline";
|
||||
if (chatStore.ollamaStatus === "checking") return "Checking";
|
||||
if (chatStore.modelStatus === "not_found") return "No model";
|
||||
if (chatStore.modelStatus === "cold") return "Cold";
|
||||
if (chatStore.modelStatus === "loaded") return "Ready";
|
||||
return "Checking";
|
||||
});
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
if (chatStore.ollamaStatus === "unavailable") return "Ollama unavailable";
|
||||
if (chatStore.ollamaStatus === "checking") return "Checking...";
|
||||
if (chatStore.modelStatus === "not_found") return "Model not installed";
|
||||
if (chatStore.modelStatus === "cold") return "Model cold — first response may be slow";
|
||||
if (chatStore.modelStatus === "loaded") return "Model loaded · ready";
|
||||
return "Checking...";
|
||||
});
|
||||
|
||||
const statusClass = computed(() => {
|
||||
if (chatStore.ollamaStatus === "unavailable") return "status-red";
|
||||
if (chatStore.ollamaStatus === "checking") return "status-gray";
|
||||
if (chatStore.modelStatus === "not_found") return "status-orange";
|
||||
if (chatStore.modelStatus === "cold") return "status-yellow";
|
||||
if (chatStore.modelStatus === "loaded") return "status-green";
|
||||
return "status-gray";
|
||||
});
|
||||
|
||||
function toggleMobileMenu() {
|
||||
mobileMenuOpen.value = !mobileMenuOpen.value;
|
||||
}
|
||||
@@ -76,20 +46,13 @@ router.afterEach(() => {
|
||||
<div class="nav-center">
|
||||
<div class="nav-pill-bar">
|
||||
<router-link to="/knowledge" class="nav-link" :class="{ 'router-link-active': isKnowledgeActive }">Knowledge</router-link>
|
||||
<router-link to="/chat" :class="['nav-link', { 'router-link-active': isChatActive }]">Chat</router-link>
|
||||
<router-link to="/journal" class="nav-link">Journal</router-link>
|
||||
<router-link to="/calendar" class="nav-link">Calendar</router-link>
|
||||
<router-link to="/projects" class="nav-link">Projects</router-link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: status + utilities + gear + user -->
|
||||
<!-- Right: utilities + gear + user -->
|
||||
<div class="nav-right">
|
||||
<span class="status-indicator" :class="statusClass" :title="statusLabel">
|
||||
<span class="status-dot"></span>
|
||||
<span class="status-text">{{ statusShortLabel }}</span>
|
||||
</span>
|
||||
|
||||
<NotificationBell />
|
||||
|
||||
<button class="btn-icon" @click="toggleShortcuts" title="Keyboard shortcuts (?)">?</button>
|
||||
@@ -122,8 +85,6 @@ router.afterEach(() => {
|
||||
<!-- Mobile dropdown -->
|
||||
<div v-if="mobileMenuOpen" class="mobile-menu">
|
||||
<router-link to="/knowledge" class="nav-link" :class="{ 'router-link-active': isKnowledgeActive }">Knowledge</router-link>
|
||||
<router-link to="/chat" :class="['nav-link', { 'router-link-active': isChatActive }]">Chat</router-link>
|
||||
<router-link to="/journal" class="nav-link">Journal</router-link>
|
||||
<router-link to="/calendar" class="nav-link">Calendar</router-link>
|
||||
<router-link to="/projects" class="nav-link">Projects</router-link>
|
||||
<router-link to="/shared" class="nav-link">Shared</router-link>
|
||||
@@ -131,10 +92,6 @@ router.afterEach(() => {
|
||||
<router-link to="/settings" class="nav-link">Settings</router-link>
|
||||
<div class="mobile-divider"></div>
|
||||
<div class="mobile-actions">
|
||||
<span class="status-indicator" :class="statusClass" :title="statusLabel">
|
||||
<span class="status-dot"></span>
|
||||
<span class="status-text">{{ statusShortLabel }}</span>
|
||||
</span>
|
||||
<button class="btn-icon" @click="toggleShortcuts">?</button>
|
||||
<button class="btn-icon" @click="toggleTheme"><Sun v-if="theme === 'dark'" :size="16" />
|
||||
<Moon v-else :size="16" /></button>
|
||||
|
||||
@@ -1,668 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, nextTick, onMounted, onUnmounted, watch } from 'vue'
|
||||
import { apiGet, transcribeAudio } from '@/api/client'
|
||||
import { useVoiceRecorder } from '@/composables/useVoiceRecorder'
|
||||
import { useVad } from '@/composables/useVad'
|
||||
import { useStreamingTts } from '@/composables/useStreamingTts'
|
||||
import { useVoiceAudio, setVoiceVolume } from '@/composables/useVoiceAudio'
|
||||
import { useListenMode } from '@/composables/useListenMode'
|
||||
import { useChatStore } from '@/stores/chat'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
import type { Note } from '@/types/note'
|
||||
import {
|
||||
Paperclip,
|
||||
Volume2,
|
||||
VolumeX,
|
||||
Square,
|
||||
Mic,
|
||||
Loader2,
|
||||
ArrowUp,
|
||||
} from 'lucide-vue-next'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** Textarea placeholder */
|
||||
placeholder?: string
|
||||
/** When true, hides the note picker (briefing mode) */
|
||||
briefingMode?: boolean
|
||||
/** Pill shape — compact rounded style for widget */
|
||||
pill?: boolean
|
||||
}>(), {
|
||||
placeholder: 'Type a message… (Enter to send, Shift+Enter for new line)',
|
||||
briefingMode: false,
|
||||
pill: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
submit: [payload: { content: string; contextNoteId?: number }]
|
||||
abort: []
|
||||
}>()
|
||||
|
||||
const store = useChatStore()
|
||||
const settingsStore = useSettingsStore()
|
||||
const voiceEnabled = computed(() => settingsStore.voiceSttReady)
|
||||
const voiceTtsEnabled = computed(() => settingsStore.voiceTtsReady)
|
||||
|
||||
// ── Streaming TTS (listen mode) ───────────────────────────────────────────────
|
||||
const listenMode = useListenMode()
|
||||
const audio = useVoiceAudio()
|
||||
const speakerPopoverOpen = ref(false)
|
||||
|
||||
const tts = useStreamingTts({
|
||||
streamingContent: computed(() => store.streamingContent),
|
||||
streaming: computed(() => store.streaming),
|
||||
enabled: computed(() => listenMode.value && voiceTtsEnabled.value),
|
||||
})
|
||||
|
||||
function lastAssistantContent(): string {
|
||||
const msgs = store.currentConversation?.messages ?? []
|
||||
return [...msgs].reverse().find((m) => m.role === 'assistant')?.content ?? ''
|
||||
}
|
||||
|
||||
function toggleListen() {
|
||||
listenMode.value = !listenMode.value
|
||||
if (listenMode.value) {
|
||||
tts.speak(lastAssistantContent())
|
||||
} else {
|
||||
tts.stop()
|
||||
}
|
||||
}
|
||||
|
||||
// ── Core input ────────────────────────────────────────────────────────────────
|
||||
const messageInput = ref('')
|
||||
const inputEl = ref<HTMLTextAreaElement | null>(null)
|
||||
const wrapperEl = ref<HTMLElement | null>(null)
|
||||
|
||||
function autoResize() {
|
||||
const el = inputEl.value
|
||||
if (!el) return
|
||||
el.style.height = 'auto'
|
||||
el.style.height = Math.min(el.scrollHeight, 150) + 'px'
|
||||
}
|
||||
|
||||
function resetTextareaHeight() {
|
||||
const el = inputEl.value
|
||||
if (!el) return
|
||||
el.style.height = 'auto'
|
||||
}
|
||||
|
||||
function onInputKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault()
|
||||
onSubmit()
|
||||
}
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
const content = messageInput.value.trim()
|
||||
if (!content) return
|
||||
emit('submit', { content, contextNoteId: attachedNote.value?.id })
|
||||
messageInput.value = ''
|
||||
attachedNote.value = null
|
||||
resetTextareaHeight()
|
||||
}
|
||||
|
||||
// ── Note picker ───────────────────────────────────────────────────────────────
|
||||
const attachedNote = ref<{ id: number; title: string } | null>(null)
|
||||
const showNotePicker = ref(false)
|
||||
const noteSearchQuery = ref('')
|
||||
const noteSearchResults = ref<{ id: number; title: string }[]>([])
|
||||
const noteSearchLoading = ref(false)
|
||||
let noteSearchTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
function toggleNotePicker() {
|
||||
showNotePicker.value = !showNotePicker.value
|
||||
if (showNotePicker.value) {
|
||||
noteSearchQuery.value = ''
|
||||
noteSearchResults.value = []
|
||||
nextTick(() => {
|
||||
(wrapperEl.value?.querySelector('.note-picker-search') as HTMLInputElement)?.focus()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function onNoteSearchInput() {
|
||||
if (noteSearchTimer) clearTimeout(noteSearchTimer)
|
||||
noteSearchTimer = setTimeout(async () => {
|
||||
const q = noteSearchQuery.value.trim()
|
||||
if (!q) { noteSearchResults.value = []; return }
|
||||
noteSearchLoading.value = true
|
||||
try {
|
||||
const data = await apiGet<{ notes: Note[] }>(`/api/notes?q=${encodeURIComponent(q)}&all=true&limit=5`)
|
||||
noteSearchResults.value = data.notes.map((n) => ({ id: n.id, title: n.title }))
|
||||
} catch {
|
||||
noteSearchResults.value = []
|
||||
} finally {
|
||||
noteSearchLoading.value = false
|
||||
}
|
||||
}, 250)
|
||||
}
|
||||
|
||||
function selectNote(note: { id: number; title: string }) {
|
||||
attachedNote.value = note
|
||||
showNotePicker.value = false
|
||||
}
|
||||
|
||||
function removeAttachedNote() {
|
||||
attachedNote.value = null
|
||||
}
|
||||
|
||||
// ── Voice (click-to-toggle + VAD speech detection) ─────────────────────────
|
||||
const transcribingVoice = ref(false)
|
||||
const recorder = useVoiceRecorder()
|
||||
// Tracks whether VAD detected speech during the current recording session.
|
||||
// Used to skip the Whisper round-trip when the user manually stops without
|
||||
// ever speaking — the recording is ambient noise and will transcribe to "".
|
||||
const vadSawSpeech = ref(false)
|
||||
|
||||
const vad = useVad({
|
||||
onSpeechEnd: () => {
|
||||
// VAD auto-stop: speech was detected and the user has paused. Proceed
|
||||
// to transcribe the MediaRecorder output.
|
||||
void stopRecording(false)
|
||||
},
|
||||
onNoSpeech: () => {
|
||||
useToastStore().show('No speech detected', 'warning')
|
||||
},
|
||||
onVadError: (msg) => {
|
||||
useToastStore().show(`VAD failed: ${msg}`, 'error')
|
||||
},
|
||||
})
|
||||
|
||||
// Live mic halo. A solid red disc sits behind the mic button and scales
|
||||
// with `vad.amplitude` (0..1 RMS, already amplified for visibility).
|
||||
const micGlowStyle = computed(() => {
|
||||
if (!recorder.recording.value) return { display: 'none' }
|
||||
const pulse = 0.2 + Math.min(vad.amplitude.value, 1) * 0.8
|
||||
return {
|
||||
transform: `translate(-50%, -50%) scale(${1 + pulse * 1.6})`,
|
||||
opacity: String(0.45 + pulse * 0.4),
|
||||
}
|
||||
})
|
||||
|
||||
// vad.speaking flips true on speech-start. Watch it once per session to
|
||||
// capture that speech was detected at some point, without clearing when
|
||||
// speech ends. This drives the no-speech guard in stopRecording.
|
||||
watch(() => vad.speaking.value, (on) => {
|
||||
if (on) vadSawSpeech.value = true
|
||||
})
|
||||
|
||||
async function toggleVoice() {
|
||||
if (transcribingVoice.value) return
|
||||
if (recorder.recording.value) {
|
||||
await stopRecording(true)
|
||||
} else {
|
||||
await startRecording()
|
||||
}
|
||||
}
|
||||
|
||||
async function startRecording() {
|
||||
if (!voiceEnabled.value || recorder.recording.value) return
|
||||
if (!recorder.isSupported) {
|
||||
useToastStore().show('Microphone requires HTTPS or localhost', 'error')
|
||||
return
|
||||
}
|
||||
vadSawSpeech.value = false
|
||||
await recorder.startRecording()
|
||||
if (recorder.error.value) {
|
||||
useToastStore().show(recorder.error.value, 'error')
|
||||
return
|
||||
}
|
||||
if (recorder.stream.value) {
|
||||
await vad.start(recorder.stream.value)
|
||||
}
|
||||
}
|
||||
|
||||
async function stopRecording(manual: boolean) {
|
||||
if (manual) {
|
||||
await vad.stopAndCheck()
|
||||
} else {
|
||||
await vad.stop()
|
||||
}
|
||||
if (!recorder.recording.value) return
|
||||
transcribingVoice.value = true
|
||||
try {
|
||||
const blob = await recorder.stopRecording()
|
||||
// No-speech guard: user manually stopped without VAD seeing speech.
|
||||
// Skip Whisper — the toast was already shown by onNoSpeech.
|
||||
if (manual && !vadSawSpeech.value) {
|
||||
return
|
||||
}
|
||||
// Pass last assistant message as context to reduce STT mishearings
|
||||
const msgs = store.currentConversation?.messages ?? []
|
||||
const lastAssistant = [...msgs].reverse().find(m => m.role === 'assistant')?.content
|
||||
const { transcript } = await transcribeAudio(blob, lastAssistant)
|
||||
if (transcript.trim()) {
|
||||
messageInput.value = transcript.trim()
|
||||
await nextTick()
|
||||
autoResize()
|
||||
onSubmit()
|
||||
}
|
||||
} catch { /* transcription failed silently */ }
|
||||
finally { transcribingVoice.value = false }
|
||||
}
|
||||
|
||||
// ── Click-outside to dismiss speaker popover ──────────────────────────────────
|
||||
function onDocumentMousedown(e: MouseEvent) {
|
||||
if (!speakerPopoverOpen.value) return
|
||||
const target = e.target as HTMLElement | null
|
||||
if (!target?.closest('.speaker-wrapper')) speakerPopoverOpen.value = false
|
||||
}
|
||||
onMounted(() => document.addEventListener('mousedown', onDocumentMousedown))
|
||||
onUnmounted(() => document.removeEventListener('mousedown', onDocumentMousedown))
|
||||
|
||||
// ── Exposed interface ─────────────────────────────────────────────────────────
|
||||
function focus() {
|
||||
inputEl.value?.focus()
|
||||
}
|
||||
|
||||
function prefill(text: string) {
|
||||
messageInput.value = text
|
||||
nextTick(() => {
|
||||
autoResize()
|
||||
inputEl.value?.focus()
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({ focus, prefill })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="wrapperEl" class="chat-input-bar" :class="{ 'chat-input-bar--pill': pill }">
|
||||
<!-- Attached note pill -->
|
||||
<div v-if="attachedNote" class="attached-note">
|
||||
<span class="attached-note-pill">
|
||||
{{ attachedNote.title }}
|
||||
<button class="attached-note-remove" aria-label="Remove" @click="removeAttachedNote">×</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="input-row">
|
||||
<!-- Note picker -->
|
||||
<div class="note-picker-wrapper">
|
||||
<button
|
||||
class="btn-icon"
|
||||
@click="toggleNotePicker"
|
||||
:disabled="!store.chatReady"
|
||||
title="Attach a note"
|
||||
>
|
||||
<Paperclip :size="16" />
|
||||
</button>
|
||||
<div v-if="showNotePicker" class="note-picker-dropdown">
|
||||
<input
|
||||
class="note-picker-search"
|
||||
v-model="noteSearchQuery"
|
||||
@input="onNoteSearchInput"
|
||||
placeholder="Search notes..."
|
||||
/>
|
||||
<div class="note-picker-results">
|
||||
<div
|
||||
v-for="note in noteSearchResults"
|
||||
:key="note.id"
|
||||
class="note-picker-item"
|
||||
@click="selectNote(note)"
|
||||
>{{ note.title || 'Untitled' }}</div>
|
||||
<div v-if="noteSearchLoading" class="note-picker-empty">Searching...</div>
|
||||
<div v-else-if="noteSearchQuery && !noteSearchResults.length" class="note-picker-empty">No notes found</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Textarea -->
|
||||
<textarea
|
||||
ref="inputEl"
|
||||
v-model="messageInput"
|
||||
@keydown="onInputKeydown"
|
||||
@input="autoResize"
|
||||
:placeholder="!store.chatReady ? 'Chat unavailable' : store.streaming ? 'Type to queue… (Enter to queue)' : placeholder"
|
||||
:disabled="!store.chatReady"
|
||||
rows="1"
|
||||
class="input-textarea"
|
||||
></textarea>
|
||||
|
||||
<!-- Speaker / listen-mode popover -->
|
||||
<div v-if="voiceTtsEnabled" class="speaker-wrapper">
|
||||
<button
|
||||
class="btn-icon btn-speaker"
|
||||
:class="{ 'speaker-active': listenMode, 'speaker-busy': tts.speaking.value }"
|
||||
@click="speakerPopoverOpen = !speakerPopoverOpen"
|
||||
:title="listenMode ? 'Listen mode on' : 'Listen / volume'"
|
||||
aria-label="Listen and volume settings"
|
||||
>
|
||||
<Volume2 v-if="!tts.speaking.value" :size="16" />
|
||||
<VolumeX v-else :size="16" />
|
||||
</button>
|
||||
<div v-if="speakerPopoverOpen" class="speaker-popover">
|
||||
<button
|
||||
class="speaker-row speaker-row--toggle"
|
||||
:class="{ 'speaker-row--active': listenMode }"
|
||||
@click="toggleListen"
|
||||
>
|
||||
<span class="speaker-row-label">{{ listenMode ? 'Listening' : 'Read aloud' }}</span>
|
||||
<span class="speaker-switch" :class="{ on: listenMode }"></span>
|
||||
</button>
|
||||
<div class="speaker-row">
|
||||
<span class="speaker-row-label">Volume</span>
|
||||
<input
|
||||
type="range" min="0" max="1" step="0.05"
|
||||
:value="audio.volume.value"
|
||||
@input="setVoiceVolume(+($event.target as HTMLInputElement).value)"
|
||||
class="speaker-volume-range"
|
||||
aria-label="Volume"
|
||||
/>
|
||||
<span class="speaker-volume-pct">{{ Math.round(audio.volume.value * 100) }}%</span>
|
||||
</div>
|
||||
<button
|
||||
v-if="tts.speaking.value"
|
||||
class="speaker-row speaker-row--stop"
|
||||
@click="tts.stop()"
|
||||
>
|
||||
<Square :size="16" fill="currentColor" />
|
||||
<span>Stop playback</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PTT mic (with live amplitude halo behind) -->
|
||||
<div v-if="voiceEnabled" class="mic-wrapper">
|
||||
<div class="mic-glow" :style="micGlowStyle" aria-hidden="true"></div>
|
||||
<button
|
||||
class="btn-icon btn-mic"
|
||||
:class="{ 'mic-recording': recorder.recording.value, 'mic-transcribing': transcribingVoice }"
|
||||
@click.prevent="toggleVoice"
|
||||
:disabled="transcribingVoice || !store.chatReady"
|
||||
:title="recorder.recording.value ? 'Click to stop (or wait for silence)' : 'Click to speak'"
|
||||
:aria-label="recorder.recording.value ? 'Stop recording' : 'Start recording'"
|
||||
>
|
||||
<Mic v-if="!transcribingVoice" :size="16" />
|
||||
<Loader2 v-else :size="16" class="mic-loader" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Abort (streaming) or Send -->
|
||||
<button
|
||||
v-if="store.streaming"
|
||||
class="btn-abort-inline"
|
||||
@click="emit('abort')"
|
||||
title="Stop generation"
|
||||
>
|
||||
<Square :size="16" fill="currentColor" />
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
class="btn-send"
|
||||
@click="onSubmit"
|
||||
:disabled="!messageInput.trim() || !store.chatReady"
|
||||
><ArrowUp :size="16" /></button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.chat-input-bar {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.attached-note {
|
||||
padding: 0.25rem 0.5rem;
|
||||
}
|
||||
.attached-note-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.2rem;
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
border-radius: 10px;
|
||||
padding: 0.15rem 0.4rem;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
.attached-note-remove {
|
||||
background: none;
|
||||
border: none;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1;
|
||||
padding: 0 0.1rem;
|
||||
}
|
||||
.attached-note-remove:hover { color: #fff; }
|
||||
|
||||
.input-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
padding: 0.5rem 0.5rem 0.5rem 0.75rem;
|
||||
background: var(--color-input-bar-bg);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px var(--color-shadow);
|
||||
}
|
||||
|
||||
.chat-input-bar--pill .input-row {
|
||||
border-radius: 24px;
|
||||
padding: 0.6rem 0.6rem 0.6rem 1rem;
|
||||
}
|
||||
|
||||
.input-textarea {
|
||||
flex: 1;
|
||||
resize: none;
|
||||
padding: 0.35rem 0.5rem;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--color-input-bar-text);
|
||||
outline: none;
|
||||
font-family: inherit;
|
||||
font-size: 0.9rem;
|
||||
max-height: 150px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.input-textarea::placeholder { color: var(--color-input-bar-placeholder); }
|
||||
.input-textarea:disabled { opacity: 0.5; }
|
||||
|
||||
.btn-icon {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
color: var(--color-input-bar-text);
|
||||
opacity: 0.6;
|
||||
padding: 0.2rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: var(--radius-sm);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.btn-icon:hover { opacity: 1; }
|
||||
.btn-icon:disabled { opacity: 0.3; cursor: default; }
|
||||
|
||||
.btn-mic.mic-recording {
|
||||
opacity: 1;
|
||||
/* White icon sits on top of the red halo so it stays legible at any
|
||||
pulse size. */
|
||||
color: #fff;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
.btn-mic.mic-transcribing { opacity: 0.5; }
|
||||
.mic-loader { animation: mic-spin 1s linear infinite; }
|
||||
@keyframes mic-spin { to { transform: rotate(360deg); } }
|
||||
|
||||
/* Mic wrapper + live amplitude halo. The glow is a filled red disc
|
||||
absolutely positioned behind the button, scaled/faded by the
|
||||
computed `micGlowStyle` so the user gets unmistakable feedback
|
||||
that their voice is being picked up while the mic icon itself
|
||||
stays put and readable on top. */
|
||||
.mic-wrapper {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.mic-glow {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(
|
||||
circle,
|
||||
rgba(239, 68, 68, 0.9) 0%,
|
||||
rgba(239, 68, 68, 0.6) 55%,
|
||||
rgba(239, 68, 68, 0) 100%
|
||||
);
|
||||
transform: translate(-50%, -50%) scale(1);
|
||||
transform-origin: center;
|
||||
pointer-events: none;
|
||||
/* Smooth between amplitude samples (~100ms) so the pulse feels continuous
|
||||
rather than stepping. */
|
||||
transition: transform 0.12s ease-out, opacity 0.12s ease-out;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.note-picker-wrapper { position: relative; }
|
||||
.note-picker-dropdown {
|
||||
position: absolute;
|
||||
bottom: calc(100% + 8px);
|
||||
left: 0;
|
||||
width: 260px;
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
box-shadow: 0 4px 16px var(--color-shadow);
|
||||
z-index: 20;
|
||||
overflow: hidden;
|
||||
}
|
||||
.note-picker-search {
|
||||
width: 100%;
|
||||
padding: 0.45rem 0.65rem;
|
||||
border: none;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
background: transparent;
|
||||
color: var(--color-text);
|
||||
font-size: 0.85rem;
|
||||
outline: none;
|
||||
font-family: inherit;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.note-picker-results { max-height: 180px; overflow-y: auto; }
|
||||
.note-picker-item {
|
||||
padding: 0.4rem 0.65rem;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.note-picker-item:hover { background: var(--color-bg-secondary); }
|
||||
.note-picker-empty { padding: 0.4rem 0.65rem; color: var(--color-text-muted); font-size: 0.8rem; }
|
||||
|
||||
.btn-send {
|
||||
width: 30px;
|
||||
min-width: 30px;
|
||||
height: 30px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--gradient-cta);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
flex-shrink: 0;
|
||||
transition: box-shadow 0.15s;
|
||||
}
|
||||
.btn-send:hover { box-shadow: 0 0 16px rgba(91, 74, 138, 0.35); }
|
||||
.btn-send:disabled { opacity: 0.35; cursor: default; box-shadow: none; }
|
||||
|
||||
.btn-abort-inline {
|
||||
width: 28px;
|
||||
min-width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--color-bg-secondary);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.btn-abort-inline:hover { border-color: #ef4444; color: #ef4444; }
|
||||
|
||||
/* Speaker / listen-mode popover */
|
||||
.speaker-wrapper { position: relative; display: inline-flex; flex-shrink: 0; }
|
||||
.btn-speaker.speaker-active { opacity: 1; color: var(--color-primary); }
|
||||
.btn-speaker.speaker-busy { opacity: 1; color: #f59e0b; }
|
||||
.speaker-popover {
|
||||
position: absolute;
|
||||
bottom: calc(100% + 8px);
|
||||
right: 0;
|
||||
min-width: 220px;
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
box-shadow: 0 4px 16px var(--color-shadow);
|
||||
padding: 0.35rem;
|
||||
z-index: 30;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.speaker-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
padding: 0.45rem 0.6rem;
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--color-text);
|
||||
font-size: 0.85rem;
|
||||
cursor: default;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
}
|
||||
.speaker-row--toggle { cursor: pointer; }
|
||||
.speaker-row--toggle:hover { background: var(--color-bg-secondary); }
|
||||
.speaker-row--active { color: var(--color-primary); }
|
||||
.speaker-row--stop {
|
||||
cursor: pointer;
|
||||
color: var(--color-text-muted);
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.speaker-row--stop:hover { color: #ef4444; background: var(--color-bg-secondary); }
|
||||
.speaker-row-label { flex: 1; }
|
||||
.speaker-volume-range { flex: 1; min-width: 0; }
|
||||
.speaker-volume-pct {
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-muted);
|
||||
min-width: 2.5rem;
|
||||
text-align: right;
|
||||
}
|
||||
.speaker-switch {
|
||||
position: relative;
|
||||
width: 28px;
|
||||
height: 16px;
|
||||
border-radius: 9999px;
|
||||
background: var(--color-border);
|
||||
transition: background 0.15s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.speaker-switch::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-bg-card);
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
.speaker-switch.on { background: var(--color-primary); }
|
||||
.speaker-switch.on::after { transform: translateX(12px); }
|
||||
</style>
|
||||
@@ -1,300 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { renderMarkdown } from "@/utils/markdown";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import ToolCallCard from "@/components/ToolCallCard.vue";
|
||||
import type { Message } from "@/types/chat";
|
||||
|
||||
const settingsStore = useSettingsStore();
|
||||
|
||||
const props = defineProps<{
|
||||
message: Message;
|
||||
isStreaming?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
saveAsNote: [messageId: number];
|
||||
}>();
|
||||
|
||||
const rendered = computed(() => renderMarkdown(props.message.content));
|
||||
|
||||
const formattedTime = computed(() => {
|
||||
if (!props.message.created_at) return "";
|
||||
const date = new Date(props.message.created_at);
|
||||
return date.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
|
||||
});
|
||||
|
||||
const roleLabel = computed(() => {
|
||||
switch (props.message.role) {
|
||||
case "user":
|
||||
return "You";
|
||||
case "assistant":
|
||||
return settingsStore.assistantName;
|
||||
default:
|
||||
return props.message.role;
|
||||
}
|
||||
});
|
||||
|
||||
function formatMs(ms: number | null | undefined): string {
|
||||
if (ms == null) return "";
|
||||
if (ms < 1000) return `${ms}ms`;
|
||||
return `${(ms / 1000).toFixed(1)}s`;
|
||||
}
|
||||
|
||||
const metadata = computed(() => (props.message.metadata ?? {}) as Record<string, unknown>);
|
||||
|
||||
// Hide LEGACY system-role daily_prep messages from earlier versions. The
|
||||
// current journal prep is a normal assistant message (renders with proper
|
||||
// bubble styling). Old system-role rows lurking in existing conversations
|
||||
// would render as a flat unstyled block — filter them.
|
||||
const hideMessage = computed(() =>
|
||||
props.message.role === "system" && metadata.value.kind === "daily_prep"
|
||||
);
|
||||
|
||||
const timingParts = computed((): string[] => {
|
||||
const t = props.message.timing;
|
||||
if (!t) return [];
|
||||
const parts: string[] = [];
|
||||
if (t.total_ms != null) parts.push(`${formatMs(t.total_ms)} total`);
|
||||
if (t.ttft_ms != null) parts.push(`first token ${formatMs(t.ttft_ms)}`);
|
||||
if (t.intent_ms != null) parts.push(`analyzed ${formatMs(t.intent_ms)}`);
|
||||
for (const tool of t.tools ?? []) {
|
||||
parts.push(`${tool.name.replace(/_/g, " ")} ${formatMs(tool.ms)}`);
|
||||
}
|
||||
if (t.generation_ms != null) parts.push(`generated ${formatMs(t.generation_ms)}`);
|
||||
return parts;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="!hideMessage" class="chat-message" :class="`role-${message.role}`">
|
||||
<div class="message-group">
|
||||
<div class="message-bubble">
|
||||
<div class="message-header">
|
||||
<span class="role-label">{{ roleLabel }}</span>
|
||||
<div class="message-actions" v-if="message.role === 'assistant' && !isStreaming">
|
||||
<button class="btn-save" @click="emit('saveAsNote', message.id)" title="Save as note">
|
||||
Save as Note
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<details v-if="message.thinking" class="thinking-block">
|
||||
<summary class="thinking-summary">Reasoning</summary>
|
||||
<pre class="thinking-text">{{ message.thinking }}</pre>
|
||||
</details>
|
||||
<div class="message-content prose" v-html="rendered"></div>
|
||||
<div v-if="message.tool_calls?.length" class="tool-calls">
|
||||
<ToolCallCard
|
||||
v-for="(tc, i) in message.tool_calls"
|
||||
:key="i"
|
||||
:tool-call="tc"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="message.context_note_id"
|
||||
class="context-badge"
|
||||
>
|
||||
<router-link :to="`/notes/${message.context_note_id}`">
|
||||
{{ message.context_note_title || `Note #${message.context_note_id}` }}
|
||||
</router-link>
|
||||
</div>
|
||||
</div>
|
||||
<span v-if="formattedTime" class="message-timestamp">{{ formattedTime }}</span>
|
||||
<div v-if="timingParts.length" class="message-timing">
|
||||
<span class="timing-icon">⏱</span>
|
||||
<span v-for="(part, i) in timingParts" :key="i" class="timing-part">
|
||||
<span v-if="i > 0" class="timing-sep">·</span>{{ part }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.chat-message {
|
||||
display: flex;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
.role-user {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.role-assistant {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.message-group {
|
||||
max-width: 80%;
|
||||
}
|
||||
|
||||
.message-bubble {
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
/* User prompts: recessed, muted — margin notes */
|
||||
.role-user .message-bubble {
|
||||
background: var(--color-bubble-user-bg);
|
||||
border: 1px solid var(--color-bubble-user-border);
|
||||
color: var(--color-bubble-user-text);
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
|
||||
/* Assistant responses: elevated, lit — the primary text */
|
||||
.role-assistant .message-bubble {
|
||||
background: var(--color-bg-card);
|
||||
border-left: 2px solid var(--color-primary);
|
||||
box-shadow: var(--color-bubble-asst-shadow);
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
|
||||
.message-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
.role-label {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
.role-user .role-label {
|
||||
color: var(--color-text-muted);
|
||||
opacity: 0.6;
|
||||
}
|
||||
.role-assistant .role-label {
|
||||
color: var(--color-primary);
|
||||
font-family: 'Fraunces', Georgia, serif;
|
||||
font-optical-sizing: auto;
|
||||
font-size: 0.8rem;
|
||||
text-transform: none;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.thinking-block {
|
||||
margin-bottom: 0.5rem;
|
||||
border-left: 2px solid rgba(91, 74, 138, 0.35);
|
||||
border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.thinking-summary {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
list-style: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
background: var(--color-bg-secondary);
|
||||
}
|
||||
.thinking-summary::-webkit-details-marker { display: none; }
|
||||
.thinking-summary::before {
|
||||
content: "▶";
|
||||
font-size: 0.6rem;
|
||||
transition: transform 0.15s;
|
||||
}
|
||||
details[open] .thinking-summary::before {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.thinking-text {
|
||||
margin: 0;
|
||||
padding: 0.5rem;
|
||||
font-size: 0.8rem;
|
||||
line-height: 1.5;
|
||||
color: var(--color-text-secondary);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
background: var(--color-bg-secondary);
|
||||
}
|
||||
/* Long-form line-height (1.7) on assistant bubbles per the design system —
|
||||
chat is a reading surface, not a snippet stream. User bubbles stay tighter. */
|
||||
.role-assistant .message-content {
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.55;
|
||||
word-break: break-word;
|
||||
}
|
||||
.message-content :deep(p:last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
|
||||
.message-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.btn-save {
|
||||
font-size: 0.7rem;
|
||||
padding: 0.1rem 0.4rem;
|
||||
background: transparent;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--color-text-secondary);
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn-save:hover {
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
.tool-calls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.3rem;
|
||||
margin-top: 0.4rem;
|
||||
}
|
||||
.context-badge {
|
||||
margin-top: 0.4rem;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
.context-badge a {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
}
|
||||
.role-user .context-badge a {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
.context-badge a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.message-timestamp {
|
||||
display: block;
|
||||
font-size: 0.7rem;
|
||||
color: var(--color-text-muted);
|
||||
margin-top: 0.15rem;
|
||||
padding: 0 0.5rem;
|
||||
}
|
||||
.message-timing {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.2rem;
|
||||
padding: 0.1rem 0.5rem 0;
|
||||
font-size: 0.68rem;
|
||||
color: var(--color-text-muted);
|
||||
opacity: 0.7;
|
||||
}
|
||||
.timing-icon {
|
||||
font-size: 0.65rem;
|
||||
}
|
||||
.timing-part {
|
||||
white-space: nowrap;
|
||||
}
|
||||
.timing-sep {
|
||||
margin-right: 0.2rem;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -1,952 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, nextTick, onMounted, onUnmounted } from 'vue'
|
||||
import { useChatStore } from '@/stores/chat'
|
||||
import ChatMessage from '@/components/ChatMessage.vue'
|
||||
import ChatStreamingBubble from '@/components/ChatStreamingBubble.vue'
|
||||
import ChatInputBar from '@/components/ChatInputBar.vue'
|
||||
import ToolCallCard from '@/components/ToolCallCard.vue'
|
||||
import type { Message, ToolCallRecord } from '@/types/chat'
|
||||
import { Mic, ChevronDown, X } from 'lucide-vue-next'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
variant: 'full' | 'widget'
|
||||
/** Workspace: pins RAG scope and workspace_project_id */
|
||||
projectId?: number
|
||||
/** Briefing: hides scope chip, hides note picker */
|
||||
briefingMode?: boolean
|
||||
/** Hides input bar — for read-only historical views */
|
||||
readOnly?: boolean
|
||||
placeholder?: string
|
||||
autoFocus?: boolean
|
||||
}>(), {
|
||||
briefingMode: false,
|
||||
readOnly: false,
|
||||
autoFocus: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** Widget only: emitted when a new conversation is created */
|
||||
'conversation-started': [convId: number]
|
||||
}>()
|
||||
|
||||
const store = useChatStore()
|
||||
|
||||
// ── Scroll ────────────────────────────────────────────────────────────────────
|
||||
const messagesEl = ref<HTMLElement | null>(null)
|
||||
|
||||
function scrollToBottom() {
|
||||
nextTick(() => {
|
||||
if (messagesEl.value) {
|
||||
messagesEl.value.scrollTop = messagesEl.value.scrollHeight
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
watch(() => store.streamingContent, () => scrollToBottom())
|
||||
watch(() => store.currentConversation?.messages.length, () => scrollToBottom())
|
||||
|
||||
// Notify CalendarView when an event is created/updated/deleted via tool
|
||||
const _calendarToolNames = new Set(['create_event', 'update_event', 'delete_event'])
|
||||
const _seenCalendarToolIdx = new Set<number>()
|
||||
watch(() => store.streamingToolCalls, (calls) => {
|
||||
calls.forEach((tc, i) => {
|
||||
if (!_seenCalendarToolIdx.has(i) && _calendarToolNames.has(tc.function) && tc.status === 'success') {
|
||||
_seenCalendarToolIdx.add(i)
|
||||
document.dispatchEvent(new CustomEvent('fable:calendar-changed'))
|
||||
}
|
||||
})
|
||||
}, { deep: true })
|
||||
watch(() => store.streaming, (s) => { if (!s) _seenCalendarToolIdx.clear() })
|
||||
|
||||
// ── Note context (full variant — included / suggested / auto-injected notes) ──
|
||||
const includedNoteIds = ref<Set<number>>(new Set())
|
||||
const includedNotes = ref<{ id: number; title: string }[]>([])
|
||||
const suggestedNotes = ref<{ id: number; title: string; score?: number | null }[]>([])
|
||||
const autoInjectedNotes = ref<{ id: number; title: string; score?: number | null }[]>([])
|
||||
const excludedNoteIds = ref<number[]>([])
|
||||
|
||||
watch(
|
||||
() => store.lastContextMeta,
|
||||
(meta) => {
|
||||
if (!meta || props.variant !== 'full') return
|
||||
const alreadyIncluded = includedNoteIds.value
|
||||
const alreadyAutoInjected = new Set(autoInjectedNotes.value.map((n) => n.id))
|
||||
const alreadySuggested = new Set(suggestedNotes.value.map((n) => n.id))
|
||||
|
||||
for (const note of meta.auto_injected_notes ?? []) {
|
||||
if (!alreadyAutoInjected.has(note.id) && !alreadyIncluded.has(note.id)) {
|
||||
autoInjectedNotes.value.push(note)
|
||||
alreadyAutoInjected.add(note.id)
|
||||
}
|
||||
}
|
||||
for (const note of meta.auto_notes ?? []) {
|
||||
if (note.auto_injected) {
|
||||
if (!alreadyAutoInjected.has(note.id) && !alreadyIncluded.has(note.id)) {
|
||||
autoInjectedNotes.value.push(note)
|
||||
alreadyAutoInjected.add(note.id)
|
||||
}
|
||||
} else {
|
||||
if (!alreadyIncluded.has(note.id) && !alreadySuggested.has(note.id) && !alreadyAutoInjected.has(note.id)) {
|
||||
suggestedNotes.value.push(note)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
function includeNote(note: { id: number; title: string }) {
|
||||
if (includedNoteIds.value.has(note.id)) return
|
||||
includedNoteIds.value = new Set([...includedNoteIds.value, note.id])
|
||||
includedNotes.value.push(note)
|
||||
suggestedNotes.value = suggestedNotes.value.filter((n) => n.id !== note.id)
|
||||
autoInjectedNotes.value = autoInjectedNotes.value.filter((n) => n.id !== note.id)
|
||||
}
|
||||
|
||||
function excludeAutoNote(noteId: number) {
|
||||
autoInjectedNotes.value = autoInjectedNotes.value.filter((n) => n.id !== noteId)
|
||||
if (!excludedNoteIds.value.includes(noteId)) {
|
||||
excludedNoteIds.value = [...excludedNoteIds.value, noteId]
|
||||
}
|
||||
}
|
||||
|
||||
function removeIncludedNote(noteId: number) {
|
||||
includedNoteIds.value = new Set([...includedNoteIds.value].filter((id) => id !== noteId))
|
||||
const removed = includedNotes.value.find((n) => n.id === noteId)
|
||||
includedNotes.value = includedNotes.value.filter((n) => n.id !== noteId)
|
||||
if (removed && !suggestedNotes.value.some((n) => n.id === noteId)) {
|
||||
suggestedNotes.value.push(removed)
|
||||
}
|
||||
}
|
||||
|
||||
const contextCount = computed(
|
||||
() => autoInjectedNotes.value.length + suggestedNotes.value.length + includedNotes.value.length
|
||||
)
|
||||
|
||||
const hasContextData = computed(
|
||||
() => props.variant === 'full' && !props.briefingMode && !props.projectId && contextCount.value > 0
|
||||
)
|
||||
|
||||
// ── Narrow-viewport sidebar toggle ────────────────────────────────────────────
|
||||
const NARROW_BREAKPOINT = 1200
|
||||
const isNarrow = ref(typeof window !== 'undefined' && window.innerWidth < NARROW_BREAKPOINT)
|
||||
const sidebarOpen = ref(false)
|
||||
|
||||
function onResize() {
|
||||
isNarrow.value = window.innerWidth < NARROW_BREAKPOINT
|
||||
}
|
||||
onMounted(() => window.addEventListener('resize', onResize))
|
||||
onUnmounted(() => window.removeEventListener('resize', onResize))
|
||||
|
||||
function toggleContextSidebar() {
|
||||
sidebarOpen.value = !sidebarOpen.value
|
||||
}
|
||||
|
||||
const hasContextSidebar = computed(() => hasContextData.value && sidebarOpen.value)
|
||||
|
||||
// ── Collapsible sections (per-conversation, localStorage) ─────────────────────
|
||||
type SectionKey = 'auto' | 'suggested' | 'included'
|
||||
const collapsedSections = ref<Set<SectionKey>>(new Set())
|
||||
|
||||
function storageKey(): string | null {
|
||||
const id = store.currentConversation?.id
|
||||
return id ? `fa_chat_ctx_collapsed_${id}` : null
|
||||
}
|
||||
|
||||
function loadCollapsed() {
|
||||
const key = storageKey()
|
||||
if (!key) { collapsedSections.value = new Set(); return }
|
||||
try {
|
||||
const raw = localStorage.getItem(key)
|
||||
if (!raw) { collapsedSections.value = new Set(); return }
|
||||
const arr = JSON.parse(raw) as SectionKey[]
|
||||
collapsedSections.value = new Set(arr)
|
||||
} catch {
|
||||
collapsedSections.value = new Set()
|
||||
}
|
||||
}
|
||||
|
||||
function saveCollapsed() {
|
||||
const key = storageKey()
|
||||
if (!key) return
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify([...collapsedSections.value]))
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
function toggleSection(key: SectionKey) {
|
||||
const next = new Set(collapsedSections.value)
|
||||
if (next.has(key)) next.delete(key)
|
||||
else next.add(key)
|
||||
collapsedSections.value = next
|
||||
saveCollapsed()
|
||||
}
|
||||
|
||||
watch(() => store.currentConversation?.id, () => loadCollapsed(), { immediate: true })
|
||||
|
||||
// ── Empty-state (full variant, fresh/empty conversation) ─────────────────────
|
||||
const showEmptyState = computed(
|
||||
() =>
|
||||
props.variant === 'full'
|
||||
&& !props.briefingMode
|
||||
&& !props.projectId
|
||||
&& !store.streaming
|
||||
&& (store.currentConversation?.messages.length ?? 0) === 0
|
||||
)
|
||||
|
||||
const recentConversations = computed(() => {
|
||||
const currentId = store.currentConversation?.id
|
||||
return store.conversations
|
||||
.filter((c) => c.id !== currentId && c.message_count > 0)
|
||||
.slice(0, 5)
|
||||
})
|
||||
|
||||
function startVoiceMode() {
|
||||
window.dispatchEvent(new CustomEvent('voice:ptt-toggle'))
|
||||
}
|
||||
|
||||
// ── Send ──────────────────────────────────────────────────────────────────────
|
||||
const inputBarRef = ref<InstanceType<typeof ChatInputBar> | null>(null)
|
||||
|
||||
async function onSubmit(payload: { content: string; contextNoteId?: number }) {
|
||||
if (props.variant === 'widget') {
|
||||
await widgetSend(payload)
|
||||
return
|
||||
}
|
||||
if (!store.currentConversation) return
|
||||
await store.sendMessage(
|
||||
payload.content,
|
||||
payload.contextNoteId,
|
||||
includedNoteIds.value.size ? [...includedNoteIds.value] : undefined,
|
||||
false,
|
||||
undefined,
|
||||
excludedNoteIds.value.length ? excludedNoteIds.value : undefined,
|
||||
props.projectId ?? store.ragProjectId,
|
||||
props.projectId ?? undefined,
|
||||
)
|
||||
scrollToBottom()
|
||||
nextTick(() => inputBarRef.value?.focus())
|
||||
}
|
||||
|
||||
// ── Widget state ──────────────────────────────────────────────────────────────
|
||||
const widgetConvId = ref<number | null>(null)
|
||||
const widgetQuery = ref('')
|
||||
const widgetDone = ref(false)
|
||||
const widgetFinalContent = ref('')
|
||||
const widgetFinalToolCalls = ref<ToolCallRecord[]>([])
|
||||
|
||||
const isConversational = computed(
|
||||
() => widgetDone.value && widgetFinalToolCalls.value.length === 0
|
||||
)
|
||||
|
||||
function clearWidget() {
|
||||
widgetConvId.value = null
|
||||
widgetDone.value = false
|
||||
widgetQuery.value = ''
|
||||
widgetFinalContent.value = ''
|
||||
widgetFinalToolCalls.value = []
|
||||
}
|
||||
|
||||
async function widgetSend(payload: { content: string; contextNoteId?: number }) {
|
||||
widgetConvId.value = null
|
||||
widgetDone.value = false
|
||||
widgetFinalContent.value = ''
|
||||
widgetFinalToolCalls.value = []
|
||||
widgetQuery.value = payload.content
|
||||
|
||||
const conv = await store.createConversation()
|
||||
await store.fetchConversation(conv.id)
|
||||
widgetConvId.value = conv.id
|
||||
emit('conversation-started', conv.id)
|
||||
|
||||
await store.sendMessage(payload.content, payload.contextNoteId, undefined, false)
|
||||
|
||||
const msgs = store.currentConversation?.messages ?? []
|
||||
const lastAssistant = [...msgs].reverse().find((m: Message) => m.role === 'assistant')
|
||||
widgetFinalContent.value = lastAssistant?.content ?? ''
|
||||
widgetFinalToolCalls.value = (lastAssistant?.tool_calls ?? []) as ToolCallRecord[]
|
||||
widgetDone.value = true
|
||||
}
|
||||
|
||||
// ── Save as note ──────────────────────────────────────────────────────────────
|
||||
async function handleSaveAsNote(messageId: number) {
|
||||
try {
|
||||
await store.saveMessageAsNote(messageId)
|
||||
const { useToastStore } = await import('@/stores/toast')
|
||||
useToastStore().show('Saved as note')
|
||||
} catch {
|
||||
const { useToastStore } = await import('@/stores/toast')
|
||||
useToastStore().show('Failed to save as note', 'error')
|
||||
}
|
||||
}
|
||||
|
||||
// ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
onMounted(() => {
|
||||
if (props.autoFocus) nextTick(() => inputBarRef.value?.focus())
|
||||
})
|
||||
|
||||
// ── Exposed ───────────────────────────────────────────────────────────────────
|
||||
function focus() {
|
||||
inputBarRef.value?.focus()
|
||||
}
|
||||
|
||||
function prefill(text: string) {
|
||||
inputBarRef.value?.prefill(text)
|
||||
}
|
||||
|
||||
async function send(text: string) {
|
||||
await onSubmit({ content: text })
|
||||
}
|
||||
|
||||
// ── Briefing slot separator helper ────────────────────────────────────────────
|
||||
function hasEarlierBriefingSlot(index: number): boolean {
|
||||
const msgs = store.currentConversation?.messages ?? []
|
||||
for (let i = 0; i < index; i++) {
|
||||
const m = msgs[i]
|
||||
const meta = m?.metadata as Record<string, unknown> | null | undefined
|
||||
if (
|
||||
m?.role === 'assistant' &&
|
||||
meta?.briefing_slot != null &&
|
||||
!meta?.briefing_intermediate
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
defineExpose({ focus, prefill, send, contextCount, sidebarOpen, toggleContextSidebar, hasContextData })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- ═══════════════════════════════ FULL VARIANT ══════════════════════════════ -->
|
||||
<template v-if="variant === 'full'">
|
||||
<div class="chat-full">
|
||||
<!-- Message list -->
|
||||
<div ref="messagesEl" class="messages-container">
|
||||
<div class="messages-inner">
|
||||
<template
|
||||
v-for="(msg, index) in store.currentConversation?.messages ?? []"
|
||||
:key="msg.id"
|
||||
>
|
||||
<!-- Briefing slot separator: before any non-first slot message (skip intermediate tool-call rows) -->
|
||||
<div
|
||||
v-if="briefingMode && msg.role === 'assistant' && msg.metadata?.briefing_slot && !msg.metadata?.briefing_intermediate && hasEarlierBriefingSlot(index)"
|
||||
class="briefing-slot-separator"
|
||||
></div>
|
||||
<ChatMessage
|
||||
:message="msg"
|
||||
@save-as-note="handleSaveAsNote"
|
||||
/>
|
||||
</template>
|
||||
<!-- Streaming bubble -->
|
||||
<ChatStreamingBubble v-if="store.streaming" />
|
||||
<!-- Queued messages -->
|
||||
<template v-if="store.queuedMessages.length">
|
||||
<div
|
||||
v-for="(q, i) in store.queuedMessages"
|
||||
:key="`queued-${i}`"
|
||||
class="chat-message role-user queued-message"
|
||||
>
|
||||
<div class="message-bubble queued-bubble">
|
||||
<div class="queued-badge">Queued</div>
|
||||
<div class="message-content">{{ q.content }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="queued-clear-row">
|
||||
<button class="queued-clear-btn" @click="store.clearQueue()">
|
||||
Cancel {{ store.queuedMessages.length }} queued
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="showEmptyState" class="chat-empty-state">
|
||||
<h2 class="empty-greeting">What's on your mind?</h2>
|
||||
<div v-if="recentConversations.length" class="empty-recent">
|
||||
<div class="empty-section-label">Jump back in</div>
|
||||
<router-link
|
||||
v-for="conv in recentConversations"
|
||||
:key="conv.id"
|
||||
:to="`/chat/${conv.id}`"
|
||||
class="empty-recent-item"
|
||||
>
|
||||
<span class="empty-recent-title">{{ conv.title || 'Untitled conversation' }}</span>
|
||||
<span class="empty-recent-count">{{ conv.message_count }} msg</span>
|
||||
</router-link>
|
||||
</div>
|
||||
<button class="empty-voice-btn" @click="startVoiceMode" title="Start in voice mode">
|
||||
<Mic class="voice-icon" :size="16" />
|
||||
<span>Start in voice mode</span>
|
||||
</button>
|
||||
</div>
|
||||
<p
|
||||
v-else-if="!store.currentConversation?.messages.length && !store.streaming"
|
||||
class="empty-msg"
|
||||
>Start a conversation.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Context sidebar (full, non-briefing, non-workspace) -->
|
||||
<aside v-if="hasContextSidebar" class="context-sidebar">
|
||||
<template v-if="autoInjectedNotes.length">
|
||||
<button
|
||||
class="context-sidebar-header"
|
||||
:class="{ collapsed: collapsedSections.has('auto') }"
|
||||
@click="toggleSection('auto')"
|
||||
>
|
||||
<ChevronDown class="chev" :size="16" />
|
||||
<span>Auto-included</span>
|
||||
<span class="section-count">{{ autoInjectedNotes.length }}</span>
|
||||
</button>
|
||||
<div v-show="!collapsedSections.has('auto')">
|
||||
<div v-for="note in autoInjectedNotes" :key="note.id" class="context-note context-note-auto">
|
||||
<span class="auto-pill" title="Auto-included by relevance">AUTO</span>
|
||||
<router-link :to="`/notes/${note.id}`" class="context-note-name">{{ note.title }}</router-link>
|
||||
<span
|
||||
v-if="note.score != null"
|
||||
class="context-note-score"
|
||||
:class="{ 'score-high': note.score >= 0.75, 'score-medium': note.score >= 0.60 && note.score < 0.75, 'score-low': note.score < 0.60 }"
|
||||
>{{ Math.round(note.score * 100) }}%</span>
|
||||
<button class="context-note-remove" @click="excludeAutoNote(note.id)" title="Remove from context"><X :size="16" /></button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="suggestedNotes.length">
|
||||
<button
|
||||
class="context-sidebar-header"
|
||||
:class="{ collapsed: collapsedSections.has('suggested'), 'context-sidebar-header-gap': autoInjectedNotes.length }"
|
||||
@click="toggleSection('suggested')"
|
||||
>
|
||||
<ChevronDown class="chev" :size="16" />
|
||||
<span>Suggested</span>
|
||||
<span class="section-count">{{ suggestedNotes.length }}</span>
|
||||
</button>
|
||||
<div v-show="!collapsedSections.has('suggested')">
|
||||
<div v-for="note in suggestedNotes" :key="note.id" class="context-note context-note-suggested">
|
||||
<router-link :to="`/notes/${note.id}`" class="context-note-name">{{ note.title }}</router-link>
|
||||
<span
|
||||
v-if="note.score != null"
|
||||
class="context-note-score"
|
||||
:class="{ 'score-high': note.score >= 0.75, 'score-medium': note.score >= 0.60 && note.score < 0.75, 'score-low': note.score < 0.60 }"
|
||||
>{{ Math.round(note.score * 100) }}%</span>
|
||||
<button class="context-note-add" @click="includeNote(note)" title="Add to context">+</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="includedNotes.length">
|
||||
<button
|
||||
class="context-sidebar-header"
|
||||
:class="{ collapsed: collapsedSections.has('included'), 'context-sidebar-header-gap': autoInjectedNotes.length || suggestedNotes.length }"
|
||||
@click="toggleSection('included')"
|
||||
>
|
||||
<ChevronDown class="chev" :size="16" />
|
||||
<span>In Context</span>
|
||||
<span class="section-count">{{ includedNotes.length }}</span>
|
||||
</button>
|
||||
<div v-show="!collapsedSections.has('included')">
|
||||
<div v-for="note in includedNotes" :key="note.id" class="context-note context-note-included">
|
||||
<router-link :to="`/notes/${note.id}`" class="context-note-name">{{ note.title }}</router-link>
|
||||
<button class="context-note-remove" @click="removeIncludedNote(note.id)" title="Remove from context"><X :size="16" /></button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</aside>
|
||||
|
||||
<!-- Input area (hidden when readOnly) -->
|
||||
<div v-if="!readOnly" class="input-wrapper">
|
||||
<!-- Unified input bar -->
|
||||
<ChatInputBar
|
||||
ref="inputBarRef"
|
||||
:placeholder="placeholder"
|
||||
:briefing-mode="briefingMode"
|
||||
@submit="onSubmit"
|
||||
@abort="store.cancelGeneration()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- ══════════════════════════════ WIDGET VARIANT ══════════════════════════════ -->
|
||||
<template v-else>
|
||||
<ChatInputBar
|
||||
ref="inputBarRef"
|
||||
pill
|
||||
:placeholder="placeholder ?? 'Start a new chat… (Enter to send)'"
|
||||
:briefing-mode="false"
|
||||
@submit="onSubmit"
|
||||
@abort="store.cancelGeneration()"
|
||||
/>
|
||||
|
||||
<!-- Inline response area -->
|
||||
<div v-if="widgetConvId" class="widget-response">
|
||||
<div class="widget-query">{{ widgetQuery }}</div>
|
||||
|
||||
<!-- Tool calls -->
|
||||
<div v-if="store.streaming && store.streamingToolCalls.length" class="widget-tool-calls">
|
||||
<ToolCallCard v-for="(tc, i) in store.streamingToolCalls" :key="i" :tool-call="tc" />
|
||||
</div>
|
||||
<div v-else-if="widgetDone && widgetFinalToolCalls.length" class="widget-tool-calls">
|
||||
<ToolCallCard v-for="(tc, i) in widgetFinalToolCalls" :key="i" :tool-call="tc" />
|
||||
</div>
|
||||
|
||||
<!-- Streaming / final text -->
|
||||
<div v-if="store.streaming" class="widget-text streaming">
|
||||
<div v-if="store.streamingStatus && !store.streamingContent" class="widget-status">
|
||||
<span class="widget-status-dot"></span>{{ store.streamingStatus }}
|
||||
</div>
|
||||
<span v-else-if="store.streamingContent">{{ store.streamingContent }}</span>
|
||||
<span v-else class="thinking-dots">...</span>
|
||||
</div>
|
||||
<div v-else-if="widgetDone && widgetFinalContent" class="widget-text">
|
||||
{{ widgetFinalContent }}
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="widget-actions" :class="{ conversational: isConversational }">
|
||||
<router-link
|
||||
:to="`/chat/${widgetConvId}`"
|
||||
class="btn-open-chat"
|
||||
:class="{ prominent: isConversational }"
|
||||
>{{ isConversational ? 'Continue the conversation →' : 'Think it through in Chat →' }}</router-link>
|
||||
<button class="btn-clear-response" @click="clearWidget">Clear</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* ── Full variant layout ──
|
||||
* Single grid owns the reading column + context sidebar + input bar so
|
||||
* messages and input bar share one centered reading track while the
|
||||
* context sidebar spans the full height from header to bottom of view.
|
||||
* Reading column is always centered (3-column grid: 1fr | content | 1fr).
|
||||
* The context sidebar overlays the right gutter so it never shifts layout.
|
||||
*/
|
||||
.chat-full {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
grid-template-columns:
|
||||
1fr
|
||||
minmax(0, var(--chat-reading-width))
|
||||
1fr;
|
||||
grid-template-rows: minmax(0, 1fr) auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.messages-container {
|
||||
grid-column: 2;
|
||||
grid-row: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1rem 1rem 0.75rem;
|
||||
mask-image: linear-gradient(to bottom, transparent, black 20px, black calc(100% - 20px), transparent);
|
||||
-webkit-mask-image: linear-gradient(to bottom, transparent, black 20px, black calc(100% - 20px), transparent);
|
||||
}
|
||||
.messages-inner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100%;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* Briefing slot separator */
|
||||
.briefing-slot-separator {
|
||||
height: 1px;
|
||||
margin: 1.25rem 0 0.75rem;
|
||||
background: var(--color-border, #333);
|
||||
opacity: 0.35;
|
||||
}
|
||||
|
||||
/* Context sidebar — overlays right gutter, never shifts reading column */
|
||||
.context-sidebar {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: var(--chat-context-sidebar-width);
|
||||
border-left: 1px solid var(--color-border);
|
||||
padding: 0.75rem 0.5rem;
|
||||
overflow-y: auto;
|
||||
background: var(--color-bg-secondary);
|
||||
font-size: 0.78rem;
|
||||
z-index: 2;
|
||||
}
|
||||
.context-sidebar-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
width: 100%;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0.15rem 0.1rem;
|
||||
font-family: inherit;
|
||||
font-size: 0.65rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: 0.35rem;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
.context-sidebar-header:hover { color: var(--color-text); }
|
||||
.context-sidebar-header .chev {
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
.context-sidebar-header.collapsed .chev {
|
||||
transform: rotate(-90deg);
|
||||
}
|
||||
.context-sidebar-header .section-count {
|
||||
margin-left: auto;
|
||||
color: var(--color-text-muted);
|
||||
font-weight: 500;
|
||||
background: var(--color-bg);
|
||||
padding: 0.05rem 0.3rem;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.context-sidebar-header-gap { margin-top: 0.75rem; }
|
||||
.context-note {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
margin-bottom: 0.25rem;
|
||||
padding: 0.2rem 0.35rem;
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
.context-note-auto {
|
||||
background: color-mix(in srgb, var(--color-text-muted) 8%, transparent);
|
||||
opacity: 0.85;
|
||||
}
|
||||
.context-note-included {
|
||||
background: color-mix(in srgb, var(--color-primary) 10%, transparent);
|
||||
border-left: 2px solid var(--color-primary);
|
||||
}
|
||||
.auto-pill {
|
||||
font-size: 0.55rem;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.05em;
|
||||
padding: 0.05rem 0.3rem;
|
||||
border-radius: 4px;
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.context-note-name {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--color-text);
|
||||
text-decoration: none;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.context-note-name:hover { color: var(--color-primary); }
|
||||
.context-note-score {
|
||||
font-size: 0.65rem;
|
||||
padding: 0.05rem 0.25rem;
|
||||
border-radius: 4px;
|
||||
background: var(--color-bg);
|
||||
}
|
||||
.score-high { color: #22c55e; }
|
||||
.score-medium { color: #f59e0b; }
|
||||
.score-low { color: var(--color-text-muted); }
|
||||
.context-note-remove, .context-note-add {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.9rem;
|
||||
line-height: 1;
|
||||
padding: 0 0.1rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.context-note-remove:hover { color: #ef4444; }
|
||||
.context-note-add:hover { color: var(--color-primary); }
|
||||
|
||||
/* Input wrapper — lives in the same reading column as messages */
|
||||
.input-wrapper {
|
||||
grid-column: 2;
|
||||
grid-row: 2;
|
||||
padding: 0.5rem 1rem 0.75rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
/* Queued messages */
|
||||
.queued-message { opacity: 0.45; }
|
||||
.queued-bubble {
|
||||
background: var(--color-bg-secondary);
|
||||
border: 1px dashed var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 0.5rem 0.75rem;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.queued-badge {
|
||||
font-size: 0.65rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--color-text-muted);
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.2rem;
|
||||
}
|
||||
.queued-clear-row {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 0.25rem 0;
|
||||
}
|
||||
.queued-clear-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.empty-msg {
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 0.9rem;
|
||||
text-align: center;
|
||||
padding: 2rem 1rem;
|
||||
font-family: 'Fraunces', Georgia, serif;
|
||||
}
|
||||
|
||||
.chat-empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 1.5rem;
|
||||
padding: 3rem 1rem 2rem;
|
||||
max-width: 520px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.empty-greeting {
|
||||
font-family: 'Fraunces', Georgia, serif;
|
||||
font-weight: 400;
|
||||
font-size: 1.75rem;
|
||||
color: var(--color-text-secondary);
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.empty-section-label {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: 0.5rem;
|
||||
padding-left: 0.25rem;
|
||||
}
|
||||
|
||||
.empty-recent {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.empty-recent-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 0.9rem;
|
||||
border-radius: var(--radius-md, 10px);
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-bg-elevated, rgba(255, 255, 255, 0.02));
|
||||
color: var(--color-text);
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
|
||||
}
|
||||
|
||||
.empty-recent-item + .empty-recent-item {
|
||||
margin-top: 0.4rem;
|
||||
}
|
||||
|
||||
.empty-recent-item:hover {
|
||||
border-color: var(--color-primary);
|
||||
background: rgba(91, 74, 138, 0.05);
|
||||
transform: translateX(2px);
|
||||
}
|
||||
|
||||
.empty-recent-title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.empty-recent-count {
|
||||
font-size: 0.7rem;
|
||||
color: var(--color-text-muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.empty-voice-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.6rem;
|
||||
padding: 0.75rem 1.2rem;
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--color-border);
|
||||
background: transparent;
|
||||
color: var(--color-text);
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
align-self: center;
|
||||
transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
|
||||
}
|
||||
|
||||
.empty-voice-btn:hover {
|
||||
border-color: var(--color-primary);
|
||||
background: linear-gradient(135deg, #5B4A8A, #3F3560);
|
||||
color: #fff;
|
||||
box-shadow: 0 4px 16px rgba(91, 74, 138, 0.35);
|
||||
}
|
||||
|
||||
.empty-voice-btn .voice-icon {
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
/* ── Widget variant ── */
|
||||
.widget-response {
|
||||
margin-top: 0.75rem;
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 0.75rem 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.widget-query {
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.widget-text {
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.55;
|
||||
color: var(--color-text);
|
||||
}
|
||||
.widget-text.streaming { color: var(--color-text-muted); }
|
||||
.thinking-dots { color: var(--color-text-muted); letter-spacing: 0.2em; }
|
||||
.widget-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.widget-status-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
animation: blink 1s infinite;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@keyframes blink { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
|
||||
.widget-tool-calls { display: flex; flex-direction: column; gap: 0.25rem; }
|
||||
.widget-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding-top: 0.25rem;
|
||||
border-top: 1px solid var(--color-border);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.btn-open-chat {
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
text-decoration: none;
|
||||
}
|
||||
.btn-open-chat:hover { color: var(--color-primary); }
|
||||
.btn-open-chat.prominent {
|
||||
font-size: 0.9rem;
|
||||
color: var(--color-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
.btn-clear-response {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
margin-left: auto;
|
||||
}
|
||||
.btn-clear-response:hover { color: var(--color-text); }
|
||||
|
||||
/* Streaming bubble styles — applied via :deep to ChatStreamingBubble children */
|
||||
:deep(.streaming-bubble) {
|
||||
max-width: 85%;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 16px 16px 16px 4px;
|
||||
background: var(--color-bg-card);
|
||||
border-left: 2px solid var(--color-primary);
|
||||
box-shadow: 0 1px 4px var(--color-shadow);
|
||||
}
|
||||
:deep(.streaming-tool-calls) { margin-bottom: 0.5rem; }
|
||||
:deep(.streaming-status-line) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
:deep(.streaming-status-dot) {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
animation: blink 1s infinite;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
:deep(.thinking-block) {
|
||||
margin-bottom: 0.5rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
overflow: hidden;
|
||||
}
|
||||
:deep(.thinking-summary) {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
background: var(--color-bg-secondary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
:deep(.thinking-summary::-webkit-details-marker) { display: none; }
|
||||
:deep(.thinking-text) {
|
||||
margin: 0;
|
||||
padding: 0.5rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-secondary);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
background: var(--color-bg-secondary);
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
:deep(.typing-indicator) {
|
||||
display: inline-block;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
animation: blink 1s infinite;
|
||||
margin-left: 4px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
</style>
|
||||
@@ -1,56 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useChatStore } from '@/stores/chat'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
import { renderMarkdown } from '@/utils/markdown'
|
||||
import ToolCallCard from '@/components/ToolCallCard.vue'
|
||||
import ToolConfirmCard from '@/components/ToolConfirmCard.vue'
|
||||
|
||||
const store = useChatStore()
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
const streamingRendered = computed(() => {
|
||||
if (!store.streamingContent) return ''
|
||||
return renderMarkdown(store.streamingContent)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="chat-message role-assistant">
|
||||
<div class="message-bubble streaming-bubble">
|
||||
<div class="message-header">
|
||||
<span class="role-label">{{ settingsStore.assistantName }}</span>
|
||||
</div>
|
||||
<div v-if="store.streamingToolCalls.length" class="streaming-tool-calls">
|
||||
<ToolCallCard
|
||||
v-for="(tc, i) in store.streamingToolCalls"
|
||||
:key="i"
|
||||
:tool-call="tc"
|
||||
/>
|
||||
</div>
|
||||
<ToolConfirmCard
|
||||
v-if="store.streamingPendingTool"
|
||||
:pending-tool="store.streamingPendingTool"
|
||||
@accept="store.confirmTool(true)"
|
||||
@decline="store.confirmTool(false)"
|
||||
/>
|
||||
<div v-if="store.streamingStatus" class="streaming-status-line">
|
||||
<span class="streaming-status-dot"></span>
|
||||
{{ store.streamingStatus }}
|
||||
</div>
|
||||
<details
|
||||
v-if="store.streamingThinking"
|
||||
class="thinking-block"
|
||||
:open="!store.streamingContent"
|
||||
>
|
||||
<summary class="thinking-summary">Reasoning</summary>
|
||||
<pre class="thinking-text">{{ store.streamingThinking }}</pre>
|
||||
</details>
|
||||
<div class="message-content prose" v-html="streamingRendered"></div>
|
||||
<span
|
||||
v-if="!store.streamingStatus && !store.streamingThinking && !store.streamingContent"
|
||||
class="typing-indicator"
|
||||
></span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,814 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { apiPost, getEvent } from "@/api/client";
|
||||
import type { EventEntry } from "@/api/client";
|
||||
import type { ToolCallRecord } from "@/types/chat";
|
||||
import EventSlideOver from "@/components/EventSlideOver.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
toolCall: ToolCallRecord;
|
||||
}>();
|
||||
|
||||
const appliedTags = ref<Set<string>>(new Set());
|
||||
const applyingTag = ref<string | null>(null);
|
||||
const confirmState = ref<"idle" | "creating" | "created" | "denied">("idle");
|
||||
|
||||
const label = computed(() => {
|
||||
if (props.toolCall.status === "declined") return "Declined";
|
||||
if (props.toolCall.result.requires_confirmation) return "Similar content found";
|
||||
if (!props.toolCall.result.success) return "Error";
|
||||
switch (props.toolCall.result.type) {
|
||||
case "task": return "Created task";
|
||||
case "note": return "Created note";
|
||||
case "note_updated": return "Updated note";
|
||||
case "note_deleted": return "Deleted note";
|
||||
case "task_deleted": return "Deleted task";
|
||||
case "note_content": return "Note";
|
||||
case "notes_list": return "Notes";
|
||||
case "tasks": return "Tasks";
|
||||
case "todo_updated": return "Updated todo";
|
||||
case "search": return "Searched notes";
|
||||
case "event": return "Created event";
|
||||
case "events": return "Found events";
|
||||
case "event_updated": return "Updated event";
|
||||
case "event_deleted": return "Deleted event";
|
||||
case "calendars": return "Calendars";
|
||||
case "todo": return "Created todo";
|
||||
case "todos": return "Calendar todos";
|
||||
case "todo_completed": return "Completed todo";
|
||||
case "todo_deleted": return "Deleted todo";
|
||||
case "web_search": return "Web search";
|
||||
case "research_pending": return "Research started";
|
||||
case "research_note": return "Research note";
|
||||
case "image_search": return "Image search";
|
||||
default: return "Tool call";
|
||||
}
|
||||
});
|
||||
|
||||
const title = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data) return null;
|
||||
if (typeof data.title === "string") return data.title;
|
||||
return null;
|
||||
});
|
||||
|
||||
const linkTo = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || typeof data.id !== "number") return null;
|
||||
return `/notes/${data.id}`;
|
||||
});
|
||||
|
||||
const noteId = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || typeof data.id !== "number") return null;
|
||||
return data.id;
|
||||
});
|
||||
|
||||
const suggestedTags = computed(() => props.toolCall.result.suggested_tags ?? []);
|
||||
|
||||
const eventData = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "event") return null;
|
||||
return data as { id?: number; title: string; start_dt?: string; end_dt?: string; location?: string; color?: string };
|
||||
});
|
||||
|
||||
const updatedEvent = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "event_updated") return null;
|
||||
return data as { id?: number; title: string; start_dt?: string; end_dt?: string; location?: string; color?: string };
|
||||
});
|
||||
|
||||
const deletedEvent = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "event_deleted") return null;
|
||||
return data as { id?: number; title: string };
|
||||
});
|
||||
|
||||
const calendarList = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "calendars") return null;
|
||||
const calendars = data.calendars as Array<{ name: string }> | undefined;
|
||||
return calendars?.map((c) => c.name) ?? [];
|
||||
});
|
||||
|
||||
const todoData = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
const type = props.toolCall.result.type;
|
||||
if (!data || (type !== "todo" && type !== "todo_completed" && type !== "todo_deleted" && type !== "todo_updated")) return null;
|
||||
return data as { summary: string; due?: string; status?: string };
|
||||
});
|
||||
|
||||
const todoList = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "todos") return null;
|
||||
return (data.todos as Array<{ summary: string; due?: string; status?: string }> | undefined) ?? [];
|
||||
});
|
||||
|
||||
const todoCount = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "todos") return 0;
|
||||
return (data.count as number) ?? 0;
|
||||
});
|
||||
|
||||
const eventList = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "events") return null;
|
||||
return (data.events as Array<{ id?: number; title: string; start_dt?: string; end_dt?: string; location?: string; color?: string }> | undefined) ?? [];
|
||||
});
|
||||
|
||||
const eventCount = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "events") return 0;
|
||||
return (data.count as number) ?? 0;
|
||||
});
|
||||
|
||||
function formatEventTime(iso: string): string {
|
||||
if (!iso) return "";
|
||||
try {
|
||||
return new Date(iso).toLocaleString(undefined, {
|
||||
weekday: "short", month: "short", day: "numeric",
|
||||
hour: "numeric", minute: "2-digit",
|
||||
});
|
||||
} catch { return iso; }
|
||||
}
|
||||
|
||||
const taskList = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "tasks") return null;
|
||||
return (data.results as Array<{ id: number; title: string; status: string; priority: string; due_date?: string }> | undefined) ?? [];
|
||||
});
|
||||
|
||||
const taskCount = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "tasks") return 0;
|
||||
return (data.total as number) ?? 0;
|
||||
});
|
||||
|
||||
const webSearch = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "web_search") return null;
|
||||
return data as { query: string; results: { url: string; title: string; snippet: string }[]; count: number };
|
||||
});
|
||||
|
||||
const searchResults = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "search") return null;
|
||||
const results = data.results as Array<{ id: number; title: string; type: string }> | undefined;
|
||||
return results && results.length > 0 ? results : null;
|
||||
});
|
||||
|
||||
const deletedNote = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
const type = props.toolCall.result.type;
|
||||
if (!data || (type !== "note_deleted" && type !== "task_deleted")) return null;
|
||||
return data as { id: number; title: string };
|
||||
});
|
||||
|
||||
const noteContent = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "note_content") return null;
|
||||
return data as { id: number; title: string; body: string; tags: string[] };
|
||||
});
|
||||
|
||||
const noteList = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "notes_list") return null;
|
||||
return (data.results as Array<{ id: number; title: string; tags: string[]; preview: string }> | undefined) ?? [];
|
||||
});
|
||||
|
||||
const noteListCount = computed(() => {
|
||||
const data = props.toolCall.result.data;
|
||||
if (!data || props.toolCall.result.type !== "notes_list") return 0;
|
||||
return (data.total as number) ?? 0;
|
||||
});
|
||||
|
||||
// ── Collapse logic ───────────────────────────────────────────────────────────
|
||||
|
||||
// Cards with rich expandable content
|
||||
const hasDetail = computed(() => {
|
||||
if (props.toolCall.status === "running") return false;
|
||||
return (
|
||||
(noteContent.value !== null && noteContent.value.tags.length > 0) ||
|
||||
(noteList.value !== null && noteList.value.length > 0) ||
|
||||
searchResults.value !== null ||
|
||||
(taskList.value !== null && taskList.value.length > 0) ||
|
||||
(eventList.value !== null && eventList.value.length > 0) ||
|
||||
(todoList.value !== null && todoList.value.length > 0) ||
|
||||
webSearch.value !== null ||
|
||||
(calendarList.value !== null && calendarList.value.length > 0) ||
|
||||
suggestedTags.value.length > 0
|
||||
);
|
||||
});
|
||||
|
||||
// Collapsed by default for completed calls; errors and running stay open
|
||||
const collapsed = ref(
|
||||
props.toolCall.status === "success" || props.toolCall.status === "declined"
|
||||
);
|
||||
|
||||
// Auto-collapse when a running tool call completes
|
||||
watch(() => props.toolCall.status, (s) => {
|
||||
if (s === "success") collapsed.value = true;
|
||||
});
|
||||
|
||||
function toggle() {
|
||||
if (hasDetail.value) collapsed.value = !collapsed.value;
|
||||
}
|
||||
|
||||
async function confirmDuplicate() {
|
||||
if (confirmState.value !== "idle") return;
|
||||
confirmState.value = "creating";
|
||||
const args = props.toolCall.arguments as Record<string, unknown>;
|
||||
const isTask = !!(args.status);
|
||||
const endpoint = isTask ? "/api/tasks" : "/api/notes";
|
||||
const payload: Record<string, unknown> = {
|
||||
title: args.title,
|
||||
body: args.body ?? "",
|
||||
tags: args.tags ?? [],
|
||||
...(args.due_date ? { due_date: args.due_date } : {}),
|
||||
...(args.priority ? { priority: args.priority } : {}),
|
||||
...(args.project ? { project: args.project } : {}),
|
||||
...(isTask ? { status: args.status ?? "todo" } : {}),
|
||||
};
|
||||
try {
|
||||
await apiPost(endpoint, payload);
|
||||
confirmState.value = "created";
|
||||
} catch {
|
||||
confirmState.value = "idle";
|
||||
}
|
||||
}
|
||||
|
||||
function denyDuplicate() {
|
||||
confirmState.value = "denied";
|
||||
}
|
||||
|
||||
async function applyTag(tag: string) {
|
||||
if (!noteId.value || appliedTags.value.has(tag) || applyingTag.value) return;
|
||||
applyingTag.value = tag;
|
||||
try {
|
||||
await apiPost(`/api/notes/${noteId.value}/append-tag`, { tag });
|
||||
appliedTags.value.add(tag);
|
||||
} catch {
|
||||
// silently fail
|
||||
} finally {
|
||||
applyingTag.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Event slide-over ─────────────────────────────────────────────────────────
|
||||
|
||||
const eventSlideOverOpen = ref(false);
|
||||
const eventSlideOverEntry = ref<EventEntry | null>(null);
|
||||
|
||||
async function openEventSlideOver(id: number | undefined) {
|
||||
if (!id) return;
|
||||
try {
|
||||
const entry = await getEvent(id);
|
||||
eventSlideOverEntry.value = entry;
|
||||
eventSlideOverOpen.value = true;
|
||||
} catch {
|
||||
// silently fail — event may have been deleted
|
||||
}
|
||||
}
|
||||
|
||||
function closeEventSlideOver(changed = false) {
|
||||
eventSlideOverOpen.value = false;
|
||||
if (changed) {
|
||||
document.dispatchEvent(new Event("fable:calendar-changed"));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="tool-call-card"
|
||||
:class="{
|
||||
error: toolCall.status === 'error' && !toolCall.result.requires_confirmation,
|
||||
'requires-confirm': toolCall.result.requires_confirmation,
|
||||
declined: toolCall.status === 'declined',
|
||||
running: toolCall.status === 'running',
|
||||
collapsible: hasDetail,
|
||||
}"
|
||||
>
|
||||
<!-- ── Header row (always visible) ─────────────────────────── -->
|
||||
<div class="tool-card-header" :class="{ clickable: hasDetail }" @click="toggle">
|
||||
<span class="tool-label">{{ label }}</span>
|
||||
|
||||
<!-- Inline summary content -->
|
||||
<template v-if="toolCall.status === 'declined'">
|
||||
<span class="tool-declined-name">
|
||||
{{ toolCall.arguments.title ?? toolCall.arguments.summary ?? toolCall.arguments.query ?? toolCall.function }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="toolCall.result.requires_confirmation">
|
||||
<router-link
|
||||
v-if="toolCall.result.similar_note"
|
||||
:to="`/notes/${toolCall.result.similar_note.id}`"
|
||||
class="tool-link"
|
||||
@click.stop
|
||||
>{{ toolCall.result.similar_note.title }}</router-link>
|
||||
<span v-else class="tool-error">{{ toolCall.result.error }}</span>
|
||||
<template v-if="confirmState === 'created'">
|
||||
<span class="confirm-created">✓ Created</span>
|
||||
</template>
|
||||
<template v-else-if="confirmState === 'denied'">
|
||||
<span class="confirm-denied">Skipped</span>
|
||||
</template>
|
||||
<template v-else-if="confirmState !== 'creating'">
|
||||
<button class="btn-confirm-duplicate" @click.stop="confirmDuplicate">Create anyway</button>
|
||||
<button class="btn-deny-duplicate" @click.stop="denyDuplicate">Skip</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="tool-summary-count">Creating…</span>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else-if="toolCall.status === 'error'">
|
||||
<span class="tool-error">{{ toolCall.result.error }}</span>
|
||||
</template>
|
||||
<template v-else-if="deletedNote">
|
||||
<span class="tool-deleted">{{ deletedNote.title || "Untitled" }}</span>
|
||||
</template>
|
||||
<template v-else-if="noteContent">
|
||||
<router-link :to="`/notes/${noteContent.id}`" class="tool-link" @click.stop>
|
||||
{{ noteContent.title || "Untitled" }}
|
||||
</router-link>
|
||||
</template>
|
||||
<template v-else-if="noteList !== null">
|
||||
<span class="tool-summary-count">{{ noteListCount }} found</span>
|
||||
</template>
|
||||
<template v-else-if="searchResults">
|
||||
<span class="tool-summary-count">
|
||||
{{ (toolCall.result.data?.count as number) ?? (toolCall.result.data?.total as number) ?? 0 }} found
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="eventData">
|
||||
<button v-if="eventData.id" class="tool-event-btn" @click.stop="openEventSlideOver(eventData.id)">
|
||||
<span class="tool-event-dot" v-if="eventData.color" :style="{ background: eventData.color }"></span>
|
||||
<span class="tool-event-title">{{ eventData.title }}</span>
|
||||
<span v-if="eventData.start_dt" class="tool-event-time">{{ formatEventTime(eventData.start_dt) }}</span>
|
||||
</button>
|
||||
<template v-else>
|
||||
<span class="tool-event-title">{{ eventData.title }}</span>
|
||||
<span v-if="eventData.start_dt" class="tool-event-time">{{ formatEventTime(eventData.start_dt) }}</span>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else-if="updatedEvent">
|
||||
<button v-if="updatedEvent.id" class="tool-event-btn" @click.stop="openEventSlideOver(updatedEvent.id)">
|
||||
<span class="tool-event-dot" v-if="updatedEvent.color" :style="{ background: updatedEvent.color }"></span>
|
||||
<span class="tool-event-title">{{ updatedEvent.title }}</span>
|
||||
<span v-if="updatedEvent.start_dt" class="tool-event-time">{{ formatEventTime(updatedEvent.start_dt) }}</span>
|
||||
</button>
|
||||
<template v-else>
|
||||
<span class="tool-event-title">{{ updatedEvent.title }}</span>
|
||||
<span v-if="updatedEvent.start_dt" class="tool-event-time">{{ formatEventTime(updatedEvent.start_dt) }}</span>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else-if="deletedEvent">
|
||||
<span class="tool-deleted">{{ deletedEvent.title }}</span>
|
||||
</template>
|
||||
<template v-else-if="calendarList !== null">
|
||||
<span class="tool-summary-count">{{ calendarList.length }} calendar{{ calendarList.length !== 1 ? "s" : "" }}</span>
|
||||
</template>
|
||||
<template v-else-if="todoData">
|
||||
<span :class="{ 'tool-deleted': toolCall.result.type === 'todo_deleted', 'tool-completed': toolCall.result.type === 'todo_completed' }">
|
||||
{{ todoData.summary }}
|
||||
</span>
|
||||
<span v-if="todoData.due" class="tool-event-time">{{ formatEventTime(todoData.due) }}</span>
|
||||
</template>
|
||||
<template v-else-if="todoList !== null">
|
||||
<span class="tool-summary-count">{{ todoCount }} found</span>
|
||||
</template>
|
||||
<template v-else-if="taskList !== null">
|
||||
<span class="tool-summary-count">{{ taskCount }} found</span>
|
||||
</template>
|
||||
<template v-else-if="eventList !== null">
|
||||
<span class="tool-summary-count">{{ eventCount }} found</span>
|
||||
</template>
|
||||
<template v-else-if="webSearch">
|
||||
<span class="tool-summary-count">
|
||||
{{ webSearch.count }} result{{ webSearch.count !== 1 ? "s" : "" }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="linkTo">
|
||||
<router-link :to="linkTo" class="tool-link" @click.stop>{{ title }}</router-link>
|
||||
</template>
|
||||
|
||||
<!-- Chevron toggle -->
|
||||
<span v-if="hasDetail" class="tool-chevron" :class="{ open: !collapsed }">▶</span>
|
||||
</div>
|
||||
|
||||
<!-- ── Detail section (expandable) ─────────────────────────── -->
|
||||
<div v-if="hasDetail" v-show="!collapsed" class="tool-card-detail">
|
||||
<template v-if="noteContent && noteContent.tags.length">
|
||||
<span class="tool-note-tags">
|
||||
<span v-for="tag in noteContent.tags" :key="tag" class="tool-note-tag">#{{ tag }}</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-else-if="noteList !== null && noteList.length > 0">
|
||||
<div class="tool-search-results">
|
||||
<router-link
|
||||
v-for="n in noteList.slice(0, 8)"
|
||||
:key="n.id"
|
||||
:to="`/notes/${n.id}`"
|
||||
class="tool-search-item"
|
||||
>{{ n.title || "Untitled" }}</router-link>
|
||||
<span v-if="noteList.length > 8" class="tool-event-more">+{{ noteList.length - 8 }} more</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="searchResults">
|
||||
<div class="tool-search-results">
|
||||
<router-link
|
||||
v-for="r in searchResults"
|
||||
:key="r.id"
|
||||
:to="`/notes/${r.id}`"
|
||||
class="tool-search-item"
|
||||
>{{ r.title || "Untitled" }}</router-link>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="todoList !== null && todoList.length > 0">
|
||||
<div class="tool-event-list">
|
||||
<div v-for="(t, i) in todoList.slice(0, 5)" :key="i" class="tool-event-item">
|
||||
<span class="tool-event-item-title">{{ t.summary }}</span>
|
||||
<span v-if="t.due" class="tool-event-item-time">{{ formatEventTime(t.due) }}</span>
|
||||
</div>
|
||||
<div v-if="todoList.length > 5" class="tool-event-more">+{{ todoList.length - 5 }} more</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="taskList !== null && taskList.length > 0">
|
||||
<div class="tool-event-list">
|
||||
<div v-for="(t, i) in taskList.slice(0, 5)" :key="i" class="tool-event-item">
|
||||
<router-link :to="`/tasks/${t.id}`" class="tool-event-item-title">{{ t.title }}</router-link>
|
||||
<span v-if="t.due_date" class="tool-event-item-time">{{ t.due_date }}</span>
|
||||
<span v-if="t.priority && t.priority !== 'none'" class="tool-task-priority" :class="`priority-${t.priority}`">{{ t.priority }}</span>
|
||||
</div>
|
||||
<div v-if="taskList.length > 5" class="tool-event-more">+{{ taskList.length - 5 }} more</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="eventList !== null && eventList.length > 0">
|
||||
<div class="tool-event-cards">
|
||||
<button
|
||||
v-for="(ev, i) in eventList.slice(0, 5)"
|
||||
:key="i"
|
||||
class="tool-event-card"
|
||||
:class="{ clickable: !!ev.id }"
|
||||
@click="openEventSlideOver(ev.id)"
|
||||
>
|
||||
<span class="tool-event-card-dot" :style="ev.color ? { background: ev.color } : {}"></span>
|
||||
<span class="tool-event-card-body">
|
||||
<span class="tool-event-card-title">{{ ev.title }}</span>
|
||||
<span v-if="ev.start_dt" class="tool-event-card-time">{{ formatEventTime(ev.start_dt) }}</span>
|
||||
<span v-if="ev.location" class="tool-event-card-loc">{{ ev.location }}</span>
|
||||
</span>
|
||||
</button>
|
||||
<div v-if="eventList.length > 5" class="tool-event-more">+{{ eventList.length - 5 }} more</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="calendarList !== null">
|
||||
<div class="tool-calendar-list">
|
||||
<span v-for="name in calendarList" :key="name" class="tool-calendar-name">{{ name }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="webSearch">
|
||||
<div class="tool-search-results web-search-results">
|
||||
<a
|
||||
v-for="(r, i) in webSearch.results"
|
||||
:key="i"
|
||||
:href="r.url"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="tool-search-item"
|
||||
>{{ r.title || r.url }}</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Suggested tags always at the bottom of detail -->
|
||||
<div v-if="suggestedTags.length > 0" class="tag-suggestions">
|
||||
<span class="tag-suggestions-label">Suggested tags:</span>
|
||||
<button
|
||||
v-for="tag in suggestedTags"
|
||||
:key="tag"
|
||||
:class="['tag-pill', { applied: appliedTags.has(tag) }]"
|
||||
:disabled="appliedTags.has(tag) || applyingTag === tag"
|
||||
@click="applyTag(tag)"
|
||||
>
|
||||
#{{ tag }}
|
||||
<span v-if="appliedTags.has(tag)" class="tag-check">✓</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Suggested tags for non-detail cards (note/task created etc.) -->
|
||||
<div v-if="!hasDetail && suggestedTags.length > 0" class="tag-suggestions">
|
||||
<span class="tag-suggestions-label">Suggested tags:</span>
|
||||
<button
|
||||
v-for="tag in suggestedTags"
|
||||
:key="tag"
|
||||
:class="['tag-pill', { applied: appliedTags.has(tag) }]"
|
||||
:disabled="appliedTags.has(tag) || applyingTag === tag"
|
||||
@click="applyTag(tag)"
|
||||
>
|
||||
#{{ tag }}
|
||||
<span v-if="appliedTags.has(tag)" class="tag-check">✓</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Event slide-over (portal-like, fixed positioned) -->
|
||||
<EventSlideOver
|
||||
v-if="eventSlideOverOpen"
|
||||
:event="eventSlideOverEntry"
|
||||
initial-date=""
|
||||
@close="closeEventSlideOver"
|
||||
@created="() => closeEventSlideOver(true)"
|
||||
@updated="() => closeEventSlideOver(true)"
|
||||
@deleted="() => closeEventSlideOver(true)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Inline ToolCallCard renders inside an assistant bubble — the bubble
|
||||
already contains it, so no outer border per the structural-not-decorative
|
||||
rule. Background tint differentiates it; error state gets a left-edge
|
||||
accent the way the assistant bubble itself uses one. */
|
||||
.tool-call-card {
|
||||
display: inline-block;
|
||||
background: var(--color-bg-secondary);
|
||||
border-radius: 10px;
|
||||
font-size: 0.8rem;
|
||||
margin-top: 0.4rem;
|
||||
overflow: hidden;
|
||||
vertical-align: top;
|
||||
}
|
||||
.tool-call-card.error {
|
||||
border-left: 3px solid var(--color-danger);
|
||||
}
|
||||
.tool-call-card.declined {
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
/* ── Header ── */
|
||||
.tool-card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.35rem;
|
||||
padding: 0.3rem 0.6rem;
|
||||
}
|
||||
.tool-card-header.clickable {
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
.tool-card-header.clickable:hover {
|
||||
background: color-mix(in srgb, var(--color-primary) 6%, transparent);
|
||||
}
|
||||
|
||||
.tool-label {
|
||||
font-weight: 500;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
font-size: 0.7rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.tool-chevron {
|
||||
font-size: 0.55rem;
|
||||
color: var(--color-text-muted);
|
||||
margin-left: auto;
|
||||
padding-left: 0.4rem;
|
||||
transition: transform 0.15s ease;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.tool-chevron.open {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.tool-summary-count {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* ── Detail ── */
|
||||
.tool-card-detail {
|
||||
padding: 0.3rem 0.6rem 0.45rem;
|
||||
border-top: 1px solid var(--color-border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
/* ── Shared content styles ── */
|
||||
.tool-link {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
}
|
||||
.tool-link:hover { text-decoration: underline; }
|
||||
|
||||
.tool-error { color: var(--color-danger, #e74c3c); }
|
||||
|
||||
.tool-declined-name {
|
||||
text-decoration: line-through;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.tool-search-results {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
.tool-search-item {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
.tool-search-item:hover { text-decoration: underline; }
|
||||
.tool-search-item:not(:last-child)::after {
|
||||
content: ",";
|
||||
color: var(--color-text-muted);
|
||||
margin-right: 0.1rem;
|
||||
}
|
||||
.web-search-results {
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
.web-search-results .tool-search-item::after { content: none; }
|
||||
|
||||
.tool-event-title { font-weight: 500; color: var(--color-text); }
|
||||
.tool-event-time { color: var(--color-text-muted); font-size: 0.75rem; }
|
||||
|
||||
.tool-event-list { display: flex; flex-direction: column; gap: 0.2rem; }
|
||||
.tool-event-item { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
|
||||
.tool-event-item-title { color: var(--color-text); font-size: 0.8rem; }
|
||||
.tool-event-item-time { color: var(--color-text-muted); font-size: 0.75rem; white-space: nowrap; }
|
||||
.tool-event-more { color: var(--color-text-muted); font-size: 0.75rem; }
|
||||
|
||||
.tool-deleted { text-decoration: line-through; opacity: 0.7; }
|
||||
.tool-completed { text-decoration: line-through; color: var(--color-success, #2ecc71); }
|
||||
|
||||
.tool-note-tags { display: flex; flex-wrap: wrap; gap: 0.2rem; }
|
||||
.tool-note-tag { font-size: 0.72rem; color: var(--color-text-muted); }
|
||||
|
||||
.tool-task-priority {
|
||||
font-size: 0.7rem; font-weight: 500; text-transform: uppercase;
|
||||
letter-spacing: 0.04em; padding: 0.1rem 0.3rem; border-radius: 3px;
|
||||
}
|
||||
.priority-high { color: var(--color-danger, #e74c3c); }
|
||||
.priority-medium { color: var(--color-warning, #f59e0b); }
|
||||
.priority-low { color: var(--color-text-muted); }
|
||||
|
||||
.tool-calendar-list { display: flex; flex-wrap: wrap; gap: 0.3rem; }
|
||||
.tool-calendar-name {
|
||||
display: inline-block; padding: 0.1rem 0.5rem;
|
||||
border-radius: 999px; background: var(--color-bg-secondary);
|
||||
border: 1px solid var(--color-border); font-size: 0.75rem; color: var(--color-text);
|
||||
}
|
||||
|
||||
/* ── Tag suggestions ── */
|
||||
.tag-suggestions {
|
||||
display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem;
|
||||
padding: 0.3rem 0.6rem; border-top: 1px solid var(--color-border);
|
||||
}
|
||||
.tool-call-card:not(:has(.tool-card-detail)) .tag-suggestions {
|
||||
/* When outside detail, no top border needed if it's the only extra content */
|
||||
}
|
||||
.tag-suggestions-label { font-size: 0.7rem; color: var(--color-text-muted); font-weight: 500; }
|
||||
|
||||
.tag-pill {
|
||||
display: inline-flex; align-items: center; gap: 0.2rem;
|
||||
padding: 0.15rem 0.5rem; border: 1px solid var(--color-primary);
|
||||
border-radius: 999px; background: transparent; color: var(--color-primary);
|
||||
font-size: 0.75rem; cursor: pointer; transition: background 0.15s, color 0.15s;
|
||||
}
|
||||
.tag-pill:hover:not(:disabled) { background: var(--color-primary); color: #fff; }
|
||||
.tag-pill.applied {
|
||||
background: var(--color-success, #2ecc71); border-color: var(--color-success, #2ecc71);
|
||||
color: #fff; cursor: default;
|
||||
}
|
||||
.tag-pill:disabled:not(.applied) { opacity: 0.6; cursor: wait; }
|
||||
.tag-check { font-size: 0.65rem; }
|
||||
|
||||
/* Duplicate confirmation */
|
||||
.tool-call-card.requires-confirm {
|
||||
border-color: color-mix(in srgb, var(--color-warning, #f59e0b) 60%, transparent);
|
||||
}
|
||||
.confirm-created {
|
||||
color: var(--color-success, #2ecc71);
|
||||
font-size: 0.78rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
.confirm-denied {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.btn-confirm-duplicate {
|
||||
padding: 0.15rem 0.5rem;
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: var(--radius-sm, 6px);
|
||||
cursor: pointer;
|
||||
font-size: 0.72rem;
|
||||
font-family: inherit;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.btn-confirm-duplicate:hover { opacity: 0.9; }
|
||||
.btn-deny-duplicate {
|
||||
padding: 0.15rem 0.5rem;
|
||||
background: none;
|
||||
color: var(--color-text-muted);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm, 6px);
|
||||
cursor: pointer;
|
||||
font-size: 0.72rem;
|
||||
font-family: inherit;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.btn-deny-duplicate:hover {
|
||||
color: var(--color-danger, #e74c3c);
|
||||
border-color: var(--color-danger, #e74c3c);
|
||||
}
|
||||
|
||||
/* ── Event header click button ── */
|
||||
.tool-event-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
.tool-event-btn:hover .tool-event-title {
|
||||
text-decoration: underline;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
.tool-event-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ── Event cards (list) ── */
|
||||
.tool-event-cards { display: flex; flex-direction: column; gap: 0.25rem; }
|
||||
.tool-event-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.45rem;
|
||||
padding: 0.3rem 0.45rem;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-bg-card, #16161a);
|
||||
text-align: left;
|
||||
font-family: inherit;
|
||||
cursor: default;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
width: 100%;
|
||||
}
|
||||
.tool-event-card.clickable { cursor: pointer; }
|
||||
.tool-event-card.clickable:hover {
|
||||
border-color: var(--color-primary);
|
||||
background: color-mix(in srgb, var(--color-primary) 6%, var(--color-bg-card, #16161a));
|
||||
}
|
||||
.tool-event-card-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
flex-shrink: 0;
|
||||
margin-top: 3px;
|
||||
}
|
||||
.tool-event-card-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.1rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.tool-event-card-title {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.tool-event-card-time {
|
||||
font-size: 0.72rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.tool-event-card-loc {
|
||||
font-size: 0.7rem;
|
||||
color: var(--color-text-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
@@ -1,108 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import type { ToolPendingRecord } from "@/types/chat";
|
||||
|
||||
const props = defineProps<{
|
||||
pendingTool: ToolPendingRecord;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "accept"): void;
|
||||
(e: "decline"): void;
|
||||
}>();
|
||||
|
||||
const label = computed(() => props.pendingTool.label ?? props.pendingTool.function);
|
||||
|
||||
const detail = computed(() => {
|
||||
const args = props.pendingTool.arguments;
|
||||
const name =
|
||||
(args.title as string | undefined) ??
|
||||
(args.summary as string | undefined) ??
|
||||
(args.query as string | undefined) ??
|
||||
"";
|
||||
return name ? `"${name}"` : "";
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="tool-confirm-card">
|
||||
<div class="tool-confirm-info">
|
||||
<span class="tool-confirm-label">{{ label }}</span>
|
||||
<span v-if="detail" class="tool-confirm-detail">{{ detail }}</span>
|
||||
</div>
|
||||
<div class="tool-confirm-actions">
|
||||
<button class="btn-accept" @click="emit('accept')">Accept</button>
|
||||
<button class="btn-decline" @click="emit('decline')">Decline</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tool-confirm-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
background: var(--color-bg-secondary);
|
||||
border: 1px solid var(--color-warning, #f59e0b);
|
||||
border-radius: 12px;
|
||||
padding: 0.45rem 0.75rem;
|
||||
font-size: 0.85rem;
|
||||
margin-top: 0.4rem;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.tool-confirm-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
.tool-confirm-label {
|
||||
font-weight: 600;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
font-size: 0.7rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tool-confirm-detail {
|
||||
color: var(--color-text);
|
||||
font-size: 0.8rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.tool-confirm-actions {
|
||||
display: flex;
|
||||
gap: 0.4rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.btn-accept,
|
||||
.btn-decline {
|
||||
padding: 0.25rem 0.65rem;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
.btn-accept {
|
||||
background: var(--color-success, #2ecc71);
|
||||
color: #fff;
|
||||
}
|
||||
.btn-decline {
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.btn-accept:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
.btn-decline:hover {
|
||||
color: var(--color-danger, #e74c3c);
|
||||
border-color: var(--color-danger, #e74c3c);
|
||||
}
|
||||
</style>
|
||||
@@ -1,391 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, nextTick, onMounted, onUnmounted, watch } from 'vue';
|
||||
import { useChatStore } from '@/stores/chat';
|
||||
import ChatPanel from '@/components/ChatPanel.vue';
|
||||
import ChatInputBar from '@/components/ChatInputBar.vue';
|
||||
import { RotateCcw, ChevronDown, ChevronUp } from 'lucide-vue-next';
|
||||
|
||||
const props = defineProps<{ projectId: number }>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'note-changed': [noteId: number];
|
||||
'task-changed': [];
|
||||
}>();
|
||||
|
||||
const chatStore = useChatStore();
|
||||
|
||||
// SSE watcher — emit refresh events when tool calls succeed during streaming
|
||||
const processedCount = ref(0);
|
||||
|
||||
watch(
|
||||
() => chatStore.streamingToolCalls,
|
||||
(calls) => {
|
||||
for (let i = processedCount.value; i < calls.length; i++) {
|
||||
const tc = calls[i];
|
||||
if (tc.status !== 'success') continue;
|
||||
|
||||
// Note-editor refresh: any successful create_note/update_note
|
||||
if (['create_note', 'update_note'].includes(tc.function) && tc.result?.data?.id) {
|
||||
emit('note-changed', tc.result.data.id as number);
|
||||
}
|
||||
|
||||
// Task-panel refresh: milestone changes, or note changes where the note is a task (has status)
|
||||
const isTaskNoteChange =
|
||||
['create_note', 'update_note'].includes(tc.function) &&
|
||||
tc.result?.data?.status !== undefined;
|
||||
const isMilestoneChange = ['create_milestone', 'update_milestone'].includes(tc.function);
|
||||
if (isTaskNoteChange || isMilestoneChange) {
|
||||
emit('task-changed');
|
||||
}
|
||||
}
|
||||
processedCount.value = calls.length;
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
watch(
|
||||
() => chatStore.streaming,
|
||||
(s) => {
|
||||
if (!s) processedCount.value = 0;
|
||||
}
|
||||
);
|
||||
|
||||
type WidgetState = 'collapsed' | 'expanded';
|
||||
const widgetState = ref<WidgetState>('collapsed');
|
||||
|
||||
const chatPanelRef = ref<InstanceType<typeof ChatPanel> | null>(null);
|
||||
const inputBarRef = ref<InstanceType<typeof ChatInputBar> | null>(null);
|
||||
|
||||
const workspaceConvId = ref<number | null>(null);
|
||||
let isNewConv = false;
|
||||
|
||||
const historyOpen = ref(false);
|
||||
|
||||
const projectConversations = computed(() =>
|
||||
chatStore.conversations
|
||||
.filter((c) => c.rag_project_id === props.projectId)
|
||||
.slice()
|
||||
.sort((a, b) => (b.updated_at || '').localeCompare(a.updated_at || ''))
|
||||
);
|
||||
|
||||
async function pickConversation(convId: number) {
|
||||
historyOpen.value = false;
|
||||
if (convId === workspaceConvId.value) return;
|
||||
await chatStore.fetchConversation(convId);
|
||||
workspaceConvId.value = convId;
|
||||
// The picked conversation already exists on the server; not ours to clean up.
|
||||
isNewConv = false;
|
||||
localStorage.setItem(_storageKey(props.projectId), String(convId));
|
||||
}
|
||||
|
||||
function toggleHistory() {
|
||||
historyOpen.value = !historyOpen.value;
|
||||
}
|
||||
|
||||
function conversationLabel(c: { id: number; title?: string | null }): string {
|
||||
return (c.title && c.title.trim()) || `Conversation #${c.id}`;
|
||||
}
|
||||
|
||||
function _storageKey(pid: number) {
|
||||
return `workspace_conv_${pid}`;
|
||||
}
|
||||
|
||||
function expand() {
|
||||
widgetState.value = 'expanded';
|
||||
nextTick(() => chatPanelRef.value?.focus());
|
||||
}
|
||||
function collapse() {
|
||||
widgetState.value = 'collapsed';
|
||||
nextTick(() => inputBarRef.value?.focus());
|
||||
}
|
||||
|
||||
async function restart() {
|
||||
const conv = await chatStore.createConversation();
|
||||
workspaceConvId.value = conv.id;
|
||||
isNewConv = true;
|
||||
localStorage.setItem(_storageKey(props.projectId), String(conv.id));
|
||||
await chatStore.fetchConversation(conv.id);
|
||||
}
|
||||
|
||||
/** Auto-expand and send — used when user submits from collapsed input. */
|
||||
async function onCollapsedSubmit(payload: { content: string; contextNoteId?: number }) {
|
||||
widgetState.value = 'expanded';
|
||||
await chatStore.sendMessage(payload.content, payload.contextNoteId, undefined, false);
|
||||
}
|
||||
|
||||
function prefill(text: string) {
|
||||
if (widgetState.value === 'expanded') {
|
||||
chatPanelRef.value?.prefill(text);
|
||||
} else {
|
||||
inputBarRef.value?.prefill(text);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (chatStore.conversations.length === 0) {
|
||||
await chatStore.fetchConversations();
|
||||
}
|
||||
|
||||
const key = _storageKey(props.projectId);
|
||||
const storedId = localStorage.getItem(key);
|
||||
|
||||
if (storedId) {
|
||||
const existingId = Number(storedId);
|
||||
try {
|
||||
await chatStore.fetchConversation(existingId);
|
||||
workspaceConvId.value = existingId;
|
||||
isNewConv = false;
|
||||
chatStore.reconnectIfGenerating(existingId);
|
||||
} catch {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (workspaceConvId.value === null) {
|
||||
const conv = await chatStore.createConversation();
|
||||
workspaceConvId.value = conv.id;
|
||||
isNewConv = true;
|
||||
await chatStore.fetchConversation(conv.id);
|
||||
localStorage.setItem(key, String(conv.id));
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(async () => {
|
||||
if (workspaceConvId.value !== null && isNewConv) {
|
||||
const id = workspaceConvId.value;
|
||||
const conv = chatStore.conversations.find((c) => c.id === id);
|
||||
if (conv && conv.message_count === 0) {
|
||||
await chatStore.deleteConversation(id);
|
||||
localStorage.removeItem(_storageKey(props.projectId));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
defineExpose({ prefill });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Bottom-anchored chat dock: collapsed (input only) or expanded (full panel) -->
|
||||
<div
|
||||
class="ws-chat-widget"
|
||||
:class="{ 'ws-chat-widget--expanded': widgetState === 'expanded' }"
|
||||
>
|
||||
<!-- Header (expanded only) -->
|
||||
<div v-if="widgetState === 'expanded'" class="ws-chat-header">
|
||||
<span class="ws-chat-title">Project chat</span>
|
||||
<div class="ws-chat-header-actions">
|
||||
<div class="ws-chat-history-wrap">
|
||||
<button
|
||||
class="btn-icon-sm"
|
||||
:class="{ active: historyOpen }"
|
||||
title="History"
|
||||
@click="toggleHistory"
|
||||
>
|
||||
<ChevronDown :size="16" />
|
||||
</button>
|
||||
<div v-if="historyOpen" class="ws-chat-history-menu">
|
||||
<div v-if="projectConversations.length === 0" class="ws-chat-history-empty">
|
||||
No past conversations
|
||||
</div>
|
||||
<button
|
||||
v-for="c in projectConversations"
|
||||
:key="c.id"
|
||||
class="ws-chat-history-item"
|
||||
:class="{ current: c.id === workspaceConvId }"
|
||||
@click="pickConversation(c.id)"
|
||||
>
|
||||
<span class="ws-chat-history-title">{{ conversationLabel(c) }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn-icon-sm" title="Restart conversation" @click="restart">
|
||||
<RotateCcw :size="16" />
|
||||
</button>
|
||||
<button class="btn-icon-sm" title="Collapse" @click="collapse">
|
||||
<ChevronDown :size="16" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Expanded body: full ChatPanel (includes its own input bar) -->
|
||||
<div v-if="widgetState === 'expanded'" class="ws-chat-body">
|
||||
<ChatPanel
|
||||
ref="chatPanelRef"
|
||||
variant="full"
|
||||
:projectId="projectId"
|
||||
placeholder="Message the agent…"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Collapsed: standalone input bar with expand affordance -->
|
||||
<div v-else class="ws-chat-collapsed">
|
||||
<button class="ws-chat-expand-btn" title="Expand chat" @click="expand">
|
||||
<ChevronUp :size="16" />
|
||||
</button>
|
||||
<div class="ws-chat-input-row">
|
||||
<ChatInputBar
|
||||
ref="inputBarRef"
|
||||
placeholder="Message the agent…"
|
||||
@submit="onCollapsedSubmit"
|
||||
@abort="chatStore.cancelGeneration()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ws-chat-widget {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
max-width: var(--page-max-width);
|
||||
margin-inline: auto;
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--color-bg-secondary);
|
||||
border-radius: 16px 16px 0 0;
|
||||
box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35), 0 -1px 0 rgba(255, 255, 255, 0.05);
|
||||
overflow: hidden;
|
||||
transition: height 0.2s ease;
|
||||
}
|
||||
.ws-chat-widget--expanded {
|
||||
height: 500px;
|
||||
}
|
||||
|
||||
.ws-chat-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 14px;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ws-chat-title {
|
||||
font-size: 0.78rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.ws-chat-header-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
}
|
||||
.btn-icon-sm {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
padding: 2px 6px;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.btn-icon-sm:hover:not(:disabled) {
|
||||
color: var(--color-text);
|
||||
background: color-mix(in srgb, var(--color-primary) 10%, transparent);
|
||||
}
|
||||
.btn-icon-sm:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.btn-icon-sm.active {
|
||||
color: var(--color-primary);
|
||||
background: color-mix(in srgb, var(--color-primary) 12%, transparent);
|
||||
}
|
||||
|
||||
.ws-chat-history-wrap {
|
||||
position: relative;
|
||||
}
|
||||
.ws-chat-history-menu {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
right: 0;
|
||||
margin-top: 4px;
|
||||
min-width: 220px;
|
||||
max-height: 260px;
|
||||
overflow-y: auto;
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
|
||||
z-index: 30;
|
||||
padding: 4px;
|
||||
}
|
||||
.ws-chat-history-empty {
|
||||
padding: 10px 12px;
|
||||
font-size: 0.82rem;
|
||||
color: var(--color-text-muted);
|
||||
text-align: center;
|
||||
}
|
||||
.ws-chat-history-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
color: var(--color-text);
|
||||
font-size: 0.85rem;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
.ws-chat-history-item:hover {
|
||||
background: color-mix(in srgb, var(--color-primary) 10%, transparent);
|
||||
}
|
||||
.ws-chat-history-item.current {
|
||||
color: var(--color-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
.ws-chat-history-title {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ws-chat-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.ws-chat-body :deep(.chat-body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.ws-chat-collapsed {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
}
|
||||
.ws-chat-expand-btn {
|
||||
flex-shrink: 0;
|
||||
padding: 0 10px;
|
||||
background: none;
|
||||
border: none;
|
||||
border-right: 1px solid var(--color-border);
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.ws-chat-expand-btn:hover {
|
||||
color: var(--color-primary);
|
||||
background: color-mix(in srgb, var(--color-primary) 8%, transparent);
|
||||
}
|
||||
|
||||
.ws-chat-input-row {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding: 10px 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,168 +0,0 @@
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import type { Ref, ComputedRef } from 'vue'
|
||||
import { synthesiseSpeech } from '@/api/client'
|
||||
import { useVoiceAudio } from '@/composables/useVoiceAudio'
|
||||
|
||||
/** Minimum stripped character count to bother synthesizing. */
|
||||
const MIN_CHARS = 3
|
||||
|
||||
/** Matches sentence-terminal punctuation followed by whitespace or end-of-string. */
|
||||
const SENTENCE_BOUNDARY = /[.!?]+(?=\s|$)/
|
||||
|
||||
function stripMarkdown(text: string): string {
|
||||
return text
|
||||
.replace(/```[\s\S]*?```/g, '')
|
||||
.replace(/`[^`]+`/g, (m) => m.slice(1, -1))
|
||||
.replace(/#{1,6}\s+/g, '')
|
||||
.replace(/\*\*([^*]+)\*\*/g, '$1')
|
||||
.replace(/\*([^*]+)\*/g, '$1')
|
||||
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
||||
.replace(/^\s*[-*+]\s+/gm, '')
|
||||
.replace(/\n{2,}/g, ' ')
|
||||
.trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract completed sentences from `text` using SENTENCE_BOUNDARY.
|
||||
* Returns the sentences found and the unconsumed remainder.
|
||||
*/
|
||||
function extractSentences(text: string): { sentences: string[]; remainder: string } {
|
||||
const sentences: string[] = []
|
||||
let remaining = text
|
||||
let match: RegExpExecArray | null
|
||||
|
||||
while ((match = SENTENCE_BOUNDARY.exec(remaining)) !== null) {
|
||||
const boundary = match.index + match[0].length
|
||||
const sentence = remaining.slice(0, boundary).trim()
|
||||
if (sentence) sentences.push(sentence)
|
||||
remaining = remaining.slice(boundary)
|
||||
}
|
||||
|
||||
return { sentences, remainder: remaining }
|
||||
}
|
||||
|
||||
export interface UseStreamingTtsOptions {
|
||||
streamingContent: Ref<string> | ComputedRef<string>
|
||||
streaming: Ref<boolean> | ComputedRef<boolean>
|
||||
enabled: Ref<boolean> | ComputedRef<boolean>
|
||||
}
|
||||
|
||||
export interface UseStreamingTtsReturn {
|
||||
/** True while any synthesis request is in-flight or audio is playing. */
|
||||
speaking: ComputedRef<boolean>
|
||||
/** Cancel all in-flight synthesis/playback and clear the queue. */
|
||||
stop: () => void
|
||||
/** Speak a complete text through the same sentence-chunking pipeline. */
|
||||
speak: (text: string) => void
|
||||
}
|
||||
|
||||
export function useStreamingTts(options: UseStreamingTtsOptions): UseStreamingTtsReturn {
|
||||
const { streamingContent, streaming, enabled } = options
|
||||
const audio = useVoiceAudio()
|
||||
|
||||
let sentenceBuffer = ''
|
||||
let lastSeenLength = 0
|
||||
let abortId = 0
|
||||
let playQueue: Promise<void> = Promise.resolve()
|
||||
const pendingCount = ref(0)
|
||||
|
||||
const speaking = computed(() => pendingCount.value > 0 || audio.playing.value)
|
||||
|
||||
function stop(): void {
|
||||
abortId++
|
||||
sentenceBuffer = ''
|
||||
lastSeenLength = 0
|
||||
playQueue = Promise.resolve()
|
||||
audio.stop()
|
||||
pendingCount.value = 0
|
||||
}
|
||||
|
||||
async function enqueueSentence(sentence: string, myAbortId: number): Promise<void> {
|
||||
const stripped = stripMarkdown(sentence)
|
||||
if (stripped.length < MIN_CHARS) return
|
||||
|
||||
pendingCount.value++
|
||||
let blob: Blob | null = null
|
||||
try {
|
||||
blob = await synthesiseSpeech(stripped)
|
||||
} catch (e) {
|
||||
const errMsg = e instanceof Error ? e.message : String(e)
|
||||
console.warn('[StreamingTTS] Synthesis failed, retrying', {
|
||||
chars: stripped.length,
|
||||
preview: stripped.slice(0, 80),
|
||||
error: errMsg,
|
||||
})
|
||||
try {
|
||||
blob = await synthesiseSpeech(stripped)
|
||||
} catch (e2) {
|
||||
const errMsg2 = e2 instanceof Error ? e2.message : String(e2)
|
||||
console.warn('[StreamingTTS] Retry failed, sentence dropped', {
|
||||
chars: stripped.length,
|
||||
preview: stripped.slice(0, 80),
|
||||
error: errMsg2,
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
pendingCount.value--
|
||||
}
|
||||
|
||||
if (!blob) return
|
||||
|
||||
// Capture blob for the closure — TS can't narrow after async gap
|
||||
const resolvedBlob = blob
|
||||
playQueue = playQueue.then(async () => {
|
||||
if (abortId !== myAbortId) return
|
||||
await audio.play(resolvedBlob)
|
||||
})
|
||||
}
|
||||
|
||||
function dispatchBuffer(flush: boolean): void {
|
||||
if (!enabled.value) return
|
||||
const myAbortId = abortId
|
||||
const { sentences, remainder } = extractSentences(sentenceBuffer)
|
||||
sentenceBuffer = flush ? '' : remainder
|
||||
for (const sentence of sentences) {
|
||||
enqueueSentence(sentence, myAbortId)
|
||||
}
|
||||
if (flush && remainder.trim().length >= MIN_CHARS) {
|
||||
enqueueSentence(remainder.trim(), myAbortId)
|
||||
}
|
||||
}
|
||||
|
||||
// Watch accumulating content — extract new characters since last check
|
||||
watch(streamingContent, (newContent) => {
|
||||
if (!enabled.value) return
|
||||
const delta = newContent.slice(lastSeenLength)
|
||||
lastSeenLength = newContent.length
|
||||
sentenceBuffer += delta
|
||||
dispatchBuffer(false)
|
||||
})
|
||||
|
||||
// Watch streaming flag — stop on new message start, flush on end
|
||||
watch(streaming, (isStreaming) => {
|
||||
if (!enabled.value) return
|
||||
if (isStreaming) {
|
||||
// New message starting — cancel previous response's audio
|
||||
stop()
|
||||
} else {
|
||||
// Stream ended — flush any remaining fragment
|
||||
dispatchBuffer(true)
|
||||
lastSeenLength = 0
|
||||
}
|
||||
})
|
||||
|
||||
function speak(text: string): void {
|
||||
stop()
|
||||
if (!text.trim()) return
|
||||
const myAbortId = abortId
|
||||
const { sentences, remainder } = extractSentences(text)
|
||||
for (const sentence of sentences) {
|
||||
enqueueSentence(sentence, myAbortId)
|
||||
}
|
||||
if (remainder.trim().length >= MIN_CHARS) {
|
||||
enqueueSentence(remainder.trim(), myAbortId)
|
||||
}
|
||||
}
|
||||
|
||||
return { speaking, stop, speak }
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
import { ref, readonly } from 'vue'
|
||||
|
||||
const VOLUME_KEY = 'fa_voice_volume'
|
||||
|
||||
// Shared volume across all instances — persisted to localStorage per device
|
||||
const _volume = ref<number>(parseFloat(localStorage.getItem(VOLUME_KEY) ?? '1.0'))
|
||||
|
||||
export function useVoiceAudio() {
|
||||
const playing = ref(false)
|
||||
const isSupported = typeof AudioContext !== 'undefined' || typeof (window as unknown as Record<string, unknown>).webkitAudioContext !== 'undefined'
|
||||
|
||||
let audioCtx: AudioContext | null = null
|
||||
let currentSource: AudioBufferSourceNode | null = null
|
||||
|
||||
function _getCtx(): AudioContext {
|
||||
if (!audioCtx || audioCtx.state === 'closed') {
|
||||
const Ctx = window.AudioContext ?? (window as unknown as Record<string, typeof AudioContext>).webkitAudioContext
|
||||
audioCtx = new Ctx()
|
||||
}
|
||||
return audioCtx
|
||||
}
|
||||
|
||||
async function play(blob: Blob): Promise<void> {
|
||||
stop()
|
||||
const ctx = _getCtx()
|
||||
if (ctx.state === 'suspended') await ctx.resume()
|
||||
|
||||
const arrayBuffer = await blob.arrayBuffer()
|
||||
const audioBuffer = await ctx.decodeAudioData(arrayBuffer)
|
||||
|
||||
const source = ctx.createBufferSource()
|
||||
source.buffer = audioBuffer
|
||||
|
||||
const gain = ctx.createGain()
|
||||
gain.gain.value = _volume.value
|
||||
source.connect(gain)
|
||||
gain.connect(ctx.destination)
|
||||
|
||||
currentSource = source
|
||||
playing.value = true
|
||||
|
||||
return new Promise<void>((resolve) => {
|
||||
source.onended = () => {
|
||||
playing.value = false
|
||||
currentSource = null
|
||||
resolve()
|
||||
}
|
||||
source.start(0)
|
||||
})
|
||||
}
|
||||
|
||||
function stop(): void {
|
||||
if (currentSource) {
|
||||
try { currentSource.stop() } catch { /* already stopped */ }
|
||||
currentSource = null
|
||||
}
|
||||
playing.value = false
|
||||
}
|
||||
|
||||
return {
|
||||
playing: readonly(playing),
|
||||
volume: _volume,
|
||||
isSupported,
|
||||
play,
|
||||
stop,
|
||||
}
|
||||
}
|
||||
|
||||
export function setVoiceVolume(v: number) {
|
||||
_volume.value = Math.max(0, Math.min(1, v))
|
||||
localStorage.setItem(VOLUME_KEY, String(_volume.value))
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
import { ref, readonly, type Ref } from 'vue'
|
||||
|
||||
/**
|
||||
* Push-to-talk recorder wrapping the browser MediaRecorder API.
|
||||
*
|
||||
* Usage:
|
||||
* const { recording, error, isSupported, startRecording, stopRecording } = useVoiceRecorder()
|
||||
* await startRecording()
|
||||
* const blob = await stopRecording() // resolves with the recorded audio Blob
|
||||
*/
|
||||
export function useVoiceRecorder() {
|
||||
const recording = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
const isSupported = typeof MediaRecorder !== 'undefined' && !!navigator.mediaDevices?.getUserMedia
|
||||
|
||||
let mediaRecorder: MediaRecorder | null = null
|
||||
let chunks: Blob[] = []
|
||||
const streamRef = ref<MediaStream | null>(null)
|
||||
let resolveStop: ((blob: Blob) => void) | null = null
|
||||
let rejectStop: ((err: Error) => void) | null = null
|
||||
|
||||
async function startRecording(): Promise<void> {
|
||||
error.value = null
|
||||
if (!isSupported) {
|
||||
error.value = 'Audio recording is not supported in this browser'
|
||||
return
|
||||
}
|
||||
if (recording.value) return
|
||||
|
||||
try {
|
||||
streamRef.value = await navigator.mediaDevices.getUserMedia({ audio: true })
|
||||
} catch (e) {
|
||||
error.value = 'Microphone access denied'
|
||||
return
|
||||
}
|
||||
|
||||
chunks = []
|
||||
const mimeType = MediaRecorder.isTypeSupported('audio/webm;codecs=opus')
|
||||
? 'audio/webm;codecs=opus'
|
||||
: MediaRecorder.isTypeSupported('audio/webm')
|
||||
? 'audio/webm'
|
||||
: ''
|
||||
|
||||
mediaRecorder = mimeType ? new MediaRecorder(streamRef.value!, { mimeType }) : new MediaRecorder(streamRef.value!)
|
||||
|
||||
mediaRecorder.ondataavailable = (e) => {
|
||||
if (e.data.size > 0) chunks.push(e.data)
|
||||
}
|
||||
|
||||
mediaRecorder.onstop = () => {
|
||||
const blob = new Blob(chunks, { type: mediaRecorder?.mimeType ?? 'audio/webm' })
|
||||
chunks = []
|
||||
streamRef.value?.getTracks().forEach((t) => t.stop())
|
||||
streamRef.value = null
|
||||
recording.value = false
|
||||
resolveStop?.(blob)
|
||||
resolveStop = null
|
||||
rejectStop = null
|
||||
}
|
||||
|
||||
mediaRecorder.onerror = () => {
|
||||
recording.value = false
|
||||
error.value = 'Recording error'
|
||||
rejectStop?.(new Error('MediaRecorder error'))
|
||||
resolveStop = null
|
||||
rejectStop = null
|
||||
}
|
||||
|
||||
mediaRecorder.start(100) // collect in 100ms chunks
|
||||
recording.value = true
|
||||
}
|
||||
|
||||
function stopRecording(): Promise<Blob> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!mediaRecorder || !recording.value) {
|
||||
reject(new Error('Not recording'))
|
||||
return
|
||||
}
|
||||
resolveStop = resolve
|
||||
rejectStop = reject
|
||||
mediaRecorder.stop()
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
recording: readonly(recording),
|
||||
error: readonly(error),
|
||||
isSupported,
|
||||
startRecording,
|
||||
stopRecording,
|
||||
stream: readonly(streamRef) as Readonly<Ref<MediaStream | null>>,
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,10 @@ const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
// Root lands on the journal. To revert to Knowledge as home, change
|
||||
// the redirect target below to "/knowledge" (Knowledge stays a real
|
||||
// route at /knowledge, so the swap is a one-line edit).
|
||||
// Knowledge is the landing page in the MCP-first architecture
|
||||
// (chat / journal / workspace surfaces have been removed).
|
||||
path: "/",
|
||||
redirect: "/journal",
|
||||
redirect: "/knowledge",
|
||||
},
|
||||
{
|
||||
path: "/knowledge",
|
||||
@@ -80,11 +79,6 @@ const router = createRouter({
|
||||
name: "project-view",
|
||||
component: () => import("@/views/ProjectView.vue"),
|
||||
},
|
||||
{
|
||||
path: "/workspace/:projectId",
|
||||
name: "workspace",
|
||||
component: () => import("@/views/WorkspaceView.vue"),
|
||||
},
|
||||
{
|
||||
path: "/tasks",
|
||||
redirect: "/",
|
||||
@@ -99,16 +93,6 @@ const router = createRouter({
|
||||
name: "task-edit",
|
||||
component: () => import("@/views/TaskEditorView.vue"),
|
||||
},
|
||||
{
|
||||
path: "/chat",
|
||||
name: "chat",
|
||||
component: () => import("@/views/ChatView.vue"),
|
||||
},
|
||||
{
|
||||
path: "/chat/:id",
|
||||
name: "chat-conversation",
|
||||
component: () => import("@/views/ChatView.vue"),
|
||||
},
|
||||
{
|
||||
path: "/shared",
|
||||
name: "shared-with-me",
|
||||
@@ -119,11 +103,6 @@ const router = createRouter({
|
||||
name: "calendar",
|
||||
component: () => import("@/views/CalendarView.vue"),
|
||||
},
|
||||
{
|
||||
path: "/journal",
|
||||
name: "journal",
|
||||
component: () => import("@/views/JournalView.vue"),
|
||||
},
|
||||
{
|
||||
path: "/settings",
|
||||
name: "settings",
|
||||
|
||||
@@ -1,640 +0,0 @@
|
||||
import { ref, computed } from "vue";
|
||||
import { defineStore } from "pinia";
|
||||
import {
|
||||
apiGet,
|
||||
apiPost,
|
||||
apiPatch,
|
||||
apiDelete,
|
||||
apiSSEStream,
|
||||
} from "@/api/client";
|
||||
import { useToastStore } from "@/stores/toast";
|
||||
import type {
|
||||
Conversation,
|
||||
ConversationDetail,
|
||||
ContextMeta,
|
||||
GenerationTiming,
|
||||
Message,
|
||||
OllamaStatus,
|
||||
SendMessageResponse,
|
||||
ToolCallRecord,
|
||||
ToolPendingRecord,
|
||||
} from "@/types/chat";
|
||||
|
||||
interface ConvStreamState {
|
||||
streaming: boolean;
|
||||
content: string;
|
||||
thinking: string;
|
||||
toolCalls: ToolCallRecord[];
|
||||
status: string;
|
||||
pendingTool: ToolPendingRecord | null;
|
||||
contextMeta: ContextMeta | null;
|
||||
}
|
||||
|
||||
interface QueuedMessage {
|
||||
content: string;
|
||||
contextNoteId?: number | null;
|
||||
includeNoteIds?: number[];
|
||||
think: boolean;
|
||||
contextNoteTitle?: string;
|
||||
excludeNoteIds?: number[];
|
||||
ragProjectId?: number | null;
|
||||
workspaceProjectId?: number | null;
|
||||
}
|
||||
|
||||
export const useChatStore = defineStore("chat", () => {
|
||||
const conversations = ref<Conversation[]>([]);
|
||||
const currentConversation = ref<ConversationDetail | null>(null);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
const convStreams = ref<Record<number, ConvStreamState>>({});
|
||||
const convQueues = ref<Record<number, QueuedMessage[]>>({});
|
||||
const ollamaStatus = ref<"checking" | "available" | "unavailable">("checking");
|
||||
const modelStatus = ref<"checking" | "loaded" | "cold" | "not_found">("checking");
|
||||
const defaultModel = ref("");
|
||||
let statusPollTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function _getOrInitStream(id: number): ConvStreamState {
|
||||
if (!convStreams.value[id]) {
|
||||
convStreams.value[id] = {
|
||||
streaming: false, content: "", thinking: "", toolCalls: [],
|
||||
status: "", pendingTool: null, contextMeta: null,
|
||||
};
|
||||
}
|
||||
return convStreams.value[id];
|
||||
}
|
||||
|
||||
// Per-conversation computed getters — same names as old refs, zero callers change
|
||||
const streaming = computed(() => {
|
||||
const id = currentConversation.value?.id;
|
||||
return !!id && (convStreams.value[id]?.streaming ?? false);
|
||||
});
|
||||
const streamingContent = computed(() => convStreams.value[currentConversation.value?.id ?? 0]?.content ?? "");
|
||||
const streamingThinking = computed(() => convStreams.value[currentConversation.value?.id ?? 0]?.thinking ?? "");
|
||||
const streamingToolCalls = computed(() => convStreams.value[currentConversation.value?.id ?? 0]?.toolCalls ?? []);
|
||||
const streamingStatus = computed(() => convStreams.value[currentConversation.value?.id ?? 0]?.status ?? "");
|
||||
const streamingPendingTool = computed(() => convStreams.value[currentConversation.value?.id ?? 0]?.pendingTool ?? null);
|
||||
const lastContextMeta = computed(() => convStreams.value[currentConversation.value?.id ?? 0]?.contextMeta ?? null);
|
||||
|
||||
const ragProjectId = computed<number | null>(
|
||||
() => currentConversation.value?.rag_project_id ?? null
|
||||
);
|
||||
|
||||
async function updateRagScope(convId: number, ragProjectId: number | null): Promise<void> {
|
||||
await apiPatch(`/api/chat/conversations/${convId}`, { rag_project_id: ragProjectId });
|
||||
if (currentConversation.value?.id === convId) {
|
||||
currentConversation.value.rag_project_id = ragProjectId;
|
||||
}
|
||||
}
|
||||
|
||||
function isStreamingConv(id: number): boolean {
|
||||
return convStreams.value[id]?.streaming ?? false;
|
||||
}
|
||||
|
||||
const queuedCount = computed(() => {
|
||||
const id = currentConversation.value?.id;
|
||||
return id ? (convQueues.value[id]?.length ?? 0) : 0;
|
||||
});
|
||||
|
||||
const queuedMessages = computed(() => {
|
||||
const id = currentConversation.value?.id;
|
||||
return id ? (convQueues.value[id] ?? []) : [];
|
||||
});
|
||||
|
||||
function _saveQueue(convId: number) {
|
||||
const q = convQueues.value[convId] ?? [];
|
||||
if (q.length) {
|
||||
localStorage.setItem(`fa_conv_queue_${convId}`, JSON.stringify(q));
|
||||
} else {
|
||||
localStorage.removeItem(`fa_conv_queue_${convId}`);
|
||||
}
|
||||
}
|
||||
|
||||
function _loadQueue(convId: number) {
|
||||
try {
|
||||
const raw = localStorage.getItem(`fa_conv_queue_${convId}`);
|
||||
if (raw) {
|
||||
convQueues.value[convId] = JSON.parse(raw) as QueuedMessage[];
|
||||
}
|
||||
} catch {
|
||||
// ignore corrupt data
|
||||
}
|
||||
}
|
||||
|
||||
// Drain the next queued message for a conversation, if conditions are met.
|
||||
// Called both at stream-end and after fetchConversation, so orphaned queue
|
||||
// messages (e.g. from a navigation away mid-stream) are picked up on return.
|
||||
function _tryDrainQueue(convId: number) {
|
||||
const queue = convQueues.value[convId];
|
||||
if (!queue?.length) return;
|
||||
if (isStreamingConv(convId)) return; // stream-end will drain naturally
|
||||
if (currentConversation.value?.id !== convId) return; // not our conversation
|
||||
const next = queue.shift()!;
|
||||
_saveQueue(convId);
|
||||
setTimeout(() => sendMessage(
|
||||
next.content,
|
||||
next.contextNoteId,
|
||||
next.includeNoteIds,
|
||||
next.think,
|
||||
next.contextNoteTitle,
|
||||
next.excludeNoteIds,
|
||||
next.ragProjectId,
|
||||
next.workspaceProjectId,
|
||||
), 0);
|
||||
}
|
||||
|
||||
function clearQueue() {
|
||||
const id = currentConversation.value?.id;
|
||||
if (id) {
|
||||
convQueues.value[id] = [];
|
||||
_saveQueue(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Chat is usable when Ollama is up and model is at least installed (cold starts still work)
|
||||
const chatReady = computed(
|
||||
() => ollamaStatus.value === "available" && (modelStatus.value === "loaded" || modelStatus.value === "cold")
|
||||
);
|
||||
|
||||
async function fetchConversations(limit = 50, offset = 0) {
|
||||
loading.value = true;
|
||||
try {
|
||||
const data = await apiGet<{ conversations: Conversation[]; total: number }>(
|
||||
`/api/chat/conversations?limit=${limit}&offset=${offset}`
|
||||
);
|
||||
conversations.value = data.conversations;
|
||||
total.value = data.total;
|
||||
} catch (e) {
|
||||
useToastStore().show("Failed to load conversations", "error");
|
||||
throw e;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createConversation(title = ""): Promise<Conversation> {
|
||||
try {
|
||||
const conv = await apiPost<Conversation>("/api/chat/conversations", {
|
||||
title,
|
||||
});
|
||||
conversations.value.unshift(conv);
|
||||
return conv;
|
||||
} catch (e) {
|
||||
useToastStore().show("Failed to create conversation", "error");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchConversation(id: number) {
|
||||
loading.value = true;
|
||||
try {
|
||||
currentConversation.value = await apiGet<ConversationDetail>(
|
||||
`/api/chat/conversations/${id}`
|
||||
);
|
||||
_loadQueue(id);
|
||||
// Drain any messages that were queued but never sent because the user
|
||||
// navigated away before the previous stream finished.
|
||||
_tryDrainQueue(id);
|
||||
} catch (e) {
|
||||
useToastStore().show("Failed to load conversation", "error");
|
||||
throw e;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function bulkDeleteConversations(ids: number[]) {
|
||||
if (!ids.length) return;
|
||||
await apiPost("/api/chat/conversations/bulk-delete", { ids });
|
||||
const idSet = new Set(ids);
|
||||
conversations.value = conversations.value.filter((c) => !idSet.has(c.id));
|
||||
if (currentConversation.value && idSet.has(currentConversation.value.id)) {
|
||||
currentConversation.value = null;
|
||||
}
|
||||
for (const id of ids) {
|
||||
delete convStreams.value[id];
|
||||
delete convQueues.value[id];
|
||||
localStorage.removeItem(`fa_conv_queue_${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteConversation(id: number) {
|
||||
try {
|
||||
await apiDelete(`/api/chat/conversations/${id}`);
|
||||
conversations.value = conversations.value.filter((c) => c.id !== id);
|
||||
if (currentConversation.value?.id === id) {
|
||||
currentConversation.value = null;
|
||||
}
|
||||
delete convStreams.value[id];
|
||||
delete convQueues.value[id];
|
||||
localStorage.removeItem(`fa_conv_queue_${id}`);
|
||||
} catch (e) {
|
||||
useToastStore().show("Failed to delete conversation", "error");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function updateTitle(id: number, title: string) {
|
||||
try {
|
||||
const updated = await apiPatch<Conversation>(
|
||||
`/api/chat/conversations/${id}`,
|
||||
{ title }
|
||||
);
|
||||
const idx = conversations.value.findIndex((c) => c.id === id);
|
||||
if (idx !== -1) {
|
||||
conversations.value[idx] = { ...conversations.value[idx], ...updated };
|
||||
}
|
||||
if (currentConversation.value?.id === id) {
|
||||
currentConversation.value.title = updated.title;
|
||||
}
|
||||
} catch (e) {
|
||||
useToastStore().show("Failed to update title", "error");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function sendMessage(
|
||||
content: string,
|
||||
contextNoteId?: number | null,
|
||||
includeNoteIds?: number[],
|
||||
think = false,
|
||||
contextNoteTitle?: string,
|
||||
excludeNoteIds?: number[],
|
||||
ragProjectId?: number | null,
|
||||
workspaceProjectId?: number | null,
|
||||
) {
|
||||
if (!currentConversation.value) return;
|
||||
|
||||
const convId = currentConversation.value.id;
|
||||
const s = _getOrInitStream(convId);
|
||||
|
||||
// If already streaming, queue the message for after the current stream ends.
|
||||
if (s.streaming) {
|
||||
if (!convQueues.value[convId]) convQueues.value[convId] = [];
|
||||
convQueues.value[convId].push({
|
||||
content, contextNoteId, includeNoteIds, think, contextNoteTitle,
|
||||
excludeNoteIds, ragProjectId, workspaceProjectId,
|
||||
});
|
||||
_saveQueue(convId);
|
||||
return;
|
||||
}
|
||||
|
||||
s.contextMeta = null;
|
||||
|
||||
// If a write tool is waiting for confirmation, intercept single-word yes/no
|
||||
// responses rather than sending them as a new message.
|
||||
if (s.pendingTool) {
|
||||
const lower = content.trim().toLowerCase();
|
||||
const YES = new Set(["yes", "y", "ok", "sure", "proceed", "accept", "confirm", "do it", "go ahead", "yeah", "yep"]);
|
||||
const NO = new Set(["no", "n", "cancel", "decline", "stop", "nope", "abort", "don't"]);
|
||||
if (YES.has(lower)) {
|
||||
await confirmTool(true);
|
||||
return;
|
||||
}
|
||||
if (NO.has(lower)) {
|
||||
await confirmTool(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Add optimistic user message
|
||||
const userMsg: Message = {
|
||||
id: -Date.now(), // Temporary ID
|
||||
conversation_id: convId,
|
||||
role: "user",
|
||||
content,
|
||||
context_note_id: contextNoteId ?? null,
|
||||
context_note_title: contextNoteTitle ?? null,
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
currentConversation.value.messages.push(userMsg);
|
||||
|
||||
s.streaming = true;
|
||||
s.content = "";
|
||||
|
||||
// Phase 1: POST to start generation
|
||||
let assistantMessageId: number;
|
||||
try {
|
||||
const resp = await apiPost<SendMessageResponse>(
|
||||
`/api/chat/conversations/${convId}/messages`,
|
||||
{
|
||||
content,
|
||||
context_note_id: contextNoteId,
|
||||
include_note_ids: includeNoteIds?.length ? includeNoteIds : undefined,
|
||||
excluded_note_ids: excludeNoteIds?.length ? excludeNoteIds : undefined,
|
||||
think,
|
||||
rag_project_id: ragProjectId ?? undefined,
|
||||
workspace_project_id: workspaceProjectId ?? undefined,
|
||||
user_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
},
|
||||
);
|
||||
assistantMessageId = resp.assistant_message_id;
|
||||
} catch (e) {
|
||||
s.streaming = false;
|
||||
s.content = "";
|
||||
useToastStore().show("Failed to send message", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
// Immediately commit the message count so cleanup watcher never sees it as empty
|
||||
const convInList = conversations.value.find((c) => c.id === convId);
|
||||
if (convInList) convInList.message_count += 2;
|
||||
|
||||
// Phase 2: Connect to SSE stream with reconnection
|
||||
await _streamGeneration(convId, assistantMessageId);
|
||||
}
|
||||
|
||||
async function _streamGeneration(
|
||||
convId: number,
|
||||
assistantMessageId: number,
|
||||
initialLastEventId = -1,
|
||||
attempt = 0,
|
||||
) {
|
||||
const MAX_RETRIES = 5;
|
||||
let lastEventId = initialLastEventId;
|
||||
let gotDone = false;
|
||||
|
||||
const handle = apiSSEStream(
|
||||
`/api/chat/conversations/${convId}/generation/stream` +
|
||||
(lastEventId >= 0 ? `?last_event_id=${lastEventId}` : ""),
|
||||
(event) => {
|
||||
lastEventId = event.id;
|
||||
const s = convStreams.value[convId];
|
||||
if (!s) return;
|
||||
|
||||
switch (event.event) {
|
||||
case "context":
|
||||
s.contextMeta = event.data.context as ContextMeta;
|
||||
break;
|
||||
case "status":
|
||||
s.status = event.data.status as string;
|
||||
break;
|
||||
case "thinking_chunk":
|
||||
s.thinking += event.data.chunk as string;
|
||||
break;
|
||||
case "chunk":
|
||||
s.content += event.data.chunk as string;
|
||||
s.status = "";
|
||||
break;
|
||||
case "tool_pending":
|
||||
s.pendingTool = event.data.tool_pending as ToolPendingRecord;
|
||||
break;
|
||||
case "tool_call":
|
||||
// Receiving a tool_call clears the pending confirmation card
|
||||
s.pendingTool = null;
|
||||
s.toolCalls = [...s.toolCalls, event.data.tool_call as ToolCallRecord];
|
||||
break;
|
||||
case "done":
|
||||
gotDone = true;
|
||||
{
|
||||
const assistantMsg: Message = {
|
||||
id: event.data.message_id as number,
|
||||
conversation_id: convId,
|
||||
role: "assistant",
|
||||
content: s.content,
|
||||
context_note_id: null,
|
||||
tool_calls: s.toolCalls.length ? [...s.toolCalls] : null,
|
||||
created_at: new Date().toISOString(),
|
||||
timing: event.data.timing as GenerationTiming | undefined,
|
||||
thinking: s.thinking || undefined,
|
||||
};
|
||||
if (currentConversation.value?.id === convId) {
|
||||
currentConversation.value.messages.push(assistantMsg);
|
||||
// Update RAG scope if the model changed it mid-conversation
|
||||
if (event.data.new_rag_scope !== undefined) {
|
||||
currentConversation.value.rag_project_id = event.data.new_rag_scope as number | null;
|
||||
}
|
||||
}
|
||||
// Update updated_at only — message_count was already incremented at send time
|
||||
const idx = conversations.value.findIndex((c) => c.id === convId);
|
||||
if (idx !== -1) {
|
||||
conversations.value[idx].updated_at = new Date().toISOString();
|
||||
}
|
||||
// Clear stream state
|
||||
s.content = "";
|
||||
s.thinking = "";
|
||||
s.toolCalls = [];
|
||||
s.status = "";
|
||||
s.pendingTool = null;
|
||||
s.streaming = false;
|
||||
}
|
||||
break;
|
||||
case "error":
|
||||
gotDone = true;
|
||||
s.streaming = false;
|
||||
s.content = "";
|
||||
s.thinking = "";
|
||||
s.toolCalls = [];
|
||||
s.status = "";
|
||||
s.pendingTool = null;
|
||||
if (currentConversation.value?.id === convId) {
|
||||
useToastStore().show(
|
||||
"Chat error: " + (event.data.error as string),
|
||||
"error",
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Wait for the stream to close (events are processed via callback above)
|
||||
await handle.done;
|
||||
|
||||
// If stream ended without done/error, attempt reconnection regardless of which
|
||||
// conv is currently viewed — background streams retry independently
|
||||
if (!gotDone && attempt < MAX_RETRIES) {
|
||||
const delay = Math.min(1000 * 2 ** attempt, 10_000);
|
||||
await new Promise((r) => setTimeout(r, delay));
|
||||
return _streamGeneration(convId, assistantMessageId, lastEventId, attempt + 1);
|
||||
}
|
||||
|
||||
// Recovery fallback: re-fetch conversation from DB only if currently viewing it
|
||||
if (!gotDone && currentConversation.value?.id === convId) {
|
||||
useToastStore().show(
|
||||
"Connection lost — response may be incomplete",
|
||||
"error",
|
||||
);
|
||||
try {
|
||||
await fetchConversation(convId);
|
||||
} catch {
|
||||
// Re-fetch failed — partial content visible on next page load
|
||||
}
|
||||
}
|
||||
|
||||
// Final cleanup (guards against done/error not having fired)
|
||||
const s = convStreams.value[convId];
|
||||
if (s) {
|
||||
s.streaming = false;
|
||||
s.content = "";
|
||||
s.thinking = "";
|
||||
s.toolCalls = [];
|
||||
s.status = "";
|
||||
s.pendingTool = null;
|
||||
}
|
||||
|
||||
// Process next queued message if this is still the active conversation.
|
||||
// If the user has navigated away, _tryDrainQueue will fire on fetchConversation.
|
||||
_tryDrainQueue(convId);
|
||||
}
|
||||
|
||||
async function reconnectIfGenerating(convId: number): Promise<void> {
|
||||
// Skip if a stream is already active for this conversation
|
||||
if (isStreamingConv(convId)) return;
|
||||
|
||||
const conv = currentConversation.value;
|
||||
if (!conv || conv.id !== convId) return;
|
||||
|
||||
// Find the last assistant message still in generating state
|
||||
const lastMsg = [...conv.messages].reverse().find(
|
||||
(m) => m.role === "assistant" && m.status === "generating"
|
||||
);
|
||||
if (!lastMsg) return;
|
||||
|
||||
// Remove the partial message — the done event will re-add the final version
|
||||
conv.messages = conv.messages.filter((m) => m.id !== lastMsg.id);
|
||||
|
||||
const s = _getOrInitStream(convId);
|
||||
s.streaming = true;
|
||||
s.content = "";
|
||||
s.thinking = "";
|
||||
s.toolCalls = [];
|
||||
s.status = "Reconnecting...";
|
||||
s.pendingTool = null;
|
||||
s.contextMeta = null;
|
||||
|
||||
// Reconnect from the beginning — the buffer replays all buffered events.
|
||||
// If the buffer is gone (>60s stale), _streamGeneration will exhaust retries
|
||||
// then fall back to fetchConversation to show the final saved content.
|
||||
await _streamGeneration(convId, lastMsg.id);
|
||||
}
|
||||
|
||||
async function confirmTool(confirmed: boolean) {
|
||||
const convId = currentConversation.value?.id;
|
||||
if (!convId) return;
|
||||
// Optimistically clear so buttons disappear immediately
|
||||
const s = convStreams.value[convId];
|
||||
if (s) s.pendingTool = null;
|
||||
try {
|
||||
await apiPost(`/api/chat/conversations/${convId}/generation/confirm`, { confirmed });
|
||||
} catch {
|
||||
// Server will auto-decline on timeout — no action needed
|
||||
}
|
||||
}
|
||||
|
||||
async function cancelGeneration() {
|
||||
if (!currentConversation.value) return;
|
||||
try {
|
||||
await apiPost(
|
||||
`/api/chat/conversations/${currentConversation.value.id}/generation/cancel`,
|
||||
{}
|
||||
);
|
||||
} catch {
|
||||
// Generation may have already finished — ignore
|
||||
}
|
||||
}
|
||||
|
||||
async function saveMessageAsNote(messageId: number) {
|
||||
return await apiPost<Record<string, unknown>>(
|
||||
`/api/chat/messages/${messageId}/save-as-note`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
async function summarizeAsNote(conversationId: number) {
|
||||
return await apiPost<Record<string, unknown>>(
|
||||
`/api/chat/conversations/${conversationId}/summarize`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
async function fetchStatus() {
|
||||
try {
|
||||
const data = await apiGet<OllamaStatus>("/api/chat/status");
|
||||
ollamaStatus.value = data.ollama;
|
||||
modelStatus.value = data.model;
|
||||
defaultModel.value = data.default_model;
|
||||
} catch {
|
||||
ollamaStatus.value = "unavailable";
|
||||
modelStatus.value = "not_found";
|
||||
}
|
||||
}
|
||||
|
||||
function startStatusPolling() {
|
||||
fetchStatus();
|
||||
stopStatusPolling();
|
||||
statusPollTimer = setInterval(fetchStatus, 30_000);
|
||||
}
|
||||
|
||||
function stopStatusPolling() {
|
||||
if (statusPollTimer !== null) {
|
||||
clearInterval(statusPollTimer);
|
||||
statusPollTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function warmModel(model: string) {
|
||||
try {
|
||||
await apiPost("/api/chat/warm", { model });
|
||||
// Poll faster after a warm request so the indicator updates promptly
|
||||
_pollUntilLoaded();
|
||||
} catch {
|
||||
// Warming is best-effort
|
||||
}
|
||||
}
|
||||
|
||||
function _pollUntilLoaded() {
|
||||
let attempts = 0;
|
||||
const MAX = 12; // up to ~60s of fast polling
|
||||
const timer = setInterval(async () => {
|
||||
try {
|
||||
await fetchStatus();
|
||||
} catch {
|
||||
// best-effort polling
|
||||
}
|
||||
attempts++;
|
||||
if (modelStatus.value === "loaded" || attempts >= MAX) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, 5_000);
|
||||
}
|
||||
|
||||
return {
|
||||
conversations,
|
||||
currentConversation,
|
||||
total,
|
||||
loading,
|
||||
streaming,
|
||||
streamingContent,
|
||||
streamingThinking,
|
||||
streamingToolCalls,
|
||||
streamingStatus,
|
||||
streamingPendingTool,
|
||||
lastContextMeta,
|
||||
ragProjectId,
|
||||
updateRagScope,
|
||||
ollamaStatus,
|
||||
modelStatus,
|
||||
defaultModel,
|
||||
chatReady,
|
||||
isStreamingConv,
|
||||
queuedCount,
|
||||
queuedMessages,
|
||||
clearQueue,
|
||||
fetchConversations,
|
||||
createConversation,
|
||||
fetchConversation,
|
||||
deleteConversation,
|
||||
bulkDeleteConversations,
|
||||
updateTitle,
|
||||
sendMessage,
|
||||
reconnectIfGenerating,
|
||||
confirmTool,
|
||||
cancelGeneration,
|
||||
saveMessageAsNote,
|
||||
summarizeAsNote,
|
||||
warmModel,
|
||||
fetchStatus,
|
||||
startStatusPolling,
|
||||
stopStatusPolling,
|
||||
};
|
||||
});
|
||||
@@ -1,839 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref, computed, watch, nextTick } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useChatStore } from "@/stores/chat";
|
||||
import { apiGet } from "@/api/client";
|
||||
import ChatPanel from "@/components/ChatPanel.vue";
|
||||
import { MoreVertical, Menu, Paperclip, Trash2 } from "lucide-vue-next";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const store = useChatStore();
|
||||
|
||||
const summarizing = ref(false);
|
||||
const sidebarOpen = ref(false);
|
||||
const convSearchQuery = ref("");
|
||||
const headerKebabOpen = ref(false);
|
||||
const sidebarKebabOpen = ref(false);
|
||||
|
||||
// ── RAG scope chip ────────────────────────────────────────────────────────────
|
||||
const projects = ref<{ id: number; title: string }[]>([]);
|
||||
const scopeDropdownOpen = ref(false);
|
||||
const scopePulse = ref(false);
|
||||
|
||||
const scopeLabel = computed(() => {
|
||||
const id = store.ragProjectId;
|
||||
if (id === -1) return "All notes";
|
||||
if (id === null) return "Orphan notes";
|
||||
return projects.value.find((p) => p.id === id)?.title ?? `Project ${id}`;
|
||||
});
|
||||
|
||||
async function loadProjects() {
|
||||
try {
|
||||
const data = await apiGet<{ projects: { id: number; title: string }[] }>(
|
||||
"/api/projects?status=active"
|
||||
);
|
||||
projects.value = data.projects ?? [];
|
||||
} catch {
|
||||
projects.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
async function onScopeSelect(value: number | null) {
|
||||
scopeDropdownOpen.value = false;
|
||||
const id = store.currentConversation?.id;
|
||||
if (!id) return;
|
||||
await store.updateRagScope(id, value);
|
||||
scopePulse.value = true;
|
||||
setTimeout(() => { scopePulse.value = false; }, 600);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => store.ragProjectId,
|
||||
() => {
|
||||
scopePulse.value = true;
|
||||
setTimeout(() => { scopePulse.value = false; }, 600);
|
||||
}
|
||||
);
|
||||
|
||||
let prevConvId: number | null = null;
|
||||
|
||||
const convId = computed(() => {
|
||||
const id = route.params.id;
|
||||
return id ? Number(id) : null;
|
||||
});
|
||||
|
||||
function formatConvDate(dateStr: string): string {
|
||||
const date = new Date(dateStr);
|
||||
const now = new Date();
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffMin = Math.floor(diffMs / 60_000);
|
||||
const diffHrs = Math.floor(diffMs / 3_600_000);
|
||||
|
||||
if (diffMin < 1) return "Just now";
|
||||
if (diffMin < 60) return `${diffMin}m ago`;
|
||||
if (diffHrs < 10) return `${diffHrs}h ago`;
|
||||
if (date.getFullYear() === now.getFullYear()) {
|
||||
return date.toLocaleDateString(undefined, { month: "short", day: "numeric" });
|
||||
}
|
||||
return date.toLocaleDateString(undefined, { month: "short", day: "numeric", year: "numeric" });
|
||||
}
|
||||
|
||||
interface ConvGroup { label: string; convs: typeof store.conversations }
|
||||
|
||||
const groupedConversations = computed((): ConvGroup[] => {
|
||||
const now = new Date();
|
||||
const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const startOfYesterday = new Date(startOfToday.getTime() - 86_400_000);
|
||||
const startOfWeek = new Date(startOfToday.getTime() - 6 * 86_400_000);
|
||||
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
|
||||
const buckets: Record<string, typeof store.conversations> = {};
|
||||
const order: string[] = [];
|
||||
|
||||
const q = convSearchQuery.value.trim().toLowerCase();
|
||||
const filtered = q
|
||||
? store.conversations.filter((c) => (c.title || "").toLowerCase().includes(q))
|
||||
: store.conversations;
|
||||
|
||||
for (const conv of filtered) {
|
||||
const d = new Date(conv.updated_at);
|
||||
let key: string;
|
||||
if (d >= startOfToday) {
|
||||
key = "Today";
|
||||
} else if (d >= startOfYesterday) {
|
||||
key = "Yesterday";
|
||||
} else if (d >= startOfWeek) {
|
||||
key = "This week";
|
||||
} else if (d >= startOfMonth) {
|
||||
key = "This month";
|
||||
} else {
|
||||
key = d.toLocaleDateString(undefined, { month: "long", year: "numeric" });
|
||||
}
|
||||
if (!buckets[key]) { buckets[key] = []; order.push(key); }
|
||||
buckets[key].push(conv);
|
||||
}
|
||||
|
||||
return order.map((label) => ({ label, convs: buckets[label] }));
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
document.addEventListener("keydown", onGlobalKeydown);
|
||||
document.addEventListener("mousedown", onDocumentMousedown);
|
||||
loadProjects();
|
||||
await store.fetchConversations();
|
||||
if (convId.value) {
|
||||
if (store.currentConversation?.id !== convId.value) {
|
||||
await store.fetchConversation(convId.value);
|
||||
}
|
||||
store.reconnectIfGenerating(convId.value);
|
||||
} else {
|
||||
await startNewConversation();
|
||||
}
|
||||
nextTick(() => chatPanelRef.value?.focus());
|
||||
});
|
||||
|
||||
watch(convId, async (newId) => {
|
||||
if (prevConvId && prevConvId !== newId) {
|
||||
const prev = store.conversations.find((c) => c.id === prevConvId);
|
||||
if (prev && prev.message_count === 0) {
|
||||
store.deleteConversation(prevConvId);
|
||||
}
|
||||
}
|
||||
prevConvId = newId ?? null;
|
||||
|
||||
if (newId) {
|
||||
if (store.currentConversation?.id !== newId && !store.isStreamingConv(newId)) {
|
||||
await store.fetchConversation(newId);
|
||||
}
|
||||
store.reconnectIfGenerating(newId);
|
||||
} else {
|
||||
await startNewConversation();
|
||||
}
|
||||
nextTick(() => chatPanelRef.value?.focus());
|
||||
});
|
||||
|
||||
function toggleSidebar() {
|
||||
sidebarOpen.value = !sidebarOpen.value;
|
||||
}
|
||||
|
||||
async function selectConversation(id: number) {
|
||||
sidebarOpen.value = false;
|
||||
router.push(`/chat/${id}`);
|
||||
}
|
||||
|
||||
async function startNewConversation() {
|
||||
const conv = await store.createConversation();
|
||||
router.push(`/chat/${conv.id}`);
|
||||
}
|
||||
|
||||
async function newConversation() {
|
||||
await startNewConversation();
|
||||
}
|
||||
|
||||
// ── Bulk selection ────────────────────────────────────────────────────────────
|
||||
const selectMode = ref(false);
|
||||
const selectedIds = ref<Set<number>>(new Set());
|
||||
const bulkConfirm = ref(false);
|
||||
const bulkDeleting = ref(false);
|
||||
|
||||
function toggleSelectMode() {
|
||||
selectMode.value = !selectMode.value;
|
||||
selectedIds.value = new Set();
|
||||
bulkConfirm.value = false;
|
||||
}
|
||||
|
||||
function toggleSelectConv(id: number) {
|
||||
if (selectedIds.value.has(id)) {
|
||||
selectedIds.value.delete(id);
|
||||
} else {
|
||||
selectedIds.value.add(id);
|
||||
}
|
||||
selectedIds.value = new Set(selectedIds.value);
|
||||
}
|
||||
|
||||
function selectAll() {
|
||||
selectedIds.value = new Set(store.conversations.map((c) => c.id));
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedIds.value = new Set();
|
||||
bulkConfirm.value = false;
|
||||
}
|
||||
|
||||
async function bulkDelete() {
|
||||
if (!bulkConfirm.value) { bulkConfirm.value = true; return; }
|
||||
bulkDeleting.value = true;
|
||||
try {
|
||||
const ids = [...selectedIds.value];
|
||||
await store.bulkDeleteConversations(ids);
|
||||
if (ids.includes(convId.value ?? -1)) router.push("/chat");
|
||||
selectedIds.value = new Set();
|
||||
bulkConfirm.value = false;
|
||||
selectMode.value = false;
|
||||
} finally {
|
||||
bulkDeleting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeConversation(id: number) {
|
||||
await store.deleteConversation(id);
|
||||
if (convId.value === id) {
|
||||
router.push("/chat");
|
||||
}
|
||||
}
|
||||
|
||||
// ── Summarize ─────────────────────────────────────────────────────────────────
|
||||
async function handleSummarize() {
|
||||
if (!store.currentConversation || summarizing.value) return;
|
||||
summarizing.value = true;
|
||||
try {
|
||||
await store.summarizeAsNote(store.currentConversation.id);
|
||||
const { useToastStore } = await import("@/stores/toast");
|
||||
useToastStore().show("Conversation summarized and saved as note");
|
||||
} catch {
|
||||
const { useToastStore } = await import("@/stores/toast");
|
||||
useToastStore().show("Failed to summarize", "error");
|
||||
} finally {
|
||||
summarizing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const chatPanelRef = ref<InstanceType<typeof ChatPanel> | null>(null);
|
||||
|
||||
const contextCount = computed(() => chatPanelRef.value?.contextCount ?? 0);
|
||||
const contextSidebarOpen = computed(() => chatPanelRef.value?.sidebarOpen ?? false);
|
||||
function toggleContextSidebar() {
|
||||
chatPanelRef.value?.toggleContextSidebar();
|
||||
}
|
||||
|
||||
// ── Kebab dismissal ───────────────────────────────────────────────────────────
|
||||
function onDocumentMousedown(e: MouseEvent) {
|
||||
const target = e.target as HTMLElement | null;
|
||||
if (headerKebabOpen.value && !target?.closest(".header-kebab-wrapper")) {
|
||||
headerKebabOpen.value = false;
|
||||
}
|
||||
if (sidebarKebabOpen.value && !target?.closest(".sidebar-kebab-wrapper")) {
|
||||
sidebarKebabOpen.value = false;
|
||||
}
|
||||
if (scopeDropdownOpen.value && !target?.closest(".scope-chip-wrapper")) {
|
||||
scopeDropdownOpen.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Keyboard ──────────────────────────────────────────────────────────────────
|
||||
function onGlobalKeydown(e: KeyboardEvent) {
|
||||
if (e.key !== "Escape") return;
|
||||
if (headerKebabOpen.value || sidebarKebabOpen.value || scopeDropdownOpen.value) {
|
||||
headerKebabOpen.value = false;
|
||||
sidebarKebabOpen.value = false;
|
||||
scopeDropdownOpen.value = false;
|
||||
return;
|
||||
}
|
||||
if (sidebarOpen.value) {
|
||||
sidebarOpen.value = false;
|
||||
return;
|
||||
}
|
||||
router.push("/");
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener("keydown", onGlobalKeydown);
|
||||
document.removeEventListener("mousedown", onDocumentMousedown);
|
||||
if (prevConvId) {
|
||||
const conv = store.conversations.find((c) => c.id === prevConvId);
|
||||
if (conv && conv.message_count === 0) {
|
||||
store.deleteConversation(prevConvId);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="chat-page">
|
||||
<div
|
||||
v-if="sidebarOpen"
|
||||
class="sidebar-overlay"
|
||||
@click="sidebarOpen = false"
|
||||
></div>
|
||||
<aside class="chat-sidebar" :class="{ open: sidebarOpen }">
|
||||
<div class="sidebar-top-bar">
|
||||
<button class="btn-new-conv btn-new-conv--full" @click="newConversation">+ New Chat</button>
|
||||
<div class="sidebar-search-row">
|
||||
<input
|
||||
v-model="convSearchQuery"
|
||||
class="conv-search-input"
|
||||
type="search"
|
||||
placeholder="Search conversations…"
|
||||
aria-label="Search conversations"
|
||||
/>
|
||||
<div class="sidebar-kebab-wrapper">
|
||||
<button
|
||||
class="btn-kebab"
|
||||
:class="{ active: sidebarKebabOpen }"
|
||||
@click="sidebarKebabOpen = !sidebarKebabOpen"
|
||||
aria-label="List actions"
|
||||
title="List actions"
|
||||
>
|
||||
<MoreVertical :size="16" />
|
||||
</button>
|
||||
<div v-if="sidebarKebabOpen" class="kebab-menu">
|
||||
<button
|
||||
class="kebab-item"
|
||||
@click="sidebarKebabOpen = false; toggleSelectMode()"
|
||||
>{{ selectMode ? "Exit select mode" : "Select conversations" }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="selectMode" class="bulk-bar">
|
||||
<span class="bulk-count">{{ selectedIds.size }} selected</span>
|
||||
<button class="bulk-link" @click="selectAll">All</button>
|
||||
<button class="bulk-link" @click="clearSelection">None</button>
|
||||
<button
|
||||
v-if="selectedIds.size"
|
||||
class="bulk-delete-btn"
|
||||
:class="{ confirm: bulkConfirm }"
|
||||
:disabled="bulkDeleting"
|
||||
@click="bulkDelete"
|
||||
>
|
||||
<Trash2 :size="16" />
|
||||
{{ bulkDeleting ? '...' : bulkConfirm ? `Delete ${selectedIds.size}?` : `Delete (${selectedIds.size})` }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="conv-list">
|
||||
<template v-for="group in groupedConversations" :key="group.label">
|
||||
<div class="conv-group-label">{{ group.label }}</div>
|
||||
<div
|
||||
v-for="conv in group.convs"
|
||||
:key="conv.id"
|
||||
class="conv-item"
|
||||
:class="{ active: convId === conv.id, selected: selectedIds.has(conv.id) }"
|
||||
@click="selectMode ? toggleSelectConv(conv.id) : selectConversation(conv.id)"
|
||||
>
|
||||
<input
|
||||
v-if="selectMode"
|
||||
type="checkbox"
|
||||
class="conv-checkbox"
|
||||
:checked="selectedIds.has(conv.id)"
|
||||
@click.stop="toggleSelectConv(conv.id)"
|
||||
/>
|
||||
<div class="conv-info">
|
||||
<span class="conv-title">{{ conv.title || "Untitled" }}</span>
|
||||
<span class="conv-date">{{ formatConvDate(conv.updated_at) }}</span>
|
||||
</div>
|
||||
<button
|
||||
v-if="!selectMode"
|
||||
class="btn-delete-conv"
|
||||
@click.stop="removeConversation(conv.id)"
|
||||
title="Delete conversation"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
<p v-if="!store.conversations.length" class="empty-msg">
|
||||
No conversations yet
|
||||
</p>
|
||||
<p
|
||||
v-else-if="convSearchQuery && !groupedConversations.length"
|
||||
class="empty-msg"
|
||||
>No matches for “{{ convSearchQuery }}”</p>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<section class="chat-main">
|
||||
<template v-if="store.currentConversation">
|
||||
<div class="chat-header">
|
||||
<button class="btn-sidebar-toggle hide-desktop" aria-label="Toggle sidebar" @click="toggleSidebar">
|
||||
<Menu :size="24" />
|
||||
</button>
|
||||
<h2>{{ store.currentConversation.title || "New Chat" }}</h2>
|
||||
|
||||
<div class="scope-chip-wrapper">
|
||||
<button
|
||||
class="scope-chip"
|
||||
:class="{ pulse: scopePulse }"
|
||||
@click="scopeDropdownOpen = !scopeDropdownOpen"
|
||||
title="Change RAG scope"
|
||||
>
|
||||
<span class="scope-dot">⊙</span> {{ scopeLabel }}
|
||||
</button>
|
||||
<div v-if="scopeDropdownOpen" class="scope-dropdown">
|
||||
<button
|
||||
class="scope-option"
|
||||
:class="{ active: store.ragProjectId === null }"
|
||||
@click="onScopeSelect(null)"
|
||||
>Orphan notes only</button>
|
||||
<button
|
||||
v-for="p in projects"
|
||||
:key="p.id"
|
||||
class="scope-option"
|
||||
:class="{ active: store.ragProjectId === p.id }"
|
||||
@click="onScopeSelect(p.id)"
|
||||
>{{ p.title }}</button>
|
||||
<button
|
||||
class="scope-option"
|
||||
:class="{ active: store.ragProjectId === -1 }"
|
||||
@click="onScopeSelect(-1)"
|
||||
>All notes</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
v-if="contextCount > 0"
|
||||
class="btn-context-toggle"
|
||||
:class="{ active: contextSidebarOpen }"
|
||||
@click="toggleContextSidebar"
|
||||
:title="contextSidebarOpen ? 'Hide context panel' : 'Show context panel'"
|
||||
>
|
||||
<Paperclip class="context-icon" :size="16" />
|
||||
<span class="context-label">Context</span>
|
||||
<span class="context-count-badge">{{ contextCount }}</span>
|
||||
</button>
|
||||
|
||||
<div class="header-kebab-wrapper">
|
||||
<button
|
||||
class="btn-kebab"
|
||||
:class="{ active: headerKebabOpen }"
|
||||
@click="headerKebabOpen = !headerKebabOpen"
|
||||
aria-label="Conversation actions"
|
||||
title="Conversation actions"
|
||||
>
|
||||
<MoreVertical :size="16" />
|
||||
</button>
|
||||
<div v-if="headerKebabOpen" class="kebab-menu kebab-menu--right">
|
||||
<button
|
||||
class="kebab-item"
|
||||
:disabled="!store.currentConversation.messages.length || summarizing || store.streaming"
|
||||
@click="headerKebabOpen = false; handleSummarize()"
|
||||
>{{ summarizing ? "Summarizing…" : "Summarize as Note" }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ChatPanel
|
||||
ref="chatPanelRef"
|
||||
variant="full"
|
||||
:auto-focus="true"
|
||||
class="chat-panel-fill"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<div v-else class="no-conversation">
|
||||
<button class="btn-sidebar-toggle no-conv-toggle hide-desktop" @click="toggleSidebar">
|
||||
<Menu :size="24" />
|
||||
</button>
|
||||
<p>Select a conversation or start a new chat.</p>
|
||||
<button class="btn-new-conv" @click="newConversation">
|
||||
+ New Chat
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.chat-page {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chat-sidebar {
|
||||
width: var(--sidebar-width);
|
||||
min-width: 200px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--color-bg-secondary);
|
||||
}
|
||||
|
||||
.sidebar-top-bar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.btn-new-conv {
|
||||
padding: 0.5rem;
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
transition: box-shadow 0.15s, opacity 0.15s;
|
||||
}
|
||||
.btn-new-conv--full { width: 100%; }
|
||||
.btn-new-conv:hover {
|
||||
opacity: 0.9;
|
||||
box-shadow: 0 0 14px rgba(91, 74, 138, 0.35);
|
||||
}
|
||||
|
||||
.sidebar-search-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
.conv-search-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding: 0.4rem 0.6rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
font-size: 0.85rem;
|
||||
outline: none;
|
||||
font-family: inherit;
|
||||
}
|
||||
.conv-search-input:focus { border-color: var(--color-primary); }
|
||||
.conv-search-input::placeholder { color: var(--color-text-muted); }
|
||||
|
||||
.bulk-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.3rem 0.75rem;
|
||||
background: color-mix(in srgb, var(--color-primary) 6%, var(--color-bg-secondary));
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.bulk-count { font-size: 0.75rem; color: var(--color-text-muted); flex-shrink: 0; }
|
||||
.bulk-link {
|
||||
background: none; border: none; color: var(--color-text-secondary);
|
||||
font-size: 0.75rem; cursor: pointer; padding: 0; text-decoration: underline;
|
||||
}
|
||||
.bulk-link:hover { color: var(--color-text); }
|
||||
|
||||
/* Destructive action — Oxblood per Hybrid rule, paired with Trash2 icon */
|
||||
.bulk-delete-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
margin-left: auto;
|
||||
background: none;
|
||||
border: 1px solid var(--color-action-destructive);
|
||||
color: var(--color-action-destructive);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
padding: 0.2rem 0.55rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.bulk-delete-btn:hover:not(:disabled) { background: var(--color-action-destructive); color: #fff; }
|
||||
.bulk-delete-btn:disabled { opacity: 0.5; cursor: default; }
|
||||
.bulk-delete-btn.confirm { background: var(--color-action-destructive-hover); color: #fff; border-color: var(--color-action-destructive-hover); }
|
||||
|
||||
.conv-checkbox {
|
||||
flex-shrink: 0;
|
||||
accent-color: var(--color-primary);
|
||||
cursor: pointer;
|
||||
width: 0.9rem;
|
||||
height: 0.9rem;
|
||||
}
|
||||
.conv-item.selected {
|
||||
background: color-mix(in srgb, var(--color-primary) 8%, var(--color-bg-secondary));
|
||||
}
|
||||
|
||||
.conv-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 0 0.5rem 0.5rem;
|
||||
}
|
||||
.conv-group-label {
|
||||
font-size: 0.68rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--color-text-muted);
|
||||
padding: 0.6rem 0.75rem 0.2rem;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background: var(--color-surface);
|
||||
z-index: 1;
|
||||
}
|
||||
.conv-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
margin-bottom: 0.25rem;
|
||||
border-left: 3px solid transparent;
|
||||
transition: background 0.15s, border-color 0.15s;
|
||||
}
|
||||
.conv-item:hover { background: rgba(91, 74, 138,0.05); border-left-color: var(--color-primary); }
|
||||
.conv-item.active {
|
||||
background: color-mix(in srgb, var(--color-primary) 15%, transparent);
|
||||
color: var(--color-primary);
|
||||
border-left-color: var(--color-primary);
|
||||
}
|
||||
.conv-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
||||
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
|
||||
.conv-date { font-size: 0.75rem; color: var(--color-text-muted); margin-top: 1px; }
|
||||
.btn-delete-conv {
|
||||
background: none; border: none; color: var(--color-text-muted);
|
||||
cursor: pointer; font-size: 1.2rem; padding: 0 0.25rem; line-height: 1;
|
||||
}
|
||||
.btn-delete-conv:hover { color: var(--color-action-destructive); }
|
||||
|
||||
.chat-main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ChatPanel fills the remaining space in chat-main. Layout (grid vs
|
||||
* flex) is owned by ChatPanel's own .chat-full root — don't force a
|
||||
* display here or it overrides the grid. */
|
||||
.chat-panel-fill {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.chat-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.chat-header h2 {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* Kebab button + dropdown menu — shared by header and sidebar */
|
||||
.btn-kebab {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
color: var(--color-text-muted);
|
||||
padding: 0.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: var(--radius-sm);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.btn-kebab:hover { color: var(--color-text); background: var(--color-bg-secondary); }
|
||||
.btn-kebab.active { color: var(--color-primary); }
|
||||
|
||||
.header-kebab-wrapper,
|
||||
.sidebar-kebab-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* RAG scope chip (header) */
|
||||
.scope-chip-wrapper { position: relative; flex-shrink: 0; }
|
||||
.scope-chip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
background: none;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 20px;
|
||||
padding: 0.2rem 0.65rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s, color 0.15s;
|
||||
}
|
||||
.scope-chip:hover { border-color: var(--color-primary); color: var(--color-primary); }
|
||||
.scope-chip.pulse { animation: pulse-chip 0.6s ease; }
|
||||
@keyframes pulse-chip {
|
||||
0%, 100% { border-color: var(--color-border); }
|
||||
50% {
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
box-shadow: 0 0 6px rgba(91, 74, 138, 0.4);
|
||||
}
|
||||
}
|
||||
.scope-dot { font-size: 0.6rem; }
|
||||
.scope-dropdown {
|
||||
position: absolute;
|
||||
top: calc(100% + 4px);
|
||||
right: 0;
|
||||
min-width: 200px;
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
box-shadow: 0 4px 16px var(--color-shadow);
|
||||
z-index: 20;
|
||||
overflow: hidden;
|
||||
}
|
||||
.scope-option {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 0.45rem 0.75rem;
|
||||
text-align: left;
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 0.85rem;
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
}
|
||||
.scope-option:hover { background: var(--color-bg-secondary); }
|
||||
.scope-option.active { color: var(--color-primary); font-weight: 500; }
|
||||
|
||||
/* Context toggle button (header) */
|
||||
.btn-context-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
background: none;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 20px;
|
||||
padding: 0.2rem 0.55rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: border-color 0.15s, color 0.15s, background 0.15s;
|
||||
font-family: inherit;
|
||||
}
|
||||
.btn-context-toggle:hover { border-color: var(--color-primary); color: var(--color-primary); }
|
||||
.btn-context-toggle.active {
|
||||
background: color-mix(in srgb, var(--color-primary) 10%, transparent);
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
.context-icon { font-size: 0.85rem; line-height: 1; }
|
||||
.context-count-badge {
|
||||
font-size: 0.65rem;
|
||||
font-weight: 500;
|
||||
background: var(--color-bg);
|
||||
padding: 0.05rem 0.35rem;
|
||||
border-radius: 8px;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.kebab-menu {
|
||||
position: absolute;
|
||||
top: calc(100% + 4px);
|
||||
left: 0;
|
||||
min-width: 180px;
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
box-shadow: 0 4px 20px var(--color-shadow);
|
||||
padding: 0.25rem;
|
||||
z-index: 20;
|
||||
}
|
||||
.kebab-menu--right { left: auto; right: 0; }
|
||||
.kebab-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text);
|
||||
font-size: 0.85rem;
|
||||
padding: 0.45rem 0.65rem;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
}
|
||||
.kebab-item:hover:not(:disabled) { background: var(--color-bg-secondary); color: var(--color-primary); }
|
||||
.kebab-item:disabled { opacity: 0.4; cursor: default; }
|
||||
|
||||
.no-conversation {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.no-conversation .btn-new-conv {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.empty-msg {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.9rem;
|
||||
text-align: center;
|
||||
padding: 2rem 1rem;
|
||||
}
|
||||
|
||||
.btn-sidebar-toggle {
|
||||
background: none; border: none; cursor: pointer;
|
||||
color: var(--color-text-muted); padding: 0.2rem;
|
||||
display: flex; align-items: center;
|
||||
}
|
||||
.btn-sidebar-toggle:hover { color: var(--color-text); }
|
||||
|
||||
.sidebar-overlay {
|
||||
position: fixed; inset: 0; background: var(--color-overlay); z-index: 99;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.hide-desktop { display: none; }
|
||||
.chat-sidebar { position: relative; transform: none !important; }
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.chat-sidebar {
|
||||
position: fixed; left: 0; top: 0; bottom: 0;
|
||||
z-index: 100; transform: translateX(-100%);
|
||||
transition: transform 0.25s ease;
|
||||
box-shadow: 4px 0 16px rgba(0,0,0,0.2);
|
||||
}
|
||||
.chat-sidebar.open { transform: translateX(0); }
|
||||
}
|
||||
</style>
|
||||
@@ -1,942 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted } from "vue";
|
||||
import { apiGet, listEvents } from "@/api/client";
|
||||
import { useBackgroundRefresh } from "@/composables/useBackgroundRefresh";
|
||||
import { milestoneColor } from "@/utils/palette";
|
||||
import { fmtRelativeDateTime } from "@/utils/dateFormat";
|
||||
import type { Note } from "@/types/note";
|
||||
import type { Task, TaskListResponse, TaskStatus } from "@/types/task";
|
||||
import type { EventEntry } from "@/api/client";
|
||||
import NoteCard from "@/components/NoteCard.vue";
|
||||
import TaskCard from "@/components/TaskCard.vue";
|
||||
import StatusBadge from "@/components/StatusBadge.vue";
|
||||
import PriorityBadge from "@/components/PriorityBadge.vue";
|
||||
import ChatPanel from "@/components/ChatPanel.vue";
|
||||
import EventSlideOver from "@/components/EventSlideOver.vue";
|
||||
import { useTasksStore } from "@/stores/tasks";
|
||||
import { useChatStore } from "@/stores/chat";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface MilestoneSummary {
|
||||
id: number;
|
||||
title: string;
|
||||
status: string;
|
||||
pct: number;
|
||||
total: number;
|
||||
completed: number;
|
||||
}
|
||||
|
||||
interface DashProject {
|
||||
id: number;
|
||||
title: string;
|
||||
status: string;
|
||||
updated_at: string;
|
||||
summary?: {
|
||||
task_counts: { todo?: number; in_progress?: number; done?: number };
|
||||
milestone_summary: MilestoneSummary[];
|
||||
};
|
||||
}
|
||||
|
||||
// A recent item from the hero project (note or task — both come from /api/notes?all=true)
|
||||
interface RecentItem {
|
||||
id: number;
|
||||
title: string;
|
||||
status: string | null;
|
||||
project_id: number | null;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
// ─── State ────────────────────────────────────────────────────────────────────
|
||||
|
||||
const loading = ref(true);
|
||||
const tasksStore = useTasksStore();
|
||||
|
||||
// Hero project — most recently active project
|
||||
const heroProject = ref<DashProject | null>(null);
|
||||
const heroRecentItems = ref<RecentItem[]>([]);
|
||||
const heroNextUp = ref<Task | null>(null);
|
||||
|
||||
// All other active projects (hero excluded)
|
||||
const activeProjects = ref<DashProject[]>([]);
|
||||
|
||||
// Orphaned items (no project_id)
|
||||
const orphanTasks = ref<Task[]>([]);
|
||||
const orphanNotes = ref<Note[]>([]);
|
||||
const inboxOpen = ref(true);
|
||||
|
||||
// Upcoming events (today + next 7 days)
|
||||
const upcomingEvents = ref<EventEntry[]>([]);
|
||||
const eventSlideOverOpen = ref(false);
|
||||
const editingEvent = ref<EventEntry | null>(null);
|
||||
|
||||
// ─── Background refresh (no-flicker) ─────────────────────────────────────────
|
||||
// Never touches `loading` so existing content stays on screen while fetching.
|
||||
|
||||
function _dateRange() {
|
||||
const today = new Date()
|
||||
const nextWeek = new Date(today)
|
||||
nextWeek.setDate(today.getDate() + 7)
|
||||
// Use full ISO strings so the server sees the correct UTC equivalent of
|
||||
// local midnight / end-of-day rather than a naive UTC-midnight guess.
|
||||
return {
|
||||
todayStr: today.toISOString(),
|
||||
nextWeekStr: nextWeek.toISOString(),
|
||||
}
|
||||
}
|
||||
|
||||
function _backgroundRefresh() {
|
||||
if (document.hidden || loading.value) return
|
||||
const { todayStr, nextWeekStr } = _dateRange()
|
||||
Promise.allSettled([
|
||||
listEvents(todayStr, nextWeekStr),
|
||||
apiGet<TaskListResponse>('/api/tasks?no_project=true&sort=updated_at&order=desc&limit=8'),
|
||||
apiGet<{ notes: Note[] }>('/api/notes?type=note&no_project=true&sort=updated_at&order=desc&limit=6'),
|
||||
]).then(([eventsRes, tasksRes, notesRes]) => {
|
||||
if (eventsRes.status === 'fulfilled') upcomingEvents.value = eventsRes.value
|
||||
if (tasksRes.status === 'fulfilled') orphanTasks.value = tasksRes.value.tasks
|
||||
if (notesRes.status === 'fulfilled') orphanNotes.value = notesRes.value.notes
|
||||
})
|
||||
if (heroProject.value) {
|
||||
apiGet<TaskListResponse>(
|
||||
`/api/tasks?project_id=${heroProject.value.id}&status=todo&sort=updated_at&order=desc&limit=1`
|
||||
)
|
||||
.then((r) => { heroNextUp.value = r.tasks[0] ?? null })
|
||||
.catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Data loading ─────────────────────────────────────────────────────────────
|
||||
|
||||
onMounted(async () => {
|
||||
// Phase 1: projects list + cross-project recent items + orphaned items + events — all parallel
|
||||
const { todayStr, nextWeekStr } = _dateRange();
|
||||
|
||||
const [projectsRes, recentRes, orphanTasksRes, orphanNotesRes, eventsRes] =
|
||||
await Promise.allSettled([
|
||||
apiGet<{ projects: DashProject[] }>("/api/projects?status=active"),
|
||||
apiGet<{ notes: RecentItem[] }>(
|
||||
"/api/notes?all=true&sort=updated_at&order=desc&limit=30"
|
||||
),
|
||||
apiGet<TaskListResponse>(
|
||||
"/api/tasks?no_project=true&sort=updated_at&order=desc&limit=8"
|
||||
),
|
||||
apiGet<{ notes: Note[] }>(
|
||||
"/api/notes?type=note&no_project=true&sort=updated_at&order=desc&limit=6"
|
||||
),
|
||||
listEvents(todayStr, nextWeekStr),
|
||||
]);
|
||||
|
||||
// Determine hero project: the project whose item was most recently touched
|
||||
let heroId: number | null = null;
|
||||
if (recentRes.status === "fulfilled") {
|
||||
const withProject = recentRes.value.notes.find(
|
||||
(n) => n.project_id != null
|
||||
);
|
||||
heroId = withProject?.project_id ?? null;
|
||||
}
|
||||
|
||||
if (projectsRes.status === "fulfilled") {
|
||||
const all = projectsRes.value.projects;
|
||||
const hero = all.find((p) => p.id === heroId) ?? all[0] ?? null;
|
||||
heroProject.value = hero;
|
||||
activeProjects.value = all.filter((p) => p.id !== hero?.id);
|
||||
}
|
||||
|
||||
if (orphanTasksRes.status === "fulfilled")
|
||||
orphanTasks.value = orphanTasksRes.value.tasks;
|
||||
if (orphanNotesRes.status === "fulfilled")
|
||||
orphanNotes.value = orphanNotesRes.value.notes;
|
||||
if (eventsRes.status === "fulfilled")
|
||||
upcomingEvents.value = eventsRes.value;
|
||||
|
||||
loading.value = false;
|
||||
|
||||
// Focus chat input after data loads
|
||||
chatPanelRef.value?.focus();
|
||||
loadProjects();
|
||||
|
||||
});
|
||||
|
||||
useBackgroundRefresh(_backgroundRefresh, 90_000, () => !loading.value);
|
||||
|
||||
async function loadProjects() {
|
||||
if (!heroProject.value) return;
|
||||
const hid = heroProject.value.id;
|
||||
|
||||
// Phase 2: hero details + all project summaries — parallel
|
||||
const [recentItemsRes, nextUpRes, heroSummaryRes] = await Promise.allSettled([
|
||||
apiGet<{ notes: RecentItem[] }>(
|
||||
`/api/notes?all=true&project_id=${hid}&sort=updated_at&order=desc&limit=5`
|
||||
),
|
||||
apiGet<TaskListResponse>(
|
||||
`/api/tasks?project_id=${hid}&status=todo&sort=updated_at&order=desc&limit=1`
|
||||
),
|
||||
apiGet<DashProject>(`/api/projects/${hid}`),
|
||||
]);
|
||||
|
||||
if (recentItemsRes.status === "fulfilled")
|
||||
heroRecentItems.value = recentItemsRes.value.notes;
|
||||
if (nextUpRes.status === "fulfilled")
|
||||
heroNextUp.value = nextUpRes.value.tasks[0] ?? null;
|
||||
if (heroSummaryRes.status === "fulfilled")
|
||||
heroProject.value = { ...heroProject.value!, ...heroSummaryRes.value };
|
||||
|
||||
// Load summaries for remaining projects
|
||||
await Promise.allSettled(
|
||||
activeProjects.value.map(async (p) => {
|
||||
try {
|
||||
const full = await apiGet<DashProject>(`/api/projects/${p.id}`);
|
||||
const idx = activeProjects.value.findIndex((x) => x.id === p.id);
|
||||
if (idx !== -1)
|
||||
activeProjects.value[idx] = { ...activeProjects.value[idx], ...full };
|
||||
} catch {
|
||||
/* non-fatal */
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Status toggle (orphaned tasks) ──────────────────────────────────────────
|
||||
|
||||
function onStatusToggle(id: number, status: TaskStatus) {
|
||||
tasksStore.patchStatus(id, status).then((updated) => {
|
||||
if (updated.status === "done") {
|
||||
orphanTasks.value = orphanTasks.value.filter((t) => t.id !== id);
|
||||
} else {
|
||||
const idx = orphanTasks.value.findIndex((t) => t.id === id);
|
||||
if (idx !== -1) orphanTasks.value[idx] = updated;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ─── Chat widget ──────────────────────────────────────────────────────────────
|
||||
|
||||
const chatPanelRef = ref<InstanceType<typeof ChatPanel> | null>(null);
|
||||
|
||||
function onFocusChatShortcut() {
|
||||
chatPanelRef.value?.focus();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener("shortcut:focus-chat", onFocusChatShortcut);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener("shortcut:focus-chat", onFocusChatShortcut);
|
||||
});
|
||||
|
||||
const chatStore = useChatStore();
|
||||
|
||||
chatStore.fetchStatus().then(() => {
|
||||
if (chatStore.defaultModel) chatStore.warmModel(chatStore.defaultModel);
|
||||
});
|
||||
|
||||
const QUICK_ACTIONS = [
|
||||
"What's due today?",
|
||||
"Events this week?",
|
||||
"Any overdue tasks?",
|
||||
"My high priority tasks?",
|
||||
];
|
||||
|
||||
async function onQuickAction(query: string) {
|
||||
await chatPanelRef.value?.send(query);
|
||||
}
|
||||
|
||||
// ─── Upcoming events slide-over ───────────────────────────────────────────────
|
||||
|
||||
function openEvent(event: EventEntry) {
|
||||
editingEvent.value = event;
|
||||
eventSlideOverOpen.value = true;
|
||||
}
|
||||
|
||||
function onEventUpdated(event: EventEntry) {
|
||||
const idx = upcomingEvents.value.findIndex((e) => e.id === event.id);
|
||||
if (idx !== -1) upcomingEvents.value[idx] = event;
|
||||
eventSlideOverOpen.value = false;
|
||||
}
|
||||
|
||||
function onEventDeleted(id: number) {
|
||||
upcomingEvents.value = upcomingEvents.value.filter((e) => e.id !== id);
|
||||
eventSlideOverOpen.value = false;
|
||||
}
|
||||
|
||||
function formatUpcomingTime(event: EventEntry): string {
|
||||
if (!event.start_dt) return "";
|
||||
return fmtRelativeDateTime(event.start_dt, event.all_day);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="home">
|
||||
|
||||
<!-- ── Chat widget ─────────────────────────────────────────── -->
|
||||
<section class="chat-section">
|
||||
<div class="quick-actions">
|
||||
<button
|
||||
v-for="q in QUICK_ACTIONS"
|
||||
:key="q"
|
||||
class="quick-action-chip"
|
||||
:disabled="chatStore.streaming || !chatStore.chatReady"
|
||||
@click="onQuickAction(q)"
|
||||
>{{ q }}</button>
|
||||
</div>
|
||||
<ChatPanel ref="chatPanelRef" variant="widget" />
|
||||
</section>
|
||||
|
||||
<!-- ── Upcoming events ────────────────────────────────────── -->
|
||||
<div v-if="!loading && upcomingEvents.length" class="upcoming-events-section">
|
||||
<div class="section-header">
|
||||
<h2>Upcoming</h2>
|
||||
<router-link to="/calendar" class="see-all">Calendar →</router-link>
|
||||
</div>
|
||||
<div class="upcoming-events-list">
|
||||
<button
|
||||
v-for="ev in upcomingEvents.slice(0, 6)"
|
||||
:key="ev.id"
|
||||
class="upcoming-event-card"
|
||||
@click="openEvent(ev)"
|
||||
>
|
||||
<span class="upcoming-event-dot" :style="ev.color ? { background: ev.color } : {}"></span>
|
||||
<span class="upcoming-event-body">
|
||||
<span class="upcoming-event-title">{{ ev.title }}</span>
|
||||
<span class="upcoming-event-time">{{ formatUpcomingTime(ev) }}</span>
|
||||
<span v-if="ev.location" class="upcoming-event-loc">{{ ev.location }}</span>
|
||||
</span>
|
||||
</button>
|
||||
<div v-if="upcomingEvents.length > 6" class="upcoming-events-more">
|
||||
+{{ upcomingEvents.length - 6 }} more —
|
||||
<router-link to="/calendar" class="see-all-inline">view all</router-link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Skeleton while loading ─────────────────────────────── -->
|
||||
<template v-if="loading">
|
||||
<div class="skeleton-hero"></div>
|
||||
<div class="skeleton-grid">
|
||||
<div class="skeleton-card" v-for="i in 3" :key="i"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
|
||||
<!-- ── Hero: Last Active Project ──────────────────────── -->
|
||||
<div v-if="heroProject" class="hero-card">
|
||||
<div class="hero-top">
|
||||
<div class="hero-identity">
|
||||
<span class="hero-label">Last active</span>
|
||||
<router-link :to="`/projects/${heroProject.id}`" class="hero-title">
|
||||
{{ heroProject.title }}
|
||||
</router-link>
|
||||
</div>
|
||||
<router-link :to="`/workspace/${heroProject.id}`" class="btn-workspace-hero">
|
||||
▶ Open Workspace
|
||||
</router-link>
|
||||
</div>
|
||||
|
||||
<!-- Milestone bars -->
|
||||
<div
|
||||
v-if="heroProject.summary?.milestone_summary?.length"
|
||||
class="hero-milestones"
|
||||
>
|
||||
<div
|
||||
v-for="(ms, i) in heroProject.summary.milestone_summary
|
||||
.filter((m) => m.status !== 'archived')
|
||||
.slice(0, 3)"
|
||||
:key="ms.id"
|
||||
class="ms-row"
|
||||
>
|
||||
<span class="ms-label">{{ ms.title }}</span>
|
||||
<div class="ms-track">
|
||||
<div
|
||||
class="ms-fill"
|
||||
:style="{ width: ms.pct + '%', background: milestoneColor(i) }"
|
||||
></div>
|
||||
</div>
|
||||
<span class="ms-pct">{{ Math.round(ms.pct) }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Recent items -->
|
||||
<div v-if="heroRecentItems.length" class="hero-recent">
|
||||
<span class="hero-section-label">Recent</span>
|
||||
<div class="hero-items">
|
||||
<router-link
|
||||
v-for="item in heroRecentItems"
|
||||
:key="item.id"
|
||||
:to="item.status != null ? `/tasks/${item.id}` : `/notes/${item.id}`"
|
||||
class="hero-item"
|
||||
>
|
||||
<span class="hero-item-icon">{{ item.status != null ? '◉' : '◈' }}</span>
|
||||
<span class="hero-item-title">{{ item.title || 'Untitled' }}</span>
|
||||
<StatusBadge
|
||||
v-if="item.status"
|
||||
:status="(item.status as TaskStatus)"
|
||||
class="hero-item-badge"
|
||||
/>
|
||||
</router-link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Next up -->
|
||||
<div v-if="heroNextUp" class="hero-next-up">
|
||||
<span class="hero-section-label">Next up</span>
|
||||
<router-link :to="`/tasks/${heroNextUp.id}`" class="hero-next-link">
|
||||
<PriorityBadge :priority="heroNextUp.priority ?? 'none'" />
|
||||
{{ heroNextUp.title }}
|
||||
</router-link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Active Projects grid ────────────────────────────── -->
|
||||
<div v-if="activeProjects.length" class="projects-section">
|
||||
<div class="section-header">
|
||||
<h2>Projects</h2>
|
||||
<router-link to="/projects" class="see-all">See all →</router-link>
|
||||
</div>
|
||||
<div class="projects-grid">
|
||||
<div
|
||||
v-for="project in activeProjects"
|
||||
:key="project.id"
|
||||
class="project-card"
|
||||
>
|
||||
<div class="project-card-top">
|
||||
<router-link
|
||||
:to="`/projects/${project.id}`"
|
||||
class="project-card-title"
|
||||
>
|
||||
{{ project.title }}
|
||||
</router-link>
|
||||
<router-link
|
||||
:to="`/workspace/${project.id}`"
|
||||
class="btn-workspace-sm"
|
||||
title="Open Workspace"
|
||||
>▶</router-link>
|
||||
</div>
|
||||
|
||||
<!-- Urgency badges -->
|
||||
<div class="project-urgency">
|
||||
<span
|
||||
v-if="(project.summary?.task_counts?.in_progress ?? 0) > 0"
|
||||
class="urgency-badge urgency-in-progress"
|
||||
>{{ project.summary!.task_counts.in_progress }} in progress</span>
|
||||
<span
|
||||
v-if="(project.summary?.task_counts?.todo ?? 0) > 0"
|
||||
class="urgency-badge urgency-todo"
|
||||
>{{ project.summary!.task_counts.todo }} todo</span>
|
||||
<span
|
||||
v-if="project.summary && !project.summary.task_counts.in_progress && !project.summary.task_counts.todo"
|
||||
class="urgency-badge urgency-clear"
|
||||
>All clear</span>
|
||||
<span v-if="!project.summary" class="urgency-badge urgency-loading">Loading…</span>
|
||||
</div>
|
||||
|
||||
<!-- Milestone bars (up to 2) -->
|
||||
<template v-if="project.summary?.milestone_summary?.length">
|
||||
<div
|
||||
v-for="(ms, i) in project.summary.milestone_summary
|
||||
.filter((m) => m.status !== 'archived')
|
||||
.slice(0, 2)"
|
||||
:key="ms.id"
|
||||
class="ms-row"
|
||||
>
|
||||
<span class="ms-label">{{ ms.title }}</span>
|
||||
<div class="ms-track">
|
||||
<div
|
||||
class="ms-fill"
|
||||
:style="{ width: ms.pct + '%', background: milestoneColor(i) }"
|
||||
></div>
|
||||
</div>
|
||||
<span class="ms-pct">{{ Math.round(ms.pct) }}%</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Inbox: orphaned items ───────────────────────────── -->
|
||||
<div
|
||||
v-if="orphanTasks.length || orphanNotes.length"
|
||||
class="inbox-section"
|
||||
>
|
||||
<button class="inbox-header" @click="inboxOpen = !inboxOpen">
|
||||
<span class="inbox-toggle">{{ inboxOpen ? '▼' : '▶' }}</span>
|
||||
<h2>
|
||||
Inbox
|
||||
<span class="inbox-count">{{ orphanTasks.length + orphanNotes.length }}</span>
|
||||
</h2>
|
||||
<span class="inbox-sub">Notes and tasks without a project</span>
|
||||
</button>
|
||||
<div v-if="inboxOpen" class="inbox-items">
|
||||
<TaskCard
|
||||
v-for="task in orphanTasks"
|
||||
:key="task.id"
|
||||
:task="task"
|
||||
compact
|
||||
@status-toggle="onStatusToggle"
|
||||
/>
|
||||
<NoteCard
|
||||
v-for="note in orphanNotes"
|
||||
:key="note.id"
|
||||
:note="note"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
</main>
|
||||
|
||||
<!-- Event slide-over -->
|
||||
<EventSlideOver
|
||||
v-if="eventSlideOverOpen"
|
||||
:event="editingEvent"
|
||||
initial-date=""
|
||||
@close="eventSlideOverOpen = false"
|
||||
@created="eventSlideOverOpen = false"
|
||||
@updated="onEventUpdated"
|
||||
@deleted="onEventDeleted"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.home {
|
||||
max-width: var(--page-max-width);
|
||||
margin: 2rem auto;
|
||||
padding: 0 var(--page-padding-x);
|
||||
}
|
||||
|
||||
/* ─── Chat widget ────────────────────────────────────────────── */
|
||||
.chat-section {
|
||||
max-width: 720px;
|
||||
margin: 0 auto 1.5rem;
|
||||
}
|
||||
.quick-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 0.4rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
.quick-action-chip {
|
||||
padding: 0.3rem 0.75rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 999px;
|
||||
background: var(--color-bg-secondary);
|
||||
color: var(--color-text);
|
||||
font-size: 0.8rem;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s, color 0.15s, background 0.15s;
|
||||
}
|
||||
.quick-action-chip:hover:not(:disabled) {
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
background: color-mix(in srgb, var(--color-primary) 8%, transparent);
|
||||
}
|
||||
.quick-action-chip:disabled { opacity: 0.4; cursor: default; }
|
||||
|
||||
/* ─── Skeleton loading ───────────────────────────────────────── */
|
||||
.skeleton-hero {
|
||||
height: 180px;
|
||||
border-radius: var(--radius-lg);
|
||||
background: linear-gradient(90deg, var(--color-bg-secondary) 25%, var(--color-border) 50%, var(--color-bg-secondary) 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: skeleton-shimmer 1.4s ease infinite;
|
||||
margin-bottom: 1.75rem;
|
||||
}
|
||||
.skeleton-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1.75rem;
|
||||
}
|
||||
.skeleton-card {
|
||||
height: 120px;
|
||||
border-radius: var(--radius-md);
|
||||
background: linear-gradient(90deg, var(--color-bg-secondary) 25%, var(--color-border) 50%, var(--color-bg-secondary) 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: skeleton-shimmer 1.4s ease infinite;
|
||||
}
|
||||
@keyframes skeleton-shimmer {
|
||||
0% { background-position: 200% 0; }
|
||||
100% { background-position: -200% 0; }
|
||||
}
|
||||
|
||||
/* ─── Hero card ──────────────────────────────────────────────── */
|
||||
.hero-card {
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 1.25rem 1.5rem;
|
||||
margin-bottom: 1.75rem;
|
||||
box-shadow: 0 2px 16px rgba(91, 74, 138, 0.08), 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
.hero-top {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.hero-identity {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.hero-label {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.hero-title {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
text-decoration: none;
|
||||
letter-spacing: -0.02em;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.hero-title:hover { color: var(--color-primary); }
|
||||
|
||||
.btn-workspace-hero {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
padding: 0.55rem 1.1rem;
|
||||
background: var(--gradient-cta);
|
||||
color: #fff;
|
||||
border-radius: var(--radius-sm);
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
box-shadow: 0 1px 6px rgba(91, 74, 138, 0.3);
|
||||
transition: opacity 0.15s, box-shadow 0.15s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.btn-workspace-hero:hover {
|
||||
opacity: 0.9;
|
||||
box-shadow: 0 3px 14px rgba(91, 74, 138, 0.45);
|
||||
}
|
||||
|
||||
.hero-milestones { margin-bottom: 0.75rem; }
|
||||
|
||||
.hero-section-label {
|
||||
font-size: 0.68rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.07em;
|
||||
color: var(--color-text-muted);
|
||||
display: block;
|
||||
margin-bottom: 0.4rem;
|
||||
}
|
||||
|
||||
.hero-recent { margin-bottom: 0.75rem; }
|
||||
.hero-items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
.hero-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.3rem 0.5rem;
|
||||
border-radius: var(--radius-sm);
|
||||
text-decoration: none;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 0.88rem;
|
||||
transition: background 0.12s, color 0.12s;
|
||||
}
|
||||
.hero-item:hover {
|
||||
background: color-mix(in srgb, var(--color-primary) 6%, transparent);
|
||||
color: var(--color-text);
|
||||
}
|
||||
.hero-item-icon { opacity: 0.45; font-size: 0.75rem; flex-shrink: 0; }
|
||||
.hero-item-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.hero-item-badge { flex-shrink: 0; }
|
||||
|
||||
.hero-next-up {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.hero-next-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--color-text);
|
||||
text-decoration: none;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
.hero-next-link:hover { color: var(--color-primary); }
|
||||
|
||||
/* ─── Projects grid ──────────────────────────────────────────── */
|
||||
.projects-section { margin-bottom: 1.75rem; }
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
.section-header h2 { margin: 0; font-size: 1rem; font-weight: 500; }
|
||||
.see-all { font-size: 0.85rem; color: var(--color-primary); text-decoration: none; }
|
||||
.see-all:hover { text-decoration: underline; }
|
||||
|
||||
.projects-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 0.75rem;
|
||||
}
|
||||
.project-card {
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 0.85rem 1rem;
|
||||
transition: box-shadow 0.18s, border-color 0.15s, transform 0.18s;
|
||||
}
|
||||
.project-card:hover {
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
|
||||
border-color: var(--color-primary);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
.project-card-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 0.5rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.project-card-title {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
text-decoration: none;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.project-card-title:hover { color: var(--color-primary); }
|
||||
.btn-workspace-sm {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
background: color-mix(in srgb, var(--color-primary) 12%, transparent);
|
||||
color: var(--color-primary);
|
||||
border-radius: var(--radius-sm);
|
||||
text-decoration: none;
|
||||
font-size: 0.75rem;
|
||||
flex-shrink: 0;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
}
|
||||
.btn-workspace-sm:hover {
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.project-urgency {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.3rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.urgency-badge {
|
||||
font-size: 0.72rem;
|
||||
padding: 0.1rem 0.45rem;
|
||||
border-radius: var(--radius-pill);
|
||||
font-weight: 500;
|
||||
}
|
||||
.urgency-in-progress {
|
||||
background: color-mix(in srgb, #5B4A8A 15%, transparent);
|
||||
color: #5B4A8A;
|
||||
}
|
||||
.urgency-todo {
|
||||
background: color-mix(in srgb, var(--color-text-muted) 12%, transparent);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.urgency-clear {
|
||||
background: color-mix(in srgb, #22c55e 12%, transparent);
|
||||
color: #16a34a;
|
||||
}
|
||||
.urgency-loading { color: var(--color-text-muted); }
|
||||
|
||||
/* ─── Inbox ──────────────────────────────────────────────────── */
|
||||
.inbox-section {
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
overflow: hidden;
|
||||
margin-bottom: 1.75rem;
|
||||
}
|
||||
.inbox-header {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
color: var(--color-text);
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.inbox-header:hover { background: var(--color-bg-secondary); }
|
||||
.inbox-toggle { font-size: 0.75rem; color: var(--color-text-muted); }
|
||||
.inbox-header h2 {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 500;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.inbox-count {
|
||||
background: color-mix(in srgb, var(--color-text-muted) 15%, transparent);
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.75rem;
|
||||
padding: 0.05rem 0.4rem;
|
||||
border-radius: var(--radius-pill);
|
||||
}
|
||||
.inbox-sub {
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
margin-left: auto;
|
||||
}
|
||||
.inbox-items {
|
||||
padding: 0.5rem 0.75rem 0.75rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
/* ─── Shared: milestone bars ─────────────────────────────────── */
|
||||
.ms-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
margin-bottom: 0.3rem;
|
||||
}
|
||||
.ms-label {
|
||||
font-size: 0.72rem;
|
||||
color: var(--color-text-muted);
|
||||
width: 5rem;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.ms-track {
|
||||
flex: 1;
|
||||
height: 5px;
|
||||
background: var(--color-bg-secondary);
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.ms-fill {
|
||||
height: 100%;
|
||||
border-radius: 999px;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
.ms-pct {
|
||||
font-size: 0.7rem;
|
||||
color: var(--color-text-muted);
|
||||
width: 2.2rem;
|
||||
text-align: right;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ─── Mobile ─────────────────────────────────────────────────── */
|
||||
@media (max-width: 680px) {
|
||||
.home { padding: 0 var(--page-padding-x); margin: 1rem auto; }
|
||||
.hero-top { flex-direction: column; align-items: flex-start; }
|
||||
.btn-workspace-hero { width: 100%; justify-content: center; }
|
||||
.projects-grid { grid-template-columns: 1fr; }
|
||||
.inbox-sub { display: none; }
|
||||
}
|
||||
|
||||
/* ─── Upcoming events ────────────────────────────────────────── */
|
||||
.upcoming-events-section {
|
||||
margin-bottom: 1.75rem;
|
||||
}
|
||||
.upcoming-events-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.upcoming-event-card {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
padding: 0.55rem 0.75rem;
|
||||
background: var(--color-bg-card);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
font-family: inherit;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
width: 100%;
|
||||
}
|
||||
.upcoming-event-card:hover {
|
||||
border-color: var(--color-primary);
|
||||
background: color-mix(in srgb, var(--color-primary) 6%, var(--color-bg-card));
|
||||
}
|
||||
.upcoming-event-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
flex-shrink: 0;
|
||||
margin-top: 4px;
|
||||
}
|
||||
.upcoming-event-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.1rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.upcoming-event-title {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.upcoming-event-time {
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.upcoming-event-loc {
|
||||
font-size: 0.72rem;
|
||||
color: var(--color-text-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.upcoming-events-more {
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
padding: 0.25rem 0;
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
.see-all-inline {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
}
|
||||
.see-all-inline:hover { text-decoration: underline; }
|
||||
</style>
|
||||
@@ -1,948 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
|
||||
import { useBackgroundRefresh } from '@/composables/useBackgroundRefresh'
|
||||
import { useChatStore } from '@/stores/chat'
|
||||
import ChatPanel from '@/components/ChatPanel.vue'
|
||||
import WeatherCard from '@/components/WeatherCard.vue'
|
||||
import { RotateCcw, Sparkles, Check, X } from 'lucide-vue-next'
|
||||
import {
|
||||
apiGet,
|
||||
apiPost,
|
||||
getJournalToday,
|
||||
getJournalDay,
|
||||
getJournalDays,
|
||||
triggerJournalPrep,
|
||||
listEvents,
|
||||
listJournalMoments,
|
||||
runJournalCurator,
|
||||
listPendingActions,
|
||||
approvePendingAction,
|
||||
rejectPendingAction,
|
||||
type EventEntry,
|
||||
type JournalMoment,
|
||||
type PendingCuratorAction,
|
||||
} from '@/api/client'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
|
||||
interface WeatherDay {
|
||||
day: string
|
||||
condition: string
|
||||
high: number
|
||||
low: number
|
||||
precip_probability: number | null
|
||||
precip_mm: number | null
|
||||
windspeed_max: number
|
||||
}
|
||||
interface WeatherData {
|
||||
location: string
|
||||
fetched_at: string
|
||||
current_temp: number
|
||||
condition: string
|
||||
today_high: number | null
|
||||
today_low: number | null
|
||||
yesterday_high: number | null
|
||||
yesterday_low: number | null
|
||||
wind_unit?: string
|
||||
forecast: WeatherDay[]
|
||||
}
|
||||
interface CurrentConditions {
|
||||
temperature: number | null
|
||||
windspeed: number | null
|
||||
description: string
|
||||
precip_next_3h: number[]
|
||||
temp_unit: string
|
||||
location: string
|
||||
}
|
||||
|
||||
const chatStore = useChatStore()
|
||||
const toastStore = useToastStore()
|
||||
|
||||
// ── Day picker + conversation state ──────────────────────────────────────────
|
||||
const days = ref<string[]>([])
|
||||
const todayDate = ref<string | null>(null)
|
||||
const selectedDay = ref<string | null>(null)
|
||||
const dayConvId = ref<number | null>(null)
|
||||
const isToday = computed(() => selectedDay.value !== null && selectedDay.value === todayDate.value)
|
||||
|
||||
// ── Curator + captures panel (Phase 1b) ──────────────────────────────────────
|
||||
// The journal chat model has no tools — moments / tasks land via a curator
|
||||
// pass (services/curator.py). The "Process captures now" button triggers
|
||||
// a pass manually; the captures panel shows everything captured for the
|
||||
// selected day.
|
||||
const moments = ref<JournalMoment[]>([])
|
||||
const momentsLoading = ref(false)
|
||||
const curatorRunning = ref(false)
|
||||
|
||||
// Needs Review queue — curator-proposed mutations awaiting user approval.
|
||||
// Visible only when count > 0; sits above the Captures panel in the rail.
|
||||
const pendingActions = ref<PendingCuratorAction[]>([])
|
||||
const pendingLoading = ref(false)
|
||||
const reviewingIds = ref<Set<number>>(new Set())
|
||||
|
||||
async function loadPendingActions() {
|
||||
pendingLoading.value = true
|
||||
try {
|
||||
const res = await listPendingActions()
|
||||
pendingActions.value = res.pending
|
||||
} catch {
|
||||
/* silent — pending feature may not be deployed yet */
|
||||
} finally {
|
||||
pendingLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function approvePending(action: PendingCuratorAction) {
|
||||
if (reviewingIds.value.has(action.id)) return
|
||||
reviewingIds.value.add(action.id)
|
||||
try {
|
||||
const result = await approvePendingAction(action.id)
|
||||
if ((result as { error?: string }).error) {
|
||||
toastStore.show(`Approve failed: ${(result as { error: string }).error}`, 'error')
|
||||
} else {
|
||||
toastStore.show(`Applied: ${action.action_type}`, 'success')
|
||||
}
|
||||
await Promise.all([loadPendingActions(), loadMoments()])
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Approve failed'
|
||||
toastStore.show(msg, 'error')
|
||||
} finally {
|
||||
reviewingIds.value.delete(action.id)
|
||||
}
|
||||
}
|
||||
|
||||
async function rejectPending(action: PendingCuratorAction) {
|
||||
if (reviewingIds.value.has(action.id)) return
|
||||
reviewingIds.value.add(action.id)
|
||||
try {
|
||||
await rejectPendingAction(action.id)
|
||||
toastStore.show(`Rejected: ${action.action_type}`, 'success')
|
||||
await loadPendingActions()
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Reject failed'
|
||||
toastStore.show(msg, 'error')
|
||||
} finally {
|
||||
reviewingIds.value.delete(action.id)
|
||||
}
|
||||
}
|
||||
|
||||
// Human-readable subject for the card header.
|
||||
function pendingTitle(a: PendingCuratorAction): string {
|
||||
const verb = a.action_type.startsWith('delete_') ? 'Delete'
|
||||
: a.action_type.startsWith('update_') ? 'Update'
|
||||
: a.action_type
|
||||
const target = a.target_label || (a.target_type ?? 'item')
|
||||
return `${verb} ${target}`
|
||||
}
|
||||
|
||||
// Compute the field-level diff between current snapshot and proposed payload.
|
||||
// Returns [{field, before, after}] only for fields the curator wants to change.
|
||||
interface DiffRow { field: string; before: unknown; after: unknown }
|
||||
function pendingDiff(a: PendingCuratorAction): DiffRow[] {
|
||||
const snap = a.current_snapshot || {}
|
||||
const payload = a.payload || {}
|
||||
const rows: DiffRow[] = []
|
||||
// Map payload param names → snapshot key names where they differ.
|
||||
// update_note uses `query` (the lookup) but we diff the target's own
|
||||
// fields — skip `query` itself from the diff.
|
||||
const skip = new Set(['query', 'task', 'project', 'milestone', 'confirmed'])
|
||||
for (const [key, after] of Object.entries(payload)) {
|
||||
if (skip.has(key)) continue
|
||||
if (after === null || after === undefined || after === '') continue
|
||||
const before = (snap as Record<string, unknown>)[key]
|
||||
if (JSON.stringify(before) === JSON.stringify(after)) continue
|
||||
rows.push({ field: key, before, after })
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
function formatDiffValue(v: unknown): string {
|
||||
if (v === null || v === undefined) return '—'
|
||||
if (Array.isArray(v)) return v.length ? v.join(', ') : '—'
|
||||
if (typeof v === 'object') return JSON.stringify(v)
|
||||
return String(v)
|
||||
}
|
||||
|
||||
async function loadMoments() {
|
||||
if (!selectedDay.value) {
|
||||
moments.value = []
|
||||
return
|
||||
}
|
||||
momentsLoading.value = true
|
||||
try {
|
||||
// /api/journal/moments takes date_from + date_to (NOT `date`).
|
||||
// Passing a single ISO date for both bounds gives us the moments
|
||||
// recorded on that calendar day, which is what the captures panel
|
||||
// means by "today".
|
||||
moments.value = await listJournalMoments({
|
||||
date_from: selectedDay.value,
|
||||
date_to: selectedDay.value,
|
||||
limit: 100,
|
||||
})
|
||||
} catch {
|
||||
/* silent — moments may not exist yet */
|
||||
} finally {
|
||||
momentsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function triggerCurator() {
|
||||
if (curatorRunning.value || !dayConvId.value) return
|
||||
curatorRunning.value = true
|
||||
try {
|
||||
const result = await runJournalCurator(dayConvId.value)
|
||||
if (result.error) {
|
||||
toastStore.show(`Curator error: ${result.error}`, 'error')
|
||||
} else {
|
||||
const captured = result.tools_succeeded
|
||||
const total = result.tools_attempted
|
||||
const detail = captured === total
|
||||
? `${captured} tool calls`
|
||||
: `${captured}/${total} tool calls`
|
||||
// toastStore only supports success/error/warning; use success for
|
||||
// both "captured something" and the no-op case (success in the
|
||||
// sense that the curator ran cleanly).
|
||||
toastStore.show(
|
||||
captured > 0
|
||||
? `Captured ${detail} (${result.duration_ms}ms)`
|
||||
: `Nothing new to capture (${result.duration_ms}ms)`,
|
||||
'success',
|
||||
)
|
||||
}
|
||||
await Promise.all([loadMoments(), loadPendingActions()])
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Curator failed'
|
||||
toastStore.show(`Curator failed: ${msg}`, 'error')
|
||||
} finally {
|
||||
curatorRunning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function formatMomentTime(iso: string): string {
|
||||
try {
|
||||
return new Date(iso).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
// ── Weather panel ────────────────────────────────────────────────────────────
|
||||
const weatherData = ref<WeatherData[]>([])
|
||||
const selectedWeatherIdx = ref(0)
|
||||
const tempUnit = ref<string>('C')
|
||||
const currentConditions = ref<CurrentConditions | null>(null)
|
||||
let currentWeatherTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
async function loadCurrentConditions() {
|
||||
try {
|
||||
currentConditions.value = await apiGet<CurrentConditions>('/api/journal/weather/current')
|
||||
if (currentConditions.value?.temperature != null && weatherData.value.length > 0) {
|
||||
weatherData.value[0] = { ...weatherData.value[0], current_temp: currentConditions.value.temperature }
|
||||
}
|
||||
} catch { /* silent */ }
|
||||
}
|
||||
|
||||
async function loadWeather() {
|
||||
try {
|
||||
const data = await apiGet<{ locations: WeatherData[]; temp_unit: string }>('/api/journal/weather')
|
||||
weatherData.value = data.locations ?? []
|
||||
tempUnit.value = data.temp_unit ?? 'C'
|
||||
} catch { /* silent */ }
|
||||
}
|
||||
|
||||
const refreshingWeather = ref(false)
|
||||
async function refreshWeather() {
|
||||
refreshingWeather.value = true
|
||||
try {
|
||||
const data = await apiPost<{ locations: WeatherData[]; temp_unit: string }>('/api/journal/weather/refresh', {})
|
||||
weatherData.value = data.locations ?? []
|
||||
tempUnit.value = data.temp_unit ?? 'C'
|
||||
} catch { /* silent */ }
|
||||
finally { refreshingWeather.value = false }
|
||||
}
|
||||
|
||||
// ── Upcoming events ──────────────────────────────────────────────────────────
|
||||
const upcomingEvents = ref<EventEntry[]>([])
|
||||
|
||||
interface GroupedDay {
|
||||
label: string
|
||||
dateKey: string
|
||||
events: EventEntry[]
|
||||
}
|
||||
|
||||
const groupedEvents = computed<GroupedDay[]>(() => {
|
||||
const groups = new Map<string, EventEntry[]>()
|
||||
const today = new Date()
|
||||
today.setHours(0, 0, 0, 0)
|
||||
for (const ev of upcomingEvents.value) {
|
||||
const d = new Date(ev.start_dt)
|
||||
const key = d.toISOString().slice(0, 10)
|
||||
if (!groups.has(key)) groups.set(key, [])
|
||||
groups.get(key)!.push(ev)
|
||||
}
|
||||
const result: GroupedDay[] = []
|
||||
for (const [key, events] of groups) {
|
||||
const d = new Date(key + 'T00:00:00')
|
||||
const diff = Math.round((d.getTime() - today.getTime()) / 86_400_000)
|
||||
let label: string
|
||||
if (diff === 0) label = 'Today'
|
||||
else if (diff === 1) label = 'Tomorrow'
|
||||
else label = d.toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric' })
|
||||
result.push({ label, dateKey: key, events })
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
function formatEventTime(ev: EventEntry): string {
|
||||
if (ev.all_day) return 'All day'
|
||||
const d = new Date(ev.start_dt)
|
||||
return d.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })
|
||||
}
|
||||
|
||||
async function loadEvents() {
|
||||
try {
|
||||
// Window: today 00:00 → 14 days out. Matches the prep's framing — events
|
||||
// earlier today (already past) still surface here, grouped under "Today",
|
||||
// so the right rail aligns with what the prep references.
|
||||
const start = new Date()
|
||||
start.setHours(0, 0, 0, 0)
|
||||
const end = new Date(start)
|
||||
end.setDate(end.getDate() + 14)
|
||||
end.setHours(23, 59, 59, 999)
|
||||
upcomingEvents.value = await listEvents(start.toISOString(), end.toISOString())
|
||||
} catch { /* silent */ }
|
||||
}
|
||||
|
||||
// ── Day load + switch ────────────────────────────────────────────────────────
|
||||
async function loadDay(iso: string) {
|
||||
const payload = iso === todayDate.value ? await getJournalToday() : await getJournalDay(iso)
|
||||
if (payload.conversation) {
|
||||
dayConvId.value = payload.conversation.id
|
||||
await chatStore.fetchConversation(payload.conversation.id)
|
||||
} else {
|
||||
dayConvId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAll() {
|
||||
try {
|
||||
const today = await getJournalToday()
|
||||
todayDate.value = today.day_date
|
||||
selectedDay.value = today.day_date
|
||||
if (today.conversation) {
|
||||
dayConvId.value = today.conversation.id
|
||||
await chatStore.fetchConversation(today.conversation.id)
|
||||
}
|
||||
} catch { /* silent */ }
|
||||
|
||||
try {
|
||||
days.value = await getJournalDays()
|
||||
if (todayDate.value && !days.value.includes(todayDate.value)) {
|
||||
days.value = [todayDate.value, ...days.value]
|
||||
}
|
||||
} catch { /* silent */ }
|
||||
|
||||
await Promise.all([
|
||||
loadWeather(),
|
||||
loadCurrentConditions(),
|
||||
loadEvents(),
|
||||
loadMoments(),
|
||||
loadPendingActions(),
|
||||
])
|
||||
}
|
||||
|
||||
watch(selectedDay, async (iso) => {
|
||||
if (!iso) return
|
||||
// For non-today dates, loadDay handles its own day-data fetch; in both
|
||||
// cases we want the captures panel to reflect the selected day.
|
||||
try {
|
||||
if (iso !== todayDate.value) await loadDay(iso)
|
||||
await loadMoments()
|
||||
} catch { /* silent */ }
|
||||
})
|
||||
|
||||
// ── Manual prep regeneration ─────────────────────────────────────────────────
|
||||
const triggering = ref(false)
|
||||
async function triggerPrep() {
|
||||
if (triggering.value) return
|
||||
triggering.value = true
|
||||
try {
|
||||
await triggerJournalPrep()
|
||||
if (_mounted) await loadAll()
|
||||
} finally {
|
||||
if (_mounted) triggering.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function dayLabel(iso: string): string {
|
||||
if (iso === todayDate.value) return 'Today'
|
||||
const d = new Date(iso + 'T00:00:00')
|
||||
return d.toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric' })
|
||||
}
|
||||
|
||||
const todayBadge = computed(() => {
|
||||
return new Date().toLocaleDateString(undefined, { weekday: 'long', month: 'long', day: 'numeric' })
|
||||
})
|
||||
|
||||
// ── Background refresh ───────────────────────────────────────────────────────
|
||||
async function _backgroundRefreshMessages() {
|
||||
try {
|
||||
if (!_mounted || !isToday.value || !dayConvId.value) return
|
||||
await chatStore.fetchConversation(dayConvId.value)
|
||||
} catch { /* silent */ }
|
||||
}
|
||||
|
||||
useBackgroundRefresh(
|
||||
_backgroundRefreshMessages,
|
||||
60_000,
|
||||
() => !chatStore.streaming && isToday.value && !!dayConvId.value,
|
||||
)
|
||||
|
||||
let _mounted = true
|
||||
onUnmounted(() => {
|
||||
_mounted = false
|
||||
if (currentWeatherTimer) clearInterval(currentWeatherTimer)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
await loadAll()
|
||||
currentWeatherTimer = setInterval(loadCurrentConditions, 30 * 60 * 1000)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="journal-root">
|
||||
<div class="journal-shell">
|
||||
<header class="journal-header">
|
||||
<div class="journal-header-left">
|
||||
<h1 class="journal-title">Journal</h1>
|
||||
<span class="journal-today-badge">{{ todayBadge }}</span>
|
||||
</div>
|
||||
<div class="journal-header-right">
|
||||
<select v-if="days.length" v-model="selectedDay" class="journal-day-select">
|
||||
<option v-for="d in days" :key="d" :value="d">{{ dayLabel(d) }}</option>
|
||||
</select>
|
||||
<button
|
||||
class="btn-trigger"
|
||||
@click="triggerPrep"
|
||||
:disabled="triggering || !isToday"
|
||||
title="Regenerate today's daily prep"
|
||||
>{{ triggering ? '…' : 'Refresh prep' }}</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Center: chat (prep is the first assistant message inside) -->
|
||||
<div class="journal-center">
|
||||
<ChatPanel
|
||||
variant="full"
|
||||
briefingMode
|
||||
:readOnly="!isToday"
|
||||
placeholder="Tell your journal…"
|
||||
class="journal-chat-panel"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Right: Weather + Events + News -->
|
||||
<div class="journal-right">
|
||||
<div class="weather-section" v-if="weatherData.length">
|
||||
<div class="weather-section-header">
|
||||
<div class="weather-tabs" v-if="weatherData.length > 1">
|
||||
<button
|
||||
v-for="(loc, i) in weatherData"
|
||||
:key="(loc as WeatherData).location"
|
||||
class="weather-tab"
|
||||
:class="{ active: selectedWeatherIdx === i }"
|
||||
@click="selectedWeatherIdx = i"
|
||||
>{{ (loc as WeatherData).location }}</button>
|
||||
</div>
|
||||
<button
|
||||
class="weather-refresh-btn"
|
||||
:class="{ spinning: refreshingWeather }"
|
||||
:disabled="refreshingWeather"
|
||||
@click="refreshWeather"
|
||||
title="Refresh weather"
|
||||
>
|
||||
<RotateCcw :size="16" />
|
||||
</button>
|
||||
</div>
|
||||
<WeatherCard
|
||||
:weather="weatherData[selectedWeatherIdx]"
|
||||
:temp-unit="tempUnit"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Needs Review panel: curator-proposed mutations awaiting user
|
||||
approval (update_note, delete_note, update_milestone, etc.).
|
||||
Hidden when nothing is pending so the rail stays calm. -->
|
||||
<div v-if="pendingActions.length > 0" class="review-section">
|
||||
<div class="panel-label-row">
|
||||
<div class="panel-label review-panel-label">
|
||||
Needs Review <span class="review-count">{{ pendingActions.length }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="review-list">
|
||||
<li v-for="a in pendingActions" :key="a.id" class="review-row">
|
||||
<div class="review-header">
|
||||
<span class="review-action-type">{{ a.action_type }}</span>
|
||||
<span class="review-title">{{ pendingTitle(a) }}</span>
|
||||
</div>
|
||||
<div v-if="a.action_type.startsWith('delete_')" class="review-delete-warn">
|
||||
Permanent delete — the entry will be gone.
|
||||
</div>
|
||||
<ul v-else-if="pendingDiff(a).length" class="review-diff">
|
||||
<li v-for="row in pendingDiff(a)" :key="row.field" class="review-diff-row">
|
||||
<span class="review-diff-field">{{ row.field }}</span>
|
||||
<span class="review-diff-before">{{ formatDiffValue(row.before) }}</span>
|
||||
<span class="review-diff-arrow">→</span>
|
||||
<span class="review-diff-after">{{ formatDiffValue(row.after) }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else class="review-diff-empty">
|
||||
No visible change preview; review payload via DB if needed.
|
||||
</div>
|
||||
<div class="review-actions">
|
||||
<button
|
||||
class="review-btn review-btn--approve"
|
||||
:disabled="reviewingIds.has(a.id)"
|
||||
@click="approvePending(a)"
|
||||
title="Apply the proposed change"
|
||||
>
|
||||
<Check :size="14" /> Approve
|
||||
</button>
|
||||
<button
|
||||
class="review-btn review-btn--reject"
|
||||
:disabled="reviewingIds.has(a.id)"
|
||||
@click="rejectPending(a)"
|
||||
title="Discard the proposal"
|
||||
>
|
||||
<X :size="14" /> Reject
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Captures panel: shows moments extracted by the curator for the
|
||||
selected day. The chat model is tools=[]; the curator pass
|
||||
(manual button below, scheduler in phase 2) populates this. -->
|
||||
<div class="captures-section">
|
||||
<div class="panel-label-row">
|
||||
<div class="panel-label">Captures</div>
|
||||
<button
|
||||
class="captures-trigger-btn"
|
||||
:class="{ spinning: curatorRunning }"
|
||||
:disabled="curatorRunning || !dayConvId || !isToday"
|
||||
:title="isToday ? 'Run curator on this conversation' : 'Curator only runs on the current day'"
|
||||
@click="triggerCurator"
|
||||
>
|
||||
<Sparkles :size="14" />
|
||||
{{ curatorRunning ? 'Working…' : 'Process captures' }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="momentsLoading && !moments.length" class="captures-empty">
|
||||
Loading…
|
||||
</div>
|
||||
<div v-else-if="!moments.length" class="captures-empty">
|
||||
No captures yet for {{ isToday ? 'today' : 'this day' }}.
|
||||
<span v-if="isToday">Talk in the journal, then press "Process captures".</span>
|
||||
</div>
|
||||
<ul v-else class="captures-list">
|
||||
<li v-for="m in moments" :key="m.id" class="capture-row">
|
||||
<div class="capture-time">{{ formatMomentTime(m.occurred_at) }}</div>
|
||||
<div class="capture-body">
|
||||
<div class="capture-content">{{ m.content }}</div>
|
||||
<div v-if="m.people.length || m.places.length || m.task_ids.length || m.note_ids.length" class="capture-meta">
|
||||
<span v-if="m.people.length" class="capture-chip">
|
||||
{{ m.people.map(p => p.title).join(', ') }}
|
||||
</span>
|
||||
<span v-if="m.places.length" class="capture-chip">
|
||||
@ {{ m.places.map(p => p.title).join(', ') }}
|
||||
</span>
|
||||
<span v-if="m.task_ids.length" class="capture-chip capture-chip--task">
|
||||
{{ m.task_ids.length }} task{{ m.task_ids.length === 1 ? '' : 's' }}
|
||||
</span>
|
||||
<span v-if="m.note_ids.length" class="capture-chip capture-chip--note">
|
||||
{{ m.note_ids.length }} note{{ m.note_ids.length === 1 ? '' : 's' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="events-section" v-if="groupedEvents.length">
|
||||
<div class="panel-label-row">
|
||||
<div class="panel-label">Upcoming</div>
|
||||
<router-link to="/calendar" class="events-cal-link">Calendar →</router-link>
|
||||
</div>
|
||||
<div class="events-list">
|
||||
<div v-for="group in groupedEvents" :key="group.dateKey" class="events-day-group">
|
||||
<div class="events-day-label">{{ group.label }}</div>
|
||||
<div v-for="ev in group.events" :key="ev.id" class="event-row">
|
||||
<span class="event-dot" :style="ev.color ? { background: ev.color } : {}"></span>
|
||||
<span class="event-body">
|
||||
<span class="event-title">{{ ev.title }}</span>
|
||||
<span class="event-time">{{ formatEventTime(ev) }}</span>
|
||||
<span v-if="ev.location" class="event-loc">{{ ev.location }}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.journal-root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.journal-shell {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr minmax(320px, 35%);
|
||||
grid-template-rows: auto 1fr;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.journal-header {
|
||||
grid-column: 1 / -1;
|
||||
grid-row: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 1.25rem 1rem 1rem;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
flex-shrink: 0;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.journal-header-left { display: flex; align-items: baseline; gap: 0.75rem; }
|
||||
.journal-title {
|
||||
/* h1 inherits Fraunces from theme.css; weight 500 follows the doc's "two weights only" rule */
|
||||
font-size: 1.3rem;
|
||||
margin: 0;
|
||||
color: var(--color-text);
|
||||
}
|
||||
.journal-today-badge { font-size: 0.82rem; color: var(--color-text-muted); }
|
||||
.journal-header-right { display: flex; align-items: center; gap: 0.5rem; }
|
||||
|
||||
.journal-day-select {
|
||||
padding: 0.35rem 0.6rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: var(--color-bg-card);
|
||||
color: var(--color-text);
|
||||
font-size: 0.82rem;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.btn-trigger {
|
||||
padding: 0.35rem 0.8rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: var(--color-bg-card);
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.8rem;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
transition: all 0.15s;
|
||||
font-family: inherit;
|
||||
}
|
||||
.btn-trigger:hover:not(:disabled) { border-color: var(--color-primary); color: var(--color-primary); }
|
||||
.btn-trigger:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
/* ── Center column: prep card + chat ──────────────────────────────────────── */
|
||||
.journal-center {
|
||||
grid-column: 1;
|
||||
grid-row: 2;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.journal-chat-panel { flex: 1; min-height: 0; }
|
||||
|
||||
/* ── Right column ─────────────────────────────────────────────────────────── */
|
||||
.journal-right {
|
||||
grid-column: 2;
|
||||
grid-row: 2;
|
||||
border-left: 1px solid var(--color-border);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.weather-section { flex-shrink: 0; padding: 1rem 1rem 0.5rem; }
|
||||
.weather-section :deep(.weather-card) { margin-bottom: 0; }
|
||||
.weather-section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.weather-refresh-btn {
|
||||
background: none;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
padding: 0.2rem 0.45rem;
|
||||
line-height: 1;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.weather-refresh-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
|
||||
.weather-refresh-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.weather-refresh-btn.spinning { animation: spin 0.8s linear infinite; }
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
|
||||
.weather-tabs { display: flex; gap: 0.25rem; }
|
||||
.weather-tab {
|
||||
padding: 0.3rem 0.7rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: none;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.78rem;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.weather-tab:hover { border-color: var(--color-primary); color: var(--color-primary); }
|
||||
.weather-tab.active {
|
||||
background: color-mix(in srgb, var(--color-primary) 12%, transparent);
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.events-section { padding: 0.75rem 1rem; border-top: 1px solid var(--color-border); }
|
||||
.events-cal-link { font-size: 0.75rem; color: var(--color-text-muted); text-decoration: none; }
|
||||
.events-cal-link:hover { color: var(--color-primary); }
|
||||
.events-list { display: flex; flex-direction: column; gap: 0.6rem; }
|
||||
.events-day-group { display: flex; flex-direction: column; gap: 0.2rem; }
|
||||
.events-day-label {
|
||||
font-size: 0.72rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
.event-row { display: flex; align-items: flex-start; gap: 0.4rem; padding: 0.25rem 0.4rem; border-radius: 6px; }
|
||||
.event-row:hover { background: color-mix(in srgb, var(--color-primary) 6%, transparent); }
|
||||
.event-dot {
|
||||
width: 7px; height: 7px; border-radius: 50%;
|
||||
background: var(--color-primary);
|
||||
flex-shrink: 0; margin-top: 5px;
|
||||
}
|
||||
.event-body { display: flex; flex-direction: column; gap: 0.05rem; min-width: 0; }
|
||||
.event-title { font-size: 0.82rem; font-weight: 500; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.event-time { font-size: 0.72rem; color: var(--color-text-muted); }
|
||||
.event-loc { font-size: 0.7rem; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
|
||||
.panel-label {
|
||||
font-size: 0.72rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--color-primary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.panel-label-row { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
|
||||
|
||||
/* Needs Review panel — curator-proposed mutations awaiting approval.
|
||||
Sits above Captures; visible only when there are pending items. */
|
||||
.review-section {
|
||||
padding: 0.75rem 1rem;
|
||||
border-top: 1px solid var(--color-border);
|
||||
background: color-mix(in srgb, var(--color-warning, #b88a2c) 6%, transparent);
|
||||
}
|
||||
.review-panel-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
color: var(--color-warning, #b88a2c);
|
||||
}
|
||||
.review-count {
|
||||
background: color-mix(in srgb, var(--color-warning, #b88a2c) 20%, transparent);
|
||||
color: var(--color-warning, #b88a2c);
|
||||
border-radius: 999px;
|
||||
padding: 0.05rem 0.5rem;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.review-list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
|
||||
.review-row {
|
||||
padding: 0.6rem;
|
||||
border-radius: 8px;
|
||||
background: var(--color-bg, #111);
|
||||
border: 1px solid color-mix(in srgb, var(--color-warning, #b88a2c) 25%, transparent);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.review-header { display: flex; align-items: baseline; gap: 0.5rem; }
|
||||
.review-action-type {
|
||||
font-family: var(--font-mono, monospace);
|
||||
font-size: 0.7rem;
|
||||
padding: 0.1rem 0.4rem;
|
||||
border-radius: 4px;
|
||||
background: color-mix(in srgb, var(--color-text-muted) 12%, transparent);
|
||||
color: var(--color-text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.review-title { font-size: 0.88rem; font-weight: 500; color: var(--color-text); }
|
||||
.review-delete-warn {
|
||||
font-size: 0.78rem;
|
||||
color: var(--color-danger, #d04848);
|
||||
font-style: italic;
|
||||
padding: 0.3rem 0.5rem;
|
||||
background: color-mix(in srgb, var(--color-danger, #d04848) 8%, transparent);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.review-diff { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
|
||||
.review-diff-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(70px, max-content) 1fr auto 1fr;
|
||||
gap: 0.4rem;
|
||||
align-items: baseline;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.review-diff-field {
|
||||
font-family: var(--font-mono, monospace);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.review-diff-before {
|
||||
color: var(--color-text-muted);
|
||||
text-decoration: line-through;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.review-diff-arrow { color: var(--color-text-muted); }
|
||||
.review-diff-after {
|
||||
color: var(--color-text);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.review-diff-empty { font-size: 0.76rem; color: var(--color-text-muted); font-style: italic; }
|
||||
.review-actions { display: flex; gap: 0.5rem; }
|
||||
.review-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
padding: 0.3rem 0.65rem;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--color-border);
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
}
|
||||
.review-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.review-btn--approve { color: var(--color-success, #22c55e); border-color: color-mix(in srgb, var(--color-success, #22c55e) 50%, transparent); }
|
||||
.review-btn--approve:hover:not(:disabled) { background: color-mix(in srgb, var(--color-success, #22c55e) 12%, transparent); }
|
||||
.review-btn--reject { color: var(--color-text-muted); }
|
||||
.review-btn--reject:hover:not(:disabled) { background: color-mix(in srgb, var(--color-text-muted) 12%, transparent); color: var(--color-text); }
|
||||
|
||||
/* Captures panel — moments extracted by the curator (services/curator.py).
|
||||
Sits above the events panel; the chat is in the center column. */
|
||||
.captures-section { padding: 0.75rem 1rem; border-top: 1px solid var(--color-border); }
|
||||
.captures-trigger-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.72rem;
|
||||
padding: 0.3rem 0.6rem;
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--color-border);
|
||||
background: transparent;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
}
|
||||
.captures-trigger-btn:hover:not(:disabled) {
|
||||
background: color-mix(in srgb, var(--color-primary) 8%, transparent);
|
||||
color: var(--color-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
.captures-trigger-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.captures-trigger-btn.spinning :first-child {
|
||||
animation: captures-spin 1.2s linear infinite;
|
||||
}
|
||||
@keyframes captures-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
|
||||
|
||||
.captures-empty {
|
||||
font-size: 0.78rem;
|
||||
color: var(--color-text-muted);
|
||||
font-style: italic;
|
||||
padding: 0.75rem 0;
|
||||
line-height: 1.45;
|
||||
}
|
||||
.captures-list {
|
||||
list-style: none;
|
||||
margin: 0.5rem 0 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.55rem;
|
||||
max-height: 380px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.capture-row {
|
||||
display: flex;
|
||||
gap: 0.6rem;
|
||||
padding: 0.4rem 0.5rem;
|
||||
border-radius: 8px;
|
||||
border-left: 2px solid color-mix(in srgb, var(--color-primary) 35%, transparent);
|
||||
background: color-mix(in srgb, var(--color-primary) 3%, transparent);
|
||||
}
|
||||
.capture-time {
|
||||
font-size: 0.7rem;
|
||||
color: var(--color-text-muted);
|
||||
flex-shrink: 0;
|
||||
padding-top: 0.1rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.capture-body { min-width: 0; flex: 1; }
|
||||
.capture-content {
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.4;
|
||||
color: var(--color-text);
|
||||
}
|
||||
.capture-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.3rem;
|
||||
margin-top: 0.3rem;
|
||||
}
|
||||
.capture-chip {
|
||||
font-size: 0.68rem;
|
||||
padding: 0.1rem 0.45rem;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--color-text-muted) 12%, transparent);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
.capture-chip--task { background: color-mix(in srgb, var(--color-primary) 14%, transparent); color: var(--color-primary); }
|
||||
.capture-chip--note { background: color-mix(in srgb, var(--color-warning, #b88a2c) 14%, transparent); color: var(--color-warning, #b88a2c); }
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.journal-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
|
||||
.journal-center { grid-column: 1; grid-row: 2; }
|
||||
.journal-right {
|
||||
grid-column: 1; grid-row: 3;
|
||||
border-left: none;
|
||||
border-top: 1px solid var(--color-border);
|
||||
max-height: 300px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -3,10 +3,7 @@ import { ref, computed, watch, onMounted, onUnmounted, nextTick } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { apiGet, apiPatch, listEvents } from "@/api/client";
|
||||
import { fmtCompact } from "@/utils/dateFormat";
|
||||
import { useChatStore } from "@/stores/chat";
|
||||
import GraphView from "@/views/GraphView.vue";
|
||||
import ChatPanel from "@/components/ChatPanel.vue";
|
||||
import ChatInputBar from "@/components/ChatInputBar.vue";
|
||||
import {
|
||||
FileText,
|
||||
CheckSquare,
|
||||
@@ -17,13 +14,10 @@ import {
|
||||
Share2,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
ChevronUp,
|
||||
ChevronDown,
|
||||
X,
|
||||
} from "lucide-vue-next";
|
||||
|
||||
const router = useRouter();
|
||||
const chatStore = useChatStore();
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -254,56 +248,6 @@ function toggleGraphExpand() {
|
||||
localStorage.setItem(_GRAPH_EXP_KEY, String(graphExpanded.value))
|
||||
}
|
||||
|
||||
// ─── Mini-chat widget ─────────────────────────────────────────────────────────
|
||||
|
||||
const chatOpen = ref(false);
|
||||
const chatCollapsed = ref(false);
|
||||
const chatConvId = ref<number | null>(null);
|
||||
async function onMinichatSubmit(payload: { content: string; contextNoteId?: number }) {
|
||||
if (!chatConvId.value) {
|
||||
const conv = await chatStore.createConversation();
|
||||
chatConvId.value = conv.id;
|
||||
await chatStore.fetchConversation(conv.id);
|
||||
} else if (chatStore.currentConversation?.id !== chatConvId.value) {
|
||||
await chatStore.fetchConversation(chatConvId.value);
|
||||
}
|
||||
chatOpen.value = true;
|
||||
chatCollapsed.value = false;
|
||||
await chatStore.sendMessage(payload.content, payload.contextNoteId, undefined, false);
|
||||
}
|
||||
|
||||
// ─── Auto-refresh cards when chat creates/edits notes or tasks ───────────────
|
||||
|
||||
const processedToolCalls = ref(0);
|
||||
|
||||
watch(
|
||||
() => chatStore.streamingToolCalls,
|
||||
(calls) => {
|
||||
for (let i = processedToolCalls.value; i < calls.length; i++) {
|
||||
const tc = calls[i];
|
||||
if (
|
||||
['create_note', 'update_note', 'create_task', 'update_task'].includes(tc.function) &&
|
||||
tc.status === 'success'
|
||||
) {
|
||||
reset();
|
||||
fetchTags();
|
||||
break;
|
||||
}
|
||||
}
|
||||
processedToolCalls.value = calls.length;
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
watch(() => chatStore.streaming, (streaming) => {
|
||||
if (!streaming) processedToolCalls.value = 0;
|
||||
});
|
||||
|
||||
function closeChat() {
|
||||
chatOpen.value = false;
|
||||
chatConvId.value = null;
|
||||
}
|
||||
|
||||
// ─── List item toggle ─────────────────────────────────────────────────────────
|
||||
|
||||
async function toggleListItem(item: KnowledgeItem, index: number) {
|
||||
@@ -424,7 +368,6 @@ onUnmounted(() => {
|
||||
<router-link v-if="overdueCount > 0" to="/tasks" class="overdue-badge">
|
||||
{{ overdueCount }} overdue
|
||||
</router-link>
|
||||
<router-link to="/chat" class="today-link">Chat</router-link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -656,41 +599,6 @@ onUnmounted(() => {
|
||||
|
||||
</div><!-- end knowledge-layout -->
|
||||
|
||||
<!-- Floating mini-chat -->
|
||||
<div class="minichat" :class="{ 'minichat--open': chatOpen }">
|
||||
<!-- Header with controls — only when chat is open -->
|
||||
<div v-if="chatOpen" class="minichat-header">
|
||||
<span class="minichat-title">Chat</span>
|
||||
<div class="minichat-header-actions">
|
||||
<button
|
||||
class="btn-icon-sm"
|
||||
@click="chatCollapsed = !chatCollapsed"
|
||||
:title="chatCollapsed ? 'Expand' : 'Collapse'"
|
||||
>
|
||||
<ChevronUp v-if="chatCollapsed" :size="16" />
|
||||
<ChevronDown v-else :size="16" />
|
||||
</button>
|
||||
<button class="btn-icon-sm" @click="closeChat" title="Close chat">
|
||||
<X :size="16" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Full ChatPanel — when open, not collapsed, conversation exists -->
|
||||
<div v-if="chatOpen && !chatCollapsed && chatConvId" class="minichat-chat-panel">
|
||||
<ChatPanel variant="full" placeholder="Ask anything…" />
|
||||
</div>
|
||||
|
||||
<!-- Standalone input bar — when closed or collapsed -->
|
||||
<div v-if="!chatOpen || chatCollapsed" class="minichat-input-row">
|
||||
<ChatInputBar
|
||||
placeholder="Ask anything…"
|
||||
@submit="onMinichatSubmit"
|
||||
@abort="chatStore.cancelGeneration()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1294,71 +1202,4 @@ onUnmounted(() => {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* ── Mini-chat ───────────────────────────────────────────── */
|
||||
.minichat {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: var(--sidebar-width); /* align with content area past filter panel */
|
||||
right: 0;
|
||||
max-width: var(--page-max-width);
|
||||
margin-inline: auto;
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--color-bg-secondary);
|
||||
border-radius: 16px 16px 0 0;
|
||||
box-shadow: 0 -8px 32px rgba(0,0,0,0.35), 0 -1px 0 rgba(255,255,255,0.05);
|
||||
transition: height 0.2s ease;
|
||||
}
|
||||
.minichat--open {
|
||||
height: 500px;
|
||||
}
|
||||
.knowledge-root.graph-open .minichat {
|
||||
right: 500px;
|
||||
transition: right 0.2s ease;
|
||||
}
|
||||
.knowledge-root.graph-open.graph-expanded .minichat {
|
||||
right: min(960px, 60vw);
|
||||
}
|
||||
|
||||
/* Header row (collapse / close buttons) */
|
||||
.minichat-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 14px;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.06);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.minichat-title {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
}
|
||||
.minichat-header-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* ChatPanel body — fills remaining space */
|
||||
.minichat-chat-panel {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.minichat-chat-panel :deep(.chat-body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
/* Standalone input row (closed / collapsed state) */
|
||||
.minichat-input-row {
|
||||
padding: 10px 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -82,7 +82,7 @@ const appVersion = ref('dev');
|
||||
const restoreFileInput = ref<HTMLInputElement | null>(null);
|
||||
|
||||
// Migrate stored "admin" → "config"; unknown tabs fall back to "general"
|
||||
const VALID_TABS = new Set(["general", "account", "profile", "notifications", "integrations", "data", "voice", "apikeys", "config", "users", "logs", "groups"]);
|
||||
const VALID_TABS = new Set(["general", "account", "profile", "notifications", "integrations", "data", "apikeys", "config", "users", "logs", "groups"]);
|
||||
const _stored = localStorage.getItem("settings_tab") ?? "general";
|
||||
const activeTab = ref(VALID_TABS.has(_stored) ? (_stored === "admin" ? "config" : _stored) : "general");
|
||||
|
||||
@@ -92,7 +92,6 @@ function _loadTabContent(tab: string) {
|
||||
else if (tab === "logs") loadLogsPanel();
|
||||
else if (tab === "groups") loadGroupsPanel();
|
||||
}
|
||||
if (tab === "voice") loadVoiceTab();
|
||||
if (tab === "apikeys") { fetchApiKeys(); }
|
||||
}
|
||||
|
||||
@@ -1482,7 +1481,7 @@ function formatUserDate(iso: string): string {
|
||||
<div class="sidebar-group">
|
||||
<div class="sidebar-group-label">User</div>
|
||||
<button
|
||||
v-for="tab in ['general', 'account', 'profile', 'notifications', 'integrations', 'data', 'voice', 'apikeys']"
|
||||
v-for="tab in ['general', 'account', 'profile', 'notifications', 'integrations', 'data', 'apikeys']"
|
||||
:key="tab"
|
||||
:class="['sidebar-item', { active: activeTab === tab }]"
|
||||
@click="activeTab = tab"
|
||||
@@ -1506,59 +1505,6 @@ function formatUserDate(iso: string): string {
|
||||
|
||||
<!-- ── General ── -->
|
||||
<div v-show="activeTab === 'general'" class="settings-grid">
|
||||
<section class="settings-section full-width">
|
||||
<h2>Assistant</h2>
|
||||
<div class="assistant-grid">
|
||||
<div class="field">
|
||||
<label for="assistant-name">Assistant Name</label>
|
||||
<input
|
||||
id="assistant-name"
|
||||
v-model="assistantName"
|
||||
type="text"
|
||||
placeholder="Fable"
|
||||
class="input"
|
||||
/>
|
||||
<p class="field-hint">The name used in chat messages and LLM context.</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="default-model">Chat & Voice Model</label>
|
||||
<select id="default-model" v-model="defaultModel" class="input">
|
||||
<option value="">Default ({{ defaultChatModel || "qwen3:latest" }})</option>
|
||||
<option v-for="m in installedModels" :key="m" :value="m">{{ m }}</option>
|
||||
</select>
|
||||
<p class="field-hint">
|
||||
Powers the journal conversation (typed or voice-driven) AND small conversational automations: note-title generation, tag suggestions.
|
||||
Pick a small fast model (e.g. <code>qwen3:8b</code>, <code>llama3.2:3b</code>) — speed and responsiveness matter more than depth.
|
||||
Ideally runs on GPU.
|
||||
<br><br>
|
||||
<strong>Tip for snappy chat:</strong> set <code>OLLAMA_NUM_PARALLEL=2</code> (or higher) on your Ollama server so background automations (tags, titles) get their own KV-cache slot and don't evict the chat model's working state. With <code>NUM_PARALLEL=1</code>, every background call pauses the chat and re-warms the prompt on the next user turn.
|
||||
</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="background-model">Curator Model</label>
|
||||
<select id="background-model" v-model="backgroundModel" class="input">
|
||||
<option value="">Default (qwen3:latest)</option>
|
||||
<option v-for="m in installedModels" :key="m" :value="m">{{ m }}</option>
|
||||
</select>
|
||||
<p class="field-hint">
|
||||
Powers the journal curator (capture moments, propose updates) and other heavy async work: daily prep generation, end-of-day closeout, task body consolidation, project summaries, profile observation processing.
|
||||
Pick a smart model — latency doesn't matter, quality does. Often runs on CPU with system RAM (e.g. <code>qwen3:32b</code>, <code>qwen3:30b-a3b</code>, <code>llama3.1:70b</code>).
|
||||
<br><br>
|
||||
<strong>Serialized:</strong> the app enforces one curator pass at a time globally, regardless of <code>OLLAMA_NUM_PARALLEL</code>. Manual triggers fired while the curator is busy return a "try again" response rather than spawning a second instance. This matters most for large CPU models where a second KV-cache slot would waste system RAM.
|
||||
<span v-if="backgroundModel && backgroundModel === (defaultModel || defaultChatModel)" class="field-hint-warn">
|
||||
⚠ Using the same model for both means curator passes compete with chat for the same KV cache. Pick different models so both can stay loaded simultaneously (<code>OLLAMA_MAX_LOADED_MODELS = 2</code>+).
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn-save" @click="saveAssistant" :disabled="saving">
|
||||
{{ saving ? "Saving..." : "Save" }}
|
||||
</button>
|
||||
<span v-if="saved" class="saved-msg">Saved!</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Tasks -->
|
||||
<section class="settings-section full-width">
|
||||
<h2>Tasks</h2>
|
||||
@@ -1608,68 +1554,6 @@ function formatUserDate(iso: string): string {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Model Management -->
|
||||
<section class="settings-section full-width">
|
||||
<div class="model-mgmt-header">
|
||||
<div>
|
||||
<h2>Model Management</h2>
|
||||
<p class="section-desc">Install and remove Ollama models without leaving the app. Search <a href="https://ollama.com/library" target="_blank" rel="noopener">ollama.com/library</a> for available models.</p>
|
||||
</div>
|
||||
<button class="btn-secondary" @click="loadOllamaModels" title="Refresh list">↺ Refresh</button>
|
||||
</div>
|
||||
|
||||
<!-- Installed models -->
|
||||
<div v-if="ollamaModels.length" class="model-list">
|
||||
<div v-for="m in ollamaModels" :key="m.name" class="model-row">
|
||||
<div class="model-row-info">
|
||||
<span class="model-name">{{ m.name }}</span>
|
||||
<span v-if="m.loaded" class="model-badge model-badge--loaded">in VRAM</span>
|
||||
<span v-if="m.name === (defaultModel || defaultChatModel)" class="model-badge model-badge--default">default</span>
|
||||
</div>
|
||||
<div class="model-row-right">
|
||||
<span class="model-size">{{ formatBytes(m.size) }}</span>
|
||||
<button
|
||||
class="model-delete-btn"
|
||||
:disabled="deletingModel === m.name"
|
||||
@click="deleteModel(m.name)"
|
||||
:title="`Remove ${m.name}`"
|
||||
>{{ deletingModel === m.name ? '…' : '✕' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="field-hint">No models installed, or Ollama is unreachable.</p>
|
||||
|
||||
<!-- Pull a model -->
|
||||
<div class="model-pull-form">
|
||||
<input
|
||||
v-model="pullModelName"
|
||||
class="input"
|
||||
placeholder="e.g. qwen3:7b"
|
||||
:disabled="pulling"
|
||||
@keydown.enter="pullModel"
|
||||
/>
|
||||
<button class="btn-secondary" @click="pullModel" :disabled="pulling || !pullModelName.trim()">
|
||||
{{ pulling ? 'Pulling…' : 'Pull' }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="model-suggestions">
|
||||
<span class="suggestions-label">Suggestions:</span>
|
||||
<button v-for="s in ['qwen3:7b','qwen3:14b','qwen3:4b','llama3.1:8b','nomic-embed-text']"
|
||||
:key="s" class="suggestion-chip"
|
||||
:disabled="pulling || ollamaModels.some(m => m.name === s)"
|
||||
@click="pullModelName = s"
|
||||
>{{ s }}</button>
|
||||
</div>
|
||||
|
||||
<!-- Pull progress -->
|
||||
<div v-if="pullProgress" class="model-pull-progress">
|
||||
<div class="pull-status">{{ pullProgress.status }}</div>
|
||||
<div class="pull-bar-track" v-if="pullProgress.pct !== null">
|
||||
<div class="pull-bar-fill" :style="{ width: pullProgress.pct + '%' }"></div>
|
||||
</div>
|
||||
<div v-else class="pull-bar-indeterminate"></div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- ── Account ── -->
|
||||
@@ -1946,109 +1830,6 @@ function formatUserDate(iso: string): string {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="settings-section full-width">
|
||||
<h2>Journal</h2>
|
||||
<p class="section-desc">Controls when the daily journal prep generates and how the day is framed.</p>
|
||||
<div class="field">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" v-model="journalConfig.prep_enabled" />
|
||||
Generate daily prep automatically
|
||||
</label>
|
||||
<p class="field-hint">When enabled, the journal generates a morning briefing at the time below. When off, the journal still works — just without the auto-generated daily prep.</p>
|
||||
</div>
|
||||
<div class="assistant-grid">
|
||||
<div class="field">
|
||||
<label>Prep generates at</label>
|
||||
<div class="time-row">
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
max="23"
|
||||
v-model.number="journalConfig.prep_hour"
|
||||
class="input time-input"
|
||||
:disabled="!journalConfig.prep_enabled"
|
||||
/>
|
||||
<span class="time-sep">:</span>
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
max="59"
|
||||
step="5"
|
||||
v-model.number="journalConfig.prep_minute"
|
||||
class="input time-input"
|
||||
:disabled="!journalConfig.prep_enabled"
|
||||
/>
|
||||
</div>
|
||||
<p class="field-hint">24-hour. Generates each morning at this local time.</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Day rolls over at</label>
|
||||
<div class="time-row">
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
max="23"
|
||||
v-model.number="journalConfig.day_rollover_hour"
|
||||
class="input time-input"
|
||||
/>
|
||||
<span class="time-sep time-sep--quiet">:00</span>
|
||||
</div>
|
||||
<p class="field-hint">Hour when the journal switches to a new day. Default 4am — late-night entries (1–3am) still count as the previous day.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn-save" @click="saveJournalCfg" :disabled="journalConfigSaving">{{ journalConfigSaving ? 'Saving…' : 'Save' }}</button>
|
||||
<span v-if="journalConfigSaved" class="saved-msg">Saved!</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="settings-section full-width">
|
||||
<h2>What the Assistant Has Learned</h2>
|
||||
<p class="section-desc">
|
||||
The assistant observes patterns from your journal and chat conversations and builds a summary over time. The summary is included in the journal's system prompt so the daily prep can reference what it knows about you.
|
||||
<span v-if="profile.observations_count > 0"> {{ profile.observations_count }} raw observation{{ profile.observations_count !== 1 ? 's' : '' }} stored.</span>
|
||||
</p>
|
||||
|
||||
<label class="toggle-row" style="display:flex;align-items:center;gap:0.6rem;margin:0.5rem 0 0.75rem">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="journalConfig.closeout_enabled !== false"
|
||||
@change="onToggleCloseout(($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
<span>
|
||||
<strong>Nightly closeout</strong>
|
||||
<small style="display:block;color:var(--color-text-muted)">Extracts patterns from yesterday's journal at your day-rollover hour.</small>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div v-if="profile.learned_summary" class="learned-summary">{{ profile.learned_summary }}</div>
|
||||
<div v-else class="learned-empty">No learned summary yet. Observations accumulate from journal and chat conversations.</div>
|
||||
|
||||
<div class="observations-panel" style="margin-top:0.75rem">
|
||||
<button class="btn-secondary" @click="toggleObservations" :disabled="profile.observations_count === 0">
|
||||
{{ observationsExpanded ? '▾' : '▸' }} Recent observations ({{ profile.observations_count }})
|
||||
</button>
|
||||
<div v-if="observationsExpanded" class="observations-list" style="margin-top:0.5rem;padding:0.5rem 0.75rem;border:1px solid var(--color-border);border-radius:var(--radius-md);background:var(--color-bg-elev-1)">
|
||||
<div v-if="observationsLoading">Loading…</div>
|
||||
<div v-else-if="observations.length === 0">No observations yet.</div>
|
||||
<div v-else>
|
||||
<div v-for="entry in observations" :key="entry.date" style="margin-bottom:0.75rem">
|
||||
<div style="font-weight:600;font-size:0.875rem;color:var(--color-text-muted)">{{ entry.date }}</div>
|
||||
<div style="white-space:pre-wrap;font-size:0.9rem">{{ entry.bullets }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions" style="gap:0.5rem;flex-wrap:wrap">
|
||||
<button class="btn-secondary" @click="runConsolidate" :disabled="consolidating || profile.observations_count === 0">
|
||||
{{ consolidating ? 'Consolidating…' : 'Consolidate Now' }}
|
||||
</button>
|
||||
<button class="btn-danger-outline" @click="clearObservations" :disabled="clearingObs">
|
||||
{{ clearingObs ? 'Clearing…' : 'Reset Learned Data' }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div v-show="activeTab === 'notifications'" class="settings-grid">
|
||||
@@ -2080,103 +1861,6 @@ function formatUserDate(iso: string): string {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="settings-section">
|
||||
<h2>Push Notifications</h2>
|
||||
<p class="section-desc">
|
||||
Receive browser push notifications when a response is ready. Requires HTTPS.
|
||||
</p>
|
||||
<template v-if="!pushStore.isSupported">
|
||||
<p class="push-unsupported">Push notifications are not supported in this browser or connection (requires HTTPS).</p>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="push-status-row">
|
||||
<span class="push-status-label">Permission:</span>
|
||||
<span
|
||||
:class="['push-permission-badge', {
|
||||
'perm-granted': pushStore.permission === 'granted',
|
||||
'perm-denied': pushStore.permission === 'denied',
|
||||
'perm-default': pushStore.permission === 'default',
|
||||
}]"
|
||||
>
|
||||
{{ pushStore.permission === 'granted' ? 'Granted' : pushStore.permission === 'denied' ? 'Denied' : 'Not asked' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="push-status-row">
|
||||
<span class="push-status-label">Status:</span>
|
||||
<span :class="['push-sub-badge', { 'sub-active': pushStore.isSubscribed }]">
|
||||
{{ pushStore.isSubscribed ? 'Subscribed' : 'Not subscribed' }}
|
||||
</span>
|
||||
</div>
|
||||
<p v-if="pushStore.error" class="push-error">{{ pushStore.error }}</p>
|
||||
<div class="actions" style="margin-top: 0.75rem;">
|
||||
<button
|
||||
v-if="!pushStore.isSubscribed"
|
||||
class="btn-save"
|
||||
@click="pushStore.subscribe()"
|
||||
:disabled="pushStore.loading || pushStore.permission === 'denied'"
|
||||
>
|
||||
{{ pushStore.loading ? 'Enabling...' : 'Enable Notifications' }}
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
class="btn-secondary"
|
||||
@click="pushStore.unsubscribe()"
|
||||
:disabled="pushStore.loading"
|
||||
>
|
||||
{{ pushStore.loading ? 'Disabling...' : 'Disable Notifications' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="pushStore.permission === 'denied'" class="field-hint" style="margin-top: 0.5rem;">
|
||||
Notifications are blocked. Allow them in your browser site settings to re-enable.
|
||||
</p>
|
||||
</template>
|
||||
<template v-if="authStore.isAdmin">
|
||||
<div class="field-divider" style="margin: 1rem 0;" />
|
||||
<p class="section-desc">
|
||||
If push notifications fail due to a corrupted or misformatted VAPID key, regenerate
|
||||
the key pair here. All existing subscriptions will be cleared — you will need to
|
||||
re-enable notifications in this browser afterwards.
|
||||
</p>
|
||||
<div class="actions" style="margin-top: 0.5rem;">
|
||||
<button class="btn-danger" :disabled="vapidResetting" @click="resetVapidKeys">
|
||||
{{ vapidResetting ? 'Regenerating…' : 'Regenerate VAPID Keys' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="vapidResetMsg" :class="vapidResetError ? 'field-error' : 'field-hint'" style="margin-top: 0.5rem;">
|
||||
{{ vapidResetMsg }}
|
||||
</p>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<section class="settings-section">
|
||||
<h2>Chat History</h2>
|
||||
<p class="section-desc">
|
||||
Conversations older than this many days are automatically deleted when you load the chat.
|
||||
Set to <strong>0</strong> to keep conversations forever.
|
||||
</p>
|
||||
<div class="field retention-field">
|
||||
<label class="field-label">Retention period (days)</label>
|
||||
<div class="retention-row">
|
||||
<input
|
||||
v-model.number="chatRetentionDays"
|
||||
type="number"
|
||||
min="0"
|
||||
max="3650"
|
||||
class="input retention-input"
|
||||
/>
|
||||
<button class="btn-primary" :disabled="savingRetention" @click="saveRetention">
|
||||
{{ savingRetention ? 'Saving...' : 'Save' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="settings-section full-width">
|
||||
<h2>About</h2>
|
||||
<p class="version-line">Fabled Scribe <span class="version-badge">{{ appVersion }}</span></p>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- ── Integrations ── -->
|
||||
<div v-show="activeTab === 'integrations'" class="settings-grid">
|
||||
@@ -2307,198 +1991,6 @@ function formatUserDate(iso: string): string {
|
||||
|
||||
</div>
|
||||
|
||||
<div v-show="activeTab === 'voice'" class="settings-grid">
|
||||
|
||||
<section class="settings-section full-width">
|
||||
<h2>Voice</h2>
|
||||
<p class="section-desc">
|
||||
Configure text-to-speech and speech-to-text for voice conversations.
|
||||
Requires <code>VOICE_ENABLED=true</code> on the server.
|
||||
</p>
|
||||
|
||||
<!-- Status indicator -->
|
||||
<div v-if="voiceStatusLoading" class="field-hint">Loading voice status…</div>
|
||||
<div v-else-if="voiceStatus === null" class="field-hint">Voice status unavailable.</div>
|
||||
<div v-else class="voice-status-row">
|
||||
<span :class="['status-badge', voiceStatus.enabled ? 'status-on' : 'status-off']">
|
||||
{{ voiceStatus.enabled ? 'Enabled' : 'Disabled' }}
|
||||
</span>
|
||||
<span v-if="voiceStatus.enabled" class="status-badge" :class="voiceStatus.stt ? 'status-on' : 'status-off'">
|
||||
STT {{ voiceStatus.stt ? 'ready' : 'loading…' }}
|
||||
</span>
|
||||
<span v-if="voiceStatus.enabled" class="status-badge" :class="voiceStatus.tts ? 'status-on' : 'status-off'">
|
||||
TTS {{ voiceStatus.tts ? 'ready' : 'loading…' }}
|
||||
</span>
|
||||
<span v-if="voiceStatus.stt_model" class="field-hint" style="margin-left:0.5rem;">
|
||||
Model: {{ voiceStatus.stt_model }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="!voiceStatus?.enabled" class="field-hint" style="margin-top:0.75rem;">
|
||||
Voice is disabled. An administrator can enable it under
|
||||
<strong>Admin → Config → Voice</strong>.
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="voiceStatus?.enabled" class="settings-section full-width">
|
||||
<h2>Speech Style</h2>
|
||||
<p class="section-desc">Controls how the assistant phrases spoken responses.</p>
|
||||
|
||||
<div class="field-group">
|
||||
<label class="field-label">Style</label>
|
||||
<div class="radio-group">
|
||||
<label v-for="opt in [
|
||||
{ value: 'conversational', label: 'Conversational', hint: 'Warm and natural, like speaking to a friend' },
|
||||
{ value: 'concise', label: 'Concise', hint: 'Short and to the point' },
|
||||
{ value: 'detailed', label: 'Detailed', hint: 'Thorough explanations spoken aloud' },
|
||||
]" :key="opt.value" class="radio-option">
|
||||
<input type="radio" v-model="voiceSpeechStyle" :value="opt.value" />
|
||||
<span>
|
||||
<strong>{{ opt.label }}</strong>
|
||||
<span class="field-hint">{{ opt.hint }}</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="voiceStatus?.enabled" class="settings-section full-width">
|
||||
<h2>Voice & Speed</h2>
|
||||
<p class="section-desc">Choose the TTS voice and playback speed.</p>
|
||||
|
||||
<div class="field-group">
|
||||
<label class="field-label" for="voice-select">Voice</label>
|
||||
<select id="voice-select" class="input" v-model="voiceTtsVoice" :disabled="availableVoices.length === 0">
|
||||
<option v-if="availableVoices.length === 0" value="af_heart">af_heart (default)</option>
|
||||
<option v-for="v in availableVoices" :key="v.id" :value="v.id">{{ v.label }}</option>
|
||||
</select>
|
||||
<p class="field-hint">Voice character and accent. Applies to all voice conversations.</p>
|
||||
</div>
|
||||
|
||||
<div class="field-group">
|
||||
<label class="field-label" for="voice-speed">
|
||||
Speed: {{ voiceTtsSpeed.toFixed(1) }}×
|
||||
</label>
|
||||
<input
|
||||
id="voice-speed"
|
||||
type="range"
|
||||
min="0.7"
|
||||
max="1.3"
|
||||
step="0.05"
|
||||
v-model.number="voiceTtsSpeed"
|
||||
class="range-input"
|
||||
/>
|
||||
<div class="range-labels">
|
||||
<span>0.7× (slow)</span>
|
||||
<span>1.0× (normal)</span>
|
||||
<span>1.3× (fast)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button class="btn-secondary" @click="previewVoice" :disabled="voicePreviewing || !voiceStatus?.tts">
|
||||
{{ voicePreviewing ? 'Generating…' : '▶ Preview' }}
|
||||
</button>
|
||||
<button class="btn-save" @click="saveVoiceSettings" :disabled="savingVoice">
|
||||
{{ voiceSaved ? 'Saved ✓' : savingVoice ? 'Saving…' : 'Save Voice Settings' }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Voice Blend section removed with the kokoro → piper migration
|
||||
(2026-05-22). Piper has no voice-blending equivalent. -->
|
||||
|
||||
<!-- Voice Library (admin only) — browse + install piper voices.
|
||||
Voices land in /data/voices and are immediately available to
|
||||
every user's voice picker. Bundled voices in /opt/piper-voices
|
||||
are read-only and show a "bundled" badge instead of a delete. -->
|
||||
<section v-if="authStore.isAdmin && voiceStatus?.enabled" class="settings-section full-width">
|
||||
<div class="voice-library-header">
|
||||
<h2>Voice Library</h2>
|
||||
<button
|
||||
class="btn-secondary"
|
||||
type="button"
|
||||
@click="voiceLibraryExpanded = !voiceLibraryExpanded; if (voiceLibraryExpanded && voiceLibrary.length === 0) loadVoiceLibrary()"
|
||||
>
|
||||
{{ voiceLibraryExpanded ? 'Hide' : 'Browse voices' }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="section-desc">
|
||||
Download additional piper voices from the
|
||||
<a href="https://huggingface.co/rhasspy/piper-voices" target="_blank" rel="noopener">piper-voices catalog</a>.
|
||||
Installed voices appear in every user's voice picker after a page reload.
|
||||
</p>
|
||||
|
||||
<template v-if="voiceLibraryExpanded">
|
||||
<div class="voice-library-toolbar">
|
||||
<input
|
||||
v-model="voiceLibraryFilter"
|
||||
type="search"
|
||||
class="input"
|
||||
placeholder="Filter by language, country, or name (e.g. 'en', 'fr_FR', 'amy')…"
|
||||
/>
|
||||
<button
|
||||
class="btn-secondary"
|
||||
type="button"
|
||||
:disabled="voiceLibraryLoading"
|
||||
@click="loadVoiceLibrary(true)"
|
||||
title="Re-fetch catalog from HuggingFace"
|
||||
>
|
||||
{{ voiceLibraryLoading ? 'Loading…' : 'Refresh' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="voiceLibraryError" class="field-hint-warn">
|
||||
{{ voiceLibraryError }}
|
||||
</p>
|
||||
|
||||
<div v-if="voiceLibraryLoading && voiceLibrary.length === 0" class="voice-library-empty">
|
||||
Loading catalog…
|
||||
</div>
|
||||
|
||||
<ul v-else-if="filteredVoiceLibrary.length > 0" class="voice-library-list">
|
||||
<li v-for="v in filteredVoiceLibrary" :key="v.id" class="voice-library-row">
|
||||
<div class="voice-library-meta">
|
||||
<div class="voice-library-id">{{ v.id }}</div>
|
||||
<div class="voice-library-sub">
|
||||
{{ v.language_name || v.language_code }}
|
||||
<span v-if="v.country"> · {{ v.country }}</span>
|
||||
· {{ v.quality }}
|
||||
<span v-if="v.num_speakers > 1"> · {{ v.num_speakers }} speakers</span>
|
||||
· {{ formatVoiceSize(v.size_bytes) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="voice-library-actions">
|
||||
<span v-if="v.installed && v.installed_source === 'bundled'" class="voice-badge voice-badge--bundled">
|
||||
bundled
|
||||
</span>
|
||||
<button
|
||||
v-else-if="v.installed && v.installed_source === 'user'"
|
||||
class="btn-danger btn-sm"
|
||||
:disabled="uninstallingVoiceIds.has(v.id)"
|
||||
@click="uninstallLibraryVoice(v.id)"
|
||||
>
|
||||
{{ uninstallingVoiceIds.has(v.id) ? 'Removing…' : 'Remove' }}
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
class="btn-secondary btn-sm"
|
||||
:disabled="installingVoiceIds.has(v.id)"
|
||||
@click="installLibraryVoice(v.id)"
|
||||
>
|
||||
{{ installingVoiceIds.has(v.id) ? 'Installing…' : 'Install' }}
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-else-if="!voiceLibraryLoading" class="voice-library-empty">
|
||||
No voices match the filter.
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- ── MCP Access ── -->
|
||||
<div v-show="activeTab === 'apikeys'" class="settings-grid">
|
||||
|
||||
@@ -1,240 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { apiGet } from "@/api/client";
|
||||
import { useToastStore } from "@/stores/toast";
|
||||
import WorkspaceTaskPanel from "@/components/WorkspaceTaskPanel.vue";
|
||||
import WorkspaceNoteEditor from "@/components/WorkspaceNoteEditor.vue";
|
||||
import WorkspaceChatWidget from "@/components/WorkspaceChatWidget.vue";
|
||||
|
||||
const route = useRoute();
|
||||
const toast = useToastStore();
|
||||
|
||||
const projectId = computed(() => Number(route.params.projectId));
|
||||
|
||||
interface Project {
|
||||
id: number;
|
||||
title: string;
|
||||
goal?: string;
|
||||
}
|
||||
|
||||
const project = ref<Project | null>(null);
|
||||
const taskPanelRef = ref<InstanceType<typeof WorkspaceTaskPanel> | null>(null);
|
||||
const noteEditorRef = ref<InstanceType<typeof WorkspaceNoteEditor> | null>(null);
|
||||
const activeNoteId = ref<number | null>(null);
|
||||
|
||||
// Panel collapse state — persisted per project (tasks + notes only; chat is now a widget)
|
||||
function _panelKey(pid: number) { return `workspace_panels_${pid}`; }
|
||||
|
||||
function _loadPanelState(pid: number) {
|
||||
try {
|
||||
const raw = localStorage.getItem(_panelKey(pid));
|
||||
if (raw) {
|
||||
const saved = JSON.parse(raw) as Partial<{ tasks: boolean; notes: boolean }>;
|
||||
const tasks = saved.tasks ?? true;
|
||||
const notes = saved.notes ?? true;
|
||||
// Guard: at least one panel must be open
|
||||
if (!tasks && !notes) return { tasks: true, notes: true };
|
||||
return { tasks, notes };
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
return { tasks: true, notes: true };
|
||||
}
|
||||
|
||||
const panelOpen = ref<{ tasks: boolean; notes: boolean }>({ tasks: true, notes: true });
|
||||
|
||||
const gridColumns = computed(() => {
|
||||
return [
|
||||
panelOpen.value.tasks ? "minmax(0, 0.85fr)" : "0px",
|
||||
panelOpen.value.notes ? "minmax(0, 2.15fr)" : "0px",
|
||||
].join(" ");
|
||||
});
|
||||
|
||||
function togglePanel(panel: keyof typeof panelOpen.value) {
|
||||
const open = panelOpen.value;
|
||||
const openCount = [open.tasks, open.notes].filter(Boolean).length;
|
||||
if (open[panel] && openCount <= 1) return;
|
||||
panelOpen.value[panel] = !panelOpen.value[panel];
|
||||
localStorage.setItem(_panelKey(projectId.value), JSON.stringify(panelOpen.value));
|
||||
}
|
||||
|
||||
function onNoteChanged(noteId: number) {
|
||||
activeNoteId.value = noteId;
|
||||
noteEditorRef.value?.reload();
|
||||
}
|
||||
|
||||
function onTaskChanged() {
|
||||
taskPanelRef.value?.reload();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
panelOpen.value = _loadPanelState(projectId.value);
|
||||
|
||||
try {
|
||||
project.value = await apiGet<Project>(`/api/projects/${projectId.value}`);
|
||||
} catch {
|
||||
toast.show("Failed to load project", "error");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="workspace-root">
|
||||
<!-- Header -->
|
||||
<header class="ws-header">
|
||||
<router-link :to="project ? `/projects/${project.id}` : '/projects'" class="ws-back">
|
||||
← {{ project?.title ?? "Project" }}
|
||||
</router-link>
|
||||
<span class="ws-title">{{ project?.goal ?? '' }}</span>
|
||||
<div class="ws-panel-toggles">
|
||||
<button
|
||||
:class="['panel-toggle', { active: panelOpen.tasks }]"
|
||||
title="Toggle Tasks panel"
|
||||
@click="togglePanel('tasks')"
|
||||
>
|
||||
Tasks
|
||||
</button>
|
||||
<button
|
||||
:class="['panel-toggle', { active: panelOpen.notes }]"
|
||||
title="Toggle Notes panel"
|
||||
@click="togglePanel('notes')"
|
||||
>
|
||||
Notes
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Two-panel body -->
|
||||
<div class="ws-body" :style="{ gridTemplateColumns: gridColumns }">
|
||||
<!-- Left: Tasks -->
|
||||
<div v-show="panelOpen.tasks" class="ws-panel">
|
||||
<Transition name="panel-fade">
|
||||
<div v-if="panelOpen.tasks" class="panel-inner">
|
||||
<WorkspaceTaskPanel
|
||||
v-if="project"
|
||||
ref="taskPanelRef"
|
||||
:project-id="project.id"
|
||||
/>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
|
||||
<!-- Right: Note Editor -->
|
||||
<div v-show="panelOpen.notes" class="ws-panel ws-panel-notes">
|
||||
<Transition name="panel-fade">
|
||||
<div v-if="panelOpen.notes" class="panel-inner">
|
||||
<WorkspaceNoteEditor
|
||||
v-if="project"
|
||||
ref="noteEditorRef"
|
||||
:project-id="project.id"
|
||||
:active-note-id="activeNoteId"
|
||||
/>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Floating chat widget -->
|
||||
<WorkspaceChatWidget
|
||||
v-if="project"
|
||||
:project-id="projectId"
|
||||
@note-changed="onNoteChanged"
|
||||
@task-changed="onTaskChanged"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.workspace-root {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
.ws-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
height: 44px;
|
||||
padding: 0 1rem;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
background: var(--color-surface);
|
||||
flex-shrink: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.ws-back {
|
||||
color: var(--color-primary);
|
||||
text-decoration: none;
|
||||
font-size: 0.875rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ws-back:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.ws-title {
|
||||
font-size: 0.78rem;
|
||||
color: var(--color-text-muted);
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ws-panel-toggles {
|
||||
display: flex;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
|
||||
.panel-toggle {
|
||||
background: none;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 5px;
|
||||
padding: 0.2rem 0.6rem;
|
||||
font-size: 0.78rem;
|
||||
cursor: pointer;
|
||||
color: var(--color-text-muted);
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.panel-toggle.active {
|
||||
background: color-mix(in srgb, var(--color-primary) 12%, transparent);
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.ws-body {
|
||||
display: grid;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
transition: grid-template-columns 0.2s ease;
|
||||
}
|
||||
|
||||
.ws-panel {
|
||||
overflow: hidden;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ws-panel-notes {
|
||||
border-left: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.panel-inner {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.panel-fade-enter-active,
|
||||
.panel-fade-leave-active {
|
||||
transition: opacity 0.18s ease;
|
||||
}
|
||||
.panel-fade-enter-from,
|
||||
.panel-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user