/ src / server / chat / slash-command-parser / reasoning.ts
reasoning.ts
 1  import type { ProviderReasoningLevel } from '@/server/providers/types'
 2  import type { SlashCommand } from './ast'
 3  import type { ParsedSlashInput } from './lexer'
 4  
 5  export function parseReasoningSlashCommand(input: ParsedSlashInput): SlashCommand | null {
 6    if (input.name !== 'reasoning') return null
 7  
 8    const normalized = input.rest.toLowerCase()
 9    if (!input.rest || normalized === 'show' || normalized === 'current') {
10      return { kind: 'reasoning-show' }
11    }
12    if (normalized === 'clear' || normalized === 'reset' || normalized === 'default') {
13      return { kind: 'reasoning-set', reasoningLevel: null }
14    }
15    const reasoningLevel = parseReasoningLevel(input.rest)
16    return reasoningLevel
17      ? { kind: 'reasoning-set', reasoningLevel }
18      : { kind: 'reasoning-show' }
19  }
20  
21  export function parseReasoningLevel(value: string): ProviderReasoningLevel | null {
22    const normalized = value.trim().toLowerCase()
23    if (!normalized) return null
24    if (normalized === 'off' || normalized === 'on' || normalized === 'stream') {
25      return normalized
26    }
27    return null
28  }