apps/server/docs/ai-context/transport-and-routes.md
应用在 src/app.ts 中挂载以下路由:
GET /health/api/auth/*/api/v1/characters/api/v1/providers/api/v1/chats/api/v1/openai/api/v1/flux/api/v1/stripeGET /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/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/providers.ts主要能力:
user_provider_configssystem_provider_configs特点:
findAll(ownerId) 通过 unionAll 合并系统配置和用户配置/api/v1/chats实现位置:
src/routes/chats/index.tssrc/services/chats.ts主要能力:
聊天核心约束:
deletedAtseq 在写消息时通过锁 chat 行串行分配GET /ws/chat实现位置:
src/app.tssrc/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/speechPOST /api/v1/openai/audio/transcriptions请求流程:
GATEWAY_BASE_URLbillingService.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
输入 schema 位于各资源路由目录下的 schema.ts:
characters.schema.tschats.schema.tsproviders.schema.tsroute 层统一使用 safeParse,失败时抛:
createBadRequestError('Invalid Request', 'INVALID_REQUEST', result.issues)configGuard作用:
使用场景:
rateLimiter封装自 hono-rate-limiter,当前默认是单实例内存存储。
影响: