import { useChatSessions } from '@/state/useChatSessions'; export type SlashCommandResult = { handled: true; feedback: string } | { handled: false }; type UseSlashCommandsParams = { sessionId: string | null; }; export const useSlashCommands = ({ sessionId }: UseSlashCommandsParams) => { const { renameSession } = useChatSessions(); const execute = async (input: string): Promise => { const trimmed = input.trim(); if (!trimmed.startsWith('/')) return { handled: false }; const spaceIndex = trimmed.indexOf(' '); const command = spaceIndex === -1 ? trimmed.slice(1) : trimmed.slice(1, spaceIndex); const args = spaceIndex === -1 ? '' : trimmed.slice(spaceIndex + 1).trim(); switch (command) { case 'rename': if (!sessionId || !args) return { handled: false }; await renameSession(sessionId, args); return { handled: true, feedback: `Session renamed to "${args}"` }; default: return { handled: false }; } }; return { execute }; };