diff --git a/server/index.ts b/server/index.ts index fb4b4c0..f53048d 100644 --- a/server/index.ts +++ b/server/index.ts @@ -104,7 +104,7 @@ app.delete('/api/models/:id', (c) => { // ── AI types ────────────────────────────────────────────────────────────────── type AIStreamRequest = { - type: 'continue' | 'polish' | 'summarize' | 'chat' + type: 'continue' | 'polish' | 'summarize' | 'translate' | 'chat' noteContent: string selection?: string messages?: { role: 'user' | 'assistant'; content: string }[] @@ -131,6 +131,10 @@ function buildMessages(req: AIStreamRequest): Anthropic.MessageParam[] { return [{ role: 'user', content: `请润色以下文字,改善语法、流畅度和表达,保持原意,直接输出润色后的结果,不要有任何解释:\n\n${selection ?? noteContent}` }] } + if (type === 'translate') { + return [{ role: 'user', content: `请将以下文字翻译成英文,保持原文风格和格式,直接输出翻译结果,不要有任何解释:\n\n${selection ?? noteContent}` }] + } + return [{ role: 'user', content: `请为以下内容提炼要点摘要,用简洁的中文输出,不超过 150 字:\n\n${selection ?? noteContent}` }] } diff --git a/src/App.tsx b/src/App.tsx index 927e259..f0e98a6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,7 @@ import { useAppStore } from './stores/appStore' import { seedIfEmpty, deduplicateDB } from './db' export default function App() { - const { loadAll, theme, focusMode, aiPanelOpen } = useAppStore() + const { loadAll, theme, focusMode, aiPanelOpen, toggleFocusMode, toggleAiPanel, createNote, activeFolderId } = useAppStore() useEffect(() => { document.documentElement.setAttribute('data-theme', theme) @@ -18,13 +18,24 @@ export default function App() { .then(() => loadAll()) }, []) + useEffect(() => { + const handler = (e: KeyboardEvent) => { + const mod = e.metaKey || e.ctrlKey + if (mod && e.key === '\\') { e.preventDefault(); toggleFocusMode() } + if (mod && e.shiftKey && e.key === 'J') { e.preventDefault(); toggleAiPanel() } + if (mod && e.key === 'n') { e.preventDefault(); createNote(activeFolderId as string | null) } + } + window.addEventListener('keydown', handler) + return () => window.removeEventListener('keydown', handler) + }, [toggleFocusMode, toggleAiPanel, createNote, activeFolderId]) + return (