dialog-survey 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +242 -0
  3. package/VERSION +1 -0
  4. package/dist/api/admin-templates.d.ts +15 -0
  5. package/dist/api/admin-templates.d.ts.map +1 -0
  6. package/dist/api/admin-templates.js +611 -0
  7. package/dist/api/admin-templates.js.map +1 -0
  8. package/dist/api/analysis.d.ts +8 -0
  9. package/dist/api/analysis.d.ts.map +1 -0
  10. package/dist/api/analysis.js +106 -0
  11. package/dist/api/analysis.js.map +1 -0
  12. package/dist/api/health.d.ts +6 -0
  13. package/dist/api/health.d.ts.map +1 -0
  14. package/dist/api/health.js +116 -0
  15. package/dist/api/health.js.map +1 -0
  16. package/dist/api/plans.d.ts +3 -0
  17. package/dist/api/plans.d.ts.map +1 -0
  18. package/dist/api/plans.js +184 -0
  19. package/dist/api/plans.js.map +1 -0
  20. package/dist/api/templates.d.ts +9 -0
  21. package/dist/api/templates.d.ts.map +1 -0
  22. package/dist/api/templates.js +211 -0
  23. package/dist/api/templates.js.map +1 -0
  24. package/dist/core/graph.d.ts +7 -0
  25. package/dist/core/graph.d.ts.map +1 -0
  26. package/dist/core/graph.js +31 -0
  27. package/dist/core/graph.js.map +1 -0
  28. package/dist/core/nodes/analyzing.d.ts +3 -0
  29. package/dist/core/nodes/analyzing.d.ts.map +1 -0
  30. package/dist/core/nodes/analyzing.js +38 -0
  31. package/dist/core/nodes/analyzing.js.map +1 -0
  32. package/dist/core/nodes/completed.d.ts +3 -0
  33. package/dist/core/nodes/completed.d.ts.map +1 -0
  34. package/dist/core/nodes/completed.js +8 -0
  35. package/dist/core/nodes/completed.js.map +1 -0
  36. package/dist/core/nodes/interviewing.d.ts +13 -0
  37. package/dist/core/nodes/interviewing.d.ts.map +1 -0
  38. package/dist/core/nodes/interviewing.js +130 -0
  39. package/dist/core/nodes/interviewing.js.map +1 -0
  40. package/dist/core/nodes/planning.d.ts +15 -0
  41. package/dist/core/nodes/planning.d.ts.map +1 -0
  42. package/dist/core/nodes/planning.js +40 -0
  43. package/dist/core/nodes/planning.js.map +1 -0
  44. package/dist/core/types/index.d.ts +69 -0
  45. package/dist/core/types/index.d.ts.map +1 -0
  46. package/dist/core/types/index.js +49 -0
  47. package/dist/core/types/index.js.map +1 -0
  48. package/dist/domains/interview/entities/interview.entity.d.ts +21 -0
  49. package/dist/domains/interview/entities/interview.entity.d.ts.map +1 -0
  50. package/dist/domains/interview/entities/interview.entity.js +20 -0
  51. package/dist/domains/interview/entities/interview.entity.js.map +1 -0
  52. package/dist/domains/interview/entities/message.entity.d.ts +15 -0
  53. package/dist/domains/interview/entities/message.entity.d.ts.map +1 -0
  54. package/dist/domains/interview/entities/message.entity.js +11 -0
  55. package/dist/domains/interview/entities/message.entity.js.map +1 -0
  56. package/dist/domains/interview/entities/response.entity.d.ts +17 -0
  57. package/dist/domains/interview/entities/response.entity.d.ts.map +1 -0
  58. package/dist/domains/interview/entities/response.entity.js +12 -0
  59. package/dist/domains/interview/entities/response.entity.js.map +1 -0
  60. package/dist/domains/interview/services/interview.domain.d.ts +8 -0
  61. package/dist/domains/interview/services/interview.domain.d.ts.map +1 -0
  62. package/dist/domains/interview/services/interview.domain.js +30 -0
  63. package/dist/domains/interview/services/interview.domain.js.map +1 -0
  64. package/dist/integrations/dingtalk/client.d.ts +32 -0
  65. package/dist/integrations/dingtalk/client.d.ts.map +1 -0
  66. package/dist/integrations/dingtalk/client.js +89 -0
  67. package/dist/integrations/dingtalk/client.js.map +1 -0
  68. package/dist/integrations/dingtalk/message-sender.d.ts +24 -0
  69. package/dist/integrations/dingtalk/message-sender.d.ts.map +1 -0
  70. package/dist/integrations/dingtalk/message-sender.js +81 -0
  71. package/dist/integrations/dingtalk/message-sender.js.map +1 -0
  72. package/dist/integrations/dingtalk/middleware.d.ts +4 -0
  73. package/dist/integrations/dingtalk/middleware.d.ts.map +1 -0
  74. package/dist/integrations/dingtalk/middleware.js +29 -0
  75. package/dist/integrations/dingtalk/middleware.js.map +1 -0
  76. package/dist/integrations/dingtalk/stream-client.d.ts +112 -0
  77. package/dist/integrations/dingtalk/stream-client.d.ts.map +1 -0
  78. package/dist/integrations/dingtalk/stream-client.js +305 -0
  79. package/dist/integrations/dingtalk/stream-client.js.map +1 -0
  80. package/dist/integrations/dingtalk/token-manager.d.ts +22 -0
  81. package/dist/integrations/dingtalk/token-manager.d.ts.map +1 -0
  82. package/dist/integrations/dingtalk/token-manager.js +109 -0
  83. package/dist/integrations/dingtalk/token-manager.js.map +1 -0
  84. package/dist/integrations/llm/alibaba.d.ts +10 -0
  85. package/dist/integrations/llm/alibaba.d.ts.map +1 -0
  86. package/dist/integrations/llm/alibaba.js +60 -0
  87. package/dist/integrations/llm/alibaba.js.map +1 -0
  88. package/dist/integrations/llm/base.d.ts +28 -0
  89. package/dist/integrations/llm/base.d.ts.map +1 -0
  90. package/dist/integrations/llm/base.js +2 -0
  91. package/dist/integrations/llm/base.js.map +1 -0
  92. package/dist/integrations/llm/volcengine.d.ts +12 -0
  93. package/dist/integrations/llm/volcengine.d.ts.map +1 -0
  94. package/dist/integrations/llm/volcengine.js +80 -0
  95. package/dist/integrations/llm/volcengine.js.map +1 -0
  96. package/dist/middleware/admin-auth.d.ts +3 -0
  97. package/dist/middleware/admin-auth.d.ts.map +1 -0
  98. package/dist/middleware/admin-auth.js +37 -0
  99. package/dist/middleware/admin-auth.js.map +1 -0
  100. package/dist/middleware/api-auth.d.ts +10 -0
  101. package/dist/middleware/api-auth.d.ts.map +1 -0
  102. package/dist/middleware/api-auth.js +30 -0
  103. package/dist/middleware/api-auth.js.map +1 -0
  104. package/dist/repositories/interview-state-mapper.d.ts +28 -0
  105. package/dist/repositories/interview-state-mapper.d.ts.map +1 -0
  106. package/dist/repositories/interview-state-mapper.js +32 -0
  107. package/dist/repositories/interview-state-mapper.js.map +1 -0
  108. package/dist/repositories/interview-state.repository.d.ts +34 -0
  109. package/dist/repositories/interview-state.repository.d.ts.map +1 -0
  110. package/dist/repositories/interview-state.repository.js +220 -0
  111. package/dist/repositories/interview-state.repository.js.map +1 -0
  112. package/dist/repositories/interview.repository.d.ts +29 -0
  113. package/dist/repositories/interview.repository.d.ts.map +1 -0
  114. package/dist/repositories/interview.repository.js +36 -0
  115. package/dist/repositories/interview.repository.js.map +1 -0
  116. package/dist/repositories/message.repository.d.ts +17 -0
  117. package/dist/repositories/message.repository.d.ts.map +1 -0
  118. package/dist/repositories/message.repository.js +37 -0
  119. package/dist/repositories/message.repository.js.map +1 -0
  120. package/dist/repositories/template.repository.d.ts +117 -0
  121. package/dist/repositories/template.repository.d.ts.map +1 -0
  122. package/dist/repositories/template.repository.js +280 -0
  123. package/dist/repositories/template.repository.js.map +1 -0
  124. package/dist/schemas/dimensions.d.ts +61 -0
  125. package/dist/schemas/dimensions.d.ts.map +1 -0
  126. package/dist/schemas/dimensions.js +44 -0
  127. package/dist/schemas/dimensions.js.map +1 -0
  128. package/dist/server.d.ts +10 -0
  129. package/dist/server.d.ts.map +1 -0
  130. package/dist/server.js +217 -0
  131. package/dist/server.js.map +1 -0
  132. package/dist/services/analysis.service.d.ts +81 -0
  133. package/dist/services/analysis.service.d.ts.map +1 -0
  134. package/dist/services/analysis.service.js +229 -0
  135. package/dist/services/analysis.service.js.map +1 -0
  136. package/dist/services/analytics.service.d.ts +44 -0
  137. package/dist/services/analytics.service.d.ts.map +1 -0
  138. package/dist/services/analytics.service.js +222 -0
  139. package/dist/services/analytics.service.js.map +1 -0
  140. package/dist/services/asr.service.d.ts +9 -0
  141. package/dist/services/asr.service.d.ts.map +1 -0
  142. package/dist/services/asr.service.js +41 -0
  143. package/dist/services/asr.service.js.map +1 -0
  144. package/dist/services/audit-cleanup.service.d.ts +9 -0
  145. package/dist/services/audit-cleanup.service.d.ts.map +1 -0
  146. package/dist/services/audit-cleanup.service.js +27 -0
  147. package/dist/services/audit-cleanup.service.js.map +1 -0
  148. package/dist/services/batch-aggregation.service.d.ts +34 -0
  149. package/dist/services/batch-aggregation.service.d.ts.map +1 -0
  150. package/dist/services/batch-aggregation.service.js +91 -0
  151. package/dist/services/batch-aggregation.service.js.map +1 -0
  152. package/dist/services/conversation-engine.d.ts +16 -0
  153. package/dist/services/conversation-engine.d.ts.map +1 -0
  154. package/dist/services/conversation-engine.js +49 -0
  155. package/dist/services/conversation-engine.js.map +1 -0
  156. package/dist/services/dead-letter.service.d.ts +12 -0
  157. package/dist/services/dead-letter.service.d.ts.map +1 -0
  158. package/dist/services/dead-letter.service.js +24 -0
  159. package/dist/services/dead-letter.service.js.map +1 -0
  160. package/dist/services/followup.service.d.ts +18 -0
  161. package/dist/services/followup.service.d.ts.map +1 -0
  162. package/dist/services/followup.service.js +146 -0
  163. package/dist/services/followup.service.js.map +1 -0
  164. package/dist/services/interview-plan-base.service.d.ts +226 -0
  165. package/dist/services/interview-plan-base.service.d.ts.map +1 -0
  166. package/dist/services/interview-plan-base.service.js +217 -0
  167. package/dist/services/interview-plan-base.service.js.map +1 -0
  168. package/dist/services/interview-plan-members.service.d.ts +45 -0
  169. package/dist/services/interview-plan-members.service.d.ts.map +1 -0
  170. package/dist/services/interview-plan-members.service.js +237 -0
  171. package/dist/services/interview-plan-members.service.js.map +1 -0
  172. package/dist/services/interview-plan-send.service.d.ts +27 -0
  173. package/dist/services/interview-plan-send.service.d.ts.map +1 -0
  174. package/dist/services/interview-plan-send.service.js +250 -0
  175. package/dist/services/interview-plan-send.service.js.map +1 -0
  176. package/dist/services/interview-plan.service.d.ts +8 -0
  177. package/dist/services/interview-plan.service.d.ts.map +1 -0
  178. package/dist/services/interview-plan.service.js +8 -0
  179. package/dist/services/interview-plan.service.js.map +1 -0
  180. package/dist/services/llm-clustering.d.ts +16 -0
  181. package/dist/services/llm-clustering.d.ts.map +1 -0
  182. package/dist/services/llm-clustering.js +91 -0
  183. package/dist/services/llm-clustering.js.map +1 -0
  184. package/dist/services/prompt.service.d.ts +13 -0
  185. package/dist/services/prompt.service.d.ts.map +1 -0
  186. package/dist/services/prompt.service.js +151 -0
  187. package/dist/services/prompt.service.js.map +1 -0
  188. package/dist/services/report.service.d.ts +28 -0
  189. package/dist/services/report.service.d.ts.map +1 -0
  190. package/dist/services/report.service.js +169 -0
  191. package/dist/services/report.service.js.map +1 -0
  192. package/dist/services/stream-message-utils.d.ts +31 -0
  193. package/dist/services/stream-message-utils.d.ts.map +1 -0
  194. package/dist/services/stream-message-utils.js +80 -0
  195. package/dist/services/stream-message-utils.js.map +1 -0
  196. package/dist/services/stream-message.service.d.ts +29 -0
  197. package/dist/services/stream-message.service.d.ts.map +1 -0
  198. package/dist/services/stream-message.service.js +184 -0
  199. package/dist/services/stream-message.service.js.map +1 -0
  200. package/dist/services/template-dimension.service.d.ts +21 -0
  201. package/dist/services/template-dimension.service.d.ts.map +1 -0
  202. package/dist/services/template-dimension.service.js +9 -0
  203. package/dist/services/template-dimension.service.js.map +1 -0
  204. package/dist/utils/db.d.ts +10 -0
  205. package/dist/utils/db.d.ts.map +1 -0
  206. package/dist/utils/db.js +21 -0
  207. package/dist/utils/db.js.map +1 -0
  208. package/dist/utils/logger.d.ts +8 -0
  209. package/dist/utils/logger.d.ts.map +1 -0
  210. package/dist/utils/logger.js +21 -0
  211. package/dist/utils/logger.js.map +1 -0
  212. package/dist/utils/markdown.d.ts +2 -0
  213. package/dist/utils/markdown.d.ts.map +1 -0
  214. package/dist/utils/markdown.js +39 -0
  215. package/dist/utils/markdown.js.map +1 -0
  216. package/dist/utils/pii-anonymizer.d.ts +2 -0
  217. package/dist/utils/pii-anonymizer.d.ts.map +1 -0
  218. package/dist/utils/pii-anonymizer.js +13 -0
  219. package/dist/utils/pii-anonymizer.js.map +1 -0
  220. package/dist/utils/retry.d.ts +8 -0
  221. package/dist/utils/retry.d.ts.map +1 -0
  222. package/dist/utils/retry.js +28 -0
  223. package/dist/utils/retry.js.map +1 -0
  224. package/dist/utils/security.d.ts +26 -0
  225. package/dist/utils/security.d.ts.map +1 -0
  226. package/dist/utils/security.js +99 -0
  227. package/dist/utils/security.js.map +1 -0
  228. package/package.json +80 -0
  229. package/prisma/schema.prisma +228 -0
  230. package/public/css/admin.css +73 -0
  231. package/public/js/alpine.min.js +2670 -0
  232. package/public/js/htmx.min.js +3422 -0
  233. package/scripts/cli.mjs +794 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,95 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.1.0] - 2026-06-16
9
+
10
+ ### Added
11
+ - **CLI for npx-based install**: `npx dialog-survey install/uninstall/start/stop/status/help` — zero external dependencies, interactive + non-interactive modes, PM2 integration, health check polling
12
+ - **npm publish pipeline**: `.npmignore` + GitHub Actions workflow for automated publishing on `v*` tags
13
+ - **25 CLI unit tests**: parseArgs, config generation, prerequisite checks, command routing
14
+
15
+ ### Changed
16
+ - **Project renamed**: `interview-bot` → `dialog-survey` (npm package name, PM2 app name, Docker container names, all references)
17
+ - **Version bump**: 1.0.4 → 1.1.0
18
+
19
+ ### Fixed
20
+ - **Windows CJK path ESM entry check**: `pathToFileURL(normalize(process.argv[1])).href` comparison — fixes server startup failure on Windows with Chinese characters in path — **Fixes #59-5**
21
+ - **System DATABASE_URL overrides .env**: `dotenv.config({ override: process.env.NODE_ENV !== 'test' })` — conditional override preserves test isolation via `vi.stubEnv()` — **Fixes #59-2**
22
+ - **Prisma generate file lock**: deploy.sh now stops service BEFORE `npm ci` to prevent DLL lock — **Fixes #59-3**
23
+ - **Windows colon filenames**: `.delphi/` added to `.gitignore`, removed from git tracking — **Fixes #59-1**
24
+ - **npm audit vulnerabilities**: all dependencies updated, 0 vulnerabilities — **Fixes #59-4**
25
+
26
+ ### Quality
27
+ - 9 atomic commits on `sprint/2026-06-16-01`
28
+ - Code walkthrough review: APPROVED (2 blocking issues caught and fixed)
29
+ - Test-specification alignment: 91.3% (21/23 acceptance criteria fully covered)
30
+ - Quality gates: 8-10/10 across all commits
31
+ - 622 unit tests pass (95 integration tests blocked by PostgreSQL env — not code regression)
32
+
33
+ ## [1.0.4] - 2026-06-16
34
+
35
+ ### Added
36
+ - Phone member support: add members via phone number, auto-resolve to DingTalk userId — **Closes #54**
37
+ - DingTalk `getUserIdByMobile()` API client with token caching and PII masking (`138****1234`)
38
+ - Docker deployment: multi-stage Dockerfile + docker-compose.yml (PG16 + app) — **Closes #53**
39
+ - 12 phone-specific tests + 7 dingtalk mobile lookup tests
40
+
41
+ ### Quality
42
+ - Pre-commit hook: Score 10.0/10, all 9 gates passed
43
+ - Full regression: 73 files / 750 tests pass, `tsc --noEmit` clean
44
+
45
+ ## [1.0.3] - 2026-06-15
46
+
47
+ ### Fixed
48
+ - Fix lint errors: remove redundant type annotation in `audit-cleanup.service.ts` (`noInferrableTypes`)
49
+ - Fix lint errors: replace `as any` with `as Record<string, unknown>` in `template.repository.ts` (`noExplicitAny`)
50
+ - Run full regression: 71 files / 731 tests pass, `biome lint src` clean
51
+
52
+ ## [1.0.2] - 2026-06-14
53
+
54
+ ### Security
55
+ - Redact DINGTALK_CLIENT_SECRET from `.omo/` and `.sisyphus/` plan docs
56
+ - Add `.gitleaks.toml` for pre-commit secret scanning (Gate 8)
57
+ - Replace side-effect `import 'dotenv/config'` with explicit `dotenv.config()`
58
+ - Add `.omo/` and `.sisyphus/` to `.gitignore` to prevent future secret leaks
59
+ - Add npm `overrides` for `qs@6.15.2` to resolve moderate vulnerability (GHSA-q8mj-m7cp-5q26)
60
+
61
+ ### Fixed
62
+ - Fix `server-api.test.ts` and `admin-tree.test.ts`: `buildApp()` now returns `{fastify, prisma}` — use `result.fastify.inject` instead of `app.inject`
63
+ - Export `checkDatabaseConnection` from `src/server.ts` for test access
64
+ - Fix `dingtalk-services.test.ts`: update file-existence tests for refactored modules
65
+ - Fix `security.test.ts`: mock `apiKey.findFirst` instead of `auditLog.findFirst`
66
+ - Fix `health-api.test.ts`: align DingTalk env var checks with Stream mode
67
+ - Add `postinstall` script for Prisma Client auto-generation - **Fixes #48**
68
+ - Remove deprecated webhook module (replaced by DingTalk Stream mode) - **Fixes #43**
69
+ - Add `await prisma.$disconnect()` to graceful shutdown - **Fixes #41**
70
+ - Add AuditLog TTL (expiresAt + @@index), cleanup service, and daily cron at 2:00 AM - **Fixes #42**
71
+ - Reduce AuditLog verbosity: only log mutations (POST/PUT/DELETE) and admin paths
72
+ - Close false-positive env-config issue (#45): DingTalk Stream mode already handles this
73
+
74
+ ### Quality
75
+ - Pre-commit hook: Score 10.0/10, all 9 gates passed
76
+ - TDD: audit-cleanup service had tests written before implementation
77
+
78
+ ## [1.0.1] - 2026-06-13
79
+
80
+ ### Fixed
81
+ - Extract `formatTemplateResponse` helper in `src/api/templates.ts` (DRY principle)
82
+ - Extract `_loadStateWithMessages` private method in `src/repositories/interview-state.repository.ts` (eliminate code duplication)
83
+ - Extract `_buildUpdateData` private method in `src/repositories/template.repository.ts` (eliminate code duplication)
84
+ - Fix empty catch block in `src/services/interview-plan-send.service.ts` (add warn logging instead of silent suppression) - **Fixes #40**
85
+ - Fix test assertions: void expression checks in `tests/dingtalk-signature.test.ts`
86
+ - Fix missing imports and mock types in `tests/admin-templates.test.ts`
87
+ - Fix undefined access using optional chaining in `tests/interviewing-node.test.ts`
88
+ - Add missing InterviewState fields in `tests/state-persistence.test.ts`
89
+ - Replace `jest.Mock` with vitest Mock type in `tests/dingtalk-stream.test.ts` - **Fixes #44**
90
+ - Update AGENTS.md: document third-party library exclusion rule for architecture checks (public/js/*.min.js, node_modules/)
91
+
92
+ ### Quality
93
+ - Pre-commit hook: Score 10.0/10, all 9 gates passed
94
+ - Resolved Gate 6 Architecture Code Clone warnings for source files
95
+
package/README.md ADDED
@@ -0,0 +1,242 @@
1
+ # Interview Bot
2
+
3
+ AI-powered interview robot with intelligent follow-up questions, multi-turn context memory, and voice input support.
4
+
5
+ ## Features
6
+
7
+ - **AI智能追问**: 基于LLM的完全智能型追问能力
8
+ - **多轮上下文记忆**: 支持跨多天、多条消息的对话连贯性
9
+ - **语音输入**: 支持语音消息回答
10
+ - **异步消息式访谈**: 被访谈者可以在碎片时间回答
11
+ - **自动生成报告**: 访谈结束后自动生成Markdown报告
12
+ - **私有部署**: 数据全留存,确保安全性
13
+
14
+ ## Tech Stack
15
+
16
+ - **对话引擎**: LangGraph.js
17
+ - **LLM服务**: 阿里云通义千问 (DashScope)
18
+ - **语音识别**: 阿里云Fun-ASR
19
+ - **消息平台**: 钉钉
20
+ - **数据存储**: PostgreSQL (Prisma ORM)
21
+ - **Web框架**: Fastify
22
+ - **语言**: TypeScript (strict mode)
23
+
24
+ ## Quick Start
25
+
26
+ ### 1. 安装依赖
27
+
28
+ ```bash
29
+ cd dialog-survey
30
+ npm install
31
+ ```
32
+
33
+ ### 2. 配置环境变量
34
+
35
+ ```bash
36
+ cp .env.example .env
37
+ # 编辑 .env 填入你的配置
38
+ ```
39
+
40
+ ### 3. 初始化数据库
41
+
42
+ ```bash
43
+ npx prisma generate
44
+ npx prisma db push
45
+ ```
46
+
47
+ ### 4. 启动服务
48
+
49
+ ```bash
50
+ npm run dev
51
+ ```
52
+
53
+ ## 项目结构
54
+
55
+ ```
56
+ dialog-survey/
57
+ ├── src/
58
+ │ ├── api/ # API层 (Fastify routes)
59
+ │ ├── core/ # 核心逻辑 (LangGraph StateGraph)
60
+ │ ├── services/ # 服务层 (LLM, ASR, 钉钉)
61
+ │ ├── repositories/ # 数据访问层 (Prisma)
62
+ │ └── utils/ # 工具函数
63
+ ├── tests/ # 测试 (Vitest)
64
+ ├── prisma/ # Prisma schema
65
+ ├── templates/ # 访谈模板
66
+ ├── reports/ # 生成的报告
67
+ ├── package.json
68
+ ├── tsconfig.json
69
+ └── vitest.config.ts
70
+ ```
71
+
72
+ ## 开发命令
73
+
74
+ ```bash
75
+ # 类型检查
76
+ npm run type-check
77
+
78
+ # 运行测试
79
+ npm test
80
+
81
+ # 测试覆盖率
82
+ npm run test:coverage
83
+
84
+ # 代码检查
85
+ npm run lint
86
+
87
+ # 构建
88
+ npm run build
89
+ ```
90
+
91
+ ## 部署
92
+
93
+ ### 环境要求
94
+
95
+ | 组件 | 版本/说明 |
96
+ |------|-----------|
97
+ | Node.js | >= 20.0.0 (推荐 v20 LTS) |
98
+ | PostgreSQL | 14+ |
99
+ | npm | 随 Node.js 自带 |
100
+ | 操作系统 | Linux / macOS / Windows |
101
+
102
+ ### 部署步骤
103
+
104
+ #### 1. 克隆或复制项目
105
+
106
+ ```bash
107
+ # 推荐: 从 Git 仓库克隆
108
+ git clone <repo-url> dialog-survey
109
+ cd dialog-survey
110
+
111
+ # 或: 直接拷贝项目目录到目标机器
112
+ ```
113
+
114
+ #### 2. 安装依赖
115
+
116
+ ```bash
117
+ npm install
118
+ ```
119
+
120
+ #### 3. 配置环境变量
121
+
122
+ ```bash
123
+ cp .env.example .env
124
+ # 编辑 .env,填入实际配置值(见下方环境变量说明)
125
+ ```
126
+
127
+ #### 4. 初始化数据库
128
+
129
+ ```bash
130
+ npx prisma generate # 生成 Prisma Client
131
+ npx prisma db push # 同步 schema 到数据库
132
+ ```
133
+
134
+ #### 5. 启动服务
135
+
136
+ **开发模式** (热重载):
137
+ ```bash
138
+ npm run dev
139
+ # 默认监听 http://0.0.0.0:3001
140
+ ```
141
+
142
+ **生产模式** (推荐用于长期运行):
143
+ ```bash
144
+ npm run build # 编译到 dist/
145
+ node dist/src/server.ts
146
+ ```
147
+
148
+ 或使用 PM2 管理进程:
149
+ ```bash
150
+ npm install -g pm2
151
+ pm2 start dist/src/server.ts --name dialog-survey
152
+ pm2 save
153
+ pm2 startup # 设置开机自启
154
+ ```
155
+
156
+ ### 环境变量说明
157
+
158
+ | 变量名 | 说明 | 示例 |
159
+ |--------|------|------|
160
+ | `NODE_ENV` | 运行环境 | `production` |
161
+ | `PORT` | 服务端口 | `3001` |
162
+ | `HOST` | 监听地址 | `0.0.0.0` |
163
+ | `DATABASE_URL` | PostgreSQL 连接串 | `postgresql://user:pass@localhost:5432/interview_bot?schema=public` |
164
+ | `DASHSCOPE_API_KEY` | 阿里云通义千问 API Key | `sk-xxx` |
165
+ | `DINGTALK_APP_KEY` | 钉钉 AppKey | 开放平台获取 |
166
+ | `DINGTALK_APP_SECRET` | 钉钉 AppSecret | 开放平台获取 |
167
+ | `DINGTALK_AGENT_ID` | 钉钉 AgentId | 开放平台获取 |
168
+ | `PUBLIC_URL` | 公网回调地址 | `https://your-domain.com` |
169
+ | `FUN_ASR_API_KEY` | 阿里云 Fun-ASR API Key | 语音识别用 |
170
+ | `ENCRYPTION_KEY` | AES 加密密钥 | 32 字节 hex 字符串 |
171
+ | `ADMIN_API_KEY` | 管理后台 API Key | 自定义密钥 |
172
+ | `REPORTS_DIR` | 报告存储目录 | `./reports` |
173
+ | `LOG_LEVEL` | 日志级别 | `info` |
174
+
175
+ 安全起见,`ENCRYPTION_KEY` 可通过 Node.js 生成:
176
+ ```bash
177
+ node -e "console.log(require('crypto').randomBytes(16).toString('hex'))"
178
+ ```
179
+
180
+ ### 健康检查
181
+
182
+ 服务启动后可访问:
183
+ ```bash
184
+ curl http://localhost:3001/health
185
+ ```
186
+
187
+ ### Docker 部署 (推荐)
188
+
189
+ 使用 Docker Compose 一键部署应用和 PostgreSQL 数据库。
190
+
191
+ #### 1. 配置环境变量
192
+
193
+ ```bash
194
+ cp .env.example .env
195
+ # 编辑 .env,填入 DingTalk、LLM、ASR 等实际配置值
196
+ ```
197
+
198
+ #### 2. 启动服务
199
+
200
+ ```bash
201
+ # 构建并启动所有服务
202
+ docker-compose up -d
203
+
204
+ # 查看日志
205
+ docker-compose logs -f app
206
+
207
+ # 查看所有服务状态
208
+ docker-compose ps
209
+ ```
210
+
211
+ #### 3. 验证部署
212
+
213
+ 服务启动后,访问健康检查端点:
214
+ ```bash
215
+ curl http://localhost:3001/health
216
+ ```
217
+
218
+ #### 常用 Docker 命令
219
+
220
+ ```bash
221
+ # 停止服务
222
+ docker-compose down
223
+
224
+ # 重启服务
225
+ docker-compose restart
226
+
227
+ # 查看数据库日志
228
+ docker-compose logs -f postgres
229
+
230
+ # 进入数据库 shell
231
+ docker-compose exec postgres psql -U interview_bot -d interview_bot
232
+
233
+ # 重新构建应用镜像
234
+ docker-compose build --no-cache app
235
+ docker-compose up -d app
236
+ ```
237
+
238
+ ### 预提交检查 (开发时)
239
+
240
+ ```bash
241
+ npm run type-check && npm run lint && npm run test:coverage
242
+ ```
package/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
@@ -0,0 +1,15 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import type { InterviewRepository } from '../repositories/interview.repository.js';
3
+ import type { TemplateRepository } from '../repositories/template.repository.js';
4
+ import type { AnalysisService } from '../services/analysis.service.js';
5
+ import type { AnalyticsService } from '../services/analytics.service.js';
6
+ import type { InterviewPlanService } from '../services/interview-plan.service.js';
7
+ export interface AdminTemplatesRoutesOptions {
8
+ templateRepo: TemplateRepository;
9
+ interviewPlanService: InterviewPlanService;
10
+ interviewRepo: InterviewRepository;
11
+ analysisService: AnalysisService;
12
+ analyticsService: AnalyticsService;
13
+ }
14
+ export declare function adminTemplatesRoutes(fastify: FastifyInstance, opts: AdminTemplatesRoutesOptions): Promise<void>;
15
+ //# sourceMappingURL=admin-templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-templates.d.ts","sourceRoot":"","sources":["../../src/api/admin-templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAG7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAGlF,MAAM,WAAW,2BAA2B;IAC1C,YAAY,EAAE,kBAAkB,CAAC;IACjC,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,aAAa,EAAE,mBAAmB,CAAC;IACnC,eAAe,EAAE,eAAe,CAAC;IACjC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAiHD,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,2BAA2B,iBAsmBlC"}