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,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook Approval Client
|
|
3
|
+
* Handles approval requests via external webhooks (Slack, Discord, custom APIs, etc.)
|
|
4
|
+
*/
|
|
5
|
+
import type { Detection } from '../engine/types.js';
|
|
6
|
+
import type { ApprovalResult, ApprovalStore, PendingApprovalRecord } from './types.js';
|
|
7
|
+
import type { WebhookApproval } from '../config/schema.js';
|
|
8
|
+
/**
|
|
9
|
+
* Request sent to the webhook endpoint
|
|
10
|
+
*/
|
|
11
|
+
export interface WebhookApprovalRequest {
|
|
12
|
+
/** Unique identifier for this approval request */
|
|
13
|
+
id: string;
|
|
14
|
+
/** The detection that triggered this approval request */
|
|
15
|
+
detection: Detection;
|
|
16
|
+
/** Information about the tool call */
|
|
17
|
+
toolCall: {
|
|
18
|
+
name: string;
|
|
19
|
+
input: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
/** Timestamp when the request was created (ms since epoch) */
|
|
22
|
+
timestamp: number;
|
|
23
|
+
/** Timestamp when the approval expires (ms since epoch) */
|
|
24
|
+
expiresAt: number;
|
|
25
|
+
/** Optional callback URL for async approval */
|
|
26
|
+
callbackUrl?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Response from the webhook endpoint
|
|
30
|
+
*/
|
|
31
|
+
export interface WebhookApprovalResponse {
|
|
32
|
+
/** Whether the action was approved */
|
|
33
|
+
approved: boolean;
|
|
34
|
+
/** Who approved/denied the action */
|
|
35
|
+
approvedBy?: string;
|
|
36
|
+
/** Reason for the decision */
|
|
37
|
+
reason?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Result of a webhook approval request
|
|
41
|
+
*/
|
|
42
|
+
export interface WebhookApprovalResult {
|
|
43
|
+
/** Whether the webhook request was successful */
|
|
44
|
+
success: boolean;
|
|
45
|
+
/** Response from the webhook (if successful) */
|
|
46
|
+
response?: WebhookApprovalResponse;
|
|
47
|
+
/** Error message (if unsuccessful) */
|
|
48
|
+
error?: string;
|
|
49
|
+
/** True if waiting for async callback (202 response) */
|
|
50
|
+
waitingForCallback: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Interface for the webhook approval client
|
|
54
|
+
*/
|
|
55
|
+
export interface WebhookApprovalClient {
|
|
56
|
+
/** Send approval request to external system */
|
|
57
|
+
requestApproval(request: WebhookApprovalRequest): Promise<WebhookApprovalResult>;
|
|
58
|
+
/** Handle callback from external system */
|
|
59
|
+
handleCallback(id: string, response: WebhookApprovalResponse): ApprovalResult;
|
|
60
|
+
/** Check if webhook approval is enabled */
|
|
61
|
+
isEnabled(): boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* HTTP client interface for making requests (allows mocking in tests)
|
|
65
|
+
*/
|
|
66
|
+
export interface HttpClient {
|
|
67
|
+
/** Make a POST request */
|
|
68
|
+
post(url: string, body: unknown, options: {
|
|
69
|
+
headers?: Record<string, string>;
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
}): Promise<HttpResponse>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* HTTP response interface
|
|
75
|
+
*/
|
|
76
|
+
export interface HttpResponse {
|
|
77
|
+
/** HTTP status code */
|
|
78
|
+
status: number;
|
|
79
|
+
/** Response body (parsed JSON) */
|
|
80
|
+
body: unknown;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Configuration for the webhook approval client
|
|
84
|
+
*/
|
|
85
|
+
export interface WebhookApprovalClientConfig {
|
|
86
|
+
/** Webhook configuration from clawsec config */
|
|
87
|
+
webhookConfig: WebhookApproval;
|
|
88
|
+
/** Optional custom HTTP client (for testing) */
|
|
89
|
+
httpClient?: HttpClient;
|
|
90
|
+
/** Approval store to use */
|
|
91
|
+
store?: ApprovalStore;
|
|
92
|
+
/** Optional callback URL template (use {id} as placeholder) */
|
|
93
|
+
callbackUrlTemplate?: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Default HTTP client implementation using fetch
|
|
97
|
+
*/
|
|
98
|
+
export declare class FetchHttpClient implements HttpClient {
|
|
99
|
+
post(url: string, body: unknown, options: {
|
|
100
|
+
headers?: Record<string, string>;
|
|
101
|
+
timeoutMs?: number;
|
|
102
|
+
}): Promise<HttpResponse>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Default webhook approval client implementation
|
|
106
|
+
*/
|
|
107
|
+
export declare class DefaultWebhookApprovalClient implements WebhookApprovalClient {
|
|
108
|
+
private config;
|
|
109
|
+
private httpClient;
|
|
110
|
+
private store;
|
|
111
|
+
private callbackUrlTemplate?;
|
|
112
|
+
constructor(config: WebhookApprovalClientConfig);
|
|
113
|
+
/**
|
|
114
|
+
* Check if webhook approval is enabled
|
|
115
|
+
*/
|
|
116
|
+
isEnabled(): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Send approval request to external system
|
|
119
|
+
*/
|
|
120
|
+
requestApproval(request: WebhookApprovalRequest): Promise<WebhookApprovalResult>;
|
|
121
|
+
/**
|
|
122
|
+
* Handle callback from external system
|
|
123
|
+
*/
|
|
124
|
+
handleCallback(id: string, response: WebhookApprovalResponse): ApprovalResult;
|
|
125
|
+
/**
|
|
126
|
+
* Handle HTTP response
|
|
127
|
+
*/
|
|
128
|
+
private handleResponse;
|
|
129
|
+
/**
|
|
130
|
+
* Handle HTTP errors
|
|
131
|
+
*/
|
|
132
|
+
private handleError;
|
|
133
|
+
/**
|
|
134
|
+
* Validate that the response is a valid approval response
|
|
135
|
+
*/
|
|
136
|
+
private isValidApprovalResponse;
|
|
137
|
+
/**
|
|
138
|
+
* Extract error message from response body
|
|
139
|
+
*/
|
|
140
|
+
private extractErrorMessage;
|
|
141
|
+
/**
|
|
142
|
+
* Format approval message
|
|
143
|
+
*/
|
|
144
|
+
private formatApprovalMessage;
|
|
145
|
+
/**
|
|
146
|
+
* Format denial message
|
|
147
|
+
*/
|
|
148
|
+
private formatDenialMessage;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Create a webhook approval client with the given configuration
|
|
152
|
+
*/
|
|
153
|
+
export declare function createWebhookApprovalClient(config: WebhookApprovalClientConfig): DefaultWebhookApprovalClient;
|
|
154
|
+
/**
|
|
155
|
+
* Get the default webhook approval client singleton
|
|
156
|
+
*/
|
|
157
|
+
export declare function getDefaultWebhookApprovalClient(): DefaultWebhookApprovalClient;
|
|
158
|
+
/**
|
|
159
|
+
* Set the default webhook approval client configuration
|
|
160
|
+
*/
|
|
161
|
+
export declare function configureDefaultWebhookApprovalClient(config: WebhookApprovalClientConfig): DefaultWebhookApprovalClient;
|
|
162
|
+
/**
|
|
163
|
+
* Reset the default client (mainly for testing)
|
|
164
|
+
*/
|
|
165
|
+
export declare function resetDefaultWebhookApprovalClient(): void;
|
|
166
|
+
/**
|
|
167
|
+
* Create a webhook approval request from a pending approval record
|
|
168
|
+
*/
|
|
169
|
+
export declare function createWebhookRequest(record: PendingApprovalRecord, callbackUrl?: string): WebhookApprovalRequest;
|
|
170
|
+
//# sourceMappingURL=webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../src/approval/webhook.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM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CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAqCtF;;OAEG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,uBAAuB,GAAG,cAAc;IA2E7E;;OAEG;IACH,OAAO,CAAC,cAAc;IAyDtB;;OAEG;IACH,OAAO,CAAC,WAAW;IAkCnB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAS/B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAsB3B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAQ7B;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAO5B;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,2BAA2B,GAClC,4BAA4B,CAE9B;AAiBD;;GAEG;AACH,wBAAgB,+BAA+B,IAAI,4BAA4B,CAO9E;AAED;;GAEG;AACH,wBAAgB,qCAAqC,CACnD,MAAM,EAAE,2BAA2B,GAClC,4BAA4B,CAG9B;AAED;;GAEG;AACH,wBAAgB,iCAAiC,IAAI,IAAI,CAExD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,qBAAqB,EAC7B,WAAW,CAAC,EAAE,MAAM,GACnB,sBAAsB,CAYxB"}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook Approval Client
|
|
3
|
+
* Handles approval requests via external webhooks (Slack, Discord, custom APIs, etc.)
|
|
4
|
+
*/
|
|
5
|
+
import { getDefaultApprovalStore } from './store.js';
|
|
6
|
+
/**
|
|
7
|
+
* Default HTTP client implementation using fetch
|
|
8
|
+
*/
|
|
9
|
+
export class FetchHttpClient {
|
|
10
|
+
async post(url, body, options) {
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const timeoutId = options.timeoutMs
|
|
13
|
+
? setTimeout(() => controller.abort(), options.timeoutMs)
|
|
14
|
+
: undefined;
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch(url, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
...options.headers,
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify(body),
|
|
23
|
+
signal: controller.signal,
|
|
24
|
+
});
|
|
25
|
+
let responseBody;
|
|
26
|
+
const contentType = response.headers.get('content-type');
|
|
27
|
+
if (contentType && contentType.includes('application/json')) {
|
|
28
|
+
responseBody = await response.json();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
responseBody = await response.text();
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
status: response.status,
|
|
35
|
+
body: responseBody,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (timeoutId) {
|
|
40
|
+
clearTimeout(timeoutId);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Default webhook approval client implementation
|
|
47
|
+
*/
|
|
48
|
+
export class DefaultWebhookApprovalClient {
|
|
49
|
+
config;
|
|
50
|
+
httpClient;
|
|
51
|
+
store;
|
|
52
|
+
callbackUrlTemplate;
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.config = config.webhookConfig;
|
|
55
|
+
this.httpClient = config.httpClient ?? new FetchHttpClient();
|
|
56
|
+
this.store = config.store ?? getDefaultApprovalStore();
|
|
57
|
+
this.callbackUrlTemplate = config.callbackUrlTemplate;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if webhook approval is enabled
|
|
61
|
+
*/
|
|
62
|
+
isEnabled() {
|
|
63
|
+
return this.config.enabled && !!this.config.url;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Send approval request to external system
|
|
67
|
+
*/
|
|
68
|
+
async requestApproval(request) {
|
|
69
|
+
// Check if enabled
|
|
70
|
+
if (!this.isEnabled()) {
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
error: 'Webhook approval is not enabled or URL is not configured',
|
|
74
|
+
waitingForCallback: false,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// Build callback URL if template is provided
|
|
78
|
+
const callbackUrl = this.callbackUrlTemplate
|
|
79
|
+
? this.callbackUrlTemplate.replace('{id}', request.id)
|
|
80
|
+
: request.callbackUrl;
|
|
81
|
+
// Build the request payload
|
|
82
|
+
const payload = {
|
|
83
|
+
...request,
|
|
84
|
+
callbackUrl,
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
const response = await this.httpClient.post(this.config.url, payload, {
|
|
88
|
+
headers: this.config.headers ?? {},
|
|
89
|
+
timeoutMs: this.config.timeout * 1000,
|
|
90
|
+
});
|
|
91
|
+
return this.handleResponse(response);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return this.handleError(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Handle callback from external system
|
|
99
|
+
*/
|
|
100
|
+
handleCallback(id, response) {
|
|
101
|
+
// Validate ID
|
|
102
|
+
if (!id || typeof id !== 'string' || id.trim() === '') {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
message: 'Invalid approval ID: ID cannot be empty',
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const trimmedId = id.trim();
|
|
109
|
+
// Get the record
|
|
110
|
+
const record = this.store.get(trimmedId);
|
|
111
|
+
if (!record) {
|
|
112
|
+
return {
|
|
113
|
+
success: false,
|
|
114
|
+
message: `Approval not found: No pending approval with ID "${trimmedId}"`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Check if expired
|
|
118
|
+
if (record.status === 'expired') {
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
message: `Approval expired: The approval "${trimmedId}" has expired`,
|
|
122
|
+
record,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// Check if already processed
|
|
126
|
+
if (record.status !== 'pending') {
|
|
127
|
+
return {
|
|
128
|
+
success: false,
|
|
129
|
+
message: `Approval already ${record.status}: The approval "${trimmedId}" was already ${record.status}`,
|
|
130
|
+
record,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Process the response
|
|
134
|
+
if (response.approved) {
|
|
135
|
+
const success = this.store.approve(trimmedId, response.approvedBy ?? 'webhook');
|
|
136
|
+
if (!success) {
|
|
137
|
+
return {
|
|
138
|
+
success: false,
|
|
139
|
+
message: `Failed to approve: Unable to approve "${trimmedId}"`,
|
|
140
|
+
record: this.store.get(trimmedId),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const approvedRecord = this.store.get(trimmedId);
|
|
144
|
+
return {
|
|
145
|
+
success: true,
|
|
146
|
+
message: this.formatApprovalMessage(approvedRecord, response),
|
|
147
|
+
record: approvedRecord,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const success = this.store.deny(trimmedId);
|
|
152
|
+
if (!success) {
|
|
153
|
+
return {
|
|
154
|
+
success: false,
|
|
155
|
+
message: `Failed to deny: Unable to deny "${trimmedId}"`,
|
|
156
|
+
record: this.store.get(trimmedId),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const deniedRecord = this.store.get(trimmedId);
|
|
160
|
+
return {
|
|
161
|
+
success: true,
|
|
162
|
+
message: this.formatDenialMessage(deniedRecord, response),
|
|
163
|
+
record: deniedRecord,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Handle HTTP response
|
|
169
|
+
*/
|
|
170
|
+
handleResponse(response) {
|
|
171
|
+
// Handle 202 Accepted (async approval)
|
|
172
|
+
if (response.status === 202) {
|
|
173
|
+
return {
|
|
174
|
+
success: true,
|
|
175
|
+
waitingForCallback: true,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
// Handle success (200)
|
|
179
|
+
if (response.status === 200) {
|
|
180
|
+
const body = response.body;
|
|
181
|
+
// Validate response format
|
|
182
|
+
if (!this.isValidApprovalResponse(body)) {
|
|
183
|
+
return {
|
|
184
|
+
success: false,
|
|
185
|
+
error: 'Invalid response format: expected { approved: boolean }',
|
|
186
|
+
waitingForCallback: false,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
success: true,
|
|
191
|
+
response: body,
|
|
192
|
+
waitingForCallback: false,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// Handle client errors (4xx)
|
|
196
|
+
if (response.status >= 400 && response.status < 500) {
|
|
197
|
+
const errorMessage = this.extractErrorMessage(response.body);
|
|
198
|
+
return {
|
|
199
|
+
success: false,
|
|
200
|
+
error: `Client error (${response.status}): ${errorMessage}`,
|
|
201
|
+
waitingForCallback: false,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
// Handle server errors (5xx)
|
|
205
|
+
if (response.status >= 500) {
|
|
206
|
+
const errorMessage = this.extractErrorMessage(response.body);
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
error: `Server error (${response.status}): ${errorMessage}`,
|
|
210
|
+
waitingForCallback: false,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
// Handle other status codes
|
|
214
|
+
return {
|
|
215
|
+
success: false,
|
|
216
|
+
error: `Unexpected status code: ${response.status}`,
|
|
217
|
+
waitingForCallback: false,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Handle HTTP errors
|
|
222
|
+
*/
|
|
223
|
+
handleError(error) {
|
|
224
|
+
// Handle timeout (AbortError)
|
|
225
|
+
if (error instanceof Error) {
|
|
226
|
+
if (error.name === 'AbortError') {
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
error: `Request timeout: Webhook did not respond within ${this.config.timeout} seconds`,
|
|
230
|
+
waitingForCallback: false,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
// Handle network errors
|
|
234
|
+
if (error.message.includes('fetch') || error.message.includes('network')) {
|
|
235
|
+
return {
|
|
236
|
+
success: false,
|
|
237
|
+
error: `Network error: ${error.message}`,
|
|
238
|
+
waitingForCallback: false,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
error: `Request failed: ${error.message}`,
|
|
244
|
+
waitingForCallback: false,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
success: false,
|
|
249
|
+
error: 'Unknown error occurred while making webhook request',
|
|
250
|
+
waitingForCallback: false,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Validate that the response is a valid approval response
|
|
255
|
+
*/
|
|
256
|
+
isValidApprovalResponse(body) {
|
|
257
|
+
if (!body || typeof body !== 'object') {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
const response = body;
|
|
261
|
+
return typeof response.approved === 'boolean';
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Extract error message from response body
|
|
265
|
+
*/
|
|
266
|
+
extractErrorMessage(body) {
|
|
267
|
+
if (!body) {
|
|
268
|
+
return 'No error details provided';
|
|
269
|
+
}
|
|
270
|
+
if (typeof body === 'string') {
|
|
271
|
+
return body;
|
|
272
|
+
}
|
|
273
|
+
if (typeof body === 'object') {
|
|
274
|
+
const obj = body;
|
|
275
|
+
if (typeof obj.error === 'string') {
|
|
276
|
+
return obj.error;
|
|
277
|
+
}
|
|
278
|
+
if (typeof obj.message === 'string') {
|
|
279
|
+
return obj.message;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return 'Unknown error';
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Format approval message
|
|
286
|
+
*/
|
|
287
|
+
formatApprovalMessage(record, response) {
|
|
288
|
+
const toolName = record.toolCall.toolName;
|
|
289
|
+
const approver = response.approvedBy ? ` by ${response.approvedBy}` : ' via webhook';
|
|
290
|
+
const reason = response.reason ? ` (${response.reason})` : '';
|
|
291
|
+
return `Approved${approver}: The action using tool "${toolName}" has been approved${reason}`;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Format denial message
|
|
295
|
+
*/
|
|
296
|
+
formatDenialMessage(record, response) {
|
|
297
|
+
const toolName = record.toolCall.toolName;
|
|
298
|
+
const denier = response.approvedBy ? ` by ${response.approvedBy}` : ' via webhook';
|
|
299
|
+
const reason = response.reason ? ` (${response.reason})` : '';
|
|
300
|
+
return `Denied${denier}: The action using tool "${toolName}" has been denied${reason}`;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Create a webhook approval client with the given configuration
|
|
305
|
+
*/
|
|
306
|
+
export function createWebhookApprovalClient(config) {
|
|
307
|
+
return new DefaultWebhookApprovalClient(config);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Default webhook config (disabled)
|
|
311
|
+
*/
|
|
312
|
+
const DEFAULT_WEBHOOK_CONFIG = {
|
|
313
|
+
enabled: false,
|
|
314
|
+
url: undefined,
|
|
315
|
+
timeout: 30,
|
|
316
|
+
headers: {},
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Default singleton client instance
|
|
320
|
+
*/
|
|
321
|
+
let defaultClient = null;
|
|
322
|
+
/**
|
|
323
|
+
* Get the default webhook approval client singleton
|
|
324
|
+
*/
|
|
325
|
+
export function getDefaultWebhookApprovalClient() {
|
|
326
|
+
if (!defaultClient) {
|
|
327
|
+
defaultClient = createWebhookApprovalClient({
|
|
328
|
+
webhookConfig: DEFAULT_WEBHOOK_CONFIG,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return defaultClient;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Set the default webhook approval client configuration
|
|
335
|
+
*/
|
|
336
|
+
export function configureDefaultWebhookApprovalClient(config) {
|
|
337
|
+
defaultClient = createWebhookApprovalClient(config);
|
|
338
|
+
return defaultClient;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Reset the default client (mainly for testing)
|
|
342
|
+
*/
|
|
343
|
+
export function resetDefaultWebhookApprovalClient() {
|
|
344
|
+
defaultClient = null;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Create a webhook approval request from a pending approval record
|
|
348
|
+
*/
|
|
349
|
+
export function createWebhookRequest(record, callbackUrl) {
|
|
350
|
+
return {
|
|
351
|
+
id: record.id,
|
|
352
|
+
detection: record.detection,
|
|
353
|
+
toolCall: {
|
|
354
|
+
name: record.toolCall.toolName,
|
|
355
|
+
input: record.toolCall.toolInput,
|
|
356
|
+
},
|
|
357
|
+
timestamp: record.createdAt,
|
|
358
|
+
expiresAt: record.expiresAt,
|
|
359
|
+
callbackUrl,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../../src/approval/webhook.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAiGrD;;GAEG;AACH,MAAM,OAAO,eAAe;IAC1B,KAAK,CAAC,IAAI,CACR,GAAW,EACX,IAAa,EACb,OAAiE;QAEjE,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS;YACjC,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,SAAS,CAAC;YACzD,CAAC,CAAC,SAAS,CAAC;QAEd,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAChC,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,GAAG,OAAO,CAAC,OAA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GAAG,2BAA2B,CAAC;YAC1C,aAAa,EAAE,sBAAsB;SACtC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qCAAqC,CACnD,MAAmC;IAEnC,aAAa,GAAG,2BAA2B,CAAC,MAAM,CAAC,CAAC;IACpD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iCAAiC;IAC/C,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAA6B,EAC7B,WAAoB;IAEpB,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ;YAC9B,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,SAAS;SACjC;QACD,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Command
|
|
3
|
+
* View and manage the audit log of detections
|
|
4
|
+
*/
|
|
5
|
+
import type { ThreatCategory } from '../../engine/index.js';
|
|
6
|
+
import type { Severity } from '../../config/index.js';
|
|
7
|
+
import type { AuditEntry, AuditOptions, AuditResult } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Add an entry to the audit log
|
|
10
|
+
*
|
|
11
|
+
* @param entry - The audit entry to add
|
|
12
|
+
*/
|
|
13
|
+
export declare function addAuditEntry(entry: Omit<AuditEntry, 'timestamp'>): void;
|
|
14
|
+
/**
|
|
15
|
+
* Clear all audit log entries
|
|
16
|
+
* Primarily used for testing
|
|
17
|
+
*/
|
|
18
|
+
export declare function clearAuditLog(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get the raw audit log (for testing)
|
|
21
|
+
*/
|
|
22
|
+
export declare function getAuditLog(): ReadonlyArray<AuditEntry>;
|
|
23
|
+
/**
|
|
24
|
+
* Execute the audit command
|
|
25
|
+
*
|
|
26
|
+
* @param options - Audit options for filtering and limiting results
|
|
27
|
+
* @returns Audit result with filtered entries
|
|
28
|
+
*/
|
|
29
|
+
export declare function auditCommand(options?: AuditOptions): Promise<AuditResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Format audit result for console output
|
|
32
|
+
*
|
|
33
|
+
* @param result - Audit result to format
|
|
34
|
+
* @param options - The options used for the query
|
|
35
|
+
* @returns Formatted string for display
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatAuditResult(result: AuditResult, options?: AuditOptions): string;
|
|
38
|
+
/**
|
|
39
|
+
* Helper function to create an audit entry from detection data
|
|
40
|
+
* This is used by the action handlers to log detections
|
|
41
|
+
*/
|
|
42
|
+
export declare function createAuditEntry(toolName: string, category: ThreatCategory, severity: Severity, action: string, reason: string, metadata?: Record<string, unknown>): void;
|
|
43
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/audit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQxE;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,IAAI,CAKxE;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,aAAa,CAAC,UAAU,CAAC,CAEvD;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAmBnF;AAuBD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAuBzF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,IAAI,CASN"}
|