Skip to content

Commit 8bbdeda

Browse files
committed
Refactor storage to filesystem JSON
1 parent 86eb685 commit 8bbdeda

File tree

18 files changed

+1274
-1251
lines changed

18 files changed

+1274
-1251
lines changed

Dockerfile

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 25 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,47 @@
11
# TreeChat — Branching Chat UI
22

3-
https://github.com/user-attachments/assets/87ed3e76-2909-452c-bc45-37be0396bf60
4-
53
## Overview
64

75
This is a minimal React + TypeScript app that renders full branching conversation trees: user edits and assistant retries create sibling branches that are preserved and displayed side-by-side. This supports retries, user edits, selecting any leaf to continue the branch, and multi-model chats.
86

7+
![TreeChat screenshot](client/public/screenshots/feb26-exmp.png)
8+
99
## What’s inside
1010

1111
- client: Vite + React + TypeScript UI that renders a conversation tree.
1212
- server: Express + OpenAI SDK proxy endpoint streaming assistant deltas.
1313

14-
## Quickstart (Docker)
15-
16-
Prereqs: Docker Desktop (includes `docker compose`).
17-
18-
### Option A: One command (pull a prebuilt image)
19-
20-
This is the easiest UX for users: pull a prebuilt image + Postgres via Docker Compose.
21-
22-
```
23-
curl -fsSL https://raw.githubusercontent.com/yxzwayne/treechat/refs/heads/main/docker-compose.pull.yml \
24-
| docker compose -f - up -d --pull always
25-
```
26-
27-
Then open http://localhost:8787
28-
29-
Defaults: the container starts with `USE_MOCK=1` (no API key required).
30-
31-
If port 8787 is busy, pick another host port:
32-
33-
```
34-
curl -fsSL https://raw.githubusercontent.com/yxzwayne/treechat/refs/heads/main/docker-compose.pull.yml \
35-
| HOST_PORT=8788 docker compose -f - up -d --pull always
36-
```
37-
38-
Finch equivalent (download first):
14+
## Quickstart (local)
3915

40-
```
41-
curl -fsSL https://raw.githubusercontent.com/yxzwayne/treechat/refs/heads/main/docker-compose.pull.yml -o /tmp/treechat.pull.yml
42-
HOST_PORT=8787 finch compose -f /tmp/treechat.pull.yml up -d
43-
```
44-
45-
To shut it down:
46-
47-
```
48-
curl -fsSL https://raw.githubusercontent.com/yxzwayne/treechat/refs/heads/main/docker-compose.pull.yml -o /tmp/treechat.pull.yml
49-
docker compose -f /tmp/treechat.pull.yml down
50-
finch compose -f /tmp/treechat.pull.yml down
51-
```
16+
Prereqs: Node.js 18+. Release and electron-ification is coming.
5217

53-
To run with real model calls, pass `USE_MOCK=0` and an API key to `docker compose`:
18+
Data is stored on disk at `~/.treechat/data` by default (override with `TREECHAT_DATA_DIR`).
5419

20+
1) Clone + install
5521
```
56-
curl -fsSL https://raw.githubusercontent.com/yxzwayne/treechat/refs/heads/main/docker-compose.pull.yml \
57-
| USE_MOCK=0 OPENROUTER_API_KEY=... docker compose -f - up -d --pull always
22+
git clone https://github.com/yxzwayne/treechat.git
23+
cd treechat
24+
cd client && npm ci
25+
cd ../server && npm ci
26+
cd ..
5827
```
5928

60-
Finch equivalent:
29+
2) Run (dev)
30+
- Terminal A: `cd server && npm run dev` (API on http://localhost:8787)
31+
- Terminal B: `cd client && npm run dev` (UI on http://localhost:5173)
6132

62-
```
63-
USE_MOCK=0 OPENROUTER_API_KEY=... finch compose -f /tmp/treechat.pull.yml up -d
64-
```
33+
3) Open the UI
34+
- http://localhost:5173
6535

66-
### Option B: Local (build from source)
36+
Notes:
37+
- By default, the server runs in mock mode when no API key is configured.
38+
- To use real models, add an API key in `server/.env` (see `docs/CONFIG.md`).
6739

68-
From this repo:
40+
## Next steps
6941

70-
- `docker compose up --build`
71-
- `finch compose up --build` (Finch)
72-
- open http://localhost:8787
73-
74-
See `docs/DOCKER.md`.
75-
76-
## Developer setup (no Docker)
77-
78-
1) Install deps
79-
- client: `cd client && npm ci`
80-
- server: `cd server && npm ci`
81-
82-
2) Configure env
83-
- In `server/.env` set `OPENROUTER_API_KEY=your_key`
84-
- Optional: set `USE_MOCK=1` to run without network
85-
86-
3) Run (two terminals)
87-
- server: `cd server && npm run dev` (default port 8787)
88-
- client: `cd client && npm run dev` (Vite dev server on 5173; proxied to the server)
89-
90-
4) Tests
91-
- client: `cd client && npm test`
42+
- Single-process mode (serve the built UI from the server): see `docs/BUILD.md`.
43+
- Env / storage configuration (including `USE_MOCK=1`): see `docs/CONFIG.md`.
44+
- Tests: `cd client && npm test`.
9245

9346
## Using the app
9447

@@ -132,7 +85,5 @@ Notes
13285

13386

13487
# TODO
135-
136-
- Image/file support: Allow uploading and rendering images/files in messages, and forwarding them to the model when supported. Include persistence in Postgres (blob storage path or presigned URL), display thumbnails, and drag-and-drop paste handling on the Composer.
137-
- ⚠️ when user edits a message, provide the option to "override current branch" and clearly notify them that this is a "delete plus create" operation
138-
- **New workflow, automatic conversation summary from the first user message**: this should be a separate workflow that runs like lambda on hardware with access to client, server and database. this workflow is triggered by a user sending the first message in a new conversation. This workflow has a system prompt instructing the model to summarize the following content and appends the user's first prompt. ask the summary to be under 10 words or characters if it's not a Latin language.
88+
- Image/file support: Allow uploading and rendering images/files in messages, and forwarding them to the model when supported. Include persistence in the filesystem store, display thumbnails, and drag-and-drop paste handling on the Composer.
89+
- New workflow, automatic conversation summary from the first user message: a separate async workflow triggered by a user sending the first message in a new conversation, instructing the model to summarize the first message to be under x words or characters if it's not a Latin language.
1.55 MB
Loading

docker-compose.pull.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

docker-compose.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

docs/BUILD.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ Run both in separate terminals:
1919
- `cd server && npm run build && npm start`
2020
- `cd client && npm run build && npm run preview`
2121

22+
To run the built UI from the server (single process):
23+
24+
- `cd client && npm run build`
25+
- `cd server && npm run build && SERVE_CLIENT=1 npm start`
26+
2227
Notes:
2328
- Use a recent Node.js (the server uses `fetch`; Node 18+ is a safe baseline).

docs/CONFIG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
# Configuration (Env + DB)
1+
# Configuration (Env + Storage)
22

33
The server loads environment variables via `dotenv` (put secrets in `server/.env`, which is gitignored).
44

55
Common variables:
66

7-
- `DATABASE_URL` (defaults to `postgres://localhost:5432/treechat`)
7+
- `TREECHAT_DATA_DIR` (defaults to `~/.treechat/data`)
88
- `OPENROUTER_API_KEY` (preferred) or `OPENAI_API_KEY`
99
- `OPENROUTER_BASE_URL` (defaults to OpenRouter)
1010
- `OPENROUTER_SITE_URL`, `OPENROUTER_APP_NAME` (attribution headers)
1111
- `USE_MOCK=1` (run without network; stream a local mock response)
1212
- `PORT` (defaults to `8787`)
1313

14+
Notes:
15+
- If `USE_MOCK` is unset and no API key is configured, the server defaults to mock mode.
16+
1417
OpenRouter troubleshooting:
1518
- If you see `404: No allowed providers are available for the selected model`, your OpenRouter API key is usually restricted to an allowlist of providers that doesn't include any provider serving that model.
1619

17-
Database notes:
18-
- Server bootstraps schema on startup and requires `pgcrypto` (for `gen_random_uuid()`); ensure your Postgres role can `CREATE EXTENSION` or install it ahead of time.
20+
Migration (optional):
21+
- If you have an existing Postgres-backed TreeChat database, you can export it into the filesystem store with `cd server && DATABASE_URL=... npm run migrate:pg-to-file`.
22+
- If the destination data dir already exists, pass force via `cd server && DATABASE_URL=... npm run migrate:pg-to-file -- --force`.

docs/DOCKER.md

Lines changed: 0 additions & 62 deletions
This file was deleted.

server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"dev": "tsx watch src/index.ts",
88
"start": "node dist/index.js",
9-
"build": "tsc -b"
9+
"build": "tsc -b",
10+
"migrate:pg-to-file": "tsx src/scripts/migrate-pg-to-file.ts"
1011
},
1112
"dependencies": {
1213
"cors": "^2.8.5",

0 commit comments

Comments
 (0)