feat: add custom slash commands support (#384)
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Box, Text, useInput } from "ink";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { getVersion } from "../../version";
|
||||
import { commands } from "../commands/registry";
|
||||
import { colors } from "./colors";
|
||||
@@ -28,18 +28,34 @@ export function HelpDialog({ onClose }: HelpDialogProps) {
|
||||
const [activeTab, setActiveTab] = useState<HelpTab>("commands");
|
||||
const [currentPage, setCurrentPage] = useState(0);
|
||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||
const [customCommands, setCustomCommands] = useState<CommandItem[]>([]);
|
||||
|
||||
// Get all non-hidden commands, sorted by order
|
||||
// Load custom commands once on mount
|
||||
useEffect(() => {
|
||||
import("../commands/custom.js").then(({ getCustomCommands }) => {
|
||||
getCustomCommands().then((customs) => {
|
||||
setCustomCommands(
|
||||
customs.map((cmd) => ({
|
||||
name: `/${cmd.id}`,
|
||||
description: `${cmd.description} (${cmd.source}${cmd.namespace ? `:${cmd.namespace}` : ""})`,
|
||||
order: 200 + (cmd.source === "project" ? 0 : 100),
|
||||
})),
|
||||
);
|
||||
});
|
||||
});
|
||||
}, []);
|
||||
|
||||
// Get all non-hidden commands, sorted by order (includes custom commands)
|
||||
const allCommands = useMemo<CommandItem[]>(() => {
|
||||
return Object.entries(commands)
|
||||
const builtins = Object.entries(commands)
|
||||
.filter(([_, cmd]) => !cmd.hidden)
|
||||
.map(([name, cmd]) => ({
|
||||
name,
|
||||
description: cmd.desc,
|
||||
order: cmd.order ?? 100,
|
||||
}))
|
||||
.sort((a, b) => a.order - b.order);
|
||||
}, []);
|
||||
}));
|
||||
return [...builtins, ...customCommands].sort((a, b) => a.order - b.order);
|
||||
}, [customCommands]);
|
||||
|
||||
// Keyboard shortcuts
|
||||
const shortcuts = useMemo<ShortcutItem[]>(() => {
|
||||
|
||||
Reference in New Issue
Block a user