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:
59
frontend/src/lib/paletteIntent.ts
Normal file
59
frontend/src/lib/paletteIntent.ts
Normal 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'
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user