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
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Database handler for user MCP server configurations.
|
|
3
|
+
|
|
4
|
+
Manages CRUD operations for user_mcp_servers, user_mcp_settings, and user_mcp_audit_log tables.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import logging
|
|
9
|
+
from typing import List, Optional, Dict, Any
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
|
|
13
|
+
from modules.database.connection import DatabaseConnection
|
|
14
|
+
from tools.mcp.security import MCPEncryption, get_encryption
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class UserMCPServer:
|
|
21
|
+
"""User MCP server record."""
|
|
22
|
+
|
|
23
|
+
id: int
|
|
24
|
+
user_id: str
|
|
25
|
+
server_name: str
|
|
26
|
+
server_url: str
|
|
27
|
+
server_type: str
|
|
28
|
+
auth_method: str
|
|
29
|
+
enabled: bool
|
|
30
|
+
timeout: int
|
|
31
|
+
retry_attempts: int
|
|
32
|
+
retry_delay: int
|
|
33
|
+
auto_reconnect: bool
|
|
34
|
+
max_concurrent_requests: int
|
|
35
|
+
auth_status: str
|
|
36
|
+
connection_count: int
|
|
37
|
+
tools_discovered: int
|
|
38
|
+
created_at: datetime
|
|
39
|
+
updated_at: datetime
|
|
40
|
+
display_name: Optional[str] = None
|
|
41
|
+
last_connected_at: Optional[datetime] = None
|
|
42
|
+
last_error: Optional[str] = None
|
|
43
|
+
message_endpoint: Optional[str] = None # For SSE servers with separate POST endpoint
|
|
44
|
+
|
|
45
|
+
# Not stored directly - decrypted on demand
|
|
46
|
+
api_key: Optional[str] = field(default=None, repr=False)
|
|
47
|
+
headers: Optional[Dict[str, str]] = field(default=None, repr=False)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class UserMCPSettings:
|
|
52
|
+
"""User MCP settings record."""
|
|
53
|
+
|
|
54
|
+
user_id: str
|
|
55
|
+
mcp_enabled: bool = True
|
|
56
|
+
include_global_servers: bool = True
|
|
57
|
+
max_servers: int = 10
|
|
58
|
+
default_timeout: int = 30
|
|
59
|
+
created_at: Optional[datetime] = None
|
|
60
|
+
updated_at: Optional[datetime] = None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class UserMCPServersHandler:
|
|
64
|
+
"""Handler for user MCP server database operations."""
|
|
65
|
+
|
|
66
|
+
# FIX #16: Schema version for migrations
|
|
67
|
+
SCHEMA_VERSION = 2 # Increment when adding migrations
|
|
68
|
+
|
|
69
|
+
# SECURITY FIX: Whitelist of allowed column names to prevent SQL injection
|
|
70
|
+
# Only these columns can be updated via update_server() and update_connection_status()
|
|
71
|
+
ALLOWED_UPDATE_COLUMNS = frozenset({
|
|
72
|
+
'display_name', 'server_url', 'server_type', 'auth_method',
|
|
73
|
+
'api_key_encrypted', 'headers_encrypted', 'enabled', 'timeout',
|
|
74
|
+
'retry_attempts', 'retry_delay', 'auto_reconnect', 'max_concurrent_requests',
|
|
75
|
+
'auth_status', 'last_connected_at', 'last_error', 'connection_count',
|
|
76
|
+
'tools_discovered', 'updated_at', 'message_endpoint'
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
def __init__(self, db: DatabaseConnection, encryption: Optional[MCPEncryption] = None):
|
|
80
|
+
"""
|
|
81
|
+
Initialize handler.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
db: Database connection
|
|
85
|
+
encryption: Encryption instance (uses default if not provided)
|
|
86
|
+
"""
|
|
87
|
+
self.db = db
|
|
88
|
+
self.encryption = encryption or get_encryption()
|
|
89
|
+
self.logger = logging.getLogger('database.user_mcp_servers')
|
|
90
|
+
self._tables_initialized = False
|
|
91
|
+
|
|
92
|
+
async def ensure_tables(self) -> None:
|
|
93
|
+
"""
|
|
94
|
+
Ensure all required tables exist and run migrations.
|
|
95
|
+
|
|
96
|
+
Creates tables if they don't exist. Safe to call multiple times.
|
|
97
|
+
Runs any pending schema migrations (FIX #16).
|
|
98
|
+
"""
|
|
99
|
+
if self._tables_initialized:
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
self.logger.info("Ensuring user MCP tables exist...")
|
|
103
|
+
|
|
104
|
+
# FIX #16: Create schema version table first
|
|
105
|
+
await self.db.execute('''
|
|
106
|
+
CREATE TABLE IF NOT EXISTS user_mcp_schema_version (
|
|
107
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
108
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
109
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
110
|
+
)
|
|
111
|
+
''')
|
|
112
|
+
|
|
113
|
+
# Get current schema version
|
|
114
|
+
current_version = await self._get_schema_version()
|
|
115
|
+
|
|
116
|
+
# Create user_mcp_servers table
|
|
117
|
+
await self.db.execute('''
|
|
118
|
+
CREATE TABLE IF NOT EXISTS user_mcp_servers (
|
|
119
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
120
|
+
user_id TEXT NOT NULL,
|
|
121
|
+
server_name TEXT NOT NULL,
|
|
122
|
+
display_name TEXT,
|
|
123
|
+
server_url TEXT NOT NULL,
|
|
124
|
+
server_type TEXT NOT NULL,
|
|
125
|
+
auth_method TEXT NOT NULL DEFAULT 'api_key',
|
|
126
|
+
api_key_encrypted BLOB,
|
|
127
|
+
headers_encrypted BLOB,
|
|
128
|
+
enabled INTEGER DEFAULT 1,
|
|
129
|
+
timeout INTEGER DEFAULT 30,
|
|
130
|
+
retry_attempts INTEGER DEFAULT 3,
|
|
131
|
+
retry_delay INTEGER DEFAULT 5,
|
|
132
|
+
auto_reconnect INTEGER DEFAULT 1,
|
|
133
|
+
max_concurrent_requests INTEGER DEFAULT 5,
|
|
134
|
+
auth_status TEXT DEFAULT 'configured',
|
|
135
|
+
last_connected_at TIMESTAMP,
|
|
136
|
+
last_error TEXT,
|
|
137
|
+
connection_count INTEGER DEFAULT 0,
|
|
138
|
+
tools_discovered INTEGER DEFAULT 0,
|
|
139
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
140
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
141
|
+
UNIQUE(user_id, server_name),
|
|
142
|
+
CHECK (server_type IN ('sse', 'http', 'streamable_http')),
|
|
143
|
+
CHECK (auth_method IN ('api_key', 'bearer', 'none'))
|
|
144
|
+
)
|
|
145
|
+
''')
|
|
146
|
+
|
|
147
|
+
# Create indices
|
|
148
|
+
await self.db.execute('''
|
|
149
|
+
CREATE INDEX IF NOT EXISTS idx_user_mcp_servers_user
|
|
150
|
+
ON user_mcp_servers(user_id)
|
|
151
|
+
''')
|
|
152
|
+
await self.db.execute('''
|
|
153
|
+
CREATE INDEX IF NOT EXISTS idx_user_mcp_servers_enabled
|
|
154
|
+
ON user_mcp_servers(user_id, enabled)
|
|
155
|
+
''')
|
|
156
|
+
|
|
157
|
+
# Create user_mcp_settings table
|
|
158
|
+
await self.db.execute('''
|
|
159
|
+
CREATE TABLE IF NOT EXISTS user_mcp_settings (
|
|
160
|
+
user_id TEXT PRIMARY KEY,
|
|
161
|
+
mcp_enabled INTEGER DEFAULT 1,
|
|
162
|
+
include_global_servers INTEGER DEFAULT 1,
|
|
163
|
+
max_servers INTEGER DEFAULT 10,
|
|
164
|
+
default_timeout INTEGER DEFAULT 30,
|
|
165
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
166
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
167
|
+
)
|
|
168
|
+
''')
|
|
169
|
+
|
|
170
|
+
# Create user_mcp_audit_log table
|
|
171
|
+
await self.db.execute('''
|
|
172
|
+
CREATE TABLE IF NOT EXISTS user_mcp_audit_log (
|
|
173
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
174
|
+
user_id TEXT NOT NULL,
|
|
175
|
+
action TEXT NOT NULL,
|
|
176
|
+
server_name TEXT,
|
|
177
|
+
details TEXT,
|
|
178
|
+
ip_address TEXT,
|
|
179
|
+
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
180
|
+
)
|
|
181
|
+
''')
|
|
182
|
+
|
|
183
|
+
# Create audit indices
|
|
184
|
+
await self.db.execute('''
|
|
185
|
+
CREATE INDEX IF NOT EXISTS idx_user_mcp_audit_user
|
|
186
|
+
ON user_mcp_audit_log(user_id)
|
|
187
|
+
''')
|
|
188
|
+
await self.db.execute('''
|
|
189
|
+
CREATE INDEX IF NOT EXISTS idx_user_mcp_audit_time
|
|
190
|
+
ON user_mcp_audit_log(timestamp)
|
|
191
|
+
''')
|
|
192
|
+
|
|
193
|
+
# FIX #16: Run migrations if needed
|
|
194
|
+
await self._run_migrations(current_version)
|
|
195
|
+
|
|
196
|
+
self._tables_initialized = True
|
|
197
|
+
self.logger.info("User MCP tables ready")
|
|
198
|
+
|
|
199
|
+
async def _get_schema_version(self) -> int:
|
|
200
|
+
"""Get current schema version (FIX #16)."""
|
|
201
|
+
try:
|
|
202
|
+
result = await self.db.fetch_one(
|
|
203
|
+
"SELECT version FROM user_mcp_schema_version WHERE id = 1"
|
|
204
|
+
)
|
|
205
|
+
return result[0] if result else 0
|
|
206
|
+
except Exception:
|
|
207
|
+
return 0
|
|
208
|
+
|
|
209
|
+
async def _set_schema_version(self, version: int) -> None:
|
|
210
|
+
"""Set schema version (FIX #16)."""
|
|
211
|
+
await self.db.execute('''
|
|
212
|
+
INSERT INTO user_mcp_schema_version (id, version, updated_at)
|
|
213
|
+
VALUES (1, ?, CURRENT_TIMESTAMP)
|
|
214
|
+
ON CONFLICT(id) DO UPDATE SET version = ?, updated_at = CURRENT_TIMESTAMP
|
|
215
|
+
''', (version, version))
|
|
216
|
+
|
|
217
|
+
async def _run_migrations(self, current_version: int) -> None:
|
|
218
|
+
"""Run pending schema migrations (FIX #16)."""
|
|
219
|
+
if current_version >= self.SCHEMA_VERSION:
|
|
220
|
+
return
|
|
221
|
+
|
|
222
|
+
self.logger.info(f"Running migrations from v{current_version} to v{self.SCHEMA_VERSION}")
|
|
223
|
+
|
|
224
|
+
# Migration v1 -> v2: Add message_endpoint column
|
|
225
|
+
if current_version < 2:
|
|
226
|
+
# Check if column already exists before trying to add it
|
|
227
|
+
try:
|
|
228
|
+
result = await self.db.fetch_one(
|
|
229
|
+
"SELECT 1 FROM pragma_table_info('user_mcp_servers') WHERE name='message_endpoint'"
|
|
230
|
+
)
|
|
231
|
+
if not result:
|
|
232
|
+
await self.db.execute('''
|
|
233
|
+
ALTER TABLE user_mcp_servers
|
|
234
|
+
ADD COLUMN message_endpoint TEXT
|
|
235
|
+
''')
|
|
236
|
+
self.logger.info("Migration v2: Added message_endpoint column")
|
|
237
|
+
else:
|
|
238
|
+
self.logger.debug("Migration v2: message_endpoint column already exists")
|
|
239
|
+
except Exception as e:
|
|
240
|
+
# Silently ignore duplicate column errors
|
|
241
|
+
if "duplicate column" not in str(e).lower():
|
|
242
|
+
self.logger.warning(f"Migration v2 warning: {e}")
|
|
243
|
+
|
|
244
|
+
# Update schema version
|
|
245
|
+
await self._set_schema_version(self.SCHEMA_VERSION)
|
|
246
|
+
self.logger.info(f"Schema migrated to v{self.SCHEMA_VERSION}")
|
|
247
|
+
|
|
248
|
+
async def add_server(
|
|
249
|
+
self,
|
|
250
|
+
user_id: str,
|
|
251
|
+
server_name: str,
|
|
252
|
+
server_url: str,
|
|
253
|
+
server_type: str = "sse",
|
|
254
|
+
auth_method: str = "api_key",
|
|
255
|
+
api_key: Optional[str] = None,
|
|
256
|
+
headers: Optional[Dict[str, str]] = None,
|
|
257
|
+
display_name: Optional[str] = None,
|
|
258
|
+
**options
|
|
259
|
+
) -> UserMCPServer:
|
|
260
|
+
"""
|
|
261
|
+
Add a new MCP server for a user.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
user_id: Owner's user ID
|
|
265
|
+
server_name: Unique name for the server
|
|
266
|
+
server_url: Server endpoint URL
|
|
267
|
+
server_type: 'sse' or 'http' (NOT 'stdio')
|
|
268
|
+
auth_method: 'api_key', 'bearer', or 'none'
|
|
269
|
+
api_key: API key (will be encrypted)
|
|
270
|
+
headers: Custom headers (will be encrypted)
|
|
271
|
+
display_name: Friendly display name
|
|
272
|
+
**options: Additional options (enabled, timeout, etc.)
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
Created UserMCPServer record
|
|
276
|
+
|
|
277
|
+
Raises:
|
|
278
|
+
ValueError: If server_type is 'stdio'
|
|
279
|
+
"""
|
|
280
|
+
# Validate server_type
|
|
281
|
+
if server_type not in ("sse", "http", "streamable_http"):
|
|
282
|
+
raise ValueError("Server type must be 'sse', 'http', or 'streamable_http' (STDIO not allowed)")
|
|
283
|
+
|
|
284
|
+
# Encrypt credentials
|
|
285
|
+
api_key_encrypted = self.encryption.encrypt(api_key) if api_key else None
|
|
286
|
+
headers_encrypted = self.encryption.encrypt_dict(headers) if headers else None
|
|
287
|
+
|
|
288
|
+
query = """
|
|
289
|
+
INSERT INTO user_mcp_servers (
|
|
290
|
+
user_id, server_name, display_name, server_url, server_type,
|
|
291
|
+
auth_method, api_key_encrypted, headers_encrypted,
|
|
292
|
+
enabled, timeout, retry_attempts, retry_delay,
|
|
293
|
+
auto_reconnect, max_concurrent_requests, auth_status, message_endpoint
|
|
294
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
295
|
+
"""
|
|
296
|
+
|
|
297
|
+
await self.db.execute(query, (
|
|
298
|
+
user_id,
|
|
299
|
+
server_name,
|
|
300
|
+
display_name,
|
|
301
|
+
server_url,
|
|
302
|
+
server_type,
|
|
303
|
+
auth_method,
|
|
304
|
+
api_key_encrypted,
|
|
305
|
+
headers_encrypted,
|
|
306
|
+
1 if options.get('enabled', True) else 0,
|
|
307
|
+
options.get('timeout', 30),
|
|
308
|
+
options.get('retry_attempts', 3),
|
|
309
|
+
options.get('retry_delay', 5),
|
|
310
|
+
1 if options.get('auto_reconnect', True) else 0,
|
|
311
|
+
options.get('max_concurrent_requests', 5),
|
|
312
|
+
'configured' if api_key or auth_method == 'none' else 'unconfigured',
|
|
313
|
+
options.get('message_endpoint')
|
|
314
|
+
))
|
|
315
|
+
|
|
316
|
+
self.logger.info(f"Added MCP server '{server_name}' for user {user_id}")
|
|
317
|
+
|
|
318
|
+
# Log audit event
|
|
319
|
+
await self._audit_log(user_id, 'add', server_name, {
|
|
320
|
+
'server_type': server_type,
|
|
321
|
+
'auth_method': auth_method,
|
|
322
|
+
'server_url': server_url
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
return await self.get_server(user_id, server_name)
|
|
326
|
+
|
|
327
|
+
async def get_server(self, user_id: str, server_name: str) -> Optional[UserMCPServer]:
|
|
328
|
+
"""
|
|
329
|
+
Get a specific server for a user.
|
|
330
|
+
|
|
331
|
+
Args:
|
|
332
|
+
user_id: Owner's user ID
|
|
333
|
+
server_name: Server name
|
|
334
|
+
|
|
335
|
+
Returns:
|
|
336
|
+
UserMCPServer or None if not found
|
|
337
|
+
"""
|
|
338
|
+
query = "SELECT * FROM user_mcp_servers WHERE user_id = ? AND server_name = ?"
|
|
339
|
+
|
|
340
|
+
row = await self.db.fetch_one(query, (user_id, server_name))
|
|
341
|
+
if row:
|
|
342
|
+
return self._row_to_server(row)
|
|
343
|
+
return None
|
|
344
|
+
|
|
345
|
+
async def get_server_by_id(self, server_id: int) -> Optional[UserMCPServer]:
|
|
346
|
+
"""
|
|
347
|
+
Get a server by its ID.
|
|
348
|
+
|
|
349
|
+
Args:
|
|
350
|
+
server_id: Server record ID
|
|
351
|
+
|
|
352
|
+
Returns:
|
|
353
|
+
UserMCPServer or None if not found
|
|
354
|
+
"""
|
|
355
|
+
query = "SELECT * FROM user_mcp_servers WHERE id = ?"
|
|
356
|
+
|
|
357
|
+
row = await self.db.fetch_one(query, (server_id,))
|
|
358
|
+
if row:
|
|
359
|
+
return self._row_to_server(row)
|
|
360
|
+
return None
|
|
361
|
+
|
|
362
|
+
async def get_user_servers(
|
|
363
|
+
self,
|
|
364
|
+
user_id: str,
|
|
365
|
+
enabled_only: bool = False
|
|
366
|
+
) -> List[UserMCPServer]:
|
|
367
|
+
"""
|
|
368
|
+
Get all MCP servers for a user.
|
|
369
|
+
|
|
370
|
+
Args:
|
|
371
|
+
user_id: Owner's user ID
|
|
372
|
+
enabled_only: Only return enabled servers
|
|
373
|
+
|
|
374
|
+
Returns:
|
|
375
|
+
List of UserMCPServer records
|
|
376
|
+
"""
|
|
377
|
+
query = "SELECT * FROM user_mcp_servers WHERE user_id = ?"
|
|
378
|
+
params = [user_id]
|
|
379
|
+
|
|
380
|
+
if enabled_only:
|
|
381
|
+
query += " AND enabled = 1"
|
|
382
|
+
|
|
383
|
+
query += " ORDER BY created_at DESC"
|
|
384
|
+
|
|
385
|
+
rows = await self.db.fetch_all(query, tuple(params))
|
|
386
|
+
return [self._row_to_server(row) for row in rows]
|
|
387
|
+
|
|
388
|
+
async def update_server(
|
|
389
|
+
self,
|
|
390
|
+
user_id: str,
|
|
391
|
+
server_name: str,
|
|
392
|
+
**updates
|
|
393
|
+
) -> bool:
|
|
394
|
+
"""
|
|
395
|
+
Update server configuration.
|
|
396
|
+
|
|
397
|
+
Args:
|
|
398
|
+
user_id: Owner's user ID
|
|
399
|
+
server_name: Server name
|
|
400
|
+
**updates: Fields to update
|
|
401
|
+
|
|
402
|
+
Returns:
|
|
403
|
+
True if updated successfully
|
|
404
|
+
"""
|
|
405
|
+
if not updates:
|
|
406
|
+
return False
|
|
407
|
+
|
|
408
|
+
# Handle credential updates specially
|
|
409
|
+
if 'api_key' in updates:
|
|
410
|
+
api_key = updates.pop('api_key')
|
|
411
|
+
updates['api_key_encrypted'] = self.encryption.encrypt(api_key) if api_key else None
|
|
412
|
+
|
|
413
|
+
if 'headers' in updates:
|
|
414
|
+
headers = updates.pop('headers')
|
|
415
|
+
updates['headers_encrypted'] = self.encryption.encrypt_dict(headers) if headers else None
|
|
416
|
+
|
|
417
|
+
# Convert boolean values to integers for SQLite
|
|
418
|
+
for key in ['enabled', 'auto_reconnect']:
|
|
419
|
+
if key in updates:
|
|
420
|
+
updates[key] = 1 if updates[key] else 0
|
|
421
|
+
|
|
422
|
+
updates['updated_at'] = datetime.utcnow().isoformat()
|
|
423
|
+
|
|
424
|
+
# SECURITY FIX: Validate all column names against whitelist to prevent SQL injection
|
|
425
|
+
invalid_columns = set(updates.keys()) - self.ALLOWED_UPDATE_COLUMNS
|
|
426
|
+
if invalid_columns:
|
|
427
|
+
self.logger.error(f"SQL injection attempt blocked: invalid columns {invalid_columns}")
|
|
428
|
+
raise ValueError(f"Invalid column names: {invalid_columns}")
|
|
429
|
+
|
|
430
|
+
set_clause = ", ".join(f"{k} = ?" for k in updates.keys())
|
|
431
|
+
query = f"""
|
|
432
|
+
UPDATE user_mcp_servers
|
|
433
|
+
SET {set_clause}
|
|
434
|
+
WHERE user_id = ? AND server_name = ?
|
|
435
|
+
"""
|
|
436
|
+
|
|
437
|
+
result = await self.db.execute(
|
|
438
|
+
query,
|
|
439
|
+
tuple(list(updates.values()) + [user_id, server_name])
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
if result:
|
|
443
|
+
self.logger.info(f"Updated MCP server '{server_name}' for user {user_id}")
|
|
444
|
+
await self._audit_log(user_id, 'update', server_name, {
|
|
445
|
+
'fields': list(updates.keys())
|
|
446
|
+
})
|
|
447
|
+
|
|
448
|
+
return result > 0 if isinstance(result, int) else True
|
|
449
|
+
|
|
450
|
+
async def delete_server(self, user_id: str, server_name: str) -> bool:
|
|
451
|
+
"""
|
|
452
|
+
Delete a server.
|
|
453
|
+
|
|
454
|
+
Args:
|
|
455
|
+
user_id: Owner's user ID
|
|
456
|
+
server_name: Server name
|
|
457
|
+
|
|
458
|
+
Returns:
|
|
459
|
+
True if deleted successfully
|
|
460
|
+
"""
|
|
461
|
+
query = "DELETE FROM user_mcp_servers WHERE user_id = ? AND server_name = ?"
|
|
462
|
+
|
|
463
|
+
result = await self.db.execute(query, (user_id, server_name))
|
|
464
|
+
|
|
465
|
+
if result:
|
|
466
|
+
self.logger.info(f"Deleted MCP server '{server_name}' for user {user_id}")
|
|
467
|
+
await self._audit_log(user_id, 'delete', server_name)
|
|
468
|
+
|
|
469
|
+
return result > 0 if isinstance(result, int) else True
|
|
470
|
+
|
|
471
|
+
async def get_decrypted_credentials(
|
|
472
|
+
self,
|
|
473
|
+
user_id: str,
|
|
474
|
+
server_name: str
|
|
475
|
+
) -> tuple[Optional[str], Optional[Dict[str, str]]]:
|
|
476
|
+
"""
|
|
477
|
+
Get decrypted API key and headers for a server.
|
|
478
|
+
|
|
479
|
+
Args:
|
|
480
|
+
user_id: Owner's user ID
|
|
481
|
+
server_name: Server name
|
|
482
|
+
|
|
483
|
+
Returns:
|
|
484
|
+
Tuple of (api_key, headers) - both may be None
|
|
485
|
+
"""
|
|
486
|
+
query = """
|
|
487
|
+
SELECT api_key_encrypted, headers_encrypted
|
|
488
|
+
FROM user_mcp_servers
|
|
489
|
+
WHERE user_id = ? AND server_name = ?
|
|
490
|
+
"""
|
|
491
|
+
|
|
492
|
+
row = await self.db.fetch_one(query, (user_id, server_name))
|
|
493
|
+
|
|
494
|
+
if not row:
|
|
495
|
+
return None, None
|
|
496
|
+
|
|
497
|
+
api_key = self.encryption.decrypt(row['api_key_encrypted']) if row['api_key_encrypted'] else None
|
|
498
|
+
headers = self.encryption.decrypt_dict(row['headers_encrypted']) if row['headers_encrypted'] else None
|
|
499
|
+
|
|
500
|
+
return api_key, headers
|
|
501
|
+
|
|
502
|
+
async def update_connection_status(
|
|
503
|
+
self,
|
|
504
|
+
user_id: str,
|
|
505
|
+
server_name: str,
|
|
506
|
+
connected: bool,
|
|
507
|
+
error: Optional[str] = None,
|
|
508
|
+
tools_count: Optional[int] = None
|
|
509
|
+
) -> bool:
|
|
510
|
+
"""
|
|
511
|
+
Update server connection status.
|
|
512
|
+
|
|
513
|
+
Args:
|
|
514
|
+
user_id: Owner's user ID
|
|
515
|
+
server_name: Server name
|
|
516
|
+
connected: Whether connection was successful
|
|
517
|
+
error: Error message if failed
|
|
518
|
+
tools_count: Number of tools discovered
|
|
519
|
+
|
|
520
|
+
Returns:
|
|
521
|
+
True if updated
|
|
522
|
+
"""
|
|
523
|
+
updates = {
|
|
524
|
+
'last_error': error,
|
|
525
|
+
'auth_status': 'connected' if connected else 'error',
|
|
526
|
+
'updated_at': datetime.utcnow().isoformat()
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if connected:
|
|
530
|
+
updates['last_connected_at'] = datetime.utcnow().isoformat()
|
|
531
|
+
updates['connection_count'] = 'connection_count + 1' # Will need special handling
|
|
532
|
+
|
|
533
|
+
if tools_count is not None:
|
|
534
|
+
updates['tools_discovered'] = tools_count
|
|
535
|
+
|
|
536
|
+
# Build query with special handling for increment
|
|
537
|
+
set_parts = []
|
|
538
|
+
values = []
|
|
539
|
+
for k, v in updates.items():
|
|
540
|
+
if v == 'connection_count + 1':
|
|
541
|
+
set_parts.append("connection_count = connection_count + 1")
|
|
542
|
+
else:
|
|
543
|
+
set_parts.append(f"{k} = ?")
|
|
544
|
+
values.append(v)
|
|
545
|
+
|
|
546
|
+
query = f"""
|
|
547
|
+
UPDATE user_mcp_servers
|
|
548
|
+
SET {', '.join(set_parts)}
|
|
549
|
+
WHERE user_id = ? AND server_name = ?
|
|
550
|
+
"""
|
|
551
|
+
|
|
552
|
+
result = await self.db.execute(query, tuple(values + [user_id, server_name]))
|
|
553
|
+
return result > 0 if isinstance(result, int) else True
|
|
554
|
+
|
|
555
|
+
async def get_user_settings(self, user_id: str) -> UserMCPSettings:
|
|
556
|
+
"""
|
|
557
|
+
Get user's MCP settings (creates defaults if not exist).
|
|
558
|
+
|
|
559
|
+
Args:
|
|
560
|
+
user_id: User ID
|
|
561
|
+
|
|
562
|
+
Returns:
|
|
563
|
+
UserMCPSettings record
|
|
564
|
+
"""
|
|
565
|
+
query = "SELECT * FROM user_mcp_settings WHERE user_id = ?"
|
|
566
|
+
row = await self.db.fetch_one(query, (user_id,))
|
|
567
|
+
|
|
568
|
+
if row:
|
|
569
|
+
return UserMCPSettings(
|
|
570
|
+
user_id=row['user_id'],
|
|
571
|
+
mcp_enabled=bool(row['mcp_enabled']),
|
|
572
|
+
include_global_servers=bool(row['include_global_servers']),
|
|
573
|
+
max_servers=row['max_servers'],
|
|
574
|
+
default_timeout=row['default_timeout'],
|
|
575
|
+
created_at=row.get('created_at'),
|
|
576
|
+
updated_at=row.get('updated_at')
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
# Return defaults (not persisted until explicitly saved)
|
|
580
|
+
return UserMCPSettings(user_id=user_id)
|
|
581
|
+
|
|
582
|
+
async def update_user_settings(self, user_id: str, **updates) -> bool:
|
|
583
|
+
"""
|
|
584
|
+
Update user's MCP settings (upsert).
|
|
585
|
+
|
|
586
|
+
Args:
|
|
587
|
+
user_id: User ID
|
|
588
|
+
**updates: Settings to update
|
|
589
|
+
|
|
590
|
+
Returns:
|
|
591
|
+
True if updated
|
|
592
|
+
"""
|
|
593
|
+
# Convert boolean values
|
|
594
|
+
for key in ['mcp_enabled', 'include_global_servers']:
|
|
595
|
+
if key in updates:
|
|
596
|
+
updates[key] = 1 if updates[key] else 0
|
|
597
|
+
|
|
598
|
+
# Upsert query
|
|
599
|
+
columns = ['user_id'] + list(updates.keys()) + ['updated_at']
|
|
600
|
+
values = [user_id] + list(updates.values()) + [datetime.utcnow().isoformat()]
|
|
601
|
+
placeholders = ', '.join(['?'] * len(columns))
|
|
602
|
+
|
|
603
|
+
update_clause = ', '.join(f"{k} = excluded.{k}" for k in updates.keys())
|
|
604
|
+
update_clause += ", updated_at = excluded.updated_at"
|
|
605
|
+
|
|
606
|
+
query = f"""
|
|
607
|
+
INSERT INTO user_mcp_settings ({', '.join(columns)})
|
|
608
|
+
VALUES ({placeholders})
|
|
609
|
+
ON CONFLICT(user_id) DO UPDATE SET {update_clause}
|
|
610
|
+
"""
|
|
611
|
+
|
|
612
|
+
await self.db.execute(query, tuple(values))
|
|
613
|
+
return True
|
|
614
|
+
|
|
615
|
+
async def _audit_log(
|
|
616
|
+
self,
|
|
617
|
+
user_id: str,
|
|
618
|
+
action: str,
|
|
619
|
+
server_name: Optional[str] = None,
|
|
620
|
+
details: Optional[Dict[str, Any]] = None,
|
|
621
|
+
ip_address: Optional[str] = None
|
|
622
|
+
) -> None:
|
|
623
|
+
"""
|
|
624
|
+
Record an audit log entry.
|
|
625
|
+
|
|
626
|
+
Args:
|
|
627
|
+
user_id: User who performed the action
|
|
628
|
+
action: Action type ('add', 'update', 'delete', 'connect', 'error')
|
|
629
|
+
server_name: Server name if applicable
|
|
630
|
+
details: Additional details (JSON serializable, no secrets!)
|
|
631
|
+
ip_address: Client IP address
|
|
632
|
+
"""
|
|
633
|
+
query = """
|
|
634
|
+
INSERT INTO user_mcp_audit_log (user_id, action, server_name, details, ip_address)
|
|
635
|
+
VALUES (?, ?, ?, ?, ?)
|
|
636
|
+
"""
|
|
637
|
+
|
|
638
|
+
details_json = json.dumps(details) if details else None
|
|
639
|
+
|
|
640
|
+
await self.db.execute(query, (
|
|
641
|
+
user_id,
|
|
642
|
+
action,
|
|
643
|
+
server_name,
|
|
644
|
+
details_json,
|
|
645
|
+
ip_address
|
|
646
|
+
))
|
|
647
|
+
|
|
648
|
+
async def get_audit_log(
|
|
649
|
+
self,
|
|
650
|
+
user_id: str,
|
|
651
|
+
limit: int = 100,
|
|
652
|
+
server_name: Optional[str] = None
|
|
653
|
+
) -> List[Dict[str, Any]]:
|
|
654
|
+
"""
|
|
655
|
+
Get audit log entries for a user.
|
|
656
|
+
|
|
657
|
+
Args:
|
|
658
|
+
user_id: User ID
|
|
659
|
+
limit: Maximum entries to return
|
|
660
|
+
server_name: Filter by server name
|
|
661
|
+
|
|
662
|
+
Returns:
|
|
663
|
+
List of audit log entries
|
|
664
|
+
"""
|
|
665
|
+
query = "SELECT * FROM user_mcp_audit_log WHERE user_id = ?"
|
|
666
|
+
params = [user_id]
|
|
667
|
+
|
|
668
|
+
if server_name:
|
|
669
|
+
query += " AND server_name = ?"
|
|
670
|
+
params.append(server_name)
|
|
671
|
+
|
|
672
|
+
query += " ORDER BY timestamp DESC LIMIT ?"
|
|
673
|
+
params.append(limit)
|
|
674
|
+
|
|
675
|
+
rows = await self.db.fetch_all(query, tuple(params))
|
|
676
|
+
|
|
677
|
+
return [
|
|
678
|
+
{
|
|
679
|
+
'id': row['id'],
|
|
680
|
+
'user_id': row['user_id'],
|
|
681
|
+
'action': row['action'],
|
|
682
|
+
'server_name': row['server_name'],
|
|
683
|
+
'details': json.loads(row['details']) if row['details'] else None,
|
|
684
|
+
'ip_address': row['ip_address'],
|
|
685
|
+
'timestamp': row['timestamp']
|
|
686
|
+
}
|
|
687
|
+
for row in rows
|
|
688
|
+
]
|
|
689
|
+
|
|
690
|
+
def _row_to_server(self, row) -> UserMCPServer:
|
|
691
|
+
"""Convert database row to UserMCPServer object."""
|
|
692
|
+
return UserMCPServer(
|
|
693
|
+
id=row['id'],
|
|
694
|
+
user_id=row['user_id'],
|
|
695
|
+
server_name=row['server_name'],
|
|
696
|
+
display_name=row.get('display_name'),
|
|
697
|
+
server_url=row['server_url'],
|
|
698
|
+
server_type=row['server_type'],
|
|
699
|
+
auth_method=row['auth_method'],
|
|
700
|
+
enabled=bool(row['enabled']),
|
|
701
|
+
timeout=row['timeout'],
|
|
702
|
+
retry_attempts=row['retry_attempts'],
|
|
703
|
+
retry_delay=row['retry_delay'],
|
|
704
|
+
auto_reconnect=bool(row['auto_reconnect']),
|
|
705
|
+
max_concurrent_requests=row['max_concurrent_requests'],
|
|
706
|
+
auth_status=row['auth_status'],
|
|
707
|
+
last_connected_at=row.get('last_connected_at'),
|
|
708
|
+
last_error=row.get('last_error'),
|
|
709
|
+
connection_count=row['connection_count'],
|
|
710
|
+
tools_discovered=row['tools_discovered'],
|
|
711
|
+
created_at=row['created_at'],
|
|
712
|
+
updated_at=row['updated_at'],
|
|
713
|
+
message_endpoint=row.get('message_endpoint')
|
|
714
|
+
)
|
|
715
|
+
|
|
716
|
+
async def server_count(self, user_id: str) -> int:
|
|
717
|
+
"""
|
|
718
|
+
Get count of servers for a user.
|
|
719
|
+
|
|
720
|
+
Args:
|
|
721
|
+
user_id: User ID
|
|
722
|
+
|
|
723
|
+
Returns:
|
|
724
|
+
Number of servers
|
|
725
|
+
"""
|
|
726
|
+
query = "SELECT COUNT(*) as count FROM user_mcp_servers WHERE user_id = ?"
|
|
727
|
+
row = await self.db.fetch_one(query, (user_id,))
|
|
728
|
+
return row['count'] if row else 0
|