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,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BaseRepository - Repository 基类
|
|
3
|
+
*
|
|
4
|
+
* 提供通用的数据库操作和事务管理
|
|
5
|
+
* 所有具体 Repository 应该继承此类
|
|
6
|
+
*/
|
|
7
|
+
import type { Pool, PoolClient, QueryResult, QueryResultRow } from 'pg';
|
|
8
|
+
/**
|
|
9
|
+
* 查询统计信息
|
|
10
|
+
*/
|
|
11
|
+
export interface QueryStats {
|
|
12
|
+
text: string;
|
|
13
|
+
duration: number;
|
|
14
|
+
rows: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Repository 基类
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class BaseRepository {
|
|
20
|
+
protected pool: Pool;
|
|
21
|
+
constructor(pool?: Pool);
|
|
22
|
+
/**
|
|
23
|
+
* 执行查询
|
|
24
|
+
*
|
|
25
|
+
* @param text - SQL 查询语句
|
|
26
|
+
* @param params - 查询参数
|
|
27
|
+
* @returns 查询结果
|
|
28
|
+
*/
|
|
29
|
+
protected query<T extends QueryResultRow>(text: string, params?: any[]): Promise<QueryResult<T>>;
|
|
30
|
+
/**
|
|
31
|
+
* 获取数据库连接(用于事务)
|
|
32
|
+
*
|
|
33
|
+
* @returns 数据库连接
|
|
34
|
+
*/
|
|
35
|
+
protected getConnection(): Promise<PoolClient>;
|
|
36
|
+
/**
|
|
37
|
+
* 执行事务
|
|
38
|
+
*
|
|
39
|
+
* @param callback - 事务回调函数
|
|
40
|
+
* @returns 回调函数的返回值
|
|
41
|
+
*/
|
|
42
|
+
protected transaction<T>(callback: (client: PoolClient) => Promise<T>): Promise<T>;
|
|
43
|
+
/**
|
|
44
|
+
* 批量执行查询(在单个事务中)
|
|
45
|
+
*
|
|
46
|
+
* @param queries - 查询数组
|
|
47
|
+
* @returns 所有查询的结果数组
|
|
48
|
+
*/
|
|
49
|
+
protected batchQuery<T extends QueryResultRow>(queries: Array<{
|
|
50
|
+
text: string;
|
|
51
|
+
params?: any[];
|
|
52
|
+
}>): Promise<QueryResult<T>[]>;
|
|
53
|
+
/**
|
|
54
|
+
* 检查记录是否存在
|
|
55
|
+
*
|
|
56
|
+
* @param table - 表名
|
|
57
|
+
* @param field - 字段名
|
|
58
|
+
* @param value - 字段值
|
|
59
|
+
* @returns 是否存在
|
|
60
|
+
*/
|
|
61
|
+
protected exists(table: string, field: string, value: any): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* 计数查询
|
|
64
|
+
*
|
|
65
|
+
* @param table - 表名
|
|
66
|
+
* @param where - WHERE 条件(可选)
|
|
67
|
+
* @returns 记录数
|
|
68
|
+
*/
|
|
69
|
+
protected count(table: string, where?: string): Promise<number>;
|
|
70
|
+
/**
|
|
71
|
+
* 记录查询日志
|
|
72
|
+
*
|
|
73
|
+
* @param stats - 查询统计信息
|
|
74
|
+
*/
|
|
75
|
+
private logQuery;
|
|
76
|
+
/**
|
|
77
|
+
* 获取连接池统计信息
|
|
78
|
+
*
|
|
79
|
+
* @returns 连接池统计信息
|
|
80
|
+
*/
|
|
81
|
+
getPoolStats(): {
|
|
82
|
+
totalCount: number;
|
|
83
|
+
idleCount: number;
|
|
84
|
+
waitingCount: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* 关闭连接池
|
|
88
|
+
* 应该在应用关闭时调用
|
|
89
|
+
*/
|
|
90
|
+
close(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* 健康检查
|
|
93
|
+
*
|
|
94
|
+
* @returns 数据库是否健康
|
|
95
|
+
*/
|
|
96
|
+
healthCheck(): Promise<boolean>;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=BaseRepository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseRepository.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/database/BaseRepository.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AAIxE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,8BAAsB,cAAc;IAClC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;gBAET,IAAI,CAAC,EAAE,IAAI;IAmBvB;;;;;;OAMG;cACa,KAAK,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAmBtG;;;;OAIG;cACa,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC;IAIpD;;;;;OAKG;cACa,WAAW,CAAC,CAAC,EAC3B,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3C,OAAO,CAAC,CAAC,CAAC;IAgBb;;;;;OAKG;cACa,UAAU,CAAC,CAAC,SAAS,cAAc,EAAE,OAAO,EAAE,KAAK,CAAC;QAClE,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IAa9B;;;;;;;OAOG;cACa,MAAM,CACpB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,GAAG,GACT,OAAO,CAAC,OAAO,CAAC;IAMnB;;;;;;OAMG;cACa,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAM7E;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAUhB;;;;OAIG;IACH,YAAY,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE;IAQ/E;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAStC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BaseRepository - Repository 基类
|
|
3
|
+
*
|
|
4
|
+
* 提供通用的数据库操作和事务管理
|
|
5
|
+
* 所有具体 Repository 应该继承此类
|
|
6
|
+
*/
|
|
7
|
+
import { Pool as PoolClass } from 'pg';
|
|
8
|
+
import { config } from '../../config/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* Repository 基类
|
|
11
|
+
*/
|
|
12
|
+
export class BaseRepository {
|
|
13
|
+
pool;
|
|
14
|
+
constructor(pool) {
|
|
15
|
+
this.pool = pool || new PoolClass({
|
|
16
|
+
host: config.database.host,
|
|
17
|
+
port: config.database.port,
|
|
18
|
+
database: config.database.database,
|
|
19
|
+
user: config.database.user,
|
|
20
|
+
password: config.database.password,
|
|
21
|
+
max: 20, // 连接池大小
|
|
22
|
+
idleTimeoutMillis: 30000,
|
|
23
|
+
connectionTimeoutMillis: 2000,
|
|
24
|
+
});
|
|
25
|
+
// 监听连接池错误
|
|
26
|
+
this.pool.on('error', (err) => {
|
|
27
|
+
console.error('Unexpected error on idle client', err);
|
|
28
|
+
process.exit(-1);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 执行查询
|
|
33
|
+
*
|
|
34
|
+
* @param text - SQL 查询语句
|
|
35
|
+
* @param params - 查询参数
|
|
36
|
+
* @returns 查询结果
|
|
37
|
+
*/
|
|
38
|
+
async query(text, params) {
|
|
39
|
+
const start = Date.now();
|
|
40
|
+
try {
|
|
41
|
+
const res = await this.pool.query(text, params);
|
|
42
|
+
const duration = Date.now() - start;
|
|
43
|
+
// 记录查询统计(开发环境)
|
|
44
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
45
|
+
this.logQuery({ text, duration, rows: res.rowCount || 0 });
|
|
46
|
+
}
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error('Query error', { text, error });
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 获取数据库连接(用于事务)
|
|
56
|
+
*
|
|
57
|
+
* @returns 数据库连接
|
|
58
|
+
*/
|
|
59
|
+
async getConnection() {
|
|
60
|
+
return await this.pool.connect();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 执行事务
|
|
64
|
+
*
|
|
65
|
+
* @param callback - 事务回调函数
|
|
66
|
+
* @returns 回调函数的返回值
|
|
67
|
+
*/
|
|
68
|
+
async transaction(callback) {
|
|
69
|
+
const client = await this.getConnection();
|
|
70
|
+
try {
|
|
71
|
+
await client.query('BEGIN');
|
|
72
|
+
const result = await callback(client);
|
|
73
|
+
await client.query('COMMIT');
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
await client.query('ROLLBACK');
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
client.release();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 批量执行查询(在单个事务中)
|
|
86
|
+
*
|
|
87
|
+
* @param queries - 查询数组
|
|
88
|
+
* @returns 所有查询的结果数组
|
|
89
|
+
*/
|
|
90
|
+
async batchQuery(queries) {
|
|
91
|
+
return this.transaction(async (client) => {
|
|
92
|
+
const results = [];
|
|
93
|
+
for (const query of queries) {
|
|
94
|
+
const result = await client.query(query.text, query.params);
|
|
95
|
+
results.push(result);
|
|
96
|
+
}
|
|
97
|
+
return results;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 检查记录是否存在
|
|
102
|
+
*
|
|
103
|
+
* @param table - 表名
|
|
104
|
+
* @param field - 字段名
|
|
105
|
+
* @param value - 字段值
|
|
106
|
+
* @returns 是否存在
|
|
107
|
+
*/
|
|
108
|
+
async exists(table, field, value) {
|
|
109
|
+
const text = `SELECT EXISTS(SELECT 1 FROM ${table} WHERE ${field} = $1)`;
|
|
110
|
+
const result = await this.query(text, [value]);
|
|
111
|
+
return result.rows[0]?.exists ?? false;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 计数查询
|
|
115
|
+
*
|
|
116
|
+
* @param table - 表名
|
|
117
|
+
* @param where - WHERE 条件(可选)
|
|
118
|
+
* @returns 记录数
|
|
119
|
+
*/
|
|
120
|
+
async count(table, where = 'TRUE') {
|
|
121
|
+
const text = `SELECT COUNT(*) as count FROM ${table} WHERE ${where}`;
|
|
122
|
+
const result = await this.query(text);
|
|
123
|
+
return parseInt(result.rows[0]?.count ?? '0', 10);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 记录查询日志
|
|
127
|
+
*
|
|
128
|
+
* @param stats - 查询统计信息
|
|
129
|
+
*/
|
|
130
|
+
logQuery(stats) {
|
|
131
|
+
const { text, duration, rows } = stats;
|
|
132
|
+
// 截断过长的查询语句
|
|
133
|
+
const truncatedText = text.length > 100 ? text.substring(0, 100) + '...' : text;
|
|
134
|
+
console.log(`[Query] ${truncatedText} - ${duration}ms - ${rows} rows`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 获取连接池统计信息
|
|
138
|
+
*
|
|
139
|
+
* @returns 连接池统计信息
|
|
140
|
+
*/
|
|
141
|
+
getPoolStats() {
|
|
142
|
+
return {
|
|
143
|
+
totalCount: this.pool.totalCount,
|
|
144
|
+
idleCount: this.pool.idleCount,
|
|
145
|
+
waitingCount: this.pool.waitingCount,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 关闭连接池
|
|
150
|
+
* 应该在应用关闭时调用
|
|
151
|
+
*/
|
|
152
|
+
async close() {
|
|
153
|
+
try {
|
|
154
|
+
await this.pool.end();
|
|
155
|
+
console.log('Database connection pool closed');
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
console.error('Error closing database connection pool:', error);
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 健康检查
|
|
164
|
+
*
|
|
165
|
+
* @returns 数据库是否健康
|
|
166
|
+
*/
|
|
167
|
+
async healthCheck() {
|
|
168
|
+
try {
|
|
169
|
+
await this.query('SELECT 1');
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error('Database health check failed:', error);
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=BaseRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseRepository.js","sourceRoot":"","sources":["../../../src/infrastructure/database/BaseRepository.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Task Repository
|
|
3
|
+
*
|
|
4
|
+
* 内存版本的 Task Repository,用于测试和开发
|
|
5
|
+
* 数据不持久化,适合快速测试工作流
|
|
6
|
+
*/
|
|
7
|
+
import type { Task, TaskCreateParams, TaskUpdateParams, TaskListFilters, PaginatedResult } from '../../domain/repositories/TaskRepository.js';
|
|
8
|
+
import { TaskStatus } from '../../domain/entities/Task.js';
|
|
9
|
+
/**
|
|
10
|
+
* 内存 Task Repository 实现
|
|
11
|
+
*/
|
|
12
|
+
export declare class MemoryTaskRepository {
|
|
13
|
+
private tasks;
|
|
14
|
+
private snapshots;
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* 创建任务
|
|
18
|
+
*/
|
|
19
|
+
create(params: TaskCreateParams): Promise<Task>;
|
|
20
|
+
/**
|
|
21
|
+
* 根据 ID 查找任务
|
|
22
|
+
*/
|
|
23
|
+
findById(id: string): Promise<Task | null>;
|
|
24
|
+
/**
|
|
25
|
+
* 更新任务
|
|
26
|
+
*/
|
|
27
|
+
update(id: string, params: TaskUpdateParams): Promise<Task>;
|
|
28
|
+
/**
|
|
29
|
+
* 更新任务状态(带乐观锁)
|
|
30
|
+
*/
|
|
31
|
+
updateStatus(taskId: string, status: TaskStatus, version: number): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* 抢占任务(Worker 抢占机制)
|
|
34
|
+
*/
|
|
35
|
+
claimForProcessing(workerId: string, limit?: number): Promise<Task[]>;
|
|
36
|
+
/**
|
|
37
|
+
* 保存状态快照(用于崩溃恢复)
|
|
38
|
+
*/
|
|
39
|
+
saveStateSnapshot(taskId: string, step: string, state: any): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* 恢复状态快照
|
|
42
|
+
*/
|
|
43
|
+
loadStateSnapshot(taskId: string): Promise<any | null>;
|
|
44
|
+
/**
|
|
45
|
+
* 列出任务(带过滤和分页)
|
|
46
|
+
*/
|
|
47
|
+
list(filters?: TaskListFilters): Promise<PaginatedResult<Task>>;
|
|
48
|
+
/**
|
|
49
|
+
* 删除任务
|
|
50
|
+
*/
|
|
51
|
+
delete(id: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* 健康检查
|
|
54
|
+
*/
|
|
55
|
+
healthCheck(): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* 更新当前步骤(带乐观锁)
|
|
58
|
+
*/
|
|
59
|
+
updateCurrentStep(taskId: string, step: string, version: number): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* 标记任务完成(带乐观锁)
|
|
62
|
+
*/
|
|
63
|
+
markAsCompleted(taskId: string, version: number): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* 标记任务失败(带乐观锁)
|
|
66
|
+
*/
|
|
67
|
+
markAsFailed(taskId: string, errorMessage: string, version: number): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* 获取统计信息
|
|
70
|
+
*/
|
|
71
|
+
getStats(): {
|
|
72
|
+
totalTasks: number;
|
|
73
|
+
snapshots: number;
|
|
74
|
+
byStatus: Record<string, number>;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=MemoryTaskRepository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryTaskRepository.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/database/MemoryTaskRepository.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,eAAe,EAChB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAI3D;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,SAAS,CAA+B;;IAMhD;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BrD;;OAEG;IACG,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAKhD;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBjE;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA6BzF;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IA0C9E;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAYhF;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAa5D;;OAEG;IACG,IAAI,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IA6CzE;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAc1C;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAyBxF;;OAEG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BxE;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA2B3F;;OAEG;IACH,QAAQ;;;;;CAUT"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Task Repository
|
|
3
|
+
*
|
|
4
|
+
* 内存版本的 Task Repository,用于测试和开发
|
|
5
|
+
* 数据不持久化,适合快速测试工作流
|
|
6
|
+
*/
|
|
7
|
+
import { createLogger } from '../../infrastructure/logging/logger.js';
|
|
8
|
+
import { TaskStatus } from '../../domain/entities/Task.js';
|
|
9
|
+
const logger = createLogger('Memory:TaskRepository');
|
|
10
|
+
/**
|
|
11
|
+
* 内存 Task Repository 实现
|
|
12
|
+
*/
|
|
13
|
+
export class MemoryTaskRepository {
|
|
14
|
+
tasks = new Map();
|
|
15
|
+
snapshots = new Map();
|
|
16
|
+
constructor() {
|
|
17
|
+
logger.info('Memory repository initialized (no persistence)');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 创建任务
|
|
21
|
+
*/
|
|
22
|
+
async create(params) {
|
|
23
|
+
const now = new Date();
|
|
24
|
+
const task = {
|
|
25
|
+
id: params.id,
|
|
26
|
+
taskId: params.id,
|
|
27
|
+
mode: params.mode,
|
|
28
|
+
type: params.type,
|
|
29
|
+
topic: params.topic,
|
|
30
|
+
requirements: params.requirements,
|
|
31
|
+
hardConstraints: params.hardConstraints,
|
|
32
|
+
status: TaskStatus.PENDING,
|
|
33
|
+
priority: 2, // NORMAL
|
|
34
|
+
version: 1,
|
|
35
|
+
textRetryCount: 0,
|
|
36
|
+
imageRetryCount: 0,
|
|
37
|
+
targetAudience: 'general',
|
|
38
|
+
createdAt: now,
|
|
39
|
+
updatedAt: now,
|
|
40
|
+
};
|
|
41
|
+
this.tasks.set(task.id, task);
|
|
42
|
+
logger.info('Task created (memory)', { taskId: task.id, topic: task.topic });
|
|
43
|
+
return task;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 根据 ID 查找任务
|
|
47
|
+
*/
|
|
48
|
+
async findById(id) {
|
|
49
|
+
const task = this.tasks.get(id);
|
|
50
|
+
return task || null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 更新任务
|
|
54
|
+
*/
|
|
55
|
+
async update(id, params) {
|
|
56
|
+
const task = this.tasks.get(id);
|
|
57
|
+
if (!task) {
|
|
58
|
+
throw new Error(`Task not found: ${id}`);
|
|
59
|
+
}
|
|
60
|
+
const now = new Date();
|
|
61
|
+
const updatedTask = {
|
|
62
|
+
...task,
|
|
63
|
+
...(params.status !== undefined && { status: params.status }),
|
|
64
|
+
...(params.currentStep !== undefined && { currentStep: params.currentStep }),
|
|
65
|
+
...(params.errorMessage !== undefined && { errorMessage: params.errorMessage }),
|
|
66
|
+
...(params.workerId !== undefined && { workerId: params.workerId }),
|
|
67
|
+
...(params.startedAt !== undefined && { startedAt: params.startedAt ? new Date(params.startedAt) : undefined }),
|
|
68
|
+
...(params.completedAt !== undefined && { completedAt: params.completedAt ? new Date(params.completedAt) : undefined }),
|
|
69
|
+
...(params.version !== undefined && { version: params.version }),
|
|
70
|
+
updatedAt: now,
|
|
71
|
+
};
|
|
72
|
+
this.tasks.set(id, updatedTask);
|
|
73
|
+
logger.debug('Task updated (memory)', { taskId: id, updates: Object.keys(params) });
|
|
74
|
+
return updatedTask;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 更新任务状态(带乐观锁)
|
|
78
|
+
*/
|
|
79
|
+
async updateStatus(taskId, status, version) {
|
|
80
|
+
const task = this.tasks.get(taskId);
|
|
81
|
+
if (!task) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
// 检查版本号(乐观锁)
|
|
85
|
+
if (task.version !== version) {
|
|
86
|
+
logger.warn('Task version mismatch for updateStatus', { taskId, expectedVersion: version, actualVersion: task.version });
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const now = new Date();
|
|
90
|
+
const updatedTask = {
|
|
91
|
+
...task,
|
|
92
|
+
status,
|
|
93
|
+
version: version + 1,
|
|
94
|
+
updatedAt: now,
|
|
95
|
+
...(status === TaskStatus.RUNNING && { startedAt: now }),
|
|
96
|
+
...(status === TaskStatus.COMPLETED && { completedAt: now }),
|
|
97
|
+
...(status === TaskStatus.FAILED && { completedAt: now }),
|
|
98
|
+
...(status === TaskStatus.CANCELLED && { completedAt: now }),
|
|
99
|
+
};
|
|
100
|
+
this.tasks.set(taskId, updatedTask);
|
|
101
|
+
logger.debug('Task status updated (memory)', { taskId, status, newVersion: updatedTask.version });
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 抢占任务(Worker 抢占机制)
|
|
106
|
+
*/
|
|
107
|
+
async claimForProcessing(workerId, limit = 1) {
|
|
108
|
+
const now = new Date();
|
|
109
|
+
const claimedTasks = [];
|
|
110
|
+
// 找出待处理任务
|
|
111
|
+
const pendingTasks = Array.from(this.tasks.values())
|
|
112
|
+
.filter((task) => task.status === TaskStatus.PENDING ||
|
|
113
|
+
(task.status === TaskStatus.WAITING &&
|
|
114
|
+
new Date(task.updatedAt).getTime() < Date.now() - 5 * 60 * 1000))
|
|
115
|
+
.sort((a, b) => {
|
|
116
|
+
// 按优先级降序,然后按创建时间升序
|
|
117
|
+
if (a.priority !== b.priority) {
|
|
118
|
+
return b.priority - a.priority;
|
|
119
|
+
}
|
|
120
|
+
return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
|
|
121
|
+
})
|
|
122
|
+
.slice(0, limit);
|
|
123
|
+
// 更新任务状态
|
|
124
|
+
for (const task of pendingTasks) {
|
|
125
|
+
const updatedTask = await this.update(task.id, {
|
|
126
|
+
status: TaskStatus.RUNNING,
|
|
127
|
+
workerId,
|
|
128
|
+
startedAt: now.toISOString(),
|
|
129
|
+
});
|
|
130
|
+
claimedTasks.push(updatedTask);
|
|
131
|
+
}
|
|
132
|
+
if (claimedTasks.length > 0) {
|
|
133
|
+
logger.info('Tasks claimed for processing (memory)', {
|
|
134
|
+
workerId,
|
|
135
|
+
count: claimedTasks.length,
|
|
136
|
+
taskIds: claimedTasks.map((t) => t.id),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return claimedTasks;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 保存状态快照(用于崩溃恢复)
|
|
143
|
+
*/
|
|
144
|
+
async saveStateSnapshot(taskId, step, state) {
|
|
145
|
+
const key = `${taskId}_${step}`;
|
|
146
|
+
this.snapshots.set(key, {
|
|
147
|
+
taskId,
|
|
148
|
+
step,
|
|
149
|
+
state,
|
|
150
|
+
savedAt: new Date(),
|
|
151
|
+
});
|
|
152
|
+
logger.debug('State snapshot saved (memory)', { taskId, step });
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 恢复状态快照
|
|
156
|
+
*/
|
|
157
|
+
async loadStateSnapshot(taskId) {
|
|
158
|
+
// 找到最新的快照
|
|
159
|
+
const snapshots = Array.from(this.snapshots.values())
|
|
160
|
+
.filter((s) => s.taskId === taskId)
|
|
161
|
+
.sort((a, b) => new Date(b.savedAt).getTime() - new Date(a.savedAt).getTime());
|
|
162
|
+
if (snapshots.length === 0) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
return snapshots[0].state;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 列出任务(带过滤和分页)
|
|
169
|
+
*/
|
|
170
|
+
async list(filters = {}) {
|
|
171
|
+
const { status, workerId, type, limit = 50, offset = 0, sortBy = 'createdAt', sortOrder = 'DESC', } = filters;
|
|
172
|
+
let tasks = Array.from(this.tasks.values());
|
|
173
|
+
// 应用过滤
|
|
174
|
+
if (status) {
|
|
175
|
+
tasks = tasks.filter((t) => t.status === status);
|
|
176
|
+
}
|
|
177
|
+
if (workerId) {
|
|
178
|
+
tasks = tasks.filter((t) => t.workerId === workerId);
|
|
179
|
+
}
|
|
180
|
+
if (type) {
|
|
181
|
+
tasks = tasks.filter((t) => t.type === type);
|
|
182
|
+
}
|
|
183
|
+
const total = tasks.length;
|
|
184
|
+
// 排序
|
|
185
|
+
tasks.sort((a, b) => {
|
|
186
|
+
const aVal = a[sortBy];
|
|
187
|
+
const bVal = b[sortBy];
|
|
188
|
+
const comparison = aVal < bVal ? -1 : aVal > bVal ? 1 : 0;
|
|
189
|
+
return sortOrder === 'DESC' ? -comparison : comparison;
|
|
190
|
+
});
|
|
191
|
+
// 分页
|
|
192
|
+
const data = tasks.slice(offset, offset + limit);
|
|
193
|
+
return {
|
|
194
|
+
data,
|
|
195
|
+
total,
|
|
196
|
+
limit,
|
|
197
|
+
offset,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* 删除任务
|
|
202
|
+
*/
|
|
203
|
+
async delete(id) {
|
|
204
|
+
const existed = this.tasks.has(id);
|
|
205
|
+
this.tasks.delete(id);
|
|
206
|
+
// 清理相关快照
|
|
207
|
+
for (const [key, snapshot] of this.snapshots.entries()) {
|
|
208
|
+
if (snapshot.taskId === id) {
|
|
209
|
+
this.snapshots.delete(key);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return existed;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 健康检查
|
|
216
|
+
*/
|
|
217
|
+
async healthCheck() {
|
|
218
|
+
return true; // 内存版本永远健康
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 更新当前步骤(带乐观锁)
|
|
222
|
+
*/
|
|
223
|
+
async updateCurrentStep(taskId, step, version) {
|
|
224
|
+
const task = this.tasks.get(taskId);
|
|
225
|
+
if (!task) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
// 检查版本号(乐观锁)
|
|
229
|
+
if (task.version !== version) {
|
|
230
|
+
logger.warn('Task version mismatch for updateCurrentStep', { taskId, expectedVersion: version, actualVersion: task.version });
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
const now = new Date();
|
|
234
|
+
const updatedTask = {
|
|
235
|
+
...task,
|
|
236
|
+
currentStep: step,
|
|
237
|
+
version: version + 1,
|
|
238
|
+
updatedAt: now,
|
|
239
|
+
};
|
|
240
|
+
this.tasks.set(taskId, updatedTask);
|
|
241
|
+
logger.debug('Task currentStep updated (memory)', { taskId, step });
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* 标记任务完成(带乐观锁)
|
|
246
|
+
*/
|
|
247
|
+
async markAsCompleted(taskId, version) {
|
|
248
|
+
const task = this.tasks.get(taskId);
|
|
249
|
+
if (!task) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
// 检查版本号(乐观锁)
|
|
253
|
+
if (task.version !== version) {
|
|
254
|
+
logger.warn('Task version mismatch for markAsCompleted', { taskId, expectedVersion: version, actualVersion: task.version });
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
const now = new Date();
|
|
258
|
+
const updatedTask = {
|
|
259
|
+
...task,
|
|
260
|
+
status: TaskStatus.COMPLETED,
|
|
261
|
+
completedAt: now,
|
|
262
|
+
version: version + 1,
|
|
263
|
+
updatedAt: now,
|
|
264
|
+
};
|
|
265
|
+
this.tasks.set(taskId, updatedTask);
|
|
266
|
+
logger.info('Task marked as completed (memory)', { taskId });
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* 标记任务失败(带乐观锁)
|
|
271
|
+
*/
|
|
272
|
+
async markAsFailed(taskId, errorMessage, version) {
|
|
273
|
+
const task = this.tasks.get(taskId);
|
|
274
|
+
if (!task) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
// 检查版本号(乐观锁)
|
|
278
|
+
if (task.version !== version) {
|
|
279
|
+
logger.warn('Task version mismatch for markAsFailed', { taskId, expectedVersion: version, actualVersion: task.version });
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
const now = new Date();
|
|
283
|
+
const updatedTask = {
|
|
284
|
+
...task,
|
|
285
|
+
status: TaskStatus.FAILED,
|
|
286
|
+
errorMessage,
|
|
287
|
+
completedAt: now,
|
|
288
|
+
version: version + 1,
|
|
289
|
+
updatedAt: now,
|
|
290
|
+
};
|
|
291
|
+
this.tasks.set(taskId, updatedTask);
|
|
292
|
+
logger.info('Task marked as failed (memory)', { taskId, errorMessage });
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 获取统计信息
|
|
297
|
+
*/
|
|
298
|
+
getStats() {
|
|
299
|
+
return {
|
|
300
|
+
totalTasks: this.tasks.size,
|
|
301
|
+
snapshots: this.snapshots.size,
|
|
302
|
+
byStatus: Array.from(this.tasks.values()).reduce((acc, task) => {
|
|
303
|
+
acc[task.status] = (acc[task.status] || 0) + 1;
|
|
304
|
+
return acc;
|
|
305
|
+
}, {}),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=MemoryTaskRepository.js.map
|