import { useEffect, useMemo, useState } from "react"; import { Command, Search, TerminalSquare } from "lucide-react"; type PiCommand = { name: string; description: string; argumentHint?: string; }; export function CommandsPage() { const [commands, setCommands] = useState([]); const [query, setQuery] = useState(""); const [loading, setLoading] = useState(true); const [error, setError] = useState(false); useEffect(() => { fetch("/api/pi/commands") .then((res) => { if (!res.ok) throw new Error("Unable to load commands"); return res.json() as Promise<{ commands?: PiCommand[] }>; }) .then((data) => setCommands(data.commands ?? [])) .catch(() => setError(true)) .finally(() => setLoading(false)); }, []); const visibleCommands = useMemo(() => { const keyword = query.trim().toLocaleLowerCase(); if (!keyword) return commands; return commands.filter((command) => `${command.name} ${command.argumentHint ?? ""} ${command.description}`.toLocaleLowerCase().includes(keyword)); }, [commands, query]); return (

BUILT-IN COMMANDS

Pi 内置命令

当前安装版本提供 {commands.length} 个交互命令,在 Pi 输入框中以斜杠调用。

{loading ?

正在读取 Pi 命令注册表…

: error ?

无法读取 Pi 内置命令。

: visibleCommands.length === 0 ?

没有匹配的命令。

: (
{visibleCommands.map((command) =>

{command.name}

{command.argumentHint && {command.argumentHint}}Pi 内置

{command.description}

)}
)}
); }