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,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配额管理服务
|
|
3
|
+
*
|
|
4
|
+
* 提供用户配额检查、预留、消费和重置功能
|
|
5
|
+
* 使用乐观锁确保并发安全
|
|
6
|
+
*/
|
|
7
|
+
import crypto from 'crypto';
|
|
8
|
+
import { createLogger } from '../logging/logger.js';
|
|
9
|
+
import { BaseRepository } from '../database/BaseRepository.js';
|
|
10
|
+
import { metricsService } from '../monitoring/MetricsService.js';
|
|
11
|
+
const logger = createLogger('Quota');
|
|
12
|
+
/**
|
|
13
|
+
* 配额服务类
|
|
14
|
+
*/
|
|
15
|
+
export class QuotaService extends BaseRepository {
|
|
16
|
+
defaultQuota = 100; // 默认每日配额
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 获取用户配额信息
|
|
22
|
+
*/
|
|
23
|
+
async getUserQuota(userId) {
|
|
24
|
+
try {
|
|
25
|
+
// 先检查是否需要重置今日配额
|
|
26
|
+
await this.resetIfNeed(userId);
|
|
27
|
+
const result = await this.query(`SELECT user_id, quota_daily, quota_used_today, quota_reserved, last_reset_at
|
|
28
|
+
FROM users
|
|
29
|
+
WHERE user_id = $1`, [userId]);
|
|
30
|
+
if (result.rows.length === 0) {
|
|
31
|
+
logger.warn('User not found', { userId });
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const row = result.rows[0];
|
|
35
|
+
const quotaDaily = row.quota_daily || this.defaultQuota;
|
|
36
|
+
const quotaUsedToday = row.quota_used_today || 0;
|
|
37
|
+
const quotaReserved = row.quota_reserved || 0;
|
|
38
|
+
const quotaAvailable = quotaDaily - quotaUsedToday - quotaReserved;
|
|
39
|
+
return {
|
|
40
|
+
userId: row.user_id,
|
|
41
|
+
quotaDaily,
|
|
42
|
+
quotaUsedToday,
|
|
43
|
+
quotaReserved,
|
|
44
|
+
quotaAvailable,
|
|
45
|
+
lastResetAt: row.last_reset_at,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
logger.error('Failed to get user quota', error, { userId });
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 检查是否有足够配额
|
|
55
|
+
*/
|
|
56
|
+
async checkQuota(userId, amount = 1) {
|
|
57
|
+
const quota = await this.getUserQuota(userId);
|
|
58
|
+
if (!quota) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return quota.quotaAvailable >= amount;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 预留配额(使用乐观锁)
|
|
65
|
+
*/
|
|
66
|
+
async reserveQuota(userId, amount, ttl = 300) {
|
|
67
|
+
try {
|
|
68
|
+
// 先检查是否有足够配额
|
|
69
|
+
const hasEnough = await this.checkQuota(userId, amount);
|
|
70
|
+
if (!hasEnough) {
|
|
71
|
+
logger.warn('Insufficient quota for reservation', { userId, amount });
|
|
72
|
+
return { success: false };
|
|
73
|
+
}
|
|
74
|
+
// 使用乐观锁预留配额
|
|
75
|
+
const result = await this.query(`UPDATE users
|
|
76
|
+
SET quota_reserved = quota_reserved + $1,
|
|
77
|
+
version = version + 1
|
|
78
|
+
WHERE user_id = $2
|
|
79
|
+
AND quota_daily - quota_used_today - quota_reserved >= $1
|
|
80
|
+
RETURNING quota_reserved, quota_daily, quota_used_today`, [amount, userId]);
|
|
81
|
+
if (result.rows.length === 0) {
|
|
82
|
+
logger.warn('Failed to reserve quota (concurrent modification)', { userId, amount });
|
|
83
|
+
return { success: false };
|
|
84
|
+
}
|
|
85
|
+
const reservationId = crypto.randomUUID();
|
|
86
|
+
const expiresAt = new Date(Date.now() + ttl * 1000);
|
|
87
|
+
// 记录预留
|
|
88
|
+
await this.query(`INSERT INTO quota_reservations (id, user_id, amount, created_at, expires_at)
|
|
89
|
+
VALUES ($1, $2, $3, NOW(), $4)`, [reservationId, userId, amount, expiresAt]);
|
|
90
|
+
logger.info('Quota reserved', {
|
|
91
|
+
reservationId,
|
|
92
|
+
userId,
|
|
93
|
+
amount,
|
|
94
|
+
expiresAt,
|
|
95
|
+
});
|
|
96
|
+
metricsService.recordCacheSet('quota_reservation');
|
|
97
|
+
return { success: true, reservationId };
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
logger.error('Failed to reserve quota', error, { userId, amount });
|
|
101
|
+
return { success: false };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 消费预留的配额
|
|
106
|
+
*/
|
|
107
|
+
async consumeQuota(userId, reservationId) {
|
|
108
|
+
try {
|
|
109
|
+
// 获取预留信息
|
|
110
|
+
const reservationResult = await this.query(`SELECT id, user_id, amount, expires_at
|
|
111
|
+
FROM quota_reservations
|
|
112
|
+
WHERE id = $1 AND user_id = $2 AND consumed = false`, [reservationId, userId]);
|
|
113
|
+
if (reservationResult.rows.length === 0) {
|
|
114
|
+
logger.warn('Quota reservation not found or already consumed', { reservationId, userId });
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const reservation = reservationResult.rows[0];
|
|
118
|
+
// 检查是否过期
|
|
119
|
+
if (new Date(reservation.expires_at) < new Date()) {
|
|
120
|
+
logger.warn('Quota reservation expired', { reservationId, expiresAt: reservation.expires_at });
|
|
121
|
+
// 释放预留
|
|
122
|
+
await this.releaseQuota(userId, reservation.amount);
|
|
123
|
+
// 标记为已消费(虽然实际没消费)
|
|
124
|
+
await this.query(`UPDATE quota_reservations SET consumed = true WHERE id = $1`, [reservationId]);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
// 使用事务确保原子性
|
|
128
|
+
await this.query('BEGIN', []);
|
|
129
|
+
try {
|
|
130
|
+
// 减少预留配额
|
|
131
|
+
await this.query(`UPDATE users
|
|
132
|
+
SET quota_reserved = quota_reserved - $1,
|
|
133
|
+
quota_used_today = quota_used_today + $1,
|
|
134
|
+
version = version + 1
|
|
135
|
+
WHERE user_id = $2`, [reservation.amount, userId]);
|
|
136
|
+
// 标记预留为已消费
|
|
137
|
+
await this.query(`UPDATE quota_reservations
|
|
138
|
+
SET consumed = true, consumed_at = NOW()
|
|
139
|
+
WHERE id = $1`, [reservationId]);
|
|
140
|
+
await this.query('COMMIT', []);
|
|
141
|
+
logger.info('Quota consumed', {
|
|
142
|
+
reservationId,
|
|
143
|
+
userId,
|
|
144
|
+
amount: reservation.amount,
|
|
145
|
+
});
|
|
146
|
+
metricsService.recordCacheDelete('quota_reservation');
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
await this.query('ROLLBACK', []);
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
logger.error('Failed to consume quota', error, { userId, reservationId });
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 直接消费配额(无预留)
|
|
161
|
+
*/
|
|
162
|
+
async consumeDirectly(userId, amount) {
|
|
163
|
+
try {
|
|
164
|
+
const result = await this.query(`UPDATE users
|
|
165
|
+
SET quota_used_today = quota_used_today + $1,
|
|
166
|
+
version = version + 1
|
|
167
|
+
WHERE user_id = $2
|
|
168
|
+
AND quota_daily - quota_used_today >= $1
|
|
169
|
+
RETURNING quota_used_today`, [amount, userId]);
|
|
170
|
+
if (result.rows.length === 0) {
|
|
171
|
+
logger.warn('Failed to consume quota directly (insufficient quota)', { userId, amount });
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
logger.info('Quota consumed directly', { userId, amount });
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
logger.error('Failed to consume quota directly', error, { userId, amount });
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* 释放预留的配额
|
|
184
|
+
*/
|
|
185
|
+
async releaseQuota(userId, amount) {
|
|
186
|
+
try {
|
|
187
|
+
await this.query(`UPDATE users
|
|
188
|
+
SET quota_reserved = GREATEST(0, quota_reserved - $1),
|
|
189
|
+
version = version + 1
|
|
190
|
+
WHERE user_id = $2`, [amount, userId]);
|
|
191
|
+
logger.info('Quota released', { userId, amount });
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
logger.error('Failed to release quota', error, { userId, amount });
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* 重置用户今日配额
|
|
201
|
+
*/
|
|
202
|
+
async resetIfNeed(userId) {
|
|
203
|
+
try {
|
|
204
|
+
const result = await this.query(`SELECT user_id, last_reset_at, quota_used_today
|
|
205
|
+
FROM users
|
|
206
|
+
WHERE user_id = $1`, [userId]);
|
|
207
|
+
if (result.rows.length === 0) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const lastReset = new Date(result.rows[0].last_reset_at);
|
|
211
|
+
const now = new Date();
|
|
212
|
+
// 如果上次重置不是今天,则重置
|
|
213
|
+
if (lastReset.toDateString() !== now.toDateString()) {
|
|
214
|
+
await this.query(`UPDATE users
|
|
215
|
+
SET quota_used_today = 0,
|
|
216
|
+
last_reset_at = NOW()
|
|
217
|
+
WHERE user_id = $1`, [userId]);
|
|
218
|
+
logger.info('User quota reset', { userId });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
logger.error('Failed to reset quota', error, { userId });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 手动重置用户配额
|
|
227
|
+
*/
|
|
228
|
+
async resetUserQuota(userId) {
|
|
229
|
+
try {
|
|
230
|
+
await this.query(`UPDATE users
|
|
231
|
+
SET quota_used_today = 0,
|
|
232
|
+
quota_reserved = 0,
|
|
233
|
+
last_reset_at = NOW()
|
|
234
|
+
WHERE user_id = $1`, [userId]);
|
|
235
|
+
logger.info('User quota manually reset', { userId });
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
logger.error('Failed to manually reset user quota', error, { userId });
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 设置用户每日配额
|
|
245
|
+
*/
|
|
246
|
+
async setUserQuota(userId, quotaDaily) {
|
|
247
|
+
try {
|
|
248
|
+
await this.query(`UPDATE users
|
|
249
|
+
SET quota_daily = $1
|
|
250
|
+
WHERE user_id = $2`, [quotaDaily, userId]);
|
|
251
|
+
logger.info('User daily quota updated', { userId, quotaDaily });
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
logger.error('Failed to set user quota', error, { userId, quotaDaily });
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* 清理过期的配额预留
|
|
261
|
+
*/
|
|
262
|
+
async cleanupExpiredReservations() {
|
|
263
|
+
try {
|
|
264
|
+
// 获取过期的预留
|
|
265
|
+
const result = await this.query(`SELECT id, user_id, amount
|
|
266
|
+
FROM quota_reservations
|
|
267
|
+
WHERE expires_at < NOW() AND consumed = false`, []);
|
|
268
|
+
const expired = result.rows;
|
|
269
|
+
// 释放预留
|
|
270
|
+
for (const row of expired) {
|
|
271
|
+
await this.releaseQuota(row.user_id, row.amount);
|
|
272
|
+
}
|
|
273
|
+
// 标记为已消费(实际未消费)
|
|
274
|
+
await this.query(`UPDATE quota_reservations
|
|
275
|
+
SET consumed = true
|
|
276
|
+
WHERE expires_at < NOW() AND consumed = false`, []);
|
|
277
|
+
logger.info('Expired quota reservations cleaned up', { count: expired.length });
|
|
278
|
+
return expired.length;
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
logger.error('Failed to cleanup expired reservations', error);
|
|
282
|
+
return 0;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* 健康检查
|
|
287
|
+
*/
|
|
288
|
+
async healthCheck() {
|
|
289
|
+
try {
|
|
290
|
+
await this.query('SELECT 1', []);
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
logger.error('Quota service health check failed', error);
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* 配额服务单例
|
|
301
|
+
*/
|
|
302
|
+
export const quotaService = new QuotaService();
|
|
303
|
+
//# sourceMappingURL=QuotaService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QuotaService.js","sourceRoot":"","sources":["../../../src/infrastructure/security/QuotaService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;AAyBrC;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,cAAc;IACtC,YAAY,GAAW,GAAG,CAAC,CAAC,SAAS;IAE7C;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,MAAc;QAC/B,IAAI,CAA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|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 速率限制结果
|
|
9
|
+
*/
|
|
10
|
+
export interface RateLimitResult {
|
|
11
|
+
allowed: boolean;
|
|
12
|
+
limit: number;
|
|
13
|
+
remaining: number;
|
|
14
|
+
resetTime: Date;
|
|
15
|
+
retryAfter?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 速率限制配置
|
|
19
|
+
*/
|
|
20
|
+
export interface RateLimitConfig {
|
|
21
|
+
limit: number;
|
|
22
|
+
window: number;
|
|
23
|
+
burst?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 速率限制器类型
|
|
27
|
+
*/
|
|
28
|
+
export type RateLimiterType = 'sliding-window' | 'token-bucket' | 'fixed-window';
|
|
29
|
+
/**
|
|
30
|
+
* 速率限制服务类
|
|
31
|
+
*/
|
|
32
|
+
export declare class RateLimiter {
|
|
33
|
+
private redisClientWrapper;
|
|
34
|
+
private redis;
|
|
35
|
+
/**
|
|
36
|
+
* 获取 Redis 客户端
|
|
37
|
+
*/
|
|
38
|
+
private getRedis;
|
|
39
|
+
/**
|
|
40
|
+
* 滑动窗口速率限制
|
|
41
|
+
*/
|
|
42
|
+
slidingWindow(identifier: string, config: RateLimitConfig): Promise<RateLimitResult>;
|
|
43
|
+
/**
|
|
44
|
+
* 令牌桶速率限制
|
|
45
|
+
*/
|
|
46
|
+
tokenBucket(identifier: string, config: Required<RateLimitConfig>): Promise<RateLimitResult>;
|
|
47
|
+
/**
|
|
48
|
+
* 固定窗口速率限制
|
|
49
|
+
*/
|
|
50
|
+
fixedWindow(identifier: string, config: RateLimitConfig): Promise<RateLimitResult>;
|
|
51
|
+
/**
|
|
52
|
+
* 通用速率限制检查
|
|
53
|
+
*/
|
|
54
|
+
checkLimit(identifier: string, config: RateLimitConfig, type?: RateLimiterType): Promise<RateLimitResult>;
|
|
55
|
+
/**
|
|
56
|
+
* 重置速率限制
|
|
57
|
+
*/
|
|
58
|
+
resetLimit(identifier: string, type?: RateLimiterType): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* 获取当前速率限制状态
|
|
61
|
+
*/
|
|
62
|
+
getStatus(identifier: string, type?: RateLimiterType): Promise<{
|
|
63
|
+
count: number;
|
|
64
|
+
limit: number;
|
|
65
|
+
} | null>;
|
|
66
|
+
/**
|
|
67
|
+
* 健康检查
|
|
68
|
+
*/
|
|
69
|
+
healthCheck(): Promise<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* 关闭连接
|
|
72
|
+
*/
|
|
73
|
+
close(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 速率限制服务单例
|
|
77
|
+
*/
|
|
78
|
+
export declare const rateLimiter: RateLimiter;
|
|
79
|
+
/**
|
|
80
|
+
* 预定义的速率限制配置
|
|
81
|
+
*/
|
|
82
|
+
export declare const RateLimitPresets: {
|
|
83
|
+
api: {
|
|
84
|
+
limit: number;
|
|
85
|
+
window: number;
|
|
86
|
+
};
|
|
87
|
+
strict: {
|
|
88
|
+
limit: number;
|
|
89
|
+
window: number;
|
|
90
|
+
};
|
|
91
|
+
loose: {
|
|
92
|
+
limit: number;
|
|
93
|
+
window: number;
|
|
94
|
+
};
|
|
95
|
+
taskCreation: {
|
|
96
|
+
limit: number;
|
|
97
|
+
window: number;
|
|
98
|
+
};
|
|
99
|
+
llmCall: {
|
|
100
|
+
limit: number;
|
|
101
|
+
window: number;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=RateLimiter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RateLimiter.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/security/RateLimiter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC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