返回 ViMax
slashCommands.ts
根目录 / web / src / slashCommands.ts
1 export type SlashCommand = {
2 name: string;
3 description: string;
4 };
5
6 export type SlashCommandMatch = SlashCommand & {
7 matchedPrefix: string;
8 unmatchedSuffix: string;
9 };
10
11 export const SLASH_COMMANDS: SlashCommand[] = [
12 {name: '/compact', description: 'Compact the current session context'},
13 ];
14
15 export function matchingSlashCommands(input: string): SlashCommandMatch[] {
16 if (!input.startsWith('/')) return [];
17 const query = input.trimStart().split(/\s+/, 1)[0] ?? '';
18 return SLASH_COMMANDS
19 .filter((command) => command.name.toLowerCase().startsWith(query.toLowerCase()))
20 .map((command) => ({
21 ...command,
22 matchedPrefix: command.name.slice(0, query.length),
23 unmatchedSuffix: command.name.slice(query.length),
24 }));
25 }
26
27 export function shouldShowSlashCommands(input: string, busy: boolean) {
28 return !busy && input.startsWith('/');
29 }
30
30 lines TYPESCRIPT