Repository: miladyboy/wingman
Pull request #23: Switch to private image storage
Author: login: miladyboy
Labels: name: codex
Created: 2025-05-31T21:21:08Z | Merged: 2025-05-31T22:01:41Z

## Summary
- upload chat images after analysis to Supabase private bucket
- compress & send images to OpenAI directly via base64
- fetch signed URLs for images when loading messages
- update unit tests for new workflow

## Testing
- `npm test --prefix backend`
- `npm test --prefix frontend`


------
https://chatgpt.com/codex/tasks/task_e_683b6c039144832e9d3480e6c7eac562

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **New Features**
	- Images are now compressed and converted to base64 before being analyzed by AI, improving privacy and efficiency.
- **Bug Fixes**
	- Image URLs for chat messages are now generated as temporary signed URLs, enhancing security and access control.
- **Tests**
	- Updated tests to use base64-encoded images and removed reliance on public URLs and certain storage mocks.
- **Refactor**
	- Changed the image upload process to separate AI analysis from storage upload, and removed the "public/" prefix from storage paths.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->


Diff:
diff --git a/backend/controllers/__tests__/generateImageDescription.test.ts b/backend/controllers/__tests__/generateImageDescription.test.ts
index 95aaca4..8e61adc 100644
--- a/backend/controllers/__tests__/generateImageDescription.test.ts
+++ b/backend/controllers/__tests__/generateImageDescription.test.ts
@@ -36,7 +36,7 @@ describe("generateImageDescription", () => {
   });
 
   const sampleFinalUserMessageContent = [
-    { type: "input_image", image_url: "http://example.com/image1.jpg" },
+    { type: "input_image", image_url: "data:image/jpeg;base64,AAA" },
     { type: "input_text", text: "Image for description." },
   ];
 
@@ -59,7 +59,7 @@ describe("generateImageDescription", () => {
         role: "user",
         content: [
           { type: "input_text", text: getImageDescriptionPrompt().content },
-          { type: "input_image", image_url: "http://example.com/image1.jpg" },
+          { type: "input_image", image_url: "data:image/jpeg;base64,AAA" },
           { type: "input_text", text: "Image for description." },
         ],
       },
diff --git a/backend/controllers/__tests__/generateImageDescriptionAndNickname.test.ts b/backend/controllers/__tests__/generateImageDescriptionAndNickname.test.ts
index aa58465..1d0b585 100644
--- a/backend/controllers/__tests__/generateImageDescriptionAndNickname.test.ts
+++ b/backend/controllers/__tests__/generateImageDescriptionAndNickname.test.ts
@@ -33,7 +33,10 @@ describe("generateImageDescriptionAndNickname", () => {
   });
 
   const sampleFinalUserMessageContent = [
-    { type: "input_image", image_url: "http://example.com/image1.jpg" },
+    {
+      type: "input_image",
+      image_url: "data:image/jpeg;base64,AAA",
+    },
     { type: "input_text", text: "Look at this!" },
   ];
 
@@ -56,7 +59,7 @@ describe("generateImageDescriptionAndNickname", () => {
             type: "input_text",
             text: getImageDescriptionAndNicknamePrompt().content,
           },
-          { type: "input_image", image_url: "http://example.com/image1.jpg" },
+          { type: "input_image", image_url: "data:image/jpeg;base64,AAA" },
           { type: "input_text", text: "Look at this!" },
         ],
       },
diff --git a/backend/controllers/__tests__/uploadFilesToStorage.test.ts b/backend/controllers/__tests__/uploadFilesToStorage.test.ts
index 344208d..079413b 100644
--- a/backend/controllers/__tests__/uploadFilesToStorage.test.ts
+++ b/backend/controllers/__tests__/uploadFilesToStorage.test.ts
@@ -93,29 +93,19 @@ describe("uploadFilesToStorage", () => {
   it("should upload files, compress images, and return correct records and URLs", async () => {
     mockUploadFn
       .mockResolvedValueOnce({
-        data: { path: "public/user-abc/message-123/testImage-test-uuid.jpg" },
+        data: { path: "user-abc/message-123/testImage-test-uuid.jpg" },
         error: null,
       })
       .mockResolvedValueOnce({
         data: {
-          path: "public/user-abc/message-123/another-image-test-uuid.jpg",
+          path: "user-abc/message-123/another-image-test-uuid.jpg",
         },
         error: null,
       })
       .mockResolvedValueOnce({
-        data: { path: "public/user-abc/message-123/document-test-uuid.pdf" },
+        data: { path: "user-abc/message-123/document-test-uuid.pdf" },
         error: null,
       });
-    mockGetPublicUrlFn
-      .mockReturnValueOnce({
-        data: { publicUrl: "http://s.com/testImage-test-uuid.jpg" },
-      })
-      .mockReturnValueOnce({
-        data: { publicUrl: "http://s.com/another-image-test-uuid.jpg" },
-      })
-      .mockReturnValueOnce({
-        data: { publicUrl: "http://s.com/document-test-uuid.pdf" },
-      });
     const result = await uploadFilesToStorage(
       supabaseAdmin,
       [...mockFilesBase],
@@ -126,19 +116,19 @@ describe("uploadFilesToStorage", () => {
     expect(mockUploadFn).toHaveBeenCalledTimes(3);
     expect(mockUploadFn).toHaveBeenNthCalledWith(
       1,
-      "public/user-abc/message-123/testImage-test-uuid.jpg",
+      "user-abc/message-123/testImage-test-uuid.jpg",
       Buffer.from("compressed-testPNG"),
       { contentType: "image/jpeg", cacheControl: "3600" }
     );
     expect(mockUploadFn).toHaveBeenNthCalledWith(
       2,
-      "public/user-abc/message-123/another-image-test-uuid.jpg",
+      "user-abc/message-123/another-image-test-uuid.jpg",
       Buffer.from("compressed-testJPG"),
       { contentType: "image/jpeg", cacheControl: "3600" }
     );
     expect(mockUploadFn).toHaveBeenNthCalledWith(
       3,
-      "public/user-abc/message-123/document-test-uuid.pdf",
+      "user-abc/message-123/document-test-uuid.pdf",
       mockFilesBase[2].buffer,
       { contentType: "application/pdf", cacheControl: "3600" }
     );
@@ -157,12 +147,9 @@ describe("uploadFilesToStorage", () => {
       size: 8,
     };
     mockUploadFn.mockResolvedValueOnce({
-      data: { path: "public/user-abc/message-123/imageToFail-test-uuid.png" },
+      data: { path: "user-abc/message-123/imageToFail-test-uuid.png" },
       error: null,
     });
-    mockGetPublicUrlFn.mockReturnValueOnce({
-      data: { publicUrl: "http://s.com/imageToFail-test-uuid.png" },
-    });
     const consoleWarnSpy = jest
       .spyOn(console, "warn")
       .mockImplementation(() => {});
@@ -173,7 +160,7 @@ describe("uploadFilesToStorage", () => {
       mockUserId
     );
     expect(mockUploadFn).toHaveBeenCalledWith(
-      "public/user-abc/message-123/imageToFail-test-uuid.png",
+      "user-abc/message-123/imageToFail-test-uuid.png",
       imageToFail.buffer,
       { contentType: "image/png", cacheControl: "3600" }
     );
@@ -193,12 +180,9 @@ describe("uploadFilesToStorage", () => {
     };
     // Expecting .jpg because it's an image and compressImage mock will run
     mockUploadFn.mockResolvedValueOnce({
-      data: { path: "public/user-abc/message-123/te_t_Im_ge_-test-uuid.jpg" },
+      data: { path: "user-abc/message-123/te_t_Im_ge_-test-uuid.jpg" },
       error: null,
     });
-    mockGetPublicUrlFn.mockReturnValueOnce({
-      data: { publicUrl: "http://s.com/te_t_Im_ge_-test-uuid.jpg" },
-    });
 
     await uploadFilesToStorage(
       supabaseAdmin,
@@ -209,7 +193,7 @@ describe("uploadFilesToStorage", () => {
 
     expect(mockedCompressImage).toHaveBeenCalledWith(specialImageFile.buffer);
     expect(mockUploadFn).toHaveBeenCalledWith(
-      "public/user-abc/message-123/te_t_Im_ge_-test-uuid.jpg", // Path should be .jpg
+      "user-abc/message-123/te_t_Im_ge_-test-uuid.jpg", // Path should be .jpg
       Buffer.from("compressed-specialPNG"), // Buffer should be the compressed one
       { contentType: "image/jpeg", cacheControl: "3600" } // ContentType should be image/jpeg
     );
@@ -260,14 +244,14 @@ describe("uploadFilesToStorage", () => {
       // 1. failCompress.png (compression fails, original uploaded with .png ext)
       .mockResolvedValueOnce({
         data: {
-          path: "public/user-abc/message-123/failCompress-test-uuid.png",
+          path: "user-abc/message-123/failCompress-test-uuid.png",
         },
         error: null,
       })
       // 2. succeedCompress.jpg (compression succeeds, uploaded with .jpg ext)
       .mockResolvedValueOnce({
         data: {
-          path: "public/user-abc/message-123/succeedCompress-test-uuid.jpg",
+          path: "user-abc/message-123/succeedCompress-test-uuid.jpg",
         },
         error: null,
       })
@@ -279,22 +263,11 @@ describe("uploadFilesToStorage", () => {
       // 4. finalSuccess.gif (compression succeeds, .jpg ext)
       .mockResolvedValueOnce({
         data: {
-          path: "public/user-abc/message-123/finalSuccess-test-uuid.jpg",
+          path: "user-abc/message-123/finalSuccess-test-uuid.jpg",
         },
         error: null,
       });
 
-    mockGetPublicUrlFn
-      .mockReturnValueOnce({
-        data: { publicUrl: "http://s.com/failCompress-test-uuid.png" },
-      }) // For failCompress.png
-      .mockReturnValueOnce({
-        data: { publicUrl: "http://s.com/succeedCompress-test-uuid.jpg" },
-      }) // For succeedCompress.jpg
-      // No getPublicUrl for uploadFail.pdf as upload failed
-      .mockReturnValueOnce({
-        data: { publicUrl: "http://s.com/finalSuccess-test-uuid.jpg" },
-      }); // For finalSuccess.gif
 
     const consoleWarnSpy = jest
       .spyOn(console, "warn")
@@ -316,25 +289,25 @@ describe("uploadFilesToStorage", () => {
     // Check calls to mockUploadFn
     expect(mockUploadFn).toHaveBeenNthCalledWith(
       1,
-      "public/user-abc/message-123/failCompress-test-uuid.png",
+      "user-abc/message-123/failCompress-test-uuid.png",
       filesForPartialFailure[0].buffer,
       { contentType: "image/png", cacheControl: "3600" }
     );
     expect(mockUploadFn).toHaveBeenNthCalledWith(
       2,
-      "public/user-abc/message-123/succeedCompress-test-uuid.jpg",
+      "user-abc/message-123/succeedCompress-test-uuid.jpg",
       Buffer.from("compressed-succeedCompressJPG"),
       { contentType: "image/jpeg", cacheControl: "3600" }
     );
     expect(mockUploadFn).toHaveBeenNthCalledWith(
       3,
-      "public/user-abc/message-123/uploadFail-test-uuid.pdf",
+      "user-abc/message-123/uploadFail-test-uuid.pdf",
       filesForPartialFailure[2].buffer,
       { contentType: "application/pdf", cacheControl: "3600" }
     );
     expect(mockUploadFn).toHaveBeenNthCalledWith(
       4,
-      "public/user-abc/message-123/finalSuccess-test-uuid.jpg",
+      "user-abc/message-123/finalSuccess-test-uuid.jpg",
       Buffer.from("compressed-finalSuccessGIF"),
       { contentType: "image/jpeg", cacheControl: "3600" }
     );
@@ -347,12 +320,6 @@ describe("uploadFilesToStorage", () => {
     expect(result.imageRecords[2].filename).toBe("finalSuccess.gif");
     expect(result.imageRecords[2].content_type).toBe("image/jpeg");
 
-    expect(result.imageUrlsForOpenAI).toHaveLength(3);
-    expect(result.imageUrlsForOpenAI).toEqual([
-      "http://s.com/failCompress-test-uuid.png",
-      "http://s.com/succeedCompress-test-uuid.jpg",
-      "http://s.com/finalSuccess-test-uuid.jpg",
-    ]);
 
     expect(consoleWarnSpy).toHaveBeenCalledWith(
       expect.stringContaining("Failed to compress image failCompress.png")
@@ -374,12 +341,9 @@ describe("uploadFilesToStorage", () => {
       size: 7,
     };
     mockUploadFn.mockResolvedValueOnce({
-      data: { path: "public/message-123/onlyImage-test-uuid.jpg" },
+      data: { path: "message-123/onlyImage-test-uuid.jpg" },
       error: null,
     });
-    mockGetPublicUrlFn.mockReturnValueOnce({
-      data: { publicUrl: "http://s.com/onlyImage-test-uuid.jpg" },
-    });
     const result = await uploadFilesToStorage(
       supabaseAdmin,
       [imageFile],
@@ -387,14 +351,14 @@ describe("uploadFilesToStorage", () => {
       null
     );
     expect(mockUploadFn).toHaveBeenCalledWith(
-      "public/message-123/onlyImage-test-uuid.jpg",
+      "message-123/onlyImage-test-uuid.jpg",
       Buffer.from("compressed-soloJPG"),
       { contentType: "image/jpeg", cacheControl: "3600" }
     );
     expect(result.imageRecords[0].content_type).toBe("image/jpeg");
   });
 
-  it("should handle cases where getPublicUrl does not return a publicUrl", async () => {
+  it("should handle cases where upload succeeds but URL is not returned", async () => {
     const imageFileToTest = {
       originalname: "noUrl.png",
       mimetype: "image/png",
@@ -402,19 +366,15 @@ describe("uploadFilesToStorage", () => {
       size: 8,
     };
     mockUploadFn.mockResolvedValueOnce({
-      data: { path: "public/user-abc/message-123/noUrl-test-uuid.jpg" },
+      data: { path: "user-abc/message-123/noUrl-test-uuid.jpg" },
       error: null,
     });
-    mockGetPublicUrlFn.mockReturnValueOnce({
-      data: { publicUrl: null as any },
-    });
     const result = await uploadFilesToStorage(
       supabaseAdmin,
       [imageFileToTest],
       mockSavedMessage,
       mockUserId
     );
-    expect(result.imageUrlsForOpenAI).toEqual([]);
     expect(result.imageRecords[0].content_type).toBe("image/jpeg"); // Still compressed
   });
 
diff --git a/backend/controllers/analyzeController.ts b/backend/controllers/analyzeController.ts
index e7bae08..4aff01d 100644
--- a/backend/controllers/analyzeController.ts
+++ b/backend/controllers/analyzeController.ts
@@ -14,6 +14,7 @@ import { toOpenAIContent } from "../utils/openaiHelpers";
 import { getPreferences, UserPrefs } from "../services/userService";
 import type { SimpPreference } from "../types/user";
 import { UploadedFile, ImageRecord } from "../services/imageUploadService";
+import { compressImage } from "../utils/imageProcessor";
 import { PromptService } from "../services/promptService";
 import { inferStage, isValidStage } from "../utils/stage";
 import { stripQuotes } from "../utils/text";
@@ -359,8 +360,7 @@ export async function analyze(req: Request, res: Response): Promise<void> {
 
     let savedMessage: MessageRecord | null = null;
     let imageRecords: ImageRecord[] = [];
-    let imageUrlsForOpenAI: string[] = [];
-    let imageUrlsForFrontend: string[] = [];
+    let base64ImagesForOpenAI: { dataUrl: string }[] = [];
 
     // --- Save the Message Stub (without AI response yet) ---
     try {
@@ -393,23 +393,25 @@ export async function analyze(req: Request, res: Response): Promise<void> {
       return;
     }
 
-    // --- Upload Files to Supabase Storage & Prepare Records ---
-    if (files.length > 0 && savedMessage) {
-      const uploadResult = await uploadFilesToStorage(
-        supabaseAdmin,
-        files,
-        savedMessage,
-        userId
-      );
-      imageRecords = uploadResult.imageRecords;
-      imageUrlsForOpenAI = uploadResult.imageUrlsForOpenAI;
-      imageUrlsForFrontend = uploadResult.imageUrlsForFrontend;
-      try {
-        await saveImageRecords(supabaseAdmin, imageRecords);
-      } catch (imageDbError: any) {
-        res.status(500).json({ error: imageDbError.message });
-        console.error("[Analyze] Error saving image records:", imageDbError);
-        return;
+    // --- Prepare images for OpenAI (compress & base64) ---
+    if (files.length > 0) {
+      for (const file of files) {
+        let processedBuffer = file.buffer;
+        let processedType = file.mimetype;
+        if (file.mimetype.startsWith("image/")) {
+          try {
+            processedBuffer = await compressImage(file.buffer);
+            processedType = "image/jpeg";
+          } catch (compressionError) {
+            console.warn(
+              `Failed to compress image ${file.originalname}: ${compressionError}`
+            );
+          }
+        }
+        const dataUrl = `data:${processedType};base64,${processedBuffer.toString(
+          "base64"
+        )}`;
+        base64ImagesForOpenAI.push({ dataUrl });
       }
     }
 
@@ -423,7 +425,7 @@ export async function analyze(req: Request, res: Response): Promise<void> {
     let promptText = newMessageText;
     if (
       (!newMessageText || newMessageText.trim() === "") &&
-      imageUrlsForOpenAI.length > 0
+      base64ImagesForOpenAI.length > 0
     ) {
       const fallbackPrompt = getFallbackImageAnalysisPrompt();
       promptText =
@@ -433,28 +435,28 @@ export async function analyze(req: Request, res: Response): Promise<void> {
     }
     // Only add the user message if there are NO images; otherwise, skip it for Vision API
     if (
-      imageUrlsForOpenAI.length === 0 &&
+      base64ImagesForOpenAI.length === 0 &&
       promptText &&
       promptText.trim() !== ""
     ) {
       finalUserMessageContent.push({ type: "input_text", text: promptText });
     }
-    if (imageUrlsForOpenAI.length > 0) {
+    if (base64ImagesForOpenAI.length > 0) {
       if (finalUserMessageContent.length === 0) {
         finalUserMessageContent.push({
           type: "input_text",
           text: "[Image(s) provided]",
         });
       }
-      imageUrlsForOpenAI.forEach((url) => {
+      base64ImagesForOpenAI.forEach((img) => {
         finalUserMessageContent.push({
           type: "input_image",
-          image_url: url,
+          image_url: img.dataUrl,
         });
       });
     }
     if (isInitialUserMessage && finalUserMessageContent.length > 0) {
-      if (imageUrlsForOpenAI.length > 0) {
+      if (base64ImagesForOpenAI.length > 0) {
         // 1. First call: get image description
         const { imageDescription } = await generateImageDescriptionAndNickname(
           finalUserMessageContent
@@ -479,7 +481,7 @@ export async function analyze(req: Request, res: Response): Promise<void> {
       }
     } else if (
       finalUserMessageContent.length > 0 &&
-      imageUrlsForOpenAI.length > 0
+      base64ImagesForOpenAI.length > 0
     ) {
       // 1. First call: get image description
       const imageDescription = await generateImageDescription(
@@ -502,6 +504,24 @@ export async function analyze(req: Request, res: Response): Promise<void> {
       savedMessage.image_description = generatedImageDescription;
     }
 
+    // --- Now store the uploaded files in the private bucket ---
+    if (files.length > 0 && savedMessage) {
+      const uploadResult = await uploadFilesToStorage(
+        supabaseAdmin,
+        files,
+        savedMessage,
+        userId
+      );
+      imageRecords = uploadResult.imageRecords;
+      try {
+        await saveImageRecords(supabaseAdmin, imageRecords);
+      } catch (imageDbError: any) {
+        res.status(500).json({ error: imageDbError.message });
+        console.error("[Analyze] Error saving image records:", imageDbError);
+        return;
+      }
+    }
+
     // --- Use the extracted stage instead of inferring it ---
     const stage = extractedStage;
 
diff --git a/backend/services/imageUploadService.ts b/backend/services/imageUploadService.ts
index ac0a769..29887c3 100644
--- a/backend/services/imageUploadService.ts
+++ b/backend/services/imageUploadService.ts
@@ -25,8 +25,7 @@ export interface ImageRecord {
 
 /**
  * Handles compressing (when applicable) and uploading user-provided files to Supabase Storage.
- * It returns both the DB records that need to be inserted and the public URLs that can be
- * consumed by OpenAI (for Vision API) and by the front-end.
+ * Returns the DB records that must be inserted once upload succeeds.
  */
 export async function uploadFilesToStorage(
   supabase: any,
@@ -35,12 +34,8 @@ export async function uploadFilesToStorage(
   userId: string | null
 ): Promise<{
   imageRecords: ImageRecord[];
-  imageUrlsForOpenAI: string[];
-  imageUrlsForFrontend: string[];
 }> {
   const imageRecords: ImageRecord[] = [];
-  const imageUrlsForOpenAI: string[] = [];
-  const imageUrlsForFrontend: string[] = [];
 
   for (const file of files) {
     const originalFileExt = path.extname(file.originalname);
@@ -74,8 +69,8 @@ export async function uploadFilesToStorage(
     // Build a unique filename/path so that collisions are impossible and files are grouped per-message
     const uniqueFileName = `${safeFileNameBase}-${uuidv4()}${processedFileExt}`;
     const storageDirPath = userId
-      ? `public/${userId}/${savedMessage.id}`
-      : `public/${savedMessage.id}`;
+      ? `${userId}/${savedMessage.id}`
+      : `${savedMessage.id}`;
     const storagePath = `${storageDirPath}/${uniqueFileName}`;
 
     const { data: uploadData, error: uploadError } = await supabase!.storage
@@ -100,15 +95,7 @@ export async function uploadFilesToStorage(
       continue;
     }
 
-    // Obtain a public URL so it can be consumed by downstream services/UI
-    const { data: urlData } = supabase!.storage
-      .from("chat-images")
-      .getPublicUrl(uploadData.path);
-    if (urlData?.publicUrl) {
-      imageUrlsForOpenAI.push(urlData.publicUrl);
-      imageUrlsForFrontend.push(urlData.publicUrl);
-    }
-
+    // File successfully uploaded; prepare DB record
     imageRecords.push({
       message_id: savedMessage.id,
       storage_path: uploadData.path,
@@ -118,5 +105,5 @@ export async function uploadFilesToStorage(
     });
   }
 
-  return { imageRecords, imageUrlsForOpenAI, imageUrlsForFrontend };
+  return { imageRecords };
 }
diff --git a/frontend/src/hooks/useMessages.ts b/frontend/src/hooks/useMessages.ts
index 09f8f4f..a059d30 100644
--- a/frontend/src/hooks/useMessages.ts
+++ b/frontend/src/hooks/useMessages.ts
@@ -91,14 +91,16 @@ export default function useMessages(
         .eq("conversation_id", activeConversationId)
         .order("created_at", { ascending: true });
       if (error) throw error;
-      const { supabaseUrl } = await import("../services/supabaseClient");
-      const bucketUrl = `${supabaseUrl}/storage/v1/object/public/chat-images/`;
-      const serverMessages = (data || []).map(
-        (msg: any): Message => ({
-          ...msg,
-          imageUrls: (msg.ChatMessageImages || []).map(
-            (img: any) => bucketUrl + img.storage_path
-          ),
+      const serverMessages = await Promise.all(
+        (data || []).map(async (msg: any): Promise<Message> => {
+          const imageUrls: string[] = [];
+          for (const img of msg.ChatMessageImages || []) {
+            const { data: signed } = await supabase.storage
+              .from("chat-images")
+              .createSignedUrl(img.storage_path, 3600);
+            if (signed?.signedUrl) imageUrls.push(signed.signedUrl);
+          }
+          return { ...msg, imageUrls };
         })
       );
       setMessages((prevMessages) => {


Reviews:
user: login: coderabbitai[bot]
body: **Actionable comments posted: 3**

<details>
<summary>🧹 Nitpick comments (2)</summary><blockquote>

<details>
<summary>frontend/src/hooks/useMessages.ts (1)</summary><blockquote>

`94-105`: **Consider performance optimization for multiple images.**

When messages contain many images, generating signed URLs sequentially could impact performance. Consider batching or limiting concurrent requests.


For better performance with multiple images, you could:

1. Implement concurrent URL generation with a concurrency limit
2. Consider caching signed URLs client-side (respecting expiry)
3. Implement pagination or lazy loading for messages with many images

Example concurrent approach:
```typescript
// Process images in batches of 5 concurrent requests
const batchSize = 5;
const imageUrls: string[] = [];
const images = msg.ChatMessageImages || [];

for (let i = 0; i < images.length; i += batchSize) {
  const batch = images.slice(i, i + batchSize);
  const batchUrls = await Promise.all(
    batch.map(async (img) => {
      const { data: signed } = await supabase.storage
        .from("chat-images")
        .createSignedUrl(img.storage_path, 3600);
      return signed?.signedUrl || null;
    })
  );
  imageUrls.push(...batchUrls.filter(Boolean));
}
```

</blockquote></details>
<details>
<summary>backend/controllers/analyzeController.ts (1)</summary><blockquote>

`396-416`: **Consider adding validation for base64 data URL size limits.**

While the image compression logic is well-implemented, OpenAI's Vision API has size limits for base64-encoded images. Consider adding validation to ensure the base64 data URLs don't exceed these limits to prevent API failures.


Add size validation after base64 encoding:

```diff
         const dataUrl = `data:${processedType};base64,${processedBuffer.toString(
           "base64"
         )}`;
+        // OpenAI typically has a limit of ~20MB for base64 images
+        const base64Size = dataUrl.length * 0.75; // Approximate size in bytes
+        if (base64Size > 20 * 1024 * 1024) {
+          console.warn(
+            `Image ${file.originalname} exceeds size limit after base64 encoding (${(base64Size / 1024 / 1024).toFixed(2)}MB)`
+          );
+          continue;
+        }
         base64ImagesForOpenAI.push({ dataUrl });
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between cc0e8e7bb06e867e013e863bc36db66917c489c3 and 4e4999e9d43a49afb48333a26a9d5ab89f3a12e4.

</details>

<details>
<summary>📒 Files selected for processing (6)</summary>

* `backend/controllers/__tests__/generateImageDescription.test.ts` (2 hunks)
* `backend/controllers/__tests__/generateImageDescriptionAndNickname.test.ts` (2 hunks)
* `backend/controllers/__tests__/uploadFilesToStorage.test.ts` (10 hunks)
* `backend/controllers/analyzeController.ts` (7 hunks)
* `backend/services/imageUploadService.ts` (4 hunks)
* `frontend/src/hooks/useMessages.ts` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (1)</summary>

<details>
<summary>backend/controllers/__tests__/uploadFilesToStorage.test.ts (1)</summary><blockquote>

<details>
<summary>backend/services/imageUploadService.ts (1)</summary>

* `uploadFilesToStorage` (30-109)

</details>

</blockquote></details>

</details>

</details>

<details>
<summary>🔇 Additional comments (12)</summary><blockquote>

<details>
<summary>backend/services/imageUploadService.ts (3)</summary>

`28-37`: **LGTM! Clean removal of public URL functionality.**

The updated function signature and removal of public URL arrays aligns well with the PR's objective of switching to private image storage.

---

`71-74`: **Good security improvement: Removed public prefix from storage paths.**

The removal of the `"public/"` prefix ensures images are stored privately, which is a significant security enhancement.

---

`98-108`: **LGTM! Simplified return structure.**

The function now correctly returns only the database records needed for insertion, which aligns with the new private storage workflow.

</details>
<details>
<summary>backend/controllers/__tests__/generateImageDescriptionAndNickname.test.ts (2)</summary>

`35-41`: **LGTM! Test data correctly updated to use base64 data URI.**

The change from HTTP URL to base64 data URI format properly reflects the new image handling approach.

---

`62-62`: **LGTM! Expected argument matches the updated test data.**

The test correctly validates that the base64 data URI is passed to the OpenAI service.

</details>
<details>
<summary>backend/controllers/__tests__/generateImageDescription.test.ts (2)</summary>

`38-41`: **LGTM! Consistent test data update.**

The test data correctly uses base64 data URI format, maintaining consistency with other test files.

---

`62-62`: **LGTM! Expected argument properly updated.**

The test expectation correctly matches the new base64 image format.

</details>
<details>
<summary>frontend/src/hooks/useMessages.ts (1)</summary>

`100-100`: <details>
<summary>❓ Verification inconclusive</summary>

**Verify consistency of signed URL expiry time.**

The 3600-second (1 hour) expiry for signed URLs should be consistent with backend cache control settings and user session duration.

---

🏁 Script executed:

```shell
#!/bin/bash
# Description: Check for consistency in cache control and expiry settings across the codebase

# Search for cache control settings in the backend
echo "Searching for cache control settings in backend:"
rg -A 3 "cacheControl|cache-control" --type ts

# Search for other signed URL expiry settings
echo -e "\nSearching for other signed URL expiry settings:"
rg -A 3 "createSignedUrl|signedUrl.*expiry|expiresIn" --type ts
```

Length of output: 4707

---



</details>

**Signed URL expiry aligns with backend cache control (3600 s)**

All instances of the 1 hour TTL match between frontend and backend:
- backend/services/imageUploadService.ts → `cacheControl: "3600"`
- backend/controllers/__tests__/uploadFilesToStorage.test.ts → `cacheControl: "3600"`
- frontend/src/hooks/useMessages.ts → `.createSignedUrl(img.storage_path, 3600)`

No discrepancies found. Please verify that your user session lifetime accommodates this 1 hour URL expiry.

</details>
<details>
<summary>backend/controllers/__tests__/uploadFilesToStorage.test.ts (2)</summary>

`93-137`: **LGTM! Test correctly reflects removal of public prefix.**

The test has been properly updated to remove the `"public/"` prefix from all expected upload paths, aligning with the changes in the actual `uploadFilesToStorage` function.

---

`361-361`: **LGTM! Test name accurately reflects the updated behavior.**

The test name has been appropriately renamed from "should handle cases where getPublicUrl does not return a publicUrl" to "should handle cases where upload succeeds but URL is not returned", which better describes the current behavior where public URLs are no longer generated.

</details>
<details>
<summary>backend/controllers/analyzeController.ts (2)</summary>

`17-17`: **LGTM! Import correctly added for image compression functionality.**

The `compressImage` utility import is properly added to support the new image compression workflow.

---

`363-363`: **LGTM! Variable declaration aligns with new base64 workflow.**

The `base64ImagesForOpenAI` array is properly declared to store compressed and base64-encoded images for OpenAI processing.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: NONE
submitted_at: 2025-05-31T21:24:57Z

Review comments:
diff_hunk: @@ -91,14 +91,16 @@ export default function useMessages(
         .eq("conversation_id", activeConversationId)
         .order("created_at", { ascending: true });
       if (error) throw error;
-      const { supabaseUrl } = await import("../services/supabaseClient");
-      const bucketUrl = `${supabaseUrl}/storage/v1/object/public/chat-images/`;
-      const serverMessages = (data || []).map(
-        (msg: any): Message => ({
-          ...msg,
-          imageUrls: (msg.ChatMessageImages || []).map(
-            (img: any) => bucketUrl + img.storage_path
-          ),
+      const serverMessages = await Promise.all(
+        (data || []).map(async (msg: any): Promise<Message> => {
+          const imageUrls: string[] = [];
+          for (const img of msg.ChatMessageImages || []) {
+            const { data: signed } = await supabase.storage
+              .from("chat-images")
+              .createSignedUrl(img.storage_path, 3600);
+            if (signed?.signedUrl) imageUrls.push(signed.signedUrl);
+          }
+          return { ...msg, imageUrls };
         })
       );
path: frontend/src/hooks/useMessages.ts
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Consider improving error handling for signed URL generation.**

While the implementation correctly generates signed URLs, it silently skips images when URL generation fails. This could lead to missing images without user awareness.

Apply this diff to add error logging:

```diff
-          for (const img of msg.ChatMessageImages || []) {
-            const { data: signed } = await supabase.storage
-              .from("chat-images")
-              .createSignedUrl(img.storage_path, 3600);
-            if (signed?.signedUrl) imageUrls.push(signed.signedUrl);
-          }
+          for (const img of msg.ChatMessageImages || []) {
+            const { data: signed, error: urlError } = await supabase.storage
+              .from("chat-images")
+              .createSignedUrl(img.storage_path, 3600);
+            if (signed?.signedUrl) {
+              imageUrls.push(signed.signedUrl);
+            } else if (urlError) {
+              console.error(`Failed to generate signed URL for image: ${img.storage_path}`, urlError);
+            }
+          }
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion
      const serverMessages = await Promise.all(
        (data || []).map(async (msg: any): Promise<Message> => {
          const imageUrls: string[] = [];
          for (const img of msg.ChatMessageImages || []) {
            const { data: signed, error: urlError } = await supabase.storage
              .from("chat-images")
              .createSignedUrl(img.storage_path, 3600);
            if (signed?.signedUrl) {
              imageUrls.push(signed.signedUrl);
            } else if (urlError) {
              console.error(`Failed to generate signed URL for image: ${img.storage_path}`, urlError);
            }
          }
          return { ...msg, imageUrls };
        })
      );
```

</details>

<!-- suggestion_end -->

<details>
<summary>🤖 Prompt for AI Agents</summary>

```
In frontend/src/hooks/useMessages.ts around lines 94 to 105, the code generating
signed URLs for images silently ignores failures, which can cause missing images
without notifying users. Modify the loop to catch errors during signed URL
generation for each image, log the error details for debugging, and continue
processing other images. This ensures failures are visible while maintaining
functionality.
```

</details>

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-31T21:24:56Z
author_association: NONE
diff_hunk: @@ -433,28 +435,28 @@ export async function analyze(req: Request, res: Response): Promise<void> {
     }
     // Only add the user message if there are NO images; otherwise, skip it for Vision API
     if (
-      imageUrlsForOpenAI.length === 0 &&
+      base64ImagesForOpenAI.length === 0 &&
       promptText &&
       promptText.trim() !== ""
     ) {
       finalUserMessageContent.push({ type: "input_text", text: promptText });
     }
-    if (imageUrlsForOpenAI.length > 0) {
+    if (base64ImagesForOpenAI.length > 0) {
       if (finalUserMessageContent.length === 0) {
         finalUserMessageContent.push({
           type: "input_text",
           text: "[Image(s) provided]",
         });
       }
-      imageUrlsForOpenAI.forEach((url) => {
+      base64ImagesForOpenAI.forEach((img) => {
         finalUserMessageContent.push({
           type: "input_image",
-          image_url: url,
+          image_url: img.dataUrl,
         });
       });
path: backend/controllers/analyzeController.ts
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Fix inconsistency in content structure for OpenAI API.**

The code uses `image_url` property when adding images to `finalUserMessageContent`, but based on the `toOpenAIContent` function usage and OpenAI's expected format, this should be `image_url: { url: img.dataUrl }` for proper content structure.


Apply this fix to match OpenAI's expected content format:

```diff
       base64ImagesForOpenAI.forEach((img) => {
         finalUserMessageContent.push({
           type: "input_image",
-          image_url: img.dataUrl,
+          image_url: { url: img.dataUrl },
         });
       });
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion
      base64ImagesForOpenAI.forEach((img) => {
        finalUserMessageContent.push({
          type: "input_image",
          image_url: { url: img.dataUrl },
        });
      });
```

</details>

<!-- suggestion_end -->

<details>
<summary>🤖 Prompt for AI Agents</summary>

```
In backend/controllers/analyzeController.ts around lines 451 to 456, the image
content added to finalUserMessageContent uses image_url as a string property,
but OpenAI expects image_url to be an object with a url property. Update the
code to set image_url as an object like { url: img.dataUrl } to match the
expected content structure for the OpenAI API.
```

</details>

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-31T21:24:57Z
author_association: NONE
diff_hunk: @@ -502,6 +504,24 @@ export async function analyze(req: Request, res: Response): Promise<void> {
       savedMessage.image_description = generatedImageDescription;
     }
 
+    // --- Now store the uploaded files in the private bucket ---
+    if (files.length > 0 && savedMessage) {
+      const uploadResult = await uploadFilesToStorage(
+        supabaseAdmin,
+        files,
+        savedMessage,
+        userId
+      );
+      imageRecords = uploadResult.imageRecords;
+      try {
+        await saveImageRecords(supabaseAdmin, imageRecords);
+      } catch (imageDbError: any) {
+        res.status(500).json({ error: imageDbError.message });
+        console.error("[Analyze] Error saving image records:", imageDbError);
+        return;
+      }
+    }
+
path: backend/controllers/analyzeController.ts
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Ensure error handling consistency for deferred image uploads.**

The deferred image upload logic is correctly implemented. However, consider wrapping the entire upload and save operation in a try-catch block to ensure consistent error handling.


Wrap the entire operation for better error handling:

```diff
     // --- Now store the uploaded files in the private bucket ---
     if (files.length > 0 && savedMessage) {
+      try {
         const uploadResult = await uploadFilesToStorage(
           supabaseAdmin,
           files,
           savedMessage,
           userId
         );
         imageRecords = uploadResult.imageRecords;
-        try {
           await saveImageRecords(supabaseAdmin, imageRecords);
-        } catch (imageDbError: any) {
+      } catch (error: any) {
           res.status(500).json({ error: imageDbError.message });
-          console.error("[Analyze] Error saving image records:", imageDbError);
+          console.error("[Analyze] Error uploading images or saving records:", error);
           return;
-        }
+      }
     }
```


> Committable suggestion skipped: line range outside the PR's diff.

<details>
<summary>🤖 Prompt for AI Agents</summary>

```
In backend/controllers/analyzeController.ts around lines 507 to 524, the current
code handles errors only when saving image records but not during the
uploadFilesToStorage call. To ensure consistent error handling, wrap the entire
block that uploads files and saves image records in a single try-catch block.
Move the uploadFilesToStorage call inside the try block along with
saveImageRecords, and handle any errors by sending a 500 response with the error
message and logging the error.
```

</details>

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-31T21:24:57Z
author_association: NONE

PR comments:
user: login: vercel[bot]
created_at: 2025-05-31T21:21:10Z
body: [vc]: #HmwgQWj7GIxiqE1UzvWmb55k26aXoFj+jmzeAWd6ql0=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJ3aW5nbWFuIiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL21pbGFkeWJveXMtcHJvamVjdHMvd2luZ21hbi9DWXlYelp0YjFMOWdtZGdUbzJ5V3lpaFNjalYzIiwicHJldmlld1VybCI6IndpbmdtYW4tZ2l0LWNvZGV4LWltcGxlbWVudC1wcml2YXRlLTM5NThjMy1taWxhZHlib3lzLXByb2plY3RzLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQiLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoid2luZ21hbi1naXQtY29kZXgtaW1wbGVtZW50LXByaXZhdGUtMzk1OGMzLW1pbGFkeWJveXMtcHJvamVjdHMudmVyY2VsLmFwcCJ9LCJyb290RGlyZWN0b3J5IjoiZnJvbnRlbmQifV19
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **wingman** | ✅ Ready ([Inspect](https://vercel.com/miladyboys-projects/wingman/CYyXzZtb1L9gmdgTo2yWyihScjV3)) | [Visit Preview](https://wingman-git-codex-implement-private-3958c3-miladyboys-projects.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/wingman-git-codex-implement-private-3958c3-miladyboys-projects.vercel.app?via=pr-comment-feedback-link) | May 31, 2025 9:21pm |


author_association: NONE
user: login: coderabbitai[bot]
created_at: 2025-05-31T21:21:14Z
body: <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- walkthrough_start -->

## Walkthrough

The changes update how images are handled throughout the application. Image files are now compressed and converted to base64 data URLs for AI analysis before being uploaded to storage. Public URL generation is replaced with signed URLs for frontend access, and test suites are updated to reflect these changes, including the use of base64 image strings.

## Changes

| File(s)                                                                                   | Change Summary                                                                                               |
|------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| backend/controllers/__tests__/generateImageDescription.test.ts,<br>...AndNickname.test.ts | Updated test image references from HTTP URLs to base64-encoded data URIs in inputs and assertions.           |
| backend/controllers/__tests__/uploadFilesToStorage.test.ts                               | Removed `"public/"` prefix from paths, eliminated `getPublicUrl` mocks, and updated related assertions.      |
| backend/controllers/analyzeController.ts                                                 | Changed image handling to compress and encode images as base64 for AI, deferred storage upload to later step.|
| backend/services/imageUploadService.ts                                                   | Modified upload function to remove public URL logic and `"public/"` prefix; now returns only image records.  |
| frontend/src/hooks/useMessages.ts                                                        | Changed image URL construction to use signed URLs via async `createSignedUrl` calls for each image.          |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant Supabase
    participant OpenAI

    User->>Frontend: Uploads message with images
    Frontend->>Backend: Sends images (multipart/form-data)
    Backend->>Backend: Compress and encode images as base64
    Backend->>OpenAI: Send base64 images for analysis
    OpenAI-->>Backend: Returns descriptions/nicknames
    Backend->>Supabase: Uploads images to storage
    Supabase-->>Backend: Confirms upload
    Backend->>Supabase: Save image records in DB
    Backend-->>Frontend: Returns message data (without public URLs)
    Frontend->>Supabase: Requests signed URLs for images
    Supabase-->>Frontend: Returns signed URLs
    Frontend-->>User: Displays messages with signed image URLs
```

## Poem

> 🐇  
> Images now hop as base64 streams,  
> Compressed and encoded, chasing AI dreams.  
> No more public links, just signed for a while,  
> Secure little carrots in a digital pile.  
> Tests and uploads pruned, all neat and tight—  
> This bunny’s code garden is running just right!  
>

<!-- walkthrough_end -->
<!-- This is an auto-generated comment: all tool run failures by coderabbit.ai -->

> [!WARNING]
> There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
> 
> <details>
> <summary>🔧 ESLint</summary>
> 
> > If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
> 
> npm error Exit handler never called!
> npm error This is an error with npm itself. Please report this error at:
> npm error   <https://github.com/npm/cli/issues>
> npm error A complete log of this run can be found in: /.npm/_logs/2025-05-31T21_21_57_939Z-debug-0.log
> 
> 
> 
> </details>

<!-- end of auto-generated comment: all tool run failures by coderabbit.ai -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNxU3bABsvkCiQBHbGlcSHFcLzpIACIAZQB3dQZYMPweCklqEhRmNFJ7AipSABpo+2wBZnUaejlIbERKSCqvNFpZAXx5NGRbSAxHASaAJgBmYpQMXApFbAZpRlhMUmQCMNhs+Fz8pYxaL3gMIkh4/AoAawAzL3x4yfXs3nwRMQ0YDchzknlsblos5CHBhebBKercG5tQ7HZLUHJ5BZrNDpTI0SACOZfUL4LCxX4qHrZNCXGh8TBoLyyRBICZMZi8aTUo7wlboPb2Mi0aEPZiQLn+MSU1KQADy3DIAEEAJKQMhMJT0Q7owkANgALJBLmdcrgJph6JcSLhktzqURyPQAKo2AAyyC1fC2COQ8Q2WEhXOZbEQiGdbwltC54hxFMpE1wH2wGHUYRCyCWUnRJDI4P+NWF/muolCEey5Dupwu11ub2gIW5h0Q0zmwYwyEQ4oY8Eu8goUejzIABhhuLyaFXOwonHt6yRuM4skKHQ9lQwvuz9ZqZlNOXz4ALCvBpKWPn1tMxVmkyLt5izslWzgiOQxsBlcN12fhuOIqg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clUlcgMHutEnUDCiohiiQpICKNoDCh/kJQ4hBq4kgDVBIDVAAE4saSAMbaA1RRg0BMbiQBA1QAAOUYCmtAYYFUNAXGkfFQUmjGy4Amr6YYdGlyO6lGsG3ACGsHMKaG2GsKVcfQIAA= -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Docstrings were successfully generated. (🔄  Check again to generate docstrings again)

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=miladyboy/wingman&utm_content=23):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->
author_association: NONE
user: login: coderabbitai[bot]
created_at: 2025-05-31T21:31:20Z
body: > [!NOTE]
> Generated docstrings for this pull request at https://github.com/miladyboy/wingman/pull/24
author_association: NONE