3e6a34297d
Squashes 25 PR commits onto current main. AppConfig becomes a pure value object with no ambient lookup. Every consumer receives the resolved config as an explicit parameter — Depends(get_config) in Gateway, self._app_config in DeerFlowClient, runtime.context.app_config in agent runs, AppConfig.from_file() at the LangGraph Server registration boundary. Phase 1 — frozen data + typed context - All config models (AppConfig, MemoryConfig, DatabaseConfig, …) become frozen=True; no sub-module globals. - AppConfig.from_file() is pure (no side-effect singleton loaders). - Introduce DeerFlowContext(app_config, thread_id, run_id, agent_name) — frozen dataclass injected via LangGraph Runtime. - Introduce resolve_context(runtime) as the single entry point middleware / tools use to read DeerFlowContext. Phase 2 — pure explicit parameter passing - Gateway: app.state.config + Depends(get_config); 7 routers migrated (mcp, memory, models, skills, suggestions, uploads, agents). - DeerFlowClient: __init__(config=...) captures config locally. - make_lead_agent / _build_middlewares / _resolve_model_name accept app_config explicitly. - RunContext.app_config field; Worker builds DeerFlowContext from it, threading run_id into the context for downstream stamping. - Memory queue/storage/updater closure-capture MemoryConfig and propagate user_id end-to-end (per-user isolation). - Sandbox/skills/community/factories/tools thread app_config. - resolve_context() rejects non-typed runtime.context. - Test suite migrated off AppConfig.current() monkey-patches. - AppConfig.current() classmethod deleted. Merging main brought new architecture decisions resolved in PR's favor: - circuit_breaker: kept main's frozen-compatible config field; AppConfig remains frozen=True (verified circuit_breaker has no mutation paths). - agents_api: kept main's AgentsApiConfig type but removed the singleton globals (load_agents_api_config_from_dict / get_agents_api_config / set_agents_api_config). 8 routes in agents.py now read via Depends(get_config). - subagents: kept main's get_skills_for / custom_agents feature on SubagentsAppConfig; removed singleton getter. registry.py now reads app_config.subagents directly. - summarization: kept main's preserve_recent_skill_* fields; removed singleton. - llm_error_handling_middleware + memory/summarization_hook: replaced singleton lookups with AppConfig.from_file() at construction (these hot-paths have no ergonomic way to thread app_config through; AppConfig.from_file is a pure load). - worker.py + thread_data_middleware.py: DeerFlowContext.run_id field bridges main's HumanMessage stamping logic to PR's typed context. Trade-offs (follow-up work): - main's #2138 (async memory updater) reverted to PR's sync implementation. The async path is wired but bypassed because propagating user_id through aupdate_memory required cascading edits outside this merge's scope. - tests/test_subagent_skills_config.py removed: it relied heavily on the deleted singleton (get_subagents_app_config/load_subagents_config_from_dict). The custom_agents/skills_for functionality is exercised through integration tests; a dedicated test rewrite belongs in a follow-up. Verification: backend test suite — 2560 passed, 4 skipped, 84 failures. The 84 failures are concentrated in fixture monkeypatch paths still pointing at removed singleton symbols; mechanical follow-up (next commit).
278 lines
10 KiB
Plaintext
278 lines
10 KiB
Plaintext
events {
|
|
worker_connections 1024;
|
|
}
|
|
pid logs/nginx.pid;
|
|
http {
|
|
# Basic settings
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout 65;
|
|
types_hash_max_size 2048;
|
|
|
|
# Logging
|
|
access_log logs/nginx-access.log;
|
|
error_log logs/nginx-error.log;
|
|
|
|
# Upstream servers (using 127.0.0.1 for local development)
|
|
upstream gateway {
|
|
server 127.0.0.1:8001;
|
|
}
|
|
|
|
upstream langgraph {
|
|
server 127.0.0.1:2024;
|
|
}
|
|
|
|
upstream frontend {
|
|
server 127.0.0.1:3000;
|
|
}
|
|
|
|
server {
|
|
listen 2026;
|
|
listen [::]:2026;
|
|
server_name _;
|
|
|
|
# Hide CORS headers from upstream to prevent duplicates
|
|
proxy_hide_header 'Access-Control-Allow-Origin';
|
|
proxy_hide_header 'Access-Control-Allow-Methods';
|
|
proxy_hide_header 'Access-Control-Allow-Headers';
|
|
proxy_hide_header 'Access-Control-Allow-Credentials';
|
|
|
|
# CORS headers for all responses (nginx handles CORS centrally)
|
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' '*' always;
|
|
|
|
# Handle OPTIONS requests (CORS preflight)
|
|
if ($request_method = 'OPTIONS') {
|
|
return 204;
|
|
}
|
|
|
|
# LangGraph API routes (served by langgraph dev)
|
|
# Rewrites /api/langgraph/* to /* before proxying to LangGraph server
|
|
location /api/langgraph/ {
|
|
rewrite ^/api/langgraph/(.*) /$1 break;
|
|
proxy_pass http://langgraph;
|
|
proxy_http_version 1.1;
|
|
|
|
# Headers
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Connection '';
|
|
|
|
# SSE/Streaming support
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
proxy_set_header X-Accel-Buffering no;
|
|
|
|
# Timeouts for long-running requests
|
|
proxy_connect_timeout 600s;
|
|
proxy_send_timeout 600s;
|
|
proxy_read_timeout 600s;
|
|
|
|
# Chunked transfer encoding
|
|
chunked_transfer_encoding on;
|
|
}
|
|
|
|
# Experimental: Gateway-backed LangGraph-compatible API
|
|
# Frontend can opt-in via NEXT_PUBLIC_LANGGRAPH_BASE_URL=/api/langgraph-compat
|
|
location /api/langgraph-compat/ {
|
|
rewrite ^/api/langgraph-compat/(.*) /api/$1 break;
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
|
|
# Headers
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Connection '';
|
|
|
|
# SSE/Streaming support
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
proxy_set_header X-Accel-Buffering no;
|
|
|
|
# Timeouts for long-running requests
|
|
proxy_connect_timeout 600s;
|
|
proxy_send_timeout 600s;
|
|
proxy_read_timeout 600s;
|
|
|
|
# Chunked transfer encoding
|
|
chunked_transfer_encoding on;
|
|
}
|
|
|
|
# Custom API: Models endpoint
|
|
location /api/models {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# Custom API: Memory endpoint
|
|
location /api/memory {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# Custom API: MCP configuration endpoint
|
|
location /api/mcp {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# Custom API: Skills configuration endpoint
|
|
location /api/skills {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# Custom API: Agents endpoint
|
|
location /api/agents {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# Custom API: Uploads endpoint
|
|
location ~ ^/api/threads/[^/]+/uploads {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
# Large file upload support
|
|
client_max_body_size 100M;
|
|
proxy_request_buffering off;
|
|
}
|
|
|
|
# Custom API: Other endpoints under /api/threads
|
|
location ~ ^/api/threads {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# API Documentation: Swagger UI
|
|
location /api/docs {
|
|
proxy_pass http://gateway/docs ;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# API Documentation: ReDoc
|
|
location /api/redoc {
|
|
proxy_pass http://gateway/redoc;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# API Documentation: OpenAPI Schema
|
|
location /openapi.json {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# Health check endpoint (gateway)
|
|
location /health {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
# Catch-all for any /api/* prefix not matched by a more specific block above.
|
|
# Covers the auth module (/api/v1/auth/login, /me, /change-password, ...),
|
|
# plus feedback / runs / token-usage routes that 2.0-rc added without
|
|
# updating this nginx config. Longest-prefix matching ensures the explicit
|
|
# blocks above (/api/models, /api/threads regex, /api/langgraph/, ...) still
|
|
# win for their paths — only truly unmatched /api/* requests land here.
|
|
location /api/ {
|
|
proxy_pass http://gateway;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
# Auth endpoints set HttpOnly cookies — make sure nginx doesn't
|
|
# strip the Set-Cookie header from upstream responses.
|
|
proxy_pass_header Set-Cookie;
|
|
}
|
|
|
|
# All other requests go to frontend
|
|
location / {
|
|
proxy_pass http://frontend;
|
|
proxy_http_version 1.1;
|
|
|
|
# Headers
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
proxy_cache_bypass $http_upgrade;
|
|
|
|
# Disable response buffering for the frontend. Without this,
|
|
# nginx tries to spool large upstream responses (e.g. Next.js
|
|
# static chunks) into ``proxy_temp_path``, which defaults to
|
|
# the system-owned ``/var/lib/nginx/proxy`` and fails with
|
|
# ``[crit] open() ... failed (13: Permission denied)`` when
|
|
# nginx is launched as a non-root user (every dev machine
|
|
# except production root containers). The symptom on the
|
|
# client side is ``ERR_INCOMPLETE_CHUNKED_ENCODING`` and
|
|
# ``ChunkLoadError`` partway through page hydration.
|
|
#
|
|
# Streaming the response straight through avoids the
|
|
# temp-file path entirely. The frontend already sets its
|
|
# own cache headers, so we don't lose anything from
|
|
# disabling nginx-side buffering.
|
|
proxy_buffering off;
|
|
proxy_request_buffering off;
|
|
|
|
# Timeouts
|
|
proxy_connect_timeout 600s;
|
|
proxy_send_timeout 600s;
|
|
proxy_read_timeout 600s;
|
|
}
|
|
}
|
|
}
|