@yasserkhanorg/impact-gate 2.0.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/LICENSE +168 -0
- package/README.md +520 -0
- package/dist/adapters/cypress.d.ts +10 -0
- package/dist/adapters/cypress.d.ts.map +1 -0
- package/dist/adapters/cypress.js +86 -0
- package/dist/adapters/framework_adapter.d.ts +41 -0
- package/dist/adapters/framework_adapter.d.ts.map +1 -0
- package/dist/adapters/framework_adapter.js +152 -0
- package/dist/adapters/playwright.d.ts +10 -0
- package/dist/adapters/playwright.d.ts.map +1 -0
- package/dist/adapters/playwright.js +86 -0
- package/dist/adapters/pytest.d.ts +10 -0
- package/dist/adapters/pytest.d.ts.map +1 -0
- package/dist/adapters/pytest.js +96 -0
- package/dist/adapters/supertest.d.ts +12 -0
- package/dist/adapters/supertest.d.ts.map +1 -0
- package/dist/adapters/supertest.js +85 -0
- package/dist/agent/api_catalog.d.ts +11 -0
- package/dist/agent/api_catalog.d.ts.map +1 -0
- package/dist/agent/api_catalog.js +210 -0
- package/dist/agent/config.d.ts +193 -0
- package/dist/agent/config.d.ts.map +1 -0
- package/dist/agent/config.js +875 -0
- package/dist/agent/feedback.d.ts +91 -0
- package/dist/agent/feedback.d.ts.map +1 -0
- package/dist/agent/feedback.js +323 -0
- package/dist/agent/git.d.ts +19 -0
- package/dist/agent/git.d.ts.map +1 -0
- package/dist/agent/git.js +257 -0
- package/dist/agent/handoff.d.ts +22 -0
- package/dist/agent/handoff.d.ts.map +1 -0
- package/dist/agent/handoff.js +180 -0
- package/dist/agent/llm_agents_flow.d.ts +15 -0
- package/dist/agent/llm_agents_flow.d.ts.map +1 -0
- package/dist/agent/llm_agents_flow.js +434 -0
- package/dist/agent/native_flow.d.ts +6 -0
- package/dist/agent/native_flow.d.ts.map +1 -0
- package/dist/agent/native_flow.js +179 -0
- package/dist/agent/pipeline.d.ts +7 -0
- package/dist/agent/pipeline.d.ts.map +1 -0
- package/dist/agent/pipeline.js +260 -0
- package/dist/agent/pipeline_types.d.ts +54 -0
- package/dist/agent/pipeline_types.d.ts.map +1 -0
- package/dist/agent/pipeline_types.js +4 -0
- package/dist/agent/pipeline_utils.d.ts +12 -0
- package/dist/agent/pipeline_utils.d.ts.map +1 -0
- package/dist/agent/pipeline_utils.js +156 -0
- package/dist/agent/plan.d.ts +170 -0
- package/dist/agent/plan.d.ts.map +1 -0
- package/dist/agent/plan.js +86 -0
- package/dist/agent/playwright_report.d.ts +8 -0
- package/dist/agent/playwright_report.d.ts.map +1 -0
- package/dist/agent/playwright_report.js +126 -0
- package/dist/agent/process_runner.d.ts +10 -0
- package/dist/agent/process_runner.d.ts.map +1 -0
- package/dist/agent/process_runner.js +92 -0
- package/dist/agent/spec_generator.d.ts +5 -0
- package/dist/agent/spec_generator.d.ts.map +1 -0
- package/dist/agent/spec_generator.js +253 -0
- package/dist/agent/test_path.d.ts +2 -0
- package/dist/agent/test_path.d.ts.map +1 -0
- package/dist/agent/test_path.js +23 -0
- package/dist/agent/traceability_capture.d.ts +18 -0
- package/dist/agent/traceability_capture.d.ts.map +1 -0
- package/dist/agent/traceability_capture.js +313 -0
- package/dist/agent/traceability_ingest.d.ts +21 -0
- package/dist/agent/traceability_ingest.d.ts.map +1 -0
- package/dist/agent/traceability_ingest.js +237 -0
- package/dist/agent/types.d.ts +42 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +4 -0
- package/dist/agent/utils.d.ts +13 -0
- package/dist/agent/utils.d.ts.map +1 -0
- package/dist/agent/utils.js +152 -0
- package/dist/agent/validation_runner.d.ts +5 -0
- package/dist/agent/validation_runner.d.ts.map +1 -0
- package/dist/agent/validation_runner.js +77 -0
- package/dist/agentic/fix_loop.d.ts +26 -0
- package/dist/agentic/fix_loop.d.ts.map +1 -0
- package/dist/agentic/fix_loop.js +96 -0
- package/dist/agentic/playwright_runner.d.ts +43 -0
- package/dist/agentic/playwright_runner.d.ts.map +1 -0
- package/dist/agentic/playwright_runner.js +165 -0
- package/dist/agentic/runner.d.ts +27 -0
- package/dist/agentic/runner.d.ts.map +1 -0
- package/dist/agentic/runner.js +210 -0
- package/dist/agentic/types.d.ts +62 -0
- package/dist/agentic/types.d.ts.map +1 -0
- package/dist/agentic/types.js +4 -0
- package/dist/agents/coverage-evaluator.d.ts +8 -0
- package/dist/agents/coverage-evaluator.d.ts.map +1 -0
- package/dist/agents/coverage-evaluator.js +41 -0
- package/dist/agents/cross-impact.d.ts +13 -0
- package/dist/agents/cross-impact.d.ts.map +1 -0
- package/dist/agents/cross-impact.js +140 -0
- package/dist/agents/executor.d.ts +8 -0
- package/dist/agents/executor.d.ts.map +1 -0
- package/dist/agents/executor.js +75 -0
- package/dist/agents/explorer.d.ts +12 -0
- package/dist/agents/explorer.d.ts.map +1 -0
- package/dist/agents/explorer.js +43 -0
- package/dist/agents/generator.d.ts +8 -0
- package/dist/agents/generator.d.ts.map +1 -0
- package/dist/agents/generator.js +77 -0
- package/dist/agents/healer.d.ts +8 -0
- package/dist/agents/healer.d.ts.map +1 -0
- package/dist/agents/healer.js +31 -0
- package/dist/agents/impact-analyst.d.ts +8 -0
- package/dist/agents/impact-analyst.d.ts.map +1 -0
- package/dist/agents/impact-analyst.js +38 -0
- package/dist/agents/regression-advisor.d.ts +8 -0
- package/dist/agents/regression-advisor.d.ts.map +1 -0
- package/dist/agents/regression-advisor.js +116 -0
- package/dist/agents/strategist.d.ts +9 -0
- package/dist/agents/strategist.d.ts.map +1 -0
- package/dist/agents/strategist.js +92 -0
- package/dist/agents/test-designer.d.ts +8 -0
- package/dist/agents/test-designer.d.ts.map +1 -0
- package/dist/agents/test-designer.js +111 -0
- package/dist/anthropic_provider.d.ts +65 -0
- package/dist/anthropic_provider.d.ts.map +1 -0
- package/dist/anthropic_provider.js +334 -0
- package/dist/api.d.ts +48 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +151 -0
- package/dist/base_provider.d.ts +109 -0
- package/dist/base_provider.d.ts.map +1 -0
- package/dist/base_provider.js +203 -0
- package/dist/budget_ledger.d.ts +28 -0
- package/dist/budget_ledger.d.ts.map +1 -0
- package/dist/budget_ledger.js +62 -0
- package/dist/cache/cached_provider.d.ts +49 -0
- package/dist/cache/cached_provider.d.ts.map +1 -0
- package/dist/cache/cached_provider.js +91 -0
- package/dist/cache/response_cache.d.ts +79 -0
- package/dist/cache/response_cache.d.ts.map +1 -0
- package/dist/cache/response_cache.js +177 -0
- package/dist/cli/commands/analyze.d.ts +3 -0
- package/dist/cli/commands/analyze.d.ts.map +1 -0
- package/dist/cli/commands/analyze.js +77 -0
- package/dist/cli/commands/bootstrap.d.ts +3 -0
- package/dist/cli/commands/bootstrap.d.ts.map +1 -0
- package/dist/cli/commands/bootstrap.js +109 -0
- package/dist/cli/commands/cost_report.d.ts +3 -0
- package/dist/cli/commands/cost_report.d.ts.map +1 -0
- package/dist/cli/commands/cost_report.js +115 -0
- package/dist/cli/commands/crew.d.ts +3 -0
- package/dist/cli/commands/crew.d.ts.map +1 -0
- package/dist/cli/commands/crew.js +255 -0
- package/dist/cli/commands/feedback.d.ts +3 -0
- package/dist/cli/commands/feedback.d.ts.map +1 -0
- package/dist/cli/commands/feedback.js +39 -0
- package/dist/cli/commands/finalize.d.ts +3 -0
- package/dist/cli/commands/finalize.d.ts.map +1 -0
- package/dist/cli/commands/finalize.js +41 -0
- package/dist/cli/commands/gate.d.ts +3 -0
- package/dist/cli/commands/gate.d.ts.map +1 -0
- package/dist/cli/commands/gate.js +89 -0
- package/dist/cli/commands/generate.d.ts +4 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +108 -0
- package/dist/cli/commands/heal.d.ts +3 -0
- package/dist/cli/commands/heal.d.ts.map +1 -0
- package/dist/cli/commands/heal.js +60 -0
- package/dist/cli/commands/impact.d.ts +4 -0
- package/dist/cli/commands/impact.d.ts.map +1 -0
- package/dist/cli/commands/impact.js +33 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +169 -0
- package/dist/cli/commands/llm_health.d.ts +2 -0
- package/dist/cli/commands/llm_health.d.ts.map +1 -0
- package/dist/cli/commands/llm_health.js +22 -0
- package/dist/cli/commands/plan.d.ts +4 -0
- package/dist/cli/commands/plan.d.ts.map +1 -0
- package/dist/cli/commands/plan.js +120 -0
- package/dist/cli/commands/plan_crew.d.ts +17 -0
- package/dist/cli/commands/plan_crew.d.ts.map +1 -0
- package/dist/cli/commands/plan_crew.js +316 -0
- package/dist/cli/commands/traceability.d.ts +4 -0
- package/dist/cli/commands/traceability.d.ts.map +1 -0
- package/dist/cli/commands/traceability.js +77 -0
- package/dist/cli/commands/train.d.ts +3 -0
- package/dist/cli/commands/train.d.ts.map +1 -0
- package/dist/cli/commands/train.js +391 -0
- package/dist/cli/defaults.d.ts +35 -0
- package/dist/cli/defaults.d.ts.map +1 -0
- package/dist/cli/defaults.js +172 -0
- package/dist/cli/errors.d.ts +27 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/errors.js +57 -0
- package/dist/cli/parse_args.d.ts +6 -0
- package/dist/cli/parse_args.d.ts.map +1 -0
- package/dist/cli/parse_args.js +257 -0
- package/dist/cli/types.d.ts +87 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +4 -0
- package/dist/cli/usage.d.ts +2 -0
- package/dist/cli/usage.d.ts.map +1 -0
- package/dist/cli/usage.js +109 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +194 -0
- package/dist/crew/context.d.ts +55 -0
- package/dist/crew/context.d.ts.map +1 -0
- package/dist/crew/context.js +36 -0
- package/dist/crew/orchestrator.d.ts +50 -0
- package/dist/crew/orchestrator.d.ts.map +1 -0
- package/dist/crew/orchestrator.js +329 -0
- package/dist/crew/protocol.d.ts +46 -0
- package/dist/crew/protocol.d.ts.map +1 -0
- package/dist/crew/protocol.js +4 -0
- package/dist/crew/provider.d.ts +17 -0
- package/dist/crew/provider.d.ts.map +1 -0
- package/dist/crew/provider.js +36 -0
- package/dist/crew/sanitize.d.ts +3 -0
- package/dist/crew/sanitize.d.ts.map +1 -0
- package/dist/crew/sanitize.js +31 -0
- package/dist/crew/types.d.ts +52 -0
- package/dist/crew/types.d.ts.map +1 -0
- package/dist/crew/types.js +4 -0
- package/dist/crew/workflows.d.ts +52 -0
- package/dist/crew/workflows.d.ts.map +1 -0
- package/dist/crew/workflows.js +36 -0
- package/dist/custom_provider.d.ts +20 -0
- package/dist/custom_provider.d.ts.map +1 -0
- package/dist/custom_provider.js +277 -0
- package/dist/engine/ai_enrichment.d.ts +44 -0
- package/dist/engine/ai_enrichment.d.ts.map +1 -0
- package/dist/engine/ai_enrichment.js +267 -0
- package/dist/engine/diff_loader.d.ts +11 -0
- package/dist/engine/diff_loader.d.ts.map +1 -0
- package/dist/engine/diff_loader.js +63 -0
- package/dist/engine/impact_engine.d.ts +72 -0
- package/dist/engine/impact_engine.d.ts.map +1 -0
- package/dist/engine/impact_engine.js +298 -0
- package/dist/engine/plan_builder.d.ts +11 -0
- package/dist/engine/plan_builder.d.ts.map +1 -0
- package/dist/engine/plan_builder.js +599 -0
- package/dist/esm/adapters/cypress.js +49 -0
- package/dist/esm/adapters/framework_adapter.js +114 -0
- package/dist/esm/adapters/playwright.js +49 -0
- package/dist/esm/adapters/pytest.js +59 -0
- package/dist/esm/adapters/supertest.js +48 -0
- package/dist/esm/agent/api_catalog.js +199 -0
- package/dist/esm/agent/config.js +872 -0
- package/dist/esm/agent/feedback.js +317 -0
- package/dist/esm/agent/git.js +252 -0
- package/dist/esm/agent/handoff.js +177 -0
- package/dist/esm/agent/llm_agents_flow.js +421 -0
- package/dist/esm/agent/native_flow.js +175 -0
- package/dist/esm/agent/pipeline.js +256 -0
- package/dist/esm/agent/pipeline_types.js +3 -0
- package/dist/esm/agent/pipeline_utils.js +146 -0
- package/dist/esm/agent/plan.js +83 -0
- package/dist/esm/agent/playwright_report.js +123 -0
- package/dist/esm/agent/process_runner.js +83 -0
- package/dist/esm/agent/spec_generator.js +249 -0
- package/dist/esm/agent/test_path.js +20 -0
- package/dist/esm/agent/traceability_capture.js +310 -0
- package/dist/esm/agent/traceability_ingest.js +234 -0
- package/dist/esm/agent/types.js +3 -0
- package/dist/esm/agent/utils.js +138 -0
- package/dist/esm/agent/validation_runner.js +73 -0
- package/dist/esm/agentic/fix_loop.js +91 -0
- package/dist/esm/agentic/playwright_runner.js +161 -0
- package/dist/esm/agentic/runner.js +207 -0
- package/dist/esm/agentic/types.js +3 -0
- package/dist/esm/agents/coverage-evaluator.js +37 -0
- package/dist/esm/agents/cross-impact.js +136 -0
- package/dist/esm/agents/executor.js +71 -0
- package/dist/esm/agents/explorer.js +39 -0
- package/dist/esm/agents/generator.js +73 -0
- package/dist/esm/agents/healer.js +27 -0
- package/dist/esm/agents/impact-analyst.js +34 -0
- package/dist/esm/agents/regression-advisor.js +112 -0
- package/dist/esm/agents/strategist.js +88 -0
- package/dist/esm/agents/test-designer.js +107 -0
- package/dist/esm/anthropic_provider.js +326 -0
- package/dist/esm/api.js +143 -0
- package/dist/esm/base_provider.js +198 -0
- package/dist/esm/budget_ledger.js +58 -0
- package/dist/esm/cache/cached_provider.js +85 -0
- package/dist/esm/cache/response_cache.js +140 -0
- package/dist/esm/cli/commands/analyze.js +74 -0
- package/dist/esm/cli/commands/bootstrap.js +106 -0
- package/dist/esm/cli/commands/cost_report.js +112 -0
- package/dist/esm/cli/commands/crew.js +252 -0
- package/dist/esm/cli/commands/feedback.js +36 -0
- package/dist/esm/cli/commands/finalize.js +38 -0
- package/dist/esm/cli/commands/gate.js +86 -0
- package/dist/esm/cli/commands/generate.js +105 -0
- package/dist/esm/cli/commands/heal.js +57 -0
- package/dist/esm/cli/commands/impact.js +30 -0
- package/dist/esm/cli/commands/init.js +133 -0
- package/dist/esm/cli/commands/llm_health.js +19 -0
- package/dist/esm/cli/commands/plan.js +117 -0
- package/dist/esm/cli/commands/plan_crew.js +309 -0
- package/dist/esm/cli/commands/traceability.js +73 -0
- package/dist/esm/cli/commands/train.js +355 -0
- package/dist/esm/cli/defaults.js +165 -0
- package/dist/esm/cli/errors.js +52 -0
- package/dist/esm/cli/parse_args.js +251 -0
- package/dist/esm/cli/types.js +3 -0
- package/dist/esm/cli/usage.js +106 -0
- package/dist/esm/cli.js +192 -0
- package/dist/esm/crew/context.js +32 -0
- package/dist/esm/crew/orchestrator.js +325 -0
- package/dist/esm/crew/protocol.js +3 -0
- package/dist/esm/crew/provider.js +33 -0
- package/dist/esm/crew/sanitize.js +27 -0
- package/dist/esm/crew/types.js +3 -0
- package/dist/esm/crew/workflows.js +33 -0
- package/dist/esm/custom_provider.js +273 -0
- package/dist/esm/engine/ai_enrichment.js +264 -0
- package/dist/esm/engine/diff_loader.js +59 -0
- package/dist/esm/engine/impact_engine.js +291 -0
- package/dist/esm/engine/plan_builder.js +593 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/knowledge/api_surface.js +408 -0
- package/dist/esm/knowledge/cluster_utils.js +60 -0
- package/dist/esm/knowledge/context_loader.js +85 -0
- package/dist/esm/knowledge/failure_history.js +121 -0
- package/dist/esm/knowledge/kg_bridge.js +381 -0
- package/dist/esm/knowledge/kg_types.js +3 -0
- package/dist/esm/knowledge/route_families.js +393 -0
- package/dist/esm/knowledge/spec_index.js +122 -0
- package/dist/esm/logger.js +115 -0
- package/dist/esm/mcp-server.js +621 -0
- package/dist/esm/metrics/prometheus.js +149 -0
- package/dist/esm/model_router.js +59 -0
- package/dist/esm/ollama_provider.js +301 -0
- package/dist/esm/openai_provider.js +243 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pipeline/orchestrator.js +228 -0
- package/dist/esm/pipeline/spec_verifier.js +75 -0
- package/dist/esm/pipeline/stage0_preprocess.js +102 -0
- package/dist/esm/pipeline/stage1_impact.js +140 -0
- package/dist/esm/pipeline/stage2_coverage.js +153 -0
- package/dist/esm/pipeline/stage3_generation.js +284 -0
- package/dist/esm/pipeline/stage4_heal.js +288 -0
- package/dist/esm/progress.js +112 -0
- package/dist/esm/prompts/coverage.js +57 -0
- package/dist/esm/prompts/cross-impact.js +53 -0
- package/dist/esm/prompts/generation.js +297 -0
- package/dist/esm/prompts/generation_profile.js +147 -0
- package/dist/esm/prompts/heal.js +91 -0
- package/dist/esm/prompts/impact.js +63 -0
- package/dist/esm/prompts/json_extract.js +36 -0
- package/dist/esm/prompts/strategist.js +61 -0
- package/dist/esm/prompts/test-designer.js +92 -0
- package/dist/esm/provider_factory.js +366 -0
- package/dist/esm/provider_interface.js +23 -0
- package/dist/esm/provider_utils.js +96 -0
- package/dist/esm/qa-agent/cli.js +205 -0
- package/dist/esm/qa-agent/orchestrator.js +120 -0
- package/dist/esm/qa-agent/phase1/runner.js +139 -0
- package/dist/esm/qa-agent/phase1/scope.js +126 -0
- package/dist/esm/qa-agent/phase2/agent_browser.js +95 -0
- package/dist/esm/qa-agent/phase2/agent_loop.js +351 -0
- package/dist/esm/qa-agent/phase2/exploration_state.js +97 -0
- package/dist/esm/qa-agent/phase2/tools.js +386 -0
- package/dist/esm/qa-agent/phase2/vision.js +75 -0
- package/dist/esm/qa-agent/phase3/feedback.js +34 -0
- package/dist/esm/qa-agent/phase3/reporter.js +145 -0
- package/dist/esm/qa-agent/phase3/spec_generator.js +62 -0
- package/dist/esm/qa-agent/phase3/verdict.js +66 -0
- package/dist/esm/qa-agent/safe_env.js +23 -0
- package/dist/esm/qa-agent/types.js +3 -0
- package/dist/esm/reporters/junit.js +86 -0
- package/dist/esm/reporters/reporter.js +3 -0
- package/dist/esm/reporters/sarif.js +132 -0
- package/dist/esm/resilience/circuit_breaker.js +78 -0
- package/dist/esm/resilience/retry.js +56 -0
- package/dist/esm/sanitize.js +66 -0
- package/dist/esm/training/enricher.js +345 -0
- package/dist/esm/training/kg_scanner.js +115 -0
- package/dist/esm/training/merger.js +204 -0
- package/dist/esm/training/scanner.js +923 -0
- package/dist/esm/training/types.js +6 -0
- package/dist/esm/training/validator.js +254 -0
- package/dist/esm/validation/guardrails.js +101 -0
- package/dist/esm/validation/output_schema.js +80 -0
- package/dist/esm/version.js +33 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -0
- package/dist/knowledge/api_surface.d.ts +37 -0
- package/dist/knowledge/api_surface.d.ts.map +1 -0
- package/dist/knowledge/api_surface.js +418 -0
- package/dist/knowledge/cluster_utils.d.ts +28 -0
- package/dist/knowledge/cluster_utils.d.ts.map +1 -0
- package/dist/knowledge/cluster_utils.js +67 -0
- package/dist/knowledge/context_loader.d.ts +13 -0
- package/dist/knowledge/context_loader.d.ts.map +1 -0
- package/dist/knowledge/context_loader.js +90 -0
- package/dist/knowledge/failure_history.d.ts +39 -0
- package/dist/knowledge/failure_history.d.ts.map +1 -0
- package/dist/knowledge/failure_history.js +128 -0
- package/dist/knowledge/kg_bridge.d.ts +31 -0
- package/dist/knowledge/kg_bridge.d.ts.map +1 -0
- package/dist/knowledge/kg_bridge.js +388 -0
- package/dist/knowledge/kg_types.d.ts +75 -0
- package/dist/knowledge/kg_types.d.ts.map +1 -0
- package/dist/knowledge/kg_types.js +4 -0
- package/dist/knowledge/route_families.d.ts +98 -0
- package/dist/knowledge/route_families.d.ts.map +1 -0
- package/dist/knowledge/route_families.js +410 -0
- package/dist/knowledge/spec_index.d.ts +18 -0
- package/dist/knowledge/spec_index.d.ts.map +1 -0
- package/dist/knowledge/spec_index.js +128 -0
- package/dist/logger.d.ts +31 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +119 -0
- package/dist/mcp-server.d.ts +68 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +629 -0
- package/dist/metrics/prometheus.d.ts +37 -0
- package/dist/metrics/prometheus.d.ts.map +1 -0
- package/dist/metrics/prometheus.js +153 -0
- package/dist/model_router.d.ts +28 -0
- package/dist/model_router.d.ts.map +1 -0
- package/dist/model_router.js +63 -0
- package/dist/ollama_provider.d.ts +65 -0
- package/dist/ollama_provider.d.ts.map +1 -0
- package/dist/ollama_provider.js +309 -0
- package/dist/openai_provider.d.ts +23 -0
- package/dist/openai_provider.d.ts.map +1 -0
- package/dist/openai_provider.js +251 -0
- package/dist/pipeline/orchestrator.d.ts +33 -0
- package/dist/pipeline/orchestrator.d.ts.map +1 -0
- package/dist/pipeline/orchestrator.js +231 -0
- package/dist/pipeline/spec_verifier.d.ts +20 -0
- package/dist/pipeline/spec_verifier.d.ts.map +1 -0
- package/dist/pipeline/spec_verifier.js +79 -0
- package/dist/pipeline/stage0_preprocess.d.ts +31 -0
- package/dist/pipeline/stage0_preprocess.d.ts.map +1 -0
- package/dist/pipeline/stage0_preprocess.js +105 -0
- package/dist/pipeline/stage1_impact.d.ts +19 -0
- package/dist/pipeline/stage1_impact.d.ts.map +1 -0
- package/dist/pipeline/stage1_impact.js +143 -0
- package/dist/pipeline/stage2_coverage.d.ts +19 -0
- package/dist/pipeline/stage2_coverage.d.ts.map +1 -0
- package/dist/pipeline/stage2_coverage.js +156 -0
- package/dist/pipeline/stage3_generation.d.ts +43 -0
- package/dist/pipeline/stage3_generation.d.ts.map +1 -0
- package/dist/pipeline/stage3_generation.js +287 -0
- package/dist/pipeline/stage4_heal.d.ts +62 -0
- package/dist/pipeline/stage4_heal.d.ts.map +1 -0
- package/dist/pipeline/stage4_heal.js +294 -0
- package/dist/progress.d.ts +22 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +116 -0
- package/dist/prompts/coverage.d.ts +39 -0
- package/dist/prompts/coverage.d.ts.map +1 -0
- package/dist/prompts/coverage.js +61 -0
- package/dist/prompts/cross-impact.d.ts +23 -0
- package/dist/prompts/cross-impact.d.ts.map +1 -0
- package/dist/prompts/cross-impact.js +57 -0
- package/dist/prompts/generation.d.ts +25 -0
- package/dist/prompts/generation.d.ts.map +1 -0
- package/dist/prompts/generation.js +302 -0
- package/dist/prompts/generation_profile.d.ts +29 -0
- package/dist/prompts/generation_profile.d.ts.map +1 -0
- package/dist/prompts/generation_profile.js +151 -0
- package/dist/prompts/heal.d.ts +23 -0
- package/dist/prompts/heal.d.ts.map +1 -0
- package/dist/prompts/heal.js +95 -0
- package/dist/prompts/impact.d.ts +31 -0
- package/dist/prompts/impact.d.ts.map +1 -0
- package/dist/prompts/impact.js +67 -0
- package/dist/prompts/json_extract.d.ts +14 -0
- package/dist/prompts/json_extract.d.ts.map +1 -0
- package/dist/prompts/json_extract.js +39 -0
- package/dist/prompts/strategist.d.ts +25 -0
- package/dist/prompts/strategist.d.ts.map +1 -0
- package/dist/prompts/strategist.js +65 -0
- package/dist/prompts/test-designer.d.ts +35 -0
- package/dist/prompts/test-designer.d.ts.map +1 -0
- package/dist/prompts/test-designer.js +96 -0
- package/dist/provider_factory.d.ts +104 -0
- package/dist/provider_factory.d.ts.map +1 -0
- package/dist/provider_factory.js +371 -0
- package/dist/provider_interface.d.ts +365 -0
- package/dist/provider_interface.d.ts.map +1 -0
- package/dist/provider_interface.js +28 -0
- package/dist/provider_utils.d.ts +39 -0
- package/dist/provider_utils.d.ts.map +1 -0
- package/dist/provider_utils.js +103 -0
- package/dist/qa-agent/cli.d.ts +3 -0
- package/dist/qa-agent/cli.d.ts.map +1 -0
- package/dist/qa-agent/cli.js +207 -0
- package/dist/qa-agent/orchestrator.d.ts +3 -0
- package/dist/qa-agent/orchestrator.d.ts.map +1 -0
- package/dist/qa-agent/orchestrator.js +123 -0
- package/dist/qa-agent/phase1/runner.d.ts +3 -0
- package/dist/qa-agent/phase1/runner.d.ts.map +1 -0
- package/dist/qa-agent/phase1/runner.js +142 -0
- package/dist/qa-agent/phase1/scope.d.ts +6 -0
- package/dist/qa-agent/phase1/scope.d.ts.map +1 -0
- package/dist/qa-agent/phase1/scope.js +129 -0
- package/dist/qa-agent/phase2/agent_browser.d.ts +35 -0
- package/dist/qa-agent/phase2/agent_browser.d.ts.map +1 -0
- package/dist/qa-agent/phase2/agent_browser.js +99 -0
- package/dist/qa-agent/phase2/agent_loop.d.ts +3 -0
- package/dist/qa-agent/phase2/agent_loop.d.ts.map +1 -0
- package/dist/qa-agent/phase2/agent_loop.js +357 -0
- package/dist/qa-agent/phase2/exploration_state.d.ts +12 -0
- package/dist/qa-agent/phase2/exploration_state.d.ts.map +1 -0
- package/dist/qa-agent/phase2/exploration_state.js +109 -0
- package/dist/qa-agent/phase2/tools.d.ts +28 -0
- package/dist/qa-agent/phase2/tools.d.ts.map +1 -0
- package/dist/qa-agent/phase2/tools.js +390 -0
- package/dist/qa-agent/phase2/vision.d.ts +3 -0
- package/dist/qa-agent/phase2/vision.d.ts.map +1 -0
- package/dist/qa-agent/phase2/vision.js +78 -0
- package/dist/qa-agent/phase3/feedback.d.ts +3 -0
- package/dist/qa-agent/phase3/feedback.d.ts.map +1 -0
- package/dist/qa-agent/phase3/feedback.js +37 -0
- package/dist/qa-agent/phase3/reporter.d.ts +3 -0
- package/dist/qa-agent/phase3/reporter.d.ts.map +1 -0
- package/dist/qa-agent/phase3/reporter.js +148 -0
- package/dist/qa-agent/phase3/spec_generator.d.ts +3 -0
- package/dist/qa-agent/phase3/spec_generator.d.ts.map +1 -0
- package/dist/qa-agent/phase3/spec_generator.js +65 -0
- package/dist/qa-agent/phase3/verdict.d.ts +3 -0
- package/dist/qa-agent/phase3/verdict.d.ts.map +1 -0
- package/dist/qa-agent/phase3/verdict.js +69 -0
- package/dist/qa-agent/safe_env.d.ts +3 -0
- package/dist/qa-agent/safe_env.d.ts.map +1 -0
- package/dist/qa-agent/safe_env.js +26 -0
- package/dist/qa-agent/types.d.ts +130 -0
- package/dist/qa-agent/types.d.ts.map +1 -0
- package/dist/qa-agent/types.js +4 -0
- package/dist/reporters/junit.d.ts +6 -0
- package/dist/reporters/junit.d.ts.map +1 -0
- package/dist/reporters/junit.js +89 -0
- package/dist/reporters/reporter.d.ts +42 -0
- package/dist/reporters/reporter.d.ts.map +1 -0
- package/dist/reporters/reporter.js +4 -0
- package/dist/reporters/sarif.d.ts +7 -0
- package/dist/reporters/sarif.d.ts.map +1 -0
- package/dist/reporters/sarif.js +135 -0
- package/dist/resilience/circuit_breaker.d.ts +36 -0
- package/dist/resilience/circuit_breaker.d.ts.map +1 -0
- package/dist/resilience/circuit_breaker.js +82 -0
- package/dist/resilience/retry.d.ts +11 -0
- package/dist/resilience/retry.d.ts.map +1 -0
- package/dist/resilience/retry.js +59 -0
- package/dist/sanitize.d.ts +15 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +71 -0
- package/dist/training/enricher.d.ts +17 -0
- package/dist/training/enricher.d.ts.map +1 -0
- package/dist/training/enricher.js +350 -0
- package/dist/training/kg_scanner.d.ts +13 -0
- package/dist/training/kg_scanner.d.ts.map +1 -0
- package/dist/training/kg_scanner.js +118 -0
- package/dist/training/merger.d.ts +15 -0
- package/dist/training/merger.d.ts.map +1 -0
- package/dist/training/merger.js +208 -0
- package/dist/training/scanner.d.ts +36 -0
- package/dist/training/scanner.d.ts.map +1 -0
- package/dist/training/scanner.js +932 -0
- package/dist/training/types.d.ts +117 -0
- package/dist/training/types.d.ts.map +1 -0
- package/dist/training/types.js +9 -0
- package/dist/training/validator.d.ts +21 -0
- package/dist/training/validator.d.ts.map +1 -0
- package/dist/training/validator.js +262 -0
- package/dist/validation/guardrails.d.ts +31 -0
- package/dist/validation/guardrails.d.ts.map +1 -0
- package/dist/validation/guardrails.js +112 -0
- package/dist/validation/output_schema.d.ts +67 -0
- package/dist/validation/output_schema.d.ts.map +1 -0
- package/dist/validation/output_schema.js +84 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +36 -0
- package/package.json +126 -0
- package/schemas/flow-decision.schema.json +83 -0
- package/schemas/gap.schema.json +18 -0
- package/schemas/impact.schema.json +455 -0
- package/schemas/plan.schema.json +491 -0
- package/schemas/route-families.schema.json +137 -0
- package/schemas/subsystem-risk-map.schema.json +62 -0
- package/schemas/traceability-input.schema.json +122 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
2
|
+
// See LICENSE.txt for license information.
|
|
3
|
+
import { sanitizeForPrompt } from '../crew/sanitize.js';
|
|
4
|
+
import { extractJsonFromResponse } from './json_extract.js';
|
|
5
|
+
export function buildStrategistPrompt(ctx) {
|
|
6
|
+
const flowsBlock = ctx.impactedFlows
|
|
7
|
+
.map((f) => {
|
|
8
|
+
const specs = f.existingSpecs.map((s) => `${s.path} (${s.coverageLevel})`).join(', ') || 'none';
|
|
9
|
+
return [
|
|
10
|
+
`- ${f.flowId} (${f.priority}): ${f.flowName}`,
|
|
11
|
+
` Route Family: ${f.routeFamily}`,
|
|
12
|
+
` Action: ${f.action}`,
|
|
13
|
+
` Confidence: ${f.confidence}%`,
|
|
14
|
+
` Existing Coverage: ${specs}`,
|
|
15
|
+
` User Actions: ${sanitizeForPrompt(f.userActions.join('; ') || 'unknown')}`,
|
|
16
|
+
` Changed Files: ${f.changedFiles.join(', ')}`,
|
|
17
|
+
].join('\n');
|
|
18
|
+
})
|
|
19
|
+
.join('\n\n');
|
|
20
|
+
const crossImpactBlock = ctx.crossImpacts.length > 0
|
|
21
|
+
? ctx.crossImpacts.map((ci) => `- ${ci.sourceFamily} → ${ci.affectedFamily} (${ci.riskLevel}): ${ci.sharedDependency} — ${ci.evidence}`).join('\n')
|
|
22
|
+
: 'No cross-family impacts detected.';
|
|
23
|
+
const regressionBlock = ctx.regressionRisks.length > 0
|
|
24
|
+
? ctx.regressionRisks.map((r) => `- ${r.familyId} (risk=${r.riskScore}): ${r.reason}`).join('\n')
|
|
25
|
+
: 'No regression risk data available.';
|
|
26
|
+
return [
|
|
27
|
+
'You are a senior QA strategist designing the overall test strategy for a code change.',
|
|
28
|
+
'',
|
|
29
|
+
`IMPACTED FLOWS (${ctx.impactedFlows.length}):`,
|
|
30
|
+
flowsBlock,
|
|
31
|
+
'',
|
|
32
|
+
'CROSS-FAMILY IMPACTS:',
|
|
33
|
+
crossImpactBlock,
|
|
34
|
+
'',
|
|
35
|
+
'REGRESSION RISK:',
|
|
36
|
+
regressionBlock,
|
|
37
|
+
'',
|
|
38
|
+
'TASK: Design a prioritized test strategy for each impacted flow.',
|
|
39
|
+
'',
|
|
40
|
+
'For each flow, decide:',
|
|
41
|
+
'1. Approach: full-test (comprehensive), smoke-test (critical path only), skip, or manual-review',
|
|
42
|
+
'2. Priority: P0 (critical path), P1 (important), P2 (nice to have)',
|
|
43
|
+
'3. Test categories to cover (from: happy-path, edge-case, boundary, negative, state-transition, race-condition, permission, accessibility, performance)',
|
|
44
|
+
'4. Cross-impact risk level based on shared dependencies',
|
|
45
|
+
'',
|
|
46
|
+
'Return strict JSON only with this shape:',
|
|
47
|
+
'{"strategy":[{"flowId":"<id>","flowName":"<name>","priority":"P0|P1|P2","approach":"full-test|smoke-test|skip|manual-review","rationale":"<why this approach>","testCategories":["happy-path","edge-case",...],"crossImpactRisk":"high|medium|low|none"}]}',
|
|
48
|
+
'',
|
|
49
|
+
'Rules:',
|
|
50
|
+
'- P0 flows with create_spec or add_scenarios action should always get full-test.',
|
|
51
|
+
'- Flows with high cross-impact risk should be promoted to at least P1.',
|
|
52
|
+
'- Flows with high regression risk should include edge-case and boundary categories.',
|
|
53
|
+
'- Skip flows only if confidence < 30 AND no cross-impact risk.',
|
|
54
|
+
'- Include accessibility category for any flow involving interactive UI elements.',
|
|
55
|
+
'- Include permission category for any flow involving role-based features.',
|
|
56
|
+
'- Keep rationale concise (1-2 sentences) explaining why this approach was chosen.',
|
|
57
|
+
].join('\n');
|
|
58
|
+
}
|
|
59
|
+
export function parseStrategistResponse(text) {
|
|
60
|
+
return extractJsonFromResponse(text, (obj) => obj != null && typeof obj === 'object' && Array.isArray(obj.strategy));
|
|
61
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
2
|
+
// See LICENSE.txt for license information.
|
|
3
|
+
import { extractJsonFromResponse } from './json_extract.js';
|
|
4
|
+
import { formatApiSurfaceForPrompt } from '../knowledge/api_surface.js';
|
|
5
|
+
import { sanitizeForPrompt } from '../crew/sanitize.js';
|
|
6
|
+
export function buildTestDesignerPrompt(ctx) {
|
|
7
|
+
const relevantClasses = ctx.apiSurface.pageObjects
|
|
8
|
+
.map((po) => po.className)
|
|
9
|
+
.filter((name) => {
|
|
10
|
+
const lower = name.toLowerCase();
|
|
11
|
+
const hints = [ctx.flow.routeFamily, ctx.flow.featureId, ...ctx.flow.userActions.join(' ').split(/\s+/)]
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.map((s) => s.toLowerCase().replace(/[^a-z]/g, ''));
|
|
14
|
+
return lower.includes('page') || hints.some((h) => h.length > 3 && lower.includes(h));
|
|
15
|
+
})
|
|
16
|
+
.slice(0, 10);
|
|
17
|
+
const apiBlock = relevantClasses.length > 0
|
|
18
|
+
? formatApiSurfaceForPrompt(ctx.apiSurface, relevantClasses)
|
|
19
|
+
: 'No page objects available.';
|
|
20
|
+
const existingSpecsBlock = ctx.existingSpecs.length > 0
|
|
21
|
+
? ctx.existingSpecs.map((s) => `- ${s.relativePath}: ${s.testTitles.join(', ')}`).join('\n')
|
|
22
|
+
: 'No existing specs.';
|
|
23
|
+
const crossImpactBlock = ctx.crossImpacts.length > 0
|
|
24
|
+
? ctx.crossImpacts.map((ci) => `- ${ci.sourceFamily} → ${ci.affectedFamily}: ${ci.sharedDependency} (${ci.riskLevel})`).join('\n')
|
|
25
|
+
: 'None detected.';
|
|
26
|
+
const categories = ctx.strategy.testCategories.join(', ');
|
|
27
|
+
return [
|
|
28
|
+
`You are a senior QA engineer designing comprehensive test cases for a ${ctx.profile?.projectName || 'project'} user flow.`,
|
|
29
|
+
'',
|
|
30
|
+
`FLOW: ${ctx.flow.flowName}`,
|
|
31
|
+
`Flow ID: ${ctx.flow.flowId}`,
|
|
32
|
+
`Route Family: ${ctx.flow.routeFamily}${ctx.flow.featureId ? ` / ${ctx.flow.featureId}` : ''}`,
|
|
33
|
+
`Route: ${ctx.flow.specificRoute || '(not specified)'}`,
|
|
34
|
+
`Priority: ${ctx.strategy.priority}`,
|
|
35
|
+
`Approach: ${ctx.strategy.approach}`,
|
|
36
|
+
`User Actions: ${sanitizeForPrompt(ctx.flow.userActions.join('; ') || 'unknown')}`,
|
|
37
|
+
`Evidence: ${sanitizeForPrompt(ctx.flow.evidence)}`,
|
|
38
|
+
'',
|
|
39
|
+
`REQUIRED TEST CATEGORIES: ${categories}`,
|
|
40
|
+
'',
|
|
41
|
+
'AVAILABLE PAGE OBJECTS:',
|
|
42
|
+
apiBlock,
|
|
43
|
+
'',
|
|
44
|
+
'EXISTING SPECS (avoid duplicating these):',
|
|
45
|
+
existingSpecsBlock,
|
|
46
|
+
'',
|
|
47
|
+
'CROSS-FAMILY IMPACTS:',
|
|
48
|
+
crossImpactBlock,
|
|
49
|
+
'',
|
|
50
|
+
'TASK: Design structured test cases for this flow.',
|
|
51
|
+
'',
|
|
52
|
+
'Return strict JSON only with this shape:',
|
|
53
|
+
'{"testDesign":{"flowId":"<id>","flowName":"<name>","testCases":[{"name":"<descriptive name>","type":"<category>","preconditions":["<state required>"],"steps":["<user action>"],"expectedOutcome":"<what should happen>","priority":"P0|P1|P2","rationale":"<why this test matters>"}]}}',
|
|
54
|
+
'',
|
|
55
|
+
'TYPE VALUES: happy-path, edge-case, boundary, negative, state-transition, race-condition, permission, accessibility, performance',
|
|
56
|
+
'',
|
|
57
|
+
'Rules:',
|
|
58
|
+
'- Every test must describe a specific USER ACTION, not an implementation detail.',
|
|
59
|
+
'- Steps must be concrete: "click Create Channel button" not "test channel creation".',
|
|
60
|
+
'- Include preconditions (logged-in role, existing data state, etc.).',
|
|
61
|
+
'- Reference only page objects and methods listed above.',
|
|
62
|
+
'- Include a mandatory rationale explaining why this specific test case matters.',
|
|
63
|
+
'- Do NOT duplicate tests already covered by existing specs.',
|
|
64
|
+
'- Maximum 15 test cases per flow.',
|
|
65
|
+
'- For accessibility: test keyboard navigation, screen reader support, ARIA labels.',
|
|
66
|
+
'- For performance: test with realistic data volumes, measure load times.',
|
|
67
|
+
'- For edge cases: test unicode input, max-length fields, empty states, concurrent edits.',
|
|
68
|
+
'',
|
|
69
|
+
'FEW-SHOT EXAMPLES:',
|
|
70
|
+
'',
|
|
71
|
+
'Edge case example:',
|
|
72
|
+
'```json',
|
|
73
|
+
'{"name":"channel creation with unicode characters and max-length name","type":"edge-case","preconditions":["logged in as team member","team has < 1000 channels"],"steps":["open create channel dialog","enter 64-character name with emoji and CJK characters","click Create"],"expectedOutcome":"channel created successfully, name renders correctly in sidebar and header","priority":"P1","rationale":"catches encoding issues in channel name storage and rendering"}',
|
|
74
|
+
'```',
|
|
75
|
+
'',
|
|
76
|
+
'Permission example:',
|
|
77
|
+
'```json',
|
|
78
|
+
'{"name":"guest user cannot archive a public channel","type":"permission","preconditions":["logged in as guest user","guest has access to public channel"],"steps":["open channel header menu","look for Archive Channel option"],"expectedOutcome":"Archive Channel option is not visible in the menu","priority":"P0","rationale":"permission escalation bug — guests archiving channels could disrupt entire teams"}',
|
|
79
|
+
'```',
|
|
80
|
+
'',
|
|
81
|
+
'Accessibility example:',
|
|
82
|
+
'```json',
|
|
83
|
+
'{"name":"keyboard navigation through channel switcher results","type":"accessibility","preconditions":["logged in","channel switcher open via Ctrl+K"],"steps":["type partial channel name","press ArrowDown to navigate results","press Enter to select"],"expectedOutcome":"focus moves visually and via aria-activedescendant, selected channel opens","priority":"P1","rationale":"screen reader users rely on keyboard navigation — broken focus management makes the app unusable"}',
|
|
84
|
+
'```',
|
|
85
|
+
].join('\n');
|
|
86
|
+
}
|
|
87
|
+
export function parseTestDesignerResponse(text) {
|
|
88
|
+
return extractJsonFromResponse(text, (obj) => {
|
|
89
|
+
const r = obj;
|
|
90
|
+
return r?.testDesign?.testCases != null && Array.isArray(r.testDesign.testCases);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
2
|
+
// See LICENSE.txt for license information.
|
|
3
|
+
import { AnthropicProvider } from './anthropic_provider.js';
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
import { CustomProvider } from './custom_provider.js';
|
|
6
|
+
import { OllamaProvider } from './ollama_provider.js';
|
|
7
|
+
import { OpenAIProvider } from './openai_provider.js';
|
|
8
|
+
import { UnsupportedCapabilityError } from './provider_interface.js';
|
|
9
|
+
/**
|
|
10
|
+
* LLM Provider Factory
|
|
11
|
+
*
|
|
12
|
+
* Creates and configures LLM providers based on configuration.
|
|
13
|
+
* Supports multiple strategies:
|
|
14
|
+
* - Single provider (Ollama, Anthropic, etc.)
|
|
15
|
+
* - Hybrid provider (free primary + premium fallback)
|
|
16
|
+
* - Auto-selection based on environment
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
*
|
|
20
|
+
* // Create single provider
|
|
21
|
+
* const provider = LLMProviderFactory.create({
|
|
22
|
+
* type: 'ollama',
|
|
23
|
+
* config: { model: 'deepseek-r1:7b' }
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Create hybrid provider
|
|
27
|
+
* const provider = LLMProviderFactory.createHybrid({
|
|
28
|
+
* primary: { type: 'ollama', config: { model: 'deepseek-r1:7b' } },
|
|
29
|
+
* fallback: { type: 'anthropic', config: { apiKey: '...' } },
|
|
30
|
+
* useFallbackFor: ['vision']
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Auto-detect from environment
|
|
34
|
+
* const provider = LLMProviderFactory.createFromEnv();
|
|
35
|
+
*/
|
|
36
|
+
export class LLMProviderFactory {
|
|
37
|
+
/**
|
|
38
|
+
* Create a single LLM provider
|
|
39
|
+
*/
|
|
40
|
+
static create(config) {
|
|
41
|
+
switch (config.type) {
|
|
42
|
+
case 'ollama':
|
|
43
|
+
return new OllamaProvider(config.config);
|
|
44
|
+
case 'anthropic':
|
|
45
|
+
return new AnthropicProvider(config.config);
|
|
46
|
+
case 'openai':
|
|
47
|
+
return new OpenAIProvider(config.config);
|
|
48
|
+
case 'custom':
|
|
49
|
+
return new CustomProvider(config.config);
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`Unknown provider type: ${config.type}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a hybrid provider (free primary + premium fallback)
|
|
56
|
+
*
|
|
57
|
+
* Use cases:
|
|
58
|
+
* - Most operations use free Ollama
|
|
59
|
+
* - Vision tasks fall back to Claude
|
|
60
|
+
* - Complex diagnosis falls back to Claude
|
|
61
|
+
*
|
|
62
|
+
* This gives best cost/quality balance:
|
|
63
|
+
* - ~$20/month instead of $80/month (75% cost reduction)
|
|
64
|
+
* - Still get premium quality for vision and complex tasks
|
|
65
|
+
*/
|
|
66
|
+
static createHybrid(config) {
|
|
67
|
+
const primary = this.create(config.primary);
|
|
68
|
+
const fallback = this.create(config.fallback);
|
|
69
|
+
return new HybridProvider({
|
|
70
|
+
primary,
|
|
71
|
+
fallback,
|
|
72
|
+
useFallbackFor: config.useFallbackFor || ['vision'],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Auto-detect provider from environment variables
|
|
77
|
+
*
|
|
78
|
+
* Priority:
|
|
79
|
+
* 1. LLM_PROVIDER env var (ollama, anthropic, openai)
|
|
80
|
+
* 2. ANTHROPIC_API_KEY exists → Anthropic
|
|
81
|
+
* 3. OPENAI_API_KEY exists → OpenAI
|
|
82
|
+
* 4. Ollama running locally → Ollama
|
|
83
|
+
* 5. Error (no provider available)
|
|
84
|
+
*/
|
|
85
|
+
static async createFromEnv() {
|
|
86
|
+
const providerType = process.env.LLM_PROVIDER?.toLowerCase();
|
|
87
|
+
const normalizedProviderType = providerType?.trim().toLowerCase();
|
|
88
|
+
if (normalizedProviderType && !['ollama', 'openai', 'anthropic', 'auto'].includes(normalizedProviderType)) {
|
|
89
|
+
throw new Error(`Unknown LLM_PROVIDER value "${providerType}". Expected one of: ollama, openai, anthropic, auto`);
|
|
90
|
+
}
|
|
91
|
+
if (normalizedProviderType === 'ollama') {
|
|
92
|
+
return new OllamaProvider({
|
|
93
|
+
baseUrl: process.env.OLLAMA_BASE_URL || 'http://localhost:11434/v1',
|
|
94
|
+
model: process.env.OLLAMA_MODEL || 'deepseek-r1:7b',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (normalizedProviderType === 'openai') {
|
|
98
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
99
|
+
throw new Error('OPENAI_API_KEY environment variable is required for OpenAI provider');
|
|
100
|
+
}
|
|
101
|
+
return new OpenAIProvider({
|
|
102
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
103
|
+
model: process.env.OPENAI_MODEL || 'gpt-4',
|
|
104
|
+
baseUrl: process.env.OPENAI_BASE_URL,
|
|
105
|
+
organizationId: process.env.OPENAI_ORG_ID,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (normalizedProviderType === 'anthropic') {
|
|
109
|
+
if (!process.env.ANTHROPIC_API_KEY) {
|
|
110
|
+
throw new Error('ANTHROPIC_API_KEY environment variable is required for Anthropic provider');
|
|
111
|
+
}
|
|
112
|
+
return new AnthropicProvider({
|
|
113
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
114
|
+
model: process.env.ANTHROPIC_MODEL || 'claude-sonnet-4-5-20250929',
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
118
|
+
return new AnthropicProvider({
|
|
119
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
120
|
+
model: process.env.ANTHROPIC_MODEL || 'claude-sonnet-4-5-20250929',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (process.env.OPENAI_API_KEY) {
|
|
124
|
+
return new OpenAIProvider({
|
|
125
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
126
|
+
model: process.env.OPENAI_MODEL || 'gpt-4',
|
|
127
|
+
baseUrl: process.env.OPENAI_BASE_URL,
|
|
128
|
+
organizationId: process.env.OPENAI_ORG_ID,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// Try Ollama as default
|
|
132
|
+
const ollama = new OllamaProvider({});
|
|
133
|
+
const health = await ollama.checkHealth();
|
|
134
|
+
if (health.healthy) {
|
|
135
|
+
logger.info('Auto-detected Ollama provider (free, local)');
|
|
136
|
+
return ollama;
|
|
137
|
+
}
|
|
138
|
+
throw new Error('No LLM provider available. Please either:\n' +
|
|
139
|
+
'1. Install Ollama: curl -fsSL https://ollama.com/install.sh | sh\n' +
|
|
140
|
+
'2. Set ANTHROPIC_API_KEY environment variable\n' +
|
|
141
|
+
'3. Set OPENAI_API_KEY environment variable\n' +
|
|
142
|
+
'4. Set LLM_PROVIDER environment variable');
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Create provider from an explicit preference when supplied, otherwise
|
|
146
|
+
* fall back to environment auto-detection.
|
|
147
|
+
*/
|
|
148
|
+
static async createFromPreference(providerPreference) {
|
|
149
|
+
const normalized = providerPreference?.trim().toLowerCase();
|
|
150
|
+
if (!normalized || normalized === 'auto') {
|
|
151
|
+
return this.createFromEnv();
|
|
152
|
+
}
|
|
153
|
+
return this.createFromString(normalized);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Create provider from simple string format
|
|
157
|
+
*
|
|
158
|
+
* Examples:
|
|
159
|
+
* - "ollama" → Ollama with defaults
|
|
160
|
+
* - "ollama:deepseek-r1:14b" → Ollama with specific model
|
|
161
|
+
* - "anthropic" → Anthropic with env API key
|
|
162
|
+
* - "anthropic:claude-opus-4-5" → Anthropic with specific model
|
|
163
|
+
* - "openai" → OpenAI with env API key
|
|
164
|
+
* - "openai:gpt-4" → OpenAI with specific model
|
|
165
|
+
*/
|
|
166
|
+
static createFromString(providerString) {
|
|
167
|
+
const [type, ...modelParts] = providerString.split(':');
|
|
168
|
+
const model = modelParts.join(':');
|
|
169
|
+
switch (type.toLowerCase()) {
|
|
170
|
+
case 'ollama':
|
|
171
|
+
return new OllamaProvider({
|
|
172
|
+
model: model || 'deepseek-r1:7b',
|
|
173
|
+
});
|
|
174
|
+
case 'anthropic':
|
|
175
|
+
if (!process.env.ANTHROPIC_API_KEY) {
|
|
176
|
+
throw new Error('ANTHROPIC_API_KEY environment variable is required');
|
|
177
|
+
}
|
|
178
|
+
return new AnthropicProvider({
|
|
179
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
180
|
+
model: model || 'claude-sonnet-4-5-20250929',
|
|
181
|
+
});
|
|
182
|
+
case 'openai':
|
|
183
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
184
|
+
throw new Error('OPENAI_API_KEY environment variable is required');
|
|
185
|
+
}
|
|
186
|
+
return new OpenAIProvider({
|
|
187
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
188
|
+
model: model || 'gpt-4',
|
|
189
|
+
baseUrl: process.env.OPENAI_BASE_URL,
|
|
190
|
+
organizationId: process.env.OPENAI_ORG_ID,
|
|
191
|
+
});
|
|
192
|
+
default:
|
|
193
|
+
throw new Error(`Unknown provider type: ${type}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Hybrid Provider - Mix free and premium providers
|
|
199
|
+
*
|
|
200
|
+
* Strategy:
|
|
201
|
+
* - Use free provider (Ollama) for most operations (~80% of requests)
|
|
202
|
+
* - Fall back to premium (Claude) only when needed (~20% of requests)
|
|
203
|
+
*
|
|
204
|
+
* Cost savings example:
|
|
205
|
+
* - Pure Claude: $80/month
|
|
206
|
+
* - Pure Ollama: $0/month but no vision
|
|
207
|
+
* - Hybrid: $20/month (75% cost reduction, keeps vision)
|
|
208
|
+
*/
|
|
209
|
+
class HybridProvider {
|
|
210
|
+
constructor(config) {
|
|
211
|
+
this.name = 'hybrid';
|
|
212
|
+
this.capabilities = {
|
|
213
|
+
// Report combined capabilities
|
|
214
|
+
vision: true, // Fallback provides vision
|
|
215
|
+
streaming: true, // Both support streaming
|
|
216
|
+
maxTokens: 0, // Will be set in constructor
|
|
217
|
+
costPer1MInputTokens: 0, // Variable cost
|
|
218
|
+
costPer1MOutputTokens: 0, // Variable cost
|
|
219
|
+
supportsTools: true,
|
|
220
|
+
supportsPromptCaching: false,
|
|
221
|
+
typicalResponseTimeMs: 0, // Variable
|
|
222
|
+
};
|
|
223
|
+
this.primary = config.primary;
|
|
224
|
+
this.fallback = config.fallback;
|
|
225
|
+
this.useFallbackFor = new Set(config.useFallbackFor);
|
|
226
|
+
// Set combined capabilities
|
|
227
|
+
this.capabilities.maxTokens = Math.max(this.primary.capabilities.maxTokens, this.fallback.capabilities.maxTokens);
|
|
228
|
+
this.capabilities.typicalResponseTimeMs = this.primary.capabilities.typicalResponseTimeMs;
|
|
229
|
+
}
|
|
230
|
+
async generateText(prompt, options) {
|
|
231
|
+
// Use primary for text generation (free)
|
|
232
|
+
logger.debug(`[Hybrid] Using ${this.primary.name} for text generation`);
|
|
233
|
+
return await this.primary.generateText(prompt, options);
|
|
234
|
+
}
|
|
235
|
+
async analyzeImage(images, prompt, options) {
|
|
236
|
+
// Check if vision is a fallback trigger
|
|
237
|
+
if (this.useFallbackFor.has('vision')) {
|
|
238
|
+
// Use fallback if primary doesn't support vision
|
|
239
|
+
if (!this.primary.capabilities.vision) {
|
|
240
|
+
logger.debug(`[Hybrid] Using ${this.fallback.name} for vision analysis (primary doesn't support vision)`);
|
|
241
|
+
if (!this.fallback.analyzeImage) {
|
|
242
|
+
throw new UnsupportedCapabilityError(this.name, 'vision');
|
|
243
|
+
}
|
|
244
|
+
return await this.fallback.analyzeImage(images, prompt, options);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Try primary first
|
|
248
|
+
if (this.primary.analyzeImage) {
|
|
249
|
+
logger.debug(`[Hybrid] Using ${this.primary.name} for vision analysis`);
|
|
250
|
+
return await this.primary.analyzeImage(images, prompt, options);
|
|
251
|
+
}
|
|
252
|
+
throw new UnsupportedCapabilityError(this.name, 'vision');
|
|
253
|
+
}
|
|
254
|
+
async *streamText(prompt, options) {
|
|
255
|
+
// Use primary for streaming (free)
|
|
256
|
+
if (!this.primary.streamText) {
|
|
257
|
+
throw new UnsupportedCapabilityError(this.primary.name, 'streaming');
|
|
258
|
+
}
|
|
259
|
+
logger.debug(`[Hybrid] Using ${this.primary.name} for streaming`);
|
|
260
|
+
yield* this.primary.streamText(prompt, options);
|
|
261
|
+
}
|
|
262
|
+
getUsageStats() {
|
|
263
|
+
const primaryStats = this.primary.getUsageStats();
|
|
264
|
+
const fallbackStats = this.fallback.getUsageStats();
|
|
265
|
+
// Combine stats
|
|
266
|
+
const totalRequests = primaryStats.requestCount + fallbackStats.requestCount;
|
|
267
|
+
return {
|
|
268
|
+
requestCount: totalRequests,
|
|
269
|
+
totalInputTokens: primaryStats.totalInputTokens + fallbackStats.totalInputTokens,
|
|
270
|
+
totalOutputTokens: primaryStats.totalOutputTokens + fallbackStats.totalOutputTokens,
|
|
271
|
+
totalTokens: primaryStats.totalTokens + fallbackStats.totalTokens,
|
|
272
|
+
totalCost: primaryStats.totalCost + fallbackStats.totalCost,
|
|
273
|
+
averageResponseTimeMs: totalRequests > 0
|
|
274
|
+
? (primaryStats.averageResponseTimeMs * primaryStats.requestCount +
|
|
275
|
+
fallbackStats.averageResponseTimeMs * fallbackStats.requestCount) / totalRequests
|
|
276
|
+
: 0,
|
|
277
|
+
failedRequests: primaryStats.failedRequests + fallbackStats.failedRequests,
|
|
278
|
+
startTime: new Date(Math.min(primaryStats.startTime.getTime(), fallbackStats.startTime.getTime())),
|
|
279
|
+
lastUpdated: new Date(Math.max(primaryStats.lastUpdated.getTime(), fallbackStats.lastUpdated.getTime())),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
resetUsageStats() {
|
|
283
|
+
this.primary.resetUsageStats();
|
|
284
|
+
this.fallback.resetUsageStats();
|
|
285
|
+
}
|
|
286
|
+
async checkHealth() {
|
|
287
|
+
const primaryHealth = await this.primary.checkHealth();
|
|
288
|
+
if (primaryHealth.healthy) {
|
|
289
|
+
return { healthy: true, message: `${this.primary.name}: ${primaryHealth.message}` };
|
|
290
|
+
}
|
|
291
|
+
const fallbackHealth = await this.fallback.checkHealth();
|
|
292
|
+
if (fallbackHealth.healthy) {
|
|
293
|
+
return {
|
|
294
|
+
healthy: true,
|
|
295
|
+
message: `${this.primary.name} unhealthy (${primaryHealth.message}); fallback ${this.fallback.name}: ${fallbackHealth.message}`,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
healthy: false,
|
|
300
|
+
message: `${this.primary.name} unhealthy (${primaryHealth.message}); fallback ${this.fallback.name} unhealthy (${fallbackHealth.message})`,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get breakdown of which provider was used for what
|
|
305
|
+
*/
|
|
306
|
+
getProviderBreakdown() {
|
|
307
|
+
const primaryStats = this.primary.getUsageStats();
|
|
308
|
+
const fallbackStats = this.fallback.getUsageStats();
|
|
309
|
+
// Calculate what it would cost if we used only fallback
|
|
310
|
+
const totalRequests = primaryStats.requestCount + fallbackStats.requestCount;
|
|
311
|
+
const fallbackCostPerRequest = fallbackStats.requestCount > 0 ? fallbackStats.totalCost / fallbackStats.requestCount : 0;
|
|
312
|
+
const hypotheticalFullCost = totalRequests * fallbackCostPerRequest;
|
|
313
|
+
const actualCost = primaryStats.totalCost + fallbackStats.totalCost;
|
|
314
|
+
const savings = hypotheticalFullCost - actualCost;
|
|
315
|
+
const savingsPercent = hypotheticalFullCost > 0 ? (savings / hypotheticalFullCost) * 100 : 0;
|
|
316
|
+
return {
|
|
317
|
+
primary: {
|
|
318
|
+
name: this.primary.name,
|
|
319
|
+
stats: primaryStats,
|
|
320
|
+
},
|
|
321
|
+
fallback: {
|
|
322
|
+
name: this.fallback.name,
|
|
323
|
+
stats: fallbackStats,
|
|
324
|
+
},
|
|
325
|
+
costSavings: `$${savings.toFixed(2)} saved (${savingsPercent.toFixed(1)}% reduction)`,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Helper to validate provider setup
|
|
331
|
+
*/
|
|
332
|
+
export async function validateProviderSetup(provider) {
|
|
333
|
+
const capabilities = [];
|
|
334
|
+
if (provider.capabilities.vision) {
|
|
335
|
+
capabilities.push('✓ Vision support (screenshot comparison)');
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
capabilities.push('✗ No vision support');
|
|
339
|
+
}
|
|
340
|
+
if (provider.capabilities.streaming) {
|
|
341
|
+
capabilities.push('✓ Streaming responses');
|
|
342
|
+
}
|
|
343
|
+
if (provider.capabilities.supportsTools) {
|
|
344
|
+
capabilities.push('✓ Function calling');
|
|
345
|
+
}
|
|
346
|
+
capabilities.push(`✓ ${provider.capabilities.maxTokens.toLocaleString()} token context window`);
|
|
347
|
+
capabilities.push(`✓ Cost: $${provider.capabilities.costPer1MOutputTokens}/1M tokens`);
|
|
348
|
+
try {
|
|
349
|
+
// Try a simple request
|
|
350
|
+
const response = await provider.generateText('Say "OK" if you can read this', {
|
|
351
|
+
maxTokens: 10,
|
|
352
|
+
});
|
|
353
|
+
return {
|
|
354
|
+
valid: response.text.length > 0,
|
|
355
|
+
message: `Provider '${provider.name}' is working correctly`,
|
|
356
|
+
capabilities,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
return {
|
|
361
|
+
valid: false,
|
|
362
|
+
message: `Provider '${provider.name}' validation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
363
|
+
capabilities,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
2
|
+
// See LICENSE.txt for license information.
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown by LLM providers
|
|
5
|
+
*/
|
|
6
|
+
export class LLMProviderError extends Error {
|
|
7
|
+
constructor(message, provider, statusCode, cause) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.provider = provider;
|
|
10
|
+
this.statusCode = statusCode;
|
|
11
|
+
this.cause = cause;
|
|
12
|
+
this.name = 'LLMProviderError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown when a required capability is not supported
|
|
17
|
+
*/
|
|
18
|
+
export class UnsupportedCapabilityError extends LLMProviderError {
|
|
19
|
+
constructor(provider, capability) {
|
|
20
|
+
super(`Provider '${provider}' does not support capability: ${capability}`, provider);
|
|
21
|
+
this.name = 'UnsupportedCapabilityError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
2
|
+
// See LICENSE.txt for license information.
|
|
3
|
+
/**
|
|
4
|
+
* SECURITY: Shared utility functions for all LLM providers
|
|
5
|
+
* Eliminates code duplication and ensures consistent error handling
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Pre-compiled regex patterns for API key validation
|
|
9
|
+
* Compiled once and reused to avoid repeated regex compilation
|
|
10
|
+
*/
|
|
11
|
+
export const API_KEY_PATTERNS = {
|
|
12
|
+
anthropic: /^sk-ant-[a-zA-Z0-9_\-]{20,}$/,
|
|
13
|
+
openai: /^sk-[a-zA-Z0-9_\-]{20,}$/,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* SECURITY: Sanitize error messages to prevent information leakage
|
|
17
|
+
* Maps specific API errors to safe, user-friendly messages
|
|
18
|
+
* Prevents leaking stack traces, API keys, or internal details
|
|
19
|
+
*/
|
|
20
|
+
export function sanitizeErrorMessage(error, context) {
|
|
21
|
+
if (error instanceof Error) {
|
|
22
|
+
const msg = error.message.toLowerCase();
|
|
23
|
+
// Map specific API errors to safe messages
|
|
24
|
+
if (msg.includes('401') || msg.includes('authentication')) {
|
|
25
|
+
return `Authentication failed (${context})`;
|
|
26
|
+
}
|
|
27
|
+
if (msg.includes('429') || msg.includes('rate')) {
|
|
28
|
+
return `Rate limit exceeded (${context})`;
|
|
29
|
+
}
|
|
30
|
+
if (msg.includes('timeout') || msg.includes('etimedout')) {
|
|
31
|
+
return `Request timeout (${context})`;
|
|
32
|
+
}
|
|
33
|
+
if (msg.includes('network') || msg.includes('econnrefused')) {
|
|
34
|
+
return `Connection failed (${context})`;
|
|
35
|
+
}
|
|
36
|
+
if (msg.includes('enotfound') || msg.includes('getaddrinfo')) {
|
|
37
|
+
return `Host not found (${context})`;
|
|
38
|
+
}
|
|
39
|
+
// Don't leak stack traces, API keys, or internal details
|
|
40
|
+
return `Operation failed (${context})`;
|
|
41
|
+
}
|
|
42
|
+
return 'An unexpected error occurred';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generic timeout wrapper for promises
|
|
46
|
+
* Rejects with timeout error if promise doesn't resolve in time
|
|
47
|
+
*/
|
|
48
|
+
export function withTimeout(promise, timeoutMs, context) {
|
|
49
|
+
if (!timeoutMs) {
|
|
50
|
+
return promise;
|
|
51
|
+
}
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const timer = setTimeout(() => reject(new Error(`Request timeout (${context})`)), timeoutMs);
|
|
54
|
+
promise.then((value) => {
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
resolve(value);
|
|
57
|
+
}, (error) => {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
reject(error);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Check if a hostname is localhost
|
|
65
|
+
* Used by URL validation to allow HTTP for local development
|
|
66
|
+
*/
|
|
67
|
+
export function isLocalhost(hostname) {
|
|
68
|
+
if (!hostname) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1';
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* SECURITY: Validate and enforce HTTPS for remote URLs
|
|
75
|
+
* Allows HTTP only for localhost development
|
|
76
|
+
* Returns validation result with optional warning message
|
|
77
|
+
*/
|
|
78
|
+
export function validateAndSanitizeUrl(baseUrl) {
|
|
79
|
+
if (!baseUrl) {
|
|
80
|
+
return { valid: true };
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const url = new URL(baseUrl);
|
|
84
|
+
// For non-localhost URLs, require HTTPS
|
|
85
|
+
if (!isLocalhost(url.hostname) && url.protocol !== 'https:') {
|
|
86
|
+
return {
|
|
87
|
+
valid: false,
|
|
88
|
+
warning: `HTTPS required for remote URLs. Got: ${url.protocol}//${url.hostname}`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return { valid: true, url: baseUrl };
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return { valid: false };
|
|
95
|
+
}
|
|
96
|
+
}
|