polyrob 0.5.0__py3-none-any.whl
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.
- agents/README.md +453 -0
- agents/__init__.py +164 -0
- agents/base_agent.py +743 -0
- agents/personality/character.py +119 -0
- agents/personality/character_manager.py +309 -0
- agents/personality/characters/rob.character.json +56 -0
- agents/personality/characters/trump.character.json +63 -0
- agents/personality/persona_render.py +78 -0
- agents/personality/persona_resolver.py +115 -0
- agents/prompt/__init__.py +58 -0
- agents/prompt/base_prompt.py +92 -0
- agents/prompt/system.py +417 -0
- agents/task/README_PATH_MANAGEMENT.md +141 -0
- agents/task/__init__.py +162 -0
- agents/task/agent/__init__.py +70 -0
- agents/task/agent/agent_state.py +408 -0
- agents/task/agent/async_delegation.py +274 -0
- agents/task/agent/autonomy_state.py +275 -0
- agents/task/agent/conversation.py +75 -0
- agents/task/agent/core/__init__.py +6 -0
- agents/task/agent/core/aux_metering.py +61 -0
- agents/task/agent/core/background_review.py +157 -0
- agents/task/agent/core/construction.py +1179 -0
- agents/task/agent/core/conversational_exit.py +49 -0
- agents/task/agent/core/correspondent_gate.py +227 -0
- agents/task/agent/core/curator.py +246 -0
- agents/task/agent/core/episodic_digest.py +103 -0
- agents/task/agent/core/error_recovery.py +480 -0
- agents/task/agent/core/history_io.py +257 -0
- agents/task/agent/core/llm_provisioning.py +287 -0
- agents/task/agent/core/llm_runner.py +547 -0
- agents/task/agent/core/logging_io.py +276 -0
- agents/task/agent/core/loop_detection.py +262 -0
- agents/task/agent/core/memory_prefetch.py +325 -0
- agents/task/agent/core/memory_writer.py +667 -0
- agents/task/agent/core/model_introspection.py +82 -0
- agents/task/agent/core/model_swap.py +177 -0
- agents/task/agent/core/next_action_internal.py +1331 -0
- agents/task/agent/core/output_validation.py +303 -0
- agents/task/agent/core/project_context.py +272 -0
- agents/task/agent/core/resources.py +93 -0
- agents/task/agent/core/result_processing.py +389 -0
- agents/task/agent/core/run_loop.py +661 -0
- agents/task/agent/core/safety_lifecycle.py +228 -0
- agents/task/agent/core/secret_guard.py +293 -0
- agents/task/agent/core/self_wake.py +280 -0
- agents/task/agent/core/session_metadata.py +104 -0
- agents/task/agent/core/step.py +781 -0
- agents/task/agent/core/step_execution.py +398 -0
- agents/task/agent/core/step_telemetry.py +222 -0
- agents/task/agent/core/test_aux_metering.py +50 -0
- agents/task/agent/core/test_billing_failover.py +68 -0
- agents/task/agent/core/test_fatal_error_classifier.py +38 -0
- agents/task/agent/core/test_judge_validation.py +275 -0
- agents/task/agent/core/test_model_swap.py +190 -0
- agents/task/agent/core/test_reflection_offload.py +54 -0
- agents/task/agent/core/turn_input.py +8 -0
- agents/task/agent/core/untrusted_wrap.py +103 -0
- agents/task/agent/core/user_ingress.py +228 -0
- agents/task/agent/hitl_manager.py +396 -0
- agents/task/agent/log_sanitize.py +36 -0
- agents/task/agent/message_manager/config.py +97 -0
- agents/task/agent/message_manager/service.py +758 -0
- agents/task/agent/message_manager/tests.py +305 -0
- agents/task/agent/message_manager/tool_call_builder.py +539 -0
- agents/task/agent/message_manager/tool_message_repair.py +364 -0
- agents/task/agent/message_manager/views.py +143 -0
- agents/task/agent/messages/__init__.py +8 -0
- agents/task/agent/messages/builders.py +309 -0
- agents/task/agent/messages/compactor.py +611 -0
- agents/task/agent/messages/context_references.py +271 -0
- agents/task/agent/messages/filters.py +333 -0
- agents/task/agent/messages/guidance.py +328 -0
- agents/task/agent/messages/persistence.py +448 -0
- agents/task/agent/messages/retrieval.py +506 -0
- agents/task/agent/messages/sqlite_persistence.py +85 -0
- agents/task/agent/messages/test_compaction_upgrade.py +349 -0
- agents/task/agent/messages/test_persistence_subdir_fix.py +28 -0
- agents/task/agent/messages/test_sqlite_persistence.py +54 -0
- agents/task/agent/messages/token_counter.py +532 -0
- agents/task/agent/orchestrator.py +776 -0
- agents/task/agent/profile_manager.py +105 -0
- agents/task/agent/profile_registry.py +173 -0
- agents/task/agent/prompts.py +1090 -0
- agents/task/agent/scenario_registry.py +226 -0
- agents/task/agent/service.py +509 -0
- agents/task/agent/session.py +984 -0
- agents/task/agent/skill_discovery.py +110 -0
- agents/task/agent/skill_frontmatter.py +94 -0
- agents/task/agent/skill_manager.py +1201 -0
- agents/task/agent/skill_store.py +627 -0
- agents/task/agent/skill_validation.py +56 -0
- agents/task/agent/skill_writer.py +492 -0
- agents/task/agent/sub_agent_manager.py +1137 -0
- agents/task/agent/test_session_disk_recovery.py +34 -0
- agents/task/agent/tests.py +513 -0
- agents/task/agent/tool_call_tracker.py +511 -0
- agents/task/agent/views.py +469 -0
- agents/task/config.py +432 -0
- agents/task/constants.py +1384 -0
- agents/task/flag_defaults.py +63 -0
- agents/task/goals/__init__.py +1 -0
- agents/task/goals/autonomy_marker.py +28 -0
- agents/task/goals/board.py +690 -0
- agents/task/goals/completion_judge.py +247 -0
- agents/task/goals/context.py +62 -0
- agents/task/goals/dispatcher.py +848 -0
- agents/task/goals/escalation.py +102 -0
- agents/task/goals/planner.py +114 -0
- agents/task/logging_config.py +155 -0
- agents/task/path.py +991 -0
- agents/task/robust_parse_config.py +400 -0
- agents/task/runtime/__init__.py +0 -0
- agents/task/runtime/run_as_session.py +130 -0
- agents/task/runtime_safety.py +308 -0
- agents/task/session/__init__.py +5 -0
- agents/task/session/browser_pool.py +130 -0
- agents/task/session/cleanup.py +612 -0
- agents/task/session/execution.py +397 -0
- agents/task/session/feed.py +200 -0
- agents/task/session/hitl_ingress.py +201 -0
- agents/task/session/hooks.py +83 -0
- agents/task/session/multi_agent.py +243 -0
- agents/task/session/workspace.py +91 -0
- agents/task/session_registry.py +91 -0
- agents/task/session_route.py +35 -0
- agents/task/sqlite_session_registry.py +261 -0
- agents/task/surface_config.py +185 -0
- agents/task/telemetry/__init__.py +58 -0
- agents/task/telemetry/event_log.py +180 -0
- agents/task/telemetry/formatters.py +642 -0
- agents/task/telemetry/manager.py +571 -0
- agents/task/telemetry/memory_events.py +66 -0
- agents/task/telemetry/self_events.py +53 -0
- agents/task/telemetry/sequence.py +160 -0
- agents/task/telemetry/service.py +1265 -0
- agents/task/telemetry/views.py +882 -0
- agents/task/templates.py +98 -0
- agents/task/test_aux_chain.py +151 -0
- agents/task/test_aux_router.py +41 -0
- agents/task/tests/test_parse_robustness.py +170 -0
- agents/task/tool_defaults.py +110 -0
- agents/task/utils.py +762 -0
- agents/task/utils_json.py +768 -0
- agents/task/utils_webview.py +86 -0
- agents/task/workspace_context.py +229 -0
- agents/task_agent_lite.py +2398 -0
- api/README.md +683 -0
- api/TASK_API_DOCS.md +151 -0
- api/__init__.py +0 -0
- api/a2a/__init__.py +37 -0
- api/a2a/agent_card.py +337 -0
- api/a2a/client.py +657 -0
- api/a2a/endpoints.py +375 -0
- api/a2a/models.py +268 -0
- api/a2a/streaming.py +419 -0
- api/a2a/task_handler.py +929 -0
- api/admin_endpoints.py +1584 -0
- api/app.py +923 -0
- api/auth_constants.py +28 -0
- api/auth_endpoints.py +402 -0
- api/auth_state.py +36 -0
- api/chat_via_task.py +42 -0
- api/conversation_manager.py +231 -0
- api/dependencies.py +186 -0
- api/eip8004_endpoints.py +452 -0
- api/hyperliquid_models.py +174 -0
- api/hyperliquid_routes.py +450 -0
- api/interfaces.py +207 -0
- api/jwt_middleware.py +83 -0
- api/kb/__init__.py +1 -0
- api/kb/endpoints.py +314 -0
- api/mcp_models.py +279 -0
- api/mcp_routes.py +438 -0
- api/middleware.py +526 -0
- api/models.py +176 -0
- api/openai_compat/__init__.py +0 -0
- api/openai_compat/model_map.py +25 -0
- api/openai_compat/models.py +59 -0
- api/openai_compat/router.py +140 -0
- api/payment_endpoints.py +444 -0
- api/payment_verification.py +138 -0
- api/polymarket_models.py +155 -0
- api/polymarket_routes.py +501 -0
- api/pricing_endpoints.py +89 -0
- api/session_routing.py +54 -0
- api/skill_endpoints.py +453 -0
- api/task_http_api.py +1856 -0
- api/webhooks.py +52 -0
- api/x402_endpoints.py +280 -0
- avatar/README.md +44 -0
- avatar/__init__.py +1 -0
- avatar/config/rob.json +7 -0
- avatar/mindprint.js +395 -0
- avatar/renders/rob.meta.json +20 -0
- avatar/renders/rob.png +0 -0
- avatar/studio.html +373 -0
- avatar/webview/avatar-live.js +44 -0
- cli/README.md +89 -0
- cli/__init__.py +0 -0
- cli/cli_surface.py +67 -0
- cli/commands/__init__.py +0 -0
- cli/commands/_bootstrap.py +49 -0
- cli/commands/_errors.py +53 -0
- cli/commands/chat.py +973 -0
- cli/commands/config.py +100 -0
- cli/commands/dashboard.py +103 -0
- cli/commands/doctor.py +222 -0
- cli/commands/email.py +174 -0
- cli/commands/gateway.py +346 -0
- cli/commands/goals.py +509 -0
- cli/commands/init.py +276 -0
- cli/commands/journey.py +30 -0
- cli/commands/kb.py +280 -0
- cli/commands/model.py +107 -0
- cli/commands/owner.py +431 -0
- cli/commands/pfp.py +232 -0
- cli/commands/run.py +414 -0
- cli/commands/serve.py +41 -0
- cli/commands/session.py +684 -0
- cli/commands/skill_install.py +786 -0
- cli/commands/skills.py +128 -0
- cli/commands/subagents.py +100 -0
- cli/commands/surface.py +81 -0
- cli/commands/telegram.py +185 -0
- cli/commands/todos.py +209 -0
- cli/commands/tools.py +102 -0
- cli/commands/update.py +316 -0
- cli/commands/whatsapp.py +175 -0
- cli/config_store.py +276 -0
- cli/gitignore.py +43 -0
- cli/inventory.py +46 -0
- cli/keys.py +101 -0
- cli/persona.py +17 -0
- cli/polyrob.py +137 -0
- cli/ui/__init__.py +64 -0
- cli/ui/activity.py +141 -0
- cli/ui/app.py +538 -0
- cli/ui/banner.py +233 -0
- cli/ui/blocks.py +534 -0
- cli/ui/bootstrap_notice.py +47 -0
- cli/ui/commands/__init__.py +41 -0
- cli/ui/commands/h_cron.py +64 -0
- cli/ui/commands/h_journey.py +164 -0
- cli/ui/commands/h_kb.py +121 -0
- cli/ui/commands/h_learn.py +100 -0
- cli/ui/commands/h_mcp.py +215 -0
- cli/ui/commands/h_self.py +113 -0
- cli/ui/commands/h_skills.py +314 -0
- cli/ui/commands/handlers.py +1672 -0
- cli/ui/commands/registry.py +426 -0
- cli/ui/dialog.py +425 -0
- cli/ui/event_registry.py +110 -0
- cli/ui/event_specs.py +45 -0
- cli/ui/events.py +433 -0
- cli/ui/identity.py +15 -0
- cli/ui/lifecycle.py +159 -0
- cli/ui/live_hooks.py +43 -0
- cli/ui/model_selector.py +532 -0
- cli/ui/persistent_loop.py +181 -0
- cli/ui/pick.py +113 -0
- cli/ui/plain_renderer.py +351 -0
- cli/ui/renderer.py +384 -0
- cli/ui/rich_renderer.py +533 -0
- cli/ui/secrets.py +115 -0
- cli/ui/state.py +376 -0
- cli/ui/statusbar.py +231 -0
- cli/ui/streaming.py +254 -0
- cli/ui/terminal_render.py +105 -0
- cli/ui/theme.py +132 -0
- cli/update/__init__.py +6 -0
- cli/update/context.py +121 -0
- cli/update/detect.py +176 -0
- cli/update/engine.py +95 -0
- cli/update/migrate_guarded.py +55 -0
- cli/update/process_guard.py +215 -0
- cli/update/runners.py +78 -0
- cli/update/snapshot.py +270 -0
- cli/update/versions.py +205 -0
- core/README.md +377 -0
- core/__init__.py +174 -0
- core/assets.py +87 -0
- core/async_bridge.py +76 -0
- core/autonomy_runtime.py +259 -0
- core/base_component.py +302 -0
- core/bootstrap.py +681 -0
- core/bot.py +310 -0
- core/config.py +833 -0
- core/constants.py +126 -0
- core/container.py +462 -0
- core/db_manifest.py +101 -0
- core/embedding.py +57 -0
- core/env.py +39 -0
- core/exceptions.py +287 -0
- core/flags.py +144 -0
- core/flags_catalog.py +345 -0
- core/home_migration.py +62 -0
- core/identity.py +118 -0
- core/initialization.py +1004 -0
- core/instance.py +537 -0
- core/interactive_gate.py +96 -0
- core/logging.py +436 -0
- core/owner_doc_writer.py +176 -0
- core/pairing.py +193 -0
- core/path_safety.py +20 -0
- core/paths.py +27 -0
- core/payment_config.py +21 -0
- core/permissions.py +322 -0
- core/runtime_config.py +96 -0
- core/runtime_paths.py +135 -0
- core/seams.py +35 -0
- core/secret_scan.py +25 -0
- core/secret_scrub.py +71 -0
- core/secrets.py +35 -0
- core/security_logging_filter.py +148 -0
- core/self_context_writer.py +333 -0
- core/self_evolution.py +294 -0
- core/session_context.py +47 -0
- core/sqlite_util.py +59 -0
- core/surfaces/__init__.py +16 -0
- core/surfaces/access.py +118 -0
- core/surfaces/binding.py +88 -0
- core/surfaces/bootstrap.py +78 -0
- core/surfaces/circuit.py +168 -0
- core/surfaces/continuity.py +77 -0
- core/surfaces/correspondents.py +228 -0
- core/surfaces/dispatcher.py +216 -0
- core/surfaces/envelopes.py +75 -0
- core/surfaces/gc.py +30 -0
- core/surfaces/idempotency.py +57 -0
- core/surfaces/inbound_webhook.py +124 -0
- core/surfaces/media.py +32 -0
- core/surfaces/message_router.py +91 -0
- core/surfaces/outbound_allowlist.py +80 -0
- core/surfaces/outbound_dispatcher.py +110 -0
- core/surfaces/outbound_mirror.py +37 -0
- core/surfaces/outbound_queue.py +107 -0
- core/surfaces/outbound_target.py +12 -0
- core/surfaces/owner_admin.py +29 -0
- core/surfaces/proactive.py +78 -0
- core/surfaces/progress.py +108 -0
- core/surfaces/rate_bucket.py +21 -0
- core/surfaces/registry.py +51 -0
- core/surfaces/rendering.py +53 -0
- core/surfaces/send_policy.py +14 -0
- core/surfaces/serialize.py +24 -0
- core/surfaces/session_chat_registry.py +112 -0
- core/surfaces/session_policy.py +60 -0
- core/surfaces/surface.py +288 -0
- core/surfaces/transcription.py +88 -0
- core/surfaces/voice_echo.py +26 -0
- core/surfaces/voice_guard.py +23 -0
- core/tickers.py +174 -0
- core/tool_catalog.py +192 -0
- core/version.py +75 -0
- core/wallet/__init__.py +5 -0
- core/wallet/agent_wallet.py +59 -0
- core/wallet/audit_sink.py +61 -0
- core/wallet/config.py +70 -0
- core/wallet/factory.py +87 -0
- core/wallet/policy.py +104 -0
- core/wallet/signer.py +51 -0
- cron/README.md +65 -0
- cron/__init__.py +0 -0
- cron/delivery.py +277 -0
- cron/digest.py +124 -0
- cron/jobs.py +207 -0
- cron/runner.py +297 -0
- cron/schedule.py +194 -0
- cron/scheduler.py +201 -0
- cron/service.py +57 -0
- cron/wake_gate.py +223 -0
- data/__init__.py +1 -0
- data/prompts/autov2_prompts.json +87 -0
- data/prompts/skills/browser-automation/SKILL.md +43 -0
- data/prompts/skills/coding-workflow/SKILL.md +36 -0
- data/prompts/skills/crypto-trading-safety/SKILL.md +53 -0
- data/prompts/skills/document-writing/SKILL.md +33 -0
- data/prompts/skills/email-comms/SKILL.md +33 -0
- data/prompts/skills/file-data-ops/SKILL.md +35 -0
- data/prompts/skills/hyperliquid-account-review/SKILL.md +48 -0
- data/prompts/skills/hyperliquid-market-data/SKILL.md +52 -0
- data/prompts/skills/hyperliquid-trading/SKILL.md +59 -0
- data/prompts/skills/lead-research/SKILL.md +86 -0
- data/prompts/skills/market-research-brief/SKILL.md +104 -0
- data/prompts/skills/person-analyzer/SKILL.md +124 -0
- data/prompts/skills/polymarket-market-research/SKILL.md +54 -0
- data/prompts/skills/polymarket-portfolio-review/SKILL.md +50 -0
- data/prompts/skills/polymarket-trading/SKILL.md +55 -0
- data/prompts/skills/presentation-creator/SKILL.md +36 -0
- data/prompts/skills/project-analyzer/SKILL.md +169 -0
- data/prompts/skills/rules.json +268 -0
- data/prompts/skills/secret-handling/SKILL.md +20 -0
- data/prompts/skills/skill-authoring/SKILL.md +31 -0
- data/prompts/skills/skill-security-review/SKILL.md +27 -0
- data/prompts/skills/social-discovery/SKILL.md +57 -0
- data/prompts/skills/task-planning/SKILL.md +33 -0
- data/prompts/skills/web-research/SKILL.md +39 -0
- data/prompts/skills/web-scraping/SKILL.md +73 -0
- data/prompts/skills/x-engagement/SKILL.md +69 -0
- data/prompts/system_prompts.json +4 -0
- data/subscription_channels.json +5 -0
- modules/README.md +503 -0
- modules/__init__.py +124 -0
- modules/auth/__init__.py +13 -0
- modules/auth/api_key_manager.py +157 -0
- modules/auth/identity_mapper.py +380 -0
- modules/auth/siwe_auth.py +273 -0
- modules/auth/tier_manager.py +173 -0
- modules/base_module.py +190 -0
- modules/credits/__init__.py +29 -0
- modules/credits/balance_manager.py +237 -0
- modules/credits/cost_utils.py +129 -0
- modules/credits/pricing.py +139 -0
- modules/credits/unified_ledger.py +148 -0
- modules/credits/usage_meter.py +310 -0
- modules/credits/usage_tracker.py +674 -0
- modules/database/__init__.py +33 -0
- modules/database/audit_log.py +322 -0
- modules/database/auth_tables.py +276 -0
- modules/database/connection.py +644 -0
- modules/database/connection_pool.py +305 -0
- modules/database/conversation_contexts.py +446 -0
- modules/database/database_manager.py +237 -0
- modules/database/hyperliquid.py +375 -0
- modules/database/polymarket.py +574 -0
- modules/database/user_mcp_servers.py +728 -0
- modules/database/user_profiles.py +562 -0
- modules/database/utils.py +107 -0
- modules/database/x402_tables.py +92 -0
- modules/eip8004/README.md +1069 -0
- modules/eip8004/__init__.py +65 -0
- modules/eip8004/contracts.py +498 -0
- modules/eip8004/models.py +271 -0
- modules/eip8004/registration.py +148 -0
- modules/eip8004/reputation.py +367 -0
- modules/eip8004/validation.py +277 -0
- modules/llm/__init__.py +97 -0
- modules/llm/adapters.py +963 -0
- modules/llm/anthropic_client.py +831 -0
- modules/llm/available_models.py +106 -0
- modules/llm/brain_scrubber.py +137 -0
- modules/llm/cache_hints.py +162 -0
- modules/llm/deepseek_client.py +562 -0
- modules/llm/gemini_client.py +1367 -0
- modules/llm/llm_client.py +1139 -0
- modules/llm/llm_client_registry.py +188 -0
- modules/llm/llm_factory.py +237 -0
- modules/llm/llm_manager.py +1036 -0
- modules/llm/messages.py +374 -0
- modules/llm/model_registry.py +1935 -0
- modules/llm/nvidia_client.py +125 -0
- modules/llm/openai_client.py +800 -0
- modules/llm/openrouter_client.py +969 -0
- modules/llm/profiles.py +178 -0
- modules/llm/test_anthropic_cache_capture.py +35 -0
- modules/llm/test_cached_pricing_derivation.py +24 -0
- modules/llm/think_scrubber.py +444 -0
- modules/llm/token_counter.py +268 -0
- modules/memory/__init__.py +35 -0
- modules/memory/backend_factory.py +83 -0
- modules/memory/cache_manager.py +186 -0
- modules/memory/episodic.py +108 -0
- modules/memory/local_vector_memory_provider.py +552 -0
- modules/memory/memory_manager.py +225 -0
- modules/memory/models.py +312 -0
- modules/memory/provider.py +210 -0
- modules/memory/registry.py +205 -0
- modules/memory/sqlite_memory_provider.py +767 -0
- modules/memory/task/__init__.py +52 -0
- modules/memory/task/compaction_manager.py +157 -0
- modules/memory/task/context_retriever.py +809 -0
- modules/memory/task/hierarchical_memory.py +1002 -0
- modules/memory/task/lexical_retriever.py +71 -0
- modules/memory/task/null_context_manager.py +213 -0
- modules/memory/task/phase_manager.py +625 -0
- modules/memory/task/reflection_service.py +157 -0
- modules/memory/task/semantic_retriever.py +218 -0
- modules/memory/task/task_context_manager.py +1165 -0
- modules/memory/task/test_forgetting_engages.py +24 -0
- modules/memory/task/test_reflection_llm.py +39 -0
- modules/memory/task/test_threat_scan.py +53 -0
- modules/memory/task/threat_scan.py +90 -0
- modules/memory/test_sqlite_memory_provider.py +106 -0
- modules/memory/user_profile_manager.py +527 -0
- modules/payments/__init__.py +11 -0
- modules/payments/deposit_monitor.py +478 -0
- modules/payments/price_oracle.py +70 -0
- modules/payments/treasury_sweeper.py +401 -0
- modules/payments/wallet_generator.py +145 -0
- modules/pfp/__init__.py +1 -0
- modules/pfp/config.py +92 -0
- modules/pfp/mesh.py +565 -0
- modules/pfp/push.py +69 -0
- modules/pfp/renderer.py +85 -0
- modules/pfp/store.py +82 -0
- modules/skills/__init__.py +1 -0
- modules/skills/skill_usage.py +248 -0
- modules/transcription/__init__.py +24 -0
- modules/transcription/base.py +20 -0
- modules/transcription/faster_whisper_transcriber.py +55 -0
- modules/x402/README.md +249 -0
- modules/x402/__init__.py +22 -0
- modules/x402/invoicing.py +416 -0
- modules/x402/middleware.py +364 -0
- modules/x402/settlement_watcher.py +145 -0
- modules/x402/x402_integration.py +344 -0
- polyrob-0.5.0.dist-info/METADATA +482 -0
- polyrob-0.5.0.dist-info/RECORD +745 -0
- polyrob-0.5.0.dist-info/WHEEL +5 -0
- polyrob-0.5.0.dist-info/entry_points.txt +2 -0
- polyrob-0.5.0.dist-info/licenses/LICENSE +21 -0
- polyrob-0.5.0.dist-info/top_level.txt +12 -0
- surfaces/README.md +70 -0
- surfaces/__init__.py +0 -0
- surfaces/email/__init__.py +0 -0
- surfaces/email/dedup.py +44 -0
- surfaces/email/harness.py +187 -0
- surfaces/email/inbound.py +159 -0
- surfaces/email/seed.py +60 -0
- surfaces/email/surface.py +105 -0
- surfaces/telegram/__init__.py +0 -0
- surfaces/telegram/dedup.py +83 -0
- surfaces/telegram/harness.py +886 -0
- surfaces/telegram/inbound.py +145 -0
- surfaces/telegram/interactive_tools.py +49 -0
- surfaces/telegram/markdown.py +347 -0
- surfaces/telegram/rate_limit.py +167 -0
- surfaces/telegram/surface.py +187 -0
- surfaces/telegram/voice.py +52 -0
- surfaces/whatsapp/__init__.py +0 -0
- surfaces/whatsapp/client.py +51 -0
- surfaces/whatsapp/harness.py +62 -0
- surfaces/whatsapp/inbound.py +132 -0
- surfaces/whatsapp/surface.py +64 -0
- surfaces/whatsapp/window.py +34 -0
- tools/README.md +578 -0
- tools/__init__.py +424 -0
- tools/alchemy/__init__.py +5 -0
- tools/alchemy/alchemy_tool.py +389 -0
- tools/anysite/__init__.py +17 -0
- tools/anysite/client.py +88 -0
- tools/anysite/tool.py +89 -0
- tools/base_tool.py +468 -0
- tools/browser/__init__.py +22 -0
- tools/browser/actions.py +118 -0
- tools/browser/browser.py +1457 -0
- tools/browser/browser_manager.py +690 -0
- tools/browser/context.py +1748 -0
- tools/browser/playwright_utils.py +137 -0
- tools/browser/views.py +56 -0
- tools/code_exec/SANDBOX_SECURITY.md +144 -0
- tools/code_exec/__init__.py +178 -0
- tools/code_exec/backend.py +73 -0
- tools/code_exec/backends/__init__.py +1 -0
- tools/code_exec/backends/docker.py +779 -0
- tools/code_exec/backends/local_subprocess.py +154 -0
- tools/code_exec/env_policy.py +45 -0
- tools/code_exec/result.py +42 -0
- tools/code_exec/sandbox_guard.py +59 -0
- tools/code_exec/tool.py +227 -0
- tools/coding/__init__.py +50 -0
- tools/coding/edit.py +107 -0
- tools/coding/search.py +113 -0
- tools/coding/tool.py +353 -0
- tools/collabland/__init__.py +5 -0
- tools/collabland/collabland_tool.py +471 -0
- tools/controller/__init__.py +0 -0
- tools/controller/_helpers.py +165 -0
- tools/controller/action_registration.py +1765 -0
- tools/controller/approval.py +244 -0
- tools/controller/approval_interactive.py +90 -0
- tools/controller/delegation.py +195 -0
- tools/controller/execution.py +797 -0
- tools/controller/execution_context.py +141 -0
- tools/controller/hooks.py +135 -0
- tools/controller/introspection.py +344 -0
- tools/controller/mcp_registrar.py +190 -0
- tools/controller/message_send.py +31 -0
- tools/controller/registry/__init__.py +4 -0
- tools/controller/registry/schema_generators.py +395 -0
- tools/controller/registry/schema_sanitizer.py +406 -0
- tools/controller/registry/service.py +1266 -0
- tools/controller/registry/views.py +151 -0
- tools/controller/service.py +409 -0
- tools/controller/tool_management.py +334 -0
- tools/controller/types.py +28 -0
- tools/controller/views.py +450 -0
- tools/cronjob_tools.py +166 -0
- tools/crypto_trade_gate.py +59 -0
- tools/descriptors.py +452 -0
- tools/dom/__init__.py +0 -0
- tools/dom/history_tree_processor/service.py +244 -0
- tools/dom/history_tree_processor/view.py +99 -0
- tools/dom/service.py +471 -0
- tools/dom/views.py +346 -0
- tools/email_tool.py +403 -0
- tools/exceptions.py +169 -0
- tools/filesystem.py +1038 -0
- tools/filesystem_docproc.py +331 -0
- tools/filesystem_pdf.py +755 -0
- tools/git/__init__.py +42 -0
- tools/git/tool.py +258 -0
- tools/github/__init__.py +33 -0
- tools/github/client.py +94 -0
- tools/github/tool.py +237 -0
- tools/goal_tools.py +309 -0
- tools/hyperliquid/__init__.py +56 -0
- tools/hyperliquid/models.py +233 -0
- tools/hyperliquid/service.py +1680 -0
- tools/knowledge_ingest.py +950 -0
- tools/mcp/README.md +535 -0
- tools/mcp/__init__.py +52 -0
- tools/mcp/catalog.py +115 -0
- tools/mcp/config.py +337 -0
- tools/mcp/mcp_tool.py +1415 -0
- tools/mcp/param_coercion.py +289 -0
- tools/mcp/protocol.py +1520 -0
- tools/mcp/rate_limit.py +50 -0
- tools/mcp/security.py +424 -0
- tools/mcp/self_install.py +111 -0
- tools/mcp/server_manager.py +829 -0
- tools/mcp/subscriptions.py +72 -0
- tools/mcp/user_mcp_service.py +899 -0
- tools/mcp/validation_tracker.py +89 -0
- tools/mcp/views.py +346 -0
- tools/oauth/__init__.py +17 -0
- tools/oauth/manager.py +75 -0
- tools/oauth/provider.py +69 -0
- tools/oauth/providers/__init__.py +1 -0
- tools/oauth/providers/generic_oauth2.py +96 -0
- tools/perplexity_tool.py +280 -0
- tools/polymarket/__init__.py +41 -0
- tools/polymarket/clob_adapter.py +76 -0
- tools/polymarket/models.py +182 -0
- tools/polymarket/service.py +2082 -0
- tools/self_env/__init__.py +61 -0
- tools/self_env/tool.py +274 -0
- tools/shell/__init__.py +80 -0
- tools/shell/backend_pool.py +118 -0
- tools/shell/discipline.py +62 -0
- tools/shell/executor.py +157 -0
- tools/shell/loopback_allow.py +87 -0
- tools/shell/process_registry.py +113 -0
- tools/shell/process_tool.py +131 -0
- tools/shell/state.py +129 -0
- tools/shell/tool.py +151 -0
- tools/task_tool.py +637 -0
- tools/twitter_tool.py +2086 -0
- tools/user_directory.py +179 -0
- tools/web_fetch/__init__.py +3 -0
- tools/web_fetch/fetcher.py +144 -0
- tools/web_fetch/render.py +44 -0
- tools/web_fetch/tool.py +60 -0
- tools/x402/__init__.py +60 -0
- tools/x402/client.py +47 -0
- tools/x402/invoice_tool.py +143 -0
- tools/x402/real_client.py +250 -0
- tools/x402/service.py +131 -0
- utils/README.md +498 -0
- utils/__init__.py +46 -0
- utils/auth_utils.py +114 -0
- utils/bounded_collections.py +162 -0
- utils/circuit_breaker.py +389 -0
- utils/gif_utils.py +435 -0
- utils/markdown_utils.py +291 -0
- utils/message_utils.py +147 -0
- utils/metrics.py +36 -0
- utils/path_validator.py +227 -0
- utils/rate_limit_manager.py +399 -0
- utils/result_size.py +296 -0
- utils/time_utils.py +206 -0
- utils/user_utils.py +188 -0
- webview/README.md +111 -0
- webview/RENAME_AND_ALIGN_HANDOFF.md +200 -0
- webview/__init__.py +8 -0
- webview/activity.py +636 -0
- webview/owner_auth.py +108 -0
- webview/pages.py +448 -0
- webview/repair_sessions.py +399 -0
- webview/server.py +4323 -0
- webview/server_launcher.py +112 -0
- webview/static/css/activity.css +89 -0
- webview/static/css/chat.css +1772 -0
- webview/static/css/components.css +1190 -0
- webview/static/css/config-panel.css +651 -0
- webview/static/css/pages/admin.css +766 -0
- webview/static/css/pages/profile.css +231 -0
- webview/static/css/pages/settings.css +297 -0
- webview/static/css/pages/signin.css +316 -0
- webview/static/css/style.css +4250 -0
- webview/static/css/variables.css +147 -0
- webview/static/css/workspace-fullwidth-fix.css +109 -0
- webview/static/img/favicon.ico +0 -0
- webview/static/js/activity.js +394 -0
- webview/static/js/admin/activity.js +186 -0
- webview/static/js/admin/dashboard.js +163 -0
- webview/static/js/admin/user_detail.js +400 -0
- webview/static/js/admin/users.js +174 -0
- webview/static/js/admin/utils.js +214 -0
- webview/static/js/chat.js +3178 -0
- webview/static/js/config-panel.js +522 -0
- webview/static/js/constants.js +20 -0
- webview/static/js/error-handler.js +226 -0
- webview/static/js/ethers.min.js +1 -0
- webview/static/js/event-filter.js +137 -0
- webview/static/js/event-store.js +351 -0
- webview/static/js/file-attachments.js +374 -0
- webview/static/js/file-loader.js +163 -0
- webview/static/js/index.js +103 -0
- webview/static/js/performance-utils.js +196 -0
- webview/static/js/profile.js +396 -0
- webview/static/js/screenshot.js +386 -0
- webview/static/js/session.js +1527 -0
- webview/static/js/settings.js +1288 -0
- webview/static/js/sidebar-data.js +766 -0
- webview/static/js/sidebar-toggle.js +296 -0
- webview/static/js/socket.io.min.js +7 -0
- webview/static/js/stats.js +355 -0
- webview/static/js/ui-utils.js +420 -0
- webview/static/js/workspace.js +966 -0
- webview/stats_service.py +613 -0
- webview/templates/__init__.py +1 -0
- webview/templates/__pycache__/__init__.cpython-311.pyc +0 -0
- webview/templates/activity.html +36 -0
- webview/templates/admin/activity.html +122 -0
- webview/templates/admin/dashboard.html +112 -0
- webview/templates/admin/user_detail.html +228 -0
- webview/templates/admin/users.html +105 -0
- webview/templates/autonomy.html +60 -0
- webview/templates/error.html +133 -0
- webview/templates/finance.html +90 -0
- webview/templates/identity.html +73 -0
- webview/templates/index.html +42 -0
- webview/templates/layout.html +125 -0
- webview/templates/memory.html +59 -0
- webview/templates/owner_login.html +15 -0
- webview/templates/profile.html +121 -0
- webview/templates/session.html +312 -0
- webview/templates/settings.html +534 -0
- webview/templates/sidebar.html +112 -0
- webview/templates/signin.html +213 -0
- webview/templates/status.html +14 -0
- webview/templates/system.html +45 -0
- webview/webgate.py +196 -0
core/config.py
ADDED
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
"""Location: core/config.py"""
|
|
2
|
+
|
|
3
|
+
"""Configuration management for the bot."""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import logging
|
|
8
|
+
from typing import Any, Optional, Dict, List
|
|
9
|
+
from pydantic import Field, field_validator, PrivateAttr, BaseModel
|
|
10
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
11
|
+
|
|
12
|
+
from core.env import parse_bool
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# ---------------------------------------------------------------------------
|
|
16
|
+
# AgentConfig — pure-agent settings that rob-core needs to run standalone.
|
|
17
|
+
#
|
|
18
|
+
# Lives in core so rob-core has a config surface that imports zero
|
|
19
|
+
# server/billing/multi-tenant fields. ServerConfig below inherits from this
|
|
20
|
+
# and adds the server-scope fields (auth, billing, blockchain, x402, etc.).
|
|
21
|
+
# Existing `from core.config import BotConfig` call sites keep working via
|
|
22
|
+
# the `BotConfig = ServerConfig` alias at the bottom of this file.
|
|
23
|
+
# When the server is extracted to a separate repo, ServerConfig moves to
|
|
24
|
+
# polyrob-platform.
|
|
25
|
+
#
|
|
26
|
+
# Conservative scope: only fields that are unambiguously agent-scope are
|
|
27
|
+
# declared here. Anything mixed (auto_*, twitter_*, blockchain, alchemy, MCP
|
|
28
|
+
# config dict, browser/agent/controller dicts) stays in ServerConfig until the
|
|
29
|
+
# Phase B repo split forces the full classification.
|
|
30
|
+
# ---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class AgentConfig(BaseSettings):
|
|
34
|
+
"""Pure-agent configuration — LLM keys, sessions, paths, logging."""
|
|
35
|
+
|
|
36
|
+
model_config = SettingsConfigDict(
|
|
37
|
+
env_file='.env',
|
|
38
|
+
env_file_encoding='utf-8',
|
|
39
|
+
extra='ignore',
|
|
40
|
+
validate_assignment=True,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Base settings
|
|
44
|
+
base_dir: str = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
45
|
+
environment: str = "development"
|
|
46
|
+
|
|
47
|
+
# Data paths
|
|
48
|
+
data_dir: str = Field(default="data")
|
|
49
|
+
db_path: str = Field(default="data/bot.db")
|
|
50
|
+
|
|
51
|
+
# Logging
|
|
52
|
+
log_level: str = Field('INFO', alias='LOG_LEVEL')
|
|
53
|
+
|
|
54
|
+
# LLM API Keys (no model selection here — that lives in
|
|
55
|
+
# modules.llm.llm_client_registry.DEFAULT_MODELS).
|
|
56
|
+
openai_api_key: Optional[str] = Field(default=None, alias='OPENAI_API_KEY')
|
|
57
|
+
anthropic_api_key: Optional[str] = Field(default=None, alias='ANTHROPIC_API_KEY')
|
|
58
|
+
gemini_api_key: Optional[str] = Field(default=None, alias='GEMINI_API_KEY')
|
|
59
|
+
deepseek_api_key: Optional[str] = Field(default=None, alias='DEEPSEEK_API_KEY')
|
|
60
|
+
deepseek_api_url: Optional[str] = Field(default="https://api.deepseek.com/v1", alias='DEEPSEEK_API_URL')
|
|
61
|
+
openrouter_api_key: Optional[str] = Field(default=None, alias='OPENROUTER_API_KEY')
|
|
62
|
+
openrouter_site_url: Optional[str] = Field(default="", alias='OPENROUTER_SITE_URL')
|
|
63
|
+
openrouter_site_name: Optional[str] = Field(default="POLYROB AI Agent", alias='OPENROUTER_SITE_NAME')
|
|
64
|
+
# NVIDIA NIM (OpenAI-compatible; free hosted inference for Kimi/Llama/etc.)
|
|
65
|
+
nvidia_api_key: Optional[str] = Field(default=None, alias='NVIDIA_API_KEY')
|
|
66
|
+
nvidia_api_url: Optional[str] = Field(default="https://integrate.api.nvidia.com/v1", alias='NVIDIA_API_URL')
|
|
67
|
+
perplexity_api_key: Optional[str] = Field(default=None, alias='PERPLEXITY_API_KEY')
|
|
68
|
+
|
|
69
|
+
# Default agent persona
|
|
70
|
+
characters_dir: str = Field(default="agents/personality/characters", alias='CHARACTERS_DIR')
|
|
71
|
+
default_character: str = Field(default="rob", alias='DEFAULT_CHARACTER')
|
|
72
|
+
|
|
73
|
+
# Session memory management
|
|
74
|
+
session_ttl_seconds: int = Field(default=86400, alias='SESSION_TTL_SECONDS')
|
|
75
|
+
max_sessions_in_memory: int = Field(default=100, alias='MAX_SESSIONS_IN_MEMORY')
|
|
76
|
+
session_cleanup_interval: int = Field(default=600, alias='SESSION_CLEANUP_INTERVAL')
|
|
77
|
+
max_sessions_per_user: int = Field(default=10, alias='MAX_SESSIONS_PER_USER')
|
|
78
|
+
# A session stuck in 'created' that never ran has no run-path activity timestamp,
|
|
79
|
+
# so the TTL/LRU GC (which keys off _session_last_activity) never retires it — yet it
|
|
80
|
+
# still counts toward max_sessions_per_user. This shorter TTL (keyed off created_at)
|
|
81
|
+
# retires such never-run sessions so they stop consuming the per-user limit.
|
|
82
|
+
created_session_ttl_seconds: int = Field(default=3600, alias='CREATED_SESSION_TTL_SECONDS')
|
|
83
|
+
|
|
84
|
+
# Sub-agent delegation (C-DELEG: ON by default with conservative caps below —
|
|
85
|
+
# depth=1, max 3 concurrent, 600s/900s timeouts. Set SUB_AGENTS_ENABLED=false to opt out.)
|
|
86
|
+
sub_agents_enabled: bool = Field(default=True, alias='SUB_AGENTS_ENABLED')
|
|
87
|
+
sub_agent_timeout: int = Field(default=600, alias='SUB_AGENT_TIMEOUT')
|
|
88
|
+
parallel_subtasks_timeout: int = Field(default=900, alias='PARALLEL_SUBTASKS_TIMEOUT')
|
|
89
|
+
max_concurrent_sub_agents: int = Field(default=3, alias='MAX_CONCURRENT_SUB_AGENTS')
|
|
90
|
+
max_sub_agent_depth: int = Field(default=1, alias='MAX_SUB_AGENT_DEPTH')
|
|
91
|
+
|
|
92
|
+
# Agent-side validators (moved out of BotConfig)
|
|
93
|
+
@field_validator('session_ttl_seconds')
|
|
94
|
+
@classmethod
|
|
95
|
+
def _validate_ttl(cls, v: int) -> int:
|
|
96
|
+
if v < 60:
|
|
97
|
+
raise ValueError("Session TTL must be at least 60 seconds")
|
|
98
|
+
if v > 604800:
|
|
99
|
+
logging.getLogger(__name__).warning(
|
|
100
|
+
f"Session TTL {v}s is very high (>7 days) - may cause memory issues"
|
|
101
|
+
)
|
|
102
|
+
return v
|
|
103
|
+
|
|
104
|
+
@field_validator('max_sessions_in_memory')
|
|
105
|
+
@classmethod
|
|
106
|
+
def _validate_max_sessions(cls, v: int) -> int:
|
|
107
|
+
if v < 1:
|
|
108
|
+
raise ValueError("Must allow at least 1 session in memory")
|
|
109
|
+
if v > 1000:
|
|
110
|
+
logging.getLogger(__name__).warning(
|
|
111
|
+
f"Max sessions {v} is very high - may cause memory issues"
|
|
112
|
+
)
|
|
113
|
+
return v
|
|
114
|
+
|
|
115
|
+
@field_validator('session_cleanup_interval')
|
|
116
|
+
@classmethod
|
|
117
|
+
def _validate_cleanup_interval(cls, v: int) -> int:
|
|
118
|
+
if v < 10:
|
|
119
|
+
raise ValueError("Cleanup interval must be at least 10 seconds")
|
|
120
|
+
if v > 3600:
|
|
121
|
+
logging.getLogger(__name__).warning(
|
|
122
|
+
f"Cleanup interval {v}s is very high (>1 hour)"
|
|
123
|
+
)
|
|
124
|
+
return v
|
|
125
|
+
|
|
126
|
+
def available_providers(self) -> list:
|
|
127
|
+
"""Provider names whose API key is set on this config, in PROFILES order.
|
|
128
|
+
|
|
129
|
+
The config-object companion to ``modules.llm.profiles.providers_with_keys``
|
|
130
|
+
(which reads an env mapping). One SSOT for "which providers have a key" for
|
|
131
|
+
callers that hold a config (banner, ``rob model list``).
|
|
132
|
+
"""
|
|
133
|
+
from modules.llm.profiles import PROFILES
|
|
134
|
+
return [
|
|
135
|
+
name for name in PROFILES
|
|
136
|
+
if getattr(self, f"{name}_api_key", None)
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class ServerConfig(AgentConfig):
|
|
141
|
+
"""Full server-side configuration: agent fields (inherited) + server-scope."""
|
|
142
|
+
|
|
143
|
+
# NOTE: model_config inherited from AgentConfig. The fields below are
|
|
144
|
+
# everything that depends on the server stack (auth, billing, payments,
|
|
145
|
+
# blockchain, multi-tenant, Telegram/Twitter/Gmail). When rob-server is
|
|
146
|
+
# extracted as a separate package, this class moves to polyrob-platform.
|
|
147
|
+
|
|
148
|
+
# Bot settings - Required fields with aliases
|
|
149
|
+
admin_ids: List[int] = Field(default_factory=list, alias='ADMIN_IDS')
|
|
150
|
+
moderator_ids: List[int] = Field(default_factory=list, alias='MODERATOR_IDS')
|
|
151
|
+
support_chat_id: Optional[int] = Field(None, alias='SUPPORT_CHAT_ID')
|
|
152
|
+
feedback_chat_id: Optional[int] = Field(None, alias='FEEDBACK_CHAT_ID')
|
|
153
|
+
auto_knowledge_retention_days: int = Field(default=7, alias='AUTO_KNOWLEDGE_RETENTION_DAYS')
|
|
154
|
+
auto_metrics_enabled: bool = Field(default=True, alias='AUTO_METRICS_ENABLED')
|
|
155
|
+
auto_safe_mode: bool = Field(default=True, alias='AUTO_SAFE_MODE')
|
|
156
|
+
|
|
157
|
+
# HITL (Human-in-the-Loop) Configuration
|
|
158
|
+
hitl_mode: str = Field(default="chat", alias='HITL_MODE') # "chat" | "block" | "off"
|
|
159
|
+
destructive_action_policy: str = Field(default="none", alias='DESTRUCTIVE_ACTION_POLICY') # "confirm_phrase" | "soft_wait" | "none"
|
|
160
|
+
interrupt_window_seconds: int = Field(default=5, alias='INTERRUPT_WINDOW_SECONDS')
|
|
161
|
+
|
|
162
|
+
# OCR Service Configuration
|
|
163
|
+
services_ocr_enabled: bool = Field(default=True, alias='SERVICES_OCR_ENABLED')
|
|
164
|
+
services_ocr_tesseract_path: str = Field(default="", alias='SERVICES_OCR_TESSERACT_PATH')
|
|
165
|
+
services_ocr_dpi: int = Field(default=300, alias='SERVICES_OCR_DPI')
|
|
166
|
+
services_ocr_languages: List[str] = Field(default_factory=lambda: ["eng"], alias='SERVICES_OCR_LANGUAGES')
|
|
167
|
+
services_ocr_use_llm_correction: bool = Field(default=True, alias='SERVICES_OCR_USE_LLM_CORRECTION')
|
|
168
|
+
services_ocr_temp_dir: str = Field(default="data/temp", alias='SERVICES_OCR_TEMP_DIR')
|
|
169
|
+
|
|
170
|
+
# LLM API keys live on AgentConfig (parent) — see top of file.
|
|
171
|
+
|
|
172
|
+
# Pinecone retired: cross-session semantic recall is now local (sqlite-vec memory
|
|
173
|
+
# backend). The local embedding model is configured via get_embedding_config().
|
|
174
|
+
|
|
175
|
+
# data_dir, db_path live on AgentConfig (parent).
|
|
176
|
+
|
|
177
|
+
# Cache Configuration
|
|
178
|
+
cache_size: int = Field(default=1000, alias='CACHE_SIZE')
|
|
179
|
+
cache_ttl: int = Field(default=3600)
|
|
180
|
+
|
|
181
|
+
# Browser Use Configuration
|
|
182
|
+
browser_use_logging_level: str = Field('info', description="Browser Use logging level", alias='BROWSER_USE_LOGGING_LEVEL')
|
|
183
|
+
anonymized_telemetry: bool = Field(True, description="Enable anonymized telemetry", alias='ANONYMIZED_TELEMETRY')
|
|
184
|
+
max_browser_contexts: int = Field(default=25, alias='MAX_BROWSER_CONTEXTS', description="Maximum concurrent browser contexts")
|
|
185
|
+
max_contexts_per_session: int = Field(default=2, alias='MAX_CONTEXTS_PER_SESSION', description="Maximum browser contexts per session")
|
|
186
|
+
browser_headless: bool = Field(default=True, alias='BROWSER_HEADLESS', description="Run browser in headless mode")
|
|
187
|
+
browser_context_timeout: float = Field(default=30.0, alias='BROWSER_CONTEXT_TIMEOUT', description="Timeout (s) for creating a browser context")
|
|
188
|
+
browser_stale_timeout: float = Field(default=300.0, alias='BROWSER_STALE_TIMEOUT', description="Idle timeout (s) before a context is considered stale")
|
|
189
|
+
browser_enable_pooling: bool = Field(default=True, alias='BROWSER_ENABLE_POOLING', description="Enable browser context pooling/reuse")
|
|
190
|
+
browser_wait_queue_backstop_interval: float = Field(default=15.0, alias='BROWSER_WAIT_QUEUE_BACKSTOP_INTERVAL', description="Poll interval (s) for the wait-queue backstop loop (primary path resolves waiters synchronously on release)")
|
|
191
|
+
|
|
192
|
+
# log_level lives on AgentConfig (parent).
|
|
193
|
+
assistant_id: Optional[str] = Field(None, alias='ASSISTANT_ID')
|
|
194
|
+
|
|
195
|
+
# Document processor settings
|
|
196
|
+
doc_max_file_size: int = Field(default=20 * 1024 * 1024, description="Maximum file size for document processor (20MB)")
|
|
197
|
+
doc_max_text_length: int = Field(default=100000, description="Maximum text length for document processor")
|
|
198
|
+
doc_chunk_size: int = Field(default=4096, description="Chunk size for document processor")
|
|
199
|
+
doc_cache_ttl: int = Field(default=3600, description="Cache TTL for document processor")
|
|
200
|
+
|
|
201
|
+
# characters_dir, default_character live on AgentConfig (parent).
|
|
202
|
+
|
|
203
|
+
# Profile monitoring configuration
|
|
204
|
+
profiles_to_monitor: List[str] = Field(default_factory=list, description="List of Twitter profiles to monitor")
|
|
205
|
+
update_interval_seconds: int = Field(360, description="Interval between profile updates in seconds")
|
|
206
|
+
|
|
207
|
+
# API configuration
|
|
208
|
+
api_host: str = Field('127.0.0.1', alias='API_HOST')
|
|
209
|
+
api_port: int = Field(9000, alias='API_PORT')
|
|
210
|
+
api_auth_token: Optional[str] = Field(None, alias='API_AUTH_TOKEN')
|
|
211
|
+
|
|
212
|
+
# Twitter configuration with correct env var names
|
|
213
|
+
twitter_api_key: Optional[str] = Field(None, alias='TWITTER_API_KEY')
|
|
214
|
+
twitter_api_secret_key: Optional[str] = Field(None, alias='TWITTER_API_SECRET_KEY') # Match env var
|
|
215
|
+
twitter_access_token: Optional[str] = Field(None, alias='TWITTER_ACCESS_TOKEN')
|
|
216
|
+
twitter_access_token_secret: Optional[str] = Field(None, alias='TWITTER_ACCESS_TOKEN_SECRET')
|
|
217
|
+
twitter_bearer_token: Optional[str] = Field(None, alias='TWITTER_BEARER_TOKEN')
|
|
218
|
+
twitter_bot_user_id: Optional[str] = Field(None, alias='TWITTER_BOT_USER_ID')
|
|
219
|
+
twitter_bot_username: Optional[str] = Field(None, alias='TWITTER_BOT_USERNAME')
|
|
220
|
+
|
|
221
|
+
# Gmail configuration
|
|
222
|
+
gmail_email: Optional[str] = Field(None, description="Gmail email address", alias='GMAIL_EMAIL')
|
|
223
|
+
gmail_app_password: Optional[str] = Field(None, description="Gmail app password", alias='GMAIL_APP_PASSWORD')
|
|
224
|
+
gmail_imap_server: str = Field('imap.gmail.com', description="Gmail IMAP server", alias='GMAIL_IMAP_SERVER')
|
|
225
|
+
gmail_smtp_server: str = Field('smtp.gmail.com', description="Gmail SMTP server", alias='GMAIL_SMTP_SERVER')
|
|
226
|
+
gmail_smtp_port: int = Field(587, description="Gmail SMTP port", alias='GMAIL_SMTP_PORT')
|
|
227
|
+
|
|
228
|
+
# perplexity_api_key lives on AgentConfig (parent) — see top of file.
|
|
229
|
+
|
|
230
|
+
# MCP (Model Context Protocol) configuration
|
|
231
|
+
mcp: Optional[Dict[str, Any]] = Field(
|
|
232
|
+
default=None,
|
|
233
|
+
description="MCP server configuration"
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
# MCP environment variable bridging
|
|
237
|
+
mcp_enabled: bool = Field(default=False, alias='MCP_ENABLED', description="Enable MCP service globally")
|
|
238
|
+
mcp_servers_config: Optional[str] = Field(default=None, alias='MCP_SERVERS_CONFIG', description="JSON string containing MCP servers configuration")
|
|
239
|
+
|
|
240
|
+
# Sub-agent config lives on AgentConfig (parent).
|
|
241
|
+
|
|
242
|
+
# Rate Limiting
|
|
243
|
+
rate_limit_window: int = Field(default=60, description="Rate limit window in seconds")
|
|
244
|
+
rate_limit_max_requests: int = Field(default=30, description="Maximum requests per window")
|
|
245
|
+
rate_limit: int = Field(
|
|
246
|
+
default=1,
|
|
247
|
+
description="Rate limit in seconds"
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
# Goals and Behavior
|
|
251
|
+
goals: Dict[str, Any] = Field(
|
|
252
|
+
default_factory=dict,
|
|
253
|
+
description="Bot goals and behavior configuration"
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Telemetry
|
|
257
|
+
telemetry_app_url: str = "https://eu.i.posthog.com"
|
|
258
|
+
telemetry_app_port: int = Field(8080, alias='TELEMETRY_APP_PORT')
|
|
259
|
+
|
|
260
|
+
# Legacy fields - kept for compatibility but not used
|
|
261
|
+
# These can be removed in a future version
|
|
262
|
+
|
|
263
|
+
# SSL verification
|
|
264
|
+
ssl_verify: bool = Field(
|
|
265
|
+
True,
|
|
266
|
+
description="Whether to verify SSL certificates",
|
|
267
|
+
alias='SSL_VERIFY'
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
# Memory feature flags — must be declared as real fields so pydantic-settings
|
|
271
|
+
# reads the env var (getattr on an undeclared key always returns the default,
|
|
272
|
+
# silently ignoring the environment — the Task 0.3 landmine).
|
|
273
|
+
HIERARCHICAL_MEMORY_ENABLED: bool = True
|
|
274
|
+
COMPACTION_ENABLED: bool = True
|
|
275
|
+
SEMANTIC_RETRIEVAL_ENABLED: bool = True
|
|
276
|
+
REFLECTION_ENABLED: bool = True
|
|
277
|
+
FORGETTING_ENABLED: bool = True
|
|
278
|
+
|
|
279
|
+
@field_validator(
|
|
280
|
+
"HIERARCHICAL_MEMORY_ENABLED", "COMPACTION_ENABLED", "SEMANTIC_RETRIEVAL_ENABLED",
|
|
281
|
+
"REFLECTION_ENABLED", "FORGETTING_ENABLED", mode="before",
|
|
282
|
+
)
|
|
283
|
+
@classmethod
|
|
284
|
+
def _coerce_mem(cls, v):
|
|
285
|
+
# POLYROB falsey-set semantics (core.env.parse_bool, the repo-wide SSOT): a bool
|
|
286
|
+
# passes through unchanged; a string is True unless it is one of the falsey tokens
|
|
287
|
+
# ('none'/''/etc, which pydantic's native bool parser would otherwise reject).
|
|
288
|
+
if isinstance(v, bool):
|
|
289
|
+
return v
|
|
290
|
+
return parse_bool(v, False)
|
|
291
|
+
|
|
292
|
+
# New fields from the code block
|
|
293
|
+
owner_id: Optional[int] = Field(None, description="Admin user ID")
|
|
294
|
+
whitelisted_chats: List[int] = Field(default_factory=list, description="List of whitelisted chats")
|
|
295
|
+
roles: Dict[str, Dict[str, bool]] = Field(default_factory=lambda: {
|
|
296
|
+
'super_admin': {
|
|
297
|
+
'all_permissions': True
|
|
298
|
+
},
|
|
299
|
+
'admin': {
|
|
300
|
+
'use_bot': True,
|
|
301
|
+
'manage_users': True,
|
|
302
|
+
'manage_modes': True,
|
|
303
|
+
'manage_knowledge': True,
|
|
304
|
+
'manage_prompts': True
|
|
305
|
+
},
|
|
306
|
+
'moderator': {
|
|
307
|
+
'use_bot': True,
|
|
308
|
+
'manage_users': False,
|
|
309
|
+
'manage_modes': True,
|
|
310
|
+
'manage_knowledge': False,
|
|
311
|
+
'manage_prompts': False
|
|
312
|
+
},
|
|
313
|
+
'user': {
|
|
314
|
+
'use_bot': True,
|
|
315
|
+
'manage_users': False,
|
|
316
|
+
'manage_modes': False,
|
|
317
|
+
'manage_knowledge': False,
|
|
318
|
+
'manage_prompts': False
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
# Add model configuration
|
|
323
|
+
model_cache_dir: Optional[str] = Field(
|
|
324
|
+
default=None,
|
|
325
|
+
description="Directory to cache model files"
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
# Embedding Configuration
|
|
329
|
+
embedding: Dict[str, Any] = Field(
|
|
330
|
+
default_factory=dict,
|
|
331
|
+
description="Embedding model configuration"
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
# Session memory management + validators live on AgentConfig (parent).
|
|
335
|
+
|
|
336
|
+
# Add after the existing config methods in BotConfig class
|
|
337
|
+
|
|
338
|
+
def get_embedding_config(self) -> Dict[str, Any]:
|
|
339
|
+
"""Get embedding model configuration."""
|
|
340
|
+
# Check if embedding configuration is provided in config
|
|
341
|
+
if hasattr(self, 'embedding') and isinstance(self.embedding, dict):
|
|
342
|
+
config = self.embedding.copy()
|
|
343
|
+
else:
|
|
344
|
+
# Use field-based configuration
|
|
345
|
+
config = {
|
|
346
|
+
'model_name': getattr(self, 'embedding_model_name', 'sentence-transformers/all-MiniLM-L6-v2'),
|
|
347
|
+
'dimension': getattr(self, 'embedding_dimension', 384),
|
|
348
|
+
'max_seq_length': getattr(self, 'embedding_max_seq_length', 128)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
# Add default values for missing keys
|
|
352
|
+
config.setdefault('model_name', 'sentence-transformers/all-MiniLM-L6-v2')
|
|
353
|
+
config.setdefault('dimension', getattr(self, 'embedding_dimension', 384))
|
|
354
|
+
config.setdefault('max_seq_length', 128)
|
|
355
|
+
config.setdefault('normalize_embeddings', True)
|
|
356
|
+
config.setdefault('cache_folder', str(Path(self.data_dir) / 'models'))
|
|
357
|
+
config.setdefault('device', 'cpu')
|
|
358
|
+
|
|
359
|
+
return config
|
|
360
|
+
|
|
361
|
+
def get_ocr_config(self) -> Dict[str, Any]:
|
|
362
|
+
"""Get OCR service configuration."""
|
|
363
|
+
return {
|
|
364
|
+
'enabled': self.services_ocr_enabled,
|
|
365
|
+
'tesseract_path': self.services_ocr_tesseract_path,
|
|
366
|
+
'dpi': self.services_ocr_dpi,
|
|
367
|
+
'languages': self.services_ocr_languages,
|
|
368
|
+
'use_llm_correction': self.services_ocr_use_llm_correction,
|
|
369
|
+
'temp_dir': self.services_ocr_temp_dir
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
# Add these new fields to model_config
|
|
373
|
+
embedding_model_name: str = Field(
|
|
374
|
+
default='sentence-transformers/all-MiniLM-L6-v2',
|
|
375
|
+
description="Name of the sentence transformer model to use",
|
|
376
|
+
alias='EMBEDDING_MODEL_NAME'
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
embedding_dimension: int = Field(
|
|
380
|
+
default=384,
|
|
381
|
+
description="Dimension of embeddings",
|
|
382
|
+
alias='EMBEDDING_DIMENSION'
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
embedding_max_seq_length: int = Field(
|
|
386
|
+
default=128,
|
|
387
|
+
description="Maximum sequence length for embeddings",
|
|
388
|
+
alias='EMBEDDING_MAX_SEQ_LENGTH'
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
# Add validators for new fields
|
|
392
|
+
@field_validator('embedding_dimension')
|
|
393
|
+
def validate_embedding_dimension(cls, v: int) -> int:
|
|
394
|
+
"""Validate embedding dimension."""
|
|
395
|
+
if v <= 0:
|
|
396
|
+
raise ValueError("Embedding dimension must be positive")
|
|
397
|
+
return v
|
|
398
|
+
|
|
399
|
+
@field_validator('embedding_max_seq_length')
|
|
400
|
+
def validate_embedding_max_seq_length(cls, v: int) -> int:
|
|
401
|
+
"""Validate max sequence length."""
|
|
402
|
+
if v <= 0:
|
|
403
|
+
raise ValueError("Max sequence length must be positive")
|
|
404
|
+
return v
|
|
405
|
+
|
|
406
|
+
@field_validator('services_ocr_dpi')
|
|
407
|
+
def validate_ocr_dpi(cls, v: int) -> int:
|
|
408
|
+
"""Validate OCR DPI setting."""
|
|
409
|
+
if v < 72:
|
|
410
|
+
raise ValueError("OCR DPI must be at least 72")
|
|
411
|
+
return v
|
|
412
|
+
|
|
413
|
+
# Private attributes
|
|
414
|
+
_logger: logging.Logger = PrivateAttr()
|
|
415
|
+
_env_path: Path = PrivateAttr()
|
|
416
|
+
_is_initialized: bool = PrivateAttr(default=False)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
@field_validator('openai_api_key', 'anthropic_api_key', 'alchemy_api_key')
|
|
420
|
+
def validate_api_keys(cls, v: Optional[str], info) -> Optional[str]:
|
|
421
|
+
"""Validate API keys."""
|
|
422
|
+
if v is None:
|
|
423
|
+
return None
|
|
424
|
+
|
|
425
|
+
v = v.strip()
|
|
426
|
+
# Basic validation - check if it looks like a placeholder
|
|
427
|
+
if v.lower() in ['your-openai-key', 'your-anthropic-key', 'your-api-key', 'your-alchemy-key']:
|
|
428
|
+
return None
|
|
429
|
+
|
|
430
|
+
# Basic length check
|
|
431
|
+
if len(v) < 20: # Most API keys are longer than 20 chars
|
|
432
|
+
return None
|
|
433
|
+
|
|
434
|
+
return v
|
|
435
|
+
|
|
436
|
+
def __init__(self, **kwargs):
|
|
437
|
+
"""Initialize configuration."""
|
|
438
|
+
# Initialize with pydantic settings
|
|
439
|
+
super().__init__(**kwargs)
|
|
440
|
+
self._ensure_directories()
|
|
441
|
+
self._load_api_keys()
|
|
442
|
+
self._build_mcp_config_from_env()
|
|
443
|
+
self._is_initialized = True
|
|
444
|
+
|
|
445
|
+
@property
|
|
446
|
+
def is_initialized(self) -> bool:
|
|
447
|
+
"""Check if config is initialized."""
|
|
448
|
+
return self._is_initialized
|
|
449
|
+
|
|
450
|
+
def _build_mcp_config_from_env(self) -> None:
|
|
451
|
+
"""Build MCP configuration from JSON file or environment variables.
|
|
452
|
+
|
|
453
|
+
Priority:
|
|
454
|
+
1. Programmatic config (self.mcp already set)
|
|
455
|
+
2. Local file-first overlay (~/.polyrob/mcp.json, ./.polyrob/mcp.json) — project wins
|
|
456
|
+
3. JSON file (config/mcp_config.json)
|
|
457
|
+
4. Environment variable (MCP_SERVERS_CONFIG)
|
|
458
|
+
"""
|
|
459
|
+
import json
|
|
460
|
+
from pathlib import Path
|
|
461
|
+
|
|
462
|
+
# Priority 1: Use config.mcp if already provided (programmatic)
|
|
463
|
+
if self.mcp is not None:
|
|
464
|
+
return
|
|
465
|
+
|
|
466
|
+
from tools.mcp.config import get_default_mcp_config, MCPConfig, load_local_mcp_servers
|
|
467
|
+
|
|
468
|
+
# File-first local overlay (single-user mode). When present these enable MCP
|
|
469
|
+
# even if MCP_ENABLED is unset, and override base servers on name clash.
|
|
470
|
+
local_servers = load_local_mcp_servers()
|
|
471
|
+
|
|
472
|
+
# Only build config if MCP is enabled OR local files supplied servers.
|
|
473
|
+
if not self.mcp_enabled and not local_servers:
|
|
474
|
+
return
|
|
475
|
+
|
|
476
|
+
# Priority 3: Load from config/mcp_config.json if it exists
|
|
477
|
+
mcp_config = None
|
|
478
|
+
mcp_config_path = Path(self.base_dir) / "config" / "mcp_config.json"
|
|
479
|
+
if mcp_config_path.exists():
|
|
480
|
+
try:
|
|
481
|
+
with open(mcp_config_path, 'r') as f:
|
|
482
|
+
mcp_data = json.load(f)
|
|
483
|
+
mcp_config = MCPConfig(**mcp_data)
|
|
484
|
+
print(f"✅ Loaded MCP config from {mcp_config_path}")
|
|
485
|
+
print(f" Servers: {list(mcp_config.servers.keys())}")
|
|
486
|
+
except Exception as e:
|
|
487
|
+
print(f"❌ Failed to load MCP config from {mcp_config_path}: {e}")
|
|
488
|
+
mcp_config = None
|
|
489
|
+
|
|
490
|
+
# Priority 4: Build from defaults + environment variable (fallback)
|
|
491
|
+
if mcp_config is None:
|
|
492
|
+
mcp_config = get_default_mcp_config()
|
|
493
|
+
mcp_config.enabled = True
|
|
494
|
+
if self.mcp_servers_config:
|
|
495
|
+
try:
|
|
496
|
+
servers_config = json.loads(self.mcp_servers_config)
|
|
497
|
+
for server_name, server_config in servers_config.items():
|
|
498
|
+
mcp_config.servers[server_name] = server_config
|
|
499
|
+
print(f"✅ Loaded MCP servers from environment variable")
|
|
500
|
+
print(f" Servers: {list(mcp_config.servers.keys())}")
|
|
501
|
+
except (json.JSONDecodeError, TypeError) as e:
|
|
502
|
+
print(f"❌ Failed to parse MCP_SERVERS_CONFIG: {e}")
|
|
503
|
+
|
|
504
|
+
# Priority 2 (overlay): local .polyrob/mcp.json servers win on name clash.
|
|
505
|
+
if local_servers:
|
|
506
|
+
for name, server_config in local_servers.items():
|
|
507
|
+
mcp_config.servers[name] = server_config
|
|
508
|
+
mcp_config.enabled = True
|
|
509
|
+
print(f"✅ Overlaid {len(local_servers)} local MCP server(s) from .polyrob/mcp.json")
|
|
510
|
+
|
|
511
|
+
self.mcp = mcp_config.model_dump()
|
|
512
|
+
|
|
513
|
+
def _ensure_directories(self) -> None:
|
|
514
|
+
"""Ensure required directories exist.
|
|
515
|
+
|
|
516
|
+
Anchor every path to base_dir BEFORE creating anything. Construction runs
|
|
517
|
+
during BotConfig() — in the CLI that is BEFORE bootstrap reassigns
|
|
518
|
+
data_dir=.rob — so a relative default ("data", "data/bot.db", "data/temp")
|
|
519
|
+
must not materialize as a stray ./data tree in the caller's CWD.
|
|
520
|
+
"""
|
|
521
|
+
# Runtime isolation (doc 01 T2): when POLYROB_DATA_DIR is set (the server
|
|
522
|
+
# data-home), anchor the relative runtime data paths there — OUTSIDE the
|
|
523
|
+
# code tree — instead of base_dir (the code root). Read via os.getenv only
|
|
524
|
+
# (BotConfig.get is a getattr that ignores the env). The CLI/local path is
|
|
525
|
+
# unaffected: bootstrap reassigns data_dir to an absolute .rob AFTER
|
|
526
|
+
# construction, and these paths are already absolute by then. Fall back to
|
|
527
|
+
# base_dir anchoring (legacy) when unset.
|
|
528
|
+
data_anchor = os.getenv("POLYROB_DATA_DIR") or self.base_dir
|
|
529
|
+
|
|
530
|
+
# Convert relative paths to absolute FIRST (so the mkdirs below never
|
|
531
|
+
# resolve against CWD).
|
|
532
|
+
if not Path(self.db_path).is_absolute():
|
|
533
|
+
self.db_path = str(Path(data_anchor) / self.db_path)
|
|
534
|
+
if not Path(self.data_dir).is_absolute():
|
|
535
|
+
self.data_dir = str(Path(data_anchor) / self.data_dir)
|
|
536
|
+
if not Path(self.services_ocr_temp_dir).is_absolute():
|
|
537
|
+
self.services_ocr_temp_dir = str(Path(data_anchor) / self.services_ocr_temp_dir)
|
|
538
|
+
|
|
539
|
+
# Now create the (absolute) directories. Fail-open on a read-only install
|
|
540
|
+
# dir (R1: pip site-packages) — the CLI reassigns data_dir to .rob anyway.
|
|
541
|
+
try:
|
|
542
|
+
for path in [self.data_dir, Path(self.db_path).parent, self.services_ocr_temp_dir]:
|
|
543
|
+
Path(path).mkdir(parents=True, exist_ok=True)
|
|
544
|
+
for subdir in ["simulations", "characters", "logs", "cache", "knowledge"]:
|
|
545
|
+
Path(self.data_dir, subdir).mkdir(parents=True, exist_ok=True)
|
|
546
|
+
except OSError as e:
|
|
547
|
+
logging.getLogger("core.config").warning("could not create data dirs: %s", e)
|
|
548
|
+
|
|
549
|
+
def _setup_logger(self) -> None:
|
|
550
|
+
"""Set up logging configuration."""
|
|
551
|
+
self._logger = logging.getLogger("config")
|
|
552
|
+
|
|
553
|
+
# Set up console handler
|
|
554
|
+
console_handler = logging.StreamHandler()
|
|
555
|
+
console_formatter = logging.Formatter(
|
|
556
|
+
'[%(asctime)s] %(levelname)s:%(name)s: %(message)s',
|
|
557
|
+
datefmt='%Y-%m-%d %H:%M:%S'
|
|
558
|
+
)
|
|
559
|
+
console_handler.setFormatter(console_formatter)
|
|
560
|
+
|
|
561
|
+
# Set up file handler — anchor to base_dir, never the caller's CWD.
|
|
562
|
+
log_dir = Path(self.base_dir) / "logs"
|
|
563
|
+
log_dir.mkdir(parents=True, exist_ok=True)
|
|
564
|
+
file_handler = logging.FileHandler(
|
|
565
|
+
log_dir / "config.log",
|
|
566
|
+
encoding='utf-8'
|
|
567
|
+
)
|
|
568
|
+
file_handler.setFormatter(console_formatter)
|
|
569
|
+
|
|
570
|
+
# Configure logger
|
|
571
|
+
self._logger.setLevel(getattr(logging, self.log_level.upper()))
|
|
572
|
+
if not self._logger.handlers:
|
|
573
|
+
self._logger.addHandler(console_handler)
|
|
574
|
+
self._logger.addHandler(file_handler)
|
|
575
|
+
self._logger.propagate = False
|
|
576
|
+
|
|
577
|
+
def _log_config_details(self) -> None:
|
|
578
|
+
"""Log configuration details safely."""
|
|
579
|
+
self._logger.debug(f"Environment: {self.environment}")
|
|
580
|
+
self._logger.debug(f"Log Level: {self.log_level}")
|
|
581
|
+
self._logger.debug(f"DB Path: {self.db_path}")
|
|
582
|
+
self._logger.debug(f"Cache Size: {self.cache_size}")
|
|
583
|
+
# Model selection handled by llm_client_registry.DEFAULT_MODELS
|
|
584
|
+
self._logger.debug(f"OCR Service Enabled: {self.services_ocr_enabled}")
|
|
585
|
+
|
|
586
|
+
# Log existence of sensitive fields without revealing values
|
|
587
|
+
self._logger.debug(f"Anthropic API Key exists: {bool(self.anthropic_api_key)}")
|
|
588
|
+
self._logger.debug(f"OpenAI API Key exists: {bool(self.openai_api_key)}")
|
|
589
|
+
self._logger.debug(f"Alchemy API Key exists: {bool(self.alchemy_api_key)}")
|
|
590
|
+
|
|
591
|
+
def load_twitter_config(self) -> None:
|
|
592
|
+
"""Load Twitter configuration from environment."""
|
|
593
|
+
if all([
|
|
594
|
+
self.twitter_api_key,
|
|
595
|
+
self.twitter_api_secret_key, # Match the field name
|
|
596
|
+
self.twitter_access_token,
|
|
597
|
+
self.twitter_access_token_secret,
|
|
598
|
+
self.twitter_bearer_token
|
|
599
|
+
]):
|
|
600
|
+
self._logger.info("Twitter API credentials configured")
|
|
601
|
+
else:
|
|
602
|
+
missing = []
|
|
603
|
+
if not self.twitter_api_key:
|
|
604
|
+
missing.append("TWITTER_API_KEY")
|
|
605
|
+
if not self.twitter_api_secret_key: # Match the field name
|
|
606
|
+
missing.append("TWITTER_API_SECRET_KEY") # Match env var name
|
|
607
|
+
if not self.twitter_access_token:
|
|
608
|
+
missing.append("TWITTER_ACCESS_TOKEN")
|
|
609
|
+
if not self.twitter_access_token_secret:
|
|
610
|
+
missing.append("TWITTER_ACCESS_TOKEN_SECRET")
|
|
611
|
+
if not self.twitter_bearer_token:
|
|
612
|
+
missing.append("TWITTER_BEARER_TOKEN")
|
|
613
|
+
|
|
614
|
+
if missing:
|
|
615
|
+
self._logger.warning(f"Missing Twitter credentials: {', '.join(missing)}")
|
|
616
|
+
|
|
617
|
+
@property
|
|
618
|
+
def is_development(self) -> bool:
|
|
619
|
+
"""Check if environment is development."""
|
|
620
|
+
return self.environment.lower() == 'development'
|
|
621
|
+
|
|
622
|
+
# Validators
|
|
623
|
+
@field_validator('api_port', 'telemetry_app_port')
|
|
624
|
+
def validate_port(cls, v: int) -> int:
|
|
625
|
+
"""Validate port number is in valid range."""
|
|
626
|
+
if not 1 <= v <= 65535:
|
|
627
|
+
raise ValueError("Port must be between 1 and 65535")
|
|
628
|
+
return v
|
|
629
|
+
|
|
630
|
+
@field_validator('twitter_api_key', 'twitter_api_secret_key',
|
|
631
|
+
'twitter_access_token', 'twitter_access_token_secret',
|
|
632
|
+
'twitter_bearer_token')
|
|
633
|
+
def validate_twitter_credentials(cls, v: Optional[str], info) -> Optional[str]:
|
|
634
|
+
"""Validate Twitter credentials."""
|
|
635
|
+
if v is None:
|
|
636
|
+
return None
|
|
637
|
+
|
|
638
|
+
v = v.strip()
|
|
639
|
+
if v.lower() in ['your-twitter-key', 'your-api-key', 'your-token']:
|
|
640
|
+
return None
|
|
641
|
+
|
|
642
|
+
if len(v) < 20: # Most Twitter keys are longer
|
|
643
|
+
return None
|
|
644
|
+
|
|
645
|
+
return v
|
|
646
|
+
|
|
647
|
+
def get(self, key: str, default=None):
|
|
648
|
+
"""Dict-like accessor. WARNING: keys that are not declared fields fall back to
|
|
649
|
+
`default` and never read the environment — declare feature flags as fields."""
|
|
650
|
+
if not hasattr(self, key):
|
|
651
|
+
logging.getLogger(__name__).debug(
|
|
652
|
+
"BotConfig.get('%s') is not a declared field; returning default %r "
|
|
653
|
+
"(env var, if any, is NOT read)", key, default
|
|
654
|
+
)
|
|
655
|
+
return getattr(self, key, default)
|
|
656
|
+
|
|
657
|
+
def _load_api_keys(self) -> None:
|
|
658
|
+
"""Load API keys from config."""
|
|
659
|
+
# Twitter API keys
|
|
660
|
+
twitter = {k: v for k, v in self.get_twitter_config().items() if v}
|
|
661
|
+
self.twitter_api_key = twitter.get('api_key')
|
|
662
|
+
self.twitter_api_secret_key = twitter.get('api_secret')
|
|
663
|
+
self.twitter_access_token = twitter.get('access_token')
|
|
664
|
+
self.twitter_access_token_secret = twitter.get('access_token_secret')
|
|
665
|
+
self.twitter_bearer_token = twitter.get('bearer_token')
|
|
666
|
+
|
|
667
|
+
def get_llm_config(self) -> Dict[str, Any]:
|
|
668
|
+
"""Get LLM configuration - API keys and endpoints only.
|
|
669
|
+
|
|
670
|
+
Model selection is handled by llm_client_registry.DEFAULT_MODELS.
|
|
671
|
+
This method only provides connection credentials.
|
|
672
|
+
"""
|
|
673
|
+
return {
|
|
674
|
+
"openai": {
|
|
675
|
+
"api_key": self.openai_api_key,
|
|
676
|
+
},
|
|
677
|
+
"anthropic": {
|
|
678
|
+
"api_key": self.anthropic_api_key,
|
|
679
|
+
},
|
|
680
|
+
"deepseek": {
|
|
681
|
+
"api_key": self.deepseek_api_key,
|
|
682
|
+
"api_url": self.deepseek_api_url,
|
|
683
|
+
},
|
|
684
|
+
"gemini": {
|
|
685
|
+
"api_key": self.gemini_api_key,
|
|
686
|
+
},
|
|
687
|
+
"openrouter": {
|
|
688
|
+
"api_key": self.openrouter_api_key,
|
|
689
|
+
"site_url": self.openrouter_site_url,
|
|
690
|
+
"site_name": self.openrouter_site_name,
|
|
691
|
+
},
|
|
692
|
+
"nvidia": {
|
|
693
|
+
"api_key": self.nvidia_api_key,
|
|
694
|
+
"api_url": self.nvidia_api_url,
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
# REMOVED: get_model_config() and validate_model_name()
|
|
699
|
+
# Use modules.llm.model_registry.get_model_config() instead
|
|
700
|
+
|
|
701
|
+
# Optional override for telemetry config
|
|
702
|
+
telemetry_config: Optional[Dict[str, Any]] = None
|
|
703
|
+
|
|
704
|
+
# Browser settings
|
|
705
|
+
browser: dict = {
|
|
706
|
+
'headless': False,
|
|
707
|
+
'timeout': 30000,
|
|
708
|
+
'viewport': {
|
|
709
|
+
'width': 1280,
|
|
710
|
+
'height': 720
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
# Agent settings
|
|
715
|
+
agent: dict = {
|
|
716
|
+
'max_steps': 50,
|
|
717
|
+
'retry_delay': 2,
|
|
718
|
+
'max_failures': 3
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
# Controller settings
|
|
722
|
+
controller: dict = {
|
|
723
|
+
'loop_threshold': 3,
|
|
724
|
+
'max_url_visits': 2
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
# REMOVED: model_configs dict - use modules.llm.model_registry instead
|
|
728
|
+
# All model configurations (context windows, max tokens, pricing) are in model_registry.py
|
|
729
|
+
|
|
730
|
+
def get_twitter_config(self) -> Dict[str, str]:
|
|
731
|
+
"""Get Twitter API configuration."""
|
|
732
|
+
twitter_config = {
|
|
733
|
+
'api_key': self.twitter_api_key,
|
|
734
|
+
'api_secret': self.twitter_api_secret_key, # Match the field name
|
|
735
|
+
'access_token': self.twitter_access_token,
|
|
736
|
+
'access_token_secret': self.twitter_access_token_secret,
|
|
737
|
+
'bearer_token': self.twitter_bearer_token
|
|
738
|
+
}
|
|
739
|
+
# Only return values that are actually set
|
|
740
|
+
return {k: v for k, v in twitter_config.items() if v and v.strip()}
|
|
741
|
+
|
|
742
|
+
# Collab.Land Configuration
|
|
743
|
+
collabland_api_key: str = Field("", env="COLLABLAND_API_KEY")
|
|
744
|
+
collabland_api_url: str = Field("https://api.collab.land", env="COLLABLAND_API_URL")
|
|
745
|
+
collabland_rules: List[Dict[str, Any]] = Field(default_factory=list)
|
|
746
|
+
|
|
747
|
+
# Update with full credentials
|
|
748
|
+
collabland_id: str = Field("", env="COLLABLAND_ID")
|
|
749
|
+
collabland_secret: str = Field("", env="COLLABLAND_SECRET")
|
|
750
|
+
|
|
751
|
+
# Alchemy API Configuration
|
|
752
|
+
alchemy_api_key: str = Field("", env="ALCHEMY_API_KEY")
|
|
753
|
+
alchemy_api_url: str = Field("https://eth-mainnet.g.alchemy.com", env="ALCHEMY_API_URL")
|
|
754
|
+
|
|
755
|
+
# Den token configuration
|
|
756
|
+
den_token_contract_address: str = Field("", env="DEN_TOKEN_CONTRACT_ADDRESS")
|
|
757
|
+
|
|
758
|
+
# ============================================
|
|
759
|
+
# AUTHENTICATION & CREDIT SYSTEM (FREE - No Privy!)
|
|
760
|
+
# ============================================
|
|
761
|
+
|
|
762
|
+
# REMOVED: Privy ($599/month) - replaced with FREE SIWE
|
|
763
|
+
# privy_app_id: Deleted - not needed anymore!
|
|
764
|
+
# privy_app_secret: Deleted - not needed anymore!
|
|
765
|
+
|
|
766
|
+
# Wallet Generation (for deposit addresses)
|
|
767
|
+
master_seed: Optional[str] = Field(None, alias='MASTER_SEED', description="Master seed for deterministic wallet generation - KEEP SECRET!")
|
|
768
|
+
|
|
769
|
+
# Blockchain RPC URLs
|
|
770
|
+
ethereum_rpc_url: Optional[str] = Field(None, alias='ETHEREUM_RPC_URL', description="Ethereum Mainnet RPC URL (e.g., Alchemy)")
|
|
771
|
+
sepolia_rpc_url: Optional[str] = Field(None, alias='SEPOLIA_RPC_URL', description="Sepolia Testnet RPC URL (e.g., Alchemy)")
|
|
772
|
+
polygon_rpc_url: Optional[str] = Field(None, alias='POLYGON_RPC_URL', description="Polygon RPC URL (e.g., Alchemy)")
|
|
773
|
+
base_rpc_url: Optional[str] = Field(None, alias='BASE_RPC_URL', description="Base RPC URL")
|
|
774
|
+
arbitrum_rpc_url: Optional[str] = Field(None, alias='ARBITRUM_RPC_URL', description="Arbitrum RPC URL")
|
|
775
|
+
|
|
776
|
+
# Treasury
|
|
777
|
+
treasury_address: Optional[str] = Field(None, alias='TREASURY_ADDRESS', description="Gnosis Safe or treasury wallet address")
|
|
778
|
+
|
|
779
|
+
# System Flags
|
|
780
|
+
enable_auth: bool = Field(False, alias='ENABLE_AUTH', description="Enable authentication system")
|
|
781
|
+
enable_credit_system: bool = Field(True, alias='ENABLE_CREDIT_SYSTEM', description="Enable credit tracking and metering")
|
|
782
|
+
deposit_monitor_enabled: bool = Field(False, alias='DEPOSIT_MONITOR_ENABLED', description="Enable deposit monitoring service")
|
|
783
|
+
deposit_check_interval: int = Field(60, alias='DEPOSIT_CHECK_INTERVAL', description="Deposit check interval in seconds")
|
|
784
|
+
sweep_interval: int = Field(3600, alias='SWEEP_INTERVAL', description="Treasury sweep interval in seconds (default: 1 hour)")
|
|
785
|
+
min_sweep_usd: float = Field(50.0, alias='MIN_SWEEP_USD', description="Minimum USD amount to trigger sweep")
|
|
786
|
+
|
|
787
|
+
# JWT Configuration
|
|
788
|
+
jwt_secret_key: Optional[str] = Field(None, alias='JWT_SECRET_KEY', description="Secret key for JWT signing")
|
|
789
|
+
|
|
790
|
+
# Beta Access Control
|
|
791
|
+
beta_mode_enabled: bool = Field(True, alias='BETA_MODE_ENABLED', description="Enable beta mode access restrictions")
|
|
792
|
+
require_den_token: bool = Field(True, alias='REQUIRE_DEN_TOKEN', description="Require DEN token ownership for access")
|
|
793
|
+
bypass_den_check_for_admins: bool = Field(True, alias='BYPASS_DEN_CHECK_FOR_ADMINS', description="Allow admins to bypass DEN token check")
|
|
794
|
+
bypass_payment_for_admins: bool = Field(True, alias='BYPASS_PAYMENT_FOR_ADMINS', description="Allow admins to bypass payment checks")
|
|
795
|
+
|
|
796
|
+
# x402 Protocol Configuration
|
|
797
|
+
x402_enabled: bool = Field(False, alias='X402_ENABLED')
|
|
798
|
+
x402_facilitator_url: str = Field(
|
|
799
|
+
"", # Empty = use direct signature verification (no external facilitator)
|
|
800
|
+
alias='X402_FACILITATOR_URL'
|
|
801
|
+
)
|
|
802
|
+
x402_facilitator_api_key: Optional[str] = Field(None, alias='X402_FACILITATOR_API_KEY')
|
|
803
|
+
x402_facilitator_api_secret: Optional[str] = Field(None, alias='X402_FACILITATOR_API_SECRET')
|
|
804
|
+
x402_default_chain: str = Field("base", alias='X402_DEFAULT_CHAIN')
|
|
805
|
+
x402_payment_recipient: Optional[str] = Field(None, alias='X402_PAYMENT_RECIPIENT')
|
|
806
|
+
x402_payment_deadline_seconds: int = Field(300, alias='X402_PAYMENT_DEADLINE')
|
|
807
|
+
|
|
808
|
+
# Agent personal wallet (core; distinct from x402 receive/tariffing gateway)
|
|
809
|
+
agent_wallet_enabled: bool = Field(False, alias='AGENT_WALLET_ENABLED')
|
|
810
|
+
agent_wallet_backend: str = Field("local_eoa", alias='AGENT_WALLET_BACKEND')
|
|
811
|
+
agent_wallet_network: str = Field("testnet", alias='AGENT_WALLET_NETWORK')
|
|
812
|
+
agent_wallet_max_per_tx_usd: float = Field(1000.0, alias='AGENT_WALLET_MAX_PER_TX_USD')
|
|
813
|
+
x402_client_enabled: bool = Field(False, alias='X402_CLIENT_ENABLED')
|
|
814
|
+
x402_client_facilitator_url: str = Field("", alias='X402_CLIENT_FACILITATOR_URL')
|
|
815
|
+
# NOTE: AGENT_WALLET_MASTER_SEED is read directly by core/wallet/config.py and is
|
|
816
|
+
# intentionally NOT mirrored here (keep the secret out of the broad BotConfig surface).
|
|
817
|
+
|
|
818
|
+
# ERC-8004 Trustless Agents Configuration
|
|
819
|
+
# https://eips.ethereum.org/EIPS/eip-8004
|
|
820
|
+
eip8004_enabled: bool = Field(False, alias='EIP8004_ENABLED', description="Enable ERC-8004 Trustless Agents integration")
|
|
821
|
+
eip8004_chain_id: int = Field(8453, alias='EIP8004_CHAIN_ID', description="Chain ID for ERC-8004 registries (default: Base)")
|
|
822
|
+
eip8004_identity_registry: Optional[str] = Field(None, alias='EIP8004_IDENTITY_REGISTRY', description="Identity Registry contract address")
|
|
823
|
+
eip8004_reputation_registry: Optional[str] = Field(None, alias='EIP8004_REPUTATION_REGISTRY', description="Reputation Registry contract address")
|
|
824
|
+
eip8004_validation_registry: Optional[str] = Field(None, alias='EIP8004_VALIDATION_REGISTRY', description="Validation Registry contract address")
|
|
825
|
+
eip8004_agent_id: Optional[int] = Field(None, alias='EIP8004_AGENT_ID', description="On-chain agent ID (ERC-721 tokenId)")
|
|
826
|
+
eip8004_agent_wallet: Optional[str] = Field(None, alias='EIP8004_AGENT_WALLET', description="Agent wallet for signing")
|
|
827
|
+
eip8004_agent_private_key: Optional[str] = Field(None, alias='EIP8004_AGENT_PRIVATE_KEY', description="Agent private key for EIP-712 signatures - KEEP SECRET!")
|
|
828
|
+
eip8004_supported_trust: str = Field("reputation", alias='EIP8004_SUPPORTED_TRUST', description="Comma-separated trust models: reputation,crypto-economic,tee-attestation")
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
# Back-compat: existing `from core.config import BotConfig` call sites keep working.
|
|
832
|
+
# BotConfig is the platform config; it will live in polyrob-platform after the split.
|
|
833
|
+
BotConfig = ServerConfig
|