| 732 | } |
| 733 | |
| 734 | func WaveAIGetChatHandler(w http.ResponseWriter, r *http.Request) { |
| 735 | // Only allow GET method |
| 736 | if r.Method != http.MethodGet { |
| 737 | http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) |
| 738 | return |
| 739 | } |
| 740 | |
| 741 | // Get chatid from URL parameters |
| 742 | chatID := r.URL.Query().Get("chatid") |
| 743 | if chatID == "" { |
| 744 | http.Error(w, "chatid parameter is required", http.StatusBadRequest) |
| 745 | return |
| 746 | } |
| 747 | |
| 748 | // Validate chatid is a UUID |
| 749 | if _, err := uuid.Parse(chatID); err != nil { |
| 750 | http.Error(w, "chatid must be a valid UUID", http.StatusBadRequest) |
| 751 | return |
| 752 | } |
| 753 | |
| 754 | // Get chat from store |
| 755 | chat := chatstore.DefaultChatStore.Get(chatID) |
| 756 | if chat == nil { |
| 757 | http.Error(w, "chat not found", http.StatusNotFound) |
| 758 | return |
| 759 | } |
| 760 | |
| 761 | // Set response headers for JSON |
| 762 | w.Header().Set("Content-Type", "application/json") |
| 763 | |
| 764 | // Encode and return the chat |
| 765 | if err := json.NewEncoder(w).Encode(chat); err != nil { |
| 766 | http.Error(w, fmt.Sprintf("Failed to encode response: %v", err), http.StatusInternalServerError) |
| 767 | return |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | // CreateWriteTextFileDiff generates a diff for write_text_file or edit_text_file tool calls. |
| 772 | // Returns the original content, modified content, and any error. |