(text: string)
| 48 | } |
| 49 | |
| 50 | export function parseCommand(text: string): { command: string; args: string[] } { |
| 51 | // Match quoted strings or non-whitespace sequences |
| 52 | const matches = text.match(/"[^"]+"|'[^']+'|\S+/g) || []; |
| 53 | |
| 54 | if (matches.length === 0 || !matches[0]) { |
| 55 | return { command: '', args: [] }; |
| 56 | } |
| 57 | |
| 58 | const command = matches[0].substring(1); // Remove leading '/' |
| 59 | const args = matches.slice(1).map(arg => { |
| 60 | // Remove surrounding quotes if present |
| 61 | if ((arg.startsWith('"') && arg.endsWith('"')) || (arg.startsWith("'") && arg.endsWith("'"))) { |
| 62 | return arg.slice(1, -1); |
| 63 | } |
| 64 | return arg; |
| 65 | }); |
| 66 | |
| 67 | return { command, args }; |
| 68 | } |
| 69 | |
| 70 | export async function handleCommand( |
| 71 | conversation: Conversation, |
no outgoing calls
no test coverage detected