From 1201acfa3732fa87c2b3c4642eff6700aacbe5a6 Mon Sep 17 00:00:00 2001 From: chihlasm Date: Mon, 16 Mar 2026 00:47:37 -0400 Subject: [PATCH] feat: add paletteIntent utility for command palette query classification Detects query intent ('question' | 'keyword' | 'page' | 'empty') to drive smart result ordering in the enhanced command palette. Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/lib/paletteIntent.ts | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 frontend/src/lib/paletteIntent.ts diff --git a/frontend/src/lib/paletteIntent.ts b/frontend/src/lib/paletteIntent.ts new file mode 100644 index 00000000..9b1f9df1 --- /dev/null +++ b/frontend/src/lib/paletteIntent.ts @@ -0,0 +1,59 @@ +/** + * Detects the intent behind a command palette query. + * Returns one of: 'question' | 'keyword' | 'page' | 'empty' + */ + +const QUESTION_WORDS = [ + 'how', 'why', 'what', 'when', 'where', 'who', 'which', + 'fix', 'help', 'troubleshoot', 'resolve', 'debug', 'diagnose', +] + +const PAGE_NAMES = [ + 'dashboard', 'home', + 'flows', 'trees', 'all flows', + 'sessions', 'history', + 'analytics', 'reports', + 'settings', 'account', 'profile', + 'admin', 'administration', 'users', + 'assistant', 'ai', 'copilot', 'flowpilot', + 'scripts', 'script generator', + 'kb', 'knowledge base', 'kb accelerator', + 'library', 'step library', +] + +export type PaletteIntent = 'question' | 'keyword' | 'page' | 'empty' + +export function detectIntent(query: string): PaletteIntent { + const trimmed = query.trim() + + if (!trimmed) { + return 'empty' + } + + const lower = trimmed.toLowerCase() + + // Check if it matches a known page name + if (PAGE_NAMES.some(p => lower === p || lower.startsWith(p + ' ') || lower.endsWith(' ' + p))) { + return 'page' + } + + // Check for question indicators: + // - Contains a question mark + if (lower.includes('?')) { + return 'question' + } + + // - Starts with a question word + const firstWord = lower.split(/\s+/)[0] + if (QUESTION_WORDS.includes(firstWord)) { + return 'question' + } + + // - 5 or more words + const wordCount = trimmed.split(/\s+/).length + if (wordCount >= 5) { + return 'question' + } + + return 'keyword' +}