(messageText: string)
| 223 | |
| 224 | // Send a chat message |
| 225 | async sendMessage(messageText: string) { |
| 226 | console.log( |
| 227 | `\n📨 [${this.currentUsername}] sendMessage called: "${messageText}"`, |
| 228 | ) |
| 229 | |
| 230 | if (!this.currentUsername) { |
| 231 | throw new Error('You must join the chat first') |
| 232 | } |
| 233 | |
| 234 | if (!messageText.trim()) { |
| 235 | throw new Error('Message cannot be empty') |
| 236 | } |
| 237 | |
| 238 | // Check for Claude trigger pattern - matches @Claude anywhere in message or Claude at start |
| 239 | const trimmedMessage = messageText.trim() |
| 240 | const isClaudeMention = |
| 241 | /@Claude/i.test(messageText) || // @Claude anywhere in message |
| 242 | /^Claude/i.test(trimmedMessage) || // Claude at start |
| 243 | /^@Claude/i.test(trimmedMessage) // @Claude at start |
| 244 | console.log( |
| 245 | `📨 [${this.currentUsername}] Checking for Claude mention in: "${messageText.substring(0, 50)}..."`, |
| 246 | ) |
| 247 | console.log( |
| 248 | `📨 [${this.currentUsername}] isClaudeMention: ${ |
| 249 | isClaudeMention ? 'YES' : 'NO' |
| 250 | }`, |
| 251 | ) |
| 252 | |
| 253 | if (isClaudeMention) { |
| 254 | console.log( |
| 255 | `📨 [${this.currentUsername}] Claude mention detected, sending user message first`, |
| 256 | ) |
| 257 | |
| 258 | // First, send the user's message to chat |
| 259 | const message = await globalChat.sendMessage( |
| 260 | this.currentUsername, |
| 261 | messageText.trim(), |
| 262 | ) |
| 263 | console.log( |
| 264 | `📨 [${this.currentUsername}] User message sent, ID: ${message.id}`, |
| 265 | ) |
| 266 | |
| 267 | // Build conversation history for Claude |
| 268 | const conversationHistory: Array<ModelMessage> = globalChat |
| 269 | .getMessages() |
| 270 | .map((msg) => ({ |
| 271 | role: 'user' as const, |
| 272 | content: `${msg.username}: ${msg.message}`, |
| 273 | })) |
| 274 | console.log( |
| 275 | `📨 [${this.currentUsername}] Built history with ${conversationHistory.length} messages`, |
| 276 | ) |
| 277 | |
| 278 | // Enqueue Claude request |
| 279 | const claudeService = await getClaudeService() |
| 280 | claudeService.enqueue({ |
| 281 | id: Math.random().toString(36).substr(2, 9), |
| 282 | username: this.currentUsername, |
nothing calls this directly
no test coverage detected