enya-agent 0.1.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/.env.example +20 -0
- package/.github/workflows/ci.yml +70 -0
- package/.github/workflows/publish.yml +250 -0
- package/.gitmodules +3 -0
- package/Cargo.lock +3584 -0
- package/Cargo.toml +97 -0
- package/crates/enact/Cargo.toml +27 -0
- package/crates/enact/src/lib.rs +60 -0
- package/crates/enact-a2a/Cargo.toml +25 -0
- package/crates/enact-a2a/src/lib.rs +411 -0
- package/crates/enact-channels/Cargo.toml +64 -0
- package/crates/enact-channels/examples/README.md +80 -0
- package/crates/enact-channels/examples/channel_bot.rs +169 -0
- package/crates/enact-channels/examples/telegram-echo.rs +34 -0
- package/crates/enact-channels/examples/whatsapp-echo.rs +142 -0
- package/crates/enact-channels/src/config.rs +213 -0
- package/crates/enact-channels/src/lib.rs +25 -0
- package/crates/enact-channels/src/runtime.rs +237 -0
- package/crates/enact-channels/src/security/mod.rs +5 -0
- package/crates/enact-channels/src/security/pairing.rs +205 -0
- package/crates/enact-channels/src/teams.rs +601 -0
- package/crates/enact-channels/src/telegram.rs +2833 -0
- package/crates/enact-channels/src/traits.rs +200 -0
- package/crates/enact-channels/src/webhook.rs +262 -0
- package/crates/enact-channels/src/whatsapp.rs +310 -0
- package/crates/enact-cli/Cargo.toml +40 -0
- package/crates/enact-cli/src/commands/doctor.rs +62 -0
- package/crates/enact-cli/src/commands/mod.rs +3 -0
- package/crates/enact-cli/src/commands/run.rs +69 -0
- package/crates/enact-cli/src/commands/serve.rs +81 -0
- package/crates/enact-cli/src/config.rs +2 -0
- package/crates/enact-cli/src/main.rs +79 -0
- package/crates/enact-config/Cargo.toml +36 -0
- package/crates/enact-config/ENV_VAR_MAPPING.md +135 -0
- package/crates/enact-config/QUICK_REFERENCE.md +92 -0
- package/crates/enact-config/README.md +107 -0
- package/crates/enact-config/TESTING.md +161 -0
- package/crates/enact-config/examples/test-env-vars.rs +100 -0
- package/crates/enact-config/src/config.rs +399 -0
- package/crates/enact-config/src/encrypted_store.rs +211 -0
- package/crates/enact-config/src/lib.rs +298 -0
- package/crates/enact-config/src/secrets.rs +149 -0
- package/crates/enact-config/src/sync.rs +260 -0
- package/crates/enact-config/test-env-vars.sh +34 -0
- package/crates/enact-config/tests/README.md +99 -0
- package/crates/enact-config/tests/config_integration_test.rs +202 -0
- package/crates/enact-config/tests/security_test.rs +140 -0
- package/crates/enact-context/Cargo.toml +41 -0
- package/crates/enact-context/src/budget.rs +314 -0
- package/crates/enact-context/src/calibrator.rs +535 -0
- package/crates/enact-context/src/compactor.rs +392 -0
- package/crates/enact-context/src/condenser.rs +826 -0
- package/crates/enact-context/src/lib.rs +94 -0
- package/crates/enact-context/src/segment.rs +238 -0
- package/crates/enact-context/src/step_context.rs +645 -0
- package/crates/enact-context/src/token_counter.rs +148 -0
- package/crates/enact-context/src/window.rs +372 -0
- package/crates/enact-core/Cargo.toml +42 -0
- package/crates/enact-core/README.md +98 -0
- package/crates/enact-core/src/background/executor.rs +524 -0
- package/crates/enact-core/src/background/mod.rs +48 -0
- package/crates/enact-core/src/background/target_binding.rs +390 -0
- package/crates/enact-core/src/background/trigger.rs +511 -0
- package/crates/enact-core/src/callable/callable.rs +152 -0
- package/crates/enact-core/src/callable/composite.rs +817 -0
- package/crates/enact-core/src/callable/graph.rs +104 -0
- package/crates/enact-core/src/callable/llm.rs +211 -0
- package/crates/enact-core/src/callable/mod.rs +64 -0
- package/crates/enact-core/src/callable/registry.rs +206 -0
- package/crates/enact-core/src/context/execution_context.rs +757 -0
- package/crates/enact-core/src/context/invocation.rs +99 -0
- package/crates/enact-core/src/context/mod.rs +50 -0
- package/crates/enact-core/src/context/tenant.rs +175 -0
- package/crates/enact-core/src/context/trace.rs +127 -0
- package/crates/enact-core/src/flow/conditional.rs +293 -0
- package/crates/enact-core/src/flow/mod.rs +43 -0
- package/crates/enact-core/src/flow/parallel.rs +437 -0
- package/crates/enact-core/src/flow/repeat.rs +534 -0
- package/crates/enact-core/src/flow/sequential.rs +248 -0
- package/crates/enact-core/src/graph/checkpoint.rs +79 -0
- package/crates/enact-core/src/graph/checkpoint_store.rs +76 -0
- package/crates/enact-core/src/graph/compiled.rs +189 -0
- package/crates/enact-core/src/graph/edge.rs +59 -0
- package/crates/enact-core/src/graph/graph_schema.rs +218 -0
- package/crates/enact-core/src/graph/loader.rs +155 -0
- package/crates/enact-core/src/graph/mod.rs +18 -0
- package/crates/enact-core/src/graph/node/function.rs +49 -0
- package/crates/enact-core/src/graph/node/mod.rs +48 -0
- package/crates/enact-core/src/graph/schema.rs +62 -0
- package/crates/enact-core/src/inbox/message.rs +405 -0
- package/crates/enact-core/src/inbox/mod.rs +31 -0
- package/crates/enact-core/src/inbox/store.rs +355 -0
- package/crates/enact-core/src/kernel/artifact/filesystem.rs +546 -0
- package/crates/enact-core/src/kernel/artifact/metadata.rs +283 -0
- package/crates/enact-core/src/kernel/artifact/mod.rs +27 -0
- package/crates/enact-core/src/kernel/artifact/store.rs +427 -0
- package/crates/enact-core/src/kernel/enforcement.rs +1315 -0
- package/crates/enact-core/src/kernel/error.rs +1200 -0
- package/crates/enact-core/src/kernel/event.rs +1394 -0
- package/crates/enact-core/src/kernel/execution_model.rs +831 -0
- package/crates/enact-core/src/kernel/execution_state.rs +189 -0
- package/crates/enact-core/src/kernel/execution_strategy.rs +117 -0
- package/crates/enact-core/src/kernel/ids.rs +2086 -0
- package/crates/enact-core/src/kernel/interrupt.rs +125 -0
- package/crates/enact-core/src/kernel/kernel.rs +1283 -0
- package/crates/enact-core/src/kernel/mod.rs +205 -0
- package/crates/enact-core/src/kernel/persistence/event_store.rs +270 -0
- package/crates/enact-core/src/kernel/persistence/message_store.rs +908 -0
- package/crates/enact-core/src/kernel/persistence/mod.rs +102 -0
- package/crates/enact-core/src/kernel/persistence/state_store.rs +228 -0
- package/crates/enact-core/src/kernel/persistence/vector_store.rs +299 -0
- package/crates/enact-core/src/kernel/reducer.rs +808 -0
- package/crates/enact-core/src/kernel/replay.rs +153 -0
- package/crates/enact-core/src/lib.rs +413 -0
- package/crates/enact-core/src/memory/episodic.rs +0 -0
- package/crates/enact-core/src/memory/mod.rs +6 -0
- package/crates/enact-core/src/memory/semantic.rs +0 -0
- package/crates/enact-core/src/memory/trait.rs +0 -0
- package/crates/enact-core/src/memory/vector_db.rs +0 -0
- package/crates/enact-core/src/memory/working.rs +0 -0
- package/crates/enact-core/src/policy/execution_policy.rs +292 -0
- package/crates/enact-core/src/policy/filters.rs +458 -0
- package/crates/enact-core/src/policy/input_processor.rs +407 -0
- package/crates/enact-core/src/policy/long_running.rs +134 -0
- package/crates/enact-core/src/policy/mod.rs +193 -0
- package/crates/enact-core/src/policy/pii_input.rs +274 -0
- package/crates/enact-core/src/policy/tenant_policy.rs +453 -0
- package/crates/enact-core/src/policy/tool_policy.rs +407 -0
- package/crates/enact-core/src/providers/mod.rs +63 -0
- package/crates/enact-core/src/providers/trait.rs +292 -0
- package/crates/enact-core/src/runner/callbacks.rs +6 -0
- package/crates/enact-core/src/runner/execution_runner.rs +476 -0
- package/crates/enact-core/src/runner/loop.rs +117 -0
- package/crates/enact-core/src/runner/mod.rs +58 -0
- package/crates/enact-core/src/runner/protected_runner.rs +280 -0
- package/crates/enact-core/src/signal/inmemory.rs +231 -0
- package/crates/enact-core/src/signal/mod.rs +108 -0
- package/crates/enact-core/src/streaming/event_logger.rs +195 -0
- package/crates/enact-core/src/streaming/event_stream.rs +1423 -0
- package/crates/enact-core/src/streaming/mod.rs +108 -0
- package/crates/enact-core/src/streaming/pause_cancel.rs +0 -0
- package/crates/enact-core/src/streaming/protected_emitter.rs +173 -0
- package/crates/enact-core/src/streaming/protection/context.rs +136 -0
- package/crates/enact-core/src/streaming/protection/encryption.rs +289 -0
- package/crates/enact-core/src/streaming/protection/mod.rs +43 -0
- package/crates/enact-core/src/streaming/protection/pii_protection.rs +243 -0
- package/crates/enact-core/src/streaming/protection/processor.rs +166 -0
- package/crates/enact-core/src/streaming/sse.rs +0 -0
- package/crates/enact-core/src/telemetry/exporter.rs +0 -0
- package/crates/enact-core/src/telemetry/init.rs +0 -0
- package/crates/enact-core/src/telemetry/mod.rs +49 -0
- package/crates/enact-core/src/telemetry/spans.rs +245 -0
- package/crates/enact-core/src/tool/agent_tool.rs +177 -0
- package/crates/enact-core/src/tool/browser/mod.rs +0 -0
- package/crates/enact-core/src/tool/browser/webdriver.rs +0 -0
- package/crates/enact-core/src/tool/cost.rs +247 -0
- package/crates/enact-core/src/tool/discovery.rs +0 -0
- package/crates/enact-core/src/tool/dispatcher.rs +347 -0
- package/crates/enact-core/src/tool/filesystem.rs +231 -0
- package/crates/enact-core/src/tool/function.rs +99 -0
- package/crates/enact-core/src/tool/git.rs +162 -0
- package/crates/enact-core/src/tool/http.rs +214 -0
- package/crates/enact-core/src/tool/mcp/client.rs +0 -0
- package/crates/enact-core/src/tool/mcp/mod.rs +0 -0
- package/crates/enact-core/src/tool/mod.rs +51 -0
- package/crates/enact-core/src/tool/reasoning/debugging.rs +0 -0
- package/crates/enact-core/src/tool/reasoning/mcts.rs +0 -0
- package/crates/enact-core/src/tool/reasoning/mod.rs +0 -0
- package/crates/enact-core/src/tool/reasoning/sequential.rs +0 -0
- package/crates/enact-core/src/tool/sandbox/dagger.rs +0 -0
- package/crates/enact-core/src/tool/sandbox/mod.rs +0 -0
- package/crates/enact-core/src/tool/shell.rs +147 -0
- package/crates/enact-core/src/tool/trait.rs +33 -0
- package/crates/enact-core/src/tool/web_search.rs +277 -0
- package/crates/enact-core/src/util/config.rs +0 -0
- package/crates/enact-core/src/util/errors.rs +0 -0
- package/crates/enact-core/src/util/mod.rs +6 -0
- package/crates/enact-core/tests/airgapped_e2e_test.rs +291 -0
- package/crates/enact-core/tests/e2e_agentic_loop.rs +119 -0
- package/crates/enact-core/tests/e2e_test.rs +259 -0
- package/crates/enact-core/tests/graph_test.rs +130 -0
- package/crates/enact-core/tests/stream_event_id_validation.rs +435 -0
- package/crates/enact-cron/Cargo.toml +28 -0
- package/crates/enact-cron/src/lib.rs +44 -0
- package/crates/enact-cron/src/schedule.rs +156 -0
- package/crates/enact-cron/src/store.rs +589 -0
- package/crates/enact-cron/src/types.rs +148 -0
- package/crates/enact-gateway/Cargo.toml +31 -0
- package/crates/enact-gateway/README.md +30 -0
- package/crates/enact-gateway/examples/whatsapp-gateway-runner-mock.rs +59 -0
- package/crates/enact-gateway/examples/whatsapp-gateway.rs +42 -0
- package/crates/enact-gateway/src/lib.rs +582 -0
- package/crates/enact-mcp/Cargo.toml +24 -0
- package/crates/enact-mcp/src/lib.rs +178 -0
- package/crates/enact-memory/Cargo.toml +25 -0
- package/crates/enact-memory/src/backend.rs +20 -0
- package/crates/enact-memory/src/chunker.rs +230 -0
- package/crates/enact-memory/src/embeddings.rs +221 -0
- package/crates/enact-memory/src/lib.rs +67 -0
- package/crates/enact-memory/src/markdown.rs +127 -0
- package/crates/enact-memory/src/none.rs +61 -0
- package/crates/enact-memory/src/sqlite.rs +276 -0
- package/crates/enact-memory/src/traits.rs +65 -0
- package/crates/enact-memory/src/vector.rs +198 -0
- package/crates/enact-oauth/Cargo.toml +27 -0
- package/crates/enact-oauth/src/lib.rs +584 -0
- package/crates/enact-observability/Cargo.toml +22 -0
- package/crates/enact-observability/src/lib.rs +197 -0
- package/crates/enact-providers/Cargo.toml +33 -0
- package/crates/enact-providers/examples/hello-agent.rs +33 -0
- package/crates/enact-providers/src/anthropic.rs +182 -0
- package/crates/enact-providers/src/azure.rs +96 -0
- package/crates/enact-providers/src/bridge.rs +221 -0
- package/crates/enact-providers/src/gemini.rs +227 -0
- package/crates/enact-providers/src/http.rs +78 -0
- package/crates/enact-providers/src/lib.rs +53 -0
- package/crates/enact-providers/src/openai_compatible.rs +167 -0
- package/crates/enact-providers/src/openrouter.rs +33 -0
- package/crates/enact-runner/Cargo.toml +24 -0
- package/crates/enact-runner/README.md +76 -0
- package/crates/enact-runner/src/compaction.rs +225 -0
- package/crates/enact-runner/src/config.rs +118 -0
- package/crates/enact-runner/src/lib.rs +63 -0
- package/crates/enact-runner/src/loop_driver.rs +414 -0
- package/crates/enact-runner/src/parser.rs +421 -0
- package/crates/enact-runner/src/retry.rs +262 -0
- package/crates/enact-runner/tests/integration.rs +278 -0
- package/crates/enact-security/Cargo.toml +22 -0
- package/crates/enact-security/src/audit.rs +375 -0
- package/crates/enact-security/src/lib.rs +37 -0
- package/crates/enact-security/src/policy.rs +406 -0
- package/crates/enact-skills/Cargo.toml +25 -0
- package/crates/enact-skills/src/lib.rs +506 -0
- package/crates/enact-tools/Cargo.toml +22 -0
- package/crates/enact-tools/src/file_read.rs +166 -0
- package/crates/enact-tools/src/file_write.rs +216 -0
- package/crates/enact-tools/src/git_operations.rs +513 -0
- package/crates/enact-tools/src/http_request.rs +417 -0
- package/crates/enact-tools/src/lib.rs +104 -0
- package/crates/enact-tools/src/security.rs +227 -0
- package/crates/enact-tools/src/shell.rs +191 -0
- package/crates/enact-tools/src/traits.rs +159 -0
- package/docs/Makefile +74 -0
- package/docs/config.toml +62 -0
- package/docs/content/_index.md +174 -0
- package/docs/content/a2a/_index.md +431 -0
- package/docs/content/api/_index.md +323 -0
- package/docs/content/channels/_index.md +160 -0
- package/docs/content/channels/teams.md +205 -0
- package/docs/content/channels/telegram.md +182 -0
- package/docs/content/channels/webhook.md +423 -0
- package/docs/content/channels/whatsapp.md +240 -0
- package/docs/content/cli/_index.md +261 -0
- package/docs/content/concepts/_index.md +273 -0
- package/docs/content/configuration/_index.md +241 -0
- package/docs/content/cron/_index.md +248 -0
- package/docs/content/developers/_index.md +278 -0
- package/docs/content/getting-started/_index.md +180 -0
- package/docs/content/installation/_index.md +186 -0
- package/docs/content/installation/uninstall.md +101 -0
- package/docs/content/installation/updating.md +120 -0
- package/docs/content/mcp/_index.md +215 -0
- package/docs/content/memory/_index.md +163 -0
- package/docs/content/oauth/_index.md +515 -0
- package/docs/content/providers/_index.md +206 -0
- package/docs/content/roadmap/_index.md +199 -0
- package/docs/content/security/_index.md +219 -0
- package/docs/content/skills/_index.md +228 -0
- package/docs/content/tools/_index.md +485 -0
- package/docs/content/troubleshooting/_index.md +259 -0
- package/docs/content/yaml-schema/_index.md +294 -0
- package/docs/static/giallo-dark.css +91 -0
- package/docs/static/giallo-light.css +91 -0
- package/docs/themes/tanuki/.github/workflows/deploy.yml +44 -0
- package/docs/themes/tanuki/LICENSE +21 -0
- package/docs/themes/tanuki/README.md +166 -0
- package/docs/themes/tanuki/examples/blog/config.toml +58 -0
- package/docs/themes/tanuki/examples/blog/content/_index.md +4 -0
- package/docs/themes/tanuki/examples/blog/content/about.md +33 -0
- package/docs/themes/tanuki/examples/blog/content/blog/_index.md +7 -0
- package/docs/themes/tanuki/examples/blog/content/blog/api-design-best-practices.md +245 -0
- package/docs/themes/tanuki/examples/blog/content/blog/building-accessible-websites.md +147 -0
- package/docs/themes/tanuki/examples/blog/content/blog/css-grid-vs-flexbox.md +165 -0
- package/docs/themes/tanuki/examples/blog/content/blog/customizing-catppuccin-colors.md +137 -0
- package/docs/themes/tanuki/examples/blog/content/blog/dark-mode-best-practices.md +82 -0
- package/docs/themes/tanuki/examples/blog/content/blog/docker-essentials.md +301 -0
- package/docs/themes/tanuki/examples/blog/content/blog/getting-started-with-zola.md +129 -0
- package/docs/themes/tanuki/examples/blog/content/blog/git-workflow-for-content.md +112 -0
- package/docs/themes/tanuki/examples/blog/content/blog/introduction-to-webassembly.md +183 -0
- package/docs/themes/tanuki/examples/blog/content/blog/modern-javascript-features.md +234 -0
- package/docs/themes/tanuki/examples/blog/content/blog/testing-strategies.md +311 -0
- package/docs/themes/tanuki/examples/blog/content/blog/typography-for-developers.md +104 -0
- package/docs/themes/tanuki/examples/blog/content/blog/welcome-to-tanuki.md +67 -0
- package/docs/themes/tanuki/examples/blog/content/blog/why-static-sites.md +85 -0
- package/docs/themes/tanuki/examples/blog/content/projects.md +64 -0
- package/docs/themes/tanuki/examples/book/config.toml +17 -0
- package/docs/themes/tanuki/examples/book/content/_index.md +12 -0
- package/docs/themes/tanuki/examples/book/content/chapter-1.md +90 -0
- package/docs/themes/tanuki/examples/book/content/chapter-2.md +143 -0
- package/docs/themes/tanuki/examples/book/content/chapter-3.md +217 -0
- package/docs/themes/tanuki/examples/book/content/chapter-4.md +224 -0
- package/docs/themes/tanuki/examples/book/content/chapter-5.md +297 -0
- package/docs/themes/tanuki/examples/book/content/print.md +6 -0
- package/docs/themes/tanuki/examples/docs/config.toml +28 -0
- package/docs/themes/tanuki/examples/docs/content/_index.md +20 -0
- package/docs/themes/tanuki/examples/docs/content/components.md +156 -0
- package/docs/themes/tanuki/examples/docs/content/configuration.md +94 -0
- package/docs/themes/tanuki/examples/docs/content/customization.md +202 -0
- package/docs/themes/tanuki/examples/docs/content/deployment.md +204 -0
- package/docs/themes/tanuki/examples/docs/content/installation.md +59 -0
- package/docs/themes/tanuki/examples/docs/content/print.md +6 -0
- package/docs/themes/tanuki/examples/docs/static/img/tanuki-icon.avif +0 -0
- package/docs/themes/tanuki/examples/index.html +2104 -0
- package/docs/themes/tanuki/mise.toml +108 -0
- package/docs/themes/tanuki/sass/base/_catppuccin.scss +164 -0
- package/docs/themes/tanuki/sass/base/_fonts.scss +64 -0
- package/docs/themes/tanuki/sass/base/_reset.scss +152 -0
- package/docs/themes/tanuki/sass/base/_typography.scss +523 -0
- package/docs/themes/tanuki/sass/components/_buttons.scss +209 -0
- package/docs/themes/tanuki/sass/components/_code.scss +457 -0
- package/docs/themes/tanuki/sass/components/_landing.scss +633 -0
- package/docs/themes/tanuki/sass/components/_layout.scss +294 -0
- package/docs/themes/tanuki/sass/components/_navigation.scss +1200 -0
- package/docs/themes/tanuki/sass/components/_print.scss +237 -0
- package/docs/themes/tanuki/sass/components/_search.scss +224 -0
- package/docs/themes/tanuki/sass/components/_sidebar.scss +473 -0
- package/docs/themes/tanuki/sass/components/_theme-toggle.scss +186 -0
- package/docs/themes/tanuki/sass/modes/_blog.scss +366 -0
- package/docs/themes/tanuki/sass/modes/_product.scss +875 -0
- package/docs/themes/tanuki/sass/modes/_raskell.scss +1696 -0
- package/docs/themes/tanuki/sass/patterns/_buttons.scss +183 -0
- package/docs/themes/tanuki/sass/patterns/_cards.scss +144 -0
- package/docs/themes/tanuki/sass/patterns/_index.scss +9 -0
- package/docs/themes/tanuki/sass/patterns/_lists.scss +259 -0
- package/docs/themes/tanuki/sass/patterns/_sections.scss +243 -0
- package/docs/themes/tanuki/sass/style.scss +47 -0
- package/docs/themes/tanuki/sass/tokens/_colors.scss +139 -0
- package/docs/themes/tanuki/sass/tokens/_spacing.scss +100 -0
- package/docs/themes/tanuki/sass/tokens/_typography.scss +186 -0
- package/docs/themes/tanuki/screenshot.png +0 -0
- package/docs/themes/tanuki/sentinel.kdl +59 -0
- package/docs/themes/tanuki/static/elasticlunr.min.js +10 -0
- package/docs/themes/tanuki/static/fonts/GEIST-LICENSE.txt +92 -0
- package/docs/themes/tanuki/static/fonts/Geist-Variable.woff2 +0 -0
- package/docs/themes/tanuki/static/fonts/GeistMono-Variable.woff2 +0 -0
- package/docs/themes/tanuki/static/img/tanuki-icon.avif +0 -0
- package/docs/themes/tanuki/static/img/tanuki-icon.png +0 -0
- package/docs/themes/tanuki/static/js/anchors.js +18 -0
- package/docs/themes/tanuki/static/js/app.js +274 -0
- package/docs/themes/tanuki/static/js/code.js +394 -0
- package/docs/themes/tanuki/static/js/navigation.js +778 -0
- package/docs/themes/tanuki/static/js/scroll-to-top.js +33 -0
- package/docs/themes/tanuki/static/js/search-raskell.js +240 -0
- package/docs/themes/tanuki/static/js/search.js +215 -0
- package/docs/themes/tanuki/static/js/theme.js +169 -0
- package/docs/themes/tanuki/static/syntax-dark.css +151 -0
- package/docs/themes/tanuki/static/syntax-light.css +151 -0
- package/docs/themes/tanuki/static/wasm/sentinel_playground_wasm.js +486 -0
- package/docs/themes/tanuki/static/wasm/sentinel_playground_wasm_bg.wasm +0 -0
- package/docs/themes/tanuki/templates/404.html +52 -0
- package/docs/themes/tanuki/templates/base.html +428 -0
- package/docs/themes/tanuki/templates/blog.html +66 -0
- package/docs/themes/tanuki/templates/home.html +108 -0
- package/docs/themes/tanuki/templates/index.html +178 -0
- package/docs/themes/tanuki/templates/landing.html +168 -0
- package/docs/themes/tanuki/templates/macros/nav.html +128 -0
- package/docs/themes/tanuki/templates/macros/posts.html +101 -0
- package/docs/themes/tanuki/templates/macros/ui.html +159 -0
- package/docs/themes/tanuki/templates/page.html +135 -0
- package/docs/themes/tanuki/templates/partials/footer.html +38 -0
- package/docs/themes/tanuki/templates/partials/header.html +366 -0
- package/docs/themes/tanuki/templates/partials/nav-buttons.html +55 -0
- package/docs/themes/tanuki/templates/partials/nav-overlay.html +81 -0
- package/docs/themes/tanuki/templates/partials/page-toc-panel.html +43 -0
- package/docs/themes/tanuki/templates/partials/search.html +52 -0
- package/docs/themes/tanuki/templates/partials/sidebar.html +107 -0
- package/docs/themes/tanuki/templates/partials/theme-toggle.html +35 -0
- package/docs/themes/tanuki/templates/partials/toc-overlay.html +146 -0
- package/docs/themes/tanuki/templates/partials/version-picker.html +38 -0
- package/docs/themes/tanuki/templates/print.html +244 -0
- package/docs/themes/tanuki/templates/section.html +186 -0
- package/docs/themes/tanuki/templates/taxonomy_list.html +18 -0
- package/docs/themes/tanuki/templates/taxonomy_single.html +31 -0
- package/docs/themes/tanuki/theme.toml +58 -0
- package/examples/hello-agent.rs +55 -0
- package/package.json +36 -0
- package/proto/config.proto +60 -0
- package/proto/events.proto +0 -0
- package/proto/runtime.proto +215 -0
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
use anyhow::Context;
|
|
2
|
+
use async_trait::async_trait;
|
|
3
|
+
use axum::body::Bytes;
|
|
4
|
+
use axum::extract::{ConnectInfo, Query, State};
|
|
5
|
+
use axum::http::{HeaderMap, StatusCode};
|
|
6
|
+
use axum::response::{IntoResponse, Response};
|
|
7
|
+
use axum::routing::{get, post};
|
|
8
|
+
use axum::{Json, Router};
|
|
9
|
+
use enact_channels::{Channel, ChannelMessage, SendMessage, WhatsAppChannel, verify_whatsapp_signature};
|
|
10
|
+
use enact_core::callable::Callable;
|
|
11
|
+
use enact_runner::{DefaultAgentRunner, LoopOutcome};
|
|
12
|
+
use serde::Deserialize;
|
|
13
|
+
use serde::Serialize;
|
|
14
|
+
use sha2::{Digest, Sha256};
|
|
15
|
+
use std::collections::HashMap;
|
|
16
|
+
use std::net::{IpAddr, SocketAddr};
|
|
17
|
+
use std::sync::{Arc, Mutex};
|
|
18
|
+
use std::time::{Duration, Instant};
|
|
19
|
+
use tower_http::limit::RequestBodyLimitLayer;
|
|
20
|
+
use tower_http::timeout::TimeoutLayer;
|
|
21
|
+
|
|
22
|
+
pub const MAX_BODY_SIZE: usize = 65_536;
|
|
23
|
+
pub const REQUEST_TIMEOUT_SECS: u64 = 30;
|
|
24
|
+
|
|
25
|
+
#[derive(Debug, Clone)]
|
|
26
|
+
pub struct GatewayConfig {
|
|
27
|
+
pub host: String,
|
|
28
|
+
pub port: u16,
|
|
29
|
+
pub webhook_rate_limit_per_minute: u32,
|
|
30
|
+
pub max_rate_limit_keys: usize,
|
|
31
|
+
pub idempotency_ttl_secs: u64,
|
|
32
|
+
pub idempotency_max_keys: usize,
|
|
33
|
+
pub trust_forwarded_headers: bool,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
impl Default for GatewayConfig {
|
|
37
|
+
fn default() -> Self {
|
|
38
|
+
Self {
|
|
39
|
+
host: "0.0.0.0".to_string(),
|
|
40
|
+
port: 8080,
|
|
41
|
+
webhook_rate_limit_per_minute: 120,
|
|
42
|
+
max_rate_limit_keys: 10_000,
|
|
43
|
+
idempotency_ttl_secs: 300,
|
|
44
|
+
idempotency_max_keys: 10_000,
|
|
45
|
+
trust_forwarded_headers: false,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#[derive(Clone)]
|
|
51
|
+
pub struct GatewayState {
|
|
52
|
+
pub whatsapp: Arc<WhatsAppChannel>,
|
|
53
|
+
pub app_secret: Option<Arc<str>>,
|
|
54
|
+
pub responder: Arc<dyn InboundResponder>,
|
|
55
|
+
pub rate_limiter: Arc<GatewayRateLimiter>,
|
|
56
|
+
pub idempotency_store: Arc<IdempotencyStore>,
|
|
57
|
+
pub trust_forwarded_headers: bool,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
impl GatewayState {
|
|
61
|
+
pub fn new(
|
|
62
|
+
whatsapp: Arc<WhatsAppChannel>,
|
|
63
|
+
app_secret: Option<String>,
|
|
64
|
+
responder: Arc<dyn InboundResponder>,
|
|
65
|
+
config: &GatewayConfig,
|
|
66
|
+
) -> Self {
|
|
67
|
+
Self {
|
|
68
|
+
whatsapp,
|
|
69
|
+
app_secret: app_secret.map(Arc::<str>::from),
|
|
70
|
+
responder,
|
|
71
|
+
rate_limiter: Arc::new(GatewayRateLimiter::new(
|
|
72
|
+
config.webhook_rate_limit_per_minute,
|
|
73
|
+
Duration::from_secs(60),
|
|
74
|
+
config.max_rate_limit_keys,
|
|
75
|
+
)),
|
|
76
|
+
idempotency_store: Arc::new(IdempotencyStore::new(
|
|
77
|
+
Duration::from_secs(config.idempotency_ttl_secs),
|
|
78
|
+
config.idempotency_max_keys,
|
|
79
|
+
)),
|
|
80
|
+
trust_forwarded_headers: config.trust_forwarded_headers,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#[async_trait]
|
|
86
|
+
pub trait InboundResponder: Send + Sync {
|
|
87
|
+
async fn handle(&self, message: &ChannelMessage) -> anyhow::Result<Option<String>>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
pub struct EchoResponder;
|
|
91
|
+
|
|
92
|
+
#[async_trait]
|
|
93
|
+
impl InboundResponder for EchoResponder {
|
|
94
|
+
async fn handle(&self, message: &ChannelMessage) -> anyhow::Result<Option<String>> {
|
|
95
|
+
Ok(Some(format!("echo: {}", message.content)))
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// Inbound responder that routes each message through `enact-runner`.
|
|
100
|
+
pub struct RunnerResponder {
|
|
101
|
+
runner: tokio::sync::Mutex<DefaultAgentRunner>,
|
|
102
|
+
callable: Arc<dyn Callable>,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
impl RunnerResponder {
|
|
106
|
+
pub fn new(callable: Arc<dyn Callable>) -> Self {
|
|
107
|
+
Self {
|
|
108
|
+
runner: tokio::sync::Mutex::new(DefaultAgentRunner::default_new()),
|
|
109
|
+
callable,
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
pub fn with_runner(callable: Arc<dyn Callable>, runner: DefaultAgentRunner) -> Self {
|
|
114
|
+
Self {
|
|
115
|
+
runner: tokio::sync::Mutex::new(runner),
|
|
116
|
+
callable,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#[async_trait]
|
|
122
|
+
impl InboundResponder for RunnerResponder {
|
|
123
|
+
async fn handle(&self, message: &ChannelMessage) -> anyhow::Result<Option<String>> {
|
|
124
|
+
let mut runner = self.runner.lock().await;
|
|
125
|
+
let outcome = runner.run(self.callable.as_ref(), &message.content).await?;
|
|
126
|
+
match outcome {
|
|
127
|
+
LoopOutcome::Completed(text) => Ok(Some(text)),
|
|
128
|
+
LoopOutcome::MaxIterationsReached { last_output, .. } => Ok(Some(last_output)),
|
|
129
|
+
LoopOutcome::Cancelled => Ok(Some("Execution cancelled".to_string())),
|
|
130
|
+
LoopOutcome::TimedOut { elapsed_secs } => {
|
|
131
|
+
Ok(Some(format!("Execution timed out after {}s", elapsed_secs)))
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
pub fn router(state: GatewayState) -> Router {
|
|
138
|
+
Router::new()
|
|
139
|
+
.route("/health", get(health_handler))
|
|
140
|
+
.route("/webhook/whatsapp", get(whatsapp_verify_handler))
|
|
141
|
+
.route("/webhook/whatsapp", post(whatsapp_webhook_handler))
|
|
142
|
+
.with_state(state)
|
|
143
|
+
.layer(TimeoutLayer::new(Duration::from_secs(REQUEST_TIMEOUT_SECS)))
|
|
144
|
+
.layer(RequestBodyLimitLayer::new(MAX_BODY_SIZE))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
pub async fn serve(config: GatewayConfig, state: GatewayState) -> anyhow::Result<()> {
|
|
148
|
+
let addr: SocketAddr = format!("{}:{}", config.host, config.port)
|
|
149
|
+
.parse()
|
|
150
|
+
.with_context(|| "failed to parse gateway bind address")?;
|
|
151
|
+
let listener = tokio::net::TcpListener::bind(addr)
|
|
152
|
+
.await
|
|
153
|
+
.with_context(|| format!("failed to bind gateway listener on {addr}"))?;
|
|
154
|
+
tracing::info!("gateway listening on http://{addr}");
|
|
155
|
+
axum::serve(listener, router(state)).await?;
|
|
156
|
+
Ok(())
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#[derive(Debug, Serialize)]
|
|
160
|
+
struct HealthResponse {
|
|
161
|
+
status: &'static str,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async fn health_handler() -> impl IntoResponse {
|
|
165
|
+
Json(HealthResponse { status: "ok" })
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#[derive(Debug, Deserialize)]
|
|
169
|
+
struct VerifyQuery {
|
|
170
|
+
#[serde(rename = "hub.mode")]
|
|
171
|
+
mode: Option<String>,
|
|
172
|
+
#[serde(rename = "hub.verify_token")]
|
|
173
|
+
verify_token: Option<String>,
|
|
174
|
+
#[serde(rename = "hub.challenge")]
|
|
175
|
+
challenge: Option<String>,
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async fn whatsapp_verify_handler(
|
|
179
|
+
State(state): State<GatewayState>,
|
|
180
|
+
Query(query): Query<VerifyQuery>,
|
|
181
|
+
) -> Response {
|
|
182
|
+
let token_matches = query
|
|
183
|
+
.verify_token
|
|
184
|
+
.as_deref()
|
|
185
|
+
.is_some_and(|token| token == state.whatsapp.verify_token());
|
|
186
|
+
|
|
187
|
+
if query.mode.as_deref() == Some("subscribe") && token_matches {
|
|
188
|
+
if let Some(challenge) = query.challenge {
|
|
189
|
+
return (StatusCode::OK, challenge).into_response();
|
|
190
|
+
}
|
|
191
|
+
return (
|
|
192
|
+
StatusCode::BAD_REQUEST,
|
|
193
|
+
Json(serde_json::json!({"error": "missing hub.challenge"})),
|
|
194
|
+
)
|
|
195
|
+
.into_response();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
(
|
|
199
|
+
StatusCode::FORBIDDEN,
|
|
200
|
+
Json(serde_json::json!({"error": "forbidden"})),
|
|
201
|
+
)
|
|
202
|
+
.into_response()
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async fn whatsapp_webhook_handler(
|
|
206
|
+
State(state): State<GatewayState>,
|
|
207
|
+
connect_info: Option<ConnectInfo<SocketAddr>>,
|
|
208
|
+
headers: HeaderMap,
|
|
209
|
+
body: Bytes,
|
|
210
|
+
) -> Response {
|
|
211
|
+
let peer_addr = connect_info.map(|ConnectInfo(addr)| addr);
|
|
212
|
+
let client_key = client_key_from_request(
|
|
213
|
+
peer_addr,
|
|
214
|
+
&headers,
|
|
215
|
+
state.trust_forwarded_headers,
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
if !state.rate_limiter.allow(&client_key) {
|
|
219
|
+
return (
|
|
220
|
+
StatusCode::TOO_MANY_REQUESTS,
|
|
221
|
+
Json(serde_json::json!({"error": "rate limit exceeded"})),
|
|
222
|
+
)
|
|
223
|
+
.into_response();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let idempotency_key = extract_idempotency_key(&headers, &body);
|
|
227
|
+
if !state.idempotency_store.record_if_new(&idempotency_key) {
|
|
228
|
+
return (
|
|
229
|
+
StatusCode::OK,
|
|
230
|
+
Json(serde_json::json!({"status": "duplicate_ignored"})),
|
|
231
|
+
)
|
|
232
|
+
.into_response();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if let Some(secret) = state.app_secret.as_deref() {
|
|
236
|
+
let signature = headers
|
|
237
|
+
.get("X-Hub-Signature-256")
|
|
238
|
+
.and_then(|v| v.to_str().ok())
|
|
239
|
+
.unwrap_or_default();
|
|
240
|
+
if !verify_whatsapp_signature(secret, &body, signature) {
|
|
241
|
+
return (
|
|
242
|
+
StatusCode::UNAUTHORIZED,
|
|
243
|
+
Json(serde_json::json!({"error": "invalid signature"})),
|
|
244
|
+
)
|
|
245
|
+
.into_response();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
let payload: serde_json::Value = match serde_json::from_slice(&body) {
|
|
250
|
+
Ok(value) => value,
|
|
251
|
+
Err(_) => {
|
|
252
|
+
return (
|
|
253
|
+
StatusCode::BAD_REQUEST,
|
|
254
|
+
Json(serde_json::json!({"error": "invalid JSON payload"})),
|
|
255
|
+
)
|
|
256
|
+
.into_response();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
let messages = state.whatsapp.parse_webhook_payload(&payload);
|
|
261
|
+
let mut processed = 0usize;
|
|
262
|
+
|
|
263
|
+
for message in messages {
|
|
264
|
+
processed += 1;
|
|
265
|
+
match state.responder.handle(&message).await {
|
|
266
|
+
Ok(Some(reply_text)) => {
|
|
267
|
+
if let Err(err) = state
|
|
268
|
+
.whatsapp
|
|
269
|
+
.send(&SendMessage::new(reply_text, &message.reply_target))
|
|
270
|
+
.await
|
|
271
|
+
{
|
|
272
|
+
tracing::warn!("failed to send whatsapp reply: {err}");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
Ok(None) => {}
|
|
276
|
+
Err(err) => {
|
|
277
|
+
tracing::warn!("inbound responder failed: {err}");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
(
|
|
283
|
+
StatusCode::OK,
|
|
284
|
+
Json(serde_json::json!({"status": "ok", "processed": processed})),
|
|
285
|
+
)
|
|
286
|
+
.into_response()
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
fn extract_idempotency_key(headers: &HeaderMap, body: &[u8]) -> String {
|
|
290
|
+
if let Some(key) = headers
|
|
291
|
+
.get("X-Idempotency-Key")
|
|
292
|
+
.and_then(|v| v.to_str().ok())
|
|
293
|
+
.filter(|s| !s.trim().is_empty())
|
|
294
|
+
{
|
|
295
|
+
return key.to_string();
|
|
296
|
+
}
|
|
297
|
+
let mut hasher = Sha256::new();
|
|
298
|
+
hasher.update(body);
|
|
299
|
+
format!("body:{}", hex::encode(hasher.finalize()))
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
#[derive(Debug)]
|
|
303
|
+
pub struct GatewayRateLimiter {
|
|
304
|
+
limit_per_window: u32,
|
|
305
|
+
window: Duration,
|
|
306
|
+
max_keys: usize,
|
|
307
|
+
requests: Mutex<HashMap<String, Vec<Instant>>>,
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
impl GatewayRateLimiter {
|
|
311
|
+
pub fn new(limit_per_window: u32, window: Duration, max_keys: usize) -> Self {
|
|
312
|
+
Self {
|
|
313
|
+
limit_per_window,
|
|
314
|
+
window,
|
|
315
|
+
max_keys: max_keys.max(1),
|
|
316
|
+
requests: Mutex::new(HashMap::new()),
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
pub fn allow(&self, key: &str) -> bool {
|
|
321
|
+
if self.limit_per_window == 0 {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
let now = Instant::now();
|
|
326
|
+
let cutoff = now.checked_sub(self.window).unwrap_or_else(Instant::now);
|
|
327
|
+
let mut requests = self.requests.lock().expect("rate limiter mutex poisoned");
|
|
328
|
+
|
|
329
|
+
requests.retain(|_, timestamps| {
|
|
330
|
+
timestamps.retain(|ts| *ts > cutoff);
|
|
331
|
+
!timestamps.is_empty()
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
if !requests.contains_key(key) && requests.len() >= self.max_keys {
|
|
335
|
+
let evict_key = requests
|
|
336
|
+
.iter()
|
|
337
|
+
.min_by_key(|(_, timestamps)| timestamps.last().copied().unwrap_or(cutoff))
|
|
338
|
+
.map(|(k, _)| k.clone());
|
|
339
|
+
if let Some(evict_key) = evict_key {
|
|
340
|
+
requests.remove(&evict_key);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
let entry = requests.entry(key.to_string()).or_default();
|
|
345
|
+
entry.retain(|ts| *ts > cutoff);
|
|
346
|
+
if entry.len() >= self.limit_per_window as usize {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
entry.push(now);
|
|
350
|
+
true
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
#[derive(Debug)]
|
|
355
|
+
pub struct IdempotencyStore {
|
|
356
|
+
ttl: Duration,
|
|
357
|
+
max_keys: usize,
|
|
358
|
+
keys: Mutex<HashMap<String, Instant>>,
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
impl IdempotencyStore {
|
|
362
|
+
pub fn new(ttl: Duration, max_keys: usize) -> Self {
|
|
363
|
+
Self {
|
|
364
|
+
ttl,
|
|
365
|
+
max_keys: max_keys.max(1),
|
|
366
|
+
keys: Mutex::new(HashMap::new()),
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
pub fn record_if_new(&self, key: &str) -> bool {
|
|
371
|
+
let now = Instant::now();
|
|
372
|
+
let mut keys = self.keys.lock().expect("idempotency mutex poisoned");
|
|
373
|
+
keys.retain(|_, ts| now.duration_since(*ts) < self.ttl);
|
|
374
|
+
|
|
375
|
+
if keys.contains_key(key) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if keys.len() >= self.max_keys {
|
|
380
|
+
let evict = keys.iter().min_by_key(|(_, ts)| *ts).map(|(k, _)| k.clone());
|
|
381
|
+
if let Some(evict) = evict {
|
|
382
|
+
keys.remove(&evict);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
keys.insert(key.to_string(), now);
|
|
387
|
+
true
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
fn parse_client_ip(value: &str) -> Option<IpAddr> {
|
|
392
|
+
let value = value.trim().trim_matches('"');
|
|
393
|
+
if value.is_empty() {
|
|
394
|
+
return None;
|
|
395
|
+
}
|
|
396
|
+
if let Ok(ip) = value.parse::<IpAddr>() {
|
|
397
|
+
return Some(ip);
|
|
398
|
+
}
|
|
399
|
+
if let Ok(addr) = value.parse::<SocketAddr>() {
|
|
400
|
+
return Some(addr.ip());
|
|
401
|
+
}
|
|
402
|
+
let value = value.trim_matches(['[', ']']);
|
|
403
|
+
value.parse::<IpAddr>().ok()
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
fn forwarded_client_ip(headers: &HeaderMap) -> Option<IpAddr> {
|
|
407
|
+
if let Some(xff) = headers.get("X-Forwarded-For").and_then(|v| v.to_str().ok()) {
|
|
408
|
+
for candidate in xff.split(',') {
|
|
409
|
+
if let Some(ip) = parse_client_ip(candidate) {
|
|
410
|
+
return Some(ip);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
headers
|
|
415
|
+
.get("X-Real-IP")
|
|
416
|
+
.and_then(|v| v.to_str().ok())
|
|
417
|
+
.and_then(parse_client_ip)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
fn client_key_from_request(
|
|
421
|
+
peer_addr: Option<SocketAddr>,
|
|
422
|
+
headers: &HeaderMap,
|
|
423
|
+
trust_forwarded_headers: bool,
|
|
424
|
+
) -> String {
|
|
425
|
+
if trust_forwarded_headers {
|
|
426
|
+
if let Some(ip) = forwarded_client_ip(headers) {
|
|
427
|
+
return ip.to_string();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
peer_addr
|
|
431
|
+
.map(|addr| addr.ip().to_string())
|
|
432
|
+
.unwrap_or_else(|| "unknown".to_string())
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
#[cfg(test)]
|
|
436
|
+
mod tests {
|
|
437
|
+
use super::*;
|
|
438
|
+
use async_trait::async_trait;
|
|
439
|
+
use axum::http::Request;
|
|
440
|
+
use enact_core::callable::Callable;
|
|
441
|
+
use hmac::{Hmac, Mac};
|
|
442
|
+
use sha2::Sha256;
|
|
443
|
+
use tower::util::ServiceExt;
|
|
444
|
+
|
|
445
|
+
struct NoopResponder;
|
|
446
|
+
|
|
447
|
+
struct StaticCallable;
|
|
448
|
+
|
|
449
|
+
#[async_trait]
|
|
450
|
+
impl Callable for StaticCallable {
|
|
451
|
+
fn name(&self) -> &str {
|
|
452
|
+
"static_callable"
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
async fn run(&self, _input: &str) -> anyhow::Result<String> {
|
|
456
|
+
Ok("runner ok".to_string())
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
#[async_trait]
|
|
461
|
+
impl InboundResponder for NoopResponder {
|
|
462
|
+
async fn handle(&self, _message: &ChannelMessage) -> anyhow::Result<Option<String>> {
|
|
463
|
+
Ok(None)
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
fn build_state(app_secret: Option<&str>) -> GatewayState {
|
|
468
|
+
let channel = Arc::new(WhatsAppChannel::new(
|
|
469
|
+
"token".to_string(),
|
|
470
|
+
"endpoint".to_string(),
|
|
471
|
+
"verify-token".to_string(),
|
|
472
|
+
vec!["*".to_string()],
|
|
473
|
+
));
|
|
474
|
+
let cfg = GatewayConfig::default();
|
|
475
|
+
GatewayState::new(
|
|
476
|
+
channel,
|
|
477
|
+
app_secret.map(|s| s.to_string()),
|
|
478
|
+
Arc::new(NoopResponder),
|
|
479
|
+
&cfg,
|
|
480
|
+
)
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
#[tokio::test]
|
|
484
|
+
async fn health_route_returns_ok() {
|
|
485
|
+
let app = router(build_state(None));
|
|
486
|
+
let req = Request::builder()
|
|
487
|
+
.uri("/health")
|
|
488
|
+
.body(axum::body::Body::empty())
|
|
489
|
+
.unwrap();
|
|
490
|
+
let res = app.oneshot(req).await.unwrap();
|
|
491
|
+
assert_eq!(res.status(), StatusCode::OK);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
#[tokio::test]
|
|
495
|
+
async fn whatsapp_verify_route_returns_challenge() {
|
|
496
|
+
let app = router(build_state(None));
|
|
497
|
+
let req = Request::builder()
|
|
498
|
+
.uri("/webhook/whatsapp?hub.mode=subscribe&hub.verify_token=verify-token&hub.challenge=123")
|
|
499
|
+
.body(axum::body::Body::empty())
|
|
500
|
+
.unwrap();
|
|
501
|
+
let res = app.oneshot(req).await.unwrap();
|
|
502
|
+
assert_eq!(res.status(), StatusCode::OK);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
#[tokio::test]
|
|
506
|
+
async fn whatsapp_webhook_rejects_invalid_signature() {
|
|
507
|
+
let app = router(build_state(Some("test_secret")));
|
|
508
|
+
let body = serde_json::json!({"entry": []}).to_string();
|
|
509
|
+
let req = Request::builder()
|
|
510
|
+
.method("POST")
|
|
511
|
+
.uri("/webhook/whatsapp")
|
|
512
|
+
.header("Content-Type", "application/json")
|
|
513
|
+
.header("X-Hub-Signature-256", "sha256=bad")
|
|
514
|
+
.body(axum::body::Body::from(body))
|
|
515
|
+
.unwrap();
|
|
516
|
+
let res = app.oneshot(req).await.unwrap();
|
|
517
|
+
assert_eq!(res.status(), StatusCode::UNAUTHORIZED);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
#[tokio::test]
|
|
521
|
+
async fn webhook_duplicate_payload_is_ignored() {
|
|
522
|
+
let app = router(build_state(None));
|
|
523
|
+
let body = serde_json::json!({"entry": []}).to_string();
|
|
524
|
+
|
|
525
|
+
let req1 = Request::builder()
|
|
526
|
+
.method("POST")
|
|
527
|
+
.uri("/webhook/whatsapp")
|
|
528
|
+
.header("Content-Type", "application/json")
|
|
529
|
+
.header("X-Idempotency-Key", "abc")
|
|
530
|
+
.body(axum::body::Body::from(body.clone()))
|
|
531
|
+
.unwrap();
|
|
532
|
+
let res1 = app.clone().oneshot(req1).await.unwrap();
|
|
533
|
+
assert_eq!(res1.status(), StatusCode::OK);
|
|
534
|
+
|
|
535
|
+
let req2 = Request::builder()
|
|
536
|
+
.method("POST")
|
|
537
|
+
.uri("/webhook/whatsapp")
|
|
538
|
+
.header("Content-Type", "application/json")
|
|
539
|
+
.header("X-Idempotency-Key", "abc")
|
|
540
|
+
.body(axum::body::Body::from(body))
|
|
541
|
+
.unwrap();
|
|
542
|
+
let res2 = app.oneshot(req2).await.unwrap();
|
|
543
|
+
assert_eq!(res2.status(), StatusCode::OK);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
#[tokio::test]
|
|
547
|
+
async fn webhook_accepts_valid_signature() {
|
|
548
|
+
let app = router(build_state(Some("test_secret")));
|
|
549
|
+
let body = serde_json::json!({"entry": []}).to_string();
|
|
550
|
+
let mut mac = Hmac::<Sha256>::new_from_slice(b"test_secret").unwrap();
|
|
551
|
+
mac.update(body.as_bytes());
|
|
552
|
+
let sig = format!("sha256={}", hex::encode(mac.finalize().into_bytes()));
|
|
553
|
+
|
|
554
|
+
let req = Request::builder()
|
|
555
|
+
.method("POST")
|
|
556
|
+
.uri("/webhook/whatsapp")
|
|
557
|
+
.header("Content-Type", "application/json")
|
|
558
|
+
.header("X-Hub-Signature-256", sig)
|
|
559
|
+
.body(axum::body::Body::from(body))
|
|
560
|
+
.unwrap();
|
|
561
|
+
let res = app.oneshot(req).await.unwrap();
|
|
562
|
+
assert_eq!(res.status(), StatusCode::OK);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
#[tokio::test]
|
|
566
|
+
async fn runner_responder_returns_callable_output() {
|
|
567
|
+
let callable: Arc<dyn Callable> = Arc::new(StaticCallable);
|
|
568
|
+
let responder = RunnerResponder::new(callable);
|
|
569
|
+
|
|
570
|
+
let message = ChannelMessage {
|
|
571
|
+
id: "m1".to_string(),
|
|
572
|
+
sender: "+10000000000".to_string(),
|
|
573
|
+
reply_target: "+10000000000".to_string(),
|
|
574
|
+
content: "hello".to_string(),
|
|
575
|
+
channel: "whatsapp".to_string(),
|
|
576
|
+
timestamp: 0,
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
let out = responder.handle(&message).await.unwrap();
|
|
580
|
+
assert_eq!(out.as_deref(), Some("runner ok"));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "enact-mcp"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
license.workspace = true
|
|
6
|
+
description = "MCP (Model Context Protocol) client for Enact"
|
|
7
|
+
repository.workspace = true
|
|
8
|
+
homepage.workspace = true
|
|
9
|
+
keywords = ["mcp", "model-context-protocol", "tools", "capabilities"]
|
|
10
|
+
categories.workspace = true
|
|
11
|
+
|
|
12
|
+
[dependencies]
|
|
13
|
+
enact-core.workspace = true
|
|
14
|
+
anyhow.workspace = true
|
|
15
|
+
async-trait.workspace = true
|
|
16
|
+
tokio.workspace = true
|
|
17
|
+
tokio-util.workspace = true
|
|
18
|
+
tokio-stream.workspace = true
|
|
19
|
+
serde.workspace = true
|
|
20
|
+
serde_json.workspace = true
|
|
21
|
+
tracing.workspace = true
|
|
22
|
+
|
|
23
|
+
[dev-dependencies]
|
|
24
|
+
tempfile.workspace = true
|