XoneAI 1.0.1__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.
- xoneai/__init__.py +86 -0
- xoneai/__main__.py +15 -0
- xoneai/_dev/__init__.py +17 -0
- xoneai/_dev/api_md.py +1024 -0
- xoneai/_dev/parity/__init__.py +42 -0
- xoneai/_dev/parity/docs_extractor.py +183 -0
- xoneai/_dev/parity/docs_generator.py +981 -0
- xoneai/_dev/parity/generator.py +785 -0
- xoneai/_dev/parity/python_docs_extractor.py +167 -0
- xoneai/_dev/parity/python_extractor.py +252 -0
- xoneai/_dev/parity/rust_docs_extractor.py +55 -0
- xoneai/_dev/parity/rust_extractor.py +332 -0
- xoneai/_dev/parity/topic_normalizer.py +170 -0
- xoneai/_dev/parity/ts_docs_extractor.py +55 -0
- xoneai/_dev/parity/typescript_extractor.py +219 -0
- xoneai/acp/__init__.py +54 -0
- xoneai/acp/config.py +159 -0
- xoneai/acp/safe_edit.py +442 -0
- xoneai/acp/server.py +587 -0
- xoneai/acp/session.py +219 -0
- xoneai/adapters/__init__.py +50 -0
- xoneai/adapters/readers.py +395 -0
- xoneai/adapters/rerankers.py +315 -0
- xoneai/adapters/retrievers.py +568 -0
- xoneai/adapters/vector_stores.py +409 -0
- xoneai/agent_scheduler.py +337 -0
- xoneai/agents_generator.py +1004 -0
- xoneai/api/call.py +292 -0
- xoneai/app/__init__.py +24 -0
- xoneai/app/agentos.py +243 -0
- xoneai/audit/__init__.py +23 -0
- xoneai/audit/agent_centric.py +580 -0
- xoneai/auto.py +1380 -0
- xoneai/bots/__init__.py +65 -0
- xoneai/bots/_ack.py +99 -0
- xoneai/bots/_approval.py +149 -0
- xoneai/bots/_approval_base.py +139 -0
- xoneai/bots/_chunk.py +127 -0
- xoneai/bots/_commands.py +74 -0
- xoneai/bots/_config_schema.py +152 -0
- xoneai/bots/_debounce.py +122 -0
- xoneai/bots/_discord_approval.py +372 -0
- xoneai/bots/_http_approval.py +255 -0
- xoneai/bots/_protocol_mixin.py +235 -0
- xoneai/bots/_registry.py +84 -0
- xoneai/bots/_resilience.py +252 -0
- xoneai/bots/_session.py +237 -0
- xoneai/bots/_slack_approval.py +399 -0
- xoneai/bots/_telegram_approval.py +373 -0
- xoneai/bots/_webhook_approval.py +254 -0
- xoneai/bots/_whatsapp_web_adapter.py +333 -0
- xoneai/bots/bot.py +313 -0
- xoneai/bots/botos.py +320 -0
- xoneai/bots/discord.py +462 -0
- xoneai/bots/media.py +78 -0
- xoneai/bots/slack.py +555 -0
- xoneai/bots/telegram.py +711 -0
- xoneai/bots/whatsapp.py +913 -0
- xoneai/browser/__init__.py +50 -0
- xoneai/browser/agent.py +827 -0
- xoneai/browser/benchmark.py +952 -0
- xoneai/browser/cdp_agent.py +1617 -0
- xoneai/browser/cdp_utils.py +367 -0
- xoneai/browser/cli.py +3161 -0
- xoneai/browser/diagnostics.py +609 -0
- xoneai/browser/launcher.py +363 -0
- xoneai/browser/playwright_agent.py +271 -0
- xoneai/browser/profiling.py +305 -0
- xoneai/browser/protocol.py +108 -0
- xoneai/browser/report.py +137 -0
- xoneai/browser/server.py +1035 -0
- xoneai/browser/sessions.py +386 -0
- xoneai/browser/video.py +333 -0
- xoneai/capabilities/__init__.py +278 -0
- xoneai/capabilities/a2a.py +140 -0
- xoneai/capabilities/assistants.py +283 -0
- xoneai/capabilities/audio.py +320 -0
- xoneai/capabilities/batches.py +469 -0
- xoneai/capabilities/completions.py +336 -0
- xoneai/capabilities/container_files.py +155 -0
- xoneai/capabilities/containers.py +93 -0
- xoneai/capabilities/embeddings.py +168 -0
- xoneai/capabilities/files.py +467 -0
- xoneai/capabilities/fine_tuning.py +293 -0
- xoneai/capabilities/guardrails.py +182 -0
- xoneai/capabilities/images.py +330 -0
- xoneai/capabilities/mcp.py +190 -0
- xoneai/capabilities/messages.py +270 -0
- xoneai/capabilities/moderations.py +154 -0
- xoneai/capabilities/ocr.py +217 -0
- xoneai/capabilities/passthrough.py +204 -0
- xoneai/capabilities/rag.py +207 -0
- xoneai/capabilities/realtime.py +160 -0
- xoneai/capabilities/rerank.py +165 -0
- xoneai/capabilities/responses.py +266 -0
- xoneai/capabilities/search.py +109 -0
- xoneai/capabilities/skills.py +133 -0
- xoneai/capabilities/vector_store_files.py +334 -0
- xoneai/capabilities/vector_stores.py +304 -0
- xoneai/capabilities/videos.py +141 -0
- xoneai/chainlit_ui.py +304 -0
- xoneai/chat/__init__.py +106 -0
- xoneai/chat/app.py +125 -0
- xoneai/cli/__init__.py +26 -0
- xoneai/cli/app.py +525 -0
- xoneai/cli/branding.py +98 -0
- xoneai/cli/commands/__init__.py +91 -0
- xoneai/cli/commands/acp.py +80 -0
- xoneai/cli/commands/agents.py +80 -0
- xoneai/cli/commands/app.py +139 -0
- xoneai/cli/commands/audit.py +102 -0
- xoneai/cli/commands/batch.py +848 -0
- xoneai/cli/commands/benchmark.py +286 -0
- xoneai/cli/commands/bot.py +403 -0
- xoneai/cli/commands/browser.py +299 -0
- xoneai/cli/commands/call.py +45 -0
- xoneai/cli/commands/chat.py +319 -0
- xoneai/cli/commands/code.py +156 -0
- xoneai/cli/commands/commit.py +47 -0
- xoneai/cli/commands/completion.py +333 -0
- xoneai/cli/commands/config.py +166 -0
- xoneai/cli/commands/context.py +414 -0
- xoneai/cli/commands/debug.py +142 -0
- xoneai/cli/commands/deploy.py +109 -0
- xoneai/cli/commands/diag.py +55 -0
- xoneai/cli/commands/docs.py +1572 -0
- xoneai/cli/commands/doctor.py +334 -0
- xoneai/cli/commands/endpoints.py +51 -0
- xoneai/cli/commands/environment.py +179 -0
- xoneai/cli/commands/eval.py +131 -0
- xoneai/cli/commands/examples.py +826 -0
- xoneai/cli/commands/gateway.py +83 -0
- xoneai/cli/commands/hooks.py +74 -0
- xoneai/cli/commands/knowledge.py +440 -0
- xoneai/cli/commands/loop.py +211 -0
- xoneai/cli/commands/lsp.py +112 -0
- xoneai/cli/commands/mcp.py +700 -0
- xoneai/cli/commands/memory.py +298 -0
- xoneai/cli/commands/obs.py +19 -0
- xoneai/cli/commands/package.py +76 -0
- xoneai/cli/commands/plugins.py +609 -0
- xoneai/cli/commands/profile.py +466 -0
- xoneai/cli/commands/rag.py +913 -0
- xoneai/cli/commands/realtime.py +45 -0
- xoneai/cli/commands/recipe.py +675 -0
- xoneai/cli/commands/registry.py +59 -0
- xoneai/cli/commands/replay.py +830 -0
- xoneai/cli/commands/research.py +49 -0
- xoneai/cli/commands/retrieval.py +377 -0
- xoneai/cli/commands/rules.py +71 -0
- xoneai/cli/commands/run.py +411 -0
- xoneai/cli/commands/sandbox.py +371 -0
- xoneai/cli/commands/schedule.py +150 -0
- xoneai/cli/commands/serve.py +579 -0
- xoneai/cli/commands/session.py +284 -0
- xoneai/cli/commands/skills.py +370 -0
- xoneai/cli/commands/standardise.py +694 -0
- xoneai/cli/commands/templates.py +54 -0
- xoneai/cli/commands/test.py +558 -0
- xoneai/cli/commands/todo.py +74 -0
- xoneai/cli/commands/tools.py +204 -0
- xoneai/cli/commands/traces.py +145 -0
- xoneai/cli/commands/tracker.py +852 -0
- xoneai/cli/commands/train.py +613 -0
- xoneai/cli/commands/ui.py +242 -0
- xoneai/cli/commands/version.py +101 -0
- xoneai/cli/commands/workflow.py +91 -0
- xoneai/cli/config_loader.py +298 -0
- xoneai/cli/configuration/__init__.py +18 -0
- xoneai/cli/configuration/loader.py +353 -0
- xoneai/cli/configuration/paths.py +114 -0
- xoneai/cli/configuration/schema.py +233 -0
- xoneai/cli/execution/__init__.py +99 -0
- xoneai/cli/execution/core.py +210 -0
- xoneai/cli/execution/profiler.py +898 -0
- xoneai/cli/execution/request.py +85 -0
- xoneai/cli/execution/result.py +74 -0
- xoneai/cli/features/__init__.py +273 -0
- xoneai/cli/features/acp.py +236 -0
- xoneai/cli/features/action_orchestrator.py +554 -0
- xoneai/cli/features/agent_scheduler.py +773 -0
- xoneai/cli/features/agent_tools.py +474 -0
- xoneai/cli/features/agents.py +375 -0
- xoneai/cli/features/approval.py +139 -0
- xoneai/cli/features/at_mentions.py +471 -0
- xoneai/cli/features/audit_cli.py +270 -0
- xoneai/cli/features/auto_memory.py +182 -0
- xoneai/cli/features/auto_mode.py +552 -0
- xoneai/cli/features/autonomy_mode.py +546 -0
- xoneai/cli/features/background.py +356 -0
- xoneai/cli/features/base.py +168 -0
- xoneai/cli/features/benchmark.py +1462 -0
- xoneai/cli/features/bots_cli.py +1133 -0
- xoneai/cli/features/capabilities.py +1326 -0
- xoneai/cli/features/checkpoints.py +338 -0
- xoneai/cli/features/cli_profiler.py +335 -0
- xoneai/cli/features/code_intelligence.py +666 -0
- xoneai/cli/features/compaction.py +294 -0
- xoneai/cli/features/compare.py +534 -0
- xoneai/cli/features/config_hierarchy.py +318 -0
- xoneai/cli/features/context_manager.py +597 -0
- xoneai/cli/features/cost_tracker.py +514 -0
- xoneai/cli/features/csv_test_runner.py +736 -0
- xoneai/cli/features/debug.py +810 -0
- xoneai/cli/features/deploy.py +517 -0
- xoneai/cli/features/diag.py +289 -0
- xoneai/cli/features/doctor/__init__.py +63 -0
- xoneai/cli/features/doctor/checks/__init__.py +24 -0
- xoneai/cli/features/doctor/checks/acp_checks.py +220 -0
- xoneai/cli/features/doctor/checks/bot_checks.py +88 -0
- xoneai/cli/features/doctor/checks/config_checks.py +366 -0
- xoneai/cli/features/doctor/checks/db_checks.py +366 -0
- xoneai/cli/features/doctor/checks/env_checks.py +628 -0
- xoneai/cli/features/doctor/checks/lsp_checks.py +231 -0
- xoneai/cli/features/doctor/checks/mcp_checks.py +349 -0
- xoneai/cli/features/doctor/checks/memory_checks.py +268 -0
- xoneai/cli/features/doctor/checks/network_checks.py +251 -0
- xoneai/cli/features/doctor/checks/obs_checks.py +328 -0
- xoneai/cli/features/doctor/checks/performance_checks.py +235 -0
- xoneai/cli/features/doctor/checks/permissions_checks.py +259 -0
- xoneai/cli/features/doctor/checks/selftest_checks.py +322 -0
- xoneai/cli/features/doctor/checks/serve_checks.py +426 -0
- xoneai/cli/features/doctor/checks/skills_checks.py +231 -0
- xoneai/cli/features/doctor/checks/tools_checks.py +371 -0
- xoneai/cli/features/doctor/engine.py +266 -0
- xoneai/cli/features/doctor/formatters.py +310 -0
- xoneai/cli/features/doctor/handler.py +397 -0
- xoneai/cli/features/doctor/models.py +265 -0
- xoneai/cli/features/doctor/registry.py +239 -0
- xoneai/cli/features/endpoints.py +1019 -0
- xoneai/cli/features/eval.py +559 -0
- xoneai/cli/features/examples.py +707 -0
- xoneai/cli/features/external_agents.py +231 -0
- xoneai/cli/features/fast_context.py +410 -0
- xoneai/cli/features/file_history.py +320 -0
- xoneai/cli/features/flow_display.py +566 -0
- xoneai/cli/features/gateway.py +238 -0
- xoneai/cli/features/git_attribution.py +159 -0
- xoneai/cli/features/git_integration.py +651 -0
- xoneai/cli/features/guardrail.py +171 -0
- xoneai/cli/features/handoff.py +252 -0
- xoneai/cli/features/hooks.py +583 -0
- xoneai/cli/features/image.py +384 -0
- xoneai/cli/features/interactive_core_headless.py +450 -0
- xoneai/cli/features/interactive_runtime.py +600 -0
- xoneai/cli/features/interactive_test_harness.py +537 -0
- xoneai/cli/features/interactive_tools.py +408 -0
- xoneai/cli/features/interactive_tui.py +603 -0
- xoneai/cli/features/jobs.py +632 -0
- xoneai/cli/features/knowledge.py +531 -0
- xoneai/cli/features/knowledge_cli.py +438 -0
- xoneai/cli/features/lite.py +244 -0
- xoneai/cli/features/logs.py +200 -0
- xoneai/cli/features/lsp_cli.py +225 -0
- xoneai/cli/features/lsp_diagnostics.py +185 -0
- xoneai/cli/features/mcp.py +169 -0
- xoneai/cli/features/message_queue.py +587 -0
- xoneai/cli/features/metrics.py +211 -0
- xoneai/cli/features/migrate.py +1297 -0
- xoneai/cli/features/migration_flow.py +463 -0
- xoneai/cli/features/migration_spec.py +276 -0
- xoneai/cli/features/n8n.py +673 -0
- xoneai/cli/features/observability.py +293 -0
- xoneai/cli/features/ollama.py +361 -0
- xoneai/cli/features/onboard.py +253 -0
- xoneai/cli/features/output_modes.py +152 -0
- xoneai/cli/features/output_style.py +273 -0
- xoneai/cli/features/package.py +631 -0
- xoneai/cli/features/performance.py +308 -0
- xoneai/cli/features/persistence.py +636 -0
- xoneai/cli/features/plugin_cli.py +295 -0
- xoneai/cli/features/profile.py +226 -0
- xoneai/cli/features/profiler/__init__.py +81 -0
- xoneai/cli/features/profiler/core.py +558 -0
- xoneai/cli/features/profiler/optimizations.py +652 -0
- xoneai/cli/features/profiler/suite.py +386 -0
- xoneai/cli/features/profiling.py +350 -0
- xoneai/cli/features/queue/__init__.py +73 -0
- xoneai/cli/features/queue/manager.py +435 -0
- xoneai/cli/features/queue/models.py +289 -0
- xoneai/cli/features/queue/persistence.py +564 -0
- xoneai/cli/features/queue/scheduler.py +529 -0
- xoneai/cli/features/queue/worker.py +400 -0
- xoneai/cli/features/recipe.py +2183 -0
- xoneai/cli/features/recipe_creator.py +996 -0
- xoneai/cli/features/recipe_optimizer.py +1364 -0
- xoneai/cli/features/recipe_prompts.py +226 -0
- xoneai/cli/features/recipes.py +449 -0
- xoneai/cli/features/registry.py +229 -0
- xoneai/cli/features/repo_map.py +860 -0
- xoneai/cli/features/router.py +466 -0
- xoneai/cli/features/safe_shell.py +354 -0
- xoneai/cli/features/sandbox_cli.py +255 -0
- xoneai/cli/features/sandbox_executor.py +515 -0
- xoneai/cli/features/sdk_knowledge.py +500 -0
- xoneai/cli/features/serve.py +829 -0
- xoneai/cli/features/session.py +222 -0
- xoneai/cli/features/skills.py +855 -0
- xoneai/cli/features/slash_commands.py +650 -0
- xoneai/cli/features/telemetry.py +179 -0
- xoneai/cli/features/templates.py +1384 -0
- xoneai/cli/features/thinking.py +305 -0
- xoneai/cli/features/todo.py +334 -0
- xoneai/cli/features/tools.py +680 -0
- xoneai/cli/features/tui/__init__.py +83 -0
- xoneai/cli/features/tui/app.py +871 -0
- xoneai/cli/features/tui/cli.py +580 -0
- xoneai/cli/features/tui/config.py +150 -0
- xoneai/cli/features/tui/debug.py +526 -0
- xoneai/cli/features/tui/events.py +99 -0
- xoneai/cli/features/tui/mock_provider.py +328 -0
- xoneai/cli/features/tui/orchestrator.py +652 -0
- xoneai/cli/features/tui/screens/__init__.py +50 -0
- xoneai/cli/features/tui/screens/help.py +157 -0
- xoneai/cli/features/tui/screens/main.py +568 -0
- xoneai/cli/features/tui/screens/queue.py +174 -0
- xoneai/cli/features/tui/screens/session.py +124 -0
- xoneai/cli/features/tui/screens/settings.py +148 -0
- xoneai/cli/features/tui/session_store.py +198 -0
- xoneai/cli/features/tui/widgets/__init__.py +56 -0
- xoneai/cli/features/tui/widgets/chat.py +263 -0
- xoneai/cli/features/tui/widgets/command_popup.py +258 -0
- xoneai/cli/features/tui/widgets/composer.py +292 -0
- xoneai/cli/features/tui/widgets/file_popup.py +207 -0
- xoneai/cli/features/tui/widgets/queue_panel.py +223 -0
- xoneai/cli/features/tui/widgets/status.py +181 -0
- xoneai/cli/features/tui/widgets/tool_panel.py +307 -0
- xoneai/cli/features/wizard.py +289 -0
- xoneai/cli/features/workflow.py +720 -0
- xoneai/cli/features/yaml_utils.py +321 -0
- xoneai/cli/interactive/__init__.py +48 -0
- xoneai/cli/interactive/async_tui.py +1187 -0
- xoneai/cli/interactive/config.py +133 -0
- xoneai/cli/interactive/core.py +578 -0
- xoneai/cli/interactive/events.py +131 -0
- xoneai/cli/interactive/frontends/__init__.py +31 -0
- xoneai/cli/interactive/frontends/rich_frontend.py +462 -0
- xoneai/cli/interactive/frontends/textual_frontend.py +157 -0
- xoneai/cli/interactive/repl.py +297 -0
- xoneai/cli/interactive/split_tui.py +456 -0
- xoneai/cli/interactive/tui_app.py +457 -0
- xoneai/cli/interactive/xone_io.py +502 -0
- xoneai/cli/legacy.py +266 -0
- xoneai/cli/main.py +6491 -0
- xoneai/cli/output/__init__.py +15 -0
- xoneai/cli/output/console.py +363 -0
- xoneai/cli/schedule_cli.py +54 -0
- xoneai/cli/session/__init__.py +13 -0
- xoneai/cli/session/unified.py +306 -0
- xoneai/cli/state/__init__.py +31 -0
- xoneai/cli/state/identifiers.py +161 -0
- xoneai/cli/state/sessions.py +390 -0
- xoneai/cli/ui/__init__.py +162 -0
- xoneai/cli/ui/config.py +46 -0
- xoneai/cli/ui/events.py +61 -0
- xoneai/cli/ui/mg_backend.py +342 -0
- xoneai/cli/ui/plain.py +133 -0
- xoneai/cli/ui/rich_backend.py +162 -0
- xoneai/code/__init__.py +93 -0
- xoneai/code/agent_tools.py +344 -0
- xoneai/code/diff/__init__.py +21 -0
- xoneai/code/diff/diff_strategy.py +432 -0
- xoneai/code/tools/__init__.py +27 -0
- xoneai/code/tools/apply_diff.py +232 -0
- xoneai/code/tools/execute_command.py +318 -0
- xoneai/code/tools/list_files.py +274 -0
- xoneai/code/tools/read_file.py +206 -0
- xoneai/code/tools/search_replace.py +248 -0
- xoneai/code/tools/write_file.py +227 -0
- xoneai/code/utils/__init__.py +46 -0
- xoneai/code/utils/file_utils.py +307 -0
- xoneai/code/utils/ignore_utils.py +308 -0
- xoneai/code/utils/text_utils.py +276 -0
- xoneai/context/__init__.py +104 -0
- xoneai/context/artifact_store.py +513 -0
- xoneai/context/config.py +111 -0
- xoneai/context/history_store.py +514 -0
- xoneai/context/queue.py +384 -0
- xoneai/context/setup.py +144 -0
- xoneai/context/terminal_logger.py +486 -0
- xoneai/daemon/__init__.py +62 -0
- xoneai/daemon/launchd.py +138 -0
- xoneai/daemon/systemd.py +123 -0
- xoneai/db/__init__.py +64 -0
- xoneai/db/adapter.py +531 -0
- xoneai/deploy/__init__.py +62 -0
- xoneai/deploy/api.py +231 -0
- xoneai/deploy/docker.py +454 -0
- xoneai/deploy/doctor.py +367 -0
- xoneai/deploy/main.py +327 -0
- xoneai/deploy/models.py +179 -0
- xoneai/deploy/providers/__init__.py +33 -0
- xoneai/deploy/providers/aws.py +331 -0
- xoneai/deploy/providers/azure.py +358 -0
- xoneai/deploy/providers/base.py +101 -0
- xoneai/deploy/providers/gcp.py +314 -0
- xoneai/deploy/schema.py +208 -0
- xoneai/deploy.py +185 -0
- xoneai/docs_runner/__init__.py +38 -0
- xoneai/docs_runner/classifier.py +152 -0
- xoneai/docs_runner/executor.py +336 -0
- xoneai/docs_runner/extractor.py +215 -0
- xoneai/docs_runner/reporter.py +289 -0
- xoneai/docs_runner/runner.py +269 -0
- xoneai/docs_runner/workspace.py +113 -0
- xoneai/endpoints/__init__.py +53 -0
- xoneai/endpoints/a2u_server.py +420 -0
- xoneai/endpoints/discovery.py +165 -0
- xoneai/endpoints/providers/__init__.py +28 -0
- xoneai/endpoints/providers/a2a.py +253 -0
- xoneai/endpoints/providers/a2u.py +208 -0
- xoneai/endpoints/providers/agents_api.py +171 -0
- xoneai/endpoints/providers/base.py +231 -0
- xoneai/endpoints/providers/mcp.py +263 -0
- xoneai/endpoints/providers/recipe.py +206 -0
- xoneai/endpoints/providers/tools_mcp.py +150 -0
- xoneai/endpoints/registry.py +131 -0
- xoneai/endpoints/server.py +161 -0
- xoneai/gateway/__init__.py +22 -0
- xoneai/gateway/server.py +1101 -0
- xoneai/inbuilt_tools/__init__.py +49 -0
- xoneai/inbuilt_tools/autogen_tools.py +117 -0
- xoneai/inc/__init__.py +12 -0
- xoneai/inc/config.py +96 -0
- xoneai/inc/models.py +153 -0
- xoneai/integrations/__init__.py +56 -0
- xoneai/integrations/base.py +303 -0
- xoneai/integrations/claude_code.py +270 -0
- xoneai/integrations/codex_cli.py +255 -0
- xoneai/integrations/cursor_cli.py +195 -0
- xoneai/integrations/gemini_cli.py +222 -0
- xoneai/jobs/__init__.py +67 -0
- xoneai/jobs/executor.py +424 -0
- xoneai/jobs/models.py +230 -0
- xoneai/jobs/router.py +314 -0
- xoneai/jobs/server.py +186 -0
- xoneai/jobs/store.py +215 -0
- xoneai/llm/__init__.py +131 -0
- xoneai/llm/registry.py +382 -0
- xoneai/mcp_server/__init__.py +152 -0
- xoneai/mcp_server/adapters/__init__.py +74 -0
- xoneai/mcp_server/adapters/agents.py +128 -0
- xoneai/mcp_server/adapters/capabilities.py +168 -0
- xoneai/mcp_server/adapters/cli_tools.py +568 -0
- xoneai/mcp_server/adapters/extended_capabilities.py +462 -0
- xoneai/mcp_server/adapters/knowledge.py +93 -0
- xoneai/mcp_server/adapters/memory.py +104 -0
- xoneai/mcp_server/adapters/prompts.py +306 -0
- xoneai/mcp_server/adapters/resources.py +124 -0
- xoneai/mcp_server/adapters/tools_bridge.py +280 -0
- xoneai/mcp_server/auth/__init__.py +48 -0
- xoneai/mcp_server/auth/api_key.py +291 -0
- xoneai/mcp_server/auth/oauth.py +460 -0
- xoneai/mcp_server/auth/oidc.py +289 -0
- xoneai/mcp_server/auth/scopes.py +260 -0
- xoneai/mcp_server/cli.py +852 -0
- xoneai/mcp_server/elicitation.py +445 -0
- xoneai/mcp_server/icons.py +302 -0
- xoneai/mcp_server/recipe_adapter.py +573 -0
- xoneai/mcp_server/recipe_cli.py +824 -0
- xoneai/mcp_server/registry.py +703 -0
- xoneai/mcp_server/sampling.py +422 -0
- xoneai/mcp_server/server.py +490 -0
- xoneai/mcp_server/tasks.py +443 -0
- xoneai/mcp_server/tool_index.py +483 -0
- xoneai/mcp_server/transports/__init__.py +18 -0
- xoneai/mcp_server/transports/http_stream.py +376 -0
- xoneai/mcp_server/transports/stdio.py +132 -0
- xoneai/persistence/__init__.py +84 -0
- xoneai/persistence/config.py +238 -0
- xoneai/persistence/conversation/__init__.py +25 -0
- xoneai/persistence/conversation/async_mysql.py +427 -0
- xoneai/persistence/conversation/async_postgres.py +410 -0
- xoneai/persistence/conversation/async_sqlite.py +371 -0
- xoneai/persistence/conversation/base.py +151 -0
- xoneai/persistence/conversation/json_store.py +250 -0
- xoneai/persistence/conversation/mysql.py +387 -0
- xoneai/persistence/conversation/postgres.py +401 -0
- xoneai/persistence/conversation/singlestore.py +240 -0
- xoneai/persistence/conversation/sqlite.py +341 -0
- xoneai/persistence/conversation/supabase.py +203 -0
- xoneai/persistence/conversation/surrealdb.py +287 -0
- xoneai/persistence/factory.py +301 -0
- xoneai/persistence/hooks/__init__.py +18 -0
- xoneai/persistence/hooks/agent_hooks.py +297 -0
- xoneai/persistence/knowledge/__init__.py +26 -0
- xoneai/persistence/knowledge/base.py +144 -0
- xoneai/persistence/knowledge/cassandra.py +232 -0
- xoneai/persistence/knowledge/chroma.py +295 -0
- xoneai/persistence/knowledge/clickhouse.py +242 -0
- xoneai/persistence/knowledge/cosmosdb_vector.py +438 -0
- xoneai/persistence/knowledge/couchbase.py +286 -0
- xoneai/persistence/knowledge/lancedb.py +216 -0
- xoneai/persistence/knowledge/langchain_adapter.py +291 -0
- xoneai/persistence/knowledge/lightrag_adapter.py +212 -0
- xoneai/persistence/knowledge/llamaindex_adapter.py +256 -0
- xoneai/persistence/knowledge/milvus.py +277 -0
- xoneai/persistence/knowledge/mongodb_vector.py +306 -0
- xoneai/persistence/knowledge/pgvector.py +335 -0
- xoneai/persistence/knowledge/pinecone.py +253 -0
- xoneai/persistence/knowledge/qdrant.py +301 -0
- xoneai/persistence/knowledge/redis_vector.py +291 -0
- xoneai/persistence/knowledge/singlestore_vector.py +299 -0
- xoneai/persistence/knowledge/surrealdb_vector.py +309 -0
- xoneai/persistence/knowledge/upstash_vector.py +266 -0
- xoneai/persistence/knowledge/weaviate.py +223 -0
- xoneai/persistence/migrations/__init__.py +10 -0
- xoneai/persistence/migrations/manager.py +251 -0
- xoneai/persistence/orchestrator.py +406 -0
- xoneai/persistence/state/__init__.py +21 -0
- xoneai/persistence/state/async_mongodb.py +200 -0
- xoneai/persistence/state/base.py +107 -0
- xoneai/persistence/state/dynamodb.py +226 -0
- xoneai/persistence/state/firestore.py +175 -0
- xoneai/persistence/state/gcs.py +155 -0
- xoneai/persistence/state/memory.py +245 -0
- xoneai/persistence/state/mongodb.py +158 -0
- xoneai/persistence/state/redis.py +190 -0
- xoneai/persistence/state/upstash.py +144 -0
- xoneai/persistence/tests/__init__.py +3 -0
- xoneai/persistence/tests/test_all_backends.py +633 -0
- xoneai/profiler.py +1214 -0
- xoneai/recipe/__init__.py +134 -0
- xoneai/recipe/bridge.py +278 -0
- xoneai/recipe/core.py +1119 -0
- xoneai/recipe/exceptions.py +54 -0
- xoneai/recipe/history.py +467 -0
- xoneai/recipe/models.py +266 -0
- xoneai/recipe/operations.py +440 -0
- xoneai/recipe/policy.py +422 -0
- xoneai/recipe/registry.py +849 -0
- xoneai/recipe/runtime.py +214 -0
- xoneai/recipe/security.py +711 -0
- xoneai/recipe/serve.py +859 -0
- xoneai/recipe/server.py +613 -0
- xoneai/replay/__init__.py +91 -0
- xoneai/replay/analyzer.py +464 -0
- xoneai/replay/applier.py +285 -0
- xoneai/replay/judge.py +2719 -0
- xoneai/replay/plan.py +200 -0
- xoneai/replay/player.py +313 -0
- xoneai/replay/reader.py +151 -0
- xoneai/replay/storage.py +132 -0
- xoneai/replay/writer.py +131 -0
- xoneai/sandbox/__init__.py +23 -0
- xoneai/sandbox/docker.py +437 -0
- xoneai/sandbox/subprocess.py +349 -0
- xoneai/scheduler/__init__.py +45 -0
- xoneai/scheduler/agent_scheduler.py +552 -0
- xoneai/scheduler/base.py +124 -0
- xoneai/scheduler/daemon_manager.py +225 -0
- xoneai/scheduler/state_manager.py +155 -0
- xoneai/scheduler/yaml_loader.py +193 -0
- xoneai/scheduler.py +194 -0
- xoneai/security/__init__.py +183 -0
- xoneai/security/audit.py +99 -0
- xoneai/security/injection.py +414 -0
- xoneai/security/protected.py +132 -0
- xoneai/setup/__init__.py +1 -0
- xoneai/setup/build.py +21 -0
- xoneai/setup/post_install.py +23 -0
- xoneai/setup/setup_conda_env.py +25 -0
- xoneai/setup.py +16 -0
- xoneai/standardise/__init__.py +84 -0
- xoneai/standardise/ai_generator.py +1278 -0
- xoneai/standardise/config.py +260 -0
- xoneai/standardise/dedupe.py +221 -0
- xoneai/standardise/discovery.py +319 -0
- xoneai/standardise/drift.py +263 -0
- xoneai/standardise/engine.py +270 -0
- xoneai/standardise/enhanced_templates.py +674 -0
- xoneai/standardise/example_verifier.py +229 -0
- xoneai/standardise/manifest.py +201 -0
- xoneai/standardise/models.py +355 -0
- xoneai/standardise/reports.py +176 -0
- xoneai/standardise/templates.py +399 -0
- xoneai/standardise/undo_redo.py +232 -0
- xoneai/standardise/validator.py +283 -0
- xoneai/suite_runner/__init__.py +73 -0
- xoneai/suite_runner/batch_source.py +351 -0
- xoneai/suite_runner/cli_docs_source.py +300 -0
- xoneai/suite_runner/discovery.py +269 -0
- xoneai/suite_runner/docs_source.py +379 -0
- xoneai/suite_runner/examples_source.py +173 -0
- xoneai/suite_runner/executor.py +232 -0
- xoneai/suite_runner/models.py +257 -0
- xoneai/suite_runner/report_viewer.py +793 -0
- xoneai/suite_runner/reporter.py +301 -0
- xoneai/suite_runner/runner.py +294 -0
- xoneai/templates/__init__.py +116 -0
- xoneai/templates/cache.py +364 -0
- xoneai/templates/dependency_checker.py +358 -0
- xoneai/templates/discovery.py +391 -0
- xoneai/templates/loader.py +649 -0
- xoneai/templates/registry.py +511 -0
- xoneai/templates/resolver.py +206 -0
- xoneai/templates/security.py +334 -0
- xoneai/templates/tool_override.py +501 -0
- xoneai/templates/tools_doctor.py +256 -0
- xoneai/test.py +105 -0
- xoneai/tool_resolver.py +418 -0
- xoneai/tools/__init__.py +61 -0
- xoneai/tools/audio.py +268 -0
- xoneai/tools/glob_tool.py +192 -0
- xoneai/tools/grep_tool.py +259 -0
- xoneai/tools/multiedit.py +224 -0
- xoneai/train/__init__.py +77 -0
- xoneai/train/agents/__init__.py +94 -0
- xoneai/train/agents/grader.py +63 -0
- xoneai/train/agents/hook.py +320 -0
- xoneai/train/agents/models.py +328 -0
- xoneai/train/agents/orchestrator.py +394 -0
- xoneai/train/agents/storage.py +282 -0
- xoneai/train/llm/__init__.py +23 -0
- xoneai/train/llm/trainer.py +562 -0
- xoneai/train.py +562 -0
- xoneai/train_vision.py +306 -0
- xoneai/ui/agents.py +838 -0
- xoneai/ui/bot.py +422 -0
- xoneai/ui/callbacks.py +57 -0
- xoneai/ui/chainlit_compat.py +246 -0
- xoneai/ui/chat.py +834 -0
- xoneai/ui/code.py +816 -0
- xoneai/ui/colab.py +474 -0
- xoneai/ui/colab_chainlit.py +81 -0
- xoneai/ui/components/aicoder.py +284 -0
- xoneai/ui/context.py +283 -0
- xoneai/ui/database_config.py +56 -0
- xoneai/ui/db.py +294 -0
- xoneai/ui/realtime.py +488 -0
- xoneai/ui/realtimeclient/__init__.py +756 -0
- xoneai/ui/realtimeclient/tools.py +242 -0
- xoneai/ui/sql_alchemy.py +710 -0
- xoneai/upload_vision.py +140 -0
- xoneai/version.py +1 -0
- xoneai-1.0.1.dist-info/METADATA +3548 -0
- xoneai-1.0.1.dist-info/RECORD +640 -0
- xoneai-1.0.1.dist-info/WHEEL +5 -0
- xoneai-1.0.1.dist-info/entry_points.txt +4 -0
- xoneai-1.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MCP Tasks API Implementation
|
|
3
|
+
|
|
4
|
+
Implements the Tasks API per MCP 2025-11-25 specification.
|
|
5
|
+
Tasks are durable state machines for tracking long-running operations.
|
|
6
|
+
|
|
7
|
+
Features:
|
|
8
|
+
- Task creation, update, cancellation
|
|
9
|
+
- Polling and deferred result retrieval
|
|
10
|
+
- In-memory storage (default) with optional DB adapters
|
|
11
|
+
- Session-scoped task management
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import asyncio
|
|
15
|
+
import logging
|
|
16
|
+
import time
|
|
17
|
+
import uuid
|
|
18
|
+
from dataclasses import dataclass, field
|
|
19
|
+
from datetime import datetime, timezone
|
|
20
|
+
from enum import Enum
|
|
21
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _iso_now() -> str:
|
|
27
|
+
"""Get current time as ISO 8601 string."""
|
|
28
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class TaskStatus(str, Enum):
|
|
32
|
+
"""Task status values per MCP 2025-11-25 specification."""
|
|
33
|
+
PENDING = "pending" # Task created but not yet started
|
|
34
|
+
WORKING = "working" # Task is actively being processed
|
|
35
|
+
INPUT_REQUIRED = "input_required" # Task needs user input (elicitation)
|
|
36
|
+
COMPLETED = "completed" # Task finished successfully
|
|
37
|
+
FAILED = "failed" # Task failed with error
|
|
38
|
+
CANCELLED = "cancelled" # Task was cancelled
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# Alias for backwards compatibility
|
|
42
|
+
TaskState = TaskStatus
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class TaskProgress:
|
|
47
|
+
"""Task progress information."""
|
|
48
|
+
current: float = 0.0
|
|
49
|
+
total: Optional[float] = None
|
|
50
|
+
message: Optional[str] = None
|
|
51
|
+
|
|
52
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
53
|
+
result = {"current": self.current}
|
|
54
|
+
if self.total is not None:
|
|
55
|
+
result["total"] = self.total
|
|
56
|
+
if self.message:
|
|
57
|
+
result["message"] = self.message
|
|
58
|
+
return result
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass
|
|
62
|
+
class Task:
|
|
63
|
+
"""
|
|
64
|
+
MCP Task representation per 2025-11-25 specification.
|
|
65
|
+
|
|
66
|
+
Tasks are durable state machines that carry information about the underlying
|
|
67
|
+
execution state of requests, intended for requestor polling and deferred result retrieval.
|
|
68
|
+
"""
|
|
69
|
+
id: str # Internal ID (maps to taskId in protocol)
|
|
70
|
+
method: str
|
|
71
|
+
params: Dict[str, Any] = field(default_factory=dict)
|
|
72
|
+
status: TaskStatus = TaskStatus.PENDING
|
|
73
|
+
status_message: Optional[str] = None
|
|
74
|
+
progress: Optional[TaskProgress] = None
|
|
75
|
+
result: Any = None
|
|
76
|
+
error: Optional[Dict[str, Any]] = None
|
|
77
|
+
created_at: str = field(default_factory=lambda: _iso_now())
|
|
78
|
+
last_updated_at: str = field(default_factory=lambda: _iso_now())
|
|
79
|
+
ttl: Optional[int] = None # TTL in milliseconds
|
|
80
|
+
poll_interval: int = 5000 # Recommended poll interval in milliseconds
|
|
81
|
+
session_id: Optional[str] = None
|
|
82
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
83
|
+
|
|
84
|
+
# Backwards compatibility alias
|
|
85
|
+
@property
|
|
86
|
+
def state(self) -> TaskStatus:
|
|
87
|
+
return self.status
|
|
88
|
+
|
|
89
|
+
@state.setter
|
|
90
|
+
def state(self, value: TaskStatus) -> None:
|
|
91
|
+
self.status = value
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def updated_at(self) -> str:
|
|
95
|
+
return self.last_updated_at
|
|
96
|
+
|
|
97
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
98
|
+
"""Convert to MCP task response format per 2025-11-25 spec."""
|
|
99
|
+
result = {
|
|
100
|
+
"taskId": self.id,
|
|
101
|
+
"status": self.status.value,
|
|
102
|
+
"createdAt": self.created_at,
|
|
103
|
+
"lastUpdatedAt": self.last_updated_at,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if self.status_message:
|
|
107
|
+
result["statusMessage"] = self.status_message
|
|
108
|
+
|
|
109
|
+
if self.ttl is not None:
|
|
110
|
+
result["ttl"] = self.ttl
|
|
111
|
+
|
|
112
|
+
if self.poll_interval:
|
|
113
|
+
result["pollInterval"] = self.poll_interval
|
|
114
|
+
|
|
115
|
+
if self.progress:
|
|
116
|
+
result["progress"] = self.progress.to_dict()
|
|
117
|
+
|
|
118
|
+
if self.metadata:
|
|
119
|
+
result["_meta"] = self.metadata
|
|
120
|
+
|
|
121
|
+
return result
|
|
122
|
+
|
|
123
|
+
def to_create_result(self) -> Dict[str, Any]:
|
|
124
|
+
"""Convert to CreateTaskResult format."""
|
|
125
|
+
return {"task": self.to_dict()}
|
|
126
|
+
|
|
127
|
+
def to_get_result(self) -> Dict[str, Any]:
|
|
128
|
+
"""Convert to GetTaskResult format."""
|
|
129
|
+
return self.to_dict()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class TaskStore:
|
|
133
|
+
"""
|
|
134
|
+
In-memory task storage.
|
|
135
|
+
|
|
136
|
+
Can be extended with DB adapters for persistence.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
def __init__(self, max_tasks: int = 1000, ttl: int = 3600):
|
|
140
|
+
"""
|
|
141
|
+
Initialize task store.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
max_tasks: Maximum number of tasks to store
|
|
145
|
+
ttl: Task TTL in seconds (for cleanup)
|
|
146
|
+
"""
|
|
147
|
+
self._tasks: Dict[str, Task] = {}
|
|
148
|
+
self._max_tasks = max_tasks
|
|
149
|
+
self._ttl = ttl
|
|
150
|
+
|
|
151
|
+
def create(
|
|
152
|
+
self,
|
|
153
|
+
method: str,
|
|
154
|
+
params: Dict[str, Any],
|
|
155
|
+
session_id: Optional[str] = None,
|
|
156
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
157
|
+
) -> Task:
|
|
158
|
+
"""Create a new task."""
|
|
159
|
+
# Cleanup old tasks if at capacity
|
|
160
|
+
if len(self._tasks) >= self._max_tasks:
|
|
161
|
+
self._cleanup_old_tasks()
|
|
162
|
+
|
|
163
|
+
task_id = f"task-{uuid.uuid4().hex[:16]}"
|
|
164
|
+
task = Task(
|
|
165
|
+
id=task_id,
|
|
166
|
+
method=method,
|
|
167
|
+
params=params,
|
|
168
|
+
session_id=session_id,
|
|
169
|
+
metadata=metadata or {},
|
|
170
|
+
)
|
|
171
|
+
self._tasks[task_id] = task
|
|
172
|
+
logger.debug(f"Created task: {task_id}")
|
|
173
|
+
return task
|
|
174
|
+
|
|
175
|
+
def get(self, task_id: str) -> Optional[Task]:
|
|
176
|
+
"""Get a task by ID."""
|
|
177
|
+
return self._tasks.get(task_id)
|
|
178
|
+
|
|
179
|
+
def update(
|
|
180
|
+
self,
|
|
181
|
+
task_id: str,
|
|
182
|
+
status: Optional[TaskStatus] = None,
|
|
183
|
+
status_message: Optional[str] = None,
|
|
184
|
+
progress: Optional[TaskProgress] = None,
|
|
185
|
+
result: Any = None,
|
|
186
|
+
error: Optional[Dict[str, Any]] = None,
|
|
187
|
+
state: Optional[TaskStatus] = None, # Backwards compat alias
|
|
188
|
+
) -> Optional[Task]:
|
|
189
|
+
"""Update a task."""
|
|
190
|
+
task = self._tasks.get(task_id)
|
|
191
|
+
if not task:
|
|
192
|
+
return None
|
|
193
|
+
|
|
194
|
+
task.last_updated_at = _iso_now()
|
|
195
|
+
|
|
196
|
+
# Support both status and state (backwards compat)
|
|
197
|
+
new_status = status or state
|
|
198
|
+
if new_status:
|
|
199
|
+
task.status = new_status
|
|
200
|
+
|
|
201
|
+
if status_message:
|
|
202
|
+
task.status_message = status_message
|
|
203
|
+
|
|
204
|
+
if progress:
|
|
205
|
+
task.progress = progress
|
|
206
|
+
|
|
207
|
+
if result is not None:
|
|
208
|
+
task.result = result
|
|
209
|
+
|
|
210
|
+
if error:
|
|
211
|
+
task.error = error
|
|
212
|
+
|
|
213
|
+
logger.debug(f"Updated task {task_id}: status={task.status}")
|
|
214
|
+
return task
|
|
215
|
+
|
|
216
|
+
def cancel(self, task_id: str) -> Optional[Task]:
|
|
217
|
+
"""Cancel a task."""
|
|
218
|
+
task = self._tasks.get(task_id)
|
|
219
|
+
if not task:
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
if task.status in (TaskStatus.PENDING, TaskStatus.WORKING):
|
|
223
|
+
task.status = TaskStatus.CANCELLED
|
|
224
|
+
task.status_message = "The task was cancelled by request."
|
|
225
|
+
task.last_updated_at = _iso_now()
|
|
226
|
+
logger.debug(f"Cancelled task: {task_id}")
|
|
227
|
+
|
|
228
|
+
return task
|
|
229
|
+
|
|
230
|
+
def delete(self, task_id: str) -> bool:
|
|
231
|
+
"""Delete a task."""
|
|
232
|
+
if task_id in self._tasks:
|
|
233
|
+
del self._tasks[task_id]
|
|
234
|
+
return True
|
|
235
|
+
return False
|
|
236
|
+
|
|
237
|
+
def list_tasks(
|
|
238
|
+
self,
|
|
239
|
+
session_id: Optional[str] = None,
|
|
240
|
+
status: Optional[TaskStatus] = None,
|
|
241
|
+
state: Optional[TaskStatus] = None, # Backwards compat alias
|
|
242
|
+
limit: int = 100,
|
|
243
|
+
) -> List[Task]:
|
|
244
|
+
"""List tasks with optional filtering."""
|
|
245
|
+
tasks = list(self._tasks.values())
|
|
246
|
+
filter_status = status or state
|
|
247
|
+
|
|
248
|
+
if session_id:
|
|
249
|
+
tasks = [t for t in tasks if t.session_id == session_id]
|
|
250
|
+
|
|
251
|
+
if filter_status:
|
|
252
|
+
tasks = [t for t in tasks if t.status == filter_status]
|
|
253
|
+
|
|
254
|
+
# Sort by created_at descending
|
|
255
|
+
tasks.sort(key=lambda t: t.created_at, reverse=True)
|
|
256
|
+
|
|
257
|
+
return tasks[:limit]
|
|
258
|
+
|
|
259
|
+
def _cleanup_old_tasks(self) -> None:
|
|
260
|
+
"""Remove old completed/failed tasks."""
|
|
261
|
+
now = time.time()
|
|
262
|
+
to_remove = []
|
|
263
|
+
|
|
264
|
+
for task_id, task in self._tasks.items():
|
|
265
|
+
if task.status in (TaskStatus.COMPLETED, TaskStatus.FAILED, TaskStatus.CANCELLED):
|
|
266
|
+
# Parse ISO timestamp to compare
|
|
267
|
+
try:
|
|
268
|
+
from datetime import datetime
|
|
269
|
+
updated = datetime.fromisoformat(task.last_updated_at.replace("Z", "+00:00"))
|
|
270
|
+
age = now - updated.timestamp()
|
|
271
|
+
if age > self._ttl:
|
|
272
|
+
to_remove.append(task_id)
|
|
273
|
+
except (ValueError, AttributeError):
|
|
274
|
+
pass
|
|
275
|
+
|
|
276
|
+
for task_id in to_remove:
|
|
277
|
+
del self._tasks[task_id]
|
|
278
|
+
|
|
279
|
+
logger.debug(f"Cleaned up {len(to_remove)} old tasks")
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class TaskManager:
|
|
283
|
+
"""
|
|
284
|
+
MCP Task Manager.
|
|
285
|
+
|
|
286
|
+
Handles task lifecycle and execution.
|
|
287
|
+
"""
|
|
288
|
+
|
|
289
|
+
def __init__(
|
|
290
|
+
self,
|
|
291
|
+
store: Optional[TaskStore] = None,
|
|
292
|
+
executor: Optional[Callable] = None,
|
|
293
|
+
):
|
|
294
|
+
"""
|
|
295
|
+
Initialize task manager.
|
|
296
|
+
|
|
297
|
+
Args:
|
|
298
|
+
store: Task storage (uses in-memory if None)
|
|
299
|
+
executor: Optional async executor for task execution
|
|
300
|
+
"""
|
|
301
|
+
self._store = store or TaskStore()
|
|
302
|
+
self._executor = executor
|
|
303
|
+
self._running_tasks: Dict[str, asyncio.Task] = {}
|
|
304
|
+
|
|
305
|
+
async def create_task(
|
|
306
|
+
self,
|
|
307
|
+
method: str,
|
|
308
|
+
params: Dict[str, Any],
|
|
309
|
+
session_id: Optional[str] = None,
|
|
310
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
311
|
+
execute: bool = True,
|
|
312
|
+
) -> Task:
|
|
313
|
+
"""
|
|
314
|
+
Create and optionally start executing a task.
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
method: Method name for the task
|
|
318
|
+
params: Task parameters
|
|
319
|
+
session_id: Optional session ID
|
|
320
|
+
metadata: Optional metadata
|
|
321
|
+
execute: Whether to start execution immediately
|
|
322
|
+
|
|
323
|
+
Returns:
|
|
324
|
+
Created task
|
|
325
|
+
"""
|
|
326
|
+
task = self._store.create(method, params, session_id, metadata)
|
|
327
|
+
|
|
328
|
+
if execute and self._executor:
|
|
329
|
+
# Start async execution
|
|
330
|
+
asyncio_task = asyncio.create_task(
|
|
331
|
+
self._execute_task(task.id)
|
|
332
|
+
)
|
|
333
|
+
self._running_tasks[task.id] = asyncio_task
|
|
334
|
+
|
|
335
|
+
return task
|
|
336
|
+
|
|
337
|
+
async def _execute_task(self, task_id: str) -> None:
|
|
338
|
+
"""Execute a task asynchronously."""
|
|
339
|
+
task = self._store.get(task_id)
|
|
340
|
+
if not task:
|
|
341
|
+
return
|
|
342
|
+
|
|
343
|
+
try:
|
|
344
|
+
# Update to working
|
|
345
|
+
self._store.update(
|
|
346
|
+
task_id,
|
|
347
|
+
status=TaskStatus.WORKING,
|
|
348
|
+
status_message="The operation is now in progress.",
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
# Execute
|
|
352
|
+
if self._executor:
|
|
353
|
+
result = await self._executor(task.method, task.params)
|
|
354
|
+
self._store.update(
|
|
355
|
+
task_id,
|
|
356
|
+
status=TaskStatus.COMPLETED,
|
|
357
|
+
status_message="The operation completed successfully.",
|
|
358
|
+
result=result,
|
|
359
|
+
)
|
|
360
|
+
else:
|
|
361
|
+
self._store.update(
|
|
362
|
+
task_id,
|
|
363
|
+
status=TaskStatus.FAILED,
|
|
364
|
+
error={"code": -32603, "message": "No executor configured"},
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
except asyncio.CancelledError:
|
|
368
|
+
self._store.update(
|
|
369
|
+
task_id,
|
|
370
|
+
status=TaskStatus.CANCELLED,
|
|
371
|
+
status_message="The task was cancelled.",
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
except Exception as e:
|
|
375
|
+
logger.exception(f"Task execution failed: {task_id}")
|
|
376
|
+
self._store.update(
|
|
377
|
+
task_id,
|
|
378
|
+
status=TaskStatus.FAILED,
|
|
379
|
+
status_message=f"Task failed: {str(e)}",
|
|
380
|
+
error={"code": -32603, "message": str(e)},
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
finally:
|
|
384
|
+
if task_id in self._running_tasks:
|
|
385
|
+
del self._running_tasks[task_id]
|
|
386
|
+
|
|
387
|
+
def get_task(self, task_id: str) -> Optional[Task]:
|
|
388
|
+
"""Get a task by ID."""
|
|
389
|
+
return self._store.get(task_id)
|
|
390
|
+
|
|
391
|
+
def update_progress(
|
|
392
|
+
self,
|
|
393
|
+
task_id: str,
|
|
394
|
+
current: float,
|
|
395
|
+
total: Optional[float] = None,
|
|
396
|
+
message: Optional[str] = None,
|
|
397
|
+
) -> Optional[Task]:
|
|
398
|
+
"""Update task progress."""
|
|
399
|
+
progress = TaskProgress(current=current, total=total, message=message)
|
|
400
|
+
return self._store.update(task_id, progress=progress)
|
|
401
|
+
|
|
402
|
+
async def cancel_task(self, task_id: str) -> Optional[Task]:
|
|
403
|
+
"""Cancel a task."""
|
|
404
|
+
# Cancel running asyncio task if exists
|
|
405
|
+
if task_id in self._running_tasks:
|
|
406
|
+
self._running_tasks[task_id].cancel()
|
|
407
|
+
try:
|
|
408
|
+
await self._running_tasks[task_id]
|
|
409
|
+
except asyncio.CancelledError:
|
|
410
|
+
pass
|
|
411
|
+
|
|
412
|
+
return self._store.cancel(task_id)
|
|
413
|
+
|
|
414
|
+
def list_tasks(
|
|
415
|
+
self,
|
|
416
|
+
session_id: Optional[str] = None,
|
|
417
|
+
state: Optional[TaskState] = None,
|
|
418
|
+
limit: int = 100,
|
|
419
|
+
) -> List[Task]:
|
|
420
|
+
"""List tasks."""
|
|
421
|
+
return self._store.list_tasks(session_id, state, limit)
|
|
422
|
+
|
|
423
|
+
def delete_task(self, task_id: str) -> bool:
|
|
424
|
+
"""Delete a task."""
|
|
425
|
+
return self._store.delete(task_id)
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
# Global task manager instance
|
|
429
|
+
_task_manager: Optional[TaskManager] = None
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def get_task_manager() -> TaskManager:
|
|
433
|
+
"""Get the global task manager."""
|
|
434
|
+
global _task_manager
|
|
435
|
+
if _task_manager is None:
|
|
436
|
+
_task_manager = TaskManager()
|
|
437
|
+
return _task_manager
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def set_task_manager(manager: TaskManager) -> None:
|
|
441
|
+
"""Set the global task manager."""
|
|
442
|
+
global _task_manager
|
|
443
|
+
_task_manager = manager
|