slash command altnames and support for ?
This commit is contained in:
parent
bb52149a06
commit
2cd976987e
|
@ -11,6 +11,7 @@ import { getCommandFromQuery } from '../utils/commandUtils.js';
|
||||||
|
|
||||||
export interface SlashCommand {
|
export interface SlashCommand {
|
||||||
name: string; // slash command
|
name: string; // slash command
|
||||||
|
altName?: string; // alternative name for the command
|
||||||
description: string; // flavor text in UI
|
description: string; // flavor text in UI
|
||||||
action: (value: PartListUnion) => void;
|
action: (value: PartListUnion) => void;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +38,7 @@ export const useSlashCommandProcessor = (
|
||||||
const slashCommands: SlashCommand[] = [
|
const slashCommands: SlashCommand[] = [
|
||||||
{
|
{
|
||||||
name: 'help',
|
name: 'help',
|
||||||
|
altName: '?',
|
||||||
description: 'for help on gemini-code',
|
description: 'for help on gemini-code',
|
||||||
action: (_value: PartListUnion) => {
|
action: (_value: PartListUnion) => {
|
||||||
setDebugMessage('Opening help.');
|
setDebugMessage('Opening help.');
|
||||||
|
@ -61,31 +63,12 @@ export const useSlashCommandProcessor = (
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'exit',
|
|
||||||
description: '',
|
|
||||||
action: (_value: PartListUnion) => {
|
|
||||||
setDebugMessage('Exiting. Good-bye.');
|
|
||||||
const timestamp = getNextMessageId(Date.now());
|
|
||||||
addHistoryItem(
|
|
||||||
setHistory,
|
|
||||||
{ type: 'info', text: 'good-bye!' },
|
|
||||||
timestamp,
|
|
||||||
);
|
|
||||||
process.exit(0);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// TODO: dedup with exit by adding altName or cmdRegex.
|
|
||||||
name: 'quit',
|
name: 'quit',
|
||||||
|
altName: 'exit',
|
||||||
description: '',
|
description: '',
|
||||||
action: (_value: PartListUnion) => {
|
action: (_value: PartListUnion) => {
|
||||||
setDebugMessage('Quitting. Good-bye.');
|
setDebugMessage('Quitting. Good-bye.');
|
||||||
const timestamp = getNextMessageId(Date.now());
|
const timestamp = getNextMessageId(Date.now());
|
||||||
addHistoryItem(
|
|
||||||
setHistory,
|
|
||||||
{ type: 'info', text: 'good-bye!' },
|
|
||||||
timestamp,
|
|
||||||
);
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -102,12 +85,16 @@ export const useSlashCommandProcessor = (
|
||||||
const [symbol, test] = getCommandFromQuery(trimmed);
|
const [symbol, test] = getCommandFromQuery(trimmed);
|
||||||
|
|
||||||
// Skip non slash commands
|
// Skip non slash commands
|
||||||
if (symbol !== '/') {
|
if (symbol !== '/' && symbol !== '?') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const cmd of slashCommands) {
|
for (const cmd of slashCommands) {
|
||||||
if (test === cmd.name) {
|
if (
|
||||||
|
test === cmd.name ||
|
||||||
|
test === cmd.altName ||
|
||||||
|
symbol === cmd.altName
|
||||||
|
) {
|
||||||
// Add user message *before* execution
|
// Add user message *before* execution
|
||||||
const userMessageTimestamp = Date.now();
|
const userMessageTimestamp = Date.now();
|
||||||
addHistoryItem(
|
addHistoryItem(
|
||||||
|
|
|
@ -119,9 +119,18 @@ export function useCompletion(
|
||||||
// --- Handle Slash Command Completion ---
|
// --- Handle Slash Command Completion ---
|
||||||
if (trimmedQuery.startsWith('/')) {
|
if (trimmedQuery.startsWith('/')) {
|
||||||
const partialCommand = trimmedQuery.substring(1);
|
const partialCommand = trimmedQuery.substring(1);
|
||||||
const filteredSuggestions = slashCommands
|
const commands = slashCommands
|
||||||
.map((cmd) => cmd.name)
|
.map((cmd) => cmd.name)
|
||||||
|
.concat(
|
||||||
|
slashCommands
|
||||||
|
.map((cmd) => cmd.altName)
|
||||||
|
.filter((cmd) => cmd !== undefined),
|
||||||
|
);
|
||||||
|
|
||||||
|
const filteredSuggestions = commands
|
||||||
.filter((name) => name.startsWith(partialCommand))
|
.filter((name) => name.startsWith(partialCommand))
|
||||||
|
// Filter out ? and any other single character commands
|
||||||
|
.filter((name) => name.length > 1)
|
||||||
.map((name) => ({ label: name, value: name }))
|
.map((name) => ({ label: name, value: name }))
|
||||||
.sort();
|
.sort();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue