@agentlensai/server 0.11.0 → 0.13.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 +21 -0
- package/dist/cloud/auth/rbac.d.ts +1 -1
- package/dist/cloud/auth/rbac.d.ts.map +1 -1
- package/dist/cloud/auth/rbac.js +2 -2
- package/dist/cloud/auth/rbac.js.map +1 -1
- package/dist/cloud/billing/stripe-client.d.ts.map +1 -1
- package/dist/cloud/billing/stripe-client.js +6 -1
- package/dist/cloud/billing/stripe-client.js.map +1 -1
- package/dist/cloud/ingestion/gateway.d.ts.map +1 -1
- package/dist/cloud/ingestion/gateway.js +0 -1
- package/dist/cloud/ingestion/gateway.js.map +1 -1
- package/dist/cloud/middleware/validate-org-access.d.ts +14 -0
- package/dist/cloud/middleware/validate-org-access.d.ts.map +1 -0
- package/dist/cloud/middleware/validate-org-access.js +38 -0
- package/dist/cloud/middleware/validate-org-access.js.map +1 -0
- package/dist/cloud/routes/index.d.ts +13 -0
- package/dist/cloud/routes/index.d.ts.map +1 -0
- package/dist/cloud/routes/index.js +98 -0
- package/dist/cloud/routes/index.js.map +1 -0
- package/dist/config.d.ts +33 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +71 -1
- package/dist/config.js.map +1 -1
- package/dist/db/api-key-lookup.d.ts +25 -0
- package/dist/db/api-key-lookup.d.ts.map +1 -0
- package/dist/db/api-key-lookup.js +38 -0
- package/dist/db/api-key-lookup.js.map +1 -0
- package/dist/db/connection.postgres.d.ts +44 -0
- package/dist/db/connection.postgres.d.ts.map +1 -0
- package/dist/db/connection.postgres.js +79 -0
- package/dist/db/connection.postgres.js.map +1 -0
- package/dist/db/cost-budget-store.d.ts +30 -0
- package/dist/db/cost-budget-store.d.ts.map +1 -0
- package/dist/db/cost-budget-store.js +201 -0
- package/dist/db/cost-budget-store.js.map +1 -0
- package/dist/db/drizzle/0000_initial.sql +336 -0
- package/dist/db/drizzle/0001_indexes.sql +20 -0
- package/dist/db/drizzle/0002_pgvector.sql +19 -0
- package/dist/db/drizzle/drizzle/0000_initial.sql +336 -0
- package/dist/db/drizzle/drizzle/0001_indexes.sql +20 -0
- package/dist/db/drizzle/drizzle/0002_pgvector.sql +19 -0
- package/dist/db/drizzle/drizzle/meta/0000_snapshot.json +2593 -0
- package/dist/db/drizzle/drizzle/meta/_journal.json +27 -0
- package/dist/db/drizzle/meta/0000_snapshot.json +2593 -0
- package/dist/db/drizzle/meta/_journal.json +27 -0
- package/dist/db/embedding-store.d.ts +2 -1
- package/dist/db/embedding-store.d.ts.map +1 -1
- package/dist/db/embedding-store.interface.d.ts +19 -0
- package/dist/db/embedding-store.interface.d.ts.map +1 -0
- package/dist/db/embedding-store.interface.js +7 -0
- package/dist/db/embedding-store.interface.js.map +1 -0
- package/dist/db/embedding-store.js +3 -1
- package/dist/db/embedding-store.js.map +1 -1
- package/dist/db/eval-store.d.ts +88 -0
- package/dist/db/eval-store.d.ts.map +1 -0
- package/dist/db/eval-store.js +408 -0
- package/dist/db/eval-store.js.map +1 -0
- package/dist/db/guardrail-store.d.ts +9 -0
- package/dist/db/guardrail-store.d.ts.map +1 -1
- package/dist/db/guardrail-store.js +57 -3
- package/dist/db/guardrail-store.js.map +1 -1
- package/dist/db/index.d.ts +7 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +4 -12
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrate.d.ts +5 -22
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +7 -637
- package/dist/db/migrate.js.map +1 -1
- package/dist/db/migrate.postgres.d.ts +16 -0
- package/dist/db/migrate.postgres.d.ts.map +1 -0
- package/dist/db/migrate.postgres.js +23 -0
- package/dist/db/migrate.postgres.js.map +1 -0
- package/dist/db/migrate.sqlite.d.ts +26 -0
- package/dist/db/migrate.sqlite.d.ts.map +1 -0
- package/dist/db/migrate.sqlite.js +920 -0
- package/dist/db/migrate.sqlite.js.map +1 -0
- package/dist/db/postgres-embedding-store.d.ts +23 -0
- package/dist/db/postgres-embedding-store.d.ts.map +1 -0
- package/dist/db/postgres-embedding-store.js +218 -0
- package/dist/db/postgres-embedding-store.js.map +1 -0
- package/dist/db/postgres-store.d.ts +80 -0
- package/dist/db/postgres-store.d.ts.map +1 -0
- package/dist/db/postgres-store.js +910 -0
- package/dist/db/postgres-store.js.map +1 -0
- package/dist/db/prompt-store.d.ts +57 -0
- package/dist/db/prompt-store.d.ts.map +1 -0
- package/dist/db/prompt-store.js +300 -0
- package/dist/db/prompt-store.js.map +1 -0
- package/dist/db/repositories/agent-repository.d.ts +21 -0
- package/dist/db/repositories/agent-repository.d.ts.map +1 -0
- package/dist/db/repositories/agent-repository.js +142 -0
- package/dist/db/repositories/agent-repository.js.map +1 -0
- package/dist/db/repositories/alert-repository.d.ts +27 -0
- package/dist/db/repositories/alert-repository.d.ts.map +1 -0
- package/dist/db/repositories/alert-repository.js +164 -0
- package/dist/db/repositories/alert-repository.js.map +1 -0
- package/dist/db/repositories/analytics-repository.d.ts +24 -0
- package/dist/db/repositories/analytics-repository.d.ts.map +1 -0
- package/dist/db/repositories/analytics-repository.js +147 -0
- package/dist/db/repositories/analytics-repository.js.map +1 -0
- package/dist/db/repositories/event-repository.d.ts +81 -0
- package/dist/db/repositories/event-repository.d.ts.map +1 -0
- package/dist/db/repositories/event-repository.js +331 -0
- package/dist/db/repositories/event-repository.js.map +1 -0
- package/dist/db/repositories/notification-channel-repository.d.ts +28 -0
- package/dist/db/repositories/notification-channel-repository.d.ts.map +1 -0
- package/dist/db/repositories/notification-channel-repository.js +151 -0
- package/dist/db/repositories/notification-channel-repository.js.map +1 -0
- package/dist/db/repositories/session-repository.d.ts +26 -0
- package/dist/db/repositories/session-repository.d.ts.map +1 -0
- package/dist/db/repositories/session-repository.js +240 -0
- package/dist/db/repositories/session-repository.js.map +1 -0
- package/dist/db/schema.postgres.d.ts +4681 -0
- package/dist/db/schema.postgres.d.ts.map +1 -0
- package/dist/db/schema.postgres.js +458 -0
- package/dist/db/schema.postgres.js.map +1 -0
- package/dist/db/schema.sqlite.d.ts +2221 -671
- package/dist/db/schema.sqlite.d.ts.map +1 -1
- package/dist/db/schema.sqlite.js +137 -2
- package/dist/db/schema.sqlite.js.map +1 -1
- package/dist/db/services/retention-service.d.ts +13 -0
- package/dist/db/services/retention-service.d.ts.map +1 -0
- package/dist/db/services/retention-service.js +48 -0
- package/dist/db/services/retention-service.js.map +1 -0
- package/dist/db/shared/query-helpers.d.ts +32 -0
- package/dist/db/shared/query-helpers.d.ts.map +1 -0
- package/dist/db/shared/query-helpers.js +180 -0
- package/dist/db/shared/query-helpers.js.map +1 -0
- package/dist/db/sqlite-store.d.ts +48 -55
- package/dist/db/sqlite-store.d.ts.map +1 -1
- package/dist/db/sqlite-store.js +78 -945
- package/dist/db/sqlite-store.js.map +1 -1
- package/dist/db/tenant-scoped-store.d.ts +18 -1
- package/dist/db/tenant-scoped-store.d.ts.map +1 -1
- package/dist/db/tenant-scoped-store.js +6 -0
- package/dist/db/tenant-scoped-store.js.map +1 -1
- package/dist/index.d.ts +28 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +432 -97
- package/dist/index.js.map +1 -1
- package/dist/lib/alert-engine.d.ts +10 -0
- package/dist/lib/alert-engine.d.ts.map +1 -1
- package/dist/lib/alert-engine.js +73 -20
- package/dist/lib/alert-engine.js.map +1 -1
- package/dist/lib/audit-verify.d.ts +40 -0
- package/dist/lib/audit-verify.d.ts.map +1 -0
- package/dist/lib/audit-verify.js +128 -0
- package/dist/lib/audit-verify.js.map +1 -0
- package/dist/lib/audit.d.ts +37 -0
- package/dist/lib/audit.d.ts.map +1 -0
- package/dist/lib/audit.js +59 -0
- package/dist/lib/audit.js.map +1 -0
- package/dist/lib/budget-engine.d.ts +26 -0
- package/dist/lib/budget-engine.d.ts.map +1 -0
- package/dist/lib/budget-engine.js +201 -0
- package/dist/lib/budget-engine.js.map +1 -0
- package/dist/lib/compliance-export.d.ts +41 -0
- package/dist/lib/compliance-export.d.ts.map +1 -0
- package/dist/lib/compliance-export.js +124 -0
- package/dist/lib/compliance-export.js.map +1 -0
- package/dist/lib/compliance-report.d.ts +87 -0
- package/dist/lib/compliance-report.d.ts.map +1 -0
- package/dist/lib/compliance-report.js +148 -0
- package/dist/lib/compliance-report.js.map +1 -0
- package/dist/lib/context/retrieval.d.ts +5 -3
- package/dist/lib/context/retrieval.d.ts.map +1 -1
- package/dist/lib/context/retrieval.js +5 -2
- package/dist/lib/context/retrieval.js.map +1 -1
- package/dist/lib/cost-anomaly-detector.d.ts +23 -0
- package/dist/lib/cost-anomaly-detector.d.ts.map +1 -0
- package/dist/lib/cost-anomaly-detector.js +108 -0
- package/dist/lib/cost-anomaly-detector.js.map +1 -0
- package/dist/lib/db-resilience.d.ts +15 -0
- package/dist/lib/db-resilience.d.ts.map +1 -0
- package/dist/lib/db-resilience.js +49 -0
- package/dist/lib/db-resilience.js.map +1 -0
- package/dist/lib/diagnostics/cache.d.ts +29 -0
- package/dist/lib/diagnostics/cache.d.ts.map +1 -0
- package/dist/lib/diagnostics/cache.js +88 -0
- package/dist/lib/diagnostics/cache.js.map +1 -0
- package/dist/lib/diagnostics/context-builder.d.ts +41 -0
- package/dist/lib/diagnostics/context-builder.d.ts.map +1 -0
- package/dist/lib/diagnostics/context-builder.js +135 -0
- package/dist/lib/diagnostics/context-builder.js.map +1 -0
- package/dist/lib/diagnostics/index.d.ts +34 -0
- package/dist/lib/diagnostics/index.d.ts.map +1 -0
- package/dist/lib/diagnostics/index.js +223 -0
- package/dist/lib/diagnostics/index.js.map +1 -0
- package/dist/lib/diagnostics/llm-client.d.ts +24 -0
- package/dist/lib/diagnostics/llm-client.d.ts.map +1 -0
- package/dist/lib/diagnostics/llm-client.js +42 -0
- package/dist/lib/diagnostics/llm-client.js.map +1 -0
- package/dist/lib/diagnostics/prompt-templates.d.ts +18 -0
- package/dist/lib/diagnostics/prompt-templates.d.ts.map +1 -0
- package/dist/lib/diagnostics/prompt-templates.js +144 -0
- package/dist/lib/diagnostics/prompt-templates.js.map +1 -0
- package/dist/lib/diagnostics/providers/anthropic.d.ts +8 -0
- package/dist/lib/diagnostics/providers/anthropic.d.ts.map +1 -0
- package/dist/lib/diagnostics/providers/anthropic.js +79 -0
- package/dist/lib/diagnostics/providers/anthropic.js.map +1 -0
- package/dist/lib/diagnostics/providers/openai.d.ts +8 -0
- package/dist/lib/diagnostics/providers/openai.d.ts.map +1 -0
- package/dist/lib/diagnostics/providers/openai.js +70 -0
- package/dist/lib/diagnostics/providers/openai.js.map +1 -0
- package/dist/lib/diagnostics/providers/types.d.ts +23 -0
- package/dist/lib/diagnostics/providers/types.d.ts.map +1 -0
- package/dist/lib/diagnostics/providers/types.js +5 -0
- package/dist/lib/diagnostics/providers/types.js.map +1 -0
- package/dist/lib/diagnostics/response-parser.d.ts +60 -0
- package/dist/lib/diagnostics/response-parser.d.ts.map +1 -0
- package/dist/lib/diagnostics/response-parser.js +55 -0
- package/dist/lib/diagnostics/response-parser.js.map +1 -0
- package/dist/lib/diagnostics/types.d.ts +60 -0
- package/dist/lib/diagnostics/types.d.ts.map +1 -0
- package/dist/lib/diagnostics/types.js +7 -0
- package/dist/lib/diagnostics/types.js.map +1 -0
- package/dist/lib/embeddings/index.d.ts +6 -3
- package/dist/lib/embeddings/index.d.ts.map +1 -1
- package/dist/lib/embeddings/index.js +7 -15
- package/dist/lib/embeddings/index.js.map +1 -1
- package/dist/lib/embeddings/worker.d.ts +2 -2
- package/dist/lib/embeddings/worker.d.ts.map +1 -1
- package/dist/lib/embeddings/worker.js +3 -1
- package/dist/lib/embeddings/worker.js.map +1 -1
- package/dist/lib/error-sanitizer.d.ts +28 -0
- package/dist/lib/error-sanitizer.d.ts.map +1 -0
- package/dist/lib/error-sanitizer.js +106 -0
- package/dist/lib/error-sanitizer.js.map +1 -0
- package/dist/lib/eval/index.d.ts +15 -0
- package/dist/lib/eval/index.d.ts.map +1 -0
- package/dist/lib/eval/index.js +24 -0
- package/dist/lib/eval/index.js.map +1 -0
- package/dist/lib/eval/runner.d.ts +28 -0
- package/dist/lib/eval/runner.d.ts.map +1 -0
- package/dist/lib/eval/runner.js +260 -0
- package/dist/lib/eval/runner.js.map +1 -0
- package/dist/lib/eval/scorers/contains.d.ts +10 -0
- package/dist/lib/eval/scorers/contains.d.ts.map +1 -0
- package/dist/lib/eval/scorers/contains.js +33 -0
- package/dist/lib/eval/scorers/contains.js.map +1 -0
- package/dist/lib/eval/scorers/exact-match.d.ts +10 -0
- package/dist/lib/eval/scorers/exact-match.d.ts.map +1 -0
- package/dist/lib/eval/scorers/exact-match.js +33 -0
- package/dist/lib/eval/scorers/exact-match.js.map +1 -0
- package/dist/lib/eval/scorers/index.d.ts +20 -0
- package/dist/lib/eval/scorers/index.d.ts.map +1 -0
- package/dist/lib/eval/scorers/index.js +19 -0
- package/dist/lib/eval/scorers/index.js.map +1 -0
- package/dist/lib/eval/scorers/llm-judge.d.ts +22 -0
- package/dist/lib/eval/scorers/llm-judge.d.ts.map +1 -0
- package/dist/lib/eval/scorers/llm-judge.js +79 -0
- package/dist/lib/eval/scorers/llm-judge.js.map +1 -0
- package/dist/lib/eval/scorers/regex.d.ts +10 -0
- package/dist/lib/eval/scorers/regex.d.ts.map +1 -0
- package/dist/lib/eval/scorers/regex.js +36 -0
- package/dist/lib/eval/scorers/regex.js.map +1 -0
- package/dist/lib/guardrails/actions.d.ts +6 -0
- package/dist/lib/guardrails/actions.d.ts.map +1 -1
- package/dist/lib/guardrails/actions.js +82 -0
- package/dist/lib/guardrails/actions.js.map +1 -1
- package/dist/lib/guardrails/conditions.d.ts +47 -0
- package/dist/lib/guardrails/conditions.d.ts.map +1 -1
- package/dist/lib/guardrails/conditions.js +55 -10
- package/dist/lib/guardrails/conditions.js.map +1 -1
- package/dist/lib/guardrails/content-engine.d.ts +19 -0
- package/dist/lib/guardrails/content-engine.d.ts.map +1 -0
- package/dist/lib/guardrails/content-engine.js +154 -0
- package/dist/lib/guardrails/content-engine.js.map +1 -0
- package/dist/lib/guardrails/engine.d.ts +33 -0
- package/dist/lib/guardrails/engine.d.ts.map +1 -1
- package/dist/lib/guardrails/engine.js +37 -2
- package/dist/lib/guardrails/engine.js.map +1 -1
- package/dist/lib/guardrails/scanners/base-scanner.d.ts +23 -0
- package/dist/lib/guardrails/scanners/base-scanner.d.ts.map +1 -0
- package/dist/lib/guardrails/scanners/base-scanner.js +7 -0
- package/dist/lib/guardrails/scanners/base-scanner.js.map +1 -0
- package/dist/lib/guardrails/scanners/patterns/pii-patterns.d.ts +13 -0
- package/dist/lib/guardrails/scanners/patterns/pii-patterns.d.ts.map +1 -0
- package/dist/lib/guardrails/scanners/patterns/pii-patterns.js +49 -0
- package/dist/lib/guardrails/scanners/patterns/pii-patterns.js.map +1 -0
- package/dist/lib/guardrails/scanners/patterns/secret-patterns.d.ts +6 -0
- package/dist/lib/guardrails/scanners/patterns/secret-patterns.d.ts.map +1 -0
- package/dist/lib/guardrails/scanners/patterns/secret-patterns.js +69 -0
- package/dist/lib/guardrails/scanners/patterns/secret-patterns.js.map +1 -0
- package/dist/lib/guardrails/scanners/pii-scanner.d.ts +10 -0
- package/dist/lib/guardrails/scanners/pii-scanner.d.ts.map +1 -0
- package/dist/lib/guardrails/scanners/pii-scanner.js +57 -0
- package/dist/lib/guardrails/scanners/pii-scanner.js.map +1 -0
- package/dist/lib/guardrails/scanners/scanner-registry.d.ts +14 -0
- package/dist/lib/guardrails/scanners/scanner-registry.d.ts.map +1 -0
- package/dist/lib/guardrails/scanners/scanner-registry.js +51 -0
- package/dist/lib/guardrails/scanners/scanner-registry.js.map +1 -0
- package/dist/lib/guardrails/scanners/secrets-scanner.d.ts +9 -0
- package/dist/lib/guardrails/scanners/secrets-scanner.d.ts.map +1 -0
- package/dist/lib/guardrails/scanners/secrets-scanner.js +47 -0
- package/dist/lib/guardrails/scanners/secrets-scanner.js.map +1 -0
- package/dist/lib/logger.d.ts +8 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +31 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/lore-client.d.ts +128 -0
- package/dist/lib/lore-client.d.ts.map +1 -0
- package/dist/lib/lore-client.js +188 -0
- package/dist/lib/lore-client.js.map +1 -0
- package/dist/lib/mesh-client.d.ts +31 -0
- package/dist/lib/mesh-client.d.ts.map +1 -0
- package/dist/lib/mesh-client.js +72 -0
- package/dist/lib/mesh-client.js.map +1 -0
- package/dist/lib/notifications/grouping-buffer.d.ts +25 -0
- package/dist/lib/notifications/grouping-buffer.d.ts.map +1 -0
- package/dist/lib/notifications/grouping-buffer.js +73 -0
- package/dist/lib/notifications/grouping-buffer.js.map +1 -0
- package/dist/lib/notifications/provider.d.ts +10 -0
- package/dist/lib/notifications/provider.d.ts.map +1 -0
- package/dist/lib/notifications/provider.js +5 -0
- package/dist/lib/notifications/provider.js.map +1 -0
- package/dist/lib/notifications/providers/email.d.ts +14 -0
- package/dist/lib/notifications/providers/email.d.ts.map +1 -0
- package/dist/lib/notifications/providers/email.js +88 -0
- package/dist/lib/notifications/providers/email.js.map +1 -0
- package/dist/lib/notifications/providers/pagerduty.d.ts +16 -0
- package/dist/lib/notifications/providers/pagerduty.d.ts.map +1 -0
- package/dist/lib/notifications/providers/pagerduty.js +94 -0
- package/dist/lib/notifications/providers/pagerduty.js.map +1 -0
- package/dist/lib/notifications/providers/slack.d.ts +14 -0
- package/dist/lib/notifications/providers/slack.d.ts.map +1 -0
- package/dist/lib/notifications/providers/slack.js +106 -0
- package/dist/lib/notifications/providers/slack.js.map +1 -0
- package/dist/lib/notifications/providers/webhook.d.ts +16 -0
- package/dist/lib/notifications/providers/webhook.d.ts.map +1 -0
- package/dist/lib/notifications/providers/webhook.js +78 -0
- package/dist/lib/notifications/providers/webhook.js.map +1 -0
- package/dist/lib/notifications/router.d.ts +30 -0
- package/dist/lib/notifications/router.d.ts.map +1 -0
- package/dist/lib/notifications/router.js +137 -0
- package/dist/lib/notifications/router.js.map +1 -0
- package/dist/lib/notifications/ssrf.d.ts +13 -0
- package/dist/lib/notifications/ssrf.d.ts.map +1 -0
- package/dist/lib/notifications/ssrf.js +37 -0
- package/dist/lib/notifications/ssrf.js.map +1 -0
- package/dist/lib/optimization/analyzers/model-downgrade.d.ts +15 -0
- package/dist/lib/optimization/analyzers/model-downgrade.d.ts.map +1 -0
- package/dist/lib/optimization/analyzers/model-downgrade.js +58 -0
- package/dist/lib/optimization/analyzers/model-downgrade.js.map +1 -0
- package/dist/lib/optimization/analyzers/prompt-optimization.d.ts +17 -0
- package/dist/lib/optimization/analyzers/prompt-optimization.d.ts.map +1 -0
- package/dist/lib/optimization/analyzers/prompt-optimization.js +160 -0
- package/dist/lib/optimization/analyzers/prompt-optimization.js.map +1 -0
- package/dist/lib/optimization/analyzers/types.d.ts +23 -0
- package/dist/lib/optimization/analyzers/types.d.ts.map +1 -0
- package/dist/lib/optimization/analyzers/types.js +5 -0
- package/dist/lib/optimization/analyzers/types.js.map +1 -0
- package/dist/lib/optimization/classifier.d.ts +4 -3
- package/dist/lib/optimization/classifier.d.ts.map +1 -1
- package/dist/lib/optimization/classifier.js +15 -9
- package/dist/lib/optimization/classifier.js.map +1 -1
- package/dist/lib/optimization/cost-optimizer.d.ts +21 -0
- package/dist/lib/optimization/cost-optimizer.d.ts.map +1 -0
- package/dist/lib/optimization/cost-optimizer.js +114 -0
- package/dist/lib/optimization/cost-optimizer.js.map +1 -0
- package/dist/lib/optimization/engine.d.ts.map +1 -1
- package/dist/lib/optimization/engine.js +45 -6
- package/dist/lib/optimization/engine.js.map +1 -1
- package/dist/lib/optimization/forecast.d.ts +39 -0
- package/dist/lib/optimization/forecast.d.ts.map +1 -0
- package/dist/lib/optimization/forecast.js +128 -0
- package/dist/lib/optimization/forecast.js.map +1 -0
- package/dist/lib/secrets.d.ts +30 -0
- package/dist/lib/secrets.d.ts.map +1 -0
- package/dist/lib/secrets.js +103 -0
- package/dist/lib/secrets.js.map +1 -0
- package/dist/lib/threshold-monitor.d.ts +53 -0
- package/dist/lib/threshold-monitor.d.ts.map +1 -0
- package/dist/lib/threshold-monitor.js +112 -0
- package/dist/lib/threshold-monitor.js.map +1 -0
- package/dist/middleware/audit.d.ts +16 -0
- package/dist/middleware/audit.d.ts.map +1 -0
- package/dist/middleware/audit.js +16 -0
- package/dist/middleware/audit.js.map +1 -0
- package/dist/middleware/auth-errors.d.ts +67 -0
- package/dist/middleware/auth-errors.d.ts.map +1 -0
- package/dist/middleware/auth-errors.js +84 -0
- package/dist/middleware/auth-errors.js.map +1 -0
- package/dist/middleware/auth.d.ts +5 -2
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +44 -17
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/body-limit.d.ts +9 -0
- package/dist/middleware/body-limit.d.ts.map +1 -0
- package/dist/middleware/body-limit.js +15 -0
- package/dist/middleware/body-limit.js.map +1 -0
- package/dist/middleware/cors-config.d.ts +30 -0
- package/dist/middleware/cors-config.d.ts.map +1 -0
- package/dist/middleware/cors-config.js +55 -0
- package/dist/middleware/cors-config.js.map +1 -0
- package/dist/middleware/rate-limit.d.ts +9 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/middleware/rate-limit.js +56 -0
- package/dist/middleware/rate-limit.js.map +1 -0
- package/dist/middleware/rbac.d.ts +30 -0
- package/dist/middleware/rbac.d.ts.map +1 -0
- package/dist/middleware/rbac.js +87 -0
- package/dist/middleware/rbac.js.map +1 -0
- package/dist/middleware/security-headers.d.ts +12 -0
- package/dist/middleware/security-headers.d.ts.map +1 -0
- package/dist/middleware/security-headers.js +57 -0
- package/dist/middleware/security-headers.js.map +1 -0
- package/dist/middleware/unified-auth.d.ts +49 -0
- package/dist/middleware/unified-auth.d.ts.map +1 -0
- package/dist/middleware/unified-auth.js +246 -0
- package/dist/middleware/unified-auth.js.map +1 -0
- package/dist/middleware/validation.d.ts +31 -0
- package/dist/middleware/validation.d.ts.map +1 -0
- package/dist/middleware/validation.js +45 -0
- package/dist/middleware/validation.js.map +1 -0
- package/dist/routes/alerts.d.ts.map +1 -1
- package/dist/routes/alerts.js +4 -3
- package/dist/routes/alerts.js.map +1 -1
- package/dist/routes/analytics.d.ts +2 -1
- package/dist/routes/analytics.d.ts.map +1 -1
- package/dist/routes/analytics.js +175 -95
- package/dist/routes/analytics.js.map +1 -1
- package/dist/routes/api-keys.d.ts +5 -0
- package/dist/routes/api-keys.d.ts.map +1 -1
- package/dist/routes/api-keys.js +89 -8
- package/dist/routes/api-keys.js.map +1 -1
- package/dist/routes/audit-verify.d.ts +12 -0
- package/dist/routes/audit-verify.d.ts.map +1 -0
- package/dist/routes/audit-verify.js +73 -0
- package/dist/routes/audit-verify.js.map +1 -0
- package/dist/routes/audit.d.ts +4 -6
- package/dist/routes/audit.d.ts.map +1 -1
- package/dist/routes/audit.js +54 -157
- package/dist/routes/audit.js.map +1 -1
- package/dist/routes/auth.d.ts +21 -0
- package/dist/routes/auth.d.ts.map +1 -0
- package/dist/routes/auth.js +235 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/benchmarks.d.ts.map +1 -1
- package/dist/routes/benchmarks.js +63 -11
- package/dist/routes/benchmarks.js.map +1 -1
- package/dist/routes/capabilities-top.d.ts.map +1 -1
- package/dist/routes/capabilities-top.js +1 -4
- package/dist/routes/capabilities-top.js.map +1 -1
- package/dist/routes/capabilities.d.ts.map +1 -1
- package/dist/routes/capabilities.js +1 -7
- package/dist/routes/capabilities.js.map +1 -1
- package/dist/routes/compliance.d.ts +17 -0
- package/dist/routes/compliance.d.ts.map +1 -0
- package/dist/routes/compliance.js +151 -0
- package/dist/routes/compliance.js.map +1 -0
- package/dist/routes/config.d.ts +1 -13
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/context.d.ts.map +1 -1
- package/dist/routes/context.js +6 -5
- package/dist/routes/context.js.map +1 -1
- package/dist/routes/cost-budgets.d.ts +20 -0
- package/dist/routes/cost-budgets.d.ts.map +1 -0
- package/dist/routes/cost-budgets.js +194 -0
- package/dist/routes/cost-budgets.js.map +1 -0
- package/dist/routes/delegation.d.ts.map +1 -1
- package/dist/routes/delegation.js +67 -41
- package/dist/routes/delegation.js.map +1 -1
- package/dist/routes/delegations-top.d.ts.map +1 -1
- package/dist/routes/delegations-top.js +1 -3
- package/dist/routes/delegations-top.js.map +1 -1
- package/dist/routes/diagnose.d.ts +16 -0
- package/dist/routes/diagnose.d.ts.map +1 -0
- package/dist/routes/diagnose.js +82 -0
- package/dist/routes/diagnose.js.map +1 -0
- package/dist/routes/discovery.d.ts.map +1 -1
- package/dist/routes/discovery.js +50 -38
- package/dist/routes/discovery.js.map +1 -1
- package/dist/routes/eval.d.ts +24 -0
- package/dist/routes/eval.d.ts.map +1 -0
- package/dist/routes/eval.js +281 -0
- package/dist/routes/eval.js.map +1 -0
- package/dist/routes/events.d.ts.map +1 -1
- package/dist/routes/events.js +11 -6
- package/dist/routes/events.js.map +1 -1
- package/dist/routes/guardrails.d.ts +2 -1
- package/dist/routes/guardrails.d.ts.map +1 -1
- package/dist/routes/guardrails.js +85 -14
- package/dist/routes/guardrails.js.map +1 -1
- package/dist/routes/health.d.ts +14 -11
- package/dist/routes/health.d.ts.map +1 -1
- package/dist/routes/health.js +181 -61
- package/dist/routes/health.js.map +1 -1
- package/dist/routes/lore-proxy.d.ts +13 -0
- package/dist/routes/lore-proxy.d.ts.map +1 -0
- package/dist/routes/lore-proxy.js +229 -0
- package/dist/routes/lore-proxy.js.map +1 -0
- package/dist/routes/mesh-proxy.d.ts +7 -0
- package/dist/routes/mesh-proxy.d.ts.map +1 -0
- package/dist/routes/mesh-proxy.js +94 -0
- package/dist/routes/mesh-proxy.js.map +1 -0
- package/dist/routes/notifications.d.ts +19 -0
- package/dist/routes/notifications.d.ts.map +1 -0
- package/dist/routes/notifications.js +129 -0
- package/dist/routes/notifications.js.map +1 -0
- package/dist/routes/optimize.d.ts.map +1 -1
- package/dist/routes/optimize.js +44 -0
- package/dist/routes/optimize.js.map +1 -1
- package/dist/routes/otlp.d.ts +17 -0
- package/dist/routes/otlp.d.ts.map +1 -0
- package/dist/routes/otlp.js +544 -0
- package/dist/routes/otlp.js.map +1 -0
- package/dist/routes/prompts.d.ts +21 -0
- package/dist/routes/prompts.d.ts.map +1 -0
- package/dist/routes/prompts.js +173 -0
- package/dist/routes/prompts.js.map +1 -0
- package/dist/routes/recall.d.ts.map +1 -1
- package/dist/routes/recall.js +6 -4
- package/dist/routes/recall.js.map +1 -1
- package/dist/routes/replay.d.ts.map +1 -1
- package/dist/routes/replay.js +2 -1
- package/dist/routes/replay.js.map +1 -1
- package/dist/routes/server-info.d.ts +9 -0
- package/dist/routes/server-info.d.ts.map +1 -0
- package/dist/routes/server-info.js +18 -0
- package/dist/routes/server-info.js.map +1 -0
- package/dist/routes/sessions.d.ts +7 -7
- package/dist/routes/sessions.d.ts.map +1 -1
- package/dist/routes/sessions.js +112 -35
- package/dist/routes/sessions.js.map +1 -1
- package/dist/routes/stats.d.ts.map +1 -1
- package/dist/routes/stats.js +40 -0
- package/dist/routes/stats.js.map +1 -1
- package/dist/routes/stream.d.ts +2 -2
- package/dist/routes/stream.d.ts.map +1 -1
- package/dist/routes/stream.js +7 -11
- package/dist/routes/stream.js.map +1 -1
- package/dist/routes/tenant-helper.d.ts +15 -10
- package/dist/routes/tenant-helper.d.ts.map +1 -1
- package/dist/routes/tenant-helper.js +36 -22
- package/dist/routes/tenant-helper.js.map +1 -1
- package/dist/routes/trust.d.ts.map +1 -1
- package/dist/routes/trust.js +1 -3
- package/dist/routes/trust.js.map +1 -1
- package/dist/schemas/api-keys.d.ts +11 -0
- package/dist/schemas/api-keys.d.ts.map +1 -0
- package/dist/schemas/api-keys.js +10 -0
- package/dist/schemas/api-keys.js.map +1 -0
- package/dist/schemas/common.d.ts +34 -0
- package/dist/schemas/common.d.ts.map +1 -0
- package/dist/schemas/common.js +43 -0
- package/dist/schemas/common.js.map +1 -0
- package/dist/schemas/delegation.d.ts +23 -0
- package/dist/schemas/delegation.d.ts.map +1 -0
- package/dist/schemas/delegation.js +22 -0
- package/dist/schemas/delegation.js.map +1 -0
- package/dist/schemas/discovery.d.ts +17 -0
- package/dist/schemas/discovery.d.ts.map +1 -0
- package/dist/schemas/discovery.js +15 -0
- package/dist/schemas/discovery.js.map +1 -0
- package/dist/schemas/health.d.ts +75 -0
- package/dist/schemas/health.d.ts.map +1 -0
- package/dist/schemas/health.js +55 -0
- package/dist/schemas/health.js.map +1 -0
- package/dist/schemas/index.d.ts +6 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +6 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/sessions.d.ts +67 -0
- package/dist/schemas/sessions.d.ts.map +1 -0
- package/dist/schemas/sessions.js +58 -0
- package/dist/schemas/sessions.js.map +1 -0
- package/dist/services/delegation-service.d.ts +1 -4
- package/dist/services/delegation-service.d.ts.map +1 -1
- package/dist/services/delegation-service.js +5 -31
- package/dist/services/delegation-service.js.map +1 -1
- package/package.json +29 -19
- package/dist/db/lesson-store.d.ts +0 -57
- package/dist/db/lesson-store.d.ts.map +0 -1
- package/dist/db/lesson-store.js +0 -217
- package/dist/db/lesson-store.js.map +0 -1
- package/dist/lib/embeddings/local.d.ts +0 -15
- package/dist/lib/embeddings/local.d.ts.map +0 -1
- package/dist/lib/embeddings/local.js +0 -65
- package/dist/lib/embeddings/local.js.map +0 -1
- package/dist/lib/redaction/human-review-layer.d.ts +0 -37
- package/dist/lib/redaction/human-review-layer.d.ts.map +0 -1
- package/dist/lib/redaction/human-review-layer.js +0 -62
- package/dist/lib/redaction/human-review-layer.js.map +0 -1
- package/dist/lib/redaction/index.d.ts +0 -12
- package/dist/lib/redaction/index.d.ts.map +0 -1
- package/dist/lib/redaction/index.js +0 -12
- package/dist/lib/redaction/index.js.map +0 -1
- package/dist/lib/redaction/pii-detection-layer.d.ts +0 -30
- package/dist/lib/redaction/pii-detection-layer.d.ts.map +0 -1
- package/dist/lib/redaction/pii-detection-layer.js +0 -183
- package/dist/lib/redaction/pii-detection-layer.js.map +0 -1
- package/dist/lib/redaction/pipeline.d.ts +0 -26
- package/dist/lib/redaction/pipeline.d.ts.map +0 -1
- package/dist/lib/redaction/pipeline.js +0 -91
- package/dist/lib/redaction/pipeline.js.map +0 -1
- package/dist/lib/redaction/secret-detection-layer.d.ts +0 -10
- package/dist/lib/redaction/secret-detection-layer.d.ts.map +0 -1
- package/dist/lib/redaction/secret-detection-layer.js +0 -79
- package/dist/lib/redaction/secret-detection-layer.js.map +0 -1
- package/dist/lib/redaction/secret-patterns.d.ts +0 -29
- package/dist/lib/redaction/secret-patterns.d.ts.map +0 -1
- package/dist/lib/redaction/secret-patterns.js +0 -133
- package/dist/lib/redaction/secret-patterns.js.map +0 -1
- package/dist/lib/redaction/semantic-denylist-layer.d.ts +0 -10
- package/dist/lib/redaction/semantic-denylist-layer.d.ts.map +0 -1
- package/dist/lib/redaction/semantic-denylist-layer.js +0 -64
- package/dist/lib/redaction/semantic-denylist-layer.js.map +0 -1
- package/dist/lib/redaction/tenant-deidentification-layer.d.ts +0 -10
- package/dist/lib/redaction/tenant-deidentification-layer.d.ts.map +0 -1
- package/dist/lib/redaction/tenant-deidentification-layer.js +0 -64
- package/dist/lib/redaction/tenant-deidentification-layer.js.map +0 -1
- package/dist/lib/redaction/url-path-scrubbing-layer.d.ts +0 -14
- package/dist/lib/redaction/url-path-scrubbing-layer.d.ts.map +0 -1
- package/dist/lib/redaction/url-path-scrubbing-layer.js +0 -156
- package/dist/lib/redaction/url-path-scrubbing-layer.js.map +0 -1
- package/dist/routes/community.d.ts +0 -24
- package/dist/routes/community.d.ts.map +0 -1
- package/dist/routes/community.js +0 -272
- package/dist/routes/community.js.map +0 -1
- package/dist/routes/lessons.d.ts +0 -19
- package/dist/routes/lessons.d.ts.map +0 -1
- package/dist/routes/lessons.js +0 -164
- package/dist/routes/lessons.js.map +0 -1
- package/dist/routes/redaction-test.d.ts +0 -14
- package/dist/routes/redaction-test.d.ts.map +0 -1
- package/dist/routes/redaction-test.js +0 -33
- package/dist/routes/redaction-test.js.map +0 -1
- package/dist/services/community-service.d.ts +0 -283
- package/dist/services/community-service.d.ts.map +0 -1
- package/dist/services/community-service.js +0 -816
- package/dist/services/community-service.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* - startServer() — standalone entry point that creates DB + starts listening
|
|
7
7
|
*/
|
|
8
8
|
import { Hono } from 'hono';
|
|
9
|
+
import { OpenAPIHono } from '@hono/zod-openapi';
|
|
10
|
+
import { apiReference } from '@scalar/hono-api-reference';
|
|
9
11
|
import { cors } from 'hono/cors';
|
|
10
12
|
import { logger } from 'hono/logger';
|
|
11
13
|
import { serve } from '@hono/node-server';
|
|
@@ -13,8 +15,15 @@ import { serveStatic } from '@hono/node-server/serve-static';
|
|
|
13
15
|
import { readFileSync, existsSync } from 'node:fs';
|
|
14
16
|
import { resolve, dirname } from 'node:path';
|
|
15
17
|
import { fileURLToPath } from 'node:url';
|
|
16
|
-
import {
|
|
18
|
+
import { BearerAuthScheme } from './schemas/common.js';
|
|
19
|
+
import { getConfig, validateConfig } from './config.js';
|
|
17
20
|
import { authMiddleware } from './middleware/auth.js';
|
|
21
|
+
import { unifiedAuthMiddleware } from './middleware/unified-auth.js';
|
|
22
|
+
import { requireCategory, requireMethodCategory, requireCategoryByMethod } from './middleware/rbac.js';
|
|
23
|
+
import { otlpAuthRequired as otlpAuthRequiredError, otlpInvalidToken } from './middleware/auth-errors.js';
|
|
24
|
+
import { securityHeadersMiddleware } from './middleware/security-headers.js';
|
|
25
|
+
import { sanitizeErrorMessage, getErrorStatus } from './lib/error-sanitizer.js';
|
|
26
|
+
import { buildCorsOptions } from './middleware/cors-config.js';
|
|
18
27
|
import { apiKeysRoutes } from './routes/api-keys.js';
|
|
19
28
|
import { eventsRoutes } from './routes/events.js';
|
|
20
29
|
import { sessionsRoutes } from './routes/sessions.js';
|
|
@@ -22,18 +31,23 @@ import { agentsRoutes } from './routes/agents.js';
|
|
|
22
31
|
import { statsRoutes } from './routes/stats.js';
|
|
23
32
|
import { configRoutes } from './routes/config.js';
|
|
24
33
|
import { alertsRoutes } from './routes/alerts.js';
|
|
34
|
+
import { notificationRoutes } from './routes/notifications.js';
|
|
35
|
+
import { NotificationChannelRepository } from './db/repositories/notification-channel-repository.js';
|
|
36
|
+
import { NotificationRouter } from './lib/notifications/router.js';
|
|
25
37
|
import { ingestRoutes } from './routes/ingest.js';
|
|
26
38
|
import { analyticsRoutes } from './routes/analytics.js';
|
|
27
39
|
import { streamRoutes } from './routes/stream.js';
|
|
28
|
-
import { lessonsRoutes } from './routes/lessons.js';
|
|
29
40
|
import { reflectRoutes } from './routes/reflect.js';
|
|
30
41
|
import { recallRoutes } from './routes/recall.js';
|
|
31
42
|
import { contextRoutes } from './routes/context.js';
|
|
32
43
|
import { optimizeRoutes } from './routes/optimize.js';
|
|
33
|
-
import {
|
|
44
|
+
import { healthRoutes } from './routes/health.js';
|
|
45
|
+
import { diagnoseRoutes } from './routes/diagnose.js';
|
|
34
46
|
import { registerReplayRoutes } from './routes/replay.js';
|
|
35
47
|
import { benchmarkRoutes } from './routes/benchmarks.js';
|
|
48
|
+
import { promptRoutes } from './routes/prompts.js';
|
|
36
49
|
import { guardrailRoutes } from './routes/guardrails.js';
|
|
50
|
+
import { evalRoutes } from './routes/eval.js';
|
|
37
51
|
import { capabilityRoutes } from './routes/capabilities.js';
|
|
38
52
|
import { capabilityTopRoutes } from './routes/capabilities-top.js';
|
|
39
53
|
import { discoveryRoutes } from './routes/discovery.js';
|
|
@@ -41,12 +55,27 @@ import { delegationRoutes } from './routes/delegation.js';
|
|
|
41
55
|
import { delegationTopRoutes } from './routes/delegations-top.js';
|
|
42
56
|
import { trustRoutes } from './routes/trust.js';
|
|
43
57
|
import { LocalPoolTransport } from './services/delegation-service.js';
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
58
|
+
import { loreProxyRoutes, loreCommunityProxyRoutes } from './routes/lore-proxy.js';
|
|
59
|
+
import { createLoreAdapter } from './lib/lore-client.js';
|
|
60
|
+
import { meshProxyRoutes } from './routes/mesh-proxy.js';
|
|
61
|
+
import { RemoteMeshAdapter } from './lib/mesh-client.js';
|
|
62
|
+
import { otlpRoutes } from './routes/otlp.js';
|
|
63
|
+
import { authRoutes } from './routes/auth.js';
|
|
64
|
+
import { authRateLimit, apiRateLimit } from './middleware/rate-limit.js';
|
|
65
|
+
import { apiBodyLimit } from './middleware/body-limit.js';
|
|
46
66
|
import { auditRoutes } from './routes/audit.js';
|
|
67
|
+
import { cloudOrgRoutes } from './cloud/routes/index.js';
|
|
68
|
+
import { auditVerifyRoutes } from './routes/audit-verify.js';
|
|
69
|
+
import { complianceRoutes } from './routes/compliance.js';
|
|
70
|
+
import { createAuditLogger, cleanupAuditLogs } from './lib/audit.js';
|
|
71
|
+
import { auditMiddleware } from './middleware/audit.js';
|
|
47
72
|
import { GuardrailEngine } from './lib/guardrails/engine.js';
|
|
48
73
|
import { GuardrailStore } from './db/guardrail-store.js';
|
|
49
|
-
import {
|
|
74
|
+
import { ContentGuardrailEngine } from './lib/guardrails/content-engine.js';
|
|
75
|
+
import { setAgentStore, setNotificationRouter } from './lib/guardrails/actions.js';
|
|
76
|
+
import { BudgetEngine } from './lib/budget-engine.js';
|
|
77
|
+
import { CostAnomalyDetector } from './lib/cost-anomaly-detector.js';
|
|
78
|
+
import { costBudgetRoutes } from './routes/cost-budgets.js';
|
|
50
79
|
import { createDb } from './db/index.js';
|
|
51
80
|
import { runMigrations } from './db/migrate.js';
|
|
52
81
|
import { SqliteEventStore } from './db/sqlite-store.js';
|
|
@@ -55,9 +84,12 @@ import { eventBus } from './lib/event-bus.js';
|
|
|
55
84
|
import { EmbeddingWorker } from './lib/embeddings/worker.js';
|
|
56
85
|
import { EmbeddingStore } from './db/embedding-store.js';
|
|
57
86
|
import { SessionSummaryStore } from './db/session-summary-store.js';
|
|
87
|
+
import { createLogger } from './lib/logger.js';
|
|
88
|
+
const log = createLogger('Server');
|
|
58
89
|
// Re-export everything consumers may need
|
|
59
|
-
export { getConfig } from './config.js';
|
|
90
|
+
export { getConfig, validateConfig } from './config.js';
|
|
60
91
|
export { authMiddleware, hashApiKey } from './middleware/auth.js';
|
|
92
|
+
export { buildCorsOptions } from './middleware/cors-config.js';
|
|
61
93
|
export { apiKeysRoutes } from './routes/api-keys.js';
|
|
62
94
|
export { eventsRoutes } from './routes/events.js';
|
|
63
95
|
export { sessionsRoutes } from './routes/sessions.js';
|
|
@@ -68,7 +100,6 @@ export { alertsRoutes } from './routes/alerts.js';
|
|
|
68
100
|
export { ingestRoutes, verifyWebhookSignature } from './routes/ingest.js';
|
|
69
101
|
export { analyticsRoutes } from './routes/analytics.js';
|
|
70
102
|
export { streamRoutes } from './routes/stream.js';
|
|
71
|
-
export { lessonsRoutes } from './routes/lessons.js';
|
|
72
103
|
export { reflectRoutes } from './routes/reflect.js';
|
|
73
104
|
export { recallRoutes } from './routes/recall.js';
|
|
74
105
|
export { optimizeRoutes } from './routes/optimize.js';
|
|
@@ -82,17 +113,27 @@ export { AlertEngine } from './lib/alert-engine.js';
|
|
|
82
113
|
export { eventBus } from './lib/event-bus.js';
|
|
83
114
|
export { createDb, createTestDb } from './db/index.js';
|
|
84
115
|
export { runMigrations } from './db/migrate.js';
|
|
85
|
-
export { LessonStore } from './db/lesson-store.js';
|
|
86
116
|
export { SessionSummaryStore } from './db/session-summary-store.js';
|
|
87
117
|
export { contextRoutes } from './routes/context.js';
|
|
88
|
-
export {
|
|
118
|
+
export { auditRoutes } from './routes/audit.js';
|
|
119
|
+
export { createAuditLogger, cleanupAuditLogs, maskSensitive } from './lib/audit.js';
|
|
120
|
+
export { validateBody, formatZodErrors } from './middleware/validation.js';
|
|
121
|
+
export { apiBodyLimit } from './middleware/body-limit.js';
|
|
122
|
+
export { auditMiddleware } from './middleware/audit.js';
|
|
123
|
+
export { healthRoutes, registerHealthRoutes } from './routes/health.js';
|
|
89
124
|
export { ContextRetriever } from './lib/context/retrieval.js';
|
|
90
|
-
export {
|
|
91
|
-
export {
|
|
125
|
+
export { loreProxyRoutes, loreCommunityProxyRoutes } from './routes/lore-proxy.js';
|
|
126
|
+
export { createLoreAdapter, RemoteLoreAdapter, LocalLoreAdapter, LoreError } from './lib/lore-client.js';
|
|
127
|
+
export { meshProxyRoutes } from './routes/mesh-proxy.js';
|
|
128
|
+
export { RemoteMeshAdapter, MeshError } from './lib/mesh-client.js';
|
|
129
|
+
export { otlpRoutes } from './routes/otlp.js';
|
|
92
130
|
export { guardrailRoutes } from './routes/guardrails.js';
|
|
93
131
|
export { GuardrailEngine } from './lib/guardrails/engine.js';
|
|
94
132
|
export { GuardrailStore } from './db/guardrail-store.js';
|
|
95
|
-
export {
|
|
133
|
+
export { BudgetEngine } from './lib/budget-engine.js';
|
|
134
|
+
export { CostAnomalyDetector } from './lib/cost-anomaly-detector.js';
|
|
135
|
+
export { CostBudgetStore } from './db/cost-budget-store.js';
|
|
136
|
+
export { costBudgetRoutes } from './routes/cost-budgets.js';
|
|
96
137
|
// ─── Dashboard SPA helpers ───────────────────────────────────
|
|
97
138
|
/**
|
|
98
139
|
* Resolve the dashboard dist/ directory path.
|
|
@@ -144,14 +185,34 @@ function getDashboardIndexHtml() {
|
|
|
144
185
|
* @param store - IEventStore implementation for data access
|
|
145
186
|
* @param config - Optional partial config override (defaults from env)
|
|
146
187
|
*/
|
|
147
|
-
export function createApp(store, config) {
|
|
188
|
+
export async function createApp(store, config) {
|
|
148
189
|
const resolvedConfig = { ...getConfig(), ...config };
|
|
149
|
-
const app = new
|
|
190
|
+
const app = new OpenAPIHono({
|
|
191
|
+
defaultHook: (result, c) => {
|
|
192
|
+
if (!result.success) {
|
|
193
|
+
return c.json({
|
|
194
|
+
error: 'Validation failed',
|
|
195
|
+
status: 400,
|
|
196
|
+
details: result.error.issues.map((i) => ({
|
|
197
|
+
path: i.path.map(String).join('.'),
|
|
198
|
+
message: i.message,
|
|
199
|
+
})),
|
|
200
|
+
}, 400);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
// Register Bearer auth security scheme for OpenAPI [F13-S1]
|
|
205
|
+
app.openAPIRegistry.registerComponent('securitySchemes', 'Bearer', BearerAuthScheme);
|
|
206
|
+
// ─── Security headers (position 1 — must be first) ────
|
|
207
|
+
app.use('*', securityHeadersMiddleware());
|
|
150
208
|
// ─── Global error handler ──────────────────────────────
|
|
151
209
|
app.onError((err, c) => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
210
|
+
const status = getErrorStatus(err);
|
|
211
|
+
if (status >= 500) {
|
|
212
|
+
log.error('Unhandled error', { error: err instanceof Error ? err.message : String(err) });
|
|
213
|
+
}
|
|
214
|
+
const message = sanitizeErrorMessage(err);
|
|
215
|
+
return c.json({ error: message, status }, status);
|
|
155
216
|
});
|
|
156
217
|
// ─── 404 handler — API routes return JSON, others get SPA fallback ──
|
|
157
218
|
app.notFound((c) => {
|
|
@@ -172,63 +233,120 @@ export function createApp(store, config) {
|
|
|
172
233
|
return c.json({ error: 'Not found', status: 404 }, 404);
|
|
173
234
|
});
|
|
174
235
|
// ─── Middleware on /api/* ──────────────────────────────
|
|
175
|
-
app.use('/api/*', cors({
|
|
236
|
+
app.use('/api/*', cors(buildCorsOptions({
|
|
237
|
+
corsOrigins: resolvedConfig.corsOrigins ?? resolvedConfig.corsOrigin,
|
|
238
|
+
nodeEnv: process.env['NODE_ENV'],
|
|
239
|
+
})));
|
|
176
240
|
app.use('/api/*', logger());
|
|
241
|
+
// ─── SH-3: Body size limit (1MB default) ────────────────
|
|
242
|
+
app.use('/api/*', apiBodyLimit);
|
|
243
|
+
// ─── Rate limiting: API endpoints ──────────────────────
|
|
244
|
+
app.use('/api/*', apiRateLimit);
|
|
177
245
|
// ─── Health check (no auth) ────────────────────────────
|
|
178
|
-
app.get('/api/health', (c) => {
|
|
179
|
-
|
|
246
|
+
app.get('/api/health', async (c) => {
|
|
247
|
+
const result = { status: 'ok', version: '0.1.0' };
|
|
248
|
+
// DB health check — works for both SQLite and Postgres
|
|
249
|
+
if (config?.pgSql) {
|
|
250
|
+
const { postgresHealthCheck } = await import('./db/index.js');
|
|
251
|
+
result.db = await postgresHealthCheck(config.pgSql);
|
|
252
|
+
}
|
|
253
|
+
else if (config?.db) {
|
|
254
|
+
// SQLite health check
|
|
255
|
+
const start = performance.now();
|
|
256
|
+
try {
|
|
257
|
+
config.db.run((await import('drizzle-orm')).sql `SELECT 1`);
|
|
258
|
+
result.db = { ok: true, latencyMs: Math.round(performance.now() - start) };
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
result.db = { ok: false, latencyMs: Math.round(performance.now() - start) };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return c.json(result);
|
|
265
|
+
});
|
|
266
|
+
// ─── Feature flags (no auth — dashboard needs before login) ──
|
|
267
|
+
app.get('/api/config/features', (c) => {
|
|
268
|
+
return c.json({ lore: resolvedConfig.loreEnabled, mesh: resolvedConfig.meshEnabled });
|
|
180
269
|
});
|
|
181
270
|
// ─── SSE stream (authenticates via Bearer header or ?token= query param) ──
|
|
182
271
|
// Mounted before auth middleware — handles its own auth internally for EventSource compat.
|
|
183
|
-
app.route('/api/stream', streamRoutes(config?.
|
|
272
|
+
app.route('/api/stream', streamRoutes(config?.apiKeyLookup, resolvedConfig.authDisabled));
|
|
184
273
|
// ─── Webhook ingest (no API key auth — uses HMAC signature verification) ──
|
|
185
274
|
app.route('/api/events/ingest', ingestRoutes(store, {
|
|
186
275
|
agentgateWebhookSecret: process.env['AGENTGATE_WEBHOOK_SECRET'],
|
|
187
276
|
formbridgeWebhookSecret: process.env['FORMBRIDGE_WEBHOOK_SECRET'],
|
|
188
277
|
}));
|
|
189
|
-
// ───
|
|
190
|
-
|
|
278
|
+
// ─── Rate limiting: auth endpoints ─────────────────────
|
|
279
|
+
app.use('/auth/*', authRateLimit);
|
|
280
|
+
// ─── OIDC Auth routes (no API key auth — handles own auth) ──
|
|
281
|
+
{
|
|
282
|
+
const authDb = config?.db;
|
|
283
|
+
if (authDb) {
|
|
284
|
+
const { loadOidcConfig } = await import('agentkit-auth');
|
|
285
|
+
const oidcConfig = loadOidcConfig();
|
|
286
|
+
if (oidcConfig) {
|
|
287
|
+
const jwtSecret = process.env['JWT_SECRET'];
|
|
288
|
+
if (!jwtSecret && process.env['NODE_ENV'] === 'production') {
|
|
289
|
+
throw new Error('JWT_SECRET must be set in production. Refusing to start with default secret.');
|
|
290
|
+
}
|
|
291
|
+
if (!jwtSecret) {
|
|
292
|
+
log.warn('JWT_SECRET not set — using insecure default. Do NOT use in production.');
|
|
293
|
+
}
|
|
294
|
+
app.route('/auth', authRoutes(authDb, {
|
|
295
|
+
oidcConfig,
|
|
296
|
+
authConfig: {
|
|
297
|
+
oidc: null,
|
|
298
|
+
jwt: {
|
|
299
|
+
secret: jwtSecret ?? 'dev-secret-change-me',
|
|
300
|
+
accessTokenTtlSeconds: Number(process.env['JWT_ACCESS_TTL'] ?? 900),
|
|
301
|
+
refreshTokenTtlSeconds: Number(process.env['JWT_REFRESH_TTL'] ?? 604800),
|
|
302
|
+
},
|
|
303
|
+
authDisabled: resolvedConfig.authDisabled,
|
|
304
|
+
},
|
|
305
|
+
}));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// ─── Fallback auth endpoints when auth is disabled ─────
|
|
310
|
+
if (resolvedConfig.authDisabled) {
|
|
311
|
+
app.get('/auth/me', (c) => c.json({ authMode: 'api-key-only' }, 200));
|
|
312
|
+
}
|
|
313
|
+
// ─── Auth middleware on protected routes [F2-S3] ───────
|
|
314
|
+
// Fail-closed: single catch-all for /api/* with public routes registered above.
|
|
191
315
|
const db = config?.db;
|
|
192
316
|
if (!db && !resolvedConfig.authDisabled) {
|
|
193
317
|
throw new Error('createApp() requires a `db` option when auth is enabled. ' +
|
|
194
318
|
'Either provide a database or set authDisabled: true.');
|
|
195
319
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
app.use('/api/
|
|
208
|
-
app.use('/api/
|
|
209
|
-
app.use('/api/
|
|
210
|
-
app.use('/api/
|
|
211
|
-
app.use('/api/
|
|
212
|
-
app.use('/api/
|
|
213
|
-
|
|
214
|
-
app.use('/api/
|
|
215
|
-
app.use('/api/
|
|
216
|
-
|
|
217
|
-
app.use('/api/
|
|
218
|
-
app.use('/api/
|
|
219
|
-
|
|
220
|
-
app.use('/api
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
app.use('/api/capabilities/*', authMiddleware(db, resolvedConfig.authDisabled));
|
|
227
|
-
app.use('/api/capabilities', authMiddleware(db, resolvedConfig.authDisabled));
|
|
228
|
-
app.use('/api/delegations/*', authMiddleware(db, resolvedConfig.authDisabled));
|
|
229
|
-
app.use('/api/delegations', authMiddleware(db, resolvedConfig.authDisabled));
|
|
230
|
-
app.use('/api/discovery/*', authMiddleware(db, resolvedConfig.authDisabled));
|
|
231
|
-
app.use('/api/discovery', authMiddleware(db, resolvedConfig.authDisabled));
|
|
320
|
+
{
|
|
321
|
+
const authLookup = config?.apiKeyLookup ?? db ?? null;
|
|
322
|
+
const authConfig = {
|
|
323
|
+
authDisabled: resolvedConfig.authDisabled,
|
|
324
|
+
jwtSecret: process.env['JWT_SECRET'],
|
|
325
|
+
};
|
|
326
|
+
// ── Unified auth catch-all (replaces 40+ individual app.use calls) ──
|
|
327
|
+
app.use('/api/*', unifiedAuthMiddleware(authLookup, authConfig));
|
|
328
|
+
// ── RBAC enforcement per architecture §3.3 ──────────
|
|
329
|
+
// Manage-level routes (owner, admin only)
|
|
330
|
+
const manageGuard = requireCategory('manage');
|
|
331
|
+
app.use('/api/keys/*', manageGuard);
|
|
332
|
+
app.use('/api/keys', manageGuard);
|
|
333
|
+
app.use('/api/audit/*', manageGuard);
|
|
334
|
+
app.use('/api/audit', manageGuard);
|
|
335
|
+
app.use('/api/compliance/*', manageGuard);
|
|
336
|
+
app.use('/api/compliance', manageGuard);
|
|
337
|
+
const configGuard = requireCategoryByMethod({ GET: 'read', PUT: 'manage', PATCH: 'manage' });
|
|
338
|
+
app.use('/api/config/*', configGuard);
|
|
339
|
+
app.use('/api/config', configGuard);
|
|
340
|
+
const guardrailGuard = requireCategoryByMethod({ GET: 'read', POST: 'manage', PUT: 'manage', DELETE: 'manage' });
|
|
341
|
+
app.use('/api/guardrails/*', guardrailGuard);
|
|
342
|
+
app.use('/api/guardrails', guardrailGuard);
|
|
343
|
+
// Default safety net: GET = read (all roles), mutations = write (member+)
|
|
344
|
+
app.use('/api/*', requireMethodCategory());
|
|
345
|
+
// ── Audit middleware (after auth — has access to auth context) ──
|
|
346
|
+
if (db) {
|
|
347
|
+
const auditLogger = createAuditLogger(db);
|
|
348
|
+
app.use('/api/*', auditMiddleware(auditLogger));
|
|
349
|
+
}
|
|
232
350
|
}
|
|
233
351
|
// ─── Routes ────────────────────────────────────────────
|
|
234
352
|
if (db) {
|
|
@@ -242,8 +360,8 @@ export function createApp(store, config) {
|
|
|
242
360
|
// (otherwise the sessions sub-app catches /api/sessions/* first)
|
|
243
361
|
registerReplayRoutes(app, store);
|
|
244
362
|
app.route('/api/sessions', sessionsRoutes(store));
|
|
245
|
-
// Health routes
|
|
246
|
-
|
|
363
|
+
// Health routes [F13-S2] — factory pattern, mounted at /api
|
|
364
|
+
app.route('/api', healthRoutes(store, db));
|
|
247
365
|
if (db) {
|
|
248
366
|
const { app: discApp } = discoveryRoutes(db);
|
|
249
367
|
app.route('/api/agents', discApp);
|
|
@@ -258,12 +376,29 @@ export function createApp(store, config) {
|
|
|
258
376
|
app.route('/api/stats', statsRoutes(store));
|
|
259
377
|
if (db) {
|
|
260
378
|
app.route('/api/config', configRoutes(db));
|
|
261
|
-
app.route('/api/analytics', analyticsRoutes(store, db));
|
|
379
|
+
app.route('/api/analytics', analyticsRoutes(store, db, config?.pgDb));
|
|
262
380
|
}
|
|
263
381
|
app.route('/api/alerts', alertsRoutes(store));
|
|
264
|
-
|
|
265
|
-
|
|
382
|
+
// Feature 12: Notification channels
|
|
383
|
+
const notifRepo = db ? new NotificationChannelRepository(db) : null;
|
|
384
|
+
const notifRouter = notifRepo ? new NotificationRouter(notifRepo) : null;
|
|
385
|
+
if (notifRepo && notifRouter) {
|
|
386
|
+
app.route('/api/notifications', notificationRoutes(notifRepo, notifRouter));
|
|
387
|
+
}
|
|
388
|
+
let loreAdapter = null;
|
|
389
|
+
if (resolvedConfig.loreEnabled) {
|
|
390
|
+
try {
|
|
391
|
+
loreAdapter = createLoreAdapter(resolvedConfig);
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
log.warn(`Lore adapter init failed: ${err instanceof Error ? err.message : err}`);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (loreAdapter) {
|
|
398
|
+
app.route('/api/lessons', loreProxyRoutes(loreAdapter));
|
|
266
399
|
}
|
|
400
|
+
// ─── AI Diagnostics (Feature 18) ───────────────────────
|
|
401
|
+
app.route('/api', diagnoseRoutes(store));
|
|
267
402
|
// ─── Reflect / Pattern Analysis ────────────────────────
|
|
268
403
|
app.route('/api/reflect', reflectRoutes(store));
|
|
269
404
|
// ─── Optimize / Cost Recommendations ──────────────────
|
|
@@ -271,11 +406,20 @@ export function createApp(store, config) {
|
|
|
271
406
|
// ─── Benchmarks / A/B Testing ─────────────────────────
|
|
272
407
|
if (db) {
|
|
273
408
|
app.route('/api/benchmarks', benchmarkRoutes(store, db));
|
|
409
|
+
app.route('/api/prompts', promptRoutes(db));
|
|
410
|
+
app.route('/api/eval', evalRoutes(db));
|
|
274
411
|
}
|
|
275
412
|
// ─── Guardrails / Proactive Guardrails ────────────────
|
|
276
413
|
if (db) {
|
|
277
414
|
const gStore = new GuardrailStore(db);
|
|
278
|
-
|
|
415
|
+
const contentEngine = new ContentGuardrailEngine(gStore);
|
|
416
|
+
app.route('/api/guardrails', guardrailRoutes(gStore, contentEngine));
|
|
417
|
+
}
|
|
418
|
+
// ─── Cost Budgets (Feature 5) ─────────────────────────
|
|
419
|
+
if (db) {
|
|
420
|
+
const cBudgetEngine = new BudgetEngine(store, db);
|
|
421
|
+
const budgetStore = cBudgetEngine.getStore();
|
|
422
|
+
app.route('/api/cost-budgets', costBudgetRoutes(budgetStore, store, cBudgetEngine));
|
|
279
423
|
}
|
|
280
424
|
// ─── Recall / Semantic Search ─────────────────────────
|
|
281
425
|
{
|
|
@@ -299,17 +443,103 @@ export function createApp(store, config) {
|
|
|
299
443
|
const { app: discTopApp } = discoveryRoutes(db);
|
|
300
444
|
app.route('/api/discovery', discTopApp);
|
|
301
445
|
}
|
|
302
|
-
// ───
|
|
446
|
+
// ─── Audit Log (SH-2) ──────────────────────────────────
|
|
303
447
|
if (db) {
|
|
304
|
-
app.
|
|
305
|
-
app.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
448
|
+
app.route('/api/audit', auditRoutes(db));
|
|
449
|
+
app.route('/api/audit/verify', auditVerifyRoutes(db, resolvedConfig.auditSigningKey));
|
|
450
|
+
app.route('/api/compliance', complianceRoutes(db, resolvedConfig.auditSigningKey, {
|
|
451
|
+
retentionDays: resolvedConfig.retentionDays,
|
|
452
|
+
}));
|
|
453
|
+
}
|
|
454
|
+
// ─── Cloud org routes with org access validation [F6-fix] ──
|
|
455
|
+
if (config?.pgSql) {
|
|
456
|
+
const cloudDb = {
|
|
457
|
+
async query(sql, params) {
|
|
458
|
+
const result = await config.pgSql.unsafe(sql, params);
|
|
459
|
+
return { rows: Array.from(result) };
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
app.route('/api/cloud/orgs', cloudOrgRoutes({ db: cloudDb }));
|
|
463
|
+
}
|
|
464
|
+
// ─── Community Sharing (Stories 4.1–4.3) ────────────────
|
|
465
|
+
// Auth is handled by the unified catch-all above.
|
|
466
|
+
if (loreAdapter) {
|
|
467
|
+
app.route('/api/community', loreCommunityProxyRoutes(loreAdapter));
|
|
468
|
+
}
|
|
469
|
+
// ─── Mesh Proxy (agentkit-mesh) ─────────────────────────
|
|
470
|
+
// Auth is handled by the unified catch-all above.
|
|
471
|
+
if (resolvedConfig.meshEnabled && resolvedConfig.meshUrl) {
|
|
472
|
+
const meshAdapter = new RemoteMeshAdapter(resolvedConfig.meshUrl);
|
|
473
|
+
app.route('/api/mesh', meshProxyRoutes(meshAdapter));
|
|
474
|
+
}
|
|
475
|
+
// ─── OTLP HTTP Receiver [F2-S5] ─────────────────────────
|
|
476
|
+
// Default: no auth (standard OTel convention). Opt-in via env vars.
|
|
477
|
+
if (resolvedConfig.otlpAuthRequired) {
|
|
478
|
+
// Full unified auth on OTLP endpoints
|
|
479
|
+
const authLookup = config?.apiKeyLookup ?? db ?? null;
|
|
480
|
+
app.use('/v1/*', unifiedAuthMiddleware(authLookup, {
|
|
481
|
+
authDisabled: resolvedConfig.authDisabled,
|
|
482
|
+
jwtSecret: process.env['JWT_SECRET'],
|
|
483
|
+
}));
|
|
484
|
+
}
|
|
485
|
+
else if (resolvedConfig.otlpAuthToken) {
|
|
486
|
+
// Simple bearer token check
|
|
487
|
+
const { createMiddleware } = await import('hono/factory');
|
|
488
|
+
app.use('/v1/*', createMiddleware(async (c, next) => {
|
|
489
|
+
const authHeader = c.req.header('Authorization');
|
|
490
|
+
if (!authHeader?.startsWith('Bearer ')) {
|
|
491
|
+
return otlpAuthRequiredError(c);
|
|
492
|
+
}
|
|
493
|
+
const token = authHeader.slice(7);
|
|
494
|
+
if (token !== resolvedConfig.otlpAuthToken) {
|
|
495
|
+
return otlpInvalidToken(c);
|
|
496
|
+
}
|
|
497
|
+
return next();
|
|
498
|
+
}));
|
|
499
|
+
}
|
|
500
|
+
app.route('/v1', otlpRoutes(store, resolvedConfig));
|
|
501
|
+
// ─── Server Info (Feature 10, Story 10.1) ─────────────
|
|
502
|
+
{
|
|
503
|
+
const features = [
|
|
504
|
+
'sessions', 'agents', 'alerts', 'analytics', 'stats',
|
|
505
|
+
'recall', 'reflect', 'optimize', 'context', 'health',
|
|
506
|
+
'replay', 'benchmarks', 'guardrails', 'discovery', 'delegation',
|
|
507
|
+
'cost-budgets', 'trust', 'lessons',
|
|
508
|
+
];
|
|
509
|
+
const { serverInfoRoutes } = await import('./routes/server-info.js');
|
|
510
|
+
app.route('/api/server-info', serverInfoRoutes(features));
|
|
511
|
+
}
|
|
512
|
+
// ─── OpenAPI Spec & Documentation [F13-S1] ────────────
|
|
513
|
+
app.doc('/api/openapi.json', {
|
|
514
|
+
openapi: '3.1.0',
|
|
515
|
+
info: {
|
|
516
|
+
title: 'AgentLens API',
|
|
517
|
+
version: '0.12.1',
|
|
518
|
+
description: 'Observability, governance, and orchestration for AI agents.',
|
|
519
|
+
license: { name: 'MIT' },
|
|
520
|
+
},
|
|
521
|
+
servers: [
|
|
522
|
+
{ url: 'http://localhost:3000', description: 'Local development' },
|
|
523
|
+
],
|
|
524
|
+
security: [{ Bearer: [] }],
|
|
525
|
+
tags: [
|
|
526
|
+
{ name: 'Sessions', description: 'Agent session lifecycle and queries' },
|
|
527
|
+
{ name: 'Events', description: 'Event ingestion and retrieval' },
|
|
528
|
+
{ name: 'Agents', description: 'Agent management and health' },
|
|
529
|
+
{ name: 'Auth', description: 'Authentication and API keys' },
|
|
530
|
+
{ name: 'Analytics', description: 'Metrics, costs, and statistics' },
|
|
531
|
+
{ name: 'Alerts', description: 'Alert rules and history' },
|
|
532
|
+
{ name: 'Intelligence', description: 'Reflect, recall, context, optimize' },
|
|
533
|
+
{ name: 'Trust & Governance', description: 'Trust scores, guardrails, cost budgets' },
|
|
534
|
+
{ name: 'Multi-Agent', description: 'Discovery, delegation, capabilities, mesh' },
|
|
535
|
+
{ name: 'Observability', description: 'Health, benchmarks, audit' },
|
|
536
|
+
{ name: 'Platform', description: 'Config, OTLP, streaming, webhooks' },
|
|
537
|
+
],
|
|
538
|
+
});
|
|
539
|
+
app.get('/api/docs', apiReference({
|
|
540
|
+
url: '/api/openapi.json',
|
|
541
|
+
theme: 'kepler',
|
|
542
|
+
}));
|
|
313
543
|
// ─── Dashboard SPA static assets ──────────────────────
|
|
314
544
|
const dashboardRoot = getDashboardRoot();
|
|
315
545
|
if (dashboardRoot) {
|
|
@@ -322,46 +552,151 @@ export function createApp(store, config) {
|
|
|
322
552
|
* Creates the database, runs migrations, and starts listening.
|
|
323
553
|
*/
|
|
324
554
|
export async function startServer() {
|
|
555
|
+
// SH-7: Resolve secrets from env / file / ARN before anything reads process.env
|
|
556
|
+
const { resolveAllSecrets } = await import('./lib/secrets.js');
|
|
557
|
+
await resolveAllSecrets();
|
|
325
558
|
const config = getConfig();
|
|
559
|
+
validateConfig(config);
|
|
326
560
|
// Create and initialize database
|
|
327
|
-
|
|
561
|
+
// For Postgres, we need the raw sql client for shutdown & health checks
|
|
562
|
+
let pgSql;
|
|
563
|
+
let pgDb;
|
|
564
|
+
let store;
|
|
565
|
+
let db;
|
|
566
|
+
// SQLite is always created for auxiliary features (api_keys, audit, guardrails, etc.)
|
|
567
|
+
// Even when PG is the primary event/embedding store
|
|
568
|
+
db = createDb({ databasePath: config.dbPath });
|
|
328
569
|
runMigrations(db);
|
|
329
|
-
|
|
570
|
+
if (config.storageBackend === 'postgres') {
|
|
571
|
+
const { createPostgresConnection, verifyPostgresConnection } = await import('./db/connection.postgres.js');
|
|
572
|
+
const conn = createPostgresConnection();
|
|
573
|
+
await verifyPostgresConnection(conn.sql); // fail fast if unreachable
|
|
574
|
+
pgSql = conn.sql;
|
|
575
|
+
pgDb = conn.db;
|
|
576
|
+
const { runPostgresMigrations } = await import('./db/migrate.postgres.js');
|
|
577
|
+
await runPostgresMigrations(pgDb);
|
|
578
|
+
const { PostgresEventStore } = await import('./db/postgres-store.js');
|
|
579
|
+
store = new PostgresEventStore(pgDb);
|
|
580
|
+
// Warn about silent SQLite → PG switch for existing Docker Compose users
|
|
581
|
+
log.warn('STORAGE_BACKEND=postgres is now active. Previous SQLite data at ' +
|
|
582
|
+
`${config.dbPath} is not automatically migrated.`);
|
|
583
|
+
log.info('Database: PostgreSQL');
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
store = new SqliteEventStore(db);
|
|
587
|
+
log.info(`Database: SQLite (${config.dbPath})`);
|
|
588
|
+
}
|
|
330
589
|
// Create embedding service & worker (optional — fail-safe)
|
|
331
590
|
let embeddingService = null;
|
|
332
591
|
let embeddingWorker = null;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
embeddingService = createEmbeddingService();
|
|
336
|
-
const embeddingStore = new EmbeddingStore(db);
|
|
337
|
-
embeddingWorker = new EmbeddingWorker(embeddingService, embeddingStore);
|
|
338
|
-
embeddingWorker.start();
|
|
339
|
-
console.log(` Embeddings: enabled (${embeddingService.modelName})`);
|
|
592
|
+
if (process.env.DISABLE_EMBEDDINGS) {
|
|
593
|
+
log.info('Embeddings: disabled (DISABLE_EMBEDDINGS set)');
|
|
340
594
|
}
|
|
341
|
-
|
|
342
|
-
|
|
595
|
+
else {
|
|
596
|
+
try {
|
|
597
|
+
const { createEmbeddingService } = await import('./lib/embeddings/index.js');
|
|
598
|
+
embeddingService = createEmbeddingService();
|
|
599
|
+
let embeddingStore;
|
|
600
|
+
if (config.storageBackend === 'postgres' && pgDb) {
|
|
601
|
+
const { PostgresEmbeddingStore } = await import('./db/postgres-embedding-store.js');
|
|
602
|
+
const pgEmbeddingStore = new PostgresEmbeddingStore(pgDb);
|
|
603
|
+
await pgEmbeddingStore.initialize();
|
|
604
|
+
embeddingStore = pgEmbeddingStore;
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
embeddingStore = new EmbeddingStore(db);
|
|
608
|
+
}
|
|
609
|
+
embeddingWorker = new EmbeddingWorker(embeddingService, embeddingStore);
|
|
610
|
+
embeddingWorker.start();
|
|
611
|
+
log.info(`Embeddings: enabled (${embeddingService.modelName})`);
|
|
612
|
+
}
|
|
613
|
+
catch (err) {
|
|
614
|
+
log.info(`Embeddings: disabled (${err instanceof Error ? err.message : 'unknown error'})`);
|
|
615
|
+
}
|
|
343
616
|
}
|
|
344
617
|
// Create app with db reference for auth
|
|
345
|
-
|
|
618
|
+
// Create API key lookup for auth (uses SQLite for auxiliary features in both modes)
|
|
619
|
+
const { SqliteApiKeyLookup } = await import('./db/api-key-lookup.js');
|
|
620
|
+
const apiKeyLookup = new SqliteApiKeyLookup(db);
|
|
621
|
+
const app = await createApp(store, { ...config, db, apiKeyLookup, embeddingService, embeddingWorker, pgSql, pgDb });
|
|
346
622
|
// Start listening
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
623
|
+
log.info(`AgentLens server starting on port ${config.port}`);
|
|
624
|
+
log.info(`Auth: ${config.authDisabled ? 'DISABLED (dev mode)' : 'enabled'}`);
|
|
625
|
+
log.info(`CORS origin: ${config.corsOrigin}`);
|
|
626
|
+
// Audit log retention cleanup (SH-2)
|
|
627
|
+
{
|
|
628
|
+
const auditRetentionDays = parseInt(process.env['AUDIT_RETENTION_DAYS'] ?? '90', 10);
|
|
629
|
+
if (auditRetentionDays > 0) {
|
|
630
|
+
try {
|
|
631
|
+
const deleted = cleanupAuditLogs(db, auditRetentionDays);
|
|
632
|
+
if (deleted > 0) {
|
|
633
|
+
log.info(`Audit log cleanup: removed ${deleted} entries older than ${auditRetentionDays} days`);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
catch (err) {
|
|
637
|
+
log.warn(`Audit log cleanup failed: ${err instanceof Error ? err.message : err}`);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
// Start alert evaluation engine — wire notification router if db is available
|
|
642
|
+
const notifRepoForEngine = db ? new NotificationChannelRepository(db) : null;
|
|
643
|
+
const notifRouterForEngine = notifRepoForEngine ? new NotificationRouter(notifRepoForEngine) : null;
|
|
644
|
+
const alertEngine = new AlertEngine(store, { notificationRouter: notifRouterForEngine ?? undefined });
|
|
353
645
|
alertEngine.start();
|
|
354
646
|
// Start guardrail evaluation engine (v0.8.0)
|
|
355
647
|
// Wire the agent store so pause_agent/downgrade_model actions can UPDATE the agents table (B1)
|
|
356
648
|
setAgentStore(store);
|
|
649
|
+
if (notifRouterForEngine)
|
|
650
|
+
setNotificationRouter(notifRouterForEngine);
|
|
357
651
|
const guardrailEngine = new GuardrailEngine(store, db);
|
|
358
652
|
guardrailEngine.start();
|
|
359
|
-
|
|
360
|
-
|
|
653
|
+
log.info('Guardrails: enabled');
|
|
654
|
+
// Start budget engine and anomaly detector (Feature 5)
|
|
655
|
+
const budgetEngine = new BudgetEngine(store, db);
|
|
656
|
+
budgetEngine.start();
|
|
657
|
+
const anomalyDetector = new CostAnomalyDetector(store, budgetEngine.getStore());
|
|
658
|
+
anomalyDetector.start();
|
|
659
|
+
log.info('Cost budgets & anomaly detection: enabled');
|
|
660
|
+
// M-11 FIX: Graceful shutdown for engines, workers, HTTP server, and PG pool
|
|
661
|
+
let httpServer;
|
|
662
|
+
let shuttingDown = false;
|
|
663
|
+
const shutdown = async () => {
|
|
664
|
+
if (shuttingDown)
|
|
665
|
+
return;
|
|
666
|
+
shuttingDown = true;
|
|
667
|
+
log.info('Shutting down...');
|
|
668
|
+
// 1. Stop accepting new requests
|
|
669
|
+
if (httpServer) {
|
|
670
|
+
httpServer.close(() => log.info('HTTP server closed'));
|
|
671
|
+
}
|
|
672
|
+
// 2. Stop engines and workers
|
|
673
|
+
alertEngine.stop();
|
|
674
|
+
guardrailEngine.stop();
|
|
675
|
+
if (embeddingWorker)
|
|
676
|
+
embeddingWorker.stop();
|
|
677
|
+
// 3. Drain PG pool (5s timeout)
|
|
678
|
+
if (pgSql) {
|
|
679
|
+
try {
|
|
680
|
+
log.info('Draining PostgreSQL connection pool...');
|
|
681
|
+
await Promise.race([
|
|
682
|
+
pgSql.end({ timeout: 5 }),
|
|
683
|
+
new Promise((resolve) => setTimeout(resolve, 5000)),
|
|
684
|
+
]);
|
|
685
|
+
log.info('PostgreSQL pool drained');
|
|
686
|
+
}
|
|
687
|
+
catch (err) {
|
|
688
|
+
log.warn(`PG pool drain error: ${err instanceof Error ? err.message : err}`);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
process.exit(0);
|
|
692
|
+
};
|
|
693
|
+
process.on('SIGTERM', shutdown);
|
|
694
|
+
process.on('SIGINT', shutdown);
|
|
695
|
+
httpServer = serve({
|
|
361
696
|
fetch: app.fetch,
|
|
362
697
|
port: config.port,
|
|
363
698
|
}, (info) => {
|
|
364
|
-
|
|
699
|
+
log.info(`AgentLens server listening on http://localhost:${info.port}`);
|
|
365
700
|
});
|
|
366
701
|
return app;
|
|
367
702
|
}
|