apps/server/docs/ai-context/transport-and-routes.md
应用在 src/app.ts 中挂载以下路由:
GET /livez — K8s 风格 liveness 探针,纯静态 200,不碰任何外部依赖GET /readyz — K8s 风格 readiness 探针,并发 ping Postgres + Redis;任一失败回 503。不检查上游 LLM key 健康(R14)GET / — 服务标识 JSON,避免邮件链接拼错落到框架默认 404/api/auth/*/api/v1/characters/api/v1/providers/api/v1/chats/api/v1/openai/api/v1/flux/api/v1/stripe/api/admin/flux-grants — adminGuard 守卫,详见 admin-flux-grants.mdGET /ws/chatsessionMiddleware(auth)
better-auth 解析当前 sessionuser / session 注入 Hono contextauthGuard
c.get('user')GET /ws/chat 走 query token:
tokenauth.api.getSession() 验证 Bearer tokenuser.id 建立 Eventa peer这意味着聊天 WS 的鉴权方式和普通 cookie session 路径不完全相同。
/api/auth/* 及 /sign-in实现位置:
src/routes/auth/index.ts(通过 .route('/') 挂载到根路径)src/routes/oidc/token-auth.tssrc/routes/oidc/electron-callback.tssrc/libs/auth.tssrc/libs/request-auth.tssrc/utils/sign-in-page.ts特点:
better-auth + oauthProvider 插件/api/auth/* 有独立 IP 限流GET /api/auth/get-session、POST /api/auth/sign-out、GET /api/auth/list-sessions 由本地路由处理auth-and-oidc.md/api/v1/characters实现位置:
src/routes/characters/index.tssrc/services/domain/characters.ts主要能力:
GET /
?all=true 返回全部未删除角色GET /:idPOST /PATCH /:idDELETE /:idPOST /:id/likePOST /:id/bookmark特点:
valibot 校验ownerId === user.id/api/v1/providers实现位置:
src/routes/providers/index.tssrc/services/domain/providers.ts主要能力:
user_provider_configssystem_provider_configs特点:
findAll(ownerId) 通过 unionAll 合并系统配置和用户配置/api/v1/chats实现位置:
src/routes/chats/index.tssrc/services/domain/chats.ts主要能力:
聊天核心约束:
deletedAtseq 在写消息时通过锁 chat 行串行分配GET /ws/chat实现位置:
src/app.ts(在 bodyLimit 之前注册)src/routes/chat-ws/index.tssrc/libs/eventa-hono-adapter.ts主要 RPC:
sendMessages
chatService.pushMessages()chatService.pullMessages() 生成广播 payloadpullMessages
chatService.pullMessages()广播策略:
Map<userId, Set<EventContext>>chat:broadcast:实现约束:
JSON.parseredis-boundaries-and-pubsub.md/api/v1/openai实现位置:
src/routes/openai/v1/index.tsfluxServicebillingServiceconfigKVrequestLogService当前已开放:
POST /api/v1/openai/chat/completionsPOST /api/v1/openai/chat/completionPOST /api/v1/openai/audio/speechGET /api/v1/openai/audio/voices(按 model 缓存上游响应,TTL 600s,仅 200 入缓存)handleTranscription(STT)目前未挂载,需要时参考 /audio/speech 接入方式。
请求流程:
llmRouter.route / llmRouter.routeTts:读 LLM_ROUTER_CONFIG,按 upstream 链路 + key rotator + envelope crypto 调上游billingService.debitFlux()llm_request_log重要取舍:
/api/v1/flux实现位置:
src/routes/flux/index.tsfluxServicefluxTransactionService主要能力:
GET /api/v1/flux
GET /api/v1/flux/history
/api/v1/stripe实现位置:
src/routes/stripe/index.tsfluxServicestripeServicebillingServiceconfigKV主要能力:
GET /packagesPOST /checkoutGET /ordersGET /invoicesPOST /portalPOST /webhook主要职责拆分:
stripeService
billingService
/api/admin/flux-grants实现位置:
src/routes/admin/flux-grants/index.tssrc/services/domain/admin/flux-grants/index.tssrc/middlewares/admin-guard.ts主要能力:
POST /api/admin/flux-grants?dryRun=true|false — 同步给一组邮箱发 FLUX,请求线程内顺序调 creditFlux,返回每条 outcomeauthGuard + adminGuard(ADMIN_EMAILS allowlist + email_verified=true)admin-flux-grants.md输入 schema 位于各资源路由目录下的 schema.ts:
characters.schema.tschats.schema.tsproviders.schema.tsroute 层统一使用 safeParse,失败时抛:
createBadRequestError('Invalid Request', 'INVALID_REQUEST', result.issues)configGuard作用:
使用场景:
rateLimiter封装自 hono-rate-limiter,当前默认是单实例内存存储。
影响: