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) <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-03-16 00:47:37 -04:00
parent 8b712b2046
commit 1201acfa37

View File

@@ -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'
}