Skip to content

Commit b92b99c

Browse files
auth updated, ai chat improved, github import fixed
1 parent 3db7df6 commit b92b99c

40 files changed

+1922
-1030
lines changed

.env.example

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# E2B Configuration
2+
E2B_API_KEY="your_e2b_api_key_here"
3+
4+
5+
# AI API Keys
6+
ANTHROPIC_API_KEY="your_anthropic_api_key_here"
7+
DEEPSEEK_API_KEY="your_deepseek_api_key_here"
8+
FIREWORKS_API_KEY="your_fireworks_api_key_here"
9+
GOOGLE_AI_API_KEY="your_google_ai_api_key_here"
10+
MISTRAL_API_KEY="your_mistral_api_key_here"
11+
OPENAI_API_KEY="your_openai_api_key_here"
12+
TOGETHER_AI_API_KEY="your_together_ai_api_key_here"
13+
XAI_API_KEY="your_xai_api_key_here"
14+
15+
# Google Services
16+
GOOGLE_CLIENT_ID="your_google_client_id_here"
17+
GOOGLE_VERTEX_CREDENTIALS="your_google_vertex_credentials_here"
18+
19+
# GitHub Configuration
20+
GITHUB_PERSONAL_ACCESS_TOKEN="your_github_personal_access_token_here"
21+
NEXT_PUBLIC_GITHUB_CLIENT_ID="your_github_client_id_here"
22+
NEXT_PUBLIC_GITHUB_CLIENT_SECRET="your_github_client_secret_here"
23+
NEXT_PUBLIC_GITHUB_PRIVATE_KEY_PEM="your_github_private_key_pem_here"
24+
PATH_TO_PRIVATE_KEY_PEM="/path/to/your/private_key.pem"
25+
26+
# Supabase Configuration
27+
NEXT_PUBLIC_ENABLE_SUPABASE="true"
28+
NEXT_PUBLIC_SUPABASE_URL="your_supabase_url_here"
29+
NEXT_PUBLIC_SUPABASE_ANON_KEY="your_supabase_anon_key_here"
30+
SUPABASE_SERVICE_ROLE_KEY="your_supabase_service_role_key_here"
31+
32+
# PostHog Analytics
33+
NEXT_PUBLIC_POSTHOG_KEY="your_posthog_key_here"
34+
NEXT_PUBLIC_POSTHOG_HOST="https://us.i.posthog.com"
35+
36+
# reCAPTCHA
37+
RECAPTCHA_SITE_KEY="your_recaptcha_site_key_here"
38+
RECAPTCHA_SECRET_KEY="your_recaptcha_secret_key_here"
39+
40+
# Other APIs
41+
FIGMA_API_KEY="your_figma_api_key_here"
42+
43+
# Application Configuration
44+
NEXT_PUBLIC_SITE_URL="https://yoursite.com"
45+
NEXT_PUBLIC_HIDE_LOCAL_MODELS="true"
46+
WEB_PUSH_CERTIFICATE="your_web_push_certificate_here"

.github/CODEOWNERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
See [GitHub documentation](https://help.github.com/en/articles/about-code-owners)
2+
for more info about CODEOWNERS file.
3+
4+
These owners will be the default owners for everything in
5+
the repo. Unless a later match takes precedence.
6+
7+
@Gerome-Elassaad/CodingIT @Gerome-Elassaad
File renamed without changes.
File renamed without changes.
File renamed without changes.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
# production
1111
/build
1212

13+
# update files
14+
.clinerules
15+
.memory-bank
16+
1317
# debug
1418
npm-debug.log*
1519
yarn-debug.log*
1620
yarn-error.log*
1721
.pnpm-debug.log*
1822

1923
# env files
20-
.env*
2124
.env.local
2225
.env
2326

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# AI Chat UI Improvement Plan
2+
3+
## 1. Introduction and Goals
4+
5+
This document outlines a plan to address potential bugs, practical errors, and areas for improvement within the existing AI Chat UI. The primary goals are to enhance stability, usability, and maintainability of the chat interface. The analysis covered frontend components, backend API interactions, state management, and overall code structure.
6+
7+
## 2. Identified Issues and Proposed Solutions
8+
9+
### 2.1. Configuration and Settings
10+
11+
**Issue 2.1.1: `ChatSettings` API Key/Base URL Input Logic (components/chat-settings.tsx, app/page.tsx)**
12+
* **Problem**: Conditional rendering based on `!process.env.NEXT_PUBLIC_NO_API_KEY_INPUT` might behave unexpectedly if env vars are undefined (showing inputs when they should be hidden). Placeholder "Auto" can be misleading when input is cleared.
13+
* **Proposed Solution**:
14+
* Change env var check to be explicit, e.g., `process.env.NEXT_PUBLIC_NO_API_KEY_INPUT === 'true'`.
15+
* Improve UI feedback for cleared API key/Base URL fields. Instead of "Auto", perhaps show "Using default" or ensure the input visually reflects its empty state if that means "use global/default". Clarify if an empty input truly falls back to a system default or if it means "no key provided".
16+
17+
**Issue 2.1.2: `ChatSidebar SettingsDialog` Display Settings Persistence (components/chat-sidebar/settings-dialog.tsx)**
18+
* **Problem**: Display settings (Auto-save, Show timestamps, Compact view) are local to the dialog and not persisted or applied globally.
19+
* **Proposed Solution**:
20+
* If these settings are intended to be functional, use `useLocalStorage` (similar to `languageModel` state in `app/page.tsx`) to persist their values.
21+
* Implement logic in relevant components (e.g., `ChatSessionItem`, `Chat.tsx`) to read and apply these settings. For example, "Compact view" could reduce padding/margins in chat items. "Show timestamps" would toggle timestamp visibility on messages. "Auto-save" might influence how/when sessions are saved (though current saving seems implicit).
22+
23+
### 2.2. Error Handling and Feedback
24+
25+
**Issue 2.2.1: Error Parsing in `EnhancedChatInput` for AI Enhance (components/enhanced-chat-input.tsx)**
26+
* **Problem**: The `handleEnhanceMessage` feature uses basic error parsing (`error.message`) instead of the more robust `parseApiError` utility from `app/page.tsx`.
27+
* **Proposed Solution**:
28+
* Refactor `EnhancedChatInput` to use or import `parseApiError` (or a shared error parsing utility) for the `/api/ai/enhance-text` call to provide more consistent and user-friendly error messages.
29+
30+
**Issue 2.2.2: Clarity on Rate Limiting Feedback (app/page.tsx, components/enhanced-chat-input.tsx)**
31+
* **Problem**: Rate limit feedback is primarily tied to the main `/api/chat` via `useObject`. Other API calls (e.g., `/api/sandbox`, `/api/ai/enhance-text`) might not trigger the same specific UI feedback if their error formats differ.
32+
* **Proposed Solution**:
33+
* Ensure all backend API endpoints that can be rate-limited return a consistent error structure (e.g., `{ code: "RATE_LIMITED", message: "..." }`).
34+
* Update client-side error handling for all API calls to recognize this consistent rate limit error structure and set the `isRateLimited` state appropriately.
35+
36+
### 2.3. Component Interactions and State
37+
38+
**Issue 2.3.1: `EnhancedChatInput` GitHub Import DOM Manipulation (components/enhanced-chat-input.tsx)**
39+
* **Problem**: Direct DOM manipulation (`textarea.value = ...; textarea.dispatchEvent(...)`) to set the chat input after GitHub import might conflict with React's controlled component pattern. The `setTimeout` for `handleSubmit` is also a minor concern.
40+
* **Proposed Solution**:
41+
* Instead of direct DOM manipulation, the `handleGitHubImport` function should call `handleInputChange` (passed as a prop from `app/page.tsx`) to update the `chatInput` state in `app/page.tsx`. This ensures React controls the input value.
42+
* Evaluate if the `setTimeout` for `handleSubmit` is strictly necessary or if the state update can reliably trigger submission.
43+
44+
**Issue 2.3.2: Redundant Floating Action Button (FAB) (app/page.tsx)**
45+
* **Problem**: The "Create New Project" FAB (`FolderPlus` icon) is rendered twice with identical logic.
46+
* **Proposed Solution**:
47+
* Remove one of the duplicate FAB rendering blocks in `app/page.tsx`.
48+
49+
**Issue 2.3.3: Command Palette `onOpenSettings` Not Implemented (app/page.tsx)**
50+
* **Problem**: The `CommandPalette`'s `onOpenSettings` prop is an empty function. The `isSettingsDialogOpen` state is unused.
51+
* **Proposed Solution**:
52+
* Implement the `onOpenSettings` callback to toggle the `isSettingsDialogOpen` state.
53+
* Connect `isSettingsDialogOpen` to the `open` prop of the `SettingsDialog` from `components/chat-sidebar/settings-dialog.tsx` (or a new main settings dialog if appropriate). This requires passing down the state and setter or using a global state/context.
54+
55+
**Issue 2.3.4: `Chat` Component's `setCurrentPreview` Prop Usage (app/page.tsx, components/chat.tsx)**
56+
* **Problem**: `currentPreview` state (a string title) in `app/page.tsx` is set by `Chat` but doesn't seem to directly control the `Preview` panel's visibility or content, which is driven by the `fragment` object.
57+
* **Proposed Solution**:
58+
* Clarify the role of `currentPreview`. If it's unused, remove it.
59+
* If it's intended for a feature (e.g., scrolling to a specific part of a preview or highlighting), implement that feature or remove the state to avoid confusion. The `onClick` in `Chat.tsx` that sets this could directly set the main `fragment` and `result` states if that's the goal.
60+
61+
### 2.4. Data Handling and Display
62+
63+
**Issue 2.4.1: `Chat` Component Image Rendering Performance (components/chat.tsx)**
64+
* **Problem**: Large base64 encoded images in messages could impact rendering performance or hit browser data URI limits.
65+
* **Proposed Solution**:
66+
* Consider client-side image resizing/compression before converting to base64 if feasible, especially for pasted images or very large uploads.
67+
* Alternatively, implement a size limit for image uploads/pastes with user feedback.
68+
* For display, ensure Next.js `Image` component's `sizes` and `quality` props are used effectively if applicable for base64.
69+
70+
**Issue 2.4.2: Hardcoded Template Fallback for `codinit-engineer` (app/page.tsx)**
71+
* **Problem**: A specific hardcoded fallback for the `codinit-engineer` template might mask a missing template in `templates.json` or indicate an undocumented special case.
72+
* **Proposed Solution**:
73+
* Verify if `codinit-engineer` should be part of `lib/templates.json`. If yes, add it.
74+
* If it's a deliberate special case, add a comment explaining why it's handled this way.
75+
* Consider a more generic fallback mechanism if a template ID is not found in `templates` data to prevent runtime errors if other templates go missing.
76+
77+
## 3. General UI/UX Enhancements
78+
79+
* **Loading States**: Review all loading states for consistency and clarity. Ensure spinners or loading indicators are present for all asynchronous operations (e.g., AI enhance, GitHub import analysis).
80+
* **Empty States**: Improve empty state displays (e.g., no chat messages, no projects in sidebar) to be more informative and visually appealing.
81+
* **Accessibility (A11y)**: While not deeply analyzed, ensure all interactive elements have proper ARIA attributes, keyboard navigation is smooth, and color contrasts meet WCAG guidelines. The existing use of `lucide-react` icons and Shadcn UI components is a good start.
82+
* **Consistency in Terminology**: Ensure terms like "Project", "Session", "Fragment" are used consistently across the UI.
83+
84+
## 4. Refactoring and Code Quality Suggestions
85+
86+
* **Shared Error Parsing**: Create a shared error parsing utility (e.g., in `lib/utils.ts` or `lib/errors.ts`) and use it across all components making API calls (e.g., `EnhancedChatInput`, `app/page.tsx` for sandbox execution).
87+
* **State Management for Sidebar Settings**: If sidebar display settings become functional, consider moving their state to the `useChatSidebarStore` (Zustand store) for easier global access and persistence.
88+
* **Environment Variable Handling**: Centralize or create helpers for accessing and parsing environment variables, especially for boolean flags, to ensure consistent interpretation.
89+
* **Review `app/page.tsx` Complexity**: This file is very large and handles a lot of state and logic. Consider opportunities for further custom hooks or component modularization if complexity grows. For instance, logic related to fragment execution and its effects could potentially be encapsulated in a custom hook.
90+
91+
## 5. High-Level Implementation Steps
92+
93+
1. **Configuration Fixes**:
94+
* Address Issue 2.1.1 (ChatSettings env vars and input clarity).
95+
* Address Issue 2.4.2 (codinit-engineer template).
96+
2. **Error Handling Improvements**:
97+
* Address Issue 2.2.1 (EnhancedChatInput error parsing).
98+
* Address Issue 2.2.2 (Consistent rate limit feedback).
99+
3. **Component Interaction & State Fixes**:
100+
* Address Issue 2.3.1 (EnhancedChatInput DOM manipulation).
101+
* Address Issue 2.3.2 (Redundant FAB).
102+
* Address Issue 2.3.3 (Command Palette settings).
103+
* Address Issue 2.1.2 (Sidebar display settings persistence and functionality - if deemed necessary).
104+
* Address Issue 2.3.4 (Chat component setCurrentPreview).
105+
4. **Data Handling/Display Improvements**:
106+
* Address Issue 2.4.1 (Chat image performance - investigate and implement if significant).
107+
5. **Code Refactoring**:
108+
* Implement shared error parsing utility.
109+
* Review and refactor other areas as identified during the fixes.
110+
6. **Testing**:
111+
* Manually test all affected areas and user flows.
112+
* Consider adding automated tests for critical functionalities if not already present.
113+
114+
## 6. Future Considerations
115+
116+
* **Optimistic Updates**: For actions like renaming chat sessions/projects or starring projects, implement optimistic updates for a smoother UX.
117+
* **WebSockets for Real-time**: For a more dynamic experience, especially if collaboration features are planned, consider WebSockets.
118+
* **Advanced Image Handling**: If image uploads are a core feature, consider dedicated image storage and serving instead of only base64 in messages, especially for larger files or more complex image manipulations.
119+
* **Comprehensive End-to-End Testing**: As the application grows, a more robust testing strategy will be crucial.
120+
121+
This plan provides a roadmap for the immediate improvements. Each item should be broken down into smaller, manageable tasks for implementation.

app/.learnings/fix_plan.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Implementation Plan: Fix Pylance Errors in `codeanalysisviewer.pyi`
2+
3+
## 1. Analyze Errors and Identify Solutions
4+
5+
The Pylance errors in `typings/gradio_codeanalysisviewer/codeanalysisviewer.pyi` stem from several issues:
6+
7+
* **Missing Type Arguments for Generics:**
8+
* `dict` is used without specifying key and value types (e.g., `dict` should be `dict[str, Any]`).
9+
* `Callable` is used without specifying argument and return types (e.g., `Callable` should be `Callable[..., Any]`).
10+
* **Undefined Names:**
11+
* `Literal`: This type hint is used but not imported. It needs to be imported from `typing`.
12+
* `Block`: This type is used in method signatures but not defined or imported. Based on Gradio's typical structure, `Block` likely refers to `gradio.blocks.Block`.
13+
* `Dependency`: This type is used as a return type but not defined or imported. This likely refers to `gradio.dependencies.Dependency`.
14+
* **String Literals as Types:**
15+
* Strings like `"full"`, `"minimal"`, `"hidden"`, `"once"`, `"multiple"`, `"always_last"`, `"default"` are used within `Literal` annotations. This is correct once `Literal` is imported.
16+
17+
## 2. Implementation Steps
18+
19+
To resolve these errors, the following changes will be made to `typings/gradio_codeanalysisviewer/codeanalysisviewer.pyi`:
20+
21+
1. **Add Imports:**
22+
* Import `Literal` from `typing`.
23+
* Import `Block` from `gradio.blocks`.
24+
* Import `Dependency` from `gradio.dependencies`.
25+
* Ensure `Any` is imported from `typing` (it already is).
26+
27+
2. **Specify Type Arguments for `dict`:**
28+
* Change `value: dict | Callable | None` to `value: dict[Any, Any] | Callable[..., Any] | None` in `__init__`. (Using `Any, Any` as a general placeholder, can be refined if more specific types are known for the dictionary's structure, but for a generic viewer, `Any` is often acceptable in stubs).
29+
* Change `payload: dict | None` to `payload: dict[Any, Any] | None` in `preprocess`.
30+
* Change `value: dict | None` to `value: dict[Any, Any] | None` in `postprocess`.
31+
* Change `cancels: dict[str, Any] | list[dict[str, Any]] | None` to `cancels: dict[str, Any] | list[dict[str, Any]] | None` (this one is already correctly typed for the dict part, but listed for completeness of review).
32+
33+
3. **Specify Type Arguments for `Callable`:**
34+
* Change `value: dict | Callable | None` to `value: dict[Any, Any] | Callable[..., Any] | None` in `__init__`.
35+
36+
4. **Address `TYPE_CHECKING` block:**
37+
* Move the new imports (`Block`, `Dependency`) into the `if TYPE_CHECKING:` block if they are only needed for type hinting and to avoid circular dependencies, which is a common practice in Gradio. `Literal` can stay at the top level.
38+
39+
## 3. Code Changes (Diff Format)
40+
41+
The following `replace_in_file` operations will be performed:
42+
43+
```diff
44+
------- SEARCH
45+
from collections.abc import Callable, Sequence
46+
from typing import Any, TYPE_CHECKING
47+
from gradio.components.base import Component, FormComponent
48+
=======
49+
from collections.abc import Callable, Sequence
50+
from typing import Any, TYPE_CHECKING, Literal
51+
from gradio.components.base import Component, FormComponent
52+
+++++++ REPLACE
53+
------- SEARCH
54+
if TYPE_CHECKING:
55+
...
56+
=======
57+
if TYPE_CHECKING:
58+
from gradio.blocks import Block
59+
from gradio.dependencies import Dependency
60+
...
61+
+++++++ REPLACE
62+
------- SEARCH
63+
def __init__(self, value: dict | Callable | None = ..., *, placeholder: str | None = ..., label: str | I18nData | None = ..., every: Timer | float | None = ..., inputs: Component | Sequence[Component] | set[Component] | None = ..., show_label: bool | None = ..., scale: int | None = ..., min_width: int = ..., interactive: bool | None = ..., visible: bool = ..., rtl: bool = ..., elem_id: str | None = ..., elem_classes: list[str] | str | None = ..., render: bool = ..., key: int | str | tuple[int | str, ...] | None = ..., preserved_by_key: list[str] | str | None = ...) -> None:
64+
=======
65+
def __init__(self, value: dict[Any, Any] | Callable[..., Any] | None = ..., *, placeholder: str | None = ..., label: str | I18nData | None = ..., every: Timer | float | None = ..., inputs: Component | Sequence[Component] | set[Component] | None = ..., show_label: bool | None = ..., scale: int | None = ..., min_width: int = ..., interactive: bool | None = ..., visible: bool = ..., rtl: bool = ..., elem_id: str | None = ..., elem_classes: list[str] | str | None = ..., render: bool = ..., key: int | str | tuple[int | str, ...] | None = ..., preserved_by_key: list[str] | str | None = ...) -> None:
66+
+++++++ REPLACE
67+
------- SEARCH
68+
def preprocess(self, payload: dict | None) -> dict | None:
69+
=======
70+
def preprocess(self, payload: dict[Any, Any] | None) -> dict[Any, Any] | None:
71+
+++++++ REPLACE
72+
------- SEARCH
73+
def postprocess(self, value: dict | None) -> dict | None:
74+
=======
75+
def postprocess(self, value: dict[Any, Any] | None) -> dict[Any, Any] | None:
76+
+++++++ REPLACE
77+
```
78+
79+
*(Note: The diff for the `change`, `input`, and `submit` methods will be extensive due to the repeated nature of `Block`, `Literal`, and `Dependency`. The key is to ensure these types are correctly imported and used. The example above shows the import changes and the first few direct type fixes. The repeated parameter lists in `change`, `input`, `submit` will be implicitly corrected by the imports of `Block`, `Literal`, and `Dependency`.)*
80+
81+
## 4. Verification
82+
83+
After applying the changes, Pylance errors should be resolved. The type stub file will be more accurate and provide better type checking for users of the `CodeAnalysisViewer` component.

0 commit comments

Comments
 (0)