Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8812e3f
refactor: integrate model selection into `ChatHeader` and simplify st…
qduc Aug 27, 2025
3e0301b
refactor: update MessageList layout and editing controls
qduc Aug 27, 2025
5ecc022
feat: add database migration support and enhance conversation persist…
qduc Aug 27, 2025
ef17087
refactor: remove legacy Chat and ChatContext components, integrate Ch…
qduc Aug 27, 2025
5ea07f3
feat: apply and persist conversation-level settings from API response
qduc Aug 27, 2025
91c48bd
feat: add entrypoint scripts for npm dependency installation and stre…
qduc Aug 28, 2025
2b95051
feat: restrict reasoning controls to gpt-5 models
qduc Aug 28, 2025
5d33115
feat: add RightSidebar for system prompt input and session-level stat…
qduc Aug 28, 2025
6aa0972
feat: enhance OpenAI proxy and orchestrators with improved streaming …
qduc Aug 28, 2025
0f58ab7
refactor: centralize OpenAI request handling and streamline proxy logic
qduc Aug 28, 2025
958b912
refactor: modularize OpenAI proxy with helper functions for validatio…
qduc Aug 28, 2025
e042f9a
fix: improve session cookie security and add conditional header check
qduc Aug 28, 2025
37535cb
Add modular chat API components with backward compatibility
qduc Aug 30, 2025
e9a2e3e
Refactor chat functionality and migrate to modular APIs with enhanced…
qduc Aug 30, 2025
d46971d
Mock chat library for iterative orchestration tests and update tests …
qduc Aug 30, 2025
a42b6d5
Improve chat state management for tool calls and content synchronization
qduc Aug 30, 2025
56a59cc
cleanup unused files
qduc Aug 28, 2025
edfc77f
feat: add multi-provider support and enhance compatibility layers
qduc Aug 30, 2025
1ad954c
feat: add settings modal and toggle in ChatV2
qduc Aug 30, 2025
cb0e7ac
feat: add providers configuration table and migrations
qduc Aug 30, 2025
dd7d17a
feat: add provider management support and enhance settings UI
qduc Aug 30, 2025
e788b71
feat: make migration idempotent for conversations table
qduc Aug 30, 2025
c4ce321
refactor: simplify `SettingsModal` and improve UI organization
qduc Aug 30, 2025
4203e05
feat: add `TabbedSelect` component and provider-based model selection
qduc Aug 30, 2025
94cf620
Add `getProviderByIdWithApiKey` for retrieving provider details with …
qduc Aug 30, 2025
6a8e5c7
Add `ModelSelector` component and integrate it into `ChatHeader`
qduc Aug 30, 2025
c225704
Remove `researchMode` functionality and integrate provider selection …
qduc Aug 30, 2025
17fb65b
Sync conversation state with URL and initialize from query parameters
qduc Aug 30, 2025
94e4cd8
Remove legacy settings and add provider connection test functionality
qduc Aug 30, 2025
70832c9
Refactor `Toggle` component and add quick toggle functionality in pro…
qduc Aug 30, 2025
677cc7c
Refine UI styling for consistency and readability
qduc Aug 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ next-env.d.ts

# logs
logs/
/requests/http-client.private.env.json
65 changes: 45 additions & 20 deletions AI_ONBOARDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Goal: Make minimal, correct changes that improve the app while preserving OpenAI

1) Project Snapshot
- Name: ChatForge (full‑stack AI chat)
- Frontend: Next.js + React (TypeScript)
- Backend: Node.js (Express, ESM) acting as an OpenAI‑compatible proxy
- Streaming: End‑to‑end SSE for chat responses
- Status: MVP complete; testing infrastructure in place; conversation persistence in development
- Frontend: Next.js 15 + React 19 (TypeScript) with enhanced UI components
- Backend: Node.js (Express, ESM) acting as an OpenAI‑compatible proxy with tool orchestration
- Streaming: End‑to‑end SSE for chat responses with tool events and thinking support
- Status: MVP complete; tool orchestration system complete; testing infrastructure in place; conversation persistence in development

2) Core Principles
- Keep diffs small, focused, and documented.
Expand All @@ -18,8 +18,11 @@ Goal: Make minimal, correct changes that improve the app while preserving OpenAI
- Update docs when changing behavior (README.md, docs/*).

3) Repository Map
- frontend/: Next.js app (app/, components/, lib/)
- frontend/: Next.js app (app/, components/, lib/, hooks/, contexts/)
- backend/: Express proxy (src/routes/, src/lib/, src/db/)
- src/lib/tools.js: Server-side tool registry and execution
- src/lib/unifiedToolOrchestrator.js: Unified tool orchestration system
- src/lib/iterativeOrchestrator.js: Iterative workflows with thinking support
- docs/: Overview/specs/progress/security
- docker-compose*.yml, dev.sh: Dev orchestration

Expand All @@ -31,7 +34,7 @@ Option B: Docker Production
- docker compose -f docker-compose.yml up --build (frontend on 3000)
Option C: Docker Development (with hot reload)
- docker compose -f docker-compose.dev.yml up --build (frontend on 3000)
Note: Dev compose includes hot reload and development dependencies.
Note: Dev compose includes hot reload and development dependencies with Turbopack for faster iteration.

5) Environment/Secrets
- backend/.env requires OPENAI_API_KEY (or provider‑compatible key)
Expand All @@ -40,55 +43,77 @@ Note: Dev compose includes hot reload and development dependencies.
6) API Contract (must preserve)
- POST /v1/responses → primary endpoint with conversation continuity support
- POST /v1/chat/completions → OpenAI‑compatible endpoint for compatibility
- Supports text/event-stream (SSE) for streaming tokens
- Supports text/event-stream (SSE) for streaming tokens and tool events
- Backend injects Authorization header from server env
- Do not break request/response JSON shape or streaming semantics
- Responses API includes `previous_response_id` for conversation linking
- Tool support: tools array enables server-side tool execution with iterative workflows
- Research mode: `research_mode: true` enables multi-step tool orchestration with thinking

7) Streaming Expectations
- Frontend consumes SSE and renders partial chunks progressively
- Backend must flush tokens promptly; no buffering of full responses
- Abort support: requests should be cancellable
- Tool events: streaming includes tool_calls, tool_output events for real-time feedback
- Thinking support: iterative orchestration streams AI reasoning between tool calls

8) Rate Limiting & Safety
- In‑memory per‑IP rate limit in backend (keep or improve without regressions)
- Avoid noisy logs and PII; follow docs/SECURITY.md guidance

9) Coding Standards
9) Tool Orchestration System (Major Feature)
- **Server-side tools**: Available tools defined in backend/src/lib/tools.js (get_time, web_search)
- **Unified orchestrator**: unifiedToolOrchestrator.js automatically adapts streaming/non-streaming
- **Iterative mode**: iterativeOrchestrator.js supports thinking between tool calls (up to 10 iterations)
- **Tool execution**: Tools execute server-side with proper error handling and timeouts
- **Streaming events**: Real-time tool_calls and tool_output events for UI feedback
- **Research mode**: When enabled, AI can use tools multiple times with reasoning between calls
- **Tool adding**: Add new tools with Zod validation schemas; they're automatically available
- **Persistence integration**: Tool results are properly stored in conversation history

10) Coding Standards
- Use TypeScript/ESM defaults already present
- Follow existing ESLint/Prettier configuration (backend and frontend configured)
- Run linting: `npm --prefix backend run lint` and `npm --prefix frontend run lint`
- Prefer small pure functions; handle errors and edge cases explicitly
- Maintain strong typing at API boundaries
- Tool development: Add tools to backend/src/lib/tools.js with proper validation schemas

10) Tests
11) Tests
- Comprehensive Jest testing infrastructure for both backend and frontend
- Tests located under package‑local __tests__/ directories
- Run tests: `npm --prefix backend test` and `npm --prefix frontend test`
- Ensure existing behavior remains green; all tests must pass
- Tool orchestration tests: iterative_orchestration.test.js, unified_tool_system.test.ts
- Frontend integration tests for enhanced UI components and chat state management

11) Performance & UX
12) Performance & UX
- Preserve fast first token time; avoid unnecessary awaits in hot paths
- Keep UI responsive during streams; don’t block the main thread
- Keep UI responsive during streams; don't block the main thread
- Tool orchestration: up to 10 iterations with smart timeout management (30s per request)
- Quality controls: UI includes quality slider (quick/balanced/thorough) for response control
- Enhanced components: floating UI positioning with @floating-ui/react for dropdowns

12) Making Changes
13) Making Changes
- Seek the smallest viable fix; avoid broad API surface changes
- If API surface must change, keep OpenAI compatibility and update docs
- Add comments near non‑obvious logic; update README/docs links as needed

13) Useful Docs
14) Useful Docs
- docs/OVERVIEW.md (architecture with current tech stack)
- docs/API-SPECS.md (both Responses API and Chat Completions API)
- docs/CONVERSATIONS-SPEC.md (conversation persistence specification)
- docs/PROGRESS.md (development progress and completed features)
- docs/TECH-STACK.md (current dependencies and infrastructure)
- docs/API-SPECS.md (both Responses API and Chat Completions API with tool support)
- docs/PROGRESS.md (development progress and completed features including tool orchestration)
- docs/TECH-STACK.md (current dependencies and infrastructure including Next.js 15, React 19)
- docs/SECURITY.md (security considerations and environment setup)
- README.md (quick start, build, and testing)
- README.md (quick start, build, testing, and tool development)
- backend/src/lib/tools.js (server-side tool registry and examples)

14) Definition of Done (for AI agents)
15) Definition of Done (for AI agents)
- Requirement satisfied with minimal diff
- Streaming and API compatibility intact
- Streaming and API compatibility intact (including tool events)
- No secrets leaked; local/dev still runs per README
- Relevant docs updated when behavior changes
- Tool orchestration behavior preserved when modifying tool-related code
- Enhanced UI components maintain accessibility and responsive design

Welcome aboard. Optimize for correctness, compatibility, and small, reviewable changes.
10 changes: 10 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## Provider selection (default: openai)
PROVIDER=openai

## Generic provider config (falls back to OpenAI values)
# PROVIDER_BASE_URL=
# PROVIDER_API_KEY=
# PROVIDER_HEADERS_JSON={"X-Custom":"Value"}

## OpenAI-compatible defaults (kept for backward-compat)
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_API_KEY=sk-xxxxx

DEFAULT_MODEL=gpt-4.1-mini
TITLE_MODEL=gpt-4.1-mini
PORT=3001
Expand Down
4 changes: 3 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ FROM node:20-slim AS dev
WORKDIR /app
ENV NODE_ENV=development
COPY package*.json ./
RUN npm install
# Copy source for dev (mounted again via volume in compose)
COPY src ./src
COPY .env.example ./
COPY entrypoint.sh ./
RUN chmod +x entrypoint.sh
EXPOSE 3001
ENTRYPOINT ["./entrypoint.sh"]
CMD ["npm", "run", "dev"]

# --- Prod stage: lean runtime image (default/final) ---
Expand Down
8 changes: 4 additions & 4 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Backend

Express-based proxy for OpenAI-compatible chat completions.
Express-based proxy for OpenAI-compatible chat completions, with pluggable providers.

## Endpoints

- `POST /v1/chat/completions` – proxies to `OPENAI_BASE_URL/chat/completions` (supports streaming)
- `POST /v1/chat/completions` – proxies to `${PROVIDER_BASE_URL||OPENAI_BASE_URL}/v1/chat/completions` (supports streaming)
- `POST /v1/conversations` – create a conversation (feature-flagged)
- `GET /v1/conversations/:id` – fetch conversation metadata (feature-flagged)
- `GET /healthz` – health/status info

## Env Vars (.env)

See `.env.example` for required variables.
See `.env.example` for required variables. You can select a provider via `PROVIDER` (default: `openai`). Generic keys `PROVIDER_BASE_URL`, `PROVIDER_API_KEY`, and optional `PROVIDER_HEADERS_JSON` are supported; OpenAI-specific vars remain for backward compatibility.

Additional (Sprint 1):

Expand Down Expand Up @@ -50,7 +50,7 @@ This reduces database write load and avoids timer-based flushes while preserving
1. Create env file (not copied into image):
```bash
cp .env.example .env
# edit OPENAI_API_KEY etc.
# edit PROVIDER/OPENAI variables as needed
```
2. Build & run (from repo root):
```bash
Expand Down
9 changes: 9 additions & 0 deletions backend/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

# Install dependencies
echo "Installing npm dependencies..."
npm install

# Execute the original command
exec "$@"
65 changes: 65 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"start": "NODE_ENV=production node src/index.js",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"lint": "eslint .",
"format": "prettier --write ."
"format": "prettier --write .",
"migrate": "node scripts/migrate.js"
},
"dependencies": {
"@blackglory/better-sqlite3-migrations": "^0.1.20",
"better-sqlite3": "^9.4.3",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
Expand Down
Loading
Loading