clawsec 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +560 -0
- package/dist/bin/clawsec.d.ts +7 -0
- package/dist/bin/clawsec.d.ts.map +1 -0
- package/dist/bin/clawsec.js +12 -0
- package/dist/bin/clawsec.js.map +1 -0
- package/dist/src/actions/block.d.ts +22 -0
- package/dist/src/actions/block.d.ts.map +1 -0
- package/dist/src/actions/block.js +83 -0
- package/dist/src/actions/block.js.map +1 -0
- package/dist/src/actions/confirm.d.ts +35 -0
- package/dist/src/actions/confirm.d.ts.map +1 -0
- package/dist/src/actions/confirm.js +156 -0
- package/dist/src/actions/confirm.js.map +1 -0
- package/dist/src/actions/executor.d.ts +64 -0
- package/dist/src/actions/executor.d.ts.map +1 -0
- package/dist/src/actions/executor.js +114 -0
- package/dist/src/actions/executor.js.map +1 -0
- package/dist/src/actions/index.d.ts +13 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/actions/index.js +15 -0
- package/dist/src/actions/index.js.map +1 -0
- package/dist/src/actions/log.d.ts +19 -0
- package/dist/src/actions/log.d.ts.map +1 -0
- package/dist/src/actions/log.js +63 -0
- package/dist/src/actions/log.js.map +1 -0
- package/dist/src/actions/types.d.ts +85 -0
- package/dist/src/actions/types.d.ts.map +1 -0
- package/dist/src/actions/types.js +78 -0
- package/dist/src/actions/types.js.map +1 -0
- package/dist/src/actions/warn.d.ts +22 -0
- package/dist/src/actions/warn.d.ts.map +1 -0
- package/dist/src/actions/warn.js +84 -0
- package/dist/src/actions/warn.js.map +1 -0
- package/dist/src/approval/agent-confirm.d.ts +104 -0
- package/dist/src/approval/agent-confirm.d.ts.map +1 -0
- package/dist/src/approval/agent-confirm.js +173 -0
- package/dist/src/approval/agent-confirm.js.map +1 -0
- package/dist/src/approval/index.d.ts +14 -0
- package/dist/src/approval/index.d.ts.map +1 -0
- package/dist/src/approval/index.js +9 -0
- package/dist/src/approval/index.js.map +1 -0
- package/dist/src/approval/native.d.ts +56 -0
- package/dist/src/approval/native.d.ts.map +1 -0
- package/dist/src/approval/native.js +196 -0
- package/dist/src/approval/native.js.map +1 -0
- package/dist/src/approval/store.d.ts +88 -0
- package/dist/src/approval/store.d.ts.map +1 -0
- package/dist/src/approval/store.js +192 -0
- package/dist/src/approval/store.js.map +1 -0
- package/dist/src/approval/types.d.ts +119 -0
- package/dist/src/approval/types.d.ts.map +1 -0
- package/dist/src/approval/types.js +6 -0
- package/dist/src/approval/types.js.map +1 -0
- package/dist/src/approval/webhook.d.ts +170 -0
- package/dist/src/approval/webhook.d.ts.map +1 -0
- package/dist/src/approval/webhook.js +362 -0
- package/dist/src/approval/webhook.js.map +1 -0
- package/dist/src/cli/commands/audit.d.ts +43 -0
- package/dist/src/cli/commands/audit.d.ts.map +1 -0
- package/dist/src/cli/commands/audit.js +115 -0
- package/dist/src/cli/commands/audit.js.map +1 -0
- package/dist/src/cli/commands/feedback.d.ts +27 -0
- package/dist/src/cli/commands/feedback.d.ts.map +1 -0
- package/dist/src/cli/commands/feedback.js +228 -0
- package/dist/src/cli/commands/feedback.js.map +1 -0
- package/dist/src/cli/commands/index.d.ts +11 -0
- package/dist/src/cli/commands/index.d.ts.map +1 -0
- package/dist/src/cli/commands/index.js +13 -0
- package/dist/src/cli/commands/index.js.map +1 -0
- package/dist/src/cli/commands/status.d.ts +20 -0
- package/dist/src/cli/commands/status.d.ts.map +1 -0
- package/dist/src/cli/commands/status.js +122 -0
- package/dist/src/cli/commands/status.js.map +1 -0
- package/dist/src/cli/commands/test.d.ts +23 -0
- package/dist/src/cli/commands/test.d.ts.map +1 -0
- package/dist/src/cli/commands/test.js +134 -0
- package/dist/src/cli/commands/test.js.map +1 -0
- package/dist/src/cli/commands/types.d.ts +81 -0
- package/dist/src/cli/commands/types.d.ts.map +1 -0
- package/dist/src/cli/commands/types.js +6 -0
- package/dist/src/cli/commands/types.js.map +1 -0
- package/dist/src/cli/index.d.ts +17 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +267 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/config/defaults.d.ts +20 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +123 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/index.d.ts +8 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +41 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/config/loader.d.ts +99 -0
- package/dist/src/config/loader.d.ts.map +1 -0
- package/dist/src/config/loader.js +242 -0
- package/dist/src/config/loader.js.map +1 -0
- package/dist/src/config/schema.d.ts +627 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +585 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/detectors/destructive/cloud-detector.d.ts +51 -0
- package/dist/src/detectors/destructive/cloud-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/cloud-detector.js +556 -0
- package/dist/src/detectors/destructive/cloud-detector.js.map +1 -0
- package/dist/src/detectors/destructive/code-detector.d.ts +59 -0
- package/dist/src/detectors/destructive/code-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/code-detector.js +558 -0
- package/dist/src/detectors/destructive/code-detector.js.map +1 -0
- package/dist/src/detectors/destructive/index.d.ts +54 -0
- package/dist/src/detectors/destructive/index.d.ts.map +1 -0
- package/dist/src/detectors/destructive/index.js +168 -0
- package/dist/src/detectors/destructive/index.js.map +1 -0
- package/dist/src/detectors/destructive/shell-detector.d.ts +43 -0
- package/dist/src/detectors/destructive/shell-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/shell-detector.js +302 -0
- package/dist/src/detectors/destructive/shell-detector.js.map +1 -0
- package/dist/src/detectors/destructive/types.d.ts +143 -0
- package/dist/src/detectors/destructive/types.d.ts.map +1 -0
- package/dist/src/detectors/destructive/types.js +6 -0
- package/dist/src/detectors/destructive/types.js.map +1 -0
- package/dist/src/detectors/exfiltration/cloud-detector.d.ts +51 -0
- package/dist/src/detectors/exfiltration/cloud-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/cloud-detector.js +427 -0
- package/dist/src/detectors/exfiltration/cloud-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/http-detector.d.ts +47 -0
- package/dist/src/detectors/exfiltration/http-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/http-detector.js +429 -0
- package/dist/src/detectors/exfiltration/http-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/index.d.ts +44 -0
- package/dist/src/detectors/exfiltration/index.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/index.js +118 -0
- package/dist/src/detectors/exfiltration/index.js.map +1 -0
- package/dist/src/detectors/exfiltration/network-detector.d.ts +55 -0
- package/dist/src/detectors/exfiltration/network-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/network-detector.js +504 -0
- package/dist/src/detectors/exfiltration/network-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/types.d.ts +139 -0
- package/dist/src/detectors/exfiltration/types.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/types.js +6 -0
- package/dist/src/detectors/exfiltration/types.js.map +1 -0
- package/dist/src/detectors/purchase/domain-detector.d.ts +44 -0
- package/dist/src/detectors/purchase/domain-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/domain-detector.js +296 -0
- package/dist/src/detectors/purchase/domain-detector.js.map +1 -0
- package/dist/src/detectors/purchase/form-detector.d.ts +27 -0
- package/dist/src/detectors/purchase/form-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/form-detector.js +344 -0
- package/dist/src/detectors/purchase/form-detector.js.map +1 -0
- package/dist/src/detectors/purchase/index.d.ts +65 -0
- package/dist/src/detectors/purchase/index.d.ts.map +1 -0
- package/dist/src/detectors/purchase/index.js +216 -0
- package/dist/src/detectors/purchase/index.js.map +1 -0
- package/dist/src/detectors/purchase/spend-tracker.d.ts +132 -0
- package/dist/src/detectors/purchase/spend-tracker.d.ts.map +1 -0
- package/dist/src/detectors/purchase/spend-tracker.js +313 -0
- package/dist/src/detectors/purchase/spend-tracker.js.map +1 -0
- package/dist/src/detectors/purchase/types.d.ts +139 -0
- package/dist/src/detectors/purchase/types.d.ts.map +1 -0
- package/dist/src/detectors/purchase/types.js +6 -0
- package/dist/src/detectors/purchase/types.js.map +1 -0
- package/dist/src/detectors/purchase/url-detector.d.ts +31 -0
- package/dist/src/detectors/purchase/url-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/url-detector.js +292 -0
- package/dist/src/detectors/purchase/url-detector.js.map +1 -0
- package/dist/src/detectors/secrets/api-key-detector.d.ts +30 -0
- package/dist/src/detectors/secrets/api-key-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/api-key-detector.js +297 -0
- package/dist/src/detectors/secrets/api-key-detector.js.map +1 -0
- package/dist/src/detectors/secrets/index.d.ts +43 -0
- package/dist/src/detectors/secrets/index.d.ts.map +1 -0
- package/dist/src/detectors/secrets/index.js +261 -0
- package/dist/src/detectors/secrets/index.js.map +1 -0
- package/dist/src/detectors/secrets/pii-detector.d.ts +54 -0
- package/dist/src/detectors/secrets/pii-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/pii-detector.js +286 -0
- package/dist/src/detectors/secrets/pii-detector.js.map +1 -0
- package/dist/src/detectors/secrets/token-detector.d.ts +51 -0
- package/dist/src/detectors/secrets/token-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/token-detector.js +233 -0
- package/dist/src/detectors/secrets/token-detector.js.map +1 -0
- package/dist/src/detectors/secrets/types.d.ts +157 -0
- package/dist/src/detectors/secrets/types.d.ts.map +1 -0
- package/dist/src/detectors/secrets/types.js +6 -0
- package/dist/src/detectors/secrets/types.js.map +1 -0
- package/dist/src/detectors/website/category-detector.d.ts +22 -0
- package/dist/src/detectors/website/category-detector.d.ts.map +1 -0
- package/dist/src/detectors/website/category-detector.js +162 -0
- package/dist/src/detectors/website/category-detector.js.map +1 -0
- package/dist/src/detectors/website/index.d.ts +53 -0
- package/dist/src/detectors/website/index.d.ts.map +1 -0
- package/dist/src/detectors/website/index.js +232 -0
- package/dist/src/detectors/website/index.js.map +1 -0
- package/dist/src/detectors/website/pattern-matcher.d.ts +33 -0
- package/dist/src/detectors/website/pattern-matcher.d.ts.map +1 -0
- package/dist/src/detectors/website/pattern-matcher.js +121 -0
- package/dist/src/detectors/website/pattern-matcher.js.map +1 -0
- package/dist/src/detectors/website/types.d.ts +105 -0
- package/dist/src/detectors/website/types.d.ts.map +1 -0
- package/dist/src/detectors/website/types.js +6 -0
- package/dist/src/detectors/website/types.js.map +1 -0
- package/dist/src/engine/analyzer.d.ts +87 -0
- package/dist/src/engine/analyzer.d.ts.map +1 -0
- package/dist/src/engine/analyzer.js +427 -0
- package/dist/src/engine/analyzer.js.map +1 -0
- package/dist/src/engine/cache.d.ts +80 -0
- package/dist/src/engine/cache.d.ts.map +1 -0
- package/dist/src/engine/cache.js +167 -0
- package/dist/src/engine/cache.js.map +1 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.d.ts.map +1 -0
- package/dist/src/engine/index.js +11 -0
- package/dist/src/engine/index.js.map +1 -0
- package/dist/src/engine/llm-client.d.ts +210 -0
- package/dist/src/engine/llm-client.d.ts.map +1 -0
- package/dist/src/engine/llm-client.js +506 -0
- package/dist/src/engine/llm-client.js.map +1 -0
- package/dist/src/engine/types.d.ts +163 -0
- package/dist/src/engine/types.d.ts.map +1 -0
- package/dist/src/engine/types.js +21 -0
- package/dist/src/engine/types.js.map +1 -0
- package/dist/src/feedback/index.d.ts +9 -0
- package/dist/src/feedback/index.d.ts.map +1 -0
- package/dist/src/feedback/index.js +8 -0
- package/dist/src/feedback/index.js.map +1 -0
- package/dist/src/feedback/learner.d.ts +222 -0
- package/dist/src/feedback/learner.d.ts.map +1 -0
- package/dist/src/feedback/learner.js +401 -0
- package/dist/src/feedback/learner.js.map +1 -0
- package/dist/src/feedback/store.d.ts +113 -0
- package/dist/src/feedback/store.d.ts.map +1 -0
- package/dist/src/feedback/store.js +228 -0
- package/dist/src/feedback/store.js.map +1 -0
- package/dist/src/feedback/types.d.ts +126 -0
- package/dist/src/feedback/types.d.ts.map +1 -0
- package/dist/src/feedback/types.js +6 -0
- package/dist/src/feedback/types.js.map +1 -0
- package/dist/src/hooks/before-agent-start/handler.d.ts +37 -0
- package/dist/src/hooks/before-agent-start/handler.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/handler.js +109 -0
- package/dist/src/hooks/before-agent-start/handler.js.map +1 -0
- package/dist/src/hooks/before-agent-start/index.d.ts +8 -0
- package/dist/src/hooks/before-agent-start/index.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/index.js +7 -0
- package/dist/src/hooks/before-agent-start/index.js.map +1 -0
- package/dist/src/hooks/before-agent-start/prompts.d.ts +48 -0
- package/dist/src/hooks/before-agent-start/prompts.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/prompts.js +103 -0
- package/dist/src/hooks/before-agent-start/prompts.js.map +1 -0
- package/dist/src/hooks/before-tool-call/handler.d.ts +42 -0
- package/dist/src/hooks/before-tool-call/handler.d.ts.map +1 -0
- package/dist/src/hooks/before-tool-call/handler.js +226 -0
- package/dist/src/hooks/before-tool-call/handler.js.map +1 -0
- package/dist/src/hooks/before-tool-call/index.d.ts +7 -0
- package/dist/src/hooks/before-tool-call/index.d.ts.map +1 -0
- package/dist/src/hooks/before-tool-call/index.js +6 -0
- package/dist/src/hooks/before-tool-call/index.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/filter.d.ts +72 -0
- package/dist/src/hooks/tool-result-persist/filter.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/filter.js +305 -0
- package/dist/src/hooks/tool-result-persist/filter.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/handler.d.ts +49 -0
- package/dist/src/hooks/tool-result-persist/handler.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/handler.js +217 -0
- package/dist/src/hooks/tool-result-persist/handler.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/index.d.ts +11 -0
- package/dist/src/hooks/tool-result-persist/index.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/index.js +11 -0
- package/dist/src/hooks/tool-result-persist/index.js.map +1 -0
- package/dist/src/index.d.ts +256 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +222 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/notifications/discord.d.ts +10 -0
- package/dist/src/notifications/discord.d.ts.map +1 -0
- package/dist/src/notifications/discord.js +218 -0
- package/dist/src/notifications/discord.js.map +1 -0
- package/dist/src/notifications/index.d.ts +37 -0
- package/dist/src/notifications/index.d.ts.map +1 -0
- package/dist/src/notifications/index.js +68 -0
- package/dist/src/notifications/index.js.map +1 -0
- package/dist/src/notifications/slack.d.ts +10 -0
- package/dist/src/notifications/slack.d.ts.map +1 -0
- package/dist/src/notifications/slack.js +218 -0
- package/dist/src/notifications/slack.js.map +1 -0
- package/dist/src/notifications/telegram.d.ts +10 -0
- package/dist/src/notifications/telegram.d.ts.map +1 -0
- package/dist/src/notifications/telegram.js +242 -0
- package/dist/src/notifications/telegram.js.map +1 -0
- package/dist/src/notifications/types.d.ts +119 -0
- package/dist/src/notifications/types.d.ts.map +1 -0
- package/dist/src/notifications/types.js +6 -0
- package/dist/src/notifications/types.js.map +1 -0
- package/dist/src/proxy/index.d.ts +8 -0
- package/dist/src/proxy/index.d.ts.map +1 -0
- package/dist/src/proxy/index.js +9 -0
- package/dist/src/proxy/index.js.map +1 -0
- package/dist/src/proxy/middleware.d.ts +55 -0
- package/dist/src/proxy/middleware.d.ts.map +1 -0
- package/dist/src/proxy/middleware.js +215 -0
- package/dist/src/proxy/middleware.js.map +1 -0
- package/dist/src/proxy/server.d.ts +57 -0
- package/dist/src/proxy/server.d.ts.map +1 -0
- package/dist/src/proxy/server.js +298 -0
- package/dist/src/proxy/server.js.map +1 -0
- package/dist/src/proxy/types.d.ts +136 -0
- package/dist/src/proxy/types.d.ts.map +1 -0
- package/dist/src/proxy/types.js +6 -0
- package/dist/src/proxy/types.js.map +1 -0
- package/dist/src/sanitization/index.d.ts +10 -0
- package/dist/src/sanitization/index.d.ts.map +1 -0
- package/dist/src/sanitization/index.js +9 -0
- package/dist/src/sanitization/index.js.map +1 -0
- package/dist/src/sanitization/patterns.d.ts +51 -0
- package/dist/src/sanitization/patterns.d.ts.map +1 -0
- package/dist/src/sanitization/patterns.js +266 -0
- package/dist/src/sanitization/patterns.js.map +1 -0
- package/dist/src/sanitization/scanner.d.ts +29 -0
- package/dist/src/sanitization/scanner.d.ts.map +1 -0
- package/dist/src/sanitization/scanner.js +328 -0
- package/dist/src/sanitization/scanner.js.map +1 -0
- package/dist/src/sanitization/types.d.ts +57 -0
- package/dist/src/sanitization/types.d.ts.map +1 -0
- package/dist/src/sanitization/types.js +5 -0
- package/dist/src/sanitization/types.js.map +1 -0
- package/openclaw.plugin.json +114 -0
- package/package.json +63 -0
- package/rules/builtin/README.md +139 -0
- package/rules/builtin/ai-services.yaml +70 -0
- package/rules/builtin/api-keys.yaml +64 -0
- package/rules/builtin/authentication.yaml +56 -0
- package/rules/builtin/aws-security.yaml +57 -0
- package/rules/builtin/azure-security.yaml +58 -0
- package/rules/builtin/cicd-security.yaml +64 -0
- package/rules/builtin/cloud-storage.yaml +64 -0
- package/rules/builtin/container-registry.yaml +55 -0
- package/rules/builtin/crypto-wallets.yaml +71 -0
- package/rules/builtin/database-nosql.yaml +58 -0
- package/rules/builtin/database-sql.yaml +62 -0
- package/rules/builtin/development-env.yaml +67 -0
- package/rules/builtin/docker.yaml +57 -0
- package/rules/builtin/filesystem.yaml +71 -0
- package/rules/builtin/financial-pci.yaml +61 -0
- package/rules/builtin/gcp-security.yaml +57 -0
- package/rules/builtin/git-operations.yaml +68 -0
- package/rules/builtin/healthcare-hipaa.yaml +64 -0
- package/rules/builtin/kubernetes.yaml +60 -0
- package/rules/builtin/messaging-services.yaml +53 -0
- package/rules/builtin/minimal.yaml +47 -0
- package/rules/builtin/mobile-development.yaml +61 -0
- package/rules/builtin/monitoring.yaml +63 -0
- package/rules/builtin/network-security.yaml +57 -0
- package/rules/builtin/package-managers.yaml +74 -0
- package/rules/builtin/payment-processing.yaml +66 -0
- package/rules/builtin/pii-protection.yaml +48 -0
- package/rules/builtin/production-strict.yaml +55 -0
- package/rules/builtin/secrets-management.yaml +63 -0
- package/rules/builtin/serverless.yaml +74 -0
- package/rules/builtin/ssh-security.yaml +66 -0
- package/rules/builtin/terraform.yaml +51 -0
- package/rules/builtin/web-security.yaml +62 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Notification Integration
|
|
3
|
+
* Sends security event notifications to Telegram via Bot API
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Severity emoji for Telegram
|
|
7
|
+
*/
|
|
8
|
+
const SEVERITY_EMOJI = {
|
|
9
|
+
critical: '🚨',
|
|
10
|
+
high: '⚠️',
|
|
11
|
+
medium: '🟡',
|
|
12
|
+
low: 'ℹ️',
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Escape special characters for Telegram MarkdownV2
|
|
16
|
+
*/
|
|
17
|
+
function escapeMarkdownV2(text) {
|
|
18
|
+
return text.replace(/[_*\[\]()~`>#+=|{}.!-]/g, '\\$&');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Escape special characters for Telegram HTML
|
|
22
|
+
*/
|
|
23
|
+
function escapeHtml(text) {
|
|
24
|
+
return text
|
|
25
|
+
.replace(/&/g, '&')
|
|
26
|
+
.replace(/</g, '<')
|
|
27
|
+
.replace(/>/g, '>');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Format a security event as a Telegram message (HTML format)
|
|
31
|
+
*/
|
|
32
|
+
function formatTelegramMessageHtml(event) {
|
|
33
|
+
const emoji = SEVERITY_EMOJI[event.severity];
|
|
34
|
+
const timestamp = new Date(event.timestamp).toISOString();
|
|
35
|
+
return `${emoji} <b>Security Alert: ${escapeHtml(event.category.toUpperCase())}</b>
|
|
36
|
+
|
|
37
|
+
<b>Reason:</b> ${escapeHtml(event.reason)}
|
|
38
|
+
|
|
39
|
+
<b>Details:</b>
|
|
40
|
+
• Severity: ${escapeHtml(event.severity.toUpperCase())}
|
|
41
|
+
• Action: ${escapeHtml(event.action.toUpperCase())}
|
|
42
|
+
• Tool: ${escapeHtml(event.toolName)}
|
|
43
|
+
• Event ID: <code>${escapeHtml(event.eventId)}</code>
|
|
44
|
+
${event.sessionId ? `• Session: <code>${escapeHtml(event.sessionId.substring(0, 8))}...</code>` : ''}
|
|
45
|
+
|
|
46
|
+
<i>Clawsec Security Plugin • ${escapeHtml(timestamp)}</i>`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Format a security event as a Telegram message (Markdown format)
|
|
50
|
+
*/
|
|
51
|
+
function formatTelegramMessageMarkdown(event) {
|
|
52
|
+
const emoji = SEVERITY_EMOJI[event.severity];
|
|
53
|
+
const timestamp = new Date(event.timestamp).toISOString();
|
|
54
|
+
return `${emoji} *Security Alert: ${event.category.toUpperCase()}*
|
|
55
|
+
|
|
56
|
+
*Reason:* ${event.reason}
|
|
57
|
+
|
|
58
|
+
*Details:*
|
|
59
|
+
• Severity: ${event.severity.toUpperCase()}
|
|
60
|
+
• Action: ${event.action.toUpperCase()}
|
|
61
|
+
• Tool: ${event.toolName}
|
|
62
|
+
• Event ID: \`${event.eventId}\`
|
|
63
|
+
${event.sessionId ? `• Session: \`${event.sessionId.substring(0, 8)}...\`` : ''}
|
|
64
|
+
|
|
65
|
+
_Clawsec Security Plugin • ${timestamp}_`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Format a security event as a Telegram message (MarkdownV2 format)
|
|
69
|
+
*/
|
|
70
|
+
function formatTelegramMessageMarkdownV2(event) {
|
|
71
|
+
const emoji = SEVERITY_EMOJI[event.severity];
|
|
72
|
+
const timestamp = new Date(event.timestamp).toISOString();
|
|
73
|
+
return `${emoji} *Security Alert: ${escapeMarkdownV2(event.category.toUpperCase())}*
|
|
74
|
+
|
|
75
|
+
*Reason:* ${escapeMarkdownV2(event.reason)}
|
|
76
|
+
|
|
77
|
+
*Details:*
|
|
78
|
+
• Severity: ${escapeMarkdownV2(event.severity.toUpperCase())}
|
|
79
|
+
• Action: ${escapeMarkdownV2(event.action.toUpperCase())}
|
|
80
|
+
• Tool: ${escapeMarkdownV2(event.toolName)}
|
|
81
|
+
• Event ID: \`${escapeMarkdownV2(event.eventId)}\`
|
|
82
|
+
${event.sessionId ? `• Session: \`${escapeMarkdownV2(event.sessionId.substring(0, 8))}\\.\\.\\.\`` : ''}
|
|
83
|
+
|
|
84
|
+
_Clawsec Security Plugin • ${escapeMarkdownV2(timestamp)}_`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Format a security event as a Telegram message
|
|
88
|
+
*/
|
|
89
|
+
function formatTelegramMessage(event, parseMode) {
|
|
90
|
+
switch (parseMode) {
|
|
91
|
+
case 'HTML':
|
|
92
|
+
return formatTelegramMessageHtml(event);
|
|
93
|
+
case 'MarkdownV2':
|
|
94
|
+
return formatTelegramMessageMarkdownV2(event);
|
|
95
|
+
case 'Markdown':
|
|
96
|
+
default:
|
|
97
|
+
return formatTelegramMessageMarkdown(event);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Format a test message for Telegram
|
|
102
|
+
*/
|
|
103
|
+
function formatTestMessage(parseMode) {
|
|
104
|
+
switch (parseMode) {
|
|
105
|
+
case 'HTML':
|
|
106
|
+
return '✅ <b>Clawsec Test Notification</b>\n\nYour Telegram integration is working correctly.\n\n<i>Clawsec Security Plugin</i>';
|
|
107
|
+
case 'MarkdownV2':
|
|
108
|
+
return '✅ *Clawsec Test Notification*\n\nYour Telegram integration is working correctly\\.\n\n_Clawsec Security Plugin_';
|
|
109
|
+
case 'Markdown':
|
|
110
|
+
default:
|
|
111
|
+
return '✅ *Clawsec Test Notification*\n\nYour Telegram integration is working correctly.\n\n_Clawsec Security Plugin_';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check if event should trigger notification based on config
|
|
116
|
+
*/
|
|
117
|
+
function shouldNotify(event, config) {
|
|
118
|
+
// Check minimum severity
|
|
119
|
+
if (config.minSeverity) {
|
|
120
|
+
const severityOrder = ['low', 'medium', 'high', 'critical'];
|
|
121
|
+
const minIndex = severityOrder.indexOf(config.minSeverity);
|
|
122
|
+
const eventIndex = severityOrder.indexOf(event.severity);
|
|
123
|
+
if (eventIndex < minIndex) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Check category filter
|
|
128
|
+
if (config.categories && config.categories.length > 0) {
|
|
129
|
+
if (!config.categories.includes(event.category)) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create a Telegram notification sender
|
|
137
|
+
*/
|
|
138
|
+
export function createTelegramSender(config) {
|
|
139
|
+
const baseUrl = `https://api.telegram.org/bot${config.botToken}`;
|
|
140
|
+
return {
|
|
141
|
+
async send(event) {
|
|
142
|
+
if (!config.enabled) {
|
|
143
|
+
return {
|
|
144
|
+
success: false,
|
|
145
|
+
channel: 'telegram',
|
|
146
|
+
error: 'Telegram notifications are disabled',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (!shouldNotify(event, config)) {
|
|
150
|
+
return {
|
|
151
|
+
success: true,
|
|
152
|
+
channel: 'telegram',
|
|
153
|
+
response: 'Skipped due to filter settings',
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const text = formatTelegramMessage(event, config.parseMode);
|
|
158
|
+
const payload = {
|
|
159
|
+
chat_id: config.chatId,
|
|
160
|
+
text,
|
|
161
|
+
};
|
|
162
|
+
if (config.parseMode) {
|
|
163
|
+
payload.parse_mode = config.parseMode;
|
|
164
|
+
}
|
|
165
|
+
const response = await fetch(`${baseUrl}/sendMessage`, {
|
|
166
|
+
method: 'POST',
|
|
167
|
+
headers: {
|
|
168
|
+
'Content-Type': 'application/json',
|
|
169
|
+
},
|
|
170
|
+
body: JSON.stringify(payload),
|
|
171
|
+
});
|
|
172
|
+
const result = await response.json();
|
|
173
|
+
if (!result.ok) {
|
|
174
|
+
return {
|
|
175
|
+
success: false,
|
|
176
|
+
channel: 'telegram',
|
|
177
|
+
error: `Telegram API error: ${result.description || 'Unknown error'}`,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
success: true,
|
|
182
|
+
channel: 'telegram',
|
|
183
|
+
response: result,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
return {
|
|
188
|
+
success: false,
|
|
189
|
+
channel: 'telegram',
|
|
190
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
async test() {
|
|
195
|
+
if (!config.enabled) {
|
|
196
|
+
return {
|
|
197
|
+
success: false,
|
|
198
|
+
channel: 'telegram',
|
|
199
|
+
error: 'Telegram notifications are disabled',
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const text = formatTestMessage(config.parseMode);
|
|
204
|
+
const payload = {
|
|
205
|
+
chat_id: config.chatId,
|
|
206
|
+
text,
|
|
207
|
+
};
|
|
208
|
+
if (config.parseMode) {
|
|
209
|
+
payload.parse_mode = config.parseMode;
|
|
210
|
+
}
|
|
211
|
+
const response = await fetch(`${baseUrl}/sendMessage`, {
|
|
212
|
+
method: 'POST',
|
|
213
|
+
headers: {
|
|
214
|
+
'Content-Type': 'application/json',
|
|
215
|
+
},
|
|
216
|
+
body: JSON.stringify(payload),
|
|
217
|
+
});
|
|
218
|
+
const result = await response.json();
|
|
219
|
+
if (!result.ok) {
|
|
220
|
+
return {
|
|
221
|
+
success: false,
|
|
222
|
+
channel: 'telegram',
|
|
223
|
+
error: `Telegram API error: ${result.description || 'Unknown error'}`,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
success: true,
|
|
228
|
+
channel: 'telegram',
|
|
229
|
+
response: 'Test message sent successfully',
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
return {
|
|
234
|
+
success: false,
|
|
235
|
+
channel: 'telegram',
|
|
236
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=telegram.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram.js","sourceRoot":"","sources":["../../../src/notifications/telegram.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;GAEG;AACH,MAAM,cAAc,GAA6B;IAC/C,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,IAAI;IACV,MAAM,EAAE,IAAI;IACZ,GAAG,EAAE,IAAI;CACV,CAAC;AAEF;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAAY;IACpC,OAAO,IAAI,CAAC,OAAO,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI;SACR,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,SAAS,yBAAyB,CAAC,KAA2B;IAC5D,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7C,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,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;iBAChE,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification Types
|
|
3
|
+
* Type definitions for the notification system
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Severity levels for security detections
|
|
7
|
+
*/
|
|
8
|
+
export type Severity = 'critical' | 'high' | 'medium' | 'low';
|
|
9
|
+
/**
|
|
10
|
+
* Categories of security threats
|
|
11
|
+
*/
|
|
12
|
+
export type ThreatCategory = 'purchase' | 'website' | 'destructive' | 'secrets' | 'exfiltration';
|
|
13
|
+
/**
|
|
14
|
+
* Supported notification channels
|
|
15
|
+
*/
|
|
16
|
+
export type NotificationChannel = 'slack' | 'discord' | 'telegram';
|
|
17
|
+
/**
|
|
18
|
+
* Security event notification payload
|
|
19
|
+
*/
|
|
20
|
+
export interface SecurityEventPayload {
|
|
21
|
+
/** Unique event ID */
|
|
22
|
+
eventId: string;
|
|
23
|
+
/** Event timestamp */
|
|
24
|
+
timestamp: number;
|
|
25
|
+
/** Threat category */
|
|
26
|
+
category: ThreatCategory;
|
|
27
|
+
/** Severity level */
|
|
28
|
+
severity: Severity;
|
|
29
|
+
/** Tool that triggered the event */
|
|
30
|
+
toolName: string;
|
|
31
|
+
/** Brief description of the threat */
|
|
32
|
+
reason: string;
|
|
33
|
+
/** Action taken */
|
|
34
|
+
action: 'blocked' | 'confirmed' | 'warned' | 'logged';
|
|
35
|
+
/** Session ID */
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
/** Additional metadata */
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Notification result
|
|
42
|
+
*/
|
|
43
|
+
export interface NotificationResult {
|
|
44
|
+
/** Whether the notification was sent successfully */
|
|
45
|
+
success: boolean;
|
|
46
|
+
/** Channel used */
|
|
47
|
+
channel: NotificationChannel;
|
|
48
|
+
/** Error message if failed */
|
|
49
|
+
error?: string;
|
|
50
|
+
/** Response from the notification service */
|
|
51
|
+
response?: unknown;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Base notification configuration
|
|
55
|
+
*/
|
|
56
|
+
export interface BaseNotificationConfig {
|
|
57
|
+
/** Whether this notification channel is enabled */
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
/** Minimum severity to trigger notification */
|
|
60
|
+
minSeverity?: Severity;
|
|
61
|
+
/** Categories to notify for (empty = all) */
|
|
62
|
+
categories?: ThreatCategory[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Slack notification configuration
|
|
66
|
+
*/
|
|
67
|
+
export interface SlackConfig extends BaseNotificationConfig {
|
|
68
|
+
/** Slack webhook URL */
|
|
69
|
+
webhookUrl: string;
|
|
70
|
+
/** Channel to post to (optional, uses webhook default) */
|
|
71
|
+
channel?: string;
|
|
72
|
+
/** Username for the bot */
|
|
73
|
+
username?: string;
|
|
74
|
+
/** Icon emoji for the bot */
|
|
75
|
+
iconEmoji?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Discord notification configuration
|
|
79
|
+
*/
|
|
80
|
+
export interface DiscordConfig extends BaseNotificationConfig {
|
|
81
|
+
/** Discord webhook URL */
|
|
82
|
+
webhookUrl: string;
|
|
83
|
+
/** Username for the bot */
|
|
84
|
+
username?: string;
|
|
85
|
+
/** Avatar URL for the bot */
|
|
86
|
+
avatarUrl?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Telegram notification configuration
|
|
90
|
+
*/
|
|
91
|
+
export interface TelegramConfig extends BaseNotificationConfig {
|
|
92
|
+
/** Telegram bot token */
|
|
93
|
+
botToken: string;
|
|
94
|
+
/** Chat ID to send messages to */
|
|
95
|
+
chatId: string;
|
|
96
|
+
/** Parse mode for messages */
|
|
97
|
+
parseMode?: 'HTML' | 'Markdown' | 'MarkdownV2';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Complete notification configuration
|
|
101
|
+
*/
|
|
102
|
+
export interface NotificationConfig {
|
|
103
|
+
/** Slack configuration */
|
|
104
|
+
slack?: SlackConfig;
|
|
105
|
+
/** Discord configuration */
|
|
106
|
+
discord?: DiscordConfig;
|
|
107
|
+
/** Telegram configuration */
|
|
108
|
+
telegram?: TelegramConfig;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Notification sender interface
|
|
112
|
+
*/
|
|
113
|
+
export interface NotificationSender {
|
|
114
|
+
/** Send a security event notification */
|
|
115
|
+
send(event: SecurityEventPayload): Promise<NotificationResult>;
|
|
116
|
+
/** Test the notification configuration */
|
|
117
|
+
test(): Promise<NotificationResult>;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/notifications/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,SAAS,GAAG,cAAc,CAAC;AAEjG;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,QAAQ,EAAE,cAAc,CAAC;IACzB,qBAAqB;IACrB,QAAQ,EAAE,QAAQ,CAAC;IACnB,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;I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,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,0BAA0B;IAC1B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,IAAI,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/D,0CAA0C;IAC1C,IAAI,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/notifications/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone Proxy Server Module
|
|
3
|
+
* HTTP proxy server for tool call analysis without OpenClaw integration
|
|
4
|
+
*/
|
|
5
|
+
export type { ProxyConfig, ProxyRequest, ProxyResponse, ApprovalActionResponse, StatusResponse, HealthResponse, ErrorResponse, ProxyServer, RequestHandler, ProxyHttpRequest, ProxyHttpResponse, } from './types.js';
|
|
6
|
+
export { toToolCallContext, toProxyResponse, AnalysisMiddleware, ValidationError, createAnalysisMiddleware, } from './middleware.js';
|
|
7
|
+
export { HttpProxyServer, createProxyServer, } from './server.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/proxy/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,aAAa,EACb,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,eAAe,EACf,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone Proxy Server Module
|
|
3
|
+
* HTTP proxy server for tool call analysis without OpenClaw integration
|
|
4
|
+
*/
|
|
5
|
+
// Middleware
|
|
6
|
+
export { toToolCallContext, toProxyResponse, AnalysisMiddleware, ValidationError, createAnalysisMiddleware, } from './middleware.js';
|
|
7
|
+
// Server
|
|
8
|
+
export { HttpProxyServer, createProxyServer, } from './server.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/proxy/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH,aAAa;AACb,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,eAAe,EACf,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy Middleware
|
|
3
|
+
* Request processing middleware that bridges HTTP requests to the detection engine
|
|
4
|
+
*/
|
|
5
|
+
import type { ToolCallContext, AnalysisResult, Analyzer } from '../engine/types.js';
|
|
6
|
+
import type { ApprovalStore } from '../approval/types.js';
|
|
7
|
+
import type { ProxyRequest, ProxyResponse, ApprovalActionResponse, StatusResponse, HealthResponse, ProxyConfig } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Convert ProxyRequest to ToolCallContext for analysis
|
|
10
|
+
*/
|
|
11
|
+
export declare function toToolCallContext(request: ProxyRequest): ToolCallContext;
|
|
12
|
+
/**
|
|
13
|
+
* Convert AnalysisResult to ProxyResponse
|
|
14
|
+
*/
|
|
15
|
+
export declare function toProxyResponse(result: AnalysisResult, pendingApprovalId?: string, approvalTimeoutSeconds?: number): ProxyResponse;
|
|
16
|
+
/**
|
|
17
|
+
* Middleware for processing analysis requests
|
|
18
|
+
*/
|
|
19
|
+
export declare class AnalysisMiddleware {
|
|
20
|
+
private readonly analyzer;
|
|
21
|
+
private readonly approvalStore;
|
|
22
|
+
private readonly approvalTimeoutSeconds;
|
|
23
|
+
constructor(analyzer: Analyzer, approvalStore: ApprovalStore, approvalTimeoutSeconds?: number);
|
|
24
|
+
/**
|
|
25
|
+
* Process an analysis request
|
|
26
|
+
*/
|
|
27
|
+
analyze(request: Record<string, unknown>): Promise<ProxyResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Approve a pending request
|
|
30
|
+
*/
|
|
31
|
+
approve(id: string, approvedBy?: string): ApprovalActionResponse;
|
|
32
|
+
/**
|
|
33
|
+
* Deny a pending request
|
|
34
|
+
*/
|
|
35
|
+
deny(id: string): ApprovalActionResponse;
|
|
36
|
+
/**
|
|
37
|
+
* Get server status
|
|
38
|
+
*/
|
|
39
|
+
getStatus(config: ProxyConfig, actualPort?: number): StatusResponse;
|
|
40
|
+
/**
|
|
41
|
+
* Get health status
|
|
42
|
+
*/
|
|
43
|
+
getHealth(): HealthResponse;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Custom error for validation failures
|
|
47
|
+
*/
|
|
48
|
+
export declare class ValidationError extends Error {
|
|
49
|
+
constructor(message: string);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create an analysis middleware instance
|
|
53
|
+
*/
|
|
54
|
+
export declare function createAnalysisMiddleware(analyzer: Analyzer, approvalStore: ApprovalStore, approvalTimeoutSeconds?: number): AnalysisMiddleware;
|
|
55
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/proxy/middleware.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,KAAK,EACV,aAAa,EAEd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,cAAc,EACd,WAAW,EACZ,MAAM,YAAY,CAAC;AAcpB;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,eAAe,CAYxE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,cAAc,EACtB,iBAAiB,CAAC,EAAE,MAAM,EAC1B,sBAAsB,CAAC,EAAE,MAAM,GAC9B,aAAa,CA4Cf;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;gBAG9C,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,EAC5B,sBAAsB,GAAE,MAAyC;IAOnE;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IA8CvE;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,sBAAsB;IA0BhE;;OAEG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,sBAAsB;IA0BxC;;OAEG;IACH,SA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