[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-107655":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":18,"fork":18,"defaultBranch":19,"hasWiki":18,"hasPages":18,"topics":20,"createdAt":9,"pushedAt":21,"updatedAt":22,"readmeContent":23,"aiSummary":24,"trendingCount":15,"starSnapshotCount":15,"syncStatus":25,"lastSyncTime":26,"discoverSource":27},107655,"RoutePilot","Wayfinder-one\u002FRoutePilot","Wayfinder-one","Smart routing, seamless flow",null,"Python",112,10,1,7,0,40,44.12,false,"main",[],"2026-11-22 11:59:39","2026-11-10 01:28:15","# RoutePilot\n\nRoutePilot is an OpenAI-compatible routing proxy for LLM traffic. Every request runs through a versioned decision graph made of request conditions, decision-service questions, logic gates, and model targets. The same graph is edited, validated, dry-run, and published in the built-in console.\n\nEnglish | [简体中文](README.zh-CN.md)\n\n![RoutePilot decision canvas](assets\u002Froutepilot\u002Fen\u002Frouting-canvas.png)\n\n## Highlights\n\n- **Visual routing policy.** Build branching policies on a canvas instead of writing if\u002Felse chains. Nodes, wires, conditions, validation, layout, undo\u002Fredo, and graph import\u002Fexport are all first-class.\n- **OpenAI-compatible entry point.** `POST \u002Fv1\u002Fchat\u002Fcompletions` supports JSON and SSE streaming, with the selected model returned in response headers.\n- **Decision-service driven.** Choice, yes\u002Fno, and score questions are batched per wave and sent to a `systemone`-compatible decision service. Answers activate downstream questions, gates, and targets.\n- **Deterministic target selection.** Activated targets compete by priority; the largest number wins. Both a normal empty result and a failed decision wave use the single fallback model, `error_fallback`.\n- **Sticky sessions and load balancing.** Reuse a model per tree revision and target, then pick a backend with `least_inflight`. Failed backends are removed by a circuit breaker.\n- **Dry-run before publishing.** `\u002Fadmin\u002Ftry` runs the same graph executor with the same trace format without touching affinity, in-flight counts, or upstream generation models.\n- **Operations built in.** Request ledger, decision replay, confidence distribution, model\u002Fprovider catalog, JEV settings, time periods, config revisions, audit history, and role-based users.\n- **Bilingual console.** Chinese and English UI, with admin and viewer roles.\n\n## How a request is routed\n\n```mermaid\nflowchart LR\n  C[Client] --> V[\"\u002Fv1\u002Fchat\u002Fcompletions\"]\n  V --> G[Graph executor]\n  G \u003C--> J[\"Decision service \u002Fv1\u002Fsystemone\"]\n  G --> T[\"Target selection\u003Cbr\u002F>priority · fallback\"]\n  T --> A[Session affinity]\n  A --> L[\"least_inflight\u003Cbr\u002F>+ circuit breaker\"]\n  L --> U[Upstream model]\n  G -. trace .-> R[(Request ledger)]\n```\n\n1. Load the immutable routing snapshot and evaluate request conditions (time period \u002F text keywords).\n2. Activate the first wave of questions. All questions in one wave are merged into one decision-service call.\n3. Update numeric ports and `selected` ports, then re-evaluate every downstream slot condition and logic gate.\n4. Repeat wave by wave until no new question is activated.\n5. Choose the highest-priority active target. If none activated, or if a decision call failed, use the fallback model `error_fallback`.\n6. Apply session affinity, select a backend with `least_inflight`, and proxy the request upstream. Failures open the circuit breaker for that model.\n\n`unknown` never activates a question or target. Numeric comparisons with an unknown value stay unknown.\n\n## Console\n\n![Overview](assets\u002Froutepilot\u002Fen\u002Foverview.png)\n\nThe console is the control plane for the router:\n\n- **Overview** — request volume, route distribution, JEV confidence, sticky hits, active decision group.\n- **Decision groups** — canvas editor, graph settings, node\u002Fedge inspector, validation, dry-run, import\u002Fexport.\n- **Calc Log** — recent decisions with model, target, candidates, waves, JEV probabilities, reasoning, upstream outcome, and a replayable trace.\n- **JEV Model** — decision-service endpoint, model, prompt\u002Fstate template, connection test, context and input-token window.\n- **Models & Settings** — model registry, upstream model ids, providers, reasoning declarations, capability notes.\n- **Users** — admin\u002Fviewer accounts, password changes, role and status management.\n\n### Canvas\n\n![Decision canvas](assets\u002Froutepilot\u002Fen\u002Frouting-canvas.png)\n\n- Drag nodes from the library, pan\u002Fzoom, auto-layout, undo\u002Fredo.\n- Draw typed wires; numeric outputs create a default condition when dropped into a boolean slot.\n- Every input slot is an OR input with its own edge condition.\n- Drag an output to empty canvas to quick-create a compatible node.\n- Save and enable are separate; dirty and layout-only states are visible.\n- Target cards show the target display name, model list, fallback roles, and scheduling strategy.\n\n### Dry-run replay\n\n![Dry-run replay](assets\u002Froutepilot\u002Fen\u002Ftry-run.png)\n\nDry-run highlights the winning path wave by wave, shows candidates and priorities, and exposes the full trace. It uses the same executor as production routing but does not consume affinity, in-flight capacity, or an upstream model call.\n\n### Decision log\n\n![Calculation log](assets\u002Froutepilot\u002Fen\u002Flogs.png)\n\nEach expanded row shows the calculation process directly in stages: input preparation, initial computation, per-round JEV, candidates & final pick, model scheduling, and the execution result; every slot and technical detail expands on demand instead of cluttering the default view. A routing failure (`routing_error`) keeps the partial process up to that point: a schedule-stage failure (e.g. an open breaker) keeps the scheduling snapshot — configured, registered, available, unavailable reasons and pre-selection inflight — with sticky shown as not checked when it was never consulted; a failed JEV wave voids that round's candidates and falls to the error-fallback target. Legacy records without a scheduling snapshot and restored ledger rows after a restart state plainly that the detail is absent rather than fabricating it. SQLite still stores only the ledger fields — no request text, trace, per-round answers, or node labels; the page reads the last 20 live records from an in-process ring, so calculation detail is replica-local: there is no cross-replica log aggregation and no long-term trace persistence.\n\n## Decision graph\n\n### Nodes\n\n| Type | Purpose | Inputs | Outputs |\n|---|---|---|---|\n| `start` | Request entry; always true | — | boolean |\n| `question` | Decision-service question: `choice`, `noul`, or `score` | Boolean slots `in_1..in_n` (OR) | choice: `prob.*`, `selected.*`, `p_top`, `margin`; noul: `yes`, `no`; score: `value` |\n| `logic` | Three-valued logic gate: `and`, `or`, `not` | Boolean slots `in_1..in_n`, one edge + condition per slot | boolean |\n| `condition` | Request condition: time period or text keywords | — | boolean |\n| `target` | Model target: models, reasoning tiers, priority, strategy | Boolean slots `in_1..in_n` (OR) | — |\n\n### Conditions\n\nConditions live on edges, not on nodes:\n\n```json\n{\n  \"id\": \"e-cap-strong-and-power\",\n  \"source\": \"capability\",\n  \"source_port\": \"prob.strong\",\n  \"target\": \"and-power\",\n  \"target_port\": \"in_1\",\n  \"condition\": { \"op\": \"gt\", \"value\": 0.65 }\n}\n```\n\n| Upstream output | Condition | Evaluation |\n|---|---|---|\n| number | `gt` \u002F `gte` \u002F `lt` \u002F `lte` \u002F `eq` \u002F `neq` + finite threshold | Compare values; unknown propagates as unknown |\n| boolean | `null` (same as `= true`) or `{ \"op\": \"is\", \"value\": true \\| false }` | Boolean expectation |\n\n- One output can feed multiple slots; each slot has its own condition.\n- Two slots of an AND gate can express a range such as `> 0.3` and `\u003C 0.8`.\n- Each input slot accepts at most one edge. Slot numbers stay stable; deleted slots can be reused.\n- `not` has exactly one slot. `and` \u002F `or` require at least two. Question and target slots are OR.\n\n### Execution rules\n\n- Questions are executed in waves; one wave = one decision-service call.\n- A failed wave voids the whole round: no ports are filled and all candidates from that round are discarded.\n- Target priorities must be unique. **Larger number wins.**\n- `error_fallback` is used when execution completes normally with zero active targets.\n- The same `error_fallback` is used when a decision call fails, times out, or returns an invalid answer.\n- The fallback model must point to an existing target.\n\n### Limits\n\n| Item | Limit |\n|---|---:|\n| Nodes | 200 |\n| Edges | 400 |\n| Question nodes | 32 |\n| Longest question chain | 8 waves |\n| Options per choice question | 255 |\n| Score criteria | 2–10 finite values |\n\n### Graph document\n\nThe canvas imports and exports a single JSON envelope:\n\n```json\n{\n  \"kind\": \"sr-routing-graph\",\n  \"version\": 3,\n  \"name\": \"Default routing\",\n  \"timezone\": \"Asia\u002FShanghai\",\n  \"sticky\": { \"enabled\": true, \"ttl_seconds\": 1800 },\n  \"root\": {\n    \"id\": \"root\",\n    \"type\": \"graph\",\n    \"error_fallback\": \"safe-target\",\n    \"nodes\": [],\n    \"edges\": []\n  }\n}\n```\n\n## Models and reasoning\n\nThe model registry maps a **model slot** used by the graph to an **upstream model id** and a provider. A target can hold several model slots; `least_inflight` picks among them.\n\n![Models and settings](assets\u002Froutepilot\u002Fen\u002Fmodels.png)\n\nProviders define the OpenAI-compatible base URL, API-key environment variable, and reasoning dialect. Model profiles can declare:\n\n- reasoning support and a default level;\n- a map from RoutePilot levels (`off`, `on`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`) to provider-specific wire values;\n- capability notes and catalog metadata.\n\nSupported reasoning dialects include OpenAI, DeepSeek, Qwen, Qwen chat template, OpenRouter, Z.ai, Together, string-thinking, and Ant Ling. If a requested level is not supported, the request is sent without reasoning injection and the response carries `x-sr-reasoning-warning`.\n\n## Decision service (JEV)\n\n![JEV model settings](assets\u002Froutepilot\u002Fen\u002Fjev.png)\n\nThe decision service exposes `POST \u002Fv1\u002Fsystemone` and is typically served by NeoHorse \u002F vLLM. Configure it in the console:\n\n- base URL, model name, API key, timeout;\n- default instructions and state template (must contain `{request}`);\n- connection test with two fixed candidates;\n- service context budget and input truncation limit. Oversized input is truncated head\u002Ftail instead of returning a 4xx\u002F5xx.\n\nEnvironment variables can seed the decision-service config on first start only; the database remains the source of truth afterward.\n\n## Access and operations\n\n- Email\u002Fpassword login with scrypt password hashing and opaque bearer sessions.\n- `admin` can edit graphs, models, JEV settings, users, and settings. `viewer` is read-only and cannot manage users.\n- The last active admin cannot be demoted, disabled, or deleted.\n- Every user and configuration change is recorded in the audit log.\n- Each graph file is content-addressed by SHA-256 for save conflicts and reload checks; graph history is not retained.\n- Control-plane state (models, providers, users, logs, settings) is SQLite (WAL); routing graphs live in shared JSON files. Request logs are flushed asynchronously and also kept in a 20-entry in-memory ring for the live UI; startup hydrates the ring from the persisted tail. Legacy `otherwise_target` in old graph files is read as the unified fallback and is normalized to `error_fallback` on save.\n- Session affinity and in-flight counts remain process-local. Multiple router replicas can share graph files, but cross-replica session\u002Fin-flight consistency requires an external shared state layer.\n\n## Shared graph storage and replicas\n\nDecision graphs are not stored in SQLite. Each group is one v3 export document at\n`ROUTER_GRAPH_DIR\u002Fgraphs\u002F{tree_id}.json`; `ROUTER_GRAPH_DIR\u002Fcurrent` contains only the enabled group id.\nThe admin API has a single writer. Other replicas run with `ROUTER_GRAPH_WRITER=false`, mount the same\ndirectory read-only, and poll every 2 seconds. A replica builds a candidate snapshot before replacing its\nin-memory snapshot; if a file is invalid, the previous snapshot keeps serving and `\u002Freadyz` reports stale.\n\n- Kubernetes: use a ReadWriteMany PVC; do not share SQLite on NFS\u002FRWX.\n- Docker: mount the same NFS export into every container. Keep SQLite on local storage for the writer.\n- Graph files and `current` are created through atomic temporary files with mode `0600`. Every writer\u002Freader container must use the same numeric UID (10001 is an example; deployments may use another shared UID). Matching only the GID or `fsGroup` cannot grant access to mode-`0600` files; replicas with different UIDs are unsupported.\n- Set the same `runAsUser`\u002F`runAsGroup` in both Kubernetes pod `securityContext`s and the same `--user UID:GID` for Docker containers. The shared directory and `graphs` subdirectory must be traversable by that UID; only the writer needs create\u002Freplace access, while readers mount the same directory read-only.\n- Writes are atomic. A stale save returns 409 `graph_conflict`; imports only change the draft. There is no graph version history or rollback.\n- `\u002Fhealthz` is the liveness probe. `\u002Freadyz` reports whether this replica has an initial snapshot; 503 means not ready. After a later reload failure, an existing snapshot continues serving with `\"stale\": true`.\n- Migration: back up first, then run `python scripts\u002Fexport_sqlite_graphs.py --db router.db --out routing-graph`. The output directory must not exist. Normal startup never deletes old SQLite graphs; clean them only after explicit confirmation.\n\n## Quick start\n\n```bash\npython3.11 -m venv .venv\n.venv\u002Fbin\u002Fpip install -r requirements.txt\n\n# Local development: authentication disabled\nROUTER_DB=\u002Ftmp\u002Froutepilot.db \\\nROUTER_GRAPH_DIR=\u002Ftmp\u002Froutepilot-graph \\\nROUTER_USER_AUTH=0 \\\n.venv\u002Fbin\u002Fpython -m router\n```\n\nOpen `http:\u002F\u002F127.0.0.1:8400\u002Fconsole\u002F`. The API root redirects there.\n\nFor a protected deployment:\n\n```bash\nROUTER_DB=\u002Fvar\u002Flib\u002Froutepilot\u002Frouter.db \\\nROUTER_GRAPH_DIR=\u002Fvar\u002Flib\u002Froutepilot\u002Fgraph \\\nROUTER_HOST=0.0.0.0 \\\nROUTER_PORT=8400 \\\nROUTER_ADMIN_EMAIL=admin@example.com \\\nROUTER_ADMIN_PASSWORD='change-me-now' \\\n.venv\u002Fbin\u002Fpython -m router\n```\n\nThe first start against an empty users table seeds the admin account. Change the password after signing in.\n\n## Configuration\n\n| Variable | Default | Purpose |\n|---|---|---|\n| `ROUTER_DB` | `router.db` | SQLite control-plane database path |\n| `ROUTER_GRAPH_DIR` | `.\u002Frouting-graph` | Shared directory for graph files and the enabled pointer |\n| `ROUTER_GRAPH_WRITER` | `true` | Allow this instance to write graph files; run exactly one writer |\n| `ROUTER_HOST` | `127.0.0.1` | Listener host |\n| `ROUTER_PORT` | `8400` | Listener port |\n| `ROUTER_JEV_URL` | empty | Decision-service base URL; seeds the database on first start |\n| `ROUTER_JEV_MODEL` | empty | Decision-service model; must be set with `ROUTER_JEV_URL` |\n| `ROUTER_JEV_API_KEY` | empty | Optional decision-service key |\n| `ROUTER_JEV_TIMEOUT` | `10` | Decision-service timeout, seconds |\n| `ROUTER_SESSION_MAX_ENTRIES` | `10000` | Session-affinity LRU capacity |\n| `ROUTER_USER_AUTH` | `true` | Enable console authentication |\n| `ROUTER_ADMIN_EMAIL` | `admin@test.com` | First-run admin email |\n| `ROUTER_ADMIN_PASSWORD` | seed value | First-run admin password; set this explicitly before the first start |\n| `ROUTER_SESSION_TTL_HOURS` | `168` | Console session lifetime |\n\n## API\n\n| Method and path | Purpose |\n|---|---|\n| `POST \u002Fv1\u002Fchat\u002Fcompletions` | OpenAI-compatible routing entry; JSON or SSE |\n| `GET \u002Fhealthz` | Liveness probe |\n| `GET \u002Freadyz` | Initial-snapshot readiness; 503 until this replica has one |\n| `POST \u002Fadmin\u002Flogin` \u002F `POST \u002Fadmin\u002Flogout` | Console session |\n| `GET \u002Fadmin\u002Fme` \u002F `POST \u002Fadmin\u002Fme\u002Fpassword` | Current user and self-service password change |\n| `GET\u002FPOST \u002Fadmin\u002Ftrees`, `GET\u002FPUT\u002FDELETE \u002Fadmin\u002Ftrees\u002F{id}` | Decision-group CRUD |\n| `POST \u002Fadmin\u002Ftrees\u002F{id}\u002Fcopy`, `\u002Fenable`, `\u002Fdisable` | Decision-group lifecycle |\n| `POST \u002Fadmin\u002Ftry` | Dry-run against a draft graph |\n| `GET\u002FPOST \u002Fadmin\u002Fmodels`, `GET\u002FPUT\u002FDELETE \u002Fadmin\u002Fmodels\u002F{id}` | Model registry |\n| `GET \u002Fadmin\u002Fmodel-catalog`, `POST \u002Fadmin\u002Ffetch-models` | Provider presets and upstream model discovery |\n| `GET \u002Fadmin\u002Fproviders`, `PUT\u002FDELETE \u002Fadmin\u002Fproviders\u002F{name}` | Provider configuration |\n| `GET\u002FPUT \u002Fadmin\u002Fjev`, `POST \u002Fadmin\u002Fjev\u002Ftest` | Decision-service settings |\n| `GET\u002FPUT \u002Fadmin\u002Fjev\u002Fwindow` | JEV context and input-token window |\n| `GET\u002FPUT \u002Fadmin\u002Ftime-periods` | Named time periods |\n| `GET \u002Fadmin\u002Frequests\u002Frecent`, `GET \u002Fadmin\u002Frequests\u002Fstats` | Live request ring and logger stats |\n| `GET \u002Fadmin\u002Foverview`, `GET \u002Fadmin\u002Fchanges`, `GET\u002FPUT \u002Fadmin\u002Fsettings` | Overview, audit history, settings |\n| `GET\u002FPOST \u002Fadmin\u002Fusers`, `PUT\u002FDELETE \u002Fadmin\u002Fusers\u002F{id}`, `POST \u002Fadmin\u002Fusers\u002F{id}\u002Fpassword` | User management |\n\n### Errors\n\n| Status | Error | Meaning |\n|---|---|---|\n| 400 | `invalid_json` \u002F `body_must_be_object` \u002F `messages_must_be_list` | Malformed request body |\n| 413 | `request_too_large` | Body exceeds 10 MiB |\n| 502 | `upstream_error` | Upstream 5xx or network failure |\n| 409 | `graph_conflict` | The graph changed after this draft was loaded; reload and reconcile |\n| 409 | `graph_already_exists` | A graph id is already in use |\n| 503 | `graph_read_only` | This replica is a reader; enable writes on the single writer |\n| 503 | `graph_storage_error` | Shared graph storage could not be read |\n| 503 | `no_valid_snapshot` | This replica has no initial snapshot yet |\n| 503 | `no_active_tree` | No enabled decision group |\n| 503 | `no_available_backend` | All backends for the chosen target are unavailable |\n| 503 | `routing_failed` \u002F `routing_invariant_violation` | Internal routing failure |\n\nUpstream 4xx responses are passed through with their status and body.\n\n## Tests\n\n```bash\n.venv\u002Fbin\u002Fpython -m pytest tests\u002F -q\n```\n\n```bash\nnpm install\nnpm run check:console\n```\n\n`check:console` runs the graph contract tests and the Playwright acceptance matrix against a temporary database, mock decision service, and mock upstream. It needs no running server and makes no external requests. Set `CHROME=\u002Fpath\u002Fto\u002Fchrome` if Chromium is not found in the usual cache.\n\n## Project layout\n\n```\nrouter\u002F\n  api\u002F                 FastAPI app, admin\u002Fv1 routes, upstream proxy, request logger\n  routing\u002F\n    graph\u002F             graph model, validation, executor, ports\n    affinity.py        session affinity\n    scheduler.py       least_inflight load balancer and leases\n    snapshot.py        immutable routing snapshots\n  jev\u002F                 decision-service client, config, input window\n  store\u002F               SQLite schema\u002Frepositories and the shared graph-file repository\n  console\u002F             static bilingual console\nconfigs\u002F               example decision groups and demo cases\ntests\u002F                 pytest suite\nscripts\u002F               graph contract tests and Playwright QA\nassets\u002Froutepilot\u002F     README screenshots\n```\n\n---\n\n© 2026 Sandlake. All rights reserved.\n","RoutePilot 是一个兼容 OpenAI API 的 LLM 流量智能路由代理。它通过版本化、可视化的决策图（含条件判断、决策服务调用、逻辑门与模型目标）实现请求的动态分发；支持多波次批量决策服务调用、基于优先级的目标选择、会话粘性与带熔断机制的负载均衡；提供内置控制台，支持策略编辑、验证、灰度试运行与全链路可观测性。适用于需要精细化管控大模型调用路径、统一接入多供应商模型、实施A\u002FB测试或灰度发布的 AI 中台、企业级 LLM 网关和 MLOps 编排场景。",2,"2026-11-24 04:32:32","CREATED_QUERY"]