Skip to content

Commit b6ce732

Browse files
committed
Merge latest main: resolve conflicts while preserving Ollama support
This merge brings the branch up to date with latest main branch changes. All conflicts resolved by accepting upstream improvements. Ollama/LocalAI customizations remain intact in settings.tsx and llm_client.py.
2 parents c51e918 + 6ee0d28 commit b6ce732

29 files changed

+2916
-1908
lines changed

.env.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ EMBEDDING_API_KEY=
6262
# API authentication key (for production deployments)
6363
# CONTEXT_API_KEY=your-secure-api-key
6464

65+
# ============================================
66+
# Web Server (Backend) Configuration
67+
# Used by both backend (FastAPI/Uvicorn) and frontend (via Vite env)
68+
# ============================================
69+
70+
# Host to bind the backend web server
71+
WEB_HOST=127.0.0.1
72+
73+
# Port to bind the backend web server (frontend will default to this port in dev)
74+
WEB_PORT=8000
75+
76+
# Note: Frontend reads Vite-prefixed vars. electron-vite is configured to map WEB_HOST/WEB_PORT
77+
# into VITE_WEB_HOST/VITE_WEB_PORT automatically. Do NOT duplicate values.
78+
6579
# ============================================
6680
# Example Configurations
6781
# ============================================

.gitignore

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ __pycache__
55
/screenshots
66
/logs
77
/persist
8-
/debug
98
/dist/*
109
/venv/*
1110
/test_storage
1211
/config/runtime
1312
/test_script
14-
/config/user*
13+
/config/user_setting.yaml
14+
/config/config.yaml
1515
.DS_Store
1616

1717
.venv/
1818
uv.lock
19-
uv.toml
20-
.idea
19+
20+
# Environment variables
21+
.env
22+
.env.local
23+
24+
⚙️ work_phases/
25+
🗄️ archive/
26+
🧠 knowledge_base/

alembic.ini

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Alembic configuration file
2+
[alembic]
3+
script_location = opencontext/db/migrations
4+
sqlalchemy.url = sqlite:///./persist/sqlite/app.db
5+
6+
[loggers]
7+
keys = root,sqlalchemy,alembic
8+
9+
[handlers]
10+
keys = console
11+
12+
[formatters]
13+
keys = generic
14+
15+
[logger_root]
16+
level = WARN
17+
handlers = console
18+
19+
[logger_sqlalchemy]
20+
level = WARN
21+
handlers =
22+
qualname = sqlalchemy.engine
23+
24+
[logger_alembic]
25+
level = INFO
26+
handlers =
27+
qualname = alembic
28+
29+
[handler_console]
30+
class = StreamHandler
31+
args = (sys.stderr,)
32+
level = NOTSET
33+
formatter = generic
34+
35+
[formatter_generic]
36+
format = %(levelname)-5.5s [%(name)s] %(message)s

docs/ENV_CONFIGURATION.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ The application will automatically load variables from `.env`!
7272
| `EMBEDDING_API_KEY` | Embedding API key | Same as `LLM_API_KEY` |
7373
| `CONTEXT_PATH` | Data storage path | `.` (current directory) |
7474
| `CONTEXT_API_KEY` | API authentication key | `test` |
75+
| `WEB_HOST` | Backend web server host | `127.0.0.1` |
76+
| `WEB_PORT` | Backend web server port | `8000` |
7577

7678
## Configuration Examples
7779

@@ -88,6 +90,10 @@ EMBEDDING_PROVIDER=ollama
8890
EMBEDDING_MODEL=nomic-embed-text
8991
EMBEDDING_BASE_URL=http://localhost:11434/v1
9092
EMBEDDING_API_KEY=
93+
94+
# Backend web server (frontend will consume this too)
95+
WEB_HOST=127.0.0.1
96+
WEB_PORT=8000
9197
```
9298

9399
**Setup:**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Title: Unify backend configuration via .env (WEB_HOST/WEB_PORT) and share with frontend
2+
3+
Date: 2025-10-19
4+
Author: Droid (Factory AI)
5+
6+
Summary
7+
- Introduce `.env`-driven backend configuration for host/port so both backend and frontend stay aligned without manual edits.
8+
9+
Scope
10+
- Backend (FastAPI/Uvicorn): read `WEB_HOST`/`WEB_PORT` from the root `.env` (overridden by CLI args).
11+
- Frontend (Electron + Vite): load root `.env` and expose them as `VITE_WEB_HOST`/`VITE_WEB_PORT`; default axios baseURL uses these values.
12+
13+
Implementation
14+
- Backend: `opencontext/cli.py` now respects `WEB_HOST`/`WEB_PORT` if provided (priority: CLI args > ENV > config defaults).
15+
- Frontend build config: set `envDir: '..'` and `define` Vite vars to map from `process.env.WEB_HOST/WEB_PORT`.
16+
- Frontend axios: default baseURL built from `VITE_WEB_HOST`/`VITE_WEB_PORT`, still supports runtime override via IPC `backend:get-port`.
17+
- Docs: Updated `.env.example` and `docs/ENV_CONFIGURATION.md` to include `WEB_HOST`/`WEB_PORT`.
18+
19+
How to Use
20+
1) Copy example and edit:
21+
cp .env.example .env
22+
2) Set values:
23+
WEB_HOST=127.0.0.1
24+
WEB_PORT=8000
25+
3) Start dev:
26+
./start-dev.sh
27+
28+
Notes
29+
- In packaged app the backend may choose an available port at runtime; the renderer still updates via IPC, so the defaults only affect initial baseURL in dev.
30+
- This change does not alter security posture; the existing `.env` load applies.
31+
32+
PR: <to be added>

frontend/electron.vite.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export default defineConfig({
4545
}
4646
},
4747
renderer: {
48+
// Point envDir to repo root so renderer can read root .env
49+
envDir: '..',
4850
resolve: {
4951
alias: {
5052
'@renderer': resolve('src/renderer/src'),
@@ -78,7 +80,12 @@ export default defineConfig({
7880
}),
7981
...(isDev ? [CodeInspectorPlugin({ bundler: 'vite' })] : []), // 只在开发环境下启用 CodeInspectorPlugin
8082
...visualizerPlugin('renderer')
81-
]
83+
],
84+
// Map WEB_HOST/WEB_PORT from process.env into Vite runtime vars
85+
define: {
86+
'import.meta.env.VITE_WEB_HOST': JSON.stringify(process.env.WEB_HOST || '127.0.0.1'),
87+
'import.meta.env.VITE_WEB_PORT': JSON.stringify(process.env.WEB_PORT || '8000')
88+
}
8289
// server: {
8390
// proxy: {
8491
// // 代理Express服务 (AI Chat)

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,6 @@
144144
"electron",
145145
"esbuild"
146146
]
147-
}
147+
},
148+
"packageManager": "pnpm@10.13.1+sha512.37ebf1a5c7a30d5fabe0c5df44ee8da4c965ca0c5af3dbab28c3a1681b70a256218d05c81c9c0dcf767ef6b8551eb5b960042b9ed4300c59242336377e01cfad"
148149
}

0 commit comments

Comments
 (0)