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.
- package/README.md +309 -0
- package/dist/application/workflow/SyncExecutor.d.ts +75 -0
- package/dist/application/workflow/SyncExecutor.d.ts.map +1 -0
- package/dist/application/workflow/SyncExecutor.js +370 -0
- package/dist/application/workflow/SyncExecutor.js.map +1 -0
- package/dist/application/workflow/types.d.ts +46 -0
- package/dist/application/workflow/types.d.ts.map +1 -0
- package/dist/application/workflow/types.js +7 -0
- package/dist/application/workflow/types.js.map +1 -0
- package/dist/config/index.d.ts +173 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +288 -0
- package/dist/config/index.js.map +1 -0
- package/dist/domain/entities/QualityCheck.d.ts +181 -0
- package/dist/domain/entities/QualityCheck.d.ts.map +1 -0
- package/dist/domain/entities/QualityCheck.js +39 -0
- package/dist/domain/entities/QualityCheck.js.map +1 -0
- package/dist/domain/entities/Result.d.ts +103 -0
- package/dist/domain/entities/Result.d.ts.map +1 -0
- package/dist/domain/entities/Result.js +15 -0
- package/dist/domain/entities/Result.js.map +1 -0
- package/dist/domain/entities/Task.d.ts +130 -0
- package/dist/domain/entities/Task.d.ts.map +1 -0
- package/dist/domain/entities/Task.js +64 -0
- package/dist/domain/entities/Task.js.map +1 -0
- package/dist/domain/entities/TaskStep.d.ts +160 -0
- package/dist/domain/entities/TaskStep.d.ts.map +1 -0
- package/dist/domain/entities/TaskStep.js +30 -0
- package/dist/domain/entities/TaskStep.js.map +1 -0
- package/dist/domain/entities/TokenUsage.d.ts +70 -0
- package/dist/domain/entities/TokenUsage.d.ts.map +1 -0
- package/dist/domain/entities/TokenUsage.js +42 -0
- package/dist/domain/entities/TokenUsage.js.map +1 -0
- package/dist/domain/entities/index.d.ts +11 -0
- package/dist/domain/entities/index.d.ts.map +1 -0
- package/dist/domain/entities/index.js +16 -0
- package/dist/domain/entities/index.js.map +1 -0
- package/dist/domain/repositories/QualityCheckRepository.d.ts +49 -0
- package/dist/domain/repositories/QualityCheckRepository.d.ts.map +1 -0
- package/dist/domain/repositories/QualityCheckRepository.js +5 -0
- package/dist/domain/repositories/QualityCheckRepository.js.map +1 -0
- package/dist/domain/repositories/ResultRepository.d.ts +43 -0
- package/dist/domain/repositories/ResultRepository.d.ts.map +1 -0
- package/dist/domain/repositories/ResultRepository.js +5 -0
- package/dist/domain/repositories/ResultRepository.js.map +1 -0
- package/dist/domain/repositories/TaskRepository.d.ts +240 -0
- package/dist/domain/repositories/TaskRepository.d.ts.map +1 -0
- package/dist/domain/repositories/TaskRepository.js +7 -0
- package/dist/domain/repositories/TaskRepository.js.map +1 -0
- package/dist/domain/workflow/CheckpointManager.d.ts +94 -0
- package/dist/domain/workflow/CheckpointManager.d.ts.map +1 -0
- package/dist/domain/workflow/CheckpointManager.js +224 -0
- package/dist/domain/workflow/CheckpointManager.js.map +1 -0
- package/dist/domain/workflow/ContentCreatorGraph.d.ts +17 -0
- package/dist/domain/workflow/ContentCreatorGraph.d.ts.map +1 -0
- package/dist/domain/workflow/ContentCreatorGraph.js +381 -0
- package/dist/domain/workflow/ContentCreatorGraph.js.map +1 -0
- package/dist/domain/workflow/State.d.ts +172 -0
- package/dist/domain/workflow/State.d.ts.map +1 -0
- package/dist/domain/workflow/State.js +184 -0
- package/dist/domain/workflow/State.js.map +1 -0
- package/dist/domain/workflow/index.d.ts +11 -0
- package/dist/domain/workflow/index.d.ts.map +1 -0
- package/dist/domain/workflow/index.js +15 -0
- package/dist/domain/workflow/index.js.map +1 -0
- package/dist/domain/workflow/nodes/BaseNode.d.ts +134 -0
- package/dist/domain/workflow/nodes/BaseNode.d.ts.map +1 -0
- package/dist/domain/workflow/nodes/BaseNode.js +253 -0
- package/dist/domain/workflow/nodes/BaseNode.js.map +1 -0
- package/dist/domain/workflow/nodes/CheckImageNode.d.ts +43 -0
- package/dist/domain/workflow/nodes/CheckImageNode.d.ts.map +1 -0
- package/dist/domain/workflow/nodes/CheckImageNode.js +254 -0
- package/dist/domain/workflow/nodes/CheckImageNode.js.map +1 -0
- package/dist/domain/workflow/nodes/CheckTextNode.d.ts +66 -0
- package/dist/domain/workflow/nodes/CheckTextNode.d.ts.map +1 -0
- package/dist/domain/workflow/nodes/CheckTextNode.js +530 -0
- package/dist/domain/workflow/nodes/CheckTextNode.js.map +1 -0
- package/dist/domain/workflow/nodes/GenerateImageNode.d.ts +44 -0
- package/dist/domain/workflow/nodes/GenerateImageNode.d.ts.map +1 -0
- package/dist/domain/workflow/nodes/GenerateImageNode.js +272 -0
- package/dist/domain/workflow/nodes/GenerateImageNode.js.map +1 -0
- package/dist/domain/workflow/nodes/OrganizeNode.d.ts +49 -0
- package/dist/domain/workflow/nodes/OrganizeNode.d.ts.map +1 -0
- package/dist/domain/workflow/nodes/OrganizeNode.js +241 -0
- package/dist/domain/workflow/nodes/OrganizeNode.js.map +1 -0
- package/dist/domain/workflow/nodes/SearchNode.d.ts +48 -0
- package/dist/domain/workflow/nodes/SearchNode.d.ts.map +1 -0
- package/dist/domain/workflow/nodes/SearchNode.js +151 -0
- package/dist/domain/workflow/nodes/SearchNode.js.map +1 -0
- package/dist/domain/workflow/nodes/WriteNode.d.ts +68 -0
- package/dist/domain/workflow/nodes/WriteNode.d.ts.map +1 -0
- package/dist/domain/workflow/nodes/WriteNode.js +431 -0
- package/dist/domain/workflow/nodes/WriteNode.js.map +1 -0
- package/dist/domain/workflow/nodes/config/index.js +287 -0
- package/dist/domain/workflow/nodes/domain/entities/Task.js +68 -0
- package/dist/domain/workflow/nodes/domain/workflow/State.js +200 -0
- package/dist/domain/workflow/nodes/domain/workflow/nodes/BaseNode.js +328 -0
- package/dist/domain/workflow/nodes/domain/workflow/nodes/CheckTextNode.js +500 -0
- package/dist/domain/workflow/nodes/index.d.ts +13 -0
- package/dist/domain/workflow/nodes/index.d.ts.map +1 -0
- package/dist/domain/workflow/nodes/index.js +13 -0
- package/dist/domain/workflow/nodes/index.js.map +1 -0
- package/dist/domain/workflow/nodes/infrastructure/logging/logger.js +275 -0
- package/dist/domain/workflow/nodes/services/llm/EnhancedLLMService.js +559 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/cache/CacheService.d.ts +139 -0
- package/dist/infrastructure/cache/CacheService.d.ts.map +1 -0
- package/dist/infrastructure/cache/CacheService.js +419 -0
- package/dist/infrastructure/cache/CacheService.js.map +1 -0
- package/dist/infrastructure/cache/index.d.ts +5 -0
- package/dist/infrastructure/cache/index.d.ts.map +1 -0
- package/dist/infrastructure/cache/index.js +6 -0
- package/dist/infrastructure/cache/index.js.map +1 -0
- package/dist/infrastructure/database/BaseRepository.d.ts +98 -0
- package/dist/infrastructure/database/BaseRepository.d.ts.map +1 -0
- package/dist/infrastructure/database/BaseRepository.js +178 -0
- package/dist/infrastructure/database/BaseRepository.js.map +1 -0
- package/dist/infrastructure/database/MemoryTaskRepository.d.ts +77 -0
- package/dist/infrastructure/database/MemoryTaskRepository.d.ts.map +1 -0
- package/dist/infrastructure/database/MemoryTaskRepository.js +309 -0
- package/dist/infrastructure/database/MemoryTaskRepository.js.map +1 -0
- package/dist/infrastructure/database/PostgresQualityCheckRepository.d.ts +36 -0
- package/dist/infrastructure/database/PostgresQualityCheckRepository.d.ts.map +1 -0
- package/dist/infrastructure/database/PostgresQualityCheckRepository.js +89 -0
- package/dist/infrastructure/database/PostgresQualityCheckRepository.js.map +1 -0
- package/dist/infrastructure/database/PostgresTaskRepository.d.ts +94 -0
- package/dist/infrastructure/database/PostgresTaskRepository.d.ts.map +1 -0
- package/dist/infrastructure/database/PostgresTaskRepository.js +364 -0
- package/dist/infrastructure/database/PostgresTaskRepository.js.map +1 -0
- package/dist/infrastructure/database/ResultRepository.d.ts +41 -0
- package/dist/infrastructure/database/ResultRepository.d.ts.map +1 -0
- package/dist/infrastructure/database/ResultRepository.js +86 -0
- package/dist/infrastructure/database/ResultRepository.js.map +1 -0
- package/dist/infrastructure/database/SQLiteTaskRepository.d.ts +101 -0
- package/dist/infrastructure/database/SQLiteTaskRepository.d.ts.map +1 -0
- package/dist/infrastructure/database/SQLiteTaskRepository.js +548 -0
- package/dist/infrastructure/database/SQLiteTaskRepository.js.map +1 -0
- package/dist/infrastructure/database/index.d.ts +32 -0
- package/dist/infrastructure/database/index.d.ts.map +1 -0
- package/dist/infrastructure/database/index.js +72 -0
- package/dist/infrastructure/database/index.js.map +1 -0
- package/dist/infrastructure/logging/logger.d.ts +69 -0
- package/dist/infrastructure/logging/logger.d.ts.map +1 -0
- package/dist/infrastructure/logging/logger.js +169 -0
- package/dist/infrastructure/logging/logger.js.map +1 -0
- package/dist/infrastructure/monitoring/LoggingService.d.ts +109 -0
- package/dist/infrastructure/monitoring/LoggingService.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/LoggingService.js +198 -0
- package/dist/infrastructure/monitoring/LoggingService.js.map +1 -0
- package/dist/infrastructure/monitoring/MetricsService.d.ts +112 -0
- package/dist/infrastructure/monitoring/MetricsService.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/MetricsService.js +362 -0
- package/dist/infrastructure/monitoring/MetricsService.js.map +1 -0
- package/dist/infrastructure/monitoring/SentryService.d.ts +108 -0
- package/dist/infrastructure/monitoring/SentryService.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/SentryService.js +282 -0
- package/dist/infrastructure/monitoring/SentryService.js.map +1 -0
- package/dist/infrastructure/monitoring/index.d.ts +7 -0
- package/dist/infrastructure/monitoring/index.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/index.js +10 -0
- package/dist/infrastructure/monitoring/index.js.map +1 -0
- package/dist/infrastructure/queue/TaskQueue.d.ts +110 -0
- package/dist/infrastructure/queue/TaskQueue.d.ts.map +1 -0
- package/dist/infrastructure/queue/TaskQueue.js +363 -0
- package/dist/infrastructure/queue/TaskQueue.js.map +1 -0
- package/dist/infrastructure/queue/index.d.ts +5 -0
- package/dist/infrastructure/queue/index.d.ts.map +1 -0
- package/dist/infrastructure/queue/index.js +5 -0
- package/dist/infrastructure/queue/index.js.map +1 -0
- package/dist/infrastructure/redis/connection.d.ts +61 -0
- package/dist/infrastructure/redis/connection.d.ts.map +1 -0
- package/dist/infrastructure/redis/connection.js +184 -0
- package/dist/infrastructure/redis/connection.js.map +1 -0
- package/dist/infrastructure/redis/index.d.ts +5 -0
- package/dist/infrastructure/redis/index.d.ts.map +1 -0
- package/dist/infrastructure/redis/index.js +5 -0
- package/dist/infrastructure/redis/index.js.map +1 -0
- package/dist/infrastructure/security/ApiKeyService.d.ts +103 -0
- package/dist/infrastructure/security/ApiKeyService.d.ts.map +1 -0
- package/dist/infrastructure/security/ApiKeyService.js +250 -0
- package/dist/infrastructure/security/ApiKeyService.js.map +1 -0
- package/dist/infrastructure/security/QuotaService.d.ts +87 -0
- package/dist/infrastructure/security/QuotaService.d.ts.map +1 -0
- package/dist/infrastructure/security/QuotaService.js +303 -0
- package/dist/infrastructure/security/QuotaService.js.map +1 -0
- package/dist/infrastructure/security/RateLimiter.d.ts +104 -0
- package/dist/infrastructure/security/RateLimiter.d.ts.map +1 -0
- package/dist/infrastructure/security/RateLimiter.js +331 -0
- package/dist/infrastructure/security/RateLimiter.js.map +1 -0
- package/dist/infrastructure/security/index.d.ts +7 -0
- package/dist/infrastructure/security/index.d.ts.map +1 -0
- package/dist/infrastructure/security/index.js +10 -0
- package/dist/infrastructure/security/index.js.map +1 -0
- package/dist/monitoring/index.d.ts +5 -0
- package/dist/monitoring/index.d.ts.map +1 -0
- package/dist/monitoring/index.js +5 -0
- package/dist/monitoring/index.js.map +1 -0
- package/dist/monitoring/server.d.ts +14 -0
- package/dist/monitoring/server.d.ts.map +1 -0
- package/dist/monitoring/server.js +99 -0
- package/dist/monitoring/server.js.map +1 -0
- package/dist/presentation/cli/commands/cancel.d.ts +8 -0
- package/dist/presentation/cli/commands/cancel.d.ts.map +1 -0
- package/dist/presentation/cli/commands/cancel.js +57 -0
- package/dist/presentation/cli/commands/cancel.js.map +1 -0
- package/dist/presentation/cli/commands/create.d.ts +8 -0
- package/dist/presentation/cli/commands/create.d.ts.map +1 -0
- package/dist/presentation/cli/commands/create.js +368 -0
- package/dist/presentation/cli/commands/create.js.map +1 -0
- package/dist/presentation/cli/commands/result.d.ts +8 -0
- package/dist/presentation/cli/commands/result.d.ts.map +1 -0
- package/dist/presentation/cli/commands/result.js +121 -0
- package/dist/presentation/cli/commands/result.js.map +1 -0
- package/dist/presentation/cli/commands/status.d.ts +8 -0
- package/dist/presentation/cli/commands/status.d.ts.map +1 -0
- package/dist/presentation/cli/commands/status.js +92 -0
- package/dist/presentation/cli/commands/status.js.map +1 -0
- package/dist/presentation/cli/index.d.ts +8 -0
- package/dist/presentation/cli/index.d.ts.map +1 -0
- package/dist/presentation/cli/index.js +32 -0
- package/dist/presentation/cli/index.js.map +1 -0
- package/dist/presentation/cli/utils/cleanup.d.ts +14 -0
- package/dist/presentation/cli/utils/cleanup.d.ts.map +1 -0
- package/dist/presentation/cli/utils/cleanup.js +62 -0
- package/dist/presentation/cli/utils/cleanup.js.map +1 -0
- package/dist/presentation/cli/utils/formatter.d.ts +28 -0
- package/dist/presentation/cli/utils/formatter.d.ts.map +1 -0
- package/dist/presentation/cli/utils/formatter.js +68 -0
- package/dist/presentation/cli/utils/formatter.js.map +1 -0
- package/dist/presentation/cli.d.ts +7 -0
- package/dist/presentation/cli.d.ts.map +1 -0
- package/dist/presentation/cli.js +8 -0
- package/dist/presentation/cli.js.map +1 -0
- package/dist/presentation/monitor-cli.d.ts +8 -0
- package/dist/presentation/monitor-cli.d.ts.map +1 -0
- package/dist/presentation/monitor-cli.js +44 -0
- package/dist/presentation/monitor-cli.js.map +1 -0
- package/dist/presentation/worker-cli.d.ts +8 -0
- package/dist/presentation/worker-cli.d.ts.map +1 -0
- package/dist/presentation/worker-cli.js +51 -0
- package/dist/presentation/worker-cli.js.map +1 -0
- package/dist/schedulers/TaskScheduler.d.ts +99 -0
- package/dist/schedulers/TaskScheduler.d.ts.map +1 -0
- package/dist/schedulers/TaskScheduler.js +233 -0
- package/dist/schedulers/TaskScheduler.js.map +1 -0
- package/dist/schedulers/index.d.ts +5 -0
- package/dist/schedulers/index.d.ts.map +1 -0
- package/dist/schedulers/index.js +5 -0
- package/dist/schedulers/index.js.map +1 -0
- package/dist/services/image/ImageService.d.ts +68 -0
- package/dist/services/image/ImageService.d.ts.map +1 -0
- package/dist/services/image/ImageService.js +166 -0
- package/dist/services/image/ImageService.js.map +1 -0
- package/dist/services/index.d.ts +8 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +12 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/llm/EnhancedLLMService.d.ts +148 -0
- package/dist/services/llm/EnhancedLLMService.d.ts.map +1 -0
- package/dist/services/llm/EnhancedLLMService.js +425 -0
- package/dist/services/llm/EnhancedLLMService.js.map +1 -0
- package/dist/services/llm/LLMService.d.ts +103 -0
- package/dist/services/llm/LLMService.d.ts.map +1 -0
- package/dist/services/llm/LLMService.js +212 -0
- package/dist/services/llm/LLMService.js.map +1 -0
- package/dist/services/quality/HardRuleChecker.d.ts +143 -0
- package/dist/services/quality/HardRuleChecker.d.ts.map +1 -0
- package/dist/services/quality/HardRuleChecker.js +353 -0
- package/dist/services/quality/HardRuleChecker.js.map +1 -0
- package/dist/services/quality/LLMEvaluator.d.ts +105 -0
- package/dist/services/quality/LLMEvaluator.d.ts.map +1 -0
- package/dist/services/quality/LLMEvaluator.js +312 -0
- package/dist/services/quality/LLMEvaluator.js.map +1 -0
- package/dist/services/quality/QualityCheckService.d.ts +112 -0
- package/dist/services/quality/QualityCheckService.d.ts.map +1 -0
- package/dist/services/quality/QualityCheckService.js +342 -0
- package/dist/services/quality/QualityCheckService.js.map +1 -0
- package/dist/services/quality/QualityService.d.ts +75 -0
- package/dist/services/quality/QualityService.d.ts.map +1 -0
- package/dist/services/quality/QualityService.js +360 -0
- package/dist/services/quality/QualityService.js.map +1 -0
- package/dist/services/quality/index.d.ts +7 -0
- package/dist/services/quality/index.d.ts.map +1 -0
- package/dist/services/quality/index.js +10 -0
- package/dist/services/quality/index.js.map +1 -0
- package/dist/services/search/SearchService.d.ts +79 -0
- package/dist/services/search/SearchService.d.ts.map +1 -0
- package/dist/services/search/SearchService.js +193 -0
- package/dist/services/search/SearchService.js.map +1 -0
- package/dist/workers/TaskWorker.d.ts +61 -0
- package/dist/workers/TaskWorker.d.ts.map +1 -0
- package/dist/workers/TaskWorker.js +256 -0
- package/dist/workers/TaskWorker.js.map +1 -0
- package/dist/workers/index.d.ts +5 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +5 -0
- package/dist/workers/index.js.map +1 -0
- package/docs/DOCUMENTATION-ANALYSIS.md +190 -0
- package/docs/README.md +145 -0
- package/docs/SOURCE-CODE-ANALYSIS.md +1107 -0
- package/docs/architecture-complete.md +5524 -0
- package/docs/archive/implementation/implementation-analysis/README.md +244 -0
- package/docs/archive/implementation/implementation-analysis/implementation-analysis-context.md +483 -0
- package/docs/archive/implementation/implementation-analysis/implementation-analysis-plan.md +1242 -0
- package/docs/archive/implementation/implementation-analysis/implementation-analysis-tasks.md +777 -0
- package/docs/archive/phases/phase-1/phase-1-completion-summary.md +284 -0
- package/docs/archive/phases/phase-1/phase-1-implementation-guide.md +1380 -0
- package/docs/archive/phases/phase-2/phase-2a/phase-2a-completion-summary.md +443 -0
- package/docs/archive/phases/phase-2/phase-2b/phase-2b-completion-report.md +430 -0
- package/docs/archive/phases/phase-2/phase-2b/phase-2b-completion-summary.md +592 -0
- package/docs/archive/phases/phase-2/phase-2b/phase-2b-final-summary.md +371 -0
- package/docs/archive/phases/phase-2/phase-2b/phase-2b-preparation-complete.md +343 -0
- package/docs/archive/phases/phase-2/phase-2b/phase-2b-preparation.md +945 -0
- package/docs/archive/phases/phase-2/phase-2b/phase-2b-progress-update.md +366 -0
- package/docs/archive/phases/phase-3/phase-3-completion-summary.md +354 -0
- package/docs/archive/phases/phase-3/phase-3-development-plan.md +878 -0
- package/docs/archive/phases/phase-3/phase-3-quick-start.md +324 -0
- package/docs/archive/phases/phase-4/phase-4-completion-summary.md +708 -0
- package/docs/archive/phases/phase-4/phase-4-development-plan.md +740 -0
- package/docs/archive/phases/phase-4/phase-4-quick-start.md +632 -0
- package/docs/archive/phases/phase-4/phase-4-session-3-security-testing.md +484 -0
- package/docs/archive/phases/phase-4/phase-4-session-4-unit-tests.md +550 -0
- package/docs/archive/phases/phase-4/phase-4-session-5-security-tests.md +564 -0
- package/docs/archive/phases/phase-4/phase-4-session-6-cache-integration.md +456 -0
- package/docs/archive/phases/phase-4/phase-4-session-7-test-fixes.md +348 -0
- package/docs/archive/phases/phase-4/phase-4-session-8-taskqueue-fixes.md +323 -0
- package/docs/archive/phases/phase-4/phase-4-session-summary-continued.md +373 -0
- package/docs/archive/phases/phase-4/phase-4-session-summary.md +595 -0
- package/docs/archive/reports/progress-reports/PHASE_0_PROGRESS.md +242 -0
- package/docs/archive/reports/progress-reports/PHASE_0_SUMMARY.md +262 -0
- package/docs/archive/reports/progress-reports/PHASE_1_2_ISSUES.md +399 -0
- package/docs/archive/reports/progress-reports/PHASE_1_PROGRESS.md +388 -0
- package/docs/archive/reports/progress-reports/PHASE_3_PREPARATION.md +574 -0
- package/docs/archive/reports/progress-reports/current-progress-update.md +294 -0
- package/docs/archive/reports/progress-reports/final-summary.md +215 -0
- package/docs/archive/reports/progress-reports/implementation-summary.md +287 -0
- package/docs/archive/reports/progress-reports/project-progress-report.md +440 -0
- package/docs/archive/reports/progress-reports/project-progress.md +386 -0
- package/docs/archive/reports/test-reports/TEST-COVERAGE-REPORT.md +441 -0
- package/docs/archive/reports/test-reports/e2e-test-report.md +293 -0
- package/docs/archive/reports/test-reports/final-test-report.md +367 -0
- package/docs/archive/reports/test-reports/real-env-test-report.md +391 -0
- package/docs/archive/reports/test-reports/test-completion-summary.md +356 -0
- package/docs/archive/reports/test-reports/test-report.md +371 -0
- package/docs/archive/sessions/session-2-summary.md +429 -0
- package/docs/archive/sessions/session-3-summary.md +395 -0
- package/docs/archive/sessions/session-summary.md +370 -0
- package/docs/config-system-update.md +239 -0
- package/docs/database-refactoring-PLAN.md +199 -0
- package/docs/database-refactoring-SUMMARY.md +384 -0
- package/docs/quality-check-architecture.md +1030 -0
- package/docs/quick-start.md +388 -0
- package/docs/references/bullmq-quick-reference.md +525 -0
- package/docs/references/monitoring-optimization-guide.md +871 -0
- package/docs/references/performance-optimization-guide.md +933 -0
- package/docs/storage-guide.md +612 -0
- package/docs/test-implementation-PLAN.md +223 -0
- package/docs/test-implementation-SUMMARY.md +194 -0
- package/docs/user-guide.md +719 -0
- package/docs/workflow-architecture.md +549 -0
- package/package.json +126 -0
- package/src/application/workflow/SyncExecutor.ts +444 -0
- package/src/application/workflow/types.ts +57 -0
- package/src/config/index.ts +352 -0
- package/src/domain/entities/QualityCheck.ts +202 -0
- package/src/domain/entities/Result.ts +130 -0
- package/src/domain/entities/Task.ts +178 -0
- package/src/domain/entities/TaskStep.ts +188 -0
- package/src/domain/entities/TokenUsage.ts +119 -0
- package/src/domain/entities/index.ts +20 -0
- package/src/domain/repositories/QualityCheckRepository.ts +52 -0
- package/src/domain/repositories/ResultRepository.ts +47 -0
- package/src/domain/repositories/TaskRepository.ts +271 -0
- package/src/domain/workflow/CheckpointManager.ts +283 -0
- package/src/domain/workflow/ContentCreatorGraph.ts +446 -0
- package/src/domain/workflow/State.ts +321 -0
- package/src/domain/workflow/index.ts +18 -0
- package/src/domain/workflow/nodes/BaseNode.ts +325 -0
- package/src/domain/workflow/nodes/CheckImageNode.ts +325 -0
- package/src/domain/workflow/nodes/CheckTextNode.ts +709 -0
- package/src/domain/workflow/nodes/GenerateImageNode.ts +342 -0
- package/src/domain/workflow/nodes/OrganizeNode.ts +304 -0
- package/src/domain/workflow/nodes/SearchNode.ts +192 -0
- package/src/domain/workflow/nodes/WriteNode.ts +505 -0
- package/src/domain/workflow/nodes/index.ts +13 -0
- package/src/index.ts +43 -0
- package/src/infrastructure/cache/CacheService.ts +483 -0
- package/src/infrastructure/cache/index.ts +6 -0
- package/src/infrastructure/database/BaseRepository.ts +214 -0
- package/src/infrastructure/database/MemoryTaskRepository.ts +377 -0
- package/src/infrastructure/database/PostgresQualityCheckRepository.ts +115 -0
- package/src/infrastructure/database/PostgresTaskRepository.ts +424 -0
- package/src/infrastructure/database/ResultRepository.ts +113 -0
- package/src/infrastructure/database/SQLiteTaskRepository.ts +651 -0
- package/src/infrastructure/database/index.ts +83 -0
- package/src/infrastructure/logging/logger.ts +231 -0
- package/src/infrastructure/monitoring/LoggingService.ts +292 -0
- package/src/infrastructure/monitoring/MetricsService.ts +468 -0
- package/src/infrastructure/monitoring/SentryService.ts +345 -0
- package/src/infrastructure/monitoring/index.ts +12 -0
- package/src/infrastructure/queue/TaskQueue.ts +429 -0
- package/src/infrastructure/queue/index.ts +5 -0
- package/src/infrastructure/redis/connection.ts +215 -0
- package/src/infrastructure/redis/index.ts +5 -0
- package/src/infrastructure/security/ApiKeyService.ts +340 -0
- package/src/infrastructure/security/QuotaService.ts +411 -0
- package/src/infrastructure/security/RateLimiter.ts +417 -0
- package/src/infrastructure/security/index.ts +12 -0
- package/src/monitoring/index.ts +5 -0
- package/src/monitoring/server.ts +109 -0
- package/src/presentation/cli/commands/cancel.ts +64 -0
- package/src/presentation/cli/commands/create.ts +400 -0
- package/src/presentation/cli/commands/result.ts +136 -0
- package/src/presentation/cli/commands/status.ts +102 -0
- package/src/presentation/cli/index.ts +39 -0
- package/src/presentation/cli/utils/cleanup.ts +65 -0
- package/src/presentation/cli/utils/formatter.ts +74 -0
- package/src/presentation/cli.ts +8 -0
- package/src/presentation/monitor-cli.ts +52 -0
- package/src/presentation/worker-cli.ts +62 -0
- package/src/schedulers/TaskScheduler.ts +314 -0
- package/src/schedulers/index.ts +11 -0
- package/src/services/image/ImageService.ts +221 -0
- package/src/services/index.ts +15 -0
- package/src/services/llm/EnhancedLLMService.ts +596 -0
- package/src/services/llm/LLMService.ts +310 -0
- package/src/services/quality/HardRuleChecker.ts +509 -0
- package/src/services/quality/LLMEvaluator.ts +400 -0
- package/src/services/quality/QualityCheckService.ts +473 -0
- package/src/services/quality/QualityService.ts +445 -0
- package/src/services/quality/index.ts +12 -0
- package/src/services/search/SearchService.ts +266 -0
- package/src/types/global.d.ts +17 -0
- package/src/workers/TaskWorker.ts +320 -0
- package/src/workers/index.ts +5 -0
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
# 阶段 4 开发完成总结
|
|
2
|
+
|
|
3
|
+
**日期**: 2026-01-19
|
|
4
|
+
**阶段**: 阶段 4 - 质量检查与监控优化
|
|
5
|
+
**状态**: ✅ 核心功能开发完成
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 📋 完成概览
|
|
10
|
+
|
|
11
|
+
### 已完成的核心模块(11/13)
|
|
12
|
+
|
|
13
|
+
| 步骤 | 任务 | 状态 | 说明 |
|
|
14
|
+
|------|------|------|------|
|
|
15
|
+
| 1.1 | 硬规则检查器(HardRuleChecker) | ✅ | 字数、关键词、结构、禁用词检查 |
|
|
16
|
+
| 1.2 | LLM 评估器(LLMEvaluator) | ✅ | 多维度智能评分(相关性、连贯性、完整性、可读性) |
|
|
17
|
+
| 1.3 | 质量检查服务(QualityCheckService) | ✅ | 整合硬规则和 LLM 评估,支持重试机制 |
|
|
18
|
+
| 1.4 | 质量检查测试用例 | ⏳ | 待编写 |
|
|
19
|
+
| 2.1 | Prometheus 指标服务(MetricsService) | ✅ | 20+ 关键指标采集 |
|
|
20
|
+
| 2.2 | Sentry 错误追踪(SentryService) | ✅ | 错误捕获、性能监控 |
|
|
21
|
+
| 2.3 | 增强日志服务(LoggingService) | ✅ | 日志轮转、结构化日志 |
|
|
22
|
+
| 3.1 | Redis 缓存服务(CacheService) | ✅ | LLM 响应、搜索结果、质量检查缓存 |
|
|
23
|
+
| 3.2 | 缓存集成到现有服务 | ⏳ | 待集成 |
|
|
24
|
+
| 4.1 | API Key 管理(ApiKeyService) | ✅ | 生成、验证、管理 API Key |
|
|
25
|
+
| 4.2 | 配额管理(QuotaService) | ✅ | 每日配额、预留、消费机制 |
|
|
26
|
+
| 4.3 | 速率限制(RateLimiter) | ✅ | 滑动窗口、令牌桶、固定窗口算法 |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 🎯 核心功能实现详情
|
|
31
|
+
|
|
32
|
+
### 1. 质量检查服务
|
|
33
|
+
|
|
34
|
+
#### 1.1 硬规则检查器(HardRuleChecker)
|
|
35
|
+
|
|
36
|
+
**文件**: `src/services/quality/HardRuleChecker.ts` (~580 行)
|
|
37
|
+
|
|
38
|
+
**功能**:
|
|
39
|
+
- ✅ 字数检查(minWords, maxWords)
|
|
40
|
+
- ✅ 关键词检查(支持"全部包含"或"至少一个"模式)
|
|
41
|
+
- ✅ 结构检查(标题、导语、结尾、段落、项目符号、编号列表)
|
|
42
|
+
- ✅ 禁用词过滤
|
|
43
|
+
- ✅ 智能错误建议生成
|
|
44
|
+
|
|
45
|
+
**接口**:
|
|
46
|
+
```typescript
|
|
47
|
+
export interface HardConstraints {
|
|
48
|
+
minWords?: number;
|
|
49
|
+
maxWords?: number;
|
|
50
|
+
keywords?: string[];
|
|
51
|
+
requireAllKeywords?: boolean;
|
|
52
|
+
requireTitle?: boolean;
|
|
53
|
+
requireIntro?: boolean;
|
|
54
|
+
requireConclusion?: boolean;
|
|
55
|
+
minSections?: number;
|
|
56
|
+
forbiddenWords?: string[];
|
|
57
|
+
hasBulletPoints?: boolean;
|
|
58
|
+
hasNumberedList?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface HardRuleCheckResult {
|
|
62
|
+
passed: boolean;
|
|
63
|
+
score: number;
|
|
64
|
+
details: { wordCount, keywords, structure, forbiddenWords };
|
|
65
|
+
issues: Array<{ severity, category, message, suggestion }>;
|
|
66
|
+
checkedAt: number;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
#### 1.2 LLM 评估器(LLMEvaluator)
|
|
73
|
+
|
|
74
|
+
**文件**: `src/services/quality/LLMEvaluator.ts` (~420 行)
|
|
75
|
+
|
|
76
|
+
**功能**:
|
|
77
|
+
- ✅ 多维度评分(相关性 30%、连贯性 30%、完整性 20%、可读性 20%)
|
|
78
|
+
- ✅ 智能反馈生成(优点、缺点、建议)
|
|
79
|
+
- ✅ 批量评估支持
|
|
80
|
+
- ✅ 可配置的通过阈值和最大尝试次数
|
|
81
|
+
|
|
82
|
+
**评分维度**:
|
|
83
|
+
```typescript
|
|
84
|
+
export interface EvaluationDimensions {
|
|
85
|
+
relevance: number; // 相关性(0-10)
|
|
86
|
+
coherence: number; // 连贯性(0-10)
|
|
87
|
+
completeness: number; // 完整性(0-10)
|
|
88
|
+
readability: number; // 可读性(0-10)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface LLMEvaluationResult {
|
|
92
|
+
passed: boolean;
|
|
93
|
+
score: number; // 总分(0-10)
|
|
94
|
+
dimensions: EvaluationDimensions;
|
|
95
|
+
details: {
|
|
96
|
+
strengths: string[];
|
|
97
|
+
weaknesses: string[];
|
|
98
|
+
suggestions: string[];
|
|
99
|
+
reasoning: string;
|
|
100
|
+
};
|
|
101
|
+
metadata: { evaluatedAt, model, tokensUsed };
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
#### 1.3 质量检查服务(QualityCheckService)
|
|
108
|
+
|
|
109
|
+
**文件**: `src/services/quality/QualityCheckService.ts` (~420 行)
|
|
110
|
+
|
|
111
|
+
**功能**:
|
|
112
|
+
- ✅ 整合硬规则和 LLM 评估
|
|
113
|
+
- ✅ 两层检查机制(先硬规则,后软评分)
|
|
114
|
+
- ✅ 自动重试机制(最多 3 次)
|
|
115
|
+
- ✅ 智能修复建议生成
|
|
116
|
+
- ✅ 统计信息收集
|
|
117
|
+
|
|
118
|
+
**工作流程**:
|
|
119
|
+
```
|
|
120
|
+
内容输入
|
|
121
|
+
↓
|
|
122
|
+
硬规则检查(字数、关键词、结构、禁用词)
|
|
123
|
+
↓ 通过?
|
|
124
|
+
├─ ❌ → 返回失败 + 具体建议
|
|
125
|
+
└─ ✅ → 继续
|
|
126
|
+
↓
|
|
127
|
+
LLM 评估(相关性、连贯性、完整性、可读性)
|
|
128
|
+
↓ 分数 >= 阈值?
|
|
129
|
+
├─ ❌ → 重试(最多 3 次)
|
|
130
|
+
└─ ✅ → 返回成功 + 详细反馈
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**统计信息**:
|
|
134
|
+
```typescript
|
|
135
|
+
export interface CheckStatistics {
|
|
136
|
+
totalChecks: number;
|
|
137
|
+
passedChecks: number;
|
|
138
|
+
failedChecks: number;
|
|
139
|
+
averageAttempts: number;
|
|
140
|
+
averageDuration: number;
|
|
141
|
+
passRate: number;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### 2. 监控系统
|
|
148
|
+
|
|
149
|
+
#### 2.1 Prometheus 指标服务
|
|
150
|
+
|
|
151
|
+
**文件**: `src/infrastructure/monitoring/MetricsService.ts` (~580 行)
|
|
152
|
+
|
|
153
|
+
**功能**:
|
|
154
|
+
- ✅ 任务指标(创建、完成、失败、取消、持续时间、进度)
|
|
155
|
+
- ✅ LLM 指标(请求数、持续时间、Token 使用、重试、错误)
|
|
156
|
+
- ✅ 队列指标(等待、活跃、完成、失败、持续时间)
|
|
157
|
+
- ✅ 质量检查指标(检查数、持续时间、通过/失败、分数分布)
|
|
158
|
+
- ✅ 缓存指标(命中、未命中、设置、删除、大小)
|
|
159
|
+
- ✅ 系统指标(内存、CPU、活跃 Worker、运行时间)
|
|
160
|
+
|
|
161
|
+
**关键指标**:
|
|
162
|
+
```typescript
|
|
163
|
+
// 任务指标
|
|
164
|
+
task_created_total
|
|
165
|
+
task_completed_total
|
|
166
|
+
task_failed_total
|
|
167
|
+
task_cancelled_total
|
|
168
|
+
task_duration_seconds
|
|
169
|
+
task_progress_percentage
|
|
170
|
+
|
|
171
|
+
// LLM 指标
|
|
172
|
+
llm_request_total
|
|
173
|
+
llm_request_duration_seconds
|
|
174
|
+
llm_token_usage_total
|
|
175
|
+
llm_retry_total
|
|
176
|
+
llm_error_total
|
|
177
|
+
|
|
178
|
+
// 队列指标
|
|
179
|
+
queue_jobs_waiting
|
|
180
|
+
queue_jobs_active
|
|
181
|
+
queue_jobs_completed_total
|
|
182
|
+
queue_jobs_failed_total
|
|
183
|
+
queue_job_duration_seconds
|
|
184
|
+
|
|
185
|
+
// 质量检查指标
|
|
186
|
+
quality_check_total
|
|
187
|
+
quality_check_duration_seconds
|
|
188
|
+
quality_check_passed_total
|
|
189
|
+
quality_check_failed_total
|
|
190
|
+
quality_check_score
|
|
191
|
+
|
|
192
|
+
// 缓存指标
|
|
193
|
+
cache_hits_total
|
|
194
|
+
cache_misses_total
|
|
195
|
+
cache_set_total
|
|
196
|
+
cache_delete_total
|
|
197
|
+
cache_size
|
|
198
|
+
|
|
199
|
+
// 系统指标
|
|
200
|
+
memory_usage_bytes
|
|
201
|
+
cpu_usage_percent
|
|
202
|
+
active_workers_total
|
|
203
|
+
uptime_seconds
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**使用示例**:
|
|
207
|
+
```typescript
|
|
208
|
+
import { metricsService } from './infrastructure/monitoring/index.js';
|
|
209
|
+
|
|
210
|
+
// 记录任务创建
|
|
211
|
+
metricsService.recordTaskCreated('worker-1', 'async');
|
|
212
|
+
|
|
213
|
+
// 记录任务完成
|
|
214
|
+
metricsService.recordTaskCompleted('worker-1', 'async', 35000);
|
|
215
|
+
|
|
216
|
+
// 记录 LLM 请求
|
|
217
|
+
metricsService.recordLLMRequest('deepseek-chat', 'generation');
|
|
218
|
+
metricsService.recordLLMTokenUsage('deepseek-chat', 'prompt', 1500);
|
|
219
|
+
|
|
220
|
+
// 获取 Prometheus 指标
|
|
221
|
+
const metrics = await metricsService.getMetrics();
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
#### 2.2 Sentry 错误追踪服务
|
|
227
|
+
|
|
228
|
+
**文件**: `src/infrastructure/monitoring/SentryService.ts` (~360 行)
|
|
229
|
+
|
|
230
|
+
**功能**:
|
|
231
|
+
- ✅ 错误捕获和上报
|
|
232
|
+
- ✅ 性能追踪(Transaction)
|
|
233
|
+
- ✅ 用户上下文管理
|
|
234
|
+
- ✅ 标签和额外信息
|
|
235
|
+
- ✅ 面包屑记录
|
|
236
|
+
- ✅ 敏感信息过滤
|
|
237
|
+
|
|
238
|
+
**使用示例**:
|
|
239
|
+
```typescript
|
|
240
|
+
import { sentryService } from './infrastructure/monitoring/index.js';
|
|
241
|
+
|
|
242
|
+
// 初始化
|
|
243
|
+
sentryService.initialize({
|
|
244
|
+
dsn: process.env.SENTRY_DSN,
|
|
245
|
+
environment: 'production',
|
|
246
|
+
tracesSampleRate: 0.1,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// 捕获异常
|
|
250
|
+
try {
|
|
251
|
+
// 业务逻辑
|
|
252
|
+
} catch (error) {
|
|
253
|
+
sentryService.captureException(error as Error, {
|
|
254
|
+
user: { id: 'user-123' },
|
|
255
|
+
tags: { component: 'quality-check' },
|
|
256
|
+
extra: { taskId: 'task-456' },
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// 性能追踪
|
|
261
|
+
const transaction = sentryService.startTransaction({
|
|
262
|
+
op: 'quality-check',
|
|
263
|
+
name: 'Full Quality Check',
|
|
264
|
+
});
|
|
265
|
+
try {
|
|
266
|
+
// 执行操作
|
|
267
|
+
} finally {
|
|
268
|
+
transaction?.finish();
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
#### 2.3 增强日志服务
|
|
275
|
+
|
|
276
|
+
**文件**: `src/infrastructure/monitoring/LoggingService.ts` (~280 行)
|
|
277
|
+
|
|
278
|
+
**功能**:
|
|
279
|
+
- ✅ 基于 Winston 的结构化日志
|
|
280
|
+
- ✅ 日志按日轮转(DailyRotateFile)
|
|
281
|
+
- ✅ 分级日志文件(综合、错误、性能)
|
|
282
|
+
- ✅ 自定义日志格式(JSON/文本)
|
|
283
|
+
- ✅ 子日志器(带上下文)
|
|
284
|
+
|
|
285
|
+
**日志文件**:
|
|
286
|
+
```
|
|
287
|
+
logs/
|
|
288
|
+
├── combined-YYYY-MM-DD.log # 综合日志
|
|
289
|
+
├── error-YYYY-MM-DD.log # 错误日志
|
|
290
|
+
├── performance-YYYY-MM-DD.log # 性能日志
|
|
291
|
+
├── exceptions.log # 未捕获异常
|
|
292
|
+
└── rejections.log # Promise 拒绝
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
**使用示例**:
|
|
296
|
+
```typescript
|
|
297
|
+
import { loggingService } from './infrastructure/monitoring/index.js';
|
|
298
|
+
|
|
299
|
+
// 记录日志
|
|
300
|
+
loggingService.info('Task started', { taskId: 'task-123' });
|
|
301
|
+
loggingService.warn('High memory usage', { memory: '2GB' });
|
|
302
|
+
loggingService.error('Task failed', error, { taskId: 'task-123' });
|
|
303
|
+
|
|
304
|
+
// 记录性能
|
|
305
|
+
loggingService.performance('quality_check', 1500, { taskId: 'task-123' });
|
|
306
|
+
|
|
307
|
+
// 记录 HTTP 请求
|
|
308
|
+
loggingService.http({
|
|
309
|
+
method: 'POST',
|
|
310
|
+
url: '/api/tasks',
|
|
311
|
+
status: 200,
|
|
312
|
+
duration: 150,
|
|
313
|
+
ip: '127.0.0.1',
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// 创建子日志器
|
|
317
|
+
const logger = loggingService.child('QualityCheck');
|
|
318
|
+
logger.info('Quality check completed');
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
### 3. 缓存服务
|
|
324
|
+
|
|
325
|
+
#### 3.1 Redis 缓存服务
|
|
326
|
+
|
|
327
|
+
**文件**: `src/infrastructure/cache/CacheService.ts` (~450 行)
|
|
328
|
+
|
|
329
|
+
**功能**:
|
|
330
|
+
- ✅ 基本缓存操作(get, set, delete, exists)
|
|
331
|
+
- ✅ 批量操作(getMany, setMany)
|
|
332
|
+
- ✅ TTL 管理(expire, ttl)
|
|
333
|
+
- ✅ 模式匹配清理(invalidate, flush)
|
|
334
|
+
- ✅ 缓存统计(hits, misses, hitRate, size)
|
|
335
|
+
- ✅ 专用缓存方法(LLM 响应、搜索结果、质量检查)
|
|
336
|
+
|
|
337
|
+
**缓存策略**:
|
|
338
|
+
```typescript
|
|
339
|
+
// LLM 响应缓存(7 天)
|
|
340
|
+
await cacheService.setCachedLLMResponse(prompt, response, 7 * 24 * 3600);
|
|
341
|
+
|
|
342
|
+
// 搜索结果缓存(1 天)
|
|
343
|
+
await cacheService.setCachedSearchResults(query, results, 24 * 3600);
|
|
344
|
+
|
|
345
|
+
// 质量检查缓存(3 天)
|
|
346
|
+
await cacheService.setCachedQualityCheck(contentHash, result, 3 * 24 * 3600);
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**缓存统计**:
|
|
350
|
+
```typescript
|
|
351
|
+
const stats = await cacheService.getStats();
|
|
352
|
+
console.log(`命中率: ${stats.hitRate}%`);
|
|
353
|
+
console.log(`缓存大小: ${stats.size}`);
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
### 4. 安全服务
|
|
359
|
+
|
|
360
|
+
#### 4.1 API Key 管理服务
|
|
361
|
+
|
|
362
|
+
**文件**: `src/infrastructure/security/ApiKeyService.ts` (~360 行)
|
|
363
|
+
|
|
364
|
+
**功能**:
|
|
365
|
+
- ✅ API Key 生成(格式:`ccak_<timestamp>_<random>`)
|
|
366
|
+
- ✅ SHA-256 哈希加密存储
|
|
367
|
+
- ✅ API Key 验证和激活检查
|
|
368
|
+
- ✅ 过期时间管理
|
|
369
|
+
- ✅ 使用追踪(lastUsedAt, usageCount)
|
|
370
|
+
- ✅ API Key 启用/禁用
|
|
371
|
+
- ✅ 用户 API Key 列表查询
|
|
372
|
+
|
|
373
|
+
**使用示例**:
|
|
374
|
+
```typescript
|
|
375
|
+
import { apiKeyService } from './infrastructure/security/index.js';
|
|
376
|
+
|
|
377
|
+
// 创建 API Key
|
|
378
|
+
const { apiKey, apiKeyId } = await apiKeyService.createApiKey({
|
|
379
|
+
userId: 'user-123',
|
|
380
|
+
name: 'Production Key',
|
|
381
|
+
description: '用于生产环境',
|
|
382
|
+
expiresIn: 30 * 24 * 3600, // 30 天
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// 验证 API Key
|
|
386
|
+
const result = await apiKeyService.verifyApiKey(apiKey);
|
|
387
|
+
if (result.valid) {
|
|
388
|
+
console.log('User ID:', result.userId);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// 禁用 API Key
|
|
392
|
+
await apiKeyService.disableApiKey(apiKeyId);
|
|
393
|
+
|
|
394
|
+
// 获取用户的 API Key 列表
|
|
395
|
+
const apiKeys = await apiKeyService.getUserApiKeys('user-123');
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
#### 4.2 配额管理服务
|
|
401
|
+
|
|
402
|
+
**文件**: `src/infrastructure/security/QuotaService.ts` (~420 行)
|
|
403
|
+
|
|
404
|
+
**功能**:
|
|
405
|
+
- ✅ 每日配额检查
|
|
406
|
+
- ✅ 配额预留机制(使用乐观锁)
|
|
407
|
+
- ✅ 配额消费(预留消费、直接消费)
|
|
408
|
+
- ✅ 配额释放
|
|
409
|
+
- ✅ 自动重置(每日)
|
|
410
|
+
- ✅ 手动重置和配额设置
|
|
411
|
+
- ✅ 过期预留清理
|
|
412
|
+
|
|
413
|
+
**配额流程**:
|
|
414
|
+
```
|
|
415
|
+
1. 检查配额 → 是否有足够配额?
|
|
416
|
+
├─ 否 → 拒绝
|
|
417
|
+
└─ 是 → 继续
|
|
418
|
+
|
|
419
|
+
2. 预留配额 → 使用乐观锁预留
|
|
420
|
+
├─ 失败 → 并发冲突,拒绝
|
|
421
|
+
└─ 成功 → 继续
|
|
422
|
+
|
|
423
|
+
3. 执行操作 → 执行实际业务
|
|
424
|
+
|
|
425
|
+
4. 消费配额 → 消费预留的配额
|
|
426
|
+
├─ 成功 → 完成
|
|
427
|
+
└─ 失败/超时 → 释放预留
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
**使用示例**:
|
|
431
|
+
```typescript
|
|
432
|
+
import { quotaService } from './infrastructure/security/index.js';
|
|
433
|
+
|
|
434
|
+
// 检查配额
|
|
435
|
+
const hasQuota = await quotaService.checkQuota('user-123', 5);
|
|
436
|
+
|
|
437
|
+
// 预留配额
|
|
438
|
+
const { success, reservationId } = await quotaService.reserveQuota('user-123', 5, 300);
|
|
439
|
+
|
|
440
|
+
// 消费配额
|
|
441
|
+
await quotaService.consumeQuota('user-123', reservationId);
|
|
442
|
+
|
|
443
|
+
// 直接消费(无预留)
|
|
444
|
+
await quotaService.consumeDirectly('user-123', 5);
|
|
445
|
+
|
|
446
|
+
// 设置用户每日配额
|
|
447
|
+
await quotaService.setUserQuota('user-123', 200);
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
#### 4.3 速率限制服务
|
|
453
|
+
|
|
454
|
+
**文件**: `src/infrastructure/security/RateLimiter.ts` (~380 行)
|
|
455
|
+
|
|
456
|
+
**功能**:
|
|
457
|
+
- ✅ 滑动窗口算法(推荐,精度高)
|
|
458
|
+
- ✅ 令牌桶算法(支持突发)
|
|
459
|
+
- ✅ 固定窗口算法(简单高效)
|
|
460
|
+
- ✅ 限流状态查询
|
|
461
|
+
- ✅ 限流重置
|
|
462
|
+
- ✅ 预定义配置(API、严格、宽松、任务创建、LLM 调用)
|
|
463
|
+
|
|
464
|
+
**算法对比**:
|
|
465
|
+
|
|
466
|
+
| 算法 | 优点 | 缺点 | 适用场景 |
|
|
467
|
+
|------|------|------|---------|
|
|
468
|
+
| 滑动窗口 | 精度高,平滑限流 | 性能稍低,Redis 操作多 | API 限流 |
|
|
469
|
+
| 令牌桶 | 支持突发,灵活性高 | 实现复杂 | 防止突发流量 |
|
|
470
|
+
| 固定窗口 | 性能高,实现简单 | 边界突发 | 简单体量控制 |
|
|
471
|
+
|
|
472
|
+
**使用示例**:
|
|
473
|
+
```typescript
|
|
474
|
+
import { rateLimiter, RateLimitPresets } from './infrastructure/security/index.js';
|
|
475
|
+
|
|
476
|
+
// 使用预设配置
|
|
477
|
+
const result = await rateLimiter.checkLimit('user-123', RateLimitPresets.api);
|
|
478
|
+
|
|
479
|
+
// 自定义配置
|
|
480
|
+
const customConfig = {
|
|
481
|
+
limit: 50,
|
|
482
|
+
window: 60, // 60 秒
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
const result = await rateLimiter.checkLimit('user-123', customConfig, 'sliding-window');
|
|
486
|
+
|
|
487
|
+
if (!result.allowed) {
|
|
488
|
+
console.log(`Rate limit exceeded. Retry after ${result.retryAfter} seconds`);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// 重置限流
|
|
492
|
+
await rateLimiter.resetLimit('user-123');
|
|
493
|
+
|
|
494
|
+
// 获取当前状态
|
|
495
|
+
const status = await rateLimiter.getStatus('user-123');
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
**预设配置**:
|
|
499
|
+
```typescript
|
|
500
|
+
export const RateLimitPresets = {
|
|
501
|
+
api: { limit: 100, window: 60 }, // 100 请求/分钟
|
|
502
|
+
strict: { limit: 10, window: 60 }, // 10 请求/分钟
|
|
503
|
+
loose: { limit: 1000, window: 60 }, // 1000 请求/分钟
|
|
504
|
+
taskCreation: { limit: 10, window: 3600 }, // 10 任务/小时
|
|
505
|
+
llmCall: { limit: 50, window: 60 }, // 50 调用/分钟
|
|
506
|
+
};
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
## 📊 代码统计
|
|
512
|
+
|
|
513
|
+
### 本次开发
|
|
514
|
+
|
|
515
|
+
| 类别 | 文件数 | 代码行数 |
|
|
516
|
+
|------|--------|---------|
|
|
517
|
+
| 质量检查服务 | 3 | ~1,420 |
|
|
518
|
+
| 监控服务 | 3 | ~1,220 |
|
|
519
|
+
| 缓存服务 | 1 | ~450 |
|
|
520
|
+
| 安全服务 | 3 | ~1,160 |
|
|
521
|
+
| 导出文件 | 3 | ~30 |
|
|
522
|
+
| **总计** | **13** | **~4,280** |
|
|
523
|
+
|
|
524
|
+
### 功能分布
|
|
525
|
+
|
|
526
|
+
| 模块 | 代码行数 | 占比 |
|
|
527
|
+
|------|---------|------|
|
|
528
|
+
| 质量检查 | ~1,420 | 33% |
|
|
529
|
+
| 监控 | ~1,220 | 29% |
|
|
530
|
+
| 安全 | ~1,160 | 27% |
|
|
531
|
+
| 缓存 | ~450 | 11% |
|
|
532
|
+
| 其他 | ~30 | <1% |
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
## 🏗️ 架构亮点
|
|
537
|
+
|
|
538
|
+
### 1. 模块化设计
|
|
539
|
+
|
|
540
|
+
每个服务都是独立的模块,职责清晰:
|
|
541
|
+
- **质量检查**: 硬规则检查器 + LLM 评估器 → 整合服务
|
|
542
|
+
- **监控**: Prometheus + Sentry + Winston → 三层监控体系
|
|
543
|
+
- **缓存**: Redis 基础操作 + 专用缓存方法 → 易用性强
|
|
544
|
+
- **安全**: API Key + 配额 + 限流 → 完整安全体系
|
|
545
|
+
|
|
546
|
+
### 2. 分层架构
|
|
547
|
+
|
|
548
|
+
```
|
|
549
|
+
┌─────────────────────────────────────┐
|
|
550
|
+
│ 业务服务层 │
|
|
551
|
+
│ - QualityCheckService │
|
|
552
|
+
│ - TaskWorker, TaskScheduler │
|
|
553
|
+
└──────────────┬──────────────────────┘
|
|
554
|
+
↓
|
|
555
|
+
┌─────────────────────────────────────┐
|
|
556
|
+
│ 基础设施层 │
|
|
557
|
+
│ - 监控 (Prometheus, Sentry) │
|
|
558
|
+
│ - 缓存 (Redis) │
|
|
559
|
+
│ - 安全 (API Key, 配额, 限流) │
|
|
560
|
+
└──────────────┬──────────────────────┘
|
|
561
|
+
↓
|
|
562
|
+
┌─────────────────────────────────────┐
|
|
563
|
+
│ 数据存储层 │
|
|
564
|
+
│ - PostgreSQL │
|
|
565
|
+
│ - Redis │
|
|
566
|
+
└─────────────────────────────────────┘
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### 3. 设计模式
|
|
570
|
+
|
|
571
|
+
- **单例模式**: 所有服务都导出单例,便于全局访问
|
|
572
|
+
- **策略模式**: RateLimiter 支持多种限流算法
|
|
573
|
+
- **工厂模式**: 各服务的 create 系列方法
|
|
574
|
+
- **观察者模式**: 指标收集、日志记录
|
|
575
|
+
- **乐观锁**: 配额预留机制
|
|
576
|
+
|
|
577
|
+
### 4. 错误处理
|
|
578
|
+
|
|
579
|
+
- **统一错误捕获**: 所有服务都有 try-catch
|
|
580
|
+
- **降级策略**: LLM 评估失败时使用默认值
|
|
581
|
+
- **重试机制**: 质量检查最多重试 3 次
|
|
582
|
+
- **Sentry 集成**: 自动捕获和上报错误
|
|
583
|
+
|
|
584
|
+
### 5. 性能优化
|
|
585
|
+
|
|
586
|
+
- **Redis Pipeline**: 批量操作使用管道
|
|
587
|
+
- **连接复用**: Redis 连接由连接池管理
|
|
588
|
+
- **缓存策略**: LLM 响应、搜索结果、质量检查结果缓存
|
|
589
|
+
- **异步处理**: 所有 I/O 操作都是异步的
|
|
590
|
+
|
|
591
|
+
---
|
|
592
|
+
|
|
593
|
+
## 📝 依赖安装
|
|
594
|
+
|
|
595
|
+
已安装的依赖:
|
|
596
|
+
```json
|
|
597
|
+
{
|
|
598
|
+
"@sentry/node": "^8.55.0",
|
|
599
|
+
"cache-manager": "^5.7.6",
|
|
600
|
+
"cache-manager-ioredis": "^2.1.0",
|
|
601
|
+
"prom-client": "^15.1.3",
|
|
602
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
603
|
+
}
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
---
|
|
607
|
+
|
|
608
|
+
## ⚠️ 待完成事项
|
|
609
|
+
|
|
610
|
+
### 1. 测试用例(优先级:高)
|
|
611
|
+
|
|
612
|
+
需要为以下服务编写单元测试:
|
|
613
|
+
- HardRuleChecker
|
|
614
|
+
- LLMEvaluator
|
|
615
|
+
- QualityCheckService
|
|
616
|
+
- MetricsService
|
|
617
|
+
- SentryService
|
|
618
|
+
- CacheService
|
|
619
|
+
- ApiKeyService
|
|
620
|
+
- QuotaService
|
|
621
|
+
- RateLimiter
|
|
622
|
+
|
|
623
|
+
预计工作量:2-3 天
|
|
624
|
+
|
|
625
|
+
### 2. 缓存集成(优先级:中)
|
|
626
|
+
|
|
627
|
+
将缓存服务集成到现有服务:
|
|
628
|
+
- LLMService: 添加 LLM 响应缓存
|
|
629
|
+
- SearchService: 添加搜索结果缓存
|
|
630
|
+
- QualityCheckService: 添加质量检查缓存
|
|
631
|
+
|
|
632
|
+
预计工作量:1 天
|
|
633
|
+
|
|
634
|
+
### 3. 数据库迁移(优先级:高)
|
|
635
|
+
|
|
636
|
+
需要创建数据库表:
|
|
637
|
+
```sql
|
|
638
|
+
-- API Keys 表
|
|
639
|
+
CREATE TABLE api_keys (
|
|
640
|
+
id VARCHAR(36) PRIMARY KEY,
|
|
641
|
+
key_hash VARCHAR(64) UNIQUE NOT NULL,
|
|
642
|
+
user_id VARCHAR(36) NOT NULL,
|
|
643
|
+
metadata JSONB,
|
|
644
|
+
is_active BOOLEAN DEFAULT true,
|
|
645
|
+
expires_at TIMESTAMP,
|
|
646
|
+
last_used_at TIMESTAMP,
|
|
647
|
+
created_at TIMESTAMP DEFAULT NOW(),
|
|
648
|
+
usage_count INT DEFAULT 0
|
|
649
|
+
);
|
|
650
|
+
|
|
651
|
+
-- 配额预留表
|
|
652
|
+
CREATE TABLE quota_reservations (
|
|
653
|
+
id VARCHAR(36) PRIMARY KEY,
|
|
654
|
+
user_id VARCHAR(36) NOT NULL,
|
|
655
|
+
amount INT NOT NULL,
|
|
656
|
+
consumed BOOLEAN DEFAULT false,
|
|
657
|
+
created_at TIMESTAMP DEFAULT NOW(),
|
|
658
|
+
expires_at TIMESTAMP NOT NULL,
|
|
659
|
+
consumed_at TIMESTAMP
|
|
660
|
+
);
|
|
661
|
+
|
|
662
|
+
-- 更新用户表
|
|
663
|
+
ALTER TABLE users ADD COLUMN quota_daily INT DEFAULT 100;
|
|
664
|
+
ALTER TABLE users ADD COLUMN quota_used_today INT DEFAULT 0;
|
|
665
|
+
ALTER TABLE users ADD COLUMN quota_reserved INT DEFAULT 0;
|
|
666
|
+
ALTER TABLE users ADD COLUMN last_reset_at TIMESTAMP DEFAULT NOW();
|
|
667
|
+
ALTER TABLE users ADD COLUMN version INT DEFAULT 0;
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
预计工作量:0.5 天
|
|
671
|
+
|
|
672
|
+
---
|
|
673
|
+
|
|
674
|
+
## 🎯 下一步建议
|
|
675
|
+
|
|
676
|
+
### 选项 1: 编写测试用例(推荐)
|
|
677
|
+
|
|
678
|
+
为所有阶段 4 服务编写单元测试和集成测试,确保代码质量。
|
|
679
|
+
|
|
680
|
+
### 选项 2: 集成缓存
|
|
681
|
+
|
|
682
|
+
将缓存服务集成到现有服务中,提升系统性能。
|
|
683
|
+
|
|
684
|
+
### 选项 3: 运行数据库迁移
|
|
685
|
+
|
|
686
|
+
创建所需的数据库表,然后测试安全服务。
|
|
687
|
+
|
|
688
|
+
### 选项 4: 部署验证
|
|
689
|
+
|
|
690
|
+
部署到测试环境,进行端到端测试。
|
|
691
|
+
|
|
692
|
+
---
|
|
693
|
+
|
|
694
|
+
## 🎉 主要成就
|
|
695
|
+
|
|
696
|
+
1. ✅ **完整的质量检查体系** - 硬规则 + LLM 评估 + 智能反馈
|
|
697
|
+
2. ✅ **全面的监控体系** - Prometheus + Sentry + Winston
|
|
698
|
+
3. ✅ **高性能缓存** - Redis + 多级缓存策略
|
|
699
|
+
4. ✅ **强大的安全机制** - API Key + 配额 + 限流
|
|
700
|
+
5. ✅ **4,280+ 行高质量代码** - 模块化、可维护、可扩展
|
|
701
|
+
6. ✅ **13 个新服务模块** - 覆盖质量、监控、缓存、安全
|
|
702
|
+
|
|
703
|
+
---
|
|
704
|
+
|
|
705
|
+
**文档生成时间**: 2026-01-19
|
|
706
|
+
**开发状态**: ✅ 阶段 4 核心功能完成
|
|
707
|
+
**待办事项**: 测试用例、缓存集成、数据库迁移
|
|
708
|
+
**下一里程碑**: 测试和集成
|