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,197 @@
|
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
use std::sync::atomic::{AtomicU64, Ordering};
|
|
3
|
+
use std::time::{Duration, Instant};
|
|
4
|
+
use tracing::{info, span, Level};
|
|
5
|
+
|
|
6
|
+
/// Execution metrics for a single run
|
|
7
|
+
#[derive(Debug, Clone)]
|
|
8
|
+
pub struct ExecutionMetrics {
|
|
9
|
+
pub execution_id: String,
|
|
10
|
+
pub start_time: Instant,
|
|
11
|
+
pub end_time: Option<Instant>,
|
|
12
|
+
pub provider: String,
|
|
13
|
+
pub model: String,
|
|
14
|
+
pub input_tokens: u64,
|
|
15
|
+
pub output_tokens: u64,
|
|
16
|
+
pub total_tokens: u64,
|
|
17
|
+
pub tool_calls: u64,
|
|
18
|
+
pub errors: u64,
|
|
19
|
+
pub retries: u64,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
impl ExecutionMetrics {
|
|
23
|
+
pub fn new(execution_id: impl Into<String>) -> Self {
|
|
24
|
+
Self {
|
|
25
|
+
execution_id: execution_id.into(),
|
|
26
|
+
start_time: Instant::now(),
|
|
27
|
+
end_time: None,
|
|
28
|
+
provider: String::new(),
|
|
29
|
+
model: String::new(),
|
|
30
|
+
input_tokens: 0,
|
|
31
|
+
output_tokens: 0,
|
|
32
|
+
total_tokens: 0,
|
|
33
|
+
tool_calls: 0,
|
|
34
|
+
errors: 0,
|
|
35
|
+
retries: 0,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pub fn finish(&mut self) {
|
|
40
|
+
self.end_time = Some(Instant::now());
|
|
41
|
+
let duration = self.duration();
|
|
42
|
+
info!(
|
|
43
|
+
execution_id = %self.execution_id,
|
|
44
|
+
duration_ms = duration.as_millis() as u64,
|
|
45
|
+
input_tokens = self.input_tokens,
|
|
46
|
+
output_tokens = self.output_tokens,
|
|
47
|
+
total_tokens = self.total_tokens,
|
|
48
|
+
tool_calls = self.tool_calls,
|
|
49
|
+
errors = self.errors,
|
|
50
|
+
"Execution completed"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub fn duration(&self) -> Duration {
|
|
55
|
+
self.end_time
|
|
56
|
+
.map(|end| end.duration_since(self.start_time))
|
|
57
|
+
.unwrap_or_else(|| self.start_time.elapsed())
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// Global metrics collector
|
|
62
|
+
pub struct MetricsCollector {
|
|
63
|
+
total_executions: AtomicU64,
|
|
64
|
+
total_tokens: AtomicU64,
|
|
65
|
+
total_errors: AtomicU64,
|
|
66
|
+
total_tool_calls: AtomicU64,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
impl MetricsCollector {
|
|
70
|
+
pub fn new() -> Self {
|
|
71
|
+
Self {
|
|
72
|
+
total_executions: AtomicU64::new(0),
|
|
73
|
+
total_tokens: AtomicU64::new(0),
|
|
74
|
+
total_errors: AtomicU64::new(0),
|
|
75
|
+
total_tool_calls: AtomicU64::new(0),
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
pub fn record_execution(&self) {
|
|
80
|
+
self.total_executions.fetch_add(1, Ordering::Relaxed);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub fn record_tokens(&self, tokens: u64) {
|
|
84
|
+
self.total_tokens.fetch_add(tokens, Ordering::Relaxed);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
pub fn record_error(&self) {
|
|
88
|
+
self.total_errors.fetch_add(1, Ordering::Relaxed);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
pub fn record_tool_call(&self) {
|
|
92
|
+
self.total_tool_calls.fetch_add(1, Ordering::Relaxed);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
pub fn get_metrics(&self) -> GlobalMetrics {
|
|
96
|
+
GlobalMetrics {
|
|
97
|
+
total_executions: self.total_executions.load(Ordering::Relaxed),
|
|
98
|
+
total_tokens: self.total_tokens.load(Ordering::Relaxed),
|
|
99
|
+
total_errors: self.total_errors.load(Ordering::Relaxed),
|
|
100
|
+
total_tool_calls: self.total_tool_calls.load(Ordering::Relaxed),
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
impl Default for MetricsCollector {
|
|
106
|
+
fn default() -> Self {
|
|
107
|
+
Self::new()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#[derive(Debug, Clone)]
|
|
112
|
+
pub struct GlobalMetrics {
|
|
113
|
+
pub total_executions: u64,
|
|
114
|
+
pub total_tokens: u64,
|
|
115
|
+
pub total_errors: u64,
|
|
116
|
+
pub total_tool_calls: u64,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// Event types for structured logging
|
|
120
|
+
#[derive(Debug, Clone)]
|
|
121
|
+
pub enum ObservabilityEvent {
|
|
122
|
+
ExecutionStart {
|
|
123
|
+
execution_id: String,
|
|
124
|
+
provider: String,
|
|
125
|
+
model: String,
|
|
126
|
+
},
|
|
127
|
+
ExecutionEnd {
|
|
128
|
+
execution_id: String,
|
|
129
|
+
success: bool,
|
|
130
|
+
duration_ms: u64,
|
|
131
|
+
},
|
|
132
|
+
ToolCall {
|
|
133
|
+
execution_id: String,
|
|
134
|
+
tool_name: String,
|
|
135
|
+
success: bool,
|
|
136
|
+
},
|
|
137
|
+
Error {
|
|
138
|
+
execution_id: String,
|
|
139
|
+
error_type: String,
|
|
140
|
+
message: String,
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Initialize tracing subscriber for observability
|
|
145
|
+
pub fn init_observability() {
|
|
146
|
+
tracing_subscriber::fmt()
|
|
147
|
+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
|
148
|
+
.with_target(true)
|
|
149
|
+
.with_thread_ids(true)
|
|
150
|
+
.with_line_number(true)
|
|
151
|
+
.with_file(true)
|
|
152
|
+
.init();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/// Create a tracing span for execution tracking
|
|
156
|
+
pub fn create_execution_span(execution_id: &str, provider: &str, model: &str) -> tracing::Span {
|
|
157
|
+
span!(
|
|
158
|
+
Level::INFO,
|
|
159
|
+
"execution",
|
|
160
|
+
execution_id = %execution_id,
|
|
161
|
+
provider = %provider,
|
|
162
|
+
model = %model
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
#[cfg(test)]
|
|
167
|
+
mod tests {
|
|
168
|
+
use super::*;
|
|
169
|
+
|
|
170
|
+
#[test]
|
|
171
|
+
fn test_execution_metrics() {
|
|
172
|
+
let mut metrics = ExecutionMetrics::new("test-1");
|
|
173
|
+
metrics.input_tokens = 100;
|
|
174
|
+
metrics.output_tokens = 50;
|
|
175
|
+
metrics.total_tokens = 150;
|
|
176
|
+
metrics.finish();
|
|
177
|
+
|
|
178
|
+
assert_eq!(metrics.execution_id, "test-1");
|
|
179
|
+
assert!(metrics.duration().as_nanos() > 0);
|
|
180
|
+
assert_eq!(metrics.input_tokens, 100);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
#[test]
|
|
184
|
+
fn test_metrics_collector() {
|
|
185
|
+
let collector = MetricsCollector::new();
|
|
186
|
+
collector.record_execution();
|
|
187
|
+
collector.record_tokens(100);
|
|
188
|
+
collector.record_error();
|
|
189
|
+
collector.record_tool_call();
|
|
190
|
+
|
|
191
|
+
let metrics = collector.get_metrics();
|
|
192
|
+
assert_eq!(metrics.total_executions, 1);
|
|
193
|
+
assert_eq!(metrics.total_tokens, 100);
|
|
194
|
+
assert_eq!(metrics.total_errors, 1);
|
|
195
|
+
assert_eq!(metrics.total_tool_calls, 1);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "enact-providers"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
license.workspace = true
|
|
6
|
+
description = "LLM provider implementations for Enact - thin HTTP adapters"
|
|
7
|
+
repository.workspace = true
|
|
8
|
+
homepage.workspace = true
|
|
9
|
+
keywords = ["llm", "openai", "anthropic", "azure", "gemini", "ollama"]
|
|
10
|
+
categories.workspace = true
|
|
11
|
+
|
|
12
|
+
[dependencies]
|
|
13
|
+
enact-core = { workspace = true }
|
|
14
|
+
reqwest.workspace = true
|
|
15
|
+
async-trait.workspace = true
|
|
16
|
+
serde.workspace = true
|
|
17
|
+
serde_json.workspace = true
|
|
18
|
+
anyhow.workspace = true
|
|
19
|
+
tokio.workspace = true
|
|
20
|
+
uuid.workspace = true
|
|
21
|
+
|
|
22
|
+
[features]
|
|
23
|
+
default = [
|
|
24
|
+
"provider-azure",
|
|
25
|
+
"provider-anthropic",
|
|
26
|
+
"provider-gemini",
|
|
27
|
+
"provider-openai-compatible",
|
|
28
|
+
]
|
|
29
|
+
provider-azure = []
|
|
30
|
+
provider-anthropic = []
|
|
31
|
+
provider-gemini = []
|
|
32
|
+
provider-openrouter = []
|
|
33
|
+
provider-openai-compatible = []
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
use enact_core::providers::{ChatMessage, ChatRequest, ModelProvider};
|
|
2
|
+
use enact_providers::OpenAICompatible;
|
|
3
|
+
|
|
4
|
+
#[tokio::main]
|
|
5
|
+
async fn main() -> anyhow::Result<()> {
|
|
6
|
+
let api_key = std::env::var("OPENAI_API_KEY")
|
|
7
|
+
.map_err(|_| anyhow::anyhow!("OPENAI_API_KEY is required for this example"))?;
|
|
8
|
+
let model = std::env::var("OPENAI_MODEL").unwrap_or_else(|_| "gpt-4o-mini".to_string());
|
|
9
|
+
let base_url = std::env::var("OPENAI_BASE_URL")
|
|
10
|
+
.unwrap_or_else(|_| "https://api.openai.com".to_string());
|
|
11
|
+
|
|
12
|
+
let provider = OpenAICompatible::new(base_url, model.clone(), Some(api_key));
|
|
13
|
+
let request = ChatRequest {
|
|
14
|
+
messages: vec![
|
|
15
|
+
ChatMessage::system("You are a concise assistant."),
|
|
16
|
+
ChatMessage::user("Say hello and describe yourself in one sentence."),
|
|
17
|
+
],
|
|
18
|
+
max_tokens: Some(128),
|
|
19
|
+
temperature: Some(0.2),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let response = provider.chat(request).await?;
|
|
23
|
+
let text = response
|
|
24
|
+
.choices
|
|
25
|
+
.first()
|
|
26
|
+
.map(|c| c.message.content.as_str())
|
|
27
|
+
.unwrap_or("");
|
|
28
|
+
|
|
29
|
+
println!("Model: {}", provider.model());
|
|
30
|
+
println!("Response: {text}");
|
|
31
|
+
|
|
32
|
+
Ok(())
|
|
33
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
use crate::http::{HttpRequestSpec, post_json};
|
|
2
|
+
use async_trait::async_trait;
|
|
3
|
+
use enact_core::providers::{
|
|
4
|
+
ChatChoice, ChatMessage, ChatRequest, ChatResponse, ChatUsage, ModelCapabilities, ModelProvider,
|
|
5
|
+
};
|
|
6
|
+
use reqwest::Client;
|
|
7
|
+
use serde::{Deserialize, Serialize};
|
|
8
|
+
use std::time::Duration;
|
|
9
|
+
|
|
10
|
+
#[derive(Debug, Serialize)]
|
|
11
|
+
struct AnthropicRequest {
|
|
12
|
+
model: String,
|
|
13
|
+
max_tokens: u32,
|
|
14
|
+
temperature: f32,
|
|
15
|
+
messages: Vec<AnthropicMessage>,
|
|
16
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
17
|
+
system: Option<String>,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#[derive(Debug, Serialize)]
|
|
21
|
+
struct AnthropicMessage {
|
|
22
|
+
role: String,
|
|
23
|
+
content: String,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[derive(Debug, Deserialize)]
|
|
27
|
+
struct AnthropicResponse {
|
|
28
|
+
id: String,
|
|
29
|
+
content: Vec<AnthropicContentBlock>,
|
|
30
|
+
#[serde(default)]
|
|
31
|
+
usage: Option<AnthropicUsage>,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#[derive(Debug, Deserialize)]
|
|
35
|
+
struct AnthropicContentBlock {
|
|
36
|
+
#[serde(rename = "type")]
|
|
37
|
+
kind: String,
|
|
38
|
+
#[serde(default)]
|
|
39
|
+
text: Option<String>,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#[derive(Debug, Deserialize)]
|
|
43
|
+
struct AnthropicUsage {
|
|
44
|
+
#[serde(default)]
|
|
45
|
+
input_tokens: u32,
|
|
46
|
+
#[serde(default)]
|
|
47
|
+
output_tokens: u32,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
pub struct Anthropic {
|
|
51
|
+
client: Client,
|
|
52
|
+
api_key: String,
|
|
53
|
+
model: String,
|
|
54
|
+
base_url: String,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
impl Anthropic {
|
|
58
|
+
pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self {
|
|
59
|
+
Self {
|
|
60
|
+
client: Client::new(),
|
|
61
|
+
api_key: api_key.into(),
|
|
62
|
+
model: model.into(),
|
|
63
|
+
base_url: "https://api.anthropic.com".to_string(),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub fn with_base_url(
|
|
68
|
+
api_key: impl Into<String>,
|
|
69
|
+
model: impl Into<String>,
|
|
70
|
+
base_url: impl Into<String>,
|
|
71
|
+
) -> Self {
|
|
72
|
+
Self {
|
|
73
|
+
client: Client::new(),
|
|
74
|
+
api_key: api_key.into(),
|
|
75
|
+
model: model.into(),
|
|
76
|
+
base_url: base_url.into().trim_end_matches('/').to_string(),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fn build_url(&self) -> String {
|
|
81
|
+
format!("{}/v1/messages", self.base_url)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn convert_messages(messages: &[ChatMessage]) -> (Option<String>, Vec<AnthropicMessage>) {
|
|
85
|
+
let mut system = None;
|
|
86
|
+
let mut out = Vec::new();
|
|
87
|
+
|
|
88
|
+
for msg in messages {
|
|
89
|
+
if msg.role == "system" && system.is_none() {
|
|
90
|
+
system = Some(msg.content.clone());
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let role = if msg.role == "assistant" {
|
|
95
|
+
"assistant"
|
|
96
|
+
} else {
|
|
97
|
+
"user"
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
out.push(AnthropicMessage {
|
|
101
|
+
role: role.to_string(),
|
|
102
|
+
content: msg.content.clone(),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
(system, out)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[async_trait]
|
|
111
|
+
impl ModelProvider for Anthropic {
|
|
112
|
+
fn name(&self) -> &str {
|
|
113
|
+
"anthropic"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fn model(&self) -> &str {
|
|
117
|
+
&self.model
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
fn capabilities(&self) -> ModelCapabilities {
|
|
121
|
+
ModelCapabilities {
|
|
122
|
+
max_tokens: 200_000,
|
|
123
|
+
max_output_tokens: 8192,
|
|
124
|
+
supports_streaming: false,
|
|
125
|
+
supports_tools: true,
|
|
126
|
+
supports_vision: true,
|
|
127
|
+
supports_json_mode: true,
|
|
128
|
+
supports_embeddings: false,
|
|
129
|
+
pii_safe: false,
|
|
130
|
+
cost_per_1k_input: None,
|
|
131
|
+
cost_per_1k_output: None,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async fn chat(&self, request: ChatRequest) -> anyhow::Result<ChatResponse> {
|
|
136
|
+
let (system, messages) = Self::convert_messages(&request.messages);
|
|
137
|
+
let body = AnthropicRequest {
|
|
138
|
+
model: self.model.clone(),
|
|
139
|
+
max_tokens: request.max_tokens.unwrap_or(4096),
|
|
140
|
+
temperature: request.temperature.unwrap_or(0.7),
|
|
141
|
+
messages,
|
|
142
|
+
system,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
let spec = HttpRequestSpec {
|
|
146
|
+
url: self.build_url(),
|
|
147
|
+
headers: vec![
|
|
148
|
+
("x-api-key".to_string(), self.api_key.clone()),
|
|
149
|
+
("anthropic-version".to_string(), "2023-06-01".to_string()),
|
|
150
|
+
("content-type".to_string(), "application/json".to_string()),
|
|
151
|
+
],
|
|
152
|
+
body: serde_json::to_value(body)?,
|
|
153
|
+
timeout: Duration::from_secs(60),
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
let response: AnthropicResponse = serde_json::from_value(post_json(&self.client, spec).await?)?;
|
|
157
|
+
|
|
158
|
+
let text = response
|
|
159
|
+
.content
|
|
160
|
+
.into_iter()
|
|
161
|
+
.filter(|block| block.kind == "text")
|
|
162
|
+
.filter_map(|block| block.text)
|
|
163
|
+
.collect::<Vec<_>>()
|
|
164
|
+
.join("\n");
|
|
165
|
+
|
|
166
|
+
let usage = response.usage.map(|u| ChatUsage {
|
|
167
|
+
prompt_tokens: u.input_tokens,
|
|
168
|
+
completion_tokens: u.output_tokens,
|
|
169
|
+
total_tokens: u.input_tokens.saturating_add(u.output_tokens),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
Ok(ChatResponse {
|
|
173
|
+
id: response.id,
|
|
174
|
+
choices: vec![ChatChoice {
|
|
175
|
+
index: 0,
|
|
176
|
+
message: ChatMessage::assistant(text),
|
|
177
|
+
finish_reason: Some("stop".to_string()),
|
|
178
|
+
}],
|
|
179
|
+
usage,
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//! Azure OpenAI provider
|
|
2
|
+
|
|
3
|
+
use crate::http::{HttpRequestSpec, post_json};
|
|
4
|
+
use enact_core::providers::{ChatRequest, ChatResponse, ModelProvider};
|
|
5
|
+
use async_trait::async_trait;
|
|
6
|
+
use reqwest::Client;
|
|
7
|
+
use std::time::Duration;
|
|
8
|
+
|
|
9
|
+
/// Azure OpenAI provider
|
|
10
|
+
pub struct AzureOpenAI {
|
|
11
|
+
client: Client,
|
|
12
|
+
endpoint: String,
|
|
13
|
+
api_key: String,
|
|
14
|
+
api_version: String,
|
|
15
|
+
deployment: String,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
impl AzureOpenAI {
|
|
19
|
+
/// Create with explicit configuration
|
|
20
|
+
pub fn new(
|
|
21
|
+
endpoint: impl Into<String>,
|
|
22
|
+
api_key: impl Into<String>,
|
|
23
|
+
deployment: impl Into<String>,
|
|
24
|
+
) -> Self {
|
|
25
|
+
Self {
|
|
26
|
+
client: Client::new(),
|
|
27
|
+
endpoint: endpoint.into().trim_end_matches('/').to_string(),
|
|
28
|
+
api_key: api_key.into(),
|
|
29
|
+
api_version: "2024-02-15-preview".to_string(),
|
|
30
|
+
deployment: deployment.into(),
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fn build_url(&self) -> String {
|
|
35
|
+
// Check if endpoint already includes deployment path
|
|
36
|
+
// e.g., https://xxx.openai.azure.com/openai/deployments/
|
|
37
|
+
if self.endpoint.ends_with("/deployments") || self.endpoint.contains("/openai/deployments") {
|
|
38
|
+
// Endpoint already has deployments path, just append deployment name
|
|
39
|
+
let base = self.endpoint.trim_end_matches('/');
|
|
40
|
+
if base.ends_with("/deployments") {
|
|
41
|
+
format!(
|
|
42
|
+
"{}/{}/chat/completions?api-version={}",
|
|
43
|
+
base, self.deployment, self.api_version
|
|
44
|
+
)
|
|
45
|
+
} else {
|
|
46
|
+
// Has /openai/deployments/ in the middle somewhere
|
|
47
|
+
format!(
|
|
48
|
+
"{}{}/chat/completions?api-version={}",
|
|
49
|
+
self.endpoint, self.deployment, self.api_version
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
// Standard Azure OpenAI endpoint format
|
|
54
|
+
format!(
|
|
55
|
+
"{}/openai/deployments/{}/chat/completions?api-version={}",
|
|
56
|
+
self.endpoint, self.deployment, self.api_version
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[async_trait]
|
|
63
|
+
impl ModelProvider for AzureOpenAI {
|
|
64
|
+
fn name(&self) -> &str {
|
|
65
|
+
"azure-openai"
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async fn chat(&self, request: ChatRequest) -> anyhow::Result<ChatResponse> {
|
|
69
|
+
let url = self.build_url();
|
|
70
|
+
|
|
71
|
+
// Debug: print URL
|
|
72
|
+
eprintln!("🔗 Azure URL: {}", url);
|
|
73
|
+
|
|
74
|
+
// Convert ChatRequest to JSON
|
|
75
|
+
let body = serde_json::to_value(&request)?;
|
|
76
|
+
|
|
77
|
+
// Build HTTP request spec
|
|
78
|
+
let http_req = HttpRequestSpec {
|
|
79
|
+
url,
|
|
80
|
+
headers: vec![
|
|
81
|
+
("api-key".to_string(), self.api_key.clone()),
|
|
82
|
+
("Content-Type".to_string(), "application/json".to_string()),
|
|
83
|
+
],
|
|
84
|
+
body,
|
|
85
|
+
timeout: Duration::from_secs(30),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Execute request using HTTP helper
|
|
89
|
+
let json_response = post_json(&self.client, http_req).await?;
|
|
90
|
+
|
|
91
|
+
// Parse response
|
|
92
|
+
let chat_response: ChatResponse = serde_json::from_value(json_response)?;
|
|
93
|
+
Ok(chat_response)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|