airlock-bot 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -33
- package/airlock.service +1 -0
- package/dist/airlock/context.d.ts.map +1 -1
- package/dist/airlock/context.js +5 -3
- package/dist/airlock/context.js.map +1 -1
- package/dist/airlock/tools.d.ts +15 -3
- package/dist/airlock/tools.d.ts.map +1 -1
- package/dist/airlock/tools.js +29 -1
- package/dist/airlock/tools.js.map +1 -1
- package/dist/allowlist/engine.d.ts +3 -0
- package/dist/allowlist/engine.d.ts.map +1 -1
- package/dist/allowlist/engine.js +46 -2
- package/dist/allowlist/engine.js.map +1 -1
- package/dist/audit/db.d.ts +22 -1
- package/dist/audit/db.d.ts.map +1 -1
- package/dist/audit/db.js +77 -10
- package/dist/audit/db.js.map +1 -1
- package/dist/audit/logger.d.ts +7 -2
- package/dist/audit/logger.d.ts.map +1 -1
- package/dist/audit/logger.js +18 -3
- package/dist/audit/logger.js.map +1 -1
- package/dist/audit/redactor.d.ts.map +1 -1
- package/dist/audit/redactor.js +6 -6
- package/dist/audit/redactor.js.map +1 -1
- package/dist/backend/airlock-adapter.d.ts +20 -2
- package/dist/backend/airlock-adapter.d.ts.map +1 -1
- package/dist/backend/airlock-adapter.js +443 -10
- package/dist/backend/airlock-adapter.js.map +1 -1
- package/dist/backend/cli/adapter.d.ts +4 -2
- package/dist/backend/cli/adapter.d.ts.map +1 -1
- package/dist/backend/cli/adapter.js +36 -11
- package/dist/backend/cli/adapter.js.map +1 -1
- package/dist/backend/cli/builder.d.ts +1 -1
- package/dist/backend/cli/builder.d.ts.map +1 -1
- package/dist/backend/cli/builder.js +28 -12
- package/dist/backend/cli/builder.js.map +1 -1
- package/dist/backend/exec-adapter.d.ts +1 -1
- package/dist/backend/exec-adapter.d.ts.map +1 -1
- package/dist/backend/exec-adapter.js +1 -5
- package/dist/backend/exec-adapter.js.map +1 -1
- package/dist/backend/factory.d.ts +2 -0
- package/dist/backend/factory.d.ts.map +1 -1
- package/dist/backend/factory.js +19 -5
- package/dist/backend/factory.js.map +1 -1
- package/dist/backend/http-adapter.d.ts +6 -3
- package/dist/backend/http-adapter.d.ts.map +1 -1
- package/dist/backend/http-adapter.js +24 -10
- package/dist/backend/http-adapter.js.map +1 -1
- package/dist/backend/mcp-adapter.d.ts +7 -2
- package/dist/backend/mcp-adapter.d.ts.map +1 -1
- package/dist/backend/mcp-adapter.js +74 -16
- package/dist/backend/mcp-adapter.js.map +1 -1
- package/dist/backend/openapi/adapter.d.ts +8 -2
- package/dist/backend/openapi/adapter.d.ts.map +1 -1
- package/dist/backend/openapi/adapter.js +196 -17
- package/dist/backend/openapi/adapter.js.map +1 -1
- package/dist/backend/openapi/parser.d.ts +15 -1
- package/dist/backend/openapi/parser.d.ts.map +1 -1
- package/dist/backend/openapi/parser.js +153 -11
- package/dist/backend/openapi/parser.js.map +1 -1
- package/dist/backend/types.d.ts +12 -1
- package/dist/backend/types.d.ts.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +334 -50
- package/dist/config/loader.js.map +1 -1
- package/dist/config/mutator.d.ts.map +1 -1
- package/dist/config/mutator.js +13 -3
- package/dist/config/mutator.js.map +1 -1
- package/dist/config/profiles.d.ts +2 -1
- package/dist/config/profiles.d.ts.map +1 -1
- package/dist/config/profiles.js +50 -2
- package/dist/config/profiles.js.map +1 -1
- package/dist/config/provider-credentials.d.ts +4 -0
- package/dist/config/provider-credentials.d.ts.map +1 -0
- package/dist/config/provider-credentials.js +48 -0
- package/dist/config/provider-credentials.js.map +1 -0
- package/dist/config/schema.d.ts +2829 -8642
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +337 -122
- package/dist/config/schema.js.map +1 -1
- package/dist/config/watcher.d.ts.map +1 -1
- package/dist/config/watcher.js +3 -0
- package/dist/config/watcher.js.map +1 -1
- package/dist/config/yaml-merge.d.ts +9 -0
- package/dist/config/yaml-merge.d.ts.map +1 -0
- package/dist/config/yaml-merge.js +54 -0
- package/dist/config/yaml-merge.js.map +1 -0
- package/dist/configure-agent/cli.d.ts +26 -0
- package/dist/configure-agent/cli.d.ts.map +1 -1
- package/dist/configure-agent/cli.js +70 -35
- package/dist/configure-agent/cli.js.map +1 -1
- package/dist/configure-cli/cli.d.ts +6 -0
- package/dist/configure-cli/cli.d.ts.map +1 -1
- package/dist/configure-cli/cli.js +45 -14
- package/dist/configure-cli/cli.js.map +1 -1
- package/dist/configure-web/assistant.d.ts +49 -0
- package/dist/configure-web/assistant.d.ts.map +1 -0
- package/dist/configure-web/assistant.js +312 -0
- package/dist/configure-web/assistant.js.map +1 -0
- package/dist/configure-web/changes.d.ts +214 -0
- package/dist/configure-web/changes.d.ts.map +1 -0
- package/dist/configure-web/changes.js +317 -0
- package/dist/configure-web/changes.js.map +1 -0
- package/dist/configure-web/cli.d.ts +33 -11
- package/dist/configure-web/cli.d.ts.map +1 -1
- package/dist/configure-web/cli.js +704 -151
- package/dist/configure-web/cli.js.map +1 -1
- package/dist/discover/cli.js +2 -2
- package/dist/discover/cli.js.map +1 -1
- package/dist/discover/index.d.ts.map +1 -1
- package/dist/discover/index.js +16 -22
- package/dist/discover/index.js.map +1 -1
- package/dist/discover/openapi.d.ts.map +1 -1
- package/dist/discover/openapi.js +2 -0
- package/dist/discover/openapi.js.map +1 -1
- package/dist/discover/strategies/completion.d.ts.map +1 -1
- package/dist/discover/strategies/completion.js +19 -2
- package/dist/discover/strategies/completion.js.map +1 -1
- package/dist/discover/strategies/fig.d.ts +10 -1
- package/dist/discover/strategies/fig.d.ts.map +1 -1
- package/dist/discover/strategies/fig.js +24 -10
- package/dist/discover/strategies/fig.js.map +1 -1
- package/dist/discover/strategies/help-parser.d.ts.map +1 -1
- package/dist/discover/strategies/help-parser.js +9 -6
- package/dist/discover/strategies/help-parser.js.map +1 -1
- package/dist/events/payload-inspector.d.ts +25 -0
- package/dist/events/payload-inspector.d.ts.map +1 -0
- package/dist/events/payload-inspector.js +210 -0
- package/dist/events/payload-inspector.js.map +1 -0
- package/dist/events/protocol.d.ts +227 -0
- package/dist/events/protocol.d.ts.map +1 -0
- package/dist/events/protocol.js +422 -0
- package/dist/events/protocol.js.map +1 -0
- package/dist/events/registry.d.ts +57 -0
- package/dist/events/registry.d.ts.map +1 -0
- package/dist/events/registry.js +179 -0
- package/dist/events/registry.js.map +1 -0
- package/dist/events/schema-validator.d.ts +13 -0
- package/dist/events/schema-validator.d.ts.map +1 -0
- package/dist/events/schema-validator.js +54 -0
- package/dist/events/schema-validator.js.map +1 -0
- package/dist/events/service.d.ts +97 -0
- package/dist/events/service.d.ts.map +1 -0
- package/dist/events/service.js +918 -0
- package/dist/events/service.js.map +1 -0
- package/dist/events/stream-manager.d.ts +58 -0
- package/dist/events/stream-manager.d.ts.map +1 -0
- package/dist/events/stream-manager.js +94 -0
- package/dist/events/stream-manager.js.map +1 -0
- package/dist/events/upstream-client.d.ts +88 -0
- package/dist/events/upstream-client.d.ts.map +1 -0
- package/dist/events/upstream-client.js +437 -0
- package/dist/events/upstream-client.js.map +1 -0
- package/dist/gateway.d.ts +14 -0
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +208 -33
- package/dist/gateway.js.map +1 -1
- package/dist/hitl/api.d.ts.map +1 -1
- package/dist/hitl/api.js +9 -2
- package/dist/hitl/api.js.map +1 -1
- package/dist/hitl/approval-dashboard.d.ts +5 -0
- package/dist/hitl/approval-dashboard.d.ts.map +1 -1
- package/dist/hitl/approval-dashboard.js +107 -20
- package/dist/hitl/approval-dashboard.js.map +1 -1
- package/dist/hitl/approval-stream.d.ts +2 -0
- package/dist/hitl/approval-stream.d.ts.map +1 -1
- package/dist/hitl/approval-stream.js +11 -0
- package/dist/hitl/approval-stream.js.map +1 -1
- package/dist/hitl/engine.d.ts +154 -4
- package/dist/hitl/engine.d.ts.map +1 -1
- package/dist/hitl/engine.js +616 -102
- package/dist/hitl/engine.js.map +1 -1
- package/dist/hitl/formatter.d.ts.map +1 -1
- package/dist/hitl/formatter.js +60 -10
- package/dist/hitl/formatter.js.map +1 -1
- package/dist/hitl/grant-api.d.ts +32 -0
- package/dist/hitl/grant-api.d.ts.map +1 -0
- package/dist/hitl/grant-api.js +249 -0
- package/dist/hitl/grant-api.js.map +1 -0
- package/dist/hitl/grants.d.ts +153 -0
- package/dist/hitl/grants.d.ts.map +1 -0
- package/dist/hitl/grants.js +273 -0
- package/dist/hitl/grants.js.map +1 -0
- package/dist/hitl/parser.d.ts +9 -0
- package/dist/hitl/parser.d.ts.map +1 -1
- package/dist/hitl/parser.js +60 -4
- package/dist/hitl/parser.js.map +1 -1
- package/dist/hitl/provider-factory.js +6 -1
- package/dist/hitl/provider-factory.js.map +1 -1
- package/dist/hitl/providers/composite.d.ts +0 -1
- package/dist/hitl/providers/composite.d.ts.map +1 -1
- package/dist/hitl/providers/composite.js +0 -3
- package/dist/hitl/providers/composite.js.map +1 -1
- package/dist/hitl/providers/dashboard.d.ts +1 -0
- package/dist/hitl/providers/dashboard.d.ts.map +1 -1
- package/dist/hitl/providers/dashboard.js +9 -2
- package/dist/hitl/providers/dashboard.js.map +1 -1
- package/dist/hitl/providers/ios.d.ts +0 -1
- package/dist/hitl/providers/ios.d.ts.map +1 -1
- package/dist/hitl/providers/ios.js +94 -39
- package/dist/hitl/providers/ios.js.map +1 -1
- package/dist/hitl/providers/macos.d.ts +2 -0
- package/dist/hitl/providers/macos.d.ts.map +1 -1
- package/dist/hitl/providers/macos.js +90 -3
- package/dist/hitl/providers/macos.js.map +1 -1
- package/dist/hitl/providers/openclaw.js +3 -9
- package/dist/hitl/providers/openclaw.js.map +1 -1
- package/dist/hitl/providers/stdio.js +3 -9
- package/dist/hitl/providers/stdio.js.map +1 -1
- package/dist/hitl/providers/telegram.d.ts.map +1 -1
- package/dist/hitl/providers/telegram.js +6 -10
- package/dist/hitl/providers/telegram.js.map +1 -1
- package/dist/hitl/providers/tui.d.ts +1 -1
- package/dist/hitl/providers/tui.d.ts.map +1 -1
- package/dist/hitl/providers/tui.js +91 -31
- package/dist/hitl/providers/tui.js.map +1 -1
- package/dist/hitl/providers/types.d.ts +38 -3
- package/dist/hitl/providers/types.d.ts.map +1 -1
- package/dist/hitl/runtime.d.ts +18 -0
- package/dist/hitl/runtime.d.ts.map +1 -0
- package/dist/hitl/runtime.js +60 -0
- package/dist/hitl/runtime.js.map +1 -0
- package/dist/hook/api.d.ts +6 -1
- package/dist/hook/api.d.ts.map +1 -1
- package/dist/hook/api.js +51 -12
- package/dist/hook/api.js.map +1 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/introspect/cli.d.ts.map +1 -1
- package/dist/introspect/cli.js +5 -2
- package/dist/introspect/cli.js.map +1 -1
- package/dist/mcp-apps/ui.d.ts +69 -0
- package/dist/mcp-apps/ui.d.ts.map +1 -0
- package/dist/mcp-apps/ui.js +143 -0
- package/dist/mcp-apps/ui.js.map +1 -0
- package/dist/middleware/audit-args.d.ts +7 -0
- package/dist/middleware/audit-args.d.ts.map +1 -0
- package/dist/middleware/audit-args.js +23 -0
- package/dist/middleware/audit-args.js.map +1 -0
- package/dist/middleware/chain-builder.d.ts +2 -2
- package/dist/middleware/chain-builder.d.ts.map +1 -1
- package/dist/middleware/chain-builder.js +7 -3
- package/dist/middleware/chain-builder.js.map +1 -1
- package/dist/middleware/core/allowlist.d.ts.map +1 -1
- package/dist/middleware/core/allowlist.js +8 -5
- package/dist/middleware/core/allowlist.js.map +1 -1
- package/dist/middleware/core/arg-policy.d.ts +1 -0
- package/dist/middleware/core/arg-policy.d.ts.map +1 -1
- package/dist/middleware/core/arg-policy.js +34 -37
- package/dist/middleware/core/arg-policy.js.map +1 -1
- package/dist/middleware/core/command-policy.d.ts +4 -1
- package/dist/middleware/core/command-policy.d.ts.map +1 -1
- package/dist/middleware/core/command-policy.js +50 -4
- package/dist/middleware/core/command-policy.js.map +1 -1
- package/dist/middleware/core/exec-policy.d.ts.map +1 -1
- package/dist/middleware/core/exec-policy.js +5 -5
- package/dist/middleware/core/exec-policy.js.map +1 -1
- package/dist/middleware/core/execute.d.ts +5 -1
- package/dist/middleware/core/execute.d.ts.map +1 -1
- package/dist/middleware/core/execute.js +18 -15
- package/dist/middleware/core/execute.js.map +1 -1
- package/dist/middleware/core/hitl-gate.d.ts +4 -1
- package/dist/middleware/core/hitl-gate.d.ts.map +1 -1
- package/dist/middleware/core/hitl-gate.js +153 -45
- package/dist/middleware/core/hitl-gate.js.map +1 -1
- package/dist/middleware/core/rate-limiter.d.ts.map +1 -1
- package/dist/middleware/core/rate-limiter.js +23 -7
- package/dist/middleware/core/rate-limiter.js.map +1 -1
- package/dist/middleware/core/schema-validator.d.ts +3 -0
- package/dist/middleware/core/schema-validator.d.ts.map +1 -1
- package/dist/middleware/core/schema-validator.js +31 -12
- package/dist/middleware/core/schema-validator.js.map +1 -1
- package/dist/middleware/core/upload-policy.d.ts +18 -0
- package/dist/middleware/core/upload-policy.d.ts.map +1 -0
- package/dist/middleware/core/upload-policy.js +98 -0
- package/dist/middleware/core/upload-policy.js.map +1 -0
- package/dist/middleware/detectors/injection-detector.d.ts.map +1 -1
- package/dist/middleware/detectors/injection-detector.js +8 -6
- package/dist/middleware/detectors/injection-detector.js.map +1 -1
- package/dist/middleware/detectors/sensitivity-classifier.d.ts.map +1 -1
- package/dist/middleware/detectors/sensitivity-classifier.js +19 -5
- package/dist/middleware/detectors/sensitivity-classifier.js.map +1 -1
- package/dist/middleware/post/untrusted-envelope.d.ts.map +1 -1
- package/dist/middleware/post/untrusted-envelope.js +4 -1
- package/dist/middleware/post/untrusted-envelope.js.map +1 -1
- package/dist/middleware/response.d.ts +33 -0
- package/dist/middleware/response.d.ts.map +1 -0
- package/dist/middleware/response.js +110 -0
- package/dist/middleware/response.js.map +1 -0
- package/dist/middleware/types.d.ts +13 -0
- package/dist/middleware/types.d.ts.map +1 -1
- package/dist/mobile/api.d.ts.map +1 -1
- package/dist/mobile/api.js +57 -34
- package/dist/mobile/api.js.map +1 -1
- package/dist/mobile/apns.d.ts +39 -2
- package/dist/mobile/apns.d.ts.map +1 -1
- package/dist/mobile/apns.js +84 -83
- package/dist/mobile/apns.js.map +1 -1
- package/dist/pool/client-credentials.d.ts +2 -0
- package/dist/pool/client-credentials.d.ts.map +1 -1
- package/dist/pool/client-credentials.js +18 -3
- package/dist/pool/client-credentials.js.map +1 -1
- package/dist/pool/credential-health.d.ts +2 -2
- package/dist/pool/credential-health.d.ts.map +1 -1
- package/dist/pool/credential-health.js +7 -2
- package/dist/pool/credential-health.js.map +1 -1
- package/dist/pool/http-client.d.ts +105 -16
- package/dist/pool/http-client.d.ts.map +1 -1
- package/dist/pool/http-client.js +712 -116
- package/dist/pool/http-client.js.map +1 -1
- package/dist/pool/oauth-callback-router.d.ts +35 -0
- package/dist/pool/oauth-callback-router.d.ts.map +1 -0
- package/dist/pool/oauth-callback-router.js +84 -0
- package/dist/pool/oauth-callback-router.js.map +1 -0
- package/dist/pool/oauth-cli.d.ts +10 -0
- package/dist/pool/oauth-cli.d.ts.map +1 -0
- package/dist/pool/oauth-cli.js +318 -0
- package/dist/pool/oauth-cli.js.map +1 -0
- package/dist/pool/oauth-lock.d.ts +149 -0
- package/dist/pool/oauth-lock.d.ts.map +1 -0
- package/dist/pool/oauth-lock.js +575 -0
- package/dist/pool/oauth-lock.js.map +1 -0
- package/dist/pool/oauth-provider.d.ts +231 -27
- package/dist/pool/oauth-provider.d.ts.map +1 -1
- package/dist/pool/oauth-provider.js +802 -142
- package/dist/pool/oauth-provider.js.map +1 -1
- package/dist/pool/oauth-refresh.d.ts +94 -0
- package/dist/pool/oauth-refresh.d.ts.map +1 -0
- package/dist/pool/oauth-refresh.js +477 -0
- package/dist/pool/oauth-refresh.js.map +1 -0
- package/dist/pool/oauth-store.d.ts +304 -0
- package/dist/pool/oauth-store.d.ts.map +1 -0
- package/dist/pool/oauth-store.js +684 -0
- package/dist/pool/oauth-store.js.map +1 -0
- package/dist/pool/pool.d.ts +37 -4
- package/dist/pool/pool.d.ts.map +1 -1
- package/dist/pool/pool.js +170 -8
- package/dist/pool/pool.js.map +1 -1
- package/dist/pool/required-mcps.d.ts +7 -0
- package/dist/pool/required-mcps.d.ts.map +1 -1
- package/dist/pool/required-mcps.js +40 -2
- package/dist/pool/required-mcps.js.map +1 -1
- package/dist/pool/sse-client.d.ts +17 -3
- package/dist/pool/sse-client.d.ts.map +1 -1
- package/dist/pool/sse-client.js +59 -6
- package/dist/pool/sse-client.js.map +1 -1
- package/dist/pool/status.d.ts +53 -0
- package/dist/pool/status.d.ts.map +1 -1
- package/dist/pool/stdio-client.d.ts +23 -3
- package/dist/pool/stdio-client.d.ts.map +1 -1
- package/dist/pool/stdio-client.js +84 -6
- package/dist/pool/stdio-client.js.map +1 -1
- package/dist/registry/airlock-policy.d.ts +1 -1
- package/dist/registry/airlock-policy.d.ts.map +1 -1
- package/dist/registry/airlock-policy.js +1 -1
- package/dist/registry/airlock-policy.js.map +1 -1
- package/dist/registry/registry.d.ts +22 -2
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +176 -22
- package/dist/registry/registry.js.map +1 -1
- package/dist/registry/sanitizer.d.ts +5 -0
- package/dist/registry/sanitizer.d.ts.map +1 -1
- package/dist/registry/sanitizer.js +17 -13
- package/dist/registry/sanitizer.js.map +1 -1
- package/dist/security/request.d.ts +19 -0
- package/dist/security/request.d.ts.map +1 -1
- package/dist/security/request.js +35 -1
- package/dist/security/request.js.map +1 -1
- package/dist/stdio-mode.d.ts.map +1 -1
- package/dist/stdio-mode.js +237 -50
- package/dist/stdio-mode.js.map +1 -1
- package/dist/tools/api.d.ts.map +1 -1
- package/dist/tools/api.js +49 -15
- package/dist/tools/api.js.map +1 -1
- package/dist/tools/exec.d.ts +1 -1
- package/dist/tools/exec.d.ts.map +1 -1
- package/dist/tools/http.d.ts +7 -3
- package/dist/tools/http.d.ts.map +1 -1
- package/dist/tools/http.js +179 -25
- package/dist/tools/http.js.map +1 -1
- package/dist/transport/agent-server.d.ts +29 -2
- package/dist/transport/agent-server.d.ts.map +1 -1
- package/dist/transport/agent-server.js +190 -32
- package/dist/transport/agent-server.js.map +1 -1
- package/dist/transport/http-server.d.ts +17 -2
- package/dist/transport/http-server.d.ts.map +1 -1
- package/dist/transport/http-server.js +109 -96
- package/dist/transport/http-server.js.map +1 -1
- package/dist/transport/keepalive.d.ts +11 -13
- package/dist/transport/keepalive.d.ts.map +1 -1
- package/dist/transport/keepalive.js +11 -13
- package/dist/transport/keepalive.js.map +1 -1
- package/dist/transport/oauth-callback.d.ts +19 -0
- package/dist/transport/oauth-callback.d.ts.map +1 -0
- package/dist/transport/oauth-callback.js +30 -0
- package/dist/transport/oauth-callback.js.map +1 -0
- package/dist/transport/session-limiter.d.ts +10 -3
- package/dist/transport/session-limiter.d.ts.map +1 -1
- package/dist/transport/session-limiter.js +13 -3
- package/dist/transport/session-limiter.js.map +1 -1
- package/dist/transport/sse-server.d.ts.map +1 -1
- package/dist/transport/sse-server.js +54 -24
- package/dist/transport/sse-server.js.map +1 -1
- package/dist/transport/stdio-server.d.ts +6 -0
- package/dist/transport/stdio-server.d.ts.map +1 -1
- package/dist/transport/stdio-server.js +19 -7
- package/dist/transport/stdio-server.js.map +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/uploads/api.d.ts +20 -0
- package/dist/uploads/api.d.ts.map +1 -0
- package/dist/uploads/api.js +280 -0
- package/dist/uploads/api.js.map +1 -0
- package/dist/uploads/refs.d.ts +48 -0
- package/dist/uploads/refs.d.ts.map +1 -0
- package/dist/uploads/refs.js +273 -0
- package/dist/uploads/refs.js.map +1 -0
- package/dist/uploads/resolve.d.ts +117 -0
- package/dist/uploads/resolve.d.ts.map +1 -0
- package/dist/uploads/resolve.js +581 -0
- package/dist/uploads/resolve.js.map +1 -0
- package/dist/uploads/store.d.ts +224 -0
- package/dist/uploads/store.d.ts.map +1 -0
- package/dist/uploads/store.js +1908 -0
- package/dist/uploads/store.js.map +1 -0
- package/dist/util/atomic-file.d.ts +6 -0
- package/dist/util/atomic-file.d.ts.map +1 -1
- package/dist/util/atomic-file.js +42 -2
- package/dist/util/atomic-file.js.map +1 -1
- package/dist/util/is-record.d.ts +3 -0
- package/dist/util/is-record.d.ts.map +1 -0
- package/dist/util/is-record.js +5 -0
- package/dist/util/is-record.js.map +1 -0
- package/dist/util/stable-json.d.ts +3 -0
- package/dist/util/stable-json.d.ts.map +1 -0
- package/dist/util/stable-json.js +10 -0
- package/dist/util/stable-json.js.map +1 -0
- package/dist/util/tool-name.d.ts +9 -0
- package/dist/util/tool-name.d.ts.map +1 -0
- package/dist/util/tool-name.js +14 -0
- package/dist/util/tool-name.js.map +1 -0
- package/dist/web/assets/airlock-shield-fPu067nB.png +0 -0
- package/dist/web/assets/favicon-DL7sWXGq.png +0 -0
- package/dist/web/assets/index-B_qY7DgQ.js +225 -0
- package/dist/web/assets/index-Bc_jHlFK.css +1 -0
- package/dist/web/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/web/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/web/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/web/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/web/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/web/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/web/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/web/index.html +17 -0
- package/examples/airlock.yaml +3 -1
- package/examples/claude-code-setup.md +1 -1
- package/examples/docker-compose.yaml +3 -1
- package/examples/docker-gateway.yaml +2 -1
- package/examples/gateway.yaml +1 -1
- package/examples/profiles.yaml +5 -2
- package/examples/sandbox-presets.yaml +4 -1
- package/extensions/openclaw/index.ts +3 -3
- package/extensions/openclaw/openclaw.plugin.json +4 -4
- package/package.json +25 -10
- package/schema.json +2819 -2029
- package/dist/transport/mcp-normalizer.d.ts +0 -9
- package/dist/transport/mcp-normalizer.d.ts.map +0 -1
- package/dist/transport/mcp-normalizer.js +0 -12
- package/dist/transport/mcp-normalizer.js.map +0 -1
- package/extensions/openclaw/package-lock.json +0 -8548
package/dist/hitl/engine.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { generateId, generateApprovalCode } from '../util/id.js';
|
|
2
|
+
import { GrantStore, describeScope, formatDuration, } from './grants.js';
|
|
2
3
|
import { childLogger } from '../util/logger.js';
|
|
3
4
|
const log = childLogger('hitl-engine');
|
|
5
|
+
export class GrantSpecError extends Error {
|
|
6
|
+
}
|
|
7
|
+
const DEFAULTS = {
|
|
8
|
+
asyncGrantTtlMs: 30 * 60_000,
|
|
9
|
+
planGrantTtlMs: 30 * 60_000,
|
|
10
|
+
defaultGrantDurationMs: 15 * 60_000,
|
|
11
|
+
maxGrantDurationMs: 24 * 60 * 60_000,
|
|
12
|
+
denialMemoryMs: 5 * 60_000,
|
|
13
|
+
};
|
|
4
14
|
function redactApprovalArgs(auditLogger, args) {
|
|
5
15
|
return (auditLogger.redactArgs?.(args) ?? args);
|
|
6
16
|
}
|
|
@@ -10,10 +20,25 @@ export class HitlEngine {
|
|
|
10
20
|
_timeoutMs;
|
|
11
21
|
pending = new Map(); // id → request
|
|
12
22
|
byCode = new Map(); // code → id
|
|
13
|
-
|
|
23
|
+
batches = new Map(); // batchId → batch
|
|
24
|
+
batchByCode = new Map(); // batch code → batchId
|
|
25
|
+
recentDenials = new Map(); // agentId\0fingerprint → expiry ms
|
|
26
|
+
grants;
|
|
27
|
+
opts;
|
|
28
|
+
constructor(auditLogger, provider, _timeoutMs, options = {}) {
|
|
14
29
|
this.auditLogger = auditLogger;
|
|
15
30
|
this.provider = provider;
|
|
16
31
|
this._timeoutMs = _timeoutMs;
|
|
32
|
+
this.grants = options.grants ?? new GrantStore(undefined);
|
|
33
|
+
this.opts = {
|
|
34
|
+
defaultMode: options.defaultMode ?? 'sync',
|
|
35
|
+
asyncGrantTtlMs: options.asyncGrantTtlMs ?? DEFAULTS.asyncGrantTtlMs,
|
|
36
|
+
planGrantTtlMs: options.planGrantTtlMs ?? DEFAULTS.planGrantTtlMs,
|
|
37
|
+
defaultGrantDurationMs: options.defaultGrantDurationMs ?? DEFAULTS.defaultGrantDurationMs,
|
|
38
|
+
maxGrantDurationMs: options.maxGrantDurationMs ?? DEFAULTS.maxGrantDurationMs,
|
|
39
|
+
denialMemoryMs: options.denialMemoryMs ?? DEFAULTS.denialMemoryMs,
|
|
40
|
+
profilesForTool: options.profilesForTool,
|
|
41
|
+
};
|
|
17
42
|
}
|
|
18
43
|
get timeoutMs() {
|
|
19
44
|
return this._timeoutMs;
|
|
@@ -21,10 +46,29 @@ export class HitlEngine {
|
|
|
21
46
|
setTimeoutMs(timeoutMs) {
|
|
22
47
|
this._timeoutMs = timeoutMs;
|
|
23
48
|
}
|
|
49
|
+
get defaultMode() {
|
|
50
|
+
return this.opts.defaultMode;
|
|
51
|
+
}
|
|
52
|
+
configure(options) {
|
|
53
|
+
for (const [key, value] of Object.entries(options)) {
|
|
54
|
+
if (value !== undefined)
|
|
55
|
+
this.opts[key] = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
24
58
|
create(params) {
|
|
25
59
|
const id = generateId();
|
|
26
60
|
const code = generateApprovalCode();
|
|
27
61
|
const approvalArgs = redactApprovalArgs(this.auditLogger, params.args);
|
|
62
|
+
const createdAt = new Date().toISOString();
|
|
63
|
+
const kind = params.kind ?? 'call';
|
|
64
|
+
const mode = params.mode ?? 'sync';
|
|
65
|
+
const meta = {
|
|
66
|
+
kind,
|
|
67
|
+
mode,
|
|
68
|
+
...(params.subject ? { subject: params.subject } : {}),
|
|
69
|
+
...(params.plan ? { plan: params.plan } : {}),
|
|
70
|
+
...(params.escalationReason ? { escalationReason: params.escalationReason } : {}),
|
|
71
|
+
};
|
|
28
72
|
// Persist to DB synchronously before returning
|
|
29
73
|
this.auditLogger.insertHitl({
|
|
30
74
|
id,
|
|
@@ -33,57 +77,75 @@ export class HitlEngine {
|
|
|
33
77
|
tool: params.tool,
|
|
34
78
|
args: JSON.stringify(withContext(approvalArgs, params.context)),
|
|
35
79
|
status: 'pending',
|
|
36
|
-
created_at:
|
|
80
|
+
created_at: createdAt,
|
|
81
|
+
meta: JSON.stringify(meta),
|
|
37
82
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
83
|
+
let resolve;
|
|
84
|
+
const result = new Promise((r) => (resolve = r));
|
|
85
|
+
const ticket = { id, code, result };
|
|
86
|
+
const req = {
|
|
87
|
+
id,
|
|
88
|
+
code,
|
|
89
|
+
agentId: params.agentId,
|
|
90
|
+
tool: params.tool,
|
|
91
|
+
args: approvalArgs,
|
|
92
|
+
...(params.context ? { context: params.context } : {}),
|
|
93
|
+
...(params.escalationReason ? { escalationReason: params.escalationReason } : {}),
|
|
94
|
+
...(params.sandbox ? { sandbox: params.sandbox } : {}),
|
|
95
|
+
kind,
|
|
96
|
+
mode,
|
|
97
|
+
...(params.subject ? { subject: params.subject } : {}),
|
|
98
|
+
...(params.plan ? { plan: params.plan } : {}),
|
|
99
|
+
createdAt,
|
|
100
|
+
result,
|
|
101
|
+
resolve,
|
|
102
|
+
ticket,
|
|
103
|
+
};
|
|
104
|
+
this.track(req, this.timeoutMs);
|
|
105
|
+
log.info({ id, code, agent: params.agentId, tool: params.tool, kind, mode }, 'HITL request created');
|
|
106
|
+
return ticket;
|
|
107
|
+
}
|
|
108
|
+
/** Redact args the same way approval requests are redacted before display. */
|
|
109
|
+
redact(args) {
|
|
110
|
+
return redactApprovalArgs(this.auditLogger, args);
|
|
111
|
+
}
|
|
112
|
+
/** The notification payload for a request just created, ready for the batcher. */
|
|
113
|
+
buildNotification(id) {
|
|
114
|
+
const req = this.pending.get(id);
|
|
115
|
+
if (!req)
|
|
116
|
+
return undefined;
|
|
117
|
+
return this.toNotification(req, this.timeoutMs);
|
|
57
118
|
}
|
|
58
|
-
approve(id) {
|
|
119
|
+
approve(id, options) {
|
|
59
120
|
const req = this.pending.get(id);
|
|
60
121
|
if (!req) {
|
|
61
122
|
log.warn({ id }, 'No pending HITL request found');
|
|
62
|
-
return;
|
|
123
|
+
return undefined;
|
|
63
124
|
}
|
|
64
|
-
this.
|
|
125
|
+
return this.approveWithOptions(req, options);
|
|
65
126
|
}
|
|
66
|
-
approveByCode(code) {
|
|
127
|
+
approveByCode(code, options) {
|
|
128
|
+
const batchId = this.batchByCode.get(code);
|
|
129
|
+
if (batchId) {
|
|
130
|
+
if (options?.grant) {
|
|
131
|
+
throw new GrantSpecError('A grant needs a single request: approve one request with a duration, not the batch');
|
|
132
|
+
}
|
|
133
|
+
return this.approveBatch(batchId);
|
|
134
|
+
}
|
|
67
135
|
const req = this.resolveRequestByCode(code);
|
|
68
136
|
if (!req) {
|
|
69
137
|
log.warn({ code }, 'No pending HITL request found for approval code');
|
|
70
|
-
return;
|
|
138
|
+
return undefined;
|
|
71
139
|
}
|
|
72
|
-
this.
|
|
140
|
+
return this.approveWithOptions(req, options);
|
|
73
141
|
}
|
|
74
142
|
/** Cancel a pending request (e.g. transport disconnected). */
|
|
75
143
|
cancel(id) {
|
|
76
144
|
const req = this.pending.get(id);
|
|
77
145
|
if (!req)
|
|
78
146
|
return;
|
|
79
|
-
|
|
80
|
-
clearTimeout(req.timer);
|
|
81
|
-
this.pending.delete(req.id);
|
|
82
|
-
this.byCode.delete(req.code);
|
|
83
|
-
this.auditLogger.updateHitlStatus(req.id, 'cancelled');
|
|
147
|
+
this.finish(req, 'cancelled');
|
|
84
148
|
log.info({ id: req.id, code: req.code }, 'HITL cancelled (session disconnected)');
|
|
85
|
-
this.updateApprovalStatus(req, 'cancelled');
|
|
86
|
-
req.resolve('cancelled');
|
|
87
149
|
}
|
|
88
150
|
deny(id, reason) {
|
|
89
151
|
const req = this.pending.get(id);
|
|
@@ -94,6 +156,11 @@ export class HitlEngine {
|
|
|
94
156
|
this.denyRequest(req, reason);
|
|
95
157
|
}
|
|
96
158
|
denyByCode(code, reason) {
|
|
159
|
+
const batchId = this.batchByCode.get(code);
|
|
160
|
+
if (batchId) {
|
|
161
|
+
this.denyBatch(batchId, reason);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
97
164
|
const req = this.resolveRequestByCode(code);
|
|
98
165
|
if (!req) {
|
|
99
166
|
log.warn({ code }, 'No pending HITL request found for approval code');
|
|
@@ -101,16 +168,104 @@ export class HitlEngine {
|
|
|
101
168
|
}
|
|
102
169
|
this.denyRequest(req, reason);
|
|
103
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Approve an explicit list of requests in one decision. Bulk approval is for routine tool calls:
|
|
173
|
+
* escalated calls (flagged by a detector or command policy) are skipped unless
|
|
174
|
+
* `includeEscalated` is set, and plans and ask_user questions are always skipped — a plan mints
|
|
175
|
+
* grants and a question needs reading, so each deserves its own look.
|
|
176
|
+
*/
|
|
177
|
+
approveMany(ids, opts = {}) {
|
|
178
|
+
const approved = [];
|
|
179
|
+
const skipped = [];
|
|
180
|
+
for (const id of ids) {
|
|
181
|
+
const req = this.pending.get(id);
|
|
182
|
+
if (!req || req.kind !== 'call' || (req.subject?.escalated && !opts.includeEscalated)) {
|
|
183
|
+
skipped.push(id);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
this.approveRequest(req);
|
|
187
|
+
approved.push(id);
|
|
188
|
+
}
|
|
189
|
+
log.info({ approved: approved.length, skipped: skipped.length }, 'HITL bulk approve');
|
|
190
|
+
return { approved, skipped };
|
|
191
|
+
}
|
|
192
|
+
denyMany(ids, reason) {
|
|
193
|
+
const denied = [];
|
|
194
|
+
for (const id of ids) {
|
|
195
|
+
const req = this.pending.get(id);
|
|
196
|
+
if (!req)
|
|
197
|
+
continue;
|
|
198
|
+
this.denyRequest(req, reason);
|
|
199
|
+
denied.push(id);
|
|
200
|
+
}
|
|
201
|
+
return denied;
|
|
202
|
+
}
|
|
203
|
+
/** Approve every still-pending, non-escalated member of a notification batch. */
|
|
204
|
+
approveBatch(batchIdOrCode) {
|
|
205
|
+
const batch = this.getBatch(batchIdOrCode);
|
|
206
|
+
if (!batch)
|
|
207
|
+
return undefined;
|
|
208
|
+
return this.approveMany(batch.ids);
|
|
209
|
+
}
|
|
210
|
+
denyBatch(batchIdOrCode, reason) {
|
|
211
|
+
const batch = this.getBatch(batchIdOrCode);
|
|
212
|
+
if (!batch)
|
|
213
|
+
return undefined;
|
|
214
|
+
return this.denyMany(batch.ids, reason);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Snapshot a set of requests notified together. Returns undefined for a single request — a
|
|
218
|
+
* batch of one is just a request. "Approve all" only ever covers this snapshot, never requests
|
|
219
|
+
* that arrived after the operator was shown the batch.
|
|
220
|
+
*/
|
|
221
|
+
registerBatch(ids) {
|
|
222
|
+
const members = ids.filter((id) => this.pending.has(id));
|
|
223
|
+
if (members.length < 2)
|
|
224
|
+
return undefined;
|
|
225
|
+
const batch = {
|
|
226
|
+
id: generateId(),
|
|
227
|
+
code: generateApprovalCode(),
|
|
228
|
+
agentId: this.pending.get(members[0]).agentId,
|
|
229
|
+
ids: members,
|
|
230
|
+
};
|
|
231
|
+
this.batches.set(batch.id, batch);
|
|
232
|
+
this.batchByCode.set(batch.code, batch.id);
|
|
233
|
+
for (const id of members)
|
|
234
|
+
this.pending.get(id).batchId = batch.id;
|
|
235
|
+
return { batchId: batch.id, batchCode: batch.code };
|
|
236
|
+
}
|
|
237
|
+
hasBatch(batchIdOrCode) {
|
|
238
|
+
return this.getBatch(batchIdOrCode) !== undefined;
|
|
239
|
+
}
|
|
104
240
|
getPending() {
|
|
105
|
-
return Array.from(this.pending.values()).map((r) =>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
241
|
+
return Array.from(this.pending.values()).map((r) => {
|
|
242
|
+
const batch = r.batchId ? this.batches.get(r.batchId) : undefined;
|
|
243
|
+
const grantOptions = this.grantOptionsFor(r);
|
|
244
|
+
return {
|
|
245
|
+
id: r.id,
|
|
246
|
+
code: r.code,
|
|
247
|
+
agentId: r.agentId,
|
|
248
|
+
tool: r.tool,
|
|
249
|
+
args: r.args,
|
|
250
|
+
...(r.context ? { context: r.context } : {}),
|
|
251
|
+
...(r.sandbox ? { sandbox: r.sandbox } : {}),
|
|
252
|
+
kind: r.kind,
|
|
253
|
+
mode: r.mode,
|
|
254
|
+
...(r.subject
|
|
255
|
+
? { tier: r.subject.tier, provider: r.subject.provider, escalated: r.subject.escalated }
|
|
256
|
+
: {}),
|
|
257
|
+
...(r.escalationReason ? { escalationReason: r.escalationReason } : {}),
|
|
258
|
+
...(r.plan ? { plan: r.plan } : {}),
|
|
259
|
+
...(batch ? { batchId: batch.id, batchCode: batch.code } : {}),
|
|
260
|
+
...(grantOptions.length > 0 ? { grantOptions } : {}),
|
|
261
|
+
createdAt: r.createdAt,
|
|
262
|
+
...(r.expiresAt ? { expiresAt: r.expiresAt } : {}),
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/** Number of pending approvals, without building each one's display payload. */
|
|
267
|
+
pendingCount() {
|
|
268
|
+
return this.pending.size;
|
|
114
269
|
}
|
|
115
270
|
hasPending(id) {
|
|
116
271
|
return this.pending.has(id);
|
|
@@ -118,40 +273,388 @@ export class HitlEngine {
|
|
|
118
273
|
getPreviewRequest(id) {
|
|
119
274
|
return this.pending.get(id);
|
|
120
275
|
}
|
|
276
|
+
// ── Grants ────────────────────────────────────────────────────────────────
|
|
277
|
+
/** Consume a grant covering this call, if one exists. */
|
|
278
|
+
consumeGrant(subject) {
|
|
279
|
+
return this.grants.consume(subject);
|
|
280
|
+
}
|
|
281
|
+
/** Create a grant directly (operator pre-approval, not tied to a request). */
|
|
282
|
+
createOperatorGrant(params) {
|
|
283
|
+
if (params.scope.kind === 'call') {
|
|
284
|
+
throw new GrantSpecError('call grants are created by plans and async approvals only');
|
|
285
|
+
}
|
|
286
|
+
if (params.maxUses !== undefined && (!Number.isInteger(params.maxUses) || params.maxUses < 1)) {
|
|
287
|
+
throw new GrantSpecError('maxUses must be a whole number of at least 1');
|
|
288
|
+
}
|
|
289
|
+
const durationMs = this.clampDuration(params.durationMs);
|
|
290
|
+
const grant = this.grants.create({
|
|
291
|
+
agentId: params.agentId,
|
|
292
|
+
scope: params.scope,
|
|
293
|
+
source: 'operator',
|
|
294
|
+
label: `${describeScope(params.scope)} for ${formatDuration(durationMs)}`,
|
|
295
|
+
expiresAt: new Date(Date.now() + durationMs).toISOString(),
|
|
296
|
+
...(params.maxUses !== undefined ? { usesRemaining: params.maxUses } : {}),
|
|
297
|
+
});
|
|
298
|
+
this.sweepPending(grant);
|
|
299
|
+
return grant;
|
|
300
|
+
}
|
|
301
|
+
listGrants(agentId) {
|
|
302
|
+
return this.grants.list(agentId);
|
|
303
|
+
}
|
|
304
|
+
isGrantActive(id) {
|
|
305
|
+
return this.grants.isGrantActive(id);
|
|
306
|
+
}
|
|
307
|
+
revokeGrant(id) {
|
|
308
|
+
return this.grants.revoke(id);
|
|
309
|
+
}
|
|
310
|
+
// ── Async support ─────────────────────────────────────────────────────────
|
|
311
|
+
/** A pending async request for the same exact call, so retries don't create duplicates. */
|
|
312
|
+
findPendingCall(agentId, fingerprint) {
|
|
313
|
+
for (const req of this.pending.values()) {
|
|
314
|
+
if (req.agentId === agentId &&
|
|
315
|
+
req.subject?.fingerprint === fingerprint &&
|
|
316
|
+
req.kind === 'call') {
|
|
317
|
+
return { id: req.id, code: req.code };
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
wasRecentlyDenied(agentId, fingerprint) {
|
|
323
|
+
const key = `${agentId}\0${fingerprint}`;
|
|
324
|
+
const expiry = this.recentDenials.get(key);
|
|
325
|
+
if (expiry === undefined)
|
|
326
|
+
return false;
|
|
327
|
+
if (expiry <= Date.now()) {
|
|
328
|
+
this.recentDenials.delete(key);
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
/** Status of an approval the given agent owns, or undefined if it isn't theirs / doesn't exist. */
|
|
334
|
+
getStatus(id, agentId) {
|
|
335
|
+
const req = this.pending.get(id);
|
|
336
|
+
if (req) {
|
|
337
|
+
if (req.agentId !== agentId)
|
|
338
|
+
return undefined;
|
|
339
|
+
return { id, code: req.code, agentId, tool: req.tool, kind: req.kind, status: 'pending' };
|
|
340
|
+
}
|
|
341
|
+
const row = this.auditLogger.getHitlById?.(id);
|
|
342
|
+
if (!row || row.agent_id !== agentId)
|
|
343
|
+
return undefined;
|
|
344
|
+
const meta = parseMeta(row.meta);
|
|
345
|
+
return {
|
|
346
|
+
id,
|
|
347
|
+
code: row.code,
|
|
348
|
+
agentId,
|
|
349
|
+
tool: row.tool,
|
|
350
|
+
kind: meta.kind ?? 'call',
|
|
351
|
+
status: row.status,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/** Wait up to `waitMs` for an approval to resolve. */
|
|
355
|
+
async waitFor(id, agentId, waitMs) {
|
|
356
|
+
const req = this.pending.get(id);
|
|
357
|
+
if (req && req.agentId === agentId && waitMs > 0) {
|
|
358
|
+
let timer;
|
|
359
|
+
await Promise.race([
|
|
360
|
+
req.result,
|
|
361
|
+
new Promise((resolve) => {
|
|
362
|
+
timer = setTimeout(resolve, waitMs);
|
|
363
|
+
timer.unref();
|
|
364
|
+
}),
|
|
365
|
+
]);
|
|
366
|
+
clearTimeout(timer);
|
|
367
|
+
}
|
|
368
|
+
return this.getStatus(id, agentId);
|
|
369
|
+
}
|
|
370
|
+
// ── Internals ─────────────────────────────────────────────────────────────
|
|
371
|
+
getBatch(batchIdOrCode) {
|
|
372
|
+
const batchId = this.batchByCode.get(batchIdOrCode) ?? batchIdOrCode;
|
|
373
|
+
return this.batches.get(batchId);
|
|
374
|
+
}
|
|
121
375
|
resolveRequestByCode(code) {
|
|
122
376
|
const id = this.byCode.get(code);
|
|
123
377
|
if (id)
|
|
124
378
|
return this.pending.get(id);
|
|
125
379
|
return undefined;
|
|
126
380
|
}
|
|
381
|
+
track(req, timeoutMs) {
|
|
382
|
+
this.pending.set(req.id, req);
|
|
383
|
+
this.byCode.set(req.code, req.id);
|
|
384
|
+
if (timeoutMs > 0) {
|
|
385
|
+
const timer = setTimeout(() => {
|
|
386
|
+
log.warn({ id: req.id, code: req.code, tool: req.tool }, 'HITL request timed out');
|
|
387
|
+
this.finish(req, 'timeout');
|
|
388
|
+
}, timeoutMs);
|
|
389
|
+
timer.unref();
|
|
390
|
+
req.timer = timer;
|
|
391
|
+
req.expiresAt = new Date(Date.now() + timeoutMs).toISOString();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
approveWithOptions(req, options) {
|
|
395
|
+
// Validate the grant before approving so a bad spec rejects the whole decision.
|
|
396
|
+
const spec = options?.grant;
|
|
397
|
+
const scope = spec ? this.scopeFromSpec(req, spec) : undefined;
|
|
398
|
+
if (spec?.maxUses !== undefined && (!Number.isInteger(spec.maxUses) || spec.maxUses < 1)) {
|
|
399
|
+
throw new GrantSpecError('maxUses must be a whole number of at least 1');
|
|
400
|
+
}
|
|
401
|
+
if (spec?.sessionOnly && !req.subject?.sessionId) {
|
|
402
|
+
// Never silently widen a session-only grant to every session of the agent.
|
|
403
|
+
throw new GrantSpecError('This request has no session to bind a session-only grant to');
|
|
404
|
+
}
|
|
405
|
+
if (!scope || !spec) {
|
|
406
|
+
this.approveRequest(req);
|
|
407
|
+
return { approved: [req.id], skipped: [] };
|
|
408
|
+
}
|
|
409
|
+
// The approval that creates the grant counts as its first use.
|
|
410
|
+
const usesRemaining = spec.maxUses !== undefined ? spec.maxUses - 1 : undefined;
|
|
411
|
+
if (usesRemaining === 0) {
|
|
412
|
+
if (req.ticket) {
|
|
413
|
+
req.ticket.grantMeta = { hasUseCap: true };
|
|
414
|
+
}
|
|
415
|
+
this.approveRequest(req);
|
|
416
|
+
return { approved: [req.id], skipped: [] };
|
|
417
|
+
}
|
|
418
|
+
const durationMs = this.clampDuration(spec.durationMs);
|
|
419
|
+
const grant = this.grants.create({
|
|
420
|
+
agentId: req.agentId,
|
|
421
|
+
...(spec.sessionOnly ? { sessionId: req.subject.sessionId } : {}),
|
|
422
|
+
scope,
|
|
423
|
+
source: 'approval',
|
|
424
|
+
approvalId: req.id,
|
|
425
|
+
label: `${describeScope(scope)} for ${formatDuration(durationMs)}`,
|
|
426
|
+
expiresAt: new Date(Date.now() + durationMs).toISOString(),
|
|
427
|
+
...(usesRemaining !== undefined ? { usesRemaining } : {}),
|
|
428
|
+
});
|
|
429
|
+
if (req.ticket) {
|
|
430
|
+
req.ticket.grantMeta = {
|
|
431
|
+
grantId: grant.id,
|
|
432
|
+
expiresAt: grant.expiresAt,
|
|
433
|
+
hasUseCap: spec.maxUses !== undefined,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
this.approveRequest(req);
|
|
437
|
+
const alsoApproved = this.sweepPending(grant);
|
|
438
|
+
return { approved: [req.id, ...alsoApproved], skipped: [], grant };
|
|
439
|
+
}
|
|
440
|
+
/** Resolve every other pending call the new grant covers — e.g. the 9 queued email reads. */
|
|
441
|
+
sweepPending(grant) {
|
|
442
|
+
const approved = [];
|
|
443
|
+
const only = new Set([grant.id]);
|
|
444
|
+
const hasUseCap = grant.usesRemaining !== undefined;
|
|
445
|
+
for (const other of [...this.pending.values()]) {
|
|
446
|
+
if (other.kind !== 'call' || !other.subject)
|
|
447
|
+
continue;
|
|
448
|
+
if (!this.grants.covers(grant, other.subject))
|
|
449
|
+
continue;
|
|
450
|
+
// Every auto-approval spends a use, so maxUses holds. (An async request then also gets its
|
|
451
|
+
// own single-use call grant, which its retry consumes first.)
|
|
452
|
+
if (!this.grants.consume(other.subject, only))
|
|
453
|
+
break;
|
|
454
|
+
if (other.ticket) {
|
|
455
|
+
other.ticket.grantMeta = {
|
|
456
|
+
grantId: grant.id,
|
|
457
|
+
expiresAt: grant.expiresAt,
|
|
458
|
+
hasUseCap,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
this.approveRequest(other);
|
|
462
|
+
approved.push(other.id);
|
|
463
|
+
}
|
|
464
|
+
if (approved.length > 0) {
|
|
465
|
+
log.info({ grantId: grant.id, count: approved.length }, 'Grant auto-approved pending calls');
|
|
466
|
+
}
|
|
467
|
+
return approved;
|
|
468
|
+
}
|
|
469
|
+
scopeFromSpec(req, spec) {
|
|
470
|
+
const subject = req.subject;
|
|
471
|
+
if (!subject || req.kind !== 'call') {
|
|
472
|
+
throw new GrantSpecError('Only tool-call approvals can be turned into a grant');
|
|
473
|
+
}
|
|
474
|
+
if (subject.escalated) {
|
|
475
|
+
throw new GrantSpecError('This call was flagged for review by a security check; it cannot be widened into a grant');
|
|
476
|
+
}
|
|
477
|
+
const isEventSubject = subject.tool.startsWith('event:');
|
|
478
|
+
if (isEventSubject && spec.scope !== 'tool') {
|
|
479
|
+
throw new GrantSpecError('Event subscription approvals only support single-event ("tool") grants');
|
|
480
|
+
}
|
|
481
|
+
switch (spec.scope) {
|
|
482
|
+
case 'tool':
|
|
483
|
+
return { kind: 'tool', tool: subject.tool };
|
|
484
|
+
case 'tier': {
|
|
485
|
+
const tier = spec.tier ?? (subject.tier === 'read' ? 'read' : 'write');
|
|
486
|
+
return {
|
|
487
|
+
kind: 'tier',
|
|
488
|
+
tier,
|
|
489
|
+
...(spec.sameProvider === false ? {} : { provider: subject.provider }),
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
case 'provider':
|
|
493
|
+
return { kind: 'provider', provider: subject.provider };
|
|
494
|
+
case 'profile': {
|
|
495
|
+
if (!spec.profile)
|
|
496
|
+
throw new GrantSpecError('profile is required for a profile grant');
|
|
497
|
+
const known = this.opts.profilesForTool?.(subject.tool) ?? [];
|
|
498
|
+
if (!known.includes(spec.profile)) {
|
|
499
|
+
throw new GrantSpecError(`Profile ${spec.profile} does not cover ${subject.tool}`);
|
|
500
|
+
}
|
|
501
|
+
return { kind: 'profile', profile: spec.profile };
|
|
502
|
+
}
|
|
503
|
+
default:
|
|
504
|
+
throw new GrantSpecError(`Unknown grant scope: ${String(spec.scope)}`);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
grantOptionsFor(req) {
|
|
508
|
+
const subject = req.subject;
|
|
509
|
+
if (req.kind !== 'call' || !subject || subject.escalated)
|
|
510
|
+
return [];
|
|
511
|
+
const options = [{ scope: 'tool', label: `Allow ${subject.tool}` }];
|
|
512
|
+
if (subject.tool.startsWith('event:')) {
|
|
513
|
+
return options;
|
|
514
|
+
}
|
|
515
|
+
if (subject.tier === 'read') {
|
|
516
|
+
options.push({
|
|
517
|
+
scope: 'tier',
|
|
518
|
+
tier: 'read',
|
|
519
|
+
label: `Allow read-only ${subject.provider} tools`,
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
else if (subject.tier === 'write') {
|
|
523
|
+
options.push({
|
|
524
|
+
scope: 'tier',
|
|
525
|
+
tier: 'write',
|
|
526
|
+
label: `Allow non-destructive ${subject.provider} tools`,
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
options.push({ scope: 'provider', label: `Allow all ${subject.provider} tools` });
|
|
530
|
+
for (const profile of this.opts.profilesForTool?.(subject.tool) ?? []) {
|
|
531
|
+
options.push({ scope: 'profile', profile, label: `Allow profile ${profile}` });
|
|
532
|
+
}
|
|
533
|
+
return options;
|
|
534
|
+
}
|
|
535
|
+
clampDuration(durationMs) {
|
|
536
|
+
const requested = durationMs && durationMs > 0 ? durationMs : this.opts.defaultGrantDurationMs;
|
|
537
|
+
return Math.min(requested, this.opts.maxGrantDurationMs);
|
|
538
|
+
}
|
|
127
539
|
approveRequest(req) {
|
|
128
|
-
|
|
129
|
-
clearTimeout(req.timer);
|
|
130
|
-
this.pending.delete(req.id);
|
|
131
|
-
this.byCode.delete(req.code);
|
|
132
|
-
this.auditLogger.updateHitlStatus(req.id, 'approved');
|
|
540
|
+
this.finish(req, 'approved');
|
|
133
541
|
log.info({ id: req.id, code: req.code }, 'HITL approved');
|
|
134
|
-
|
|
135
|
-
|
|
542
|
+
if (req.kind === 'call' && req.mode === 'async' && req.subject) {
|
|
543
|
+
// The agent got an immediate "pending" answer; leave a single-use grant so its retry of the
|
|
544
|
+
// exact same call goes through.
|
|
545
|
+
this.grants.create({
|
|
546
|
+
agentId: req.agentId,
|
|
547
|
+
scope: { kind: 'call', tool: req.subject.tool, fingerprint: req.subject.fingerprint },
|
|
548
|
+
source: 'async',
|
|
549
|
+
approvalId: req.id,
|
|
550
|
+
label: `retry of ${req.subject.tool}`,
|
|
551
|
+
expiresAt: new Date(Date.now() + this.opts.asyncGrantTtlMs).toISOString(),
|
|
552
|
+
usesRemaining: 1,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
if (req.kind === 'plan' && req.plan) {
|
|
556
|
+
const counts = new Map();
|
|
557
|
+
for (const entry of req.plan) {
|
|
558
|
+
const existing = counts.get(entry.fingerprint);
|
|
559
|
+
if (existing)
|
|
560
|
+
existing.count += 1;
|
|
561
|
+
else
|
|
562
|
+
counts.set(entry.fingerprint, { entry, count: 1 });
|
|
563
|
+
}
|
|
564
|
+
const expiresAt = new Date(Date.now() + this.opts.planGrantTtlMs).toISOString();
|
|
565
|
+
for (const [fingerprint, { entry, count }] of counts) {
|
|
566
|
+
const tool = entry.tool;
|
|
567
|
+
const summary = argsSummary(entry.args);
|
|
568
|
+
this.grants.create({
|
|
569
|
+
agentId: req.agentId,
|
|
570
|
+
scope: { kind: 'call', tool, fingerprint },
|
|
571
|
+
source: 'plan',
|
|
572
|
+
approvalId: req.id,
|
|
573
|
+
label: summary ? `planned ${tool} (${summary})` : `planned ${tool}`,
|
|
574
|
+
expiresAt,
|
|
575
|
+
usesRemaining: count,
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
136
579
|
}
|
|
137
580
|
denyRequest(req, reason) {
|
|
581
|
+
this.finish(req, 'denied', reason);
|
|
582
|
+
log.info({ id: req.id, code: req.code, reason }, 'HITL denied');
|
|
583
|
+
if (req.mode === 'async' && req.subject) {
|
|
584
|
+
const now = Date.now();
|
|
585
|
+
for (const [key, expiry] of this.recentDenials) {
|
|
586
|
+
if (expiry <= now)
|
|
587
|
+
this.recentDenials.delete(key);
|
|
588
|
+
}
|
|
589
|
+
this.recentDenials.set(`${req.agentId}\0${req.subject.fingerprint}`, Date.now() + this.opts.denialMemoryMs);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
finish(req, result, reason) {
|
|
138
593
|
if (req.timer)
|
|
139
594
|
clearTimeout(req.timer);
|
|
140
595
|
this.pending.delete(req.id);
|
|
141
596
|
this.byCode.delete(req.code);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
597
|
+
if (reason === undefined)
|
|
598
|
+
this.auditLogger.updateHitlStatus(req.id, result);
|
|
599
|
+
else
|
|
600
|
+
this.auditLogger.updateHitlStatus(req.id, result, reason);
|
|
601
|
+
// Also releases the batch once its last member resolves.
|
|
602
|
+
this.updateApprovalStatus(req, result);
|
|
603
|
+
req.resolve(result);
|
|
604
|
+
}
|
|
605
|
+
/** Pending members left in a batch; forgets the batch once none are. */
|
|
606
|
+
releaseBatch(batchId) {
|
|
607
|
+
if (!batchId)
|
|
608
|
+
return undefined;
|
|
609
|
+
const batch = this.batches.get(batchId);
|
|
610
|
+
if (!batch)
|
|
611
|
+
return undefined;
|
|
612
|
+
const remaining = batch.ids.filter((id) => this.pending.has(id)).length;
|
|
613
|
+
if (remaining === 0) {
|
|
614
|
+
this.batches.delete(batch.id);
|
|
615
|
+
this.batchByCode.delete(batch.code);
|
|
616
|
+
}
|
|
617
|
+
return remaining;
|
|
618
|
+
}
|
|
619
|
+
toNotification(req, timeoutMs) {
|
|
620
|
+
const grantOptions = this.grantOptionsFor(req);
|
|
621
|
+
return {
|
|
622
|
+
id: req.id,
|
|
623
|
+
code: req.code,
|
|
624
|
+
agentId: req.agentId,
|
|
625
|
+
tool: req.tool,
|
|
626
|
+
args: req.args,
|
|
627
|
+
...(req.context ? { context: req.context } : {}),
|
|
628
|
+
...(req.sandbox ? { sandbox: req.sandbox } : {}),
|
|
629
|
+
timeoutMs,
|
|
630
|
+
createdAt: req.createdAt,
|
|
631
|
+
...(req.expiresAt ? { expiresAt: req.expiresAt } : {}),
|
|
632
|
+
kind: req.kind,
|
|
633
|
+
mode: req.mode,
|
|
634
|
+
...(req.subject
|
|
635
|
+
? {
|
|
636
|
+
tier: req.subject.tier,
|
|
637
|
+
provider: req.subject.provider,
|
|
638
|
+
escalated: req.subject.escalated,
|
|
639
|
+
}
|
|
640
|
+
: {}),
|
|
641
|
+
...(req.escalationReason ? { escalationReason: req.escalationReason } : {}),
|
|
642
|
+
...(req.plan ? { plan: req.plan } : {}),
|
|
643
|
+
...(grantOptions.length > 0 ? { grantOptions } : {}),
|
|
644
|
+
};
|
|
146
645
|
}
|
|
147
646
|
/** Recover pending requests from DB on startup */
|
|
148
647
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
149
648
|
async recoverPending() {
|
|
649
|
+
this.grants.load();
|
|
150
650
|
const rows = this.auditLogger.getPendingHitl();
|
|
151
651
|
if (rows.length === 0)
|
|
152
652
|
return;
|
|
153
653
|
log.info({ count: rows.length }, 'Recovering pending HITL requests from DB');
|
|
154
654
|
for (const row of rows) {
|
|
655
|
+
const meta = parseMeta(row.meta);
|
|
656
|
+
const kind = meta.kind ?? 'call';
|
|
657
|
+
const mode = meta.mode ?? 'sync';
|
|
155
658
|
let args = {};
|
|
156
659
|
try {
|
|
157
660
|
args = JSON.parse(row.args);
|
|
@@ -172,63 +675,74 @@ export class HitlEngine {
|
|
|
172
675
|
else {
|
|
173
676
|
remaining = 0; // no timeout
|
|
174
677
|
}
|
|
678
|
+
// A sync caller's held-open call died with the old process, so nothing is waiting on this
|
|
679
|
+
// decision any more. Only async requests (whose agent will retry) and plans (whose grants
|
|
680
|
+
// outlive the call) are still worth resolving; approving anything else would do nothing.
|
|
681
|
+
if (mode === 'sync' && kind !== 'plan') {
|
|
682
|
+
this.auditLogger.updateHitlStatus(row.id, 'cancelled', 'Caller disconnected on restart');
|
|
683
|
+
this.updateApprovalStatus({ id: row.id, code: row.code }, 'cancelled');
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
175
686
|
const context = readContext(args);
|
|
176
687
|
const cleanArgs = stripStoredContext(args);
|
|
177
|
-
// Re-arm
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}, remaining);
|
|
198
|
-
timer.unref();
|
|
199
|
-
req.timer = timer;
|
|
200
|
-
}
|
|
201
|
-
});
|
|
688
|
+
// Re-arm with the time left from the original creation, then notify again below.
|
|
689
|
+
let resolve;
|
|
690
|
+
const result = new Promise((r) => (resolve = r));
|
|
691
|
+
const req = {
|
|
692
|
+
id: row.id,
|
|
693
|
+
code: row.code,
|
|
694
|
+
agentId: row.agent_id,
|
|
695
|
+
tool: row.tool,
|
|
696
|
+
args: cleanArgs,
|
|
697
|
+
...(context ? { context } : {}),
|
|
698
|
+
...(meta.escalationReason ? { escalationReason: meta.escalationReason } : {}),
|
|
699
|
+
kind,
|
|
700
|
+
mode,
|
|
701
|
+
...(meta.subject ? { subject: meta.subject } : {}),
|
|
702
|
+
...(meta.plan ? { plan: meta.plan } : {}),
|
|
703
|
+
createdAt: row.created_at,
|
|
704
|
+
result,
|
|
705
|
+
resolve,
|
|
706
|
+
};
|
|
707
|
+
this.track(req, remaining);
|
|
202
708
|
// Notify again so operator sees recovered requests
|
|
203
709
|
void this.provider
|
|
204
|
-
.notify([
|
|
205
|
-
{
|
|
206
|
-
id: row.id,
|
|
207
|
-
code: row.code,
|
|
208
|
-
agentId: row.agent_id,
|
|
209
|
-
tool: row.tool,
|
|
210
|
-
args: cleanArgs,
|
|
211
|
-
...(context ? { context } : {}),
|
|
212
|
-
sandbox: undefined,
|
|
213
|
-
timeoutMs: remaining,
|
|
214
|
-
badgeCount: this.getPending().length,
|
|
215
|
-
},
|
|
216
|
-
])
|
|
710
|
+
.notify([{ ...this.toNotification(req, remaining), badgeCount: this.pending.size }])
|
|
217
711
|
.catch((err) => log.warn({ err }, 'Failed to re-notify recovered HITL request'));
|
|
218
|
-
void promise; // tracked in pending map
|
|
219
712
|
}
|
|
220
713
|
}
|
|
221
714
|
updateApprovalStatus(req, result) {
|
|
222
|
-
const badgeCount = this.
|
|
223
|
-
|
|
224
|
-
void this.provider
|
|
225
|
-
.updateApprovalStatus({ id: req.id, code: req.code, result, badgeCount })
|
|
226
|
-
.catch((err) => log.warn({ err }, 'Failed to update approval status'));
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
715
|
+
const badgeCount = this.pending.size;
|
|
716
|
+
const batchPending = this.releaseBatch(req.batchId);
|
|
229
717
|
void this.provider
|
|
230
|
-
.
|
|
231
|
-
|
|
718
|
+
.updateApprovalStatus?.({
|
|
719
|
+
id: req.id,
|
|
720
|
+
code: req.code,
|
|
721
|
+
result,
|
|
722
|
+
badgeCount,
|
|
723
|
+
...(req.batchId && batchPending !== undefined
|
|
724
|
+
? { batchId: req.batchId, batchPending }
|
|
725
|
+
: {}),
|
|
726
|
+
})
|
|
727
|
+
.catch((err) => log.warn({ err }, 'Failed to update approval status'));
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
/** Short "key: value" summary so several planned calls to one tool are distinguishable. */
|
|
731
|
+
function argsSummary(args) {
|
|
732
|
+
const text = Object.entries(args)
|
|
733
|
+
.slice(0, 2)
|
|
734
|
+
.map(([key, value]) => `${key}: ${typeof value === 'string' ? value : JSON.stringify(value)}`)
|
|
735
|
+
.join(', ');
|
|
736
|
+
return text.length > 60 ? `${text.slice(0, 57)}...` : text;
|
|
737
|
+
}
|
|
738
|
+
function parseMeta(raw) {
|
|
739
|
+
if (!raw)
|
|
740
|
+
return {};
|
|
741
|
+
try {
|
|
742
|
+
return JSON.parse(raw);
|
|
743
|
+
}
|
|
744
|
+
catch {
|
|
745
|
+
return {};
|
|
232
746
|
}
|
|
233
747
|
}
|
|
234
748
|
function withContext(args, context) {
|