feat(proxy): T-P0 代理层骨架(包结构/DDL/门控挂载/单进程校验)

- gateway/proxy/ 十文件:config(ProxyConfig:元->毫元加载期换算 D-P1、差异化售价、
  桶/峰谷/限流/semcache 配置)/ errors(8 类 HTTP 语义异常)/ ledger(四表两索引 DDL,
  WAL,ReviewQueue 连接纪律)/ auth·pricing·normalizer·semcache·upstream(§6 签名占位)
  / routes(/proxy/v1/models OpenAI 形状)/ __init__(build_proxy_router 组装点)
- settings DEFAULTS 增 proxy 段(enabled 默认 False,D-P7)
- api.py 首次 include_router(enabled 门控 + 装配失败不拖垮主应用)
- serve.py workers>1 拒绝启动(D-P9:WEB_CONCURRENCY/UVICORN_WORKERS 校验)
- 测试 +4(门控 404/DDL 幂等/毫元换算/池模型列表),全量 322 passed
This commit is contained in:
tzt
2026-09-05 08:35:31 +08:00
parent 3cc9851623
commit b109576707
15 changed files with 580 additions and 1 deletions
+20
View File
@@ -48,6 +48,26 @@ DEFAULTS: Dict[str, Any] = {
"approval_policy": "dangerous", # 审批策略:off | dangerous(写/编辑/命令询问)| all
"approval_timeout_s": 120, # 审批等待超时(超时自动拒绝)
},
# 校园 AI 代理层(T-P0;结构见《实施方案_代理层与缓存层.md》§4)
"proxy": {
"enabled": False, # D-P7:默认关,开启需显式配置(重启生效)
"admin_key": "", # 管理面密钥;空 = 仅 loopback 放行
"db_path": "data/proxy.sqlite3",
"buckets": { # 桶配置(嵌套对象原样存储)
"default": {"system_template": "你是校园学习助手。",
"doc_prefix_file": None, "doc_version": 1, "ttl_hours": 72},
},
"pricing": { # 元/1M tokens(加载期转毫元整数,D-P1)
"deepseek-chat": {"in_miss": 3.0, "in_hit": 0.1, "out": 9.0},
"peak_window": {"start": "08:30", "end": "23:59"},
"offpeak_factor": 0.5,
"sale_discount": {"in": 0.5, "out": 0.8}, # 差异化(设计文档 §2.5
},
"limits": {"rpm_per_key": 10, "day_req_cap": 200,
"concurrent_per_key": 2, "max_body_chars": 60000},
"semcache": {"enabled": True, "sim_threshold": 0.92,
"max_entries": 300000, "promote_frequency": 5},
},
}