thinking.ts
1 import type { ProviderThinkingLevel } from '@/server/providers/types' 2 import type { SlashCommand } from './ast' 3 import type { ParsedSlashInput } from './lexer' 4 5 export function parseThinkingSlashCommand(input: ParsedSlashInput): SlashCommand | null { 6 if (input.name !== 'think' && input.name !== 'thinking') return null 7 8 const normalized = input.rest.toLowerCase() 9 if (!input.rest || normalized === 'show' || normalized === 'current') { 10 return { kind: 'think-show' } 11 } 12 if (normalized === 'clear' || normalized === 'reset' || normalized === 'default') { 13 return { kind: 'think-set', thinkingLevel: null } 14 } 15 const thinkingLevel = parseThinkingLevel(input.rest) 16 return thinkingLevel ? { kind: 'think-set', thinkingLevel } : { kind: 'think-show' } 17 } 18 19 export function parseThinkingLevel(value: string): ProviderThinkingLevel | null { 20 const normalized = value.trim().toLowerCase() 21 if (!normalized) return null 22 if ( 23 normalized === 'off' || 24 normalized === 'minimal' || 25 normalized === 'low' || 26 normalized === 'medium' || 27 normalized === 'high' 28 ) { 29 return normalized 30 } 31 return null 32 }