Conversation
P0 基础设施:
- shared 包新增 TypeBox schemas(tasks/tts/ai/focus/hooks/knowledge/errors)
- 新增 typed error 层级(HttpError + BadRequest/NotFound/Unauthorized/Forbidden/Stale/ServiceUnavailable)
- app.ts 接入 setErrorHandler,统一错误响应为 { error, code?, details? }
- 所有路由用手写 if 校验改为 schema + typed error,清理 as Type 断言
- WsMessage 新增 tts:error / server:shutdown 类型
P1-A 安全与健壮性:
- 接入 @fastify/helmet(禁用 CSP/HSTS,sidecar 只吐 JSON)
- 接入 @fastify/rate-limit(200 req/min,IP 维度)
- 显式 bodyLimit 1MB
- SIGINT/SIGTERM 优雅退出:app.close() → exit 0
- WsHub.close() 广播 server:shutdown 并关闭所有 WS(1001)
P1-B WebSocket 加固:
- WsHub 重写:30s 心跳 ping/pong,无响应连接 terminate
- 背压保护:bufferedAmount > 1MB 跳过,连续 5 次丢弃则 terminate
- WS 路由:消息大小限制 64KB(超限 close 1009)
- 每连接 token bucket 频率限制 30 msg/s(超限 close 1008)
P1-C 业务增强:
- Tasks 分页:list({limit,offset}) 返回 {items,total},前端 listTasks 适配
- Weather in-memory 缓存(TTL 10min,NEO_WEATHER_CACHE_TTL_MS 可配)
- TTS 失败广播 tts:error(路由 try/catch + focus 自动播报失败)
验证:typecheck 全绿;server-local 53/53、db 20/20、ai 8/8、tts 1/1 测试通过。
|
Important Fenno AI is not enabled for this organization Fenno AI is currently in internal testing and is not yet open for external organizations. If you would like to request access, sign in to Fenno AI Console, choose Give Feedback in the lower-left corner, and tell us what you need. We will follow up promptly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
本 PR 继续后端基础设施整理:将数据库层迁移到 Node 24 的
node:sqlite,补齐 server-local 路由校验、安全边界和错误处理,并修复知识库/embedding 相关问题。主要变更
better-sqlite3/Drizzle 迁移到node:sqlite,新增手写 row types,并更新 schema 初始化、查询映射和测试。/api/tasks响应改为{ items, total },desktop API 端保持调用方仍拿到Task[]。NULL语义,以及 embedding 配置避免回写明文 API key。验证
git diff --check origin/main...HEADpnpm typecheckpnpm --filter @neo-companion/db testpnpm --filter @neo-companion/server-local testpnpm --filter @neo-companion/shared testCI Check:包含pnpm typecheck、pnpm test、./scripts/verify-docs.shCI Build:Windows、macOS、Ubuntu备注
>=24.0.0,因为数据库层使用node:sqlite。pnpm test可能因 markdown fixture 被 checkout 为 CRLF 而复现 3 个 byte-for-byte 换行失败;GitHub CI 使用 LF checkout,当前 PR 的 CI 已全绿。