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