llm-content-creator 0.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 (438) hide show
  1. package/README.md +309 -0
  2. package/dist/application/workflow/SyncExecutor.d.ts +75 -0
  3. package/dist/application/workflow/SyncExecutor.d.ts.map +1 -0
  4. package/dist/application/workflow/SyncExecutor.js +370 -0
  5. package/dist/application/workflow/SyncExecutor.js.map +1 -0
  6. package/dist/application/workflow/types.d.ts +46 -0
  7. package/dist/application/workflow/types.d.ts.map +1 -0
  8. package/dist/application/workflow/types.js +7 -0
  9. package/dist/application/workflow/types.js.map +1 -0
  10. package/dist/config/index.d.ts +173 -0
  11. package/dist/config/index.d.ts.map +1 -0
  12. package/dist/config/index.js +288 -0
  13. package/dist/config/index.js.map +1 -0
  14. package/dist/domain/entities/QualityCheck.d.ts +181 -0
  15. package/dist/domain/entities/QualityCheck.d.ts.map +1 -0
  16. package/dist/domain/entities/QualityCheck.js +39 -0
  17. package/dist/domain/entities/QualityCheck.js.map +1 -0
  18. package/dist/domain/entities/Result.d.ts +103 -0
  19. package/dist/domain/entities/Result.d.ts.map +1 -0
  20. package/dist/domain/entities/Result.js +15 -0
  21. package/dist/domain/entities/Result.js.map +1 -0
  22. package/dist/domain/entities/Task.d.ts +130 -0
  23. package/dist/domain/entities/Task.d.ts.map +1 -0
  24. package/dist/domain/entities/Task.js +64 -0
  25. package/dist/domain/entities/Task.js.map +1 -0
  26. package/dist/domain/entities/TaskStep.d.ts +160 -0
  27. package/dist/domain/entities/TaskStep.d.ts.map +1 -0
  28. package/dist/domain/entities/TaskStep.js +30 -0
  29. package/dist/domain/entities/TaskStep.js.map +1 -0
  30. package/dist/domain/entities/TokenUsage.d.ts +70 -0
  31. package/dist/domain/entities/TokenUsage.d.ts.map +1 -0
  32. package/dist/domain/entities/TokenUsage.js +42 -0
  33. package/dist/domain/entities/TokenUsage.js.map +1 -0
  34. package/dist/domain/entities/index.d.ts +11 -0
  35. package/dist/domain/entities/index.d.ts.map +1 -0
  36. package/dist/domain/entities/index.js +16 -0
  37. package/dist/domain/entities/index.js.map +1 -0
  38. package/dist/domain/repositories/QualityCheckRepository.d.ts +49 -0
  39. package/dist/domain/repositories/QualityCheckRepository.d.ts.map +1 -0
  40. package/dist/domain/repositories/QualityCheckRepository.js +5 -0
  41. package/dist/domain/repositories/QualityCheckRepository.js.map +1 -0
  42. package/dist/domain/repositories/ResultRepository.d.ts +43 -0
  43. package/dist/domain/repositories/ResultRepository.d.ts.map +1 -0
  44. package/dist/domain/repositories/ResultRepository.js +5 -0
  45. package/dist/domain/repositories/ResultRepository.js.map +1 -0
  46. package/dist/domain/repositories/TaskRepository.d.ts +240 -0
  47. package/dist/domain/repositories/TaskRepository.d.ts.map +1 -0
  48. package/dist/domain/repositories/TaskRepository.js +7 -0
  49. package/dist/domain/repositories/TaskRepository.js.map +1 -0
  50. package/dist/domain/workflow/CheckpointManager.d.ts +94 -0
  51. package/dist/domain/workflow/CheckpointManager.d.ts.map +1 -0
  52. package/dist/domain/workflow/CheckpointManager.js +224 -0
  53. package/dist/domain/workflow/CheckpointManager.js.map +1 -0
  54. package/dist/domain/workflow/ContentCreatorGraph.d.ts +17 -0
  55. package/dist/domain/workflow/ContentCreatorGraph.d.ts.map +1 -0
  56. package/dist/domain/workflow/ContentCreatorGraph.js +381 -0
  57. package/dist/domain/workflow/ContentCreatorGraph.js.map +1 -0
  58. package/dist/domain/workflow/State.d.ts +172 -0
  59. package/dist/domain/workflow/State.d.ts.map +1 -0
  60. package/dist/domain/workflow/State.js +184 -0
  61. package/dist/domain/workflow/State.js.map +1 -0
  62. package/dist/domain/workflow/index.d.ts +11 -0
  63. package/dist/domain/workflow/index.d.ts.map +1 -0
  64. package/dist/domain/workflow/index.js +15 -0
  65. package/dist/domain/workflow/index.js.map +1 -0
  66. package/dist/domain/workflow/nodes/BaseNode.d.ts +134 -0
  67. package/dist/domain/workflow/nodes/BaseNode.d.ts.map +1 -0
  68. package/dist/domain/workflow/nodes/BaseNode.js +253 -0
  69. package/dist/domain/workflow/nodes/BaseNode.js.map +1 -0
  70. package/dist/domain/workflow/nodes/CheckImageNode.d.ts +43 -0
  71. package/dist/domain/workflow/nodes/CheckImageNode.d.ts.map +1 -0
  72. package/dist/domain/workflow/nodes/CheckImageNode.js +254 -0
  73. package/dist/domain/workflow/nodes/CheckImageNode.js.map +1 -0
  74. package/dist/domain/workflow/nodes/CheckTextNode.d.ts +66 -0
  75. package/dist/domain/workflow/nodes/CheckTextNode.d.ts.map +1 -0
  76. package/dist/domain/workflow/nodes/CheckTextNode.js +530 -0
  77. package/dist/domain/workflow/nodes/CheckTextNode.js.map +1 -0
  78. package/dist/domain/workflow/nodes/GenerateImageNode.d.ts +44 -0
  79. package/dist/domain/workflow/nodes/GenerateImageNode.d.ts.map +1 -0
  80. package/dist/domain/workflow/nodes/GenerateImageNode.js +272 -0
  81. package/dist/domain/workflow/nodes/GenerateImageNode.js.map +1 -0
  82. package/dist/domain/workflow/nodes/OrganizeNode.d.ts +49 -0
  83. package/dist/domain/workflow/nodes/OrganizeNode.d.ts.map +1 -0
  84. package/dist/domain/workflow/nodes/OrganizeNode.js +241 -0
  85. package/dist/domain/workflow/nodes/OrganizeNode.js.map +1 -0
  86. package/dist/domain/workflow/nodes/SearchNode.d.ts +48 -0
  87. package/dist/domain/workflow/nodes/SearchNode.d.ts.map +1 -0
  88. package/dist/domain/workflow/nodes/SearchNode.js +151 -0
  89. package/dist/domain/workflow/nodes/SearchNode.js.map +1 -0
  90. package/dist/domain/workflow/nodes/WriteNode.d.ts +68 -0
  91. package/dist/domain/workflow/nodes/WriteNode.d.ts.map +1 -0
  92. package/dist/domain/workflow/nodes/WriteNode.js +431 -0
  93. package/dist/domain/workflow/nodes/WriteNode.js.map +1 -0
  94. package/dist/domain/workflow/nodes/config/index.js +287 -0
  95. package/dist/domain/workflow/nodes/domain/entities/Task.js +68 -0
  96. package/dist/domain/workflow/nodes/domain/workflow/State.js +200 -0
  97. package/dist/domain/workflow/nodes/domain/workflow/nodes/BaseNode.js +328 -0
  98. package/dist/domain/workflow/nodes/domain/workflow/nodes/CheckTextNode.js +500 -0
  99. package/dist/domain/workflow/nodes/index.d.ts +13 -0
  100. package/dist/domain/workflow/nodes/index.d.ts.map +1 -0
  101. package/dist/domain/workflow/nodes/index.js +13 -0
  102. package/dist/domain/workflow/nodes/index.js.map +1 -0
  103. package/dist/domain/workflow/nodes/infrastructure/logging/logger.js +275 -0
  104. package/dist/domain/workflow/nodes/services/llm/EnhancedLLMService.js +559 -0
  105. package/dist/index.d.ts +24 -0
  106. package/dist/index.d.ts.map +1 -0
  107. package/dist/index.js +34 -0
  108. package/dist/index.js.map +1 -0
  109. package/dist/infrastructure/cache/CacheService.d.ts +139 -0
  110. package/dist/infrastructure/cache/CacheService.d.ts.map +1 -0
  111. package/dist/infrastructure/cache/CacheService.js +419 -0
  112. package/dist/infrastructure/cache/CacheService.js.map +1 -0
  113. package/dist/infrastructure/cache/index.d.ts +5 -0
  114. package/dist/infrastructure/cache/index.d.ts.map +1 -0
  115. package/dist/infrastructure/cache/index.js +6 -0
  116. package/dist/infrastructure/cache/index.js.map +1 -0
  117. package/dist/infrastructure/database/BaseRepository.d.ts +98 -0
  118. package/dist/infrastructure/database/BaseRepository.d.ts.map +1 -0
  119. package/dist/infrastructure/database/BaseRepository.js +178 -0
  120. package/dist/infrastructure/database/BaseRepository.js.map +1 -0
  121. package/dist/infrastructure/database/MemoryTaskRepository.d.ts +77 -0
  122. package/dist/infrastructure/database/MemoryTaskRepository.d.ts.map +1 -0
  123. package/dist/infrastructure/database/MemoryTaskRepository.js +309 -0
  124. package/dist/infrastructure/database/MemoryTaskRepository.js.map +1 -0
  125. package/dist/infrastructure/database/PostgresQualityCheckRepository.d.ts +36 -0
  126. package/dist/infrastructure/database/PostgresQualityCheckRepository.d.ts.map +1 -0
  127. package/dist/infrastructure/database/PostgresQualityCheckRepository.js +89 -0
  128. package/dist/infrastructure/database/PostgresQualityCheckRepository.js.map +1 -0
  129. package/dist/infrastructure/database/PostgresTaskRepository.d.ts +94 -0
  130. package/dist/infrastructure/database/PostgresTaskRepository.d.ts.map +1 -0
  131. package/dist/infrastructure/database/PostgresTaskRepository.js +364 -0
  132. package/dist/infrastructure/database/PostgresTaskRepository.js.map +1 -0
  133. package/dist/infrastructure/database/ResultRepository.d.ts +41 -0
  134. package/dist/infrastructure/database/ResultRepository.d.ts.map +1 -0
  135. package/dist/infrastructure/database/ResultRepository.js +86 -0
  136. package/dist/infrastructure/database/ResultRepository.js.map +1 -0
  137. package/dist/infrastructure/database/SQLiteTaskRepository.d.ts +101 -0
  138. package/dist/infrastructure/database/SQLiteTaskRepository.d.ts.map +1 -0
  139. package/dist/infrastructure/database/SQLiteTaskRepository.js +548 -0
  140. package/dist/infrastructure/database/SQLiteTaskRepository.js.map +1 -0
  141. package/dist/infrastructure/database/index.d.ts +32 -0
  142. package/dist/infrastructure/database/index.d.ts.map +1 -0
  143. package/dist/infrastructure/database/index.js +72 -0
  144. package/dist/infrastructure/database/index.js.map +1 -0
  145. package/dist/infrastructure/logging/logger.d.ts +69 -0
  146. package/dist/infrastructure/logging/logger.d.ts.map +1 -0
  147. package/dist/infrastructure/logging/logger.js +169 -0
  148. package/dist/infrastructure/logging/logger.js.map +1 -0
  149. package/dist/infrastructure/monitoring/LoggingService.d.ts +109 -0
  150. package/dist/infrastructure/monitoring/LoggingService.d.ts.map +1 -0
  151. package/dist/infrastructure/monitoring/LoggingService.js +198 -0
  152. package/dist/infrastructure/monitoring/LoggingService.js.map +1 -0
  153. package/dist/infrastructure/monitoring/MetricsService.d.ts +112 -0
  154. package/dist/infrastructure/monitoring/MetricsService.d.ts.map +1 -0
  155. package/dist/infrastructure/monitoring/MetricsService.js +362 -0
  156. package/dist/infrastructure/monitoring/MetricsService.js.map +1 -0
  157. package/dist/infrastructure/monitoring/SentryService.d.ts +108 -0
  158. package/dist/infrastructure/monitoring/SentryService.d.ts.map +1 -0
  159. package/dist/infrastructure/monitoring/SentryService.js +282 -0
  160. package/dist/infrastructure/monitoring/SentryService.js.map +1 -0
  161. package/dist/infrastructure/monitoring/index.d.ts +7 -0
  162. package/dist/infrastructure/monitoring/index.d.ts.map +1 -0
  163. package/dist/infrastructure/monitoring/index.js +10 -0
  164. package/dist/infrastructure/monitoring/index.js.map +1 -0
  165. package/dist/infrastructure/queue/TaskQueue.d.ts +110 -0
  166. package/dist/infrastructure/queue/TaskQueue.d.ts.map +1 -0
  167. package/dist/infrastructure/queue/TaskQueue.js +363 -0
  168. package/dist/infrastructure/queue/TaskQueue.js.map +1 -0
  169. package/dist/infrastructure/queue/index.d.ts +5 -0
  170. package/dist/infrastructure/queue/index.d.ts.map +1 -0
  171. package/dist/infrastructure/queue/index.js +5 -0
  172. package/dist/infrastructure/queue/index.js.map +1 -0
  173. package/dist/infrastructure/redis/connection.d.ts +61 -0
  174. package/dist/infrastructure/redis/connection.d.ts.map +1 -0
  175. package/dist/infrastructure/redis/connection.js +184 -0
  176. package/dist/infrastructure/redis/connection.js.map +1 -0
  177. package/dist/infrastructure/redis/index.d.ts +5 -0
  178. package/dist/infrastructure/redis/index.d.ts.map +1 -0
  179. package/dist/infrastructure/redis/index.js +5 -0
  180. package/dist/infrastructure/redis/index.js.map +1 -0
  181. package/dist/infrastructure/security/ApiKeyService.d.ts +103 -0
  182. package/dist/infrastructure/security/ApiKeyService.d.ts.map +1 -0
  183. package/dist/infrastructure/security/ApiKeyService.js +250 -0
  184. package/dist/infrastructure/security/ApiKeyService.js.map +1 -0
  185. package/dist/infrastructure/security/QuotaService.d.ts +87 -0
  186. package/dist/infrastructure/security/QuotaService.d.ts.map +1 -0
  187. package/dist/infrastructure/security/QuotaService.js +303 -0
  188. package/dist/infrastructure/security/QuotaService.js.map +1 -0
  189. package/dist/infrastructure/security/RateLimiter.d.ts +104 -0
  190. package/dist/infrastructure/security/RateLimiter.d.ts.map +1 -0
  191. package/dist/infrastructure/security/RateLimiter.js +331 -0
  192. package/dist/infrastructure/security/RateLimiter.js.map +1 -0
  193. package/dist/infrastructure/security/index.d.ts +7 -0
  194. package/dist/infrastructure/security/index.d.ts.map +1 -0
  195. package/dist/infrastructure/security/index.js +10 -0
  196. package/dist/infrastructure/security/index.js.map +1 -0
  197. package/dist/monitoring/index.d.ts +5 -0
  198. package/dist/monitoring/index.d.ts.map +1 -0
  199. package/dist/monitoring/index.js +5 -0
  200. package/dist/monitoring/index.js.map +1 -0
  201. package/dist/monitoring/server.d.ts +14 -0
  202. package/dist/monitoring/server.d.ts.map +1 -0
  203. package/dist/monitoring/server.js +99 -0
  204. package/dist/monitoring/server.js.map +1 -0
  205. package/dist/presentation/cli/commands/cancel.d.ts +8 -0
  206. package/dist/presentation/cli/commands/cancel.d.ts.map +1 -0
  207. package/dist/presentation/cli/commands/cancel.js +57 -0
  208. package/dist/presentation/cli/commands/cancel.js.map +1 -0
  209. package/dist/presentation/cli/commands/create.d.ts +8 -0
  210. package/dist/presentation/cli/commands/create.d.ts.map +1 -0
  211. package/dist/presentation/cli/commands/create.js +368 -0
  212. package/dist/presentation/cli/commands/create.js.map +1 -0
  213. package/dist/presentation/cli/commands/result.d.ts +8 -0
  214. package/dist/presentation/cli/commands/result.d.ts.map +1 -0
  215. package/dist/presentation/cli/commands/result.js +121 -0
  216. package/dist/presentation/cli/commands/result.js.map +1 -0
  217. package/dist/presentation/cli/commands/status.d.ts +8 -0
  218. package/dist/presentation/cli/commands/status.d.ts.map +1 -0
  219. package/dist/presentation/cli/commands/status.js +92 -0
  220. package/dist/presentation/cli/commands/status.js.map +1 -0
  221. package/dist/presentation/cli/index.d.ts +8 -0
  222. package/dist/presentation/cli/index.d.ts.map +1 -0
  223. package/dist/presentation/cli/index.js +32 -0
  224. package/dist/presentation/cli/index.js.map +1 -0
  225. package/dist/presentation/cli/utils/cleanup.d.ts +14 -0
  226. package/dist/presentation/cli/utils/cleanup.d.ts.map +1 -0
  227. package/dist/presentation/cli/utils/cleanup.js +62 -0
  228. package/dist/presentation/cli/utils/cleanup.js.map +1 -0
  229. package/dist/presentation/cli/utils/formatter.d.ts +28 -0
  230. package/dist/presentation/cli/utils/formatter.d.ts.map +1 -0
  231. package/dist/presentation/cli/utils/formatter.js +68 -0
  232. package/dist/presentation/cli/utils/formatter.js.map +1 -0
  233. package/dist/presentation/cli.d.ts +7 -0
  234. package/dist/presentation/cli.d.ts.map +1 -0
  235. package/dist/presentation/cli.js +8 -0
  236. package/dist/presentation/cli.js.map +1 -0
  237. package/dist/presentation/monitor-cli.d.ts +8 -0
  238. package/dist/presentation/monitor-cli.d.ts.map +1 -0
  239. package/dist/presentation/monitor-cli.js +44 -0
  240. package/dist/presentation/monitor-cli.js.map +1 -0
  241. package/dist/presentation/worker-cli.d.ts +8 -0
  242. package/dist/presentation/worker-cli.d.ts.map +1 -0
  243. package/dist/presentation/worker-cli.js +51 -0
  244. package/dist/presentation/worker-cli.js.map +1 -0
  245. package/dist/schedulers/TaskScheduler.d.ts +99 -0
  246. package/dist/schedulers/TaskScheduler.d.ts.map +1 -0
  247. package/dist/schedulers/TaskScheduler.js +233 -0
  248. package/dist/schedulers/TaskScheduler.js.map +1 -0
  249. package/dist/schedulers/index.d.ts +5 -0
  250. package/dist/schedulers/index.d.ts.map +1 -0
  251. package/dist/schedulers/index.js +5 -0
  252. package/dist/schedulers/index.js.map +1 -0
  253. package/dist/services/image/ImageService.d.ts +68 -0
  254. package/dist/services/image/ImageService.d.ts.map +1 -0
  255. package/dist/services/image/ImageService.js +166 -0
  256. package/dist/services/image/ImageService.js.map +1 -0
  257. package/dist/services/index.d.ts +8 -0
  258. package/dist/services/index.d.ts.map +1 -0
  259. package/dist/services/index.js +12 -0
  260. package/dist/services/index.js.map +1 -0
  261. package/dist/services/llm/EnhancedLLMService.d.ts +148 -0
  262. package/dist/services/llm/EnhancedLLMService.d.ts.map +1 -0
  263. package/dist/services/llm/EnhancedLLMService.js +425 -0
  264. package/dist/services/llm/EnhancedLLMService.js.map +1 -0
  265. package/dist/services/llm/LLMService.d.ts +103 -0
  266. package/dist/services/llm/LLMService.d.ts.map +1 -0
  267. package/dist/services/llm/LLMService.js +212 -0
  268. package/dist/services/llm/LLMService.js.map +1 -0
  269. package/dist/services/quality/HardRuleChecker.d.ts +143 -0
  270. package/dist/services/quality/HardRuleChecker.d.ts.map +1 -0
  271. package/dist/services/quality/HardRuleChecker.js +353 -0
  272. package/dist/services/quality/HardRuleChecker.js.map +1 -0
  273. package/dist/services/quality/LLMEvaluator.d.ts +105 -0
  274. package/dist/services/quality/LLMEvaluator.d.ts.map +1 -0
  275. package/dist/services/quality/LLMEvaluator.js +312 -0
  276. package/dist/services/quality/LLMEvaluator.js.map +1 -0
  277. package/dist/services/quality/QualityCheckService.d.ts +112 -0
  278. package/dist/services/quality/QualityCheckService.d.ts.map +1 -0
  279. package/dist/services/quality/QualityCheckService.js +342 -0
  280. package/dist/services/quality/QualityCheckService.js.map +1 -0
  281. package/dist/services/quality/QualityService.d.ts +75 -0
  282. package/dist/services/quality/QualityService.d.ts.map +1 -0
  283. package/dist/services/quality/QualityService.js +360 -0
  284. package/dist/services/quality/QualityService.js.map +1 -0
  285. package/dist/services/quality/index.d.ts +7 -0
  286. package/dist/services/quality/index.d.ts.map +1 -0
  287. package/dist/services/quality/index.js +10 -0
  288. package/dist/services/quality/index.js.map +1 -0
  289. package/dist/services/search/SearchService.d.ts +79 -0
  290. package/dist/services/search/SearchService.d.ts.map +1 -0
  291. package/dist/services/search/SearchService.js +193 -0
  292. package/dist/services/search/SearchService.js.map +1 -0
  293. package/dist/workers/TaskWorker.d.ts +61 -0
  294. package/dist/workers/TaskWorker.d.ts.map +1 -0
  295. package/dist/workers/TaskWorker.js +256 -0
  296. package/dist/workers/TaskWorker.js.map +1 -0
  297. package/dist/workers/index.d.ts +5 -0
  298. package/dist/workers/index.d.ts.map +1 -0
  299. package/dist/workers/index.js +5 -0
  300. package/dist/workers/index.js.map +1 -0
  301. package/docs/DOCUMENTATION-ANALYSIS.md +190 -0
  302. package/docs/README.md +145 -0
  303. package/docs/SOURCE-CODE-ANALYSIS.md +1107 -0
  304. package/docs/architecture-complete.md +5524 -0
  305. package/docs/archive/implementation/implementation-analysis/README.md +244 -0
  306. package/docs/archive/implementation/implementation-analysis/implementation-analysis-context.md +483 -0
  307. package/docs/archive/implementation/implementation-analysis/implementation-analysis-plan.md +1242 -0
  308. package/docs/archive/implementation/implementation-analysis/implementation-analysis-tasks.md +777 -0
  309. package/docs/archive/phases/phase-1/phase-1-completion-summary.md +284 -0
  310. package/docs/archive/phases/phase-1/phase-1-implementation-guide.md +1380 -0
  311. package/docs/archive/phases/phase-2/phase-2a/phase-2a-completion-summary.md +443 -0
  312. package/docs/archive/phases/phase-2/phase-2b/phase-2b-completion-report.md +430 -0
  313. package/docs/archive/phases/phase-2/phase-2b/phase-2b-completion-summary.md +592 -0
  314. package/docs/archive/phases/phase-2/phase-2b/phase-2b-final-summary.md +371 -0
  315. package/docs/archive/phases/phase-2/phase-2b/phase-2b-preparation-complete.md +343 -0
  316. package/docs/archive/phases/phase-2/phase-2b/phase-2b-preparation.md +945 -0
  317. package/docs/archive/phases/phase-2/phase-2b/phase-2b-progress-update.md +366 -0
  318. package/docs/archive/phases/phase-3/phase-3-completion-summary.md +354 -0
  319. package/docs/archive/phases/phase-3/phase-3-development-plan.md +878 -0
  320. package/docs/archive/phases/phase-3/phase-3-quick-start.md +324 -0
  321. package/docs/archive/phases/phase-4/phase-4-completion-summary.md +708 -0
  322. package/docs/archive/phases/phase-4/phase-4-development-plan.md +740 -0
  323. package/docs/archive/phases/phase-4/phase-4-quick-start.md +632 -0
  324. package/docs/archive/phases/phase-4/phase-4-session-3-security-testing.md +484 -0
  325. package/docs/archive/phases/phase-4/phase-4-session-4-unit-tests.md +550 -0
  326. package/docs/archive/phases/phase-4/phase-4-session-5-security-tests.md +564 -0
  327. package/docs/archive/phases/phase-4/phase-4-session-6-cache-integration.md +456 -0
  328. package/docs/archive/phases/phase-4/phase-4-session-7-test-fixes.md +348 -0
  329. package/docs/archive/phases/phase-4/phase-4-session-8-taskqueue-fixes.md +323 -0
  330. package/docs/archive/phases/phase-4/phase-4-session-summary-continued.md +373 -0
  331. package/docs/archive/phases/phase-4/phase-4-session-summary.md +595 -0
  332. package/docs/archive/reports/progress-reports/PHASE_0_PROGRESS.md +242 -0
  333. package/docs/archive/reports/progress-reports/PHASE_0_SUMMARY.md +262 -0
  334. package/docs/archive/reports/progress-reports/PHASE_1_2_ISSUES.md +399 -0
  335. package/docs/archive/reports/progress-reports/PHASE_1_PROGRESS.md +388 -0
  336. package/docs/archive/reports/progress-reports/PHASE_3_PREPARATION.md +574 -0
  337. package/docs/archive/reports/progress-reports/current-progress-update.md +294 -0
  338. package/docs/archive/reports/progress-reports/final-summary.md +215 -0
  339. package/docs/archive/reports/progress-reports/implementation-summary.md +287 -0
  340. package/docs/archive/reports/progress-reports/project-progress-report.md +440 -0
  341. package/docs/archive/reports/progress-reports/project-progress.md +386 -0
  342. package/docs/archive/reports/test-reports/TEST-COVERAGE-REPORT.md +441 -0
  343. package/docs/archive/reports/test-reports/e2e-test-report.md +293 -0
  344. package/docs/archive/reports/test-reports/final-test-report.md +367 -0
  345. package/docs/archive/reports/test-reports/real-env-test-report.md +391 -0
  346. package/docs/archive/reports/test-reports/test-completion-summary.md +356 -0
  347. package/docs/archive/reports/test-reports/test-report.md +371 -0
  348. package/docs/archive/sessions/session-2-summary.md +429 -0
  349. package/docs/archive/sessions/session-3-summary.md +395 -0
  350. package/docs/archive/sessions/session-summary.md +370 -0
  351. package/docs/config-system-update.md +239 -0
  352. package/docs/database-refactoring-PLAN.md +199 -0
  353. package/docs/database-refactoring-SUMMARY.md +384 -0
  354. package/docs/quality-check-architecture.md +1030 -0
  355. package/docs/quick-start.md +388 -0
  356. package/docs/references/bullmq-quick-reference.md +525 -0
  357. package/docs/references/monitoring-optimization-guide.md +871 -0
  358. package/docs/references/performance-optimization-guide.md +933 -0
  359. package/docs/storage-guide.md +612 -0
  360. package/docs/test-implementation-PLAN.md +223 -0
  361. package/docs/test-implementation-SUMMARY.md +194 -0
  362. package/docs/user-guide.md +719 -0
  363. package/docs/workflow-architecture.md +549 -0
  364. package/package.json +126 -0
  365. package/src/application/workflow/SyncExecutor.ts +444 -0
  366. package/src/application/workflow/types.ts +57 -0
  367. package/src/config/index.ts +352 -0
  368. package/src/domain/entities/QualityCheck.ts +202 -0
  369. package/src/domain/entities/Result.ts +130 -0
  370. package/src/domain/entities/Task.ts +178 -0
  371. package/src/domain/entities/TaskStep.ts +188 -0
  372. package/src/domain/entities/TokenUsage.ts +119 -0
  373. package/src/domain/entities/index.ts +20 -0
  374. package/src/domain/repositories/QualityCheckRepository.ts +52 -0
  375. package/src/domain/repositories/ResultRepository.ts +47 -0
  376. package/src/domain/repositories/TaskRepository.ts +271 -0
  377. package/src/domain/workflow/CheckpointManager.ts +283 -0
  378. package/src/domain/workflow/ContentCreatorGraph.ts +446 -0
  379. package/src/domain/workflow/State.ts +321 -0
  380. package/src/domain/workflow/index.ts +18 -0
  381. package/src/domain/workflow/nodes/BaseNode.ts +325 -0
  382. package/src/domain/workflow/nodes/CheckImageNode.ts +325 -0
  383. package/src/domain/workflow/nodes/CheckTextNode.ts +709 -0
  384. package/src/domain/workflow/nodes/GenerateImageNode.ts +342 -0
  385. package/src/domain/workflow/nodes/OrganizeNode.ts +304 -0
  386. package/src/domain/workflow/nodes/SearchNode.ts +192 -0
  387. package/src/domain/workflow/nodes/WriteNode.ts +505 -0
  388. package/src/domain/workflow/nodes/index.ts +13 -0
  389. package/src/index.ts +43 -0
  390. package/src/infrastructure/cache/CacheService.ts +483 -0
  391. package/src/infrastructure/cache/index.ts +6 -0
  392. package/src/infrastructure/database/BaseRepository.ts +214 -0
  393. package/src/infrastructure/database/MemoryTaskRepository.ts +377 -0
  394. package/src/infrastructure/database/PostgresQualityCheckRepository.ts +115 -0
  395. package/src/infrastructure/database/PostgresTaskRepository.ts +424 -0
  396. package/src/infrastructure/database/ResultRepository.ts +113 -0
  397. package/src/infrastructure/database/SQLiteTaskRepository.ts +651 -0
  398. package/src/infrastructure/database/index.ts +83 -0
  399. package/src/infrastructure/logging/logger.ts +231 -0
  400. package/src/infrastructure/monitoring/LoggingService.ts +292 -0
  401. package/src/infrastructure/monitoring/MetricsService.ts +468 -0
  402. package/src/infrastructure/monitoring/SentryService.ts +345 -0
  403. package/src/infrastructure/monitoring/index.ts +12 -0
  404. package/src/infrastructure/queue/TaskQueue.ts +429 -0
  405. package/src/infrastructure/queue/index.ts +5 -0
  406. package/src/infrastructure/redis/connection.ts +215 -0
  407. package/src/infrastructure/redis/index.ts +5 -0
  408. package/src/infrastructure/security/ApiKeyService.ts +340 -0
  409. package/src/infrastructure/security/QuotaService.ts +411 -0
  410. package/src/infrastructure/security/RateLimiter.ts +417 -0
  411. package/src/infrastructure/security/index.ts +12 -0
  412. package/src/monitoring/index.ts +5 -0
  413. package/src/monitoring/server.ts +109 -0
  414. package/src/presentation/cli/commands/cancel.ts +64 -0
  415. package/src/presentation/cli/commands/create.ts +400 -0
  416. package/src/presentation/cli/commands/result.ts +136 -0
  417. package/src/presentation/cli/commands/status.ts +102 -0
  418. package/src/presentation/cli/index.ts +39 -0
  419. package/src/presentation/cli/utils/cleanup.ts +65 -0
  420. package/src/presentation/cli/utils/formatter.ts +74 -0
  421. package/src/presentation/cli.ts +8 -0
  422. package/src/presentation/monitor-cli.ts +52 -0
  423. package/src/presentation/worker-cli.ts +62 -0
  424. package/src/schedulers/TaskScheduler.ts +314 -0
  425. package/src/schedulers/index.ts +11 -0
  426. package/src/services/image/ImageService.ts +221 -0
  427. package/src/services/index.ts +15 -0
  428. package/src/services/llm/EnhancedLLMService.ts +596 -0
  429. package/src/services/llm/LLMService.ts +310 -0
  430. package/src/services/quality/HardRuleChecker.ts +509 -0
  431. package/src/services/quality/LLMEvaluator.ts +400 -0
  432. package/src/services/quality/QualityCheckService.ts +473 -0
  433. package/src/services/quality/QualityService.ts +445 -0
  434. package/src/services/quality/index.ts +12 -0
  435. package/src/services/search/SearchService.ts +266 -0
  436. package/src/types/global.d.ts +17 -0
  437. package/src/workers/TaskWorker.ts +320 -0
  438. package/src/workers/index.ts +5 -0
@@ -0,0 +1,559 @@
1
+ "use strict";
2
+ /**
3
+ * Enhanced LLM Service
4
+ *
5
+ * 在原有 LLMService 基础上添加:
6
+ * - 重试机制(指数退避)
7
+ * - Token 使用记录
8
+ * - 成本估算
9
+ * - 性能监控
10
+ */
11
+ var __assign = (this && this.__assign) || function () {
12
+ __assign = Object.assign || function(t) {
13
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
14
+ s = arguments[i];
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
16
+ t[p] = s[p];
17
+ }
18
+ return t;
19
+ };
20
+ return __assign.apply(this, arguments);
21
+ };
22
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
+ return new (P || (P = Promise))(function (resolve, reject) {
25
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
29
+ });
30
+ };
31
+ var __generator = (this && this.__generator) || function (thisArg, body) {
32
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
33
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
34
+ function verb(n) { return function (v) { return step([n, v]); }; }
35
+ function step(op) {
36
+ if (f) throw new TypeError("Generator is already executing.");
37
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
38
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
39
+ if (y = 0, t) op = [op[0] & 2, t.value];
40
+ switch (op[0]) {
41
+ case 0: case 1: t = op; break;
42
+ case 4: _.label++; return { value: op[1], done: false };
43
+ case 5: _.label++; y = op[1]; op = [0]; continue;
44
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
45
+ default:
46
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
47
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
48
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
49
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
50
+ if (t[2]) _.ops.pop();
51
+ _.trys.pop(); continue;
52
+ }
53
+ op = body.call(thisArg, _);
54
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
55
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
56
+ }
57
+ };
58
+ var __importDefault = (this && this.__importDefault) || function (mod) {
59
+ return (mod && mod.__esModule) ? mod : { "default": mod };
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.enhancedLLMService = exports.EnhancedLLMService = void 0;
63
+ var axios_1 = __importDefault(require("axios"));
64
+ var index_js_1 = require("../../config/index.js");
65
+ var logger_js_1 = require("../../infrastructure/logging/logger.js");
66
+ var logger = (0, logger_js_1.createLogger)('LLM:Enhanced');
67
+ /**
68
+ * 默认重试配置
69
+ */
70
+ var DEFAULT_RETRY_CONFIG = {
71
+ maxRetries: 3,
72
+ initialDelay: 1000, // 1 秒
73
+ maxDelay: 10000, // 10 秒
74
+ backoffMultiplier: 2, // 指数退避
75
+ };
76
+ /**
77
+ * 成本配置(元/1k tokens)
78
+ */
79
+ var COST_CONFIG = {
80
+ deepseek: {
81
+ 'deepseek-chat': {
82
+ costPer1kTokensIn: 0.001,
83
+ costPer1kTokensOut: 0.002,
84
+ },
85
+ },
86
+ };
87
+ /**
88
+ * 增强的 LLM 服务类
89
+ */
90
+ var EnhancedLLMService = /** @class */ (function () {
91
+ function EnhancedLLMService(retryConfig) {
92
+ this.baseURL = index_js_1.config.llm.baseURL;
93
+ this.apiKey = index_js_1.config.llm.apiKey;
94
+ this.modelName = index_js_1.config.llm.modelName;
95
+ this.maxTokens = index_js_1.config.llm.maxTokens;
96
+ this.temperature = index_js_1.config.llm.temperature;
97
+ this.retryConfig = __assign(__assign({}, DEFAULT_RETRY_CONFIG), retryConfig);
98
+ this.tokenUsageRepo = new TempTokenUsageRepository();
99
+ }
100
+ /**
101
+ * 聊天对话(带重试和 Token 记录)
102
+ */
103
+ EnhancedLLMService.prototype.chat = function (request) {
104
+ return __awaiter(this, void 0, void 0, function () {
105
+ var startTime, response, choice, content, usage, cost, error_1;
106
+ return __generator(this, function (_a) {
107
+ switch (_a.label) {
108
+ case 0:
109
+ startTime = Date.now();
110
+ _a.label = 1;
111
+ case 1:
112
+ _a.trys.push([1, 5, , 6]);
113
+ logger.debug('Sending chat request with retry', {
114
+ model: request.model || this.modelName,
115
+ messagesCount: request.messages.length,
116
+ maxRetries: this.retryConfig.maxRetries,
117
+ stream: request.stream || false,
118
+ });
119
+ return [4 /*yield*/, this.chatWithRetry(request)];
120
+ case 2:
121
+ response = _a.sent();
122
+ choice = response.choices[0];
123
+ content = choice.message.content;
124
+ usage = response.usage;
125
+ cost = this.calculateCost(usage.promptTokens, usage.completionTokens, this.modelName);
126
+ if (!(request.taskId && request.stepName)) return [3 /*break*/, 4];
127
+ return [4 /*yield*/, this.recordTokenUsage({
128
+ taskId: request.taskId,
129
+ stepName: request.stepName,
130
+ tokensIn: usage.promptTokens,
131
+ tokensOut: usage.completionTokens,
132
+ totalTokens: usage.totalTokens,
133
+ costPer1kTokensIn: COST_CONFIG.deepseek[this.modelName].costPer1kTokensIn,
134
+ costPer1kTokensOut: COST_CONFIG.deepseek[this.modelName].costPer1kTokensOut,
135
+ totalCost: cost,
136
+ duration: Date.now() - startTime,
137
+ })];
138
+ case 3:
139
+ _a.sent();
140
+ _a.label = 4;
141
+ case 4:
142
+ logger.info('Chat request completed', {
143
+ promptTokens: usage.promptTokens,
144
+ completionTokens: usage.completionTokens,
145
+ totalTokens: usage.totalTokens,
146
+ cost: cost,
147
+ finishReason: choice.finishReason,
148
+ duration: Date.now() - startTime,
149
+ stream: request.stream || false,
150
+ });
151
+ return [2 /*return*/, {
152
+ content: content,
153
+ usage: {
154
+ promptTokens: usage.promptTokens,
155
+ completionTokens: usage.completionTokens,
156
+ totalTokens: usage.totalTokens,
157
+ },
158
+ cost: cost,
159
+ }];
160
+ case 5:
161
+ error_1 = _a.sent();
162
+ logger.error('LLM API request failed after retries', {
163
+ error: error_1 instanceof Error ? error_1.message : String(error_1),
164
+ duration: Date.now() - startTime,
165
+ stream: request.stream || false,
166
+ });
167
+ throw error_1;
168
+ case 6: return [2 /*return*/];
169
+ }
170
+ });
171
+ });
172
+ };
173
+ /**
174
+ * 带重试的聊天请求
175
+ */
176
+ EnhancedLLMService.prototype.chatWithRetry = function (request) {
177
+ return __awaiter(this, void 0, void 0, function () {
178
+ var lastError, attempt, delay, error_2;
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0:
182
+ lastError = null;
183
+ attempt = 0;
184
+ _a.label = 1;
185
+ case 1:
186
+ if (!(attempt <= this.retryConfig.maxRetries)) return [3 /*break*/, 8];
187
+ _a.label = 2;
188
+ case 2:
189
+ _a.trys.push([2, 6, , 7]);
190
+ if (!(attempt > 0)) return [3 /*break*/, 4];
191
+ delay = this.calculateRetryDelay(attempt);
192
+ logger.info("Retrying chat request (attempt ".concat(attempt + 1, "/").concat(this.retryConfig.maxRetries + 1, ")"), {
193
+ delay: delay,
194
+ });
195
+ return [4 /*yield*/, this.sleep(delay)];
196
+ case 3:
197
+ _a.sent();
198
+ _a.label = 4;
199
+ case 4: return [4 /*yield*/, this.chatRequest(request)];
200
+ case 5: return [2 /*return*/, _a.sent()];
201
+ case 6:
202
+ error_2 = _a.sent();
203
+ lastError = error_2 instanceof Error ? error_2 : new Error(String(error_2));
204
+ // 判断是否应该重试
205
+ if (!this.shouldRetry(lastError, attempt)) {
206
+ throw lastError;
207
+ }
208
+ logger.warn('Chat request failed, will retry', {
209
+ attempt: attempt + 1,
210
+ error: lastError.message,
211
+ });
212
+ return [3 /*break*/, 7];
213
+ case 7:
214
+ attempt++;
215
+ return [3 /*break*/, 1];
216
+ case 8: throw lastError;
217
+ }
218
+ });
219
+ });
220
+ };
221
+ /**
222
+ * 单次聊天请求
223
+ */
224
+ EnhancedLLMService.prototype.chatRequest = function (request) {
225
+ return __awaiter(this, void 0, void 0, function () {
226
+ var maxTokens, temperature, useStream, response;
227
+ var _a, _b, _c;
228
+ return __generator(this, function (_d) {
229
+ switch (_d.label) {
230
+ case 0:
231
+ maxTokens = typeof (request.maxTokens || this.maxTokens) === 'number'
232
+ ? request.maxTokens || this.maxTokens
233
+ : parseInt(request.maxTokens || String(this.maxTokens));
234
+ temperature = typeof ((_a = request.temperature) !== null && _a !== void 0 ? _a : this.temperature) === 'number'
235
+ ? (_b = request.temperature) !== null && _b !== void 0 ? _b : this.temperature
236
+ : parseFloat((_c = request.temperature) !== null && _c !== void 0 ? _c : String(this.temperature));
237
+ useStream = request.stream || false;
238
+ if (!useStream) return [3 /*break*/, 2];
239
+ return [4 /*yield*/, this.chatRequestStream(request, maxTokens, temperature)];
240
+ case 1: return [2 /*return*/, _d.sent()];
241
+ case 2: return [4 /*yield*/, axios_1.default.post("".concat(this.baseURL, "/v1/chat/completions"), {
242
+ model: request.model || this.modelName,
243
+ messages: request.messages,
244
+ max_tokens: maxTokens,
245
+ temperature: temperature,
246
+ stream: false,
247
+ }, {
248
+ headers: {
249
+ 'Authorization': "Bearer ".concat(this.apiKey),
250
+ 'Content-Type': 'application/json',
251
+ },
252
+ timeout: 60000, // 60 秒超时
253
+ })];
254
+ case 3:
255
+ response = _d.sent();
256
+ return [2 /*return*/, response.data];
257
+ }
258
+ });
259
+ });
260
+ };
261
+ /**
262
+ * 流式聊天请求
263
+ */
264
+ EnhancedLLMService.prototype.chatRequestStream = function (request, maxTokens, temperature) {
265
+ return __awaiter(this, void 0, void 0, function () {
266
+ var response, fullContent, finishReason, promptTokens, completionTokens, totalTokens;
267
+ var _this = this;
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0:
271
+ logger.debug('Starting stream request', {
272
+ model: request.model || this.modelName,
273
+ });
274
+ return [4 /*yield*/, axios_1.default.post("".concat(this.baseURL, "/v1/chat/completions"), {
275
+ model: request.model || this.modelName,
276
+ messages: request.messages,
277
+ max_tokens: maxTokens,
278
+ temperature: temperature,
279
+ stream: true,
280
+ }, {
281
+ headers: {
282
+ 'Authorization': "Bearer ".concat(this.apiKey),
283
+ 'Content-Type': 'application/json',
284
+ },
285
+ responseType: 'stream',
286
+ timeout: 120000, // 流式请求超时时间更长
287
+ })];
288
+ case 1:
289
+ response = _a.sent();
290
+ fullContent = '';
291
+ finishReason = null;
292
+ promptTokens = 0;
293
+ completionTokens = 0;
294
+ totalTokens = 0;
295
+ return [2 /*return*/, new Promise(function (resolve, reject) {
296
+ var chunks = [];
297
+ response.data.on('data', function (chunk) {
298
+ var _a, _b, _c, _d;
299
+ chunks.push(chunk);
300
+ // 解析 SSE 数据
301
+ var chunkStr = chunk.toString('utf-8');
302
+ var lines = chunkStr.split('\n').filter(function (line) { return line.trim() !== ''; });
303
+ for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
304
+ var line = lines_1[_i];
305
+ if (line.startsWith('data: ')) {
306
+ var data = line.slice(6);
307
+ if (data === '[DONE]') {
308
+ continue;
309
+ }
310
+ try {
311
+ var parsed = JSON.parse(data);
312
+ var delta = (_b = (_a = parsed.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.delta;
313
+ if (delta === null || delta === void 0 ? void 0 : delta.content) {
314
+ fullContent += delta.content;
315
+ }
316
+ if ((_d = (_c = parsed.choices) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.finish_reason) {
317
+ finishReason = parsed.choices[0].finish_reason;
318
+ }
319
+ // 从最后一个 chunk 获取 usage 信息
320
+ if (parsed.usage) {
321
+ promptTokens = parsed.usage.prompt_tokens || 0;
322
+ completionTokens = parsed.usage.completion_tokens || 0;
323
+ totalTokens = parsed.usage.total_tokens || 0;
324
+ }
325
+ }
326
+ catch (error) {
327
+ // 忽略解析错误(可能是空行或其他格式)
328
+ }
329
+ }
330
+ }
331
+ });
332
+ response.data.on('end', function () {
333
+ logger.debug('Stream request completed', {
334
+ contentLength: fullContent.length,
335
+ finishReason: finishReason,
336
+ });
337
+ // 构造标准响应格式
338
+ resolve({
339
+ id: "chatcmpl-".concat(Date.now()),
340
+ object: 'chat.completion',
341
+ created: Math.floor(Date.now() / 1000),
342
+ model: request.model || _this.modelName,
343
+ choices: [{
344
+ index: 0,
345
+ message: {
346
+ role: 'assistant',
347
+ content: fullContent,
348
+ },
349
+ finishReason: finishReason,
350
+ }],
351
+ usage: {
352
+ promptTokens: promptTokens,
353
+ completionTokens: completionTokens,
354
+ totalTokens: totalTokens,
355
+ },
356
+ });
357
+ });
358
+ response.data.on('error', function (error) {
359
+ logger.error('Stream request error', { error: error.message });
360
+ reject(error);
361
+ });
362
+ })];
363
+ }
364
+ });
365
+ });
366
+ };
367
+ /**
368
+ * 判断是否应该重试
369
+ */
370
+ EnhancedLLMService.prototype.shouldRetry = function (error, attempt) {
371
+ // 超过最大重试次数
372
+ if (attempt >= this.retryConfig.maxRetries) {
373
+ return false;
374
+ }
375
+ // 网络错误或超时
376
+ if (axios_1.default.isAxiosError(error)) {
377
+ var axiosError = error;
378
+ var isRetryable = !axiosError.response || // 无响应(网络错误)
379
+ axiosError.response.status >= 500 || // 服务器错误
380
+ axiosError.response.status === 429; // 限流
381
+ return isRetryable;
382
+ }
383
+ // 其他错误不重试
384
+ return false;
385
+ };
386
+ /**
387
+ * 计算重试延迟(指数退避)
388
+ */
389
+ EnhancedLLMService.prototype.calculateRetryDelay = function (attempt) {
390
+ var delay = Math.min(this.retryConfig.initialDelay * Math.pow(this.retryConfig.backoffMultiplier, attempt), this.retryConfig.maxDelay);
391
+ return delay;
392
+ };
393
+ /**
394
+ * 计算 Token 成本
395
+ */
396
+ EnhancedLLMService.prototype.calculateCost = function (tokensIn, tokensOut, modelName) {
397
+ if (modelName === void 0) { modelName = this.modelName; }
398
+ var config = COST_CONFIG.deepseek[modelName];
399
+ if (!config) {
400
+ logger.warn("No cost config found for model: ".concat(modelName));
401
+ return 0;
402
+ }
403
+ var costIn = (tokensIn / 1000) * config.costPer1kTokensIn;
404
+ var costOut = (tokensOut / 1000) * config.costPer1kTokensOut;
405
+ return Number((costIn + costOut).toFixed(6));
406
+ };
407
+ /**
408
+ * 记录 Token 使用到数据库
409
+ */
410
+ EnhancedLLMService.prototype.recordTokenUsage = function (params) {
411
+ return __awaiter(this, void 0, void 0, function () {
412
+ var error_3;
413
+ return __generator(this, function (_a) {
414
+ switch (_a.label) {
415
+ case 0:
416
+ _a.trys.push([0, 2, , 3]);
417
+ return [4 /*yield*/, this.tokenUsageRepo.create({
418
+ taskId: params.taskId,
419
+ traceId: this.generateTraceId(),
420
+ stepName: params.stepName,
421
+ apiName: 'deepseek',
422
+ modelName: this.modelName,
423
+ tokensIn: params.tokensIn,
424
+ tokensOut: params.tokensOut,
425
+ totalTokens: params.totalTokens,
426
+ costPer1kTokensIn: params.costPer1kTokensIn,
427
+ costPer1kTokensOut: params.costPer1kTokensOut,
428
+ totalCost: params.totalCost,
429
+ metadata: {
430
+ duration: params.duration,
431
+ temperature: this.temperature,
432
+ maxTokens: this.maxTokens,
433
+ },
434
+ })];
435
+ case 1:
436
+ _a.sent();
437
+ logger.debug('Token usage recorded', {
438
+ taskId: params.taskId,
439
+ stepName: params.stepName,
440
+ totalTokens: params.totalTokens,
441
+ cost: params.totalCost,
442
+ });
443
+ return [3 /*break*/, 3];
444
+ case 2:
445
+ error_3 = _a.sent();
446
+ logger.error('Failed to record token usage', {
447
+ error: error_3 instanceof Error ? error_3.message : String(error_3),
448
+ });
449
+ return [3 /*break*/, 3];
450
+ case 3: return [2 /*return*/];
451
+ }
452
+ });
453
+ });
454
+ };
455
+ /**
456
+ * 生成 Trace ID(用于链路追踪)
457
+ */
458
+ EnhancedLLMService.prototype.generateTraceId = function () {
459
+ return "trace_".concat(Date.now(), "_").concat(Math.random().toString(36).substring(2, 15));
460
+ };
461
+ /**
462
+ * 延迟函数
463
+ */
464
+ EnhancedLLMService.prototype.sleep = function (ms) {
465
+ return new Promise(function (resolve) { return setTimeout(resolve, ms); });
466
+ };
467
+ /**
468
+ * 生成文本(简化接口)
469
+ */
470
+ EnhancedLLMService.prototype.generateText = function (prompt, systemPrompt, options) {
471
+ return __awaiter(this, void 0, void 0, function () {
472
+ var messages, result;
473
+ return __generator(this, function (_a) {
474
+ switch (_a.label) {
475
+ case 0:
476
+ messages = [];
477
+ if (systemPrompt) {
478
+ messages.push({ role: 'system', content: systemPrompt });
479
+ }
480
+ messages.push({ role: 'user', content: prompt });
481
+ return [4 /*yield*/, this.chat({
482
+ messages: messages,
483
+ taskId: options === null || options === void 0 ? void 0 : options.taskId,
484
+ stepName: options === null || options === void 0 ? void 0 : options.stepName,
485
+ })];
486
+ case 1:
487
+ result = _a.sent();
488
+ return [2 /*return*/, result.content];
489
+ }
490
+ });
491
+ });
492
+ };
493
+ /**
494
+ * 健康检查
495
+ */
496
+ EnhancedLLMService.prototype.healthCheck = function () {
497
+ return __awaiter(this, void 0, void 0, function () {
498
+ var error_4;
499
+ return __generator(this, function (_a) {
500
+ switch (_a.label) {
501
+ case 0:
502
+ _a.trys.push([0, 2, , 3]);
503
+ return [4 /*yield*/, this.chat({
504
+ messages: [{ role: 'user', content: 'test' }],
505
+ maxTokens: 1,
506
+ })];
507
+ case 1:
508
+ _a.sent();
509
+ logger.info('LLM service health check passed');
510
+ return [2 /*return*/, true];
511
+ case 2:
512
+ error_4 = _a.sent();
513
+ logger.error('LLM service health check failed', error_4);
514
+ return [2 /*return*/, false];
515
+ case 3: return [2 /*return*/];
516
+ }
517
+ });
518
+ });
519
+ };
520
+ /**
521
+ * 计算文本的 Token 数量(估算)
522
+ */
523
+ EnhancedLLMService.prototype.estimateTokens = function (text) {
524
+ // 粗略估算:英文约 4 字符/token,中文约 1.5 字符/token
525
+ var chineseChars = (text.match(/[\u4e00-\u9fa5]/g) || []).length;
526
+ var englishChars = text.length - chineseChars;
527
+ return Math.ceil(chineseChars / 1.5 + englishChars / 4);
528
+ };
529
+ /**
530
+ * 估算成本(未调用 API)
531
+ */
532
+ EnhancedLLMService.prototype.estimateCost = function (tokensIn, tokensOut) {
533
+ return this.calculateCost(tokensIn, tokensOut, this.modelName);
534
+ };
535
+ return EnhancedLLMService;
536
+ }());
537
+ exports.EnhancedLLMService = EnhancedLLMService;
538
+ /**
539
+ * Token Usage Repository(临时实现,后续使用真实的 Repository)
540
+ */
541
+ var TempTokenUsageRepository = /** @class */ (function () {
542
+ function TempTokenUsageRepository() {
543
+ }
544
+ TempTokenUsageRepository.prototype.create = function (params) {
545
+ return __awaiter(this, void 0, void 0, function () {
546
+ return __generator(this, function (_a) {
547
+ // TODO: 实现真实的数据库保存
548
+ // 目前只记录日志
549
+ logger.debug('Token usage would be saved to database', params);
550
+ return [2 /*return*/];
551
+ });
552
+ });
553
+ };
554
+ return TempTokenUsageRepository;
555
+ }());
556
+ /**
557
+ * 增强的 LLM 服务单例
558
+ */
559
+ exports.enhancedLLMService = new EnhancedLLMService();
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Content Creator 工具库
3
+ *
4
+ * 提供 AI 驱动的内容创作功能的核心库
5
+ */
6
+ export * from './config/index.js';
7
+ export * from './infrastructure/database/index.js';
8
+ export * from './domain/workflow/ContentCreatorGraph.js';
9
+ export * from './domain/workflow/State.js';
10
+ export * from './domain/workflow/CheckpointManager.js';
11
+ export * from './domain/workflow/nodes/index.js';
12
+ export * from './domain/entities/index.js';
13
+ export * from './domain/repositories/TaskRepository.js';
14
+ export * from './domain/repositories/ResultRepository.js';
15
+ export * from './domain/repositories/QualityCheckRepository.js';
16
+ export * from './application/workflow/SyncExecutor.js';
17
+ export * from './infrastructure/cache/index.js';
18
+ export * from './infrastructure/queue/index.js';
19
+ export * from './infrastructure/monitoring/index.js';
20
+ export * from './infrastructure/security/index.js';
21
+ export * from './infrastructure/logging/logger.js';
22
+ export * from './schedulers/TaskScheduler.js';
23
+ export * from './workers/TaskWorker.js';
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,mBAAmB,CAAC;AAGlC,cAAc,oCAAoC,CAAC;AAGnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AAGvD,cAAc,kCAAkC,CAAC;AAGjD,cAAc,4BAA4B,CAAC;AAG3C,cAAc,yCAAyC,CAAC;AACxD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iDAAiD,CAAC;AAGhE,cAAc,wCAAwC,CAAC;AAGvD,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AAGnD,cAAc,+BAA+B,CAAC;AAG9C,cAAc,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Content Creator 工具库
3
+ *
4
+ * 提供 AI 驱动的内容创作功能的核心库
5
+ */
6
+ // 导出配置系统
7
+ export * from './config/index.js';
8
+ // 导出数据库层
9
+ export * from './infrastructure/database/index.js';
10
+ // 导出工作流系统
11
+ export * from './domain/workflow/ContentCreatorGraph.js';
12
+ export * from './domain/workflow/State.js';
13
+ export * from './domain/workflow/CheckpointManager.js';
14
+ // 导出工作流节点
15
+ export * from './domain/workflow/nodes/index.js';
16
+ // 导出领域实体
17
+ export * from './domain/entities/index.js';
18
+ // 导出领域仓库
19
+ export * from './domain/repositories/TaskRepository.js';
20
+ export * from './domain/repositories/ResultRepository.js';
21
+ export * from './domain/repositories/QualityCheckRepository.js';
22
+ // 导出应用层服务
23
+ export * from './application/workflow/SyncExecutor.js';
24
+ // 导出基础设施服务
25
+ export * from './infrastructure/cache/index.js';
26
+ export * from './infrastructure/queue/index.js';
27
+ export * from './infrastructure/monitoring/index.js';
28
+ export * from './infrastructure/security/index.js';
29
+ export * from './infrastructure/logging/logger.js';
30
+ // 导出调度器
31
+ export * from './schedulers/TaskScheduler.js';
32
+ // 导出工作者
33
+ export * from './workers/TaskWorker.js';
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,SAAS;AACT,cAAc,mBAAmB,CAAC;AAElC,SAAS;AACT,cAAc,oCAAoC,CAAC;AAEnD,UAAU;AACV,cAAc,0CAA0C,CAAC;AACzD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AAEvD,UAAU;AACV,cAAc,kCAAkC,CAAC;AAEjD,SAAS;AACT,cAAc,4BAA4B,CAAC;AAE3C,SAAS;AACT,cAAc,yCAAyC,CAAC;AACxD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iDAAiD,CAAC;AAEhE,UAAU;AACV,cAAc,wCAAwC,CAAC;AAEvD,WAAW;AACX,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AAEnD,QAAQ;AACR,cAAc,+BAA+B,CAAC;AAE9C,QAAQ;AACR,cAAc,yBAAyB,CAAC"}