model.ts
 1  import type { SlashCommand } from './ast'
 2  import type { ParsedSlashInput } from './lexer'
 3  
 4  export function parseModelSlashCommand(input: ParsedSlashInput): SlashCommand | null {
 5    if (input.name === 'models') return { kind: 'model-list' }
 6    if (input.name !== 'model') return null
 7  
 8    const normalized = input.rest.toLowerCase()
 9    if (!input.rest || normalized === 'list') return { kind: 'model-list' }
10    if (normalized === 'current' || normalized === 'show') {
11      return { kind: 'model-current' }
12    }
13    if (normalized === 'clear' || normalized === 'default' || normalized === 'reset') {
14      return { kind: 'model-clear' }
15    }
16    if (normalized.startsWith('chat:')) {
17      return {
18        kind: 'model-set',
19        model: input.rest.slice(input.rest.indexOf(':') + 1).trim(),
20      }
21    }
22    if (normalized.startsWith('set ')) {
23      return { kind: 'model-set', model: input.rest.slice(4).trim() }
24    }
25    return { kind: 'model-set', model: input.rest }
26  }