(userInput string)
| 374 | } |
| 375 | |
| 376 | func ParseAttachCommand(userInput string) (messageText, attachPath string) { |
| 377 | lines := strings.Split(userInput, "\n") |
| 378 | var messageLines []string |
| 379 | |
| 380 | for _, line := range lines { |
| 381 | // Look for /attach anywhere in the line |
| 382 | attachIndex := strings.Index(line, "/attach ") |
| 383 | if attachIndex != -1 { |
| 384 | // Extract the part before /attach |
| 385 | beforeAttach := line[:attachIndex] |
| 386 | |
| 387 | // Extract the part after /attach (starting after "/attach ") |
| 388 | afterAttachStart := attachIndex + 8 // Length of "/attach " |
| 389 | if afterAttachStart < len(line) { |
| 390 | afterAttach := line[afterAttachStart:] |
| 391 | |
| 392 | // Split on spaces to get the file path (first token) and any remaining text |
| 393 | tokens := strings.Fields(afterAttach) |
| 394 | if len(tokens) > 0 { |
| 395 | attachPath = tokens[0] |
| 396 | |
| 397 | // Reconstruct the line with /attach and file path removed |
| 398 | var remainingText string |
| 399 | if len(tokens) > 1 { |
| 400 | remainingText = strings.Join(tokens[1:], " ") |
| 401 | } |
| 402 | |
| 403 | // Combine the text before /attach and any text after the file path |
| 404 | var parts []string |
| 405 | if strings.TrimSpace(beforeAttach) != "" { |
| 406 | parts = append(parts, strings.TrimSpace(beforeAttach)) |
| 407 | } |
| 408 | if remainingText != "" { |
| 409 | parts = append(parts, remainingText) |
| 410 | } |
| 411 | reconstructedLine := strings.Join(parts, " ") |
| 412 | if reconstructedLine != "" { |
| 413 | messageLines = append(messageLines, reconstructedLine) |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } else { |
| 418 | // Keep lines without /attach commands |
| 419 | messageLines = append(messageLines, line) |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | // Join the message lines back together |
| 424 | messageText = strings.TrimSpace(strings.Join(messageLines, "\n")) |
| 425 | return messageText, attachPath |
| 426 | } |
| 427 | |
| 428 | // CreateUserMessageWithAttachment creates a user message with optional file attachment. |
| 429 | // All attachment processing (MIME detection, image resize, text inlining) is delegated |
no outgoing calls
no test coverage detected