legate 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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +345 -0
- data/bin/legate +13 -0
- data/examples/00_quickstart.rb +51 -0
- data/examples/01_simple_agent.rb +105 -0
- data/examples/02_multi_tool_agent.rb +140 -0
- data/examples/03_custom_tool.rb +93 -0
- data/examples/04_agent_instructions.rb +84 -0
- data/examples/05_state_and_sessions.rb +91 -0
- data/examples/06_callbacks.rb +186 -0
- data/examples/07_async_jobs.rb +112 -0
- data/examples/08_loop_agent.rb +197 -0
- data/examples/09_sequential_workflow.rb +40 -0
- data/examples/10_parallel_workflow.rb +34 -0
- data/examples/11_agent_delegation.rb +24 -0
- data/examples/12_http_client_tool.rb +156 -0
- data/examples/13_authentication.rb +220 -0
- data/examples/14_mcp_client.rb +154 -0
- data/examples/15_mcp_server.rb +79 -0
- data/examples/16_webhooks.rb +91 -0
- data/examples/README_sequential_agents.md +164 -0
- data/examples/advanced/auth/cookie_auth_tool.rb +146 -0
- data/examples/advanced/auth/custom_auth_flows_example.rb +626 -0
- data/examples/advanced/auth/excon_middleware.rb +317 -0
- data/examples/advanced/auth/excon_middleware_auth.rb +399 -0
- data/examples/advanced/auth/fiber_auth_example.rb +281 -0
- data/examples/advanced/auth/fiber_oidc_example.rb +403 -0
- data/examples/advanced/auth/httpbin_bearer_tool.rb +159 -0
- data/examples/advanced/auth/oauth2_auth.rb +419 -0
- data/examples/advanced/auth/oidc_auth.rb +514 -0
- data/examples/advanced/auth/openweather_api.rb +251 -0
- data/examples/advanced/auth/openweather_tool.rb +153 -0
- data/examples/advanced/auth/query_param_middleware_test.rb +138 -0
- data/examples/advanced/auth/service_account.rb +135 -0
- data/examples/advanced/auth/test_with_httpbin.rb +202 -0
- data/examples/advanced/auth/token_lifecycle_example.rb +428 -0
- data/examples/advanced/callback_monitoring.rb +679 -0
- data/examples/advanced/mas/fixed_delegation_example.rb +191 -0
- data/examples/advanced/mas/loop_workflow.rb +28 -0
- data/examples/advanced/mas/mock_planner.rb +77 -0
- data/examples/advanced/mas/proper_delegation_example.rb +276 -0
- data/examples/advanced/mcp/legate_mcp_server_resource_example.rb +182 -0
- data/examples/advanced/mcp/mcp_resource_server_example.rb +309 -0
- data/examples/advanced/mcp/mcp_server_async.rb +76 -0
- data/examples/advanced/mcp/mcp_server_async_tools.rb +122 -0
- data/examples/advanced/mcp/mcp_server_legate_agent.rb +95 -0
- data/examples/advanced/mcp/mcp_server_rack.rb +89 -0
- data/examples/advanced/random_calculator.rb +104 -0
- data/examples/advanced/sleep_agent.rb +153 -0
- data/examples/advanced/webhooks/webhook_e2e_runner.rb +110 -0
- data/examples/advanced/webhooks/webhook_receiver_agent.rb +58 -0
- data/examples/advanced/workflows/task_refinement_loop_agent.rb +278 -0
- data/examples/advanced/workflows/travel_planner_auto_sequential.rb +444 -0
- data/examples/advanced/workflows/travel_planner_parallel.rb +656 -0
- data/examples/advanced/workflows/travel_planner_sequential.rb +512 -0
- data/examples/tools/oauth2_example.rb +136 -0
- data/examples/tools/sleepy_tool.rb +42 -0
- data/lib/legate/activity_log.rb +71 -0
- data/lib/legate/agent.rb +959 -0
- data/lib/legate/agent_code_generator.rb +185 -0
- data/lib/legate/agent_definition.rb +812 -0
- data/lib/legate/agentic/decision.rb +49 -0
- data/lib/legate/agentic/loop.rb +134 -0
- data/lib/legate/agentic.rb +5 -0
- data/lib/legate/agents/loop_agent.rb +248 -0
- data/lib/legate/agents/parallel_agent.rb +163 -0
- data/lib/legate/agents/sequential_agent.rb +190 -0
- data/lib/legate/agents.rb +14 -0
- data/lib/legate/auth/config.rb +148 -0
- data/lib/legate/auth/coordinator.rb +218 -0
- data/lib/legate/auth/coordinators/oauth2_coordinator.rb +99 -0
- data/lib/legate/auth/coordinators/oidc_coordinator.rb +68 -0
- data/lib/legate/auth/coordinators/service_account_coordinator.rb +122 -0
- data/lib/legate/auth/credential.rb +157 -0
- data/lib/legate/auth/encryption.rb +108 -0
- data/lib/legate/auth/error.rb +94 -0
- data/lib/legate/auth/exchanged_credential.rb +180 -0
- data/lib/legate/auth/excon_middleware.rb +285 -0
- data/lib/legate/auth/http_client_utils.rb +364 -0
- data/lib/legate/auth/manager.rb +531 -0
- data/lib/legate/auth/manager_store.rb +394 -0
- data/lib/legate/auth/middleware_factory.rb +290 -0
- data/lib/legate/auth/runner.rb +279 -0
- data/lib/legate/auth/scheme.rb +125 -0
- data/lib/legate/auth/schemes/api_key.rb +212 -0
- data/lib/legate/auth/schemes/google_service_account.rb +108 -0
- data/lib/legate/auth/schemes/http_bearer.rb +98 -0
- data/lib/legate/auth/schemes/oauth2.rb +396 -0
- data/lib/legate/auth/schemes/openid_connect.rb +346 -0
- data/lib/legate/auth/schemes/service_account.rb +388 -0
- data/lib/legate/auth/schemes.rb +40 -0
- data/lib/legate/auth/token_manager.rb +362 -0
- data/lib/legate/auth/token_store.rb +86 -0
- data/lib/legate/auth/tool_context_extension.rb +97 -0
- data/lib/legate/auth/tool_integration.rb +188 -0
- data/lib/legate/auth/url_guard.rb +81 -0
- data/lib/legate/auth.rb +453 -0
- data/lib/legate/callbacks/callback_context.rb +71 -0
- data/lib/legate/cli/agent_commands.rb +950 -0
- data/lib/legate/cli/auth_commands.rb +520 -0
- data/lib/legate/cli/base_command.rb +24 -0
- data/lib/legate/cli/deployment_commands.rb +934 -0
- data/lib/legate/cli/output_helper.rb +108 -0
- data/lib/legate/cli/session_commands.rb +138 -0
- data/lib/legate/cli/skaffold_commands.rb +223 -0
- data/lib/legate/cli/tool_commands.rb +261 -0
- data/lib/legate/cli/web_commands.rb +182 -0
- data/lib/legate/cli.rb +40 -0
- data/lib/legate/configuration/webhooks.rb +113 -0
- data/lib/legate/configuration.rb +39 -0
- data/lib/legate/definition_store.rb +23 -0
- data/lib/legate/errors.rb +118 -0
- data/lib/legate/event.rb +161 -0
- data/lib/legate/gemini_ai_beta_patch.rb +39 -0
- data/lib/legate/generators/agent_generator.rb +412 -0
- data/lib/legate/generators/code_validator.rb +48 -0
- data/lib/legate/generators/legate/install_generator.rb +35 -0
- data/lib/legate/generators/legate/templates/create_legate_tables.rb.tt +36 -0
- data/lib/legate/generators/legate/templates/initializer.rb +18 -0
- data/lib/legate/generators/runtime_tool_loader.rb +76 -0
- data/lib/legate/generators/tool_generator.rb +408 -0
- data/lib/legate/generators.rb +11 -0
- data/lib/legate/global_definition_registry.rb +506 -0
- data/lib/legate/global_tool_manager.rb +135 -0
- data/lib/legate/llm/adapter.rb +69 -0
- data/lib/legate/llm/gemini.rb +172 -0
- data/lib/legate/llm/ollama.rb +80 -0
- data/lib/legate/llm.rb +34 -0
- data/lib/legate/mcp/client.rb +320 -0
- data/lib/legate/mcp/connection/sse.rb +292 -0
- data/lib/legate/mcp/connection/stdio.rb +273 -0
- data/lib/legate/mcp/connection_manager.rb +103 -0
- data/lib/legate/mcp/server/legate_agent_adapter.rb +170 -0
- data/lib/legate/mcp/server/legate_direct_agent_adapter.rb +140 -0
- data/lib/legate/mcp/server/legate_tool_adapter.rb +119 -0
- data/lib/legate/mcp/tool_wrapper.rb +138 -0
- data/lib/legate/mcp/util/schema_converter.rb +134 -0
- data/lib/legate/mcp.rb +23 -0
- data/lib/legate/plan_executor.rb +375 -0
- data/lib/legate/planner.rb +839 -0
- data/lib/legate/rails/railtie.rb +43 -0
- data/lib/legate/rails.rb +9 -0
- data/lib/legate/redaction.rb +32 -0
- data/lib/legate/session.rb +299 -0
- data/lib/legate/session_service/active_record.rb +300 -0
- data/lib/legate/session_service/base.rb +68 -0
- data/lib/legate/session_service/event_broadcast.rb +74 -0
- data/lib/legate/session_service/in_memory.rb +188 -0
- data/lib/legate/tool/metadata_dsl.rb +122 -0
- data/lib/legate/tool.rb +276 -0
- data/lib/legate/tool_code_generator.rb +103 -0
- data/lib/legate/tool_context.rb +350 -0
- data/lib/legate/tool_loader.rb +39 -0
- data/lib/legate/tool_registry.rb +73 -0
- data/lib/legate/tool_result.rb +61 -0
- data/lib/legate/tools/agent_tool.rb +187 -0
- data/lib/legate/tools/base/http_client.rb +319 -0
- data/lib/legate/tools/base/safe_url.rb +56 -0
- data/lib/legate/tools/base_async_job_tool.rb +91 -0
- data/lib/legate/tools/calculator.rb +89 -0
- data/lib/legate/tools/cat_facts.rb +81 -0
- data/lib/legate/tools/check_job_status_tool.rb +48 -0
- data/lib/legate/tools/current_time_tool.rb +64 -0
- data/lib/legate/tools/echo.rb +43 -0
- data/lib/legate/tools/http_request_tool.rb +105 -0
- data/lib/legate/tools/random_number_tool.rb +64 -0
- data/lib/legate/tools/read_webpage_tool.rb +92 -0
- data/lib/legate/tools/sleepy_tool.rb +74 -0
- data/lib/legate/tools/webhook_tool.rb +146 -0
- data/lib/legate/version.rb +5 -0
- data/lib/legate/web/app.rb +984 -0
- data/lib/legate/web/public/css/main.css +4980 -0
- data/lib/legate/web/public/images/favicon-256.png +0 -0
- data/lib/legate/web/public/images/favicon-32.png +0 -0
- data/lib/legate/web/public/images/legate-logo-dark.png +0 -0
- data/lib/legate/web/public/images/legate-logo-light.png +0 -0
- data/lib/legate/web/public/js/legate.js +616 -0
- data/lib/legate/web/public/styles/main.scss +4402 -0
- data/lib/legate/web/routes/agent_authentication_routes.rb +530 -0
- data/lib/legate/web/routes/agent_definition_routes.rb +803 -0
- data/lib/legate/web/routes/agent_generator_routes.rb +80 -0
- data/lib/legate/web/routes/agent_interaction_routes.rb +734 -0
- data/lib/legate/web/routes/agent_runtime_routes.rb +323 -0
- data/lib/legate/web/routes/api_routes.rb +56 -0
- data/lib/legate/web/routes/authentication_routes.rb +1541 -0
- data/lib/legate/web/routes/core_routes.rb +111 -0
- data/lib/legate/web/routes/documentation_routes.rb +220 -0
- data/lib/legate/web/routes/tool_generator_routes.rb +81 -0
- data/lib/legate/web/routes/tools_ui_routes.rb +207 -0
- data/lib/legate/web/sass_compiler.rb +73 -0
- data/lib/legate/web/views/_active_session_info.slim +25 -0
- data/lib/legate/web/views/_activity_list.slim +55 -0
- data/lib/legate/web/views/_agent_card.slim +56 -0
- data/lib/legate/web/views/_agent_generator_modal.slim +382 -0
- data/lib/legate/web/views/_agent_status_controls.slim +71 -0
- data/lib/legate/web/views/_agent_tool_table.slim +74 -0
- data/lib/legate/web/views/_chat_message.slim +95 -0
- data/lib/legate/web/views/_display_agent_configuration.slim +26 -0
- data/lib/legate/web/views/_display_agent_description.slim +11 -0
- data/lib/legate/web/views/_display_agent_fallback.slim +15 -0
- data/lib/legate/web/views/_display_agent_hierarchy.slim +93 -0
- data/lib/legate/web/views/_display_agent_instruction.slim +17 -0
- data/lib/legate/web/views/_display_agent_mcp.slim +13 -0
- data/lib/legate/web/views/_display_agent_model.slim +17 -0
- data/lib/legate/web/views/_display_agent_name.slim +42 -0
- data/lib/legate/web/views/_display_agent_output_key.slim +26 -0
- data/lib/legate/web/views/_display_agent_type.slim +65 -0
- data/lib/legate/web/views/_edit_agent_configuration.slim +74 -0
- data/lib/legate/web/views/_edit_agent_description.slim +16 -0
- data/lib/legate/web/views/_edit_agent_fallback.slim +25 -0
- data/lib/legate/web/views/_edit_agent_hierarchy.slim +98 -0
- data/lib/legate/web/views/_edit_agent_instruction.slim +49 -0
- data/lib/legate/web/views/_edit_agent_mcp.slim +33 -0
- data/lib/legate/web/views/_edit_agent_model.slim +23 -0
- data/lib/legate/web/views/_edit_agent_output_key.slim +36 -0
- data/lib/legate/web/views/_edit_agent_tools.slim +40 -0
- data/lib/legate/web/views/_edit_agent_type.slim +67 -0
- data/lib/legate/web/views/_session_error.slim +4 -0
- data/lib/legate/web/views/_skeleton.slim +69 -0
- data/lib/legate/web/views/_tool_card.slim +9 -0
- data/lib/legate/web/views/_tool_generator_modal.slim +311 -0
- data/lib/legate/web/views/agent.slim +436 -0
- data/lib/legate/web/views/agent_auth.slim +562 -0
- data/lib/legate/web/views/agents.slim +369 -0
- data/lib/legate/web/views/auth.slim +112 -0
- data/lib/legate/web/views/auth_credential_detail.slim +327 -0
- data/lib/legate/web/views/auth_credentials.slim +261 -0
- data/lib/legate/web/views/auth_debug.slim +94 -0
- data/lib/legate/web/views/auth_mapping_detail.slim +151 -0
- data/lib/legate/web/views/auth_mapping_new.slim +123 -0
- data/lib/legate/web/views/auth_mappings.slim +120 -0
- data/lib/legate/web/views/auth_scheme_detail.slim +274 -0
- data/lib/legate/web/views/auth_schemes.slim +259 -0
- data/lib/legate/web/views/auth_test.slim +418 -0
- data/lib/legate/web/views/chat.slim +192 -0
- data/lib/legate/web/views/docs_index.slim +105 -0
- data/lib/legate/web/views/docs_show.slim +105 -0
- data/lib/legate/web/views/error_404.slim +5 -0
- data/lib/legate/web/views/index.slim +148 -0
- data/lib/legate/web/views/layout.slim +144 -0
- data/lib/legate/web/views/tool_detail.slim +87 -0
- data/lib/legate/web/views/tools.slim +50 -0
- data/lib/legate/web/webhook_listener.rb +367 -0
- data/lib/legate/web.rb +9 -0
- data/lib/legate.rb +220 -0
- data/public/docs/advanced/callbacks.md +828 -0
- data/public/docs/advanced/mcp_schema_conversion.md +59 -0
- data/public/docs/authentication/api_reference/config.md +210 -0
- data/public/docs/authentication/api_reference/credential.md +246 -0
- data/public/docs/authentication/api_reference/encryption.md +218 -0
- data/public/docs/authentication/api_reference/exchanged_credential.md +271 -0
- data/public/docs/authentication/api_reference/excon_middleware.md +175 -0
- data/public/docs/authentication/api_reference/index.md +30 -0
- data/public/docs/authentication/api_reference/scheme.md +250 -0
- data/public/docs/authentication/api_reference/schemes/api_key.md +175 -0
- data/public/docs/authentication/api_reference/schemes/google_service_account.md +221 -0
- data/public/docs/authentication/api_reference/schemes/http_bearer.md +169 -0
- data/public/docs/authentication/api_reference/schemes/oauth2.md +343 -0
- data/public/docs/authentication/api_reference/schemes/oidc.md +73 -0
- data/public/docs/authentication/api_reference/schemes/openid_connect.md +311 -0
- data/public/docs/authentication/api_reference/schemes/service_account.md +287 -0
- data/public/docs/authentication/api_reference/token_manager.md +221 -0
- data/public/docs/authentication/api_reference/token_store.md +146 -0
- data/public/docs/authentication/api_reference/tool_context_extension.md +166 -0
- data/public/docs/authentication/guides/api_key.md +190 -0
- data/public/docs/authentication/guides/bearer.md +172 -0
- data/public/docs/authentication/guides/configuration.md +255 -0
- data/public/docs/authentication/guides/custom_flow.md +523 -0
- data/public/docs/authentication/guides/index.md +24 -0
- data/public/docs/authentication/guides/migration.md +435 -0
- data/public/docs/authentication/guides/oauth2.md +252 -0
- data/public/docs/authentication/guides/oidc.md +241 -0
- data/public/docs/authentication/guides/overview.md +155 -0
- data/public/docs/authentication/guides/secure_storage.md +301 -0
- data/public/docs/authentication/guides/service_account.md +228 -0
- data/public/docs/authentication/guides/token_lifecycle.md +295 -0
- data/public/docs/authentication/guides/web_ui_integration.md +504 -0
- data/public/docs/authentication/index.md +58 -0
- data/public/docs/authentication/troubleshooting/credential_storage.md +550 -0
- data/public/docs/authentication/troubleshooting/environment_variables.md +540 -0
- data/public/docs/authentication/troubleshooting/index.md +11 -0
- data/public/docs/authentication/troubleshooting/oauth2_issues.md +220 -0
- data/public/docs/authentication/troubleshooting/oidc_issues.md +412 -0
- data/public/docs/authentication/troubleshooting/token_refresh.md +338 -0
- data/public/docs/cli/legate_cli_usage.md +363 -0
- data/public/docs/core_concepts/legate_agent_lifecycle.md +124 -0
- data/public/docs/core_concepts/legate_architecture_overview.md +110 -0
- data/public/docs/core_concepts/legate_configuration.md +116 -0
- data/public/docs/core_concepts/legate_definition_store.md +102 -0
- data/public/docs/core_concepts/legate_planner.md +94 -0
- data/public/docs/core_concepts/legate_session_service.md +104 -0
- data/public/docs/error_handling/legate_error_handling.md +122 -0
- data/public/docs/examples.md +199 -0
- data/public/docs/getting_started.md +111 -0
- data/public/docs/guides/agentic_agents.md +137 -0
- data/public/docs/guides/ai_code_generators.md +437 -0
- data/public/docs/guides/auto_loading.md +326 -0
- data/public/docs/guides/configuring_agent_webhooks.md +219 -0
- data/public/docs/guides/http_client_usage.md +264 -0
- data/public/docs/guides/llm_providers.md +137 -0
- data/public/docs/guides/mcp_client_integration.md +232 -0
- data/public/docs/guides/mcp_server_exposure.md +206 -0
- data/public/docs/guides/rails_integration.md +128 -0
- data/public/docs/guides/sending_outbound_webhooks.md +227 -0
- data/public/docs/guides/streaming.md +112 -0
- data/public/docs/guides/webhooks.md +288 -0
- data/public/docs/introduction.md +51 -0
- data/public/docs/multi_agent_systems/advanced_features.md +57 -0
- data/public/docs/multi_agent_systems/agent_delegation.md +190 -0
- data/public/docs/multi_agent_systems/agent_hierarchy.md +49 -0
- data/public/docs/multi_agent_systems/state_management.md +47 -0
- data/public/docs/multi_agent_systems/workflow_agents.md +72 -0
- data/public/docs/tools/legate_built_in_tools.md +332 -0
- data/public/docs/tools/legate_tools_and_registry.md +263 -0
- data/public/docs/web_ui/legate_web_ui.md +137 -0
- metadata +823 -0
data/lib/legate.rb
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# File: lib/legate.rb
|
|
4
|
+
# NOTE: Loading .env is the application's job, not the library's. The `legate`
|
|
5
|
+
# executable does it via Legate.load_environment; requiring 'legate' must not
|
|
6
|
+
# read the consumer's working directory (and dotenv is only a dev dependency).
|
|
7
|
+
require 'logger'
|
|
8
|
+
require_relative 'legate/version'
|
|
9
|
+
require 'forwardable'
|
|
10
|
+
require 'openssl' # For HMAC in validator
|
|
11
|
+
|
|
12
|
+
# --- Eager Logger Initialization (Moved BEFORE other Legate requires) ---
|
|
13
|
+
module Legate
|
|
14
|
+
# --- Logger Initialization Logic ---
|
|
15
|
+
# Log levels that suppress all output
|
|
16
|
+
SILENT_LOG_LEVELS = %w[NONE SILENT].freeze
|
|
17
|
+
|
|
18
|
+
def self.initialize_logger
|
|
19
|
+
level_str = determine_log_level_str
|
|
20
|
+
log_target, level = configure_log_settings(level_str)
|
|
21
|
+
|
|
22
|
+
logger_instance = Logger.new(log_target)
|
|
23
|
+
logger_instance.level = level
|
|
24
|
+
logger_instance.formatter = proc { |severity, _, _, msg| "#{severity}: #{msg}\n" }
|
|
25
|
+
|
|
26
|
+
logger_instance
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Private helper methods for logger initialization
|
|
30
|
+
class << self
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def determine_log_level_str
|
|
34
|
+
default_level = ENV['RACK_ENV'] == 'development' ? 'DEBUG' : 'WARN'
|
|
35
|
+
ENV['LEGATE_LOG_LEVEL']&.upcase || default_level
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def configure_log_settings(level_str)
|
|
39
|
+
if SILENT_LOG_LEVELS.include?(level_str)
|
|
40
|
+
[IO::NULL, Logger::FATAL + 1]
|
|
41
|
+
else
|
|
42
|
+
[$stdout, parse_log_level(level_str)]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def parse_log_level(level_str)
|
|
47
|
+
case level_str
|
|
48
|
+
when 'DEBUG' then Logger::DEBUG
|
|
49
|
+
when 'INFO' then Logger::INFO
|
|
50
|
+
when 'WARN' then Logger::WARN
|
|
51
|
+
when 'ERROR' then Logger::ERROR
|
|
52
|
+
when 'FATAL' then Logger::FATAL
|
|
53
|
+
else Logger::WARN
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
@logger = initialize_logger
|
|
59
|
+
|
|
60
|
+
# --- Define Logger Accessor Method EARLY ---
|
|
61
|
+
def self.logger
|
|
62
|
+
@logger
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
# --- End Eager Logger Initialization & Accessor ---
|
|
66
|
+
|
|
67
|
+
# --- NOW Require Configuration (Depends on Logger for its own initialization maybe?) ---
|
|
68
|
+
require_relative 'legate/configuration'
|
|
69
|
+
|
|
70
|
+
# --- Central Legate Module (Reopened) ---
|
|
71
|
+
module Legate
|
|
72
|
+
@configuration = nil
|
|
73
|
+
# Guards lazy construction of the singleton configuration so concurrent
|
|
74
|
+
# first-callers (and reset_config! in tests) can't each build one.
|
|
75
|
+
@config_mutex = Mutex.new
|
|
76
|
+
|
|
77
|
+
def self.load_environment
|
|
78
|
+
begin
|
|
79
|
+
require 'bundler/setup'
|
|
80
|
+
# Compatibility shim for Bundler 4.0+ and older gems (like Puma 6.x)
|
|
81
|
+
if defined?(Bundler) && !Bundler.const_defined?(:ORIGINAL_ENV)
|
|
82
|
+
env = if Bundler.respond_to?(:original_env)
|
|
83
|
+
Bundler.original_env
|
|
84
|
+
elsif Bundler.respond_to?(:with_original_env)
|
|
85
|
+
Bundler.with_original_env { ENV.to_h }
|
|
86
|
+
else
|
|
87
|
+
ENV.to_h
|
|
88
|
+
end
|
|
89
|
+
Bundler.const_set(:ORIGINAL_ENV, env)
|
|
90
|
+
end
|
|
91
|
+
rescue LoadError
|
|
92
|
+
# Ignore if Bundler is not used or gem not found
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
begin
|
|
96
|
+
# Load .env here (the application's entry point), not at library require
|
|
97
|
+
# time. dotenv is a dev-only dependency, so guard against it being absent.
|
|
98
|
+
require 'dotenv/load'
|
|
99
|
+
rescue LoadError
|
|
100
|
+
# Ignore if dotenv gem is not used or .env doesn't exist
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Accept GEMINI_API_KEY as an alias for GOOGLE_API_KEY (the variable the
|
|
104
|
+
# gemini-ai gem reads). Users naturally reach for "Gemini API key", and the
|
|
105
|
+
# README documents GEMINI_API_KEY — map it here so the CLI and library paths
|
|
106
|
+
# behave like config.ru's deployment entrypoint.
|
|
107
|
+
ENV['GOOGLE_API_KEY'] ||= ENV['GEMINI_API_KEY'] if ENV['GEMINI_API_KEY']
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Configure Legate settings
|
|
111
|
+
def self.configure
|
|
112
|
+
config # Ensure the singleton exists (under the mutex)
|
|
113
|
+
yield @configuration # Yield the instance
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Returns the singleton configuration instance.
|
|
117
|
+
def self.config
|
|
118
|
+
@config_mutex.synchronize { @configuration ||= Legate::Configuration.new }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# --- NEW: Register Core Webhook Validators --- #
|
|
122
|
+
config.webhooks.register_validator(:hmac_sha256) do |request, secret|
|
|
123
|
+
return false unless secret
|
|
124
|
+
|
|
125
|
+
signature_header = request.env['HTTP_X_HUB_SIGNATURE_256']
|
|
126
|
+
return false unless signature_header&.start_with?('sha256=')
|
|
127
|
+
|
|
128
|
+
expected_signature = signature_header.delete_prefix('sha256=')
|
|
129
|
+
request.body.rewind
|
|
130
|
+
payload_body = request.body.read
|
|
131
|
+
request.body.rewind
|
|
132
|
+
calculated_signature = OpenSSL::HMAC.hexdigest('sha256', secret, payload_body)
|
|
133
|
+
calculated_signature.bytesize == expected_signature.bytesize && OpenSSL.fixed_length_secure_compare(
|
|
134
|
+
calculated_signature, expected_signature
|
|
135
|
+
)
|
|
136
|
+
end
|
|
137
|
+
# --- END NEW --- #
|
|
138
|
+
|
|
139
|
+
# Reset configuration (mainly for testing)
|
|
140
|
+
def self.reset_config!
|
|
141
|
+
@config_mutex.synchronize { @configuration = nil }
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# --- Require rest of components ---
|
|
146
|
+
require_relative 'legate/errors'
|
|
147
|
+
require_relative 'legate/event'
|
|
148
|
+
require_relative 'legate/session'
|
|
149
|
+
require_relative 'legate/tool_context'
|
|
150
|
+
require_relative 'legate/callbacks/callback_context' # Add callbacks module
|
|
151
|
+
require_relative 'legate/tool_result'
|
|
152
|
+
require_relative 'legate/tool' # Logger is definitely ready now
|
|
153
|
+
require_relative 'legate/tool_registry'
|
|
154
|
+
require_relative 'legate/global_tool_manager'
|
|
155
|
+
require_relative 'legate/tool_loader'
|
|
156
|
+
require_relative 'legate/llm'
|
|
157
|
+
require_relative 'legate/agentic'
|
|
158
|
+
require_relative 'legate/planner'
|
|
159
|
+
require_relative 'legate/session_service/base'
|
|
160
|
+
require_relative 'legate/session_service/in_memory'
|
|
161
|
+
require_relative 'legate/mcp'
|
|
162
|
+
require_relative 'legate/plan_executor'
|
|
163
|
+
require_relative 'legate/agent'
|
|
164
|
+
require_relative 'legate/agents' # Load specialized workflow agents
|
|
165
|
+
# NOTE: the CLI (require 'legate/cli') and web UI (require 'legate/web') are
|
|
166
|
+
# opt-in — they are NOT loaded here, so `require 'legate'` does not drag in Thor,
|
|
167
|
+
# Sinatra, Puma, Slim, or sass-embedded for library-only consumers. The `legate`
|
|
168
|
+
# executable loads the CLI explicitly; web hosts load 'legate/web'.
|
|
169
|
+
|
|
170
|
+
# Tools
|
|
171
|
+
require_relative 'legate/tools/echo'
|
|
172
|
+
require_relative 'legate/tools/calculator'
|
|
173
|
+
require_relative 'legate/tools/cat_facts'
|
|
174
|
+
# RandomNumberTool is loaded so examples/tests can opt into it, but it is NOT
|
|
175
|
+
# registered as a default tool (see the registration list below) — it's a demo
|
|
176
|
+
# tool, not something an agent should be offered out of the box.
|
|
177
|
+
require_relative 'legate/tools/random_number_tool'
|
|
178
|
+
require_relative 'legate/tools/agent_tool' # Tool that allows an agent to call another agent
|
|
179
|
+
require_relative 'legate/tools/base_async_job_tool' # Base class for tools that run asynchronously
|
|
180
|
+
require_relative 'legate/tools/check_job_status_tool' # Tool to check the status of async jobs
|
|
181
|
+
require_relative 'legate/tools/sleepy_tool' # Example async tool
|
|
182
|
+
require_relative 'legate/tools/webhook_tool' # Added webhook_tool here
|
|
183
|
+
require_relative 'legate/tools/http_request_tool' # General-purpose SSRF-safe HTTP client
|
|
184
|
+
require_relative 'legate/tools/current_time_tool' # Current date/time
|
|
185
|
+
require_relative 'legate/tools/read_webpage_tool' # Fetch a page as readable text
|
|
186
|
+
|
|
187
|
+
module Legate
|
|
188
|
+
# Reopen module if needed for final definitions
|
|
189
|
+
# class Error < StandardError; end # Already defined
|
|
190
|
+
module SessionService; end
|
|
191
|
+
|
|
192
|
+
# Lists metadata (name, description, parameters) for every globally registered
|
|
193
|
+
# tool — a discoverable entry point over GlobalToolManager.
|
|
194
|
+
# @return [Array<Hash>]
|
|
195
|
+
def self.tools
|
|
196
|
+
Legate::GlobalToolManager.list_all_tools
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
Legate.logger.debug 'Explicitly registering built-in Legate tools...'
|
|
201
|
+
[
|
|
202
|
+
Legate::Tools::Echo,
|
|
203
|
+
Legate::Tools::Calculator,
|
|
204
|
+
Legate::Tools::CatFacts,
|
|
205
|
+
Legate::Tools::AgentTool, # Ensure this is registered
|
|
206
|
+
Legate::Tools::CheckJobStatusTool,
|
|
207
|
+
Legate::Tools::SleepyTool,
|
|
208
|
+
Legate::Tools::WebhookTool,
|
|
209
|
+
Legate::Tools::HttpRequest,
|
|
210
|
+
Legate::Tools::CurrentTime,
|
|
211
|
+
Legate::Tools::ReadWebpage
|
|
212
|
+
# Legate::Tools::BaseAsyncJobTool should NOT be registered as it's abstract
|
|
213
|
+
].each do |tool_klass|
|
|
214
|
+
if tool_klass.respond_to?(:abstract?) && tool_klass.abstract?
|
|
215
|
+
Legate.logger.debug "Skipping explicit registration of abstract tool: #{tool_klass}"
|
|
216
|
+
else
|
|
217
|
+
Legate::GlobalToolManager.register_tool(tool_klass)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
Legate.logger.debug "Explicit tool registration complete. Current global tools: #{Legate::GlobalToolManager.registered_tool_names.inspect}"
|