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,1527 @@
|
|
|
1
|
+
import { on, emit, setText, fetchJSON, escapeHtml, formatCost, sessionState, logger, ExponentialBackoff } from '/static/js/ui-utils.js?v=5';
|
|
2
|
+
import { updateSessionInfo } from '/static/js/sidebar-data.js?v=5';
|
|
3
|
+
import { loadStats } from '/static/js/stats.js?v=5';
|
|
4
|
+
import { loadScreenshot } from '/static/js/screenshot.js?v=5';
|
|
5
|
+
import { eventStore } from '/static/js/event-store.js?v=5';
|
|
6
|
+
import { feedFilter } from '/static/js/event-filter.js?v=5';
|
|
7
|
+
|
|
8
|
+
// Initialize session state from DOM
|
|
9
|
+
sessionState.init();
|
|
10
|
+
|
|
11
|
+
// Create socketReady promise for backwards compatibility with chat.js
|
|
12
|
+
window.socketReadyResolve = null;
|
|
13
|
+
window.socketReady = new Promise((resolve) => {
|
|
14
|
+
window.socketReadyResolve = resolve;
|
|
15
|
+
});
|
|
16
|
+
logger.debug('[Session] socketReady promise created');
|
|
17
|
+
|
|
18
|
+
// Listen for tab activation events
|
|
19
|
+
on('tab:activated', (event) => {
|
|
20
|
+
const tabId = event.detail.tabId;
|
|
21
|
+
|
|
22
|
+
// If the feed tab is activated, scroll to the top of the feed (newest first)
|
|
23
|
+
if (tabId === 'feed-tab') {
|
|
24
|
+
const feedContainer = document.getElementById('feed-container');
|
|
25
|
+
if (feedContainer) {
|
|
26
|
+
feedContainer.scrollTop = 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Socket initialization state - using mutex pattern to prevent race conditions
|
|
32
|
+
let socketInitialized = false;
|
|
33
|
+
let socketInitializing = false;
|
|
34
|
+
let socketInitLock = Promise.resolve(); // Mutex lock for initialization
|
|
35
|
+
|
|
36
|
+
// Create a function to initialize the socket so we can call it when ready
|
|
37
|
+
// Uses mutex pattern to prevent race conditions
|
|
38
|
+
async function initializeSocket(io) {
|
|
39
|
+
// Acquire lock - wait for any pending initialization
|
|
40
|
+
const previousLock = socketInitLock;
|
|
41
|
+
let releaseLock;
|
|
42
|
+
socketInitLock = new Promise(resolve => { releaseLock = resolve; });
|
|
43
|
+
await previousLock;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
// Guard against multiple initializations (double-check after acquiring lock)
|
|
47
|
+
if (socketInitialized) {
|
|
48
|
+
logger.debug('[Session] Socket already initialized');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (socketInitializing) {
|
|
53
|
+
logger.debug('[Session] Socket initialization already in progress');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Check if io is properly initialized
|
|
58
|
+
if (!io) {
|
|
59
|
+
logger.error('[Session] Socket.IO not loaded correctly');
|
|
60
|
+
const refreshText = document.getElementById('refresh-text');
|
|
61
|
+
if (refreshText) refreshText.textContent = 'Connection failed - Socket.IO not loaded';
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Use centralized session state
|
|
66
|
+
const currentSessionId = sessionState.sessionId;
|
|
67
|
+
const isNew = sessionState.isNew;
|
|
68
|
+
|
|
69
|
+
// Don't initialize socket for new sessions (empty state)
|
|
70
|
+
if (!currentSessionId || isNew) {
|
|
71
|
+
logger.debug('[Session] Skipping socket initialization - no active session yet');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Mark as initializing
|
|
76
|
+
socketInitializing = true;
|
|
77
|
+
|
|
78
|
+
// Store sessionId in closure for use in handlers
|
|
79
|
+
const sessionId = currentSessionId;
|
|
80
|
+
|
|
81
|
+
// Use the centralized WS_BASE from constants.js
|
|
82
|
+
const socket = io(window.WS_BASE, {
|
|
83
|
+
path: '/socket.io',
|
|
84
|
+
transports: ['polling', 'websocket'], // Use polling first, then upgrade to WebSocket
|
|
85
|
+
reconnection: true,
|
|
86
|
+
reconnectionAttempts: 10,
|
|
87
|
+
reconnectionDelay: 1000,
|
|
88
|
+
reconnectionDelayMax: 30000,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Expose socket globally for chat.js to access
|
|
92
|
+
window.socket = socket;
|
|
93
|
+
logger.debug('[Session] Socket created and exposed as window.socket');
|
|
94
|
+
|
|
95
|
+
// Connection state for UI feedback
|
|
96
|
+
let connectionBackoff = new ExponentialBackoff({ maxRetries: 10 });
|
|
97
|
+
|
|
98
|
+
// FeedRenderer - subscribes to EventStore and renders to DOM
|
|
99
|
+
// Defer creation until DOM is ready
|
|
100
|
+
let feedRenderer = null;
|
|
101
|
+
function ensureFeedRenderer() {
|
|
102
|
+
if (!feedRenderer) {
|
|
103
|
+
feedRenderer = createFeedRenderer('feed-container');
|
|
104
|
+
}
|
|
105
|
+
return feedRenderer;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Create renderer when DOM is ready
|
|
109
|
+
if (document.readyState === 'loading') {
|
|
110
|
+
document.addEventListener('DOMContentLoaded', ensureFeedRenderer);
|
|
111
|
+
} else {
|
|
112
|
+
ensureFeedRenderer();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
socket.on('connect', () => {
|
|
116
|
+
logger.info('[Session] WebSocket connected');
|
|
117
|
+
logger.debug('[Session] Emitting join_session for:', sessionId);
|
|
118
|
+
socket.emit('join_session', { session_id: sessionId });
|
|
119
|
+
|
|
120
|
+
// Mark socket as fully initialized
|
|
121
|
+
socketInitialized = true;
|
|
122
|
+
socketInitializing = false;
|
|
123
|
+
connectionBackoff.reset();
|
|
124
|
+
|
|
125
|
+
// Resolve the socketReady promise so chat.js can initialize
|
|
126
|
+
if (window.socketReadyResolve) {
|
|
127
|
+
window.socketReadyResolve(socket);
|
|
128
|
+
logger.debug('[Session] ✅ Socket ready promise resolved');
|
|
129
|
+
} else {
|
|
130
|
+
logger.warn('[Session] ⚠️ window.socketReadyResolve not found');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Update UI to show connected state
|
|
134
|
+
setText('refresh-text', 'Live updates active');
|
|
135
|
+
updateConnectionStatus('connected');
|
|
136
|
+
|
|
137
|
+
// Emit connection event for other modules
|
|
138
|
+
emit('socket:connected', { sessionId });
|
|
139
|
+
|
|
140
|
+
logger.debug('[Session] ✅ WebSocket setup complete, waiting for events...');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Handle initial feed from server - use EventStore for storage and ordering
|
|
144
|
+
socket.on('initial_feed', async (payload) => {
|
|
145
|
+
logger.debug('[Session] Received initial_feed, payload length=', payload?.length);
|
|
146
|
+
try {
|
|
147
|
+
// Clear loading indicator
|
|
148
|
+
const loadingEl = document.getElementById('feed-loading');
|
|
149
|
+
if (loadingEl) loadingEl.style.display = 'none';
|
|
150
|
+
|
|
151
|
+
const items = JSON.parse(payload);
|
|
152
|
+
logger.debug(`[Session] Parsed initial_feed with ${items.length} events`);
|
|
153
|
+
|
|
154
|
+
// Insert batch into EventStore (handles ordering and dedup)
|
|
155
|
+
const inserted = eventStore.insertBatch(items);
|
|
156
|
+
logger.info(`[Session] EventStore: inserted ${inserted.length}/${items.length} events`);
|
|
157
|
+
|
|
158
|
+
// Refresh sidebar after initial load
|
|
159
|
+
try {
|
|
160
|
+
const { refreshSidebar } = await import('./sidebar-data.js');
|
|
161
|
+
refreshSidebar('all', true);
|
|
162
|
+
emit('stats:refreshRequest');
|
|
163
|
+
} catch (sidebarErr) {
|
|
164
|
+
logger.warn('[Session] Sidebar refresh error:', sidebarErr.message);
|
|
165
|
+
}
|
|
166
|
+
} catch (err) {
|
|
167
|
+
logger.error('[Session] Failed to parse initial feed:', err);
|
|
168
|
+
showFeedError('Failed to load feed data. Please try refreshing the page.');
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Handle chunked feed (backwards compatibility) - combine into single batch
|
|
173
|
+
let chunkBuffer = { chunks: [], expected: 0 };
|
|
174
|
+
|
|
175
|
+
socket.on('initial_feed_chunk', async (chunkData) => {
|
|
176
|
+
logger.debug('[Session] Received initial_feed_chunk, index=', chunkData.chunk_index, 'of', chunkData.total_chunks);
|
|
177
|
+
try {
|
|
178
|
+
// Clear loading indicator on first chunk
|
|
179
|
+
if (chunkData.chunk_index === 0) {
|
|
180
|
+
const loadingEl = document.getElementById('feed-loading');
|
|
181
|
+
if (loadingEl) loadingEl.style.display = 'none';
|
|
182
|
+
chunkBuffer = { chunks: [], expected: chunkData.total_chunks };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
chunkBuffer.chunks[chunkData.chunk_index] = chunkData.chunk;
|
|
186
|
+
logger.debug(`[Session] Chunk ${chunkData.chunk_index + 1}/${chunkData.total_chunks}`);
|
|
187
|
+
|
|
188
|
+
// Process when all chunks received
|
|
189
|
+
if (chunkData.is_last) {
|
|
190
|
+
const allItems = chunkBuffer.chunks.flat();
|
|
191
|
+
const inserted = eventStore.insertBatch(allItems);
|
|
192
|
+
logger.info(`[Session] EventStore: inserted ${inserted.length}/${allItems.length} from chunks`);
|
|
193
|
+
chunkBuffer = { chunks: [], expected: 0 };
|
|
194
|
+
|
|
195
|
+
// Refresh sidebar
|
|
196
|
+
try {
|
|
197
|
+
const { refreshSidebar } = await import('./sidebar-data.js');
|
|
198
|
+
refreshSidebar('all', true);
|
|
199
|
+
emit('stats:refreshRequest');
|
|
200
|
+
} catch (sidebarErr) {
|
|
201
|
+
logger.warn('[Session] Sidebar refresh error:', sidebarErr.message);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} catch (err) {
|
|
205
|
+
logger.error('[Session] Failed to process chunk:', err);
|
|
206
|
+
chunkBuffer = { chunks: [], expected: 0 };
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
socket.on('feed_update', (item) => {
|
|
211
|
+
logger.debug('[Feed] 📨 Received feed_update:', item.type, '_seq=', item._seq);
|
|
212
|
+
|
|
213
|
+
// Insert into EventStore (handles dedup and ordering)
|
|
214
|
+
// Chat.js subscribes to EventStore directly - no separate event bus needed
|
|
215
|
+
const inserted = eventStore.insert(item);
|
|
216
|
+
if (inserted) {
|
|
217
|
+
// Update sidebar based on event type
|
|
218
|
+
handleSidebarUpdates(item);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
socket.on('disconnect', (reason) => {
|
|
223
|
+
logger.warn('[Session] WebSocket disconnected:', reason);
|
|
224
|
+
|
|
225
|
+
// Reset state to allow reconnection
|
|
226
|
+
socketInitialized = false;
|
|
227
|
+
socketInitializing = false;
|
|
228
|
+
|
|
229
|
+
setText('refresh-text', 'Connection lost');
|
|
230
|
+
updateConnectionStatus('disconnected');
|
|
231
|
+
|
|
232
|
+
// Emit disconnect event for other modules
|
|
233
|
+
emit('socket:disconnected', { reason });
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
socket.on('reconnect_attempt', (attemptNumber) => {
|
|
237
|
+
logger.debug(`[Session] Reconnection attempt ${attemptNumber}`);
|
|
238
|
+
setText('refresh-text', `Reconnecting... (${attemptNumber})`);
|
|
239
|
+
updateConnectionStatus('reconnecting');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
socket.on('reconnect', async (attemptNumber) => {
|
|
243
|
+
logger.info(`[Session] Reconnected after ${attemptNumber} attempts`);
|
|
244
|
+
setText('refresh-text', 'Live updates active');
|
|
245
|
+
updateConnectionStatus('connected');
|
|
246
|
+
connectionBackoff.reset();
|
|
247
|
+
|
|
248
|
+
// Re-join the session room
|
|
249
|
+
socket.emit('join_session', { session_id: sessionId });
|
|
250
|
+
|
|
251
|
+
// Delta sync: fetch only events we missed during disconnection
|
|
252
|
+
const lastSeq = eventStore.getLastSeq();
|
|
253
|
+
if (lastSeq > 0) {
|
|
254
|
+
try {
|
|
255
|
+
logger.debug(`[Session] Delta sync: fetching events after _seq=${lastSeq}`);
|
|
256
|
+
const response = await fetch(`/api/session/${sessionId}/feed/events?after_seq=${lastSeq}&limit=500`);
|
|
257
|
+
if (response.ok) {
|
|
258
|
+
const data = await response.json();
|
|
259
|
+
const events = data.events || [];
|
|
260
|
+
if (events.length > 0) {
|
|
261
|
+
const inserted = eventStore.insertBatch(events);
|
|
262
|
+
logger.info(`[Session] Delta sync: inserted ${inserted.length} missed events`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
} catch (err) {
|
|
266
|
+
logger.warn('[Session] Delta sync failed:', err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
emit('socket:reconnected', { attemptNumber });
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
socket.on('reconnect_failed', () => {
|
|
274
|
+
logger.error('[Session] Reconnection failed after all attempts');
|
|
275
|
+
setText('refresh-text', 'Connection lost - please refresh');
|
|
276
|
+
updateConnectionStatus('disconnected');
|
|
277
|
+
emit('socket:reconnectFailed', {});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Helper to update connection status indicator
|
|
281
|
+
function updateConnectionStatus(status) {
|
|
282
|
+
const indicator = document.getElementById('connection-status');
|
|
283
|
+
if (indicator) {
|
|
284
|
+
indicator.className = `connection-status ${status}`;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* FeedRenderer - Renders events from EventStore to DOM
|
|
290
|
+
* Subscribes to EventStore changes and renders filtered events.
|
|
291
|
+
*/
|
|
292
|
+
function createFeedRenderer(containerId) {
|
|
293
|
+
logger.debug('[FeedRenderer] Creating renderer for container:', containerId);
|
|
294
|
+
const container = document.getElementById(containerId);
|
|
295
|
+
if (!container) {
|
|
296
|
+
logger.warn('[FeedRenderer] Container not found:', containerId);
|
|
297
|
+
return { render: () => {}, clear: () => {}, destroy: () => {} };
|
|
298
|
+
}
|
|
299
|
+
logger.debug('[FeedRenderer] Container found:', containerId);
|
|
300
|
+
|
|
301
|
+
// Track rendered event IDs to avoid re-rendering
|
|
302
|
+
const renderedIds = new Set();
|
|
303
|
+
|
|
304
|
+
// Subscribe to EventStore changes - save unsubscribe for cleanup
|
|
305
|
+
const unsubscribe = eventStore.subscribe('all', (change) => {
|
|
306
|
+
if (change.action === 'insert') {
|
|
307
|
+
renderEvent(change.event);
|
|
308
|
+
} else if (change.action === 'batch') {
|
|
309
|
+
renderBatch(change.events);
|
|
310
|
+
} else if (change.action === 'clear') {
|
|
311
|
+
clear();
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// Render any existing events (handles race condition where events loaded before subscription)
|
|
316
|
+
const existingEvents = eventStore.getAll();
|
|
317
|
+
if (existingEvents.length > 0) {
|
|
318
|
+
logger.debug(`[FeedRenderer] Rendering ${existingEvents.length} existing events`);
|
|
319
|
+
renderBatch(existingEvents);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function renderEvent(event) {
|
|
323
|
+
if (!feedFilter.shouldShow(event)) return;
|
|
324
|
+
|
|
325
|
+
const eventId = event._id || `${event.type}_${event.timestamp}`;
|
|
326
|
+
if (renderedIds.has(eventId)) return;
|
|
327
|
+
renderedIds.add(eventId);
|
|
328
|
+
|
|
329
|
+
const itemEl = document.createElement('div');
|
|
330
|
+
itemEl.className = 'feed-item';
|
|
331
|
+
itemEl.innerHTML = formatFeedItem(event);
|
|
332
|
+
itemEl.dataset.seq = event._seq || 0;
|
|
333
|
+
itemEl.dataset.id = eventId;
|
|
334
|
+
|
|
335
|
+
if (event.type === 'llm_request') {
|
|
336
|
+
itemEl.classList.add('feed-llm-item');
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Insert in correct position by _seq (newest first = prepend)
|
|
340
|
+
insertBySeq(itemEl, event._seq || 0);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function renderBatch(events) {
|
|
344
|
+
const toRender = events.filter(e => {
|
|
345
|
+
if (!feedFilter.shouldShow(e)) return false;
|
|
346
|
+
const eventId = e._id || `${e.type}_${e.timestamp}`;
|
|
347
|
+
if (renderedIds.has(eventId)) return false;
|
|
348
|
+
renderedIds.add(eventId);
|
|
349
|
+
return true;
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
if (toRender.length === 0) return;
|
|
353
|
+
|
|
354
|
+
// Sort by _seq descending (newest first)
|
|
355
|
+
toRender.sort((a, b) => (b._seq || 0) - (a._seq || 0));
|
|
356
|
+
|
|
357
|
+
const fragment = document.createDocumentFragment();
|
|
358
|
+
toRender.forEach(event => {
|
|
359
|
+
const itemEl = document.createElement('div');
|
|
360
|
+
itemEl.className = 'feed-item';
|
|
361
|
+
itemEl.innerHTML = formatFeedItem(event);
|
|
362
|
+
itemEl.dataset.seq = event._seq || 0;
|
|
363
|
+
itemEl.dataset.id = event._id || '';
|
|
364
|
+
|
|
365
|
+
if (event.type === 'llm_request') {
|
|
366
|
+
itemEl.classList.add('feed-llm-item');
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
fragment.appendChild(itemEl);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// Prepend all (newest first)
|
|
373
|
+
container.insertBefore(fragment, container.firstChild);
|
|
374
|
+
logger.debug(`[FeedRenderer] Rendered ${toRender.length} events`);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function insertBySeq(itemEl, seq) {
|
|
378
|
+
// For real-time updates, insert at correct position
|
|
379
|
+
// Events are displayed newest first (descending _seq)
|
|
380
|
+
const children = Array.from(container.children);
|
|
381
|
+
|
|
382
|
+
for (let i = 0; i < children.length; i++) {
|
|
383
|
+
const childSeq = parseInt(children[i].dataset.seq || '0', 10);
|
|
384
|
+
if (seq > childSeq) {
|
|
385
|
+
container.insertBefore(itemEl, children[i]);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Oldest event, append at end
|
|
391
|
+
container.appendChild(itemEl);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function clear() {
|
|
395
|
+
container.innerHTML = '';
|
|
396
|
+
renderedIds.clear();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function destroy() {
|
|
400
|
+
unsubscribe();
|
|
401
|
+
clear();
|
|
402
|
+
logger.debug('[FeedRenderer] Destroyed');
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return { render: renderEvent, renderBatch, clear, destroy };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function formatFeedItem(item) {
|
|
409
|
+
// Default formatting for unknown types
|
|
410
|
+
if (!item || !item.type) {
|
|
411
|
+
return `<pre class="feed-content">${escapeHtml(JSON.stringify(item, null, 2))}</pre>`;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Format timestamp if available
|
|
415
|
+
const timestamp = item.timestamp
|
|
416
|
+
? new Date(item.timestamp * 1000).toLocaleTimeString()
|
|
417
|
+
: '';
|
|
418
|
+
|
|
419
|
+
// Get icon and color based on type
|
|
420
|
+
const typeInfo = getEventTypeInfo(item.type);
|
|
421
|
+
|
|
422
|
+
let content = '';
|
|
423
|
+
|
|
424
|
+
// Format content based on event type
|
|
425
|
+
switch (item.type) {
|
|
426
|
+
case 'step': {
|
|
427
|
+
const stepNum = item.step || 0;
|
|
428
|
+
const actions = item.data?.actions || [];
|
|
429
|
+
|
|
430
|
+
// Improved agent name extraction with more fallbacks
|
|
431
|
+
let agentName = null;
|
|
432
|
+
|
|
433
|
+
// First try in data.agent_name (main and preferred source)
|
|
434
|
+
if (item.data?.agent_name && item.data.agent_name !== 'Unknown') {
|
|
435
|
+
agentName = item.data.agent_name;
|
|
436
|
+
}
|
|
437
|
+
// Then try item.agent_name (older format)
|
|
438
|
+
else if (item.agent_name) {
|
|
439
|
+
agentName = item.agent_name;
|
|
440
|
+
}
|
|
441
|
+
// Then try item.data.name
|
|
442
|
+
else if (item.data?.name) {
|
|
443
|
+
agentName = item.data.name;
|
|
444
|
+
}
|
|
445
|
+
// Last fallback - try to extract from agent_id if available
|
|
446
|
+
else if (item.data?.agent_id) {
|
|
447
|
+
const agentId = item.data.agent_id;
|
|
448
|
+
// Extract prefix from format like "planner_xyz123"
|
|
449
|
+
if (agentId.includes('_')) {
|
|
450
|
+
const prefix = agentId.split('_')[0];
|
|
451
|
+
// Capitalize first letter for display
|
|
452
|
+
agentName = prefix.charAt(0).toUpperCase() + prefix.slice(1);
|
|
453
|
+
} else {
|
|
454
|
+
agentName = agentId; // Use entire ID if no underscore
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Final fallback
|
|
459
|
+
if (!agentName) {
|
|
460
|
+
agentName = 'Agent';
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
logger.debug(`Step ${stepNum} agent: "${agentName}"`);
|
|
464
|
+
|
|
465
|
+
// Detect next goal (preferred) or fallback to generic progress
|
|
466
|
+
const nextGoal = item.data?.next_goal || item.data?.task_progress || '';
|
|
467
|
+
|
|
468
|
+
// Extract error information if available
|
|
469
|
+
const errors = item.data?.errors || [];
|
|
470
|
+
const hasErrors = errors && errors.length > 0;
|
|
471
|
+
|
|
472
|
+
// Build header: "Step N – Agent"
|
|
473
|
+
const headerTitle = `Step ${stepNum} – ${agentName}`;
|
|
474
|
+
|
|
475
|
+
// Compact actions summary for step feed items
|
|
476
|
+
const actionsCountByService = {};
|
|
477
|
+
actions.forEach(action => {
|
|
478
|
+
const service = detectServiceFromAction(action);
|
|
479
|
+
actionsCountByService[service] = (actionsCountByService[service] || 0) + 1;
|
|
480
|
+
});
|
|
481
|
+
const actionsSummary = Object.entries(actionsCountByService)
|
|
482
|
+
.map(([service, count]) => `${service}(${count})`)
|
|
483
|
+
.join(', ');
|
|
484
|
+
|
|
485
|
+
content = `
|
|
486
|
+
<div class="feed-header">
|
|
487
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> ${headerTitle}</span>
|
|
488
|
+
<span class="feed-time">${timestamp}</span>
|
|
489
|
+
</div>
|
|
490
|
+
<div class="feed-content compact">
|
|
491
|
+
${nextGoal ? `<div class="event-next-goal">${escapeHtml(nextGoal)}</div>` : ''}
|
|
492
|
+
${hasErrors ? `
|
|
493
|
+
<div class="event-error">
|
|
494
|
+
<div class="event-error-header">Errors:</div>
|
|
495
|
+
<div class="event-error-content">
|
|
496
|
+
${errors.map(error => `<div class="event-error-item">${escapeHtml(error)}</div>`).join('')}
|
|
497
|
+
</div>
|
|
498
|
+
</div>
|
|
499
|
+
` : ''}
|
|
500
|
+
${actionsSummary ? `<div class="event-actions-summary">${actionsSummary}</div>` : ''}
|
|
501
|
+
</div>
|
|
502
|
+
`;
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
case 'planner':
|
|
507
|
+
content = `
|
|
508
|
+
<div class="feed-header">
|
|
509
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> Planner</span>
|
|
510
|
+
<span class="feed-time">${timestamp}</span>
|
|
511
|
+
</div>
|
|
512
|
+
<div class="feed-content">
|
|
513
|
+
<div class="event-step">Step ${item.step || 0}</div>
|
|
514
|
+
<div class="event-model">${item.data?.model_name || 'Unknown model'}</div>
|
|
515
|
+
${formatPlannerComponents(item.data?.components || {})}
|
|
516
|
+
</div>
|
|
517
|
+
`;
|
|
518
|
+
break;
|
|
519
|
+
|
|
520
|
+
case 'evaluation':
|
|
521
|
+
content = `
|
|
522
|
+
<div class="feed-header">
|
|
523
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> Evaluation</span>
|
|
524
|
+
<span class="feed-time">${timestamp}</span>
|
|
525
|
+
</div>
|
|
526
|
+
<div class="feed-content">
|
|
527
|
+
<div class="event-step">Step ${item.step || 0}</div>
|
|
528
|
+
<div class="event-assessment">${item.data?.assessment || 'No assessment'}</div>
|
|
529
|
+
${formatEvaluationDetails(item.data || {})}
|
|
530
|
+
</div>
|
|
531
|
+
`;
|
|
532
|
+
break;
|
|
533
|
+
|
|
534
|
+
case 'tool_execution': {
|
|
535
|
+
const toolName = item.data?.tool_name || 'unknown';
|
|
536
|
+
const actionName = item.data?.action_name || 'unknown';
|
|
537
|
+
const success = item.data?.success !== false;
|
|
538
|
+
const duration = item.data?.duration_seconds || 0;
|
|
539
|
+
const parameters = item.data?.parameters || {};
|
|
540
|
+
const error = item.data?.error;
|
|
541
|
+
|
|
542
|
+
// Format parameters for display (compact)
|
|
543
|
+
const paramsList = Object.entries(parameters)
|
|
544
|
+
.filter(([key, val]) => val !== null && val !== undefined)
|
|
545
|
+
.map(([key, val]) => {
|
|
546
|
+
const valStr = typeof val === 'string' ? val : JSON.stringify(val);
|
|
547
|
+
const truncated = valStr.length > 100 ? valStr.substring(0, 100) + '...' : valStr;
|
|
548
|
+
return `${key}=${truncated}`;
|
|
549
|
+
})
|
|
550
|
+
.join(', ');
|
|
551
|
+
|
|
552
|
+
const statusIcon = success ? '✓' : '✗';
|
|
553
|
+
const statusClass = success ? 'success' : 'error';
|
|
554
|
+
|
|
555
|
+
content = `
|
|
556
|
+
<div class="feed-header">
|
|
557
|
+
<span class="feed-type">
|
|
558
|
+
<span class="event-icon">${typeInfo.icon}</span>
|
|
559
|
+
<span class="tool-badge">${toolName}</span> → ${actionName}
|
|
560
|
+
<span class="status-${statusClass}">${statusIcon}</span>
|
|
561
|
+
</span>
|
|
562
|
+
<span class="feed-time">${timestamp} (${duration.toFixed(2)}s)</span>
|
|
563
|
+
</div>
|
|
564
|
+
${paramsList ? `<div class="feed-content compact">
|
|
565
|
+
<div class="event-parameters">📋 ${escapeHtml(paramsList)}</div>
|
|
566
|
+
</div>` : ''}
|
|
567
|
+
${error ? `<div class="feed-content compact">
|
|
568
|
+
<div class="event-error">❌ ${escapeHtml(error)}</div>
|
|
569
|
+
</div>` : ''}
|
|
570
|
+
`;
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
case 'llm_request': {
|
|
575
|
+
const tokenCount = item.data?.token_count || 0;
|
|
576
|
+
const costEstimate = item.data?.cost_estimate || 0;
|
|
577
|
+
|
|
578
|
+
// Determine model name with provider prefix if available
|
|
579
|
+
let modelName = item.data?.model_name || item.data?.model || 'unknown';
|
|
580
|
+
const provider = item.data?.provider || '';
|
|
581
|
+
if (provider && !modelName.toLowerCase().includes(provider.toLowerCase())) {
|
|
582
|
+
modelName = `${provider} ${modelName}`;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
const summary = `LLM Request ${modelName} Tokens: ${tokenCount.toLocaleString()} Cost: ${formatCost(costEstimate)}`;
|
|
586
|
+
|
|
587
|
+
// Single-line minimal block
|
|
588
|
+
content = `
|
|
589
|
+
<div class="feed-header feed-llm-line">
|
|
590
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> ${escapeHtml(summary)}</span>
|
|
591
|
+
<span class="feed-time">${timestamp}</span>
|
|
592
|
+
</div>
|
|
593
|
+
`;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
case 'status':
|
|
598
|
+
content = `
|
|
599
|
+
<div class="feed-header">
|
|
600
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> Status Update</span>
|
|
601
|
+
<span class="feed-time">${timestamp}</span>
|
|
602
|
+
</div>
|
|
603
|
+
<div class="feed-content">
|
|
604
|
+
<div class="event-status-value">Status: <span class="status-${item.data?.status || 'unknown'}">${item.data?.status || 'Unknown'}</span></div>
|
|
605
|
+
${item.data?.previous_status ? `<div class="event-previous-status">Previous: ${item.data.previous_status}</div>` : ''}
|
|
606
|
+
</div>
|
|
607
|
+
`;
|
|
608
|
+
break;
|
|
609
|
+
|
|
610
|
+
case 'task_update':
|
|
611
|
+
content = `
|
|
612
|
+
<div class="feed-header">
|
|
613
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> Task Update</span>
|
|
614
|
+
<span class="feed-time">${timestamp}</span>
|
|
615
|
+
</div>
|
|
616
|
+
<div class="feed-content">
|
|
617
|
+
<div class="event-task">${item.data?.task || 'Unknown task'}</div>
|
|
618
|
+
<div class="event-status-value">Status: ${item.data?.status || 'Unknown'}</div>
|
|
619
|
+
</div>
|
|
620
|
+
`;
|
|
621
|
+
break;
|
|
622
|
+
|
|
623
|
+
case 'agent_registration':
|
|
624
|
+
content = `
|
|
625
|
+
<div class="feed-header">
|
|
626
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> Agent Registration</span>
|
|
627
|
+
<span class="feed-time">${timestamp}</span>
|
|
628
|
+
</div>
|
|
629
|
+
<div class="feed-content">
|
|
630
|
+
<div class="event-agent-id">${item.data?.id || item.data?.agent_id || 'Unknown ID'}</div>
|
|
631
|
+
<div class="event-agent-name">${item.data?.name || item.data?.agent_name || 'Unknown agent'}</div>
|
|
632
|
+
<div class="event-agent-type">${item.data?.type || item.data?.agent_type || 'Unknown type'}</div>
|
|
633
|
+
</div>
|
|
634
|
+
`;
|
|
635
|
+
break;
|
|
636
|
+
|
|
637
|
+
case 'multi_agent_relationship':
|
|
638
|
+
case 'multi_agent_relationship_detailed':
|
|
639
|
+
const data = item.data || {};
|
|
640
|
+
const agentIds = data.agent_ids || data.execution_sequence || [];
|
|
641
|
+
const agentDetails = data.agent_details || [];
|
|
642
|
+
const agentModels = data.agent_models || {};
|
|
643
|
+
|
|
644
|
+
// Create a comprehensive agent list with models
|
|
645
|
+
const agentsWithModels = agentDetails.map(agent => ({
|
|
646
|
+
...agent,
|
|
647
|
+
model: agent.model || agentModels[agent.id || agent.agent_id] || ''
|
|
648
|
+
}));
|
|
649
|
+
|
|
650
|
+
content = `
|
|
651
|
+
<div class="feed-header">
|
|
652
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> Multi-Agent Setup</span>
|
|
653
|
+
<span class="feed-time">${timestamp}</span>
|
|
654
|
+
</div>
|
|
655
|
+
<div class="feed-content">
|
|
656
|
+
<div class="event-agent-count">${agentIds.length} agents in collaboration</div>
|
|
657
|
+
${data.orchestrator_type ? `<div class="event-orchestrator">Orchestrator: ${data.orchestrator_type}</div>` : ''}
|
|
658
|
+
${agentsWithModels.length > 0 ? formatAgentRelationships(agentsWithModels) : ''}
|
|
659
|
+
${agentIds.length > 0 && agentsWithModels.length === 0 ? `
|
|
660
|
+
<div class="event-agents">
|
|
661
|
+
<div class="event-agents-header">Agent IDs:</div>
|
|
662
|
+
<div class="event-agents-list">
|
|
663
|
+
${agentIds.map(id => `<div class="event-agent-id">${id}</div>`).join('')}
|
|
664
|
+
</div>
|
|
665
|
+
</div>
|
|
666
|
+
` : ''}
|
|
667
|
+
</div>
|
|
668
|
+
`;
|
|
669
|
+
break;
|
|
670
|
+
|
|
671
|
+
case 'available_actions':
|
|
672
|
+
const services = item.data?.by_service || {};
|
|
673
|
+
const availableActionsHtml = Object.entries(services).map(([serviceName, actions]) => {
|
|
674
|
+
if (!Array.isArray(actions)) return '';
|
|
675
|
+
return `
|
|
676
|
+
<div class="service-section">
|
|
677
|
+
<div class="service-header">${serviceName}</div>
|
|
678
|
+
<div class="actions-list">
|
|
679
|
+
${actions.map(actionName => `<span class="action-tag" title="${actionName}">${actionName}</span>`).join('')}
|
|
680
|
+
</div>
|
|
681
|
+
</div>`;
|
|
682
|
+
}).join('');
|
|
683
|
+
|
|
684
|
+
content = `
|
|
685
|
+
<div class="feed-header">
|
|
686
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> Available Actions</span>
|
|
687
|
+
<span class="feed-time">${timestamp}</span>
|
|
688
|
+
</div>
|
|
689
|
+
<div class="feed-content">
|
|
690
|
+
${availableActionsHtml || '<div class="empty-state">No actions listed</div>'}
|
|
691
|
+
</div>
|
|
692
|
+
`;
|
|
693
|
+
break;
|
|
694
|
+
|
|
695
|
+
case 'service_actions':
|
|
696
|
+
// Handle service_actions entries without displaying raw JSON
|
|
697
|
+
const serviceInfo = item.data || {};
|
|
698
|
+
|
|
699
|
+
// Extract only essential service information
|
|
700
|
+
const serviceName = serviceInfo.service_name || 'Unknown Service';
|
|
701
|
+
const serviceType = serviceInfo.service_type || '';
|
|
702
|
+
const actionCount = serviceInfo.action_count || 0;
|
|
703
|
+
|
|
704
|
+
// Get only the action names without their full definitions
|
|
705
|
+
const actionsList = Array.isArray(serviceInfo.available_actions)
|
|
706
|
+
? serviceInfo.available_actions
|
|
707
|
+
: [];
|
|
708
|
+
|
|
709
|
+
content = `
|
|
710
|
+
<div class="feed-header">
|
|
711
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> Service Actions</span>
|
|
712
|
+
<span class="feed-time">${timestamp}</span>
|
|
713
|
+
</div>
|
|
714
|
+
<div class="feed-content">
|
|
715
|
+
<div class="service-section">
|
|
716
|
+
<div class="service-header">${serviceName} ${serviceType ? `(${serviceType})` : ''}</div>
|
|
717
|
+
<div class="actions-list">
|
|
718
|
+
${actionsList.map(actionName => `<span class="action-tag" title="${actionName}">${actionName}</span>`).join('')}
|
|
719
|
+
</div>
|
|
720
|
+
</div>
|
|
721
|
+
</div>
|
|
722
|
+
`;
|
|
723
|
+
break;
|
|
724
|
+
|
|
725
|
+
case 'event': {
|
|
726
|
+
// Format generic events to show their payload in a clean way
|
|
727
|
+
content = `
|
|
728
|
+
<div class="feed-header">
|
|
729
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> ${item.data?.event_type || 'Event'}</span>
|
|
730
|
+
<span class="feed-time">${timestamp}</span>
|
|
731
|
+
</div>
|
|
732
|
+
<div class="feed-content">
|
|
733
|
+
<pre class="code-content">${escapeHtml(JSON.stringify(item.data || {}, null, 2))}</pre>
|
|
734
|
+
</div>
|
|
735
|
+
`;
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
case 'agent_message':
|
|
740
|
+
// Agent sent a message to user (via send_message action)
|
|
741
|
+
const isQuestion = item.data?.wait_for_response === true;
|
|
742
|
+
content = `
|
|
743
|
+
<div class="feed-header">
|
|
744
|
+
<span class="feed-type"><span class="event-icon">💬</span> ${isQuestion ? 'Agent Question' : 'Agent Message'}</span>
|
|
745
|
+
<span class="feed-time">${timestamp}</span>
|
|
746
|
+
</div>
|
|
747
|
+
<div class="feed-content agent-message">
|
|
748
|
+
<div class="message-text">${escapeHtml(item.data?.text || '')}</div>
|
|
749
|
+
${isQuestion ? '<div class="message-waiting">⏳ Waiting for your response...</div>' : ''}
|
|
750
|
+
</div>
|
|
751
|
+
`;
|
|
752
|
+
break;
|
|
753
|
+
|
|
754
|
+
case 'task_complete':
|
|
755
|
+
// Task completion message (via done action)
|
|
756
|
+
content = `
|
|
757
|
+
<div class="feed-header">
|
|
758
|
+
<span class="feed-type"><span class="event-icon">✅</span> Task Complete</span>
|
|
759
|
+
<span class="feed-time">${timestamp}</span>
|
|
760
|
+
</div>
|
|
761
|
+
<div class="feed-content task-complete">
|
|
762
|
+
<div class="completion-message">${escapeHtml(item.data?.message || 'Task completed')}</div>
|
|
763
|
+
</div>
|
|
764
|
+
`;
|
|
765
|
+
break;
|
|
766
|
+
|
|
767
|
+
default:
|
|
768
|
+
// Generic formatting for other types
|
|
769
|
+
let dataContent = '';
|
|
770
|
+
|
|
771
|
+
// Check if the data is a complex object that needs special handling
|
|
772
|
+
if (item.data && typeof item.data === 'object') {
|
|
773
|
+
// Handle deep event structures and large objects
|
|
774
|
+
if (item.type === 'event') {
|
|
775
|
+
// Filter out registered_functions and other large metadata
|
|
776
|
+
const simplifiedData = { ...item.data };
|
|
777
|
+
|
|
778
|
+
// Remove any large arrays/objects (special handling for agent communication)
|
|
779
|
+
if (Array.isArray(simplifiedData.registered_functions)) {
|
|
780
|
+
simplifiedData.functions_summary = `${simplifiedData.registered_functions.length} registered functions available`;
|
|
781
|
+
delete simplifiedData.registered_functions;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// Summarize other large props
|
|
785
|
+
Object.keys(simplifiedData).forEach(key => {
|
|
786
|
+
if (key !== 'functions_summary') {
|
|
787
|
+
const value = simplifiedData[key];
|
|
788
|
+
|
|
789
|
+
// Summarize large arrays
|
|
790
|
+
if (Array.isArray(value) && value.length > 5) {
|
|
791
|
+
simplifiedData[key] = `[Array with ${value.length} items]`;
|
|
792
|
+
}
|
|
793
|
+
// Summarize large nested objects
|
|
794
|
+
else if (typeof value === 'object' && value !== null) {
|
|
795
|
+
const objStr = JSON.stringify(value);
|
|
796
|
+
if (objStr.length > 500) {
|
|
797
|
+
const propCount = Object.keys(value).length;
|
|
798
|
+
simplifiedData[key] = `[Object with ${propCount} properties]`;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
dataContent = escapeHtml(JSON.stringify(simplifiedData, null, 2));
|
|
805
|
+
} else {
|
|
806
|
+
// For other objects, prepare cleaned display version
|
|
807
|
+
const displayObj = { ...item.data };
|
|
808
|
+
|
|
809
|
+
// Look for large items to summarize
|
|
810
|
+
Object.keys(displayObj).forEach(key => {
|
|
811
|
+
const value = displayObj[key];
|
|
812
|
+
|
|
813
|
+
// Summarize large arrays
|
|
814
|
+
if (Array.isArray(value) && value.length > 5) {
|
|
815
|
+
displayObj[key] = `[Array with ${value.length} items]`;
|
|
816
|
+
}
|
|
817
|
+
// Summarize large nested objects
|
|
818
|
+
else if (typeof value === 'object' && value !== null) {
|
|
819
|
+
const objStr = JSON.stringify(value);
|
|
820
|
+
if (objStr.length > 500) {
|
|
821
|
+
const propCount = Object.keys(value).length;
|
|
822
|
+
displayObj[key] = `[Object with ${propCount} properties]`;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
dataContent = escapeHtml(JSON.stringify(displayObj, null, 2));
|
|
828
|
+
}
|
|
829
|
+
} else if (item.data === null || item.data === undefined) {
|
|
830
|
+
dataContent = '{}';
|
|
831
|
+
} else {
|
|
832
|
+
// For primitive data types
|
|
833
|
+
dataContent = escapeHtml(JSON.stringify(item.data, null, 2));
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
content = `
|
|
837
|
+
<div class="feed-header">
|
|
838
|
+
<span class="feed-type"><span class="event-icon">${typeInfo.icon}</span> ${typeInfo.label}</span>
|
|
839
|
+
<span class="feed-time">${timestamp}</span>
|
|
840
|
+
</div>
|
|
841
|
+
<pre class="feed-content">${dataContent}</pre>
|
|
842
|
+
`;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
return content;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
function getEventTypeInfo(type) {
|
|
849
|
+
// Map of event types to icons and labels
|
|
850
|
+
const eventTypes = {
|
|
851
|
+
'step': { icon: '🤖', label: 'Agent Step', className: 'event-agent-step' },
|
|
852
|
+
'tool_execution': { icon: '🔧', label: 'Tool Execution', className: 'event-tool-execution' },
|
|
853
|
+
'planner': { icon: '🧠', label: 'Planner', className: 'event-planner' },
|
|
854
|
+
'agent_message': { icon: '💬', label: 'Agent Message', className: 'event-agent-message' },
|
|
855
|
+
'task_complete': { icon: '✅', label: 'Task Complete', className: 'event-task-complete' },
|
|
856
|
+
'evaluation': { icon: '📊', label: 'Evaluation', className: 'event-evaluation' },
|
|
857
|
+
'multi_agent_relationship': { icon: '🔄', label: 'Agent Relationship', className: 'event-relationship' },
|
|
858
|
+
'agent_registration': { icon: '📝', label: 'Agent Registration', className: 'event-registration' },
|
|
859
|
+
'session_start': { icon: '🚀', label: 'Session Start', className: 'event-session-start' },
|
|
860
|
+
'task_update': { icon: '📋', label: 'Task Update', className: 'event-task-update' },
|
|
861
|
+
'llm_request': { icon: '💬', label: 'LLM Request', className: 'event-llm-request' },
|
|
862
|
+
'service_actions': { icon: '🔧', label: 'Service Actions', className: 'event-service-actions' },
|
|
863
|
+
'available_actions': { icon: '⚡', label: 'Available Actions', className: 'event-available-actions' },
|
|
864
|
+
'status': { icon: '🔔', label: 'Status Update', className: 'event-status' }
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
return eventTypes[type] || { icon: '📌', label: 'Event', className: 'event-generic' };
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Detect service name from action object
|
|
872
|
+
*/
|
|
873
|
+
function detectServiceFromAction(action) {
|
|
874
|
+
if (action.service) return action.service;
|
|
875
|
+
|
|
876
|
+
const actionName = action.name || action.action_type || '';
|
|
877
|
+
const serviceMap = {
|
|
878
|
+
'open_tab': 'browser',
|
|
879
|
+
'close_tab': 'browser',
|
|
880
|
+
'click': 'browser',
|
|
881
|
+
'type_text': 'browser',
|
|
882
|
+
'scroll': 'browser',
|
|
883
|
+
'go_back': 'browser',
|
|
884
|
+
'refresh': 'browser',
|
|
885
|
+
'search': 'browser',
|
|
886
|
+
'write_file': 'filesystem',
|
|
887
|
+
'read_file': 'filesystem',
|
|
888
|
+
'list_files': 'filesystem',
|
|
889
|
+
'delete_file': 'filesystem',
|
|
890
|
+
'create_directory': 'filesystem'
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
return serviceMap[actionName] || 'default';
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Format action items in the feed
|
|
898
|
+
*/
|
|
899
|
+
function formatActions(actions) {
|
|
900
|
+
if (!actions || !actions.length) return '';
|
|
901
|
+
|
|
902
|
+
return `
|
|
903
|
+
<div class="event-actions">
|
|
904
|
+
<div class="event-actions-header">Actions (${actions.length}):</div>
|
|
905
|
+
<div class="event-actions-list">
|
|
906
|
+
${actions.map(action => {
|
|
907
|
+
const serviceName = action.service || 'default';
|
|
908
|
+
const actionName = action.name || action.action_type || 'unknown';
|
|
909
|
+
|
|
910
|
+
// Skip rendering params for certain large payload actions
|
|
911
|
+
const skipParamsDisplay = actionName === 'extract_content' ||
|
|
912
|
+
(actionName === 'process_document' && action.content && action.content.length > 1000);
|
|
913
|
+
|
|
914
|
+
// Special handling for open_tab actions
|
|
915
|
+
const isOpenTab = actionName === 'open_tab';
|
|
916
|
+
|
|
917
|
+
// For open_tab actions, create a more compact representation
|
|
918
|
+
if (isOpenTab && action.url) {
|
|
919
|
+
return `
|
|
920
|
+
<div class="event-action event-action-url">
|
|
921
|
+
<div class="event-action-header">
|
|
922
|
+
<span class="event-action-service">${serviceName}</span>
|
|
923
|
+
<span class="event-action-separator">→</span>
|
|
924
|
+
<span class="event-action-name">${actionName}</span>
|
|
925
|
+
</div>
|
|
926
|
+
<div class="compact-url">
|
|
927
|
+
<a href="${action.url}" target="_blank" rel="noopener noreferrer" title="${action.url}">${escapeHtml(action.url)}</a>
|
|
928
|
+
</div>
|
|
929
|
+
</div>
|
|
930
|
+
`;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// For standard actions, use the normal representation
|
|
934
|
+
return `
|
|
935
|
+
<div class="event-action ${isOpenTab ? 'event-action-url' : ''}">
|
|
936
|
+
<div class="event-action-header">
|
|
937
|
+
<span class="event-action-service">${serviceName}</span>
|
|
938
|
+
<span class="event-action-separator">→</span>
|
|
939
|
+
<span class="event-action-name">${actionName}</span>
|
|
940
|
+
</div>
|
|
941
|
+
${skipParamsDisplay ?
|
|
942
|
+
'<div class="param-summary">Large content parameters omitted</div>' :
|
|
943
|
+
createParamsTable(action)}
|
|
944
|
+
</div>
|
|
945
|
+
`;
|
|
946
|
+
}).join('')}
|
|
947
|
+
</div>
|
|
948
|
+
</div>
|
|
949
|
+
`;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function formatPlannerComponents(components) {
|
|
953
|
+
if (!components || Object.keys(components).length === 0) return '';
|
|
954
|
+
|
|
955
|
+
return `
|
|
956
|
+
<div class="event-components">
|
|
957
|
+
<div class="event-components-header">Components:</div>
|
|
958
|
+
<div class="event-components-list">
|
|
959
|
+
${Object.entries(components).map(([key, value]) => {
|
|
960
|
+
const formattedKey = key.replace('has_', '').replace(/_/g, ' ');
|
|
961
|
+
return `
|
|
962
|
+
<div class="event-component">
|
|
963
|
+
<span class="event-component-name">${formattedKey}</span>
|
|
964
|
+
<span class="event-component-value">${value ? '✓' : '✗'}</span>
|
|
965
|
+
</div>
|
|
966
|
+
`;
|
|
967
|
+
}).join('')}
|
|
968
|
+
</div>
|
|
969
|
+
</div>
|
|
970
|
+
`;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function formatEvaluationDetails(evaluation) {
|
|
974
|
+
if (!evaluation) return '';
|
|
975
|
+
|
|
976
|
+
let details = '';
|
|
977
|
+
|
|
978
|
+
if (evaluation.strengths && evaluation.strengths.length) {
|
|
979
|
+
details += `
|
|
980
|
+
<div class="event-eval-section">
|
|
981
|
+
<div class="event-eval-header">Strengths:</div>
|
|
982
|
+
<ul class="event-eval-list">
|
|
983
|
+
${evaluation.strengths.map(item => `<li>${item}</li>`).join('')}
|
|
984
|
+
</ul>
|
|
985
|
+
</div>
|
|
986
|
+
`;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
if (evaluation.weaknesses && evaluation.weaknesses.length) {
|
|
990
|
+
details += `
|
|
991
|
+
<div class="event-eval-section">
|
|
992
|
+
<div class="event-eval-header">Weaknesses:</div>
|
|
993
|
+
<ul class="event-eval-list">
|
|
994
|
+
${evaluation.weaknesses.map(item => `<li>${item}</li>`).join('')}
|
|
995
|
+
</ul>
|
|
996
|
+
</div>
|
|
997
|
+
`;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
if (evaluation.suggestions && evaluation.suggestions.length) {
|
|
1001
|
+
details += `
|
|
1002
|
+
<div class="event-eval-section">
|
|
1003
|
+
<div class="event-eval-header">Suggestions:</div>
|
|
1004
|
+
<ul class="event-eval-list">
|
|
1005
|
+
${evaluation.suggestions.map(item => `<li>${item}</li>`).join('')}
|
|
1006
|
+
</ul>
|
|
1007
|
+
</div>
|
|
1008
|
+
`;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
return details;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function formatAgentRelationships(agents) {
|
|
1015
|
+
if (!agents || !agents.length) return '';
|
|
1016
|
+
|
|
1017
|
+
return `
|
|
1018
|
+
<div class="event-agents">
|
|
1019
|
+
<div class="event-agents-header">Agents:</div>
|
|
1020
|
+
<div class="event-agents-list">
|
|
1021
|
+
${agents.map(agent => {
|
|
1022
|
+
return `
|
|
1023
|
+
<div class="event-agent">
|
|
1024
|
+
<span class="event-agent-name">${agent.name || agent.agent_name || 'Unknown'}</span>
|
|
1025
|
+
<span class="event-agent-type">${agent.type || agent.agent_type || 'Unknown'}</span>
|
|
1026
|
+
${agent.model ? `<span class="event-agent-model">${agent.model}</span>` : ''}
|
|
1027
|
+
</div>
|
|
1028
|
+
`;
|
|
1029
|
+
}).join('')}
|
|
1030
|
+
</div>
|
|
1031
|
+
</div>
|
|
1032
|
+
`;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
function scrollToBottom(element) {
|
|
1036
|
+
element.scrollTop = element.scrollHeight;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
function showFeedError(message) {
|
|
1040
|
+
const errorEl = document.getElementById('feed-error');
|
|
1041
|
+
if (errorEl) {
|
|
1042
|
+
errorEl.textContent = message;
|
|
1043
|
+
errorEl.style.display = 'block';
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Creates a clean, tabular representation of action parameters
|
|
1049
|
+
*/
|
|
1050
|
+
function createParamsTable(action) {
|
|
1051
|
+
// Expanded list of keys to skip from display
|
|
1052
|
+
const skipKeys = [
|
|
1053
|
+
'service', 'name', 'action_type', 'registered_functions',
|
|
1054
|
+
'by_service', 'action_count', 'service_name', 'service_type',
|
|
1055
|
+
'available_actions', 'orchestrator_type'
|
|
1056
|
+
];
|
|
1057
|
+
|
|
1058
|
+
// If action contains a nested "params" object, merge its keys at the same
|
|
1059
|
+
// level for display purposes so we don't show a redundant "params" row.
|
|
1060
|
+
const merged = { ...action };
|
|
1061
|
+
if (merged.params && typeof merged.params === 'object') {
|
|
1062
|
+
Object.assign(merged, merged.params);
|
|
1063
|
+
delete merged.params;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// Filter out service and action internal keys and massive payload objects
|
|
1067
|
+
let params = Object.entries(merged).filter(([k, v]) => {
|
|
1068
|
+
// Skip system/meta properties
|
|
1069
|
+
if (skipKeys.includes(k)) return false;
|
|
1070
|
+
|
|
1071
|
+
// Skip large JSON objects (like registered_functions or by_service payloads)
|
|
1072
|
+
if (typeof v === 'object' && v !== null) {
|
|
1073
|
+
// Check if this is a service definition object
|
|
1074
|
+
if (k === 'services' ||
|
|
1075
|
+
(typeof v === 'object' &&
|
|
1076
|
+
(v.service_name || v.service_type || v.available_actions))) {
|
|
1077
|
+
return false;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
const jsonStr = JSON.stringify(v);
|
|
1081
|
+
// Skip large objects over 1000 chars
|
|
1082
|
+
if (jsonStr.length > 1000) return false;
|
|
1083
|
+
|
|
1084
|
+
// Skip service-related objects or arrays that contain service definitions
|
|
1085
|
+
if (jsonStr.includes('"service":') ||
|
|
1086
|
+
jsonStr.includes('"available_actions":') ||
|
|
1087
|
+
jsonStr.includes('"service_name":') ||
|
|
1088
|
+
jsonStr.includes('"orchestrator_type":')) {
|
|
1089
|
+
return false;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
return true;
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
// Prioritise specific keys
|
|
1097
|
+
const priority = ['next_goal', 'criteria', 'query', 'text', 'file_path', 'url'];
|
|
1098
|
+
params.sort(([a], [b]) => {
|
|
1099
|
+
const ai = priority.indexOf(a);
|
|
1100
|
+
const bi = priority.indexOf(b);
|
|
1101
|
+
if (ai === -1 && bi === -1) return 0;
|
|
1102
|
+
if (ai === -1) return 1;
|
|
1103
|
+
if (bi === -1) return -1;
|
|
1104
|
+
return ai - bi;
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
if (!params.length) {
|
|
1108
|
+
// If we've filtered everything out, just show a summary message
|
|
1109
|
+
return `<div class="param-summary">Simple action with no additional parameters</div>`;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// Special handling for file operations
|
|
1113
|
+
if (action.name === 'write_file' || action.name === 'read_file') {
|
|
1114
|
+
return createFileParamsTable(params);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// Special handling for URL actions
|
|
1118
|
+
if (action.name === 'open_tab' || (action.name && action.name.includes('url'))) {
|
|
1119
|
+
return createUrlParamsTable(params);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// Default parameter table
|
|
1123
|
+
return `
|
|
1124
|
+
<table class="params-table">
|
|
1125
|
+
<tbody>
|
|
1126
|
+
${params.map(([key, value]) => {
|
|
1127
|
+
// Format value based on type
|
|
1128
|
+
let displayValue;
|
|
1129
|
+
if (typeof value === 'object' && value !== null) {
|
|
1130
|
+
// For objects, check size first
|
|
1131
|
+
const jsonStr = JSON.stringify(value, null, 2);
|
|
1132
|
+
|
|
1133
|
+
// For very large objects, show a summary instead
|
|
1134
|
+
if (jsonStr.length > 500) {
|
|
1135
|
+
if (Array.isArray(value)) {
|
|
1136
|
+
return `
|
|
1137
|
+
<tr>
|
|
1138
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1139
|
+
<td class="param-value"><div class="param-summary">Array with ${value.length} items</div></td>
|
|
1140
|
+
</tr>
|
|
1141
|
+
`;
|
|
1142
|
+
} else {
|
|
1143
|
+
return `
|
|
1144
|
+
<tr>
|
|
1145
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1146
|
+
<td class="param-value"><div class="param-summary">Object with ${Object.keys(value).length} properties</div></td>
|
|
1147
|
+
</tr>
|
|
1148
|
+
`;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// For normal sized objects, format as pretty JSON
|
|
1153
|
+
displayValue = escapeHtml(jsonStr);
|
|
1154
|
+
return `
|
|
1155
|
+
<tr>
|
|
1156
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1157
|
+
<td class="param-value"><pre class="json-value">${displayValue}</pre></td>
|
|
1158
|
+
</tr>
|
|
1159
|
+
`;
|
|
1160
|
+
} else {
|
|
1161
|
+
// Format simple values directly
|
|
1162
|
+
const valueStr = String(value);
|
|
1163
|
+
|
|
1164
|
+
// Check if the value looks like a URL
|
|
1165
|
+
if (isUrl(valueStr)) {
|
|
1166
|
+
return `
|
|
1167
|
+
<tr>
|
|
1168
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1169
|
+
<td class="param-value url-value">
|
|
1170
|
+
<a href="${valueStr}" target="_blank" rel="noopener noreferrer" title="${valueStr}">${escapeHtml(valueStr)}</a>
|
|
1171
|
+
</td>
|
|
1172
|
+
</tr>
|
|
1173
|
+
`;
|
|
1174
|
+
} else {
|
|
1175
|
+
displayValue = escapeHtml(valueStr);
|
|
1176
|
+
return `
|
|
1177
|
+
<tr>
|
|
1178
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1179
|
+
<td class="param-value">${displayValue}</td>
|
|
1180
|
+
</tr>
|
|
1181
|
+
`;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}).join('')}
|
|
1185
|
+
</tbody>
|
|
1186
|
+
</table>
|
|
1187
|
+
`;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Create a specialized table for file operations
|
|
1192
|
+
*/
|
|
1193
|
+
function createFileParamsTable(params) {
|
|
1194
|
+
// Extract file path and content
|
|
1195
|
+
let filePath = '';
|
|
1196
|
+
let fileContent = '';
|
|
1197
|
+
let fileType = '';
|
|
1198
|
+
const otherParams = [];
|
|
1199
|
+
|
|
1200
|
+
params.forEach(([key, value]) => {
|
|
1201
|
+
if (key === 'file_path') {
|
|
1202
|
+
filePath = value;
|
|
1203
|
+
fileType = value.split('.').pop().toLowerCase();
|
|
1204
|
+
} else if (key === 'content' || key === 'file_content') {
|
|
1205
|
+
fileContent = value;
|
|
1206
|
+
} else {
|
|
1207
|
+
otherParams.push([key, value]);
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
// Start with the simple parameters
|
|
1212
|
+
let html = '<table class="params-table">';
|
|
1213
|
+
|
|
1214
|
+
// Always show file path first
|
|
1215
|
+
if (filePath) {
|
|
1216
|
+
html += `
|
|
1217
|
+
<tr>
|
|
1218
|
+
<td class="param-name">file_path</td>
|
|
1219
|
+
<td class="param-value file-path">${escapeHtml(filePath)}</td>
|
|
1220
|
+
</tr>
|
|
1221
|
+
`;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// Add any other parameters except content (which we'll handle separately)
|
|
1225
|
+
otherParams.forEach(([key, value]) => {
|
|
1226
|
+
const valueStr = String(value);
|
|
1227
|
+
|
|
1228
|
+
// Check if the value looks like a URL
|
|
1229
|
+
if (isUrl(valueStr)) {
|
|
1230
|
+
html += `
|
|
1231
|
+
<tr>
|
|
1232
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1233
|
+
<td class="param-value url-value">
|
|
1234
|
+
<a href="${valueStr}" target="_blank" rel="noopener noreferrer" title="${valueStr}">${escapeHtml(valueStr)}</a>
|
|
1235
|
+
</td>
|
|
1236
|
+
</tr>
|
|
1237
|
+
`;
|
|
1238
|
+
} else {
|
|
1239
|
+
html += `
|
|
1240
|
+
<tr>
|
|
1241
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1242
|
+
<td class="param-value">${escapeHtml(valueStr)}</td>
|
|
1243
|
+
</tr>
|
|
1244
|
+
`;
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
html += '</table>';
|
|
1249
|
+
|
|
1250
|
+
// Add file content if present
|
|
1251
|
+
if (fileContent) {
|
|
1252
|
+
const langClass = fileType === 'md' ? 'code-md' :
|
|
1253
|
+
fileType === 'json' ? 'code-json' :
|
|
1254
|
+
fileType === 'html' ? 'code-html' :
|
|
1255
|
+
fileType === 'css' ? 'code-css' :
|
|
1256
|
+
fileType === 'js' ? 'code-js' :
|
|
1257
|
+
fileType === 'py' ? 'code-py' : '';
|
|
1258
|
+
|
|
1259
|
+
// Special handling for fileType that might contain URLs
|
|
1260
|
+
if (fileType === 'md' || fileType === 'html' || fileType === 'txt') {
|
|
1261
|
+
// For text-based content, look for possible URLs to enhance
|
|
1262
|
+
html += `
|
|
1263
|
+
<div class="file-content-header">Content:</div>
|
|
1264
|
+
<pre class="file-content ${langClass}"><code>${formatContentWithUrls(fileContent)}</code></pre>
|
|
1265
|
+
`;
|
|
1266
|
+
} else {
|
|
1267
|
+
html += `
|
|
1268
|
+
<div class="file-content-header">Content:</div>
|
|
1269
|
+
<pre class="file-content ${langClass}"><code>${escapeHtml(fileContent)}</code></pre>
|
|
1270
|
+
`;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
return html;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Format content with URL detection and turn URLs into clickable links
|
|
1279
|
+
*/
|
|
1280
|
+
function formatContentWithUrls(content) {
|
|
1281
|
+
if (typeof content !== 'string') {
|
|
1282
|
+
return escapeHtml(String(content));
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// First escape the HTML to prevent XSS
|
|
1286
|
+
const escapedContent = escapeHtml(content);
|
|
1287
|
+
|
|
1288
|
+
// Simple regex to find URLs in text
|
|
1289
|
+
const urlRegex = /https?:\/\/[^\s"<>()]+/g;
|
|
1290
|
+
|
|
1291
|
+
// Replace URLs with clickable links
|
|
1292
|
+
return escapedContent.replace(urlRegex, (url) => {
|
|
1293
|
+
return `<a href="${url}" target="_blank" rel="noopener noreferrer" class="content-url" title="${url}">${url}</a>`;
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
/**
|
|
1298
|
+
* Creates special handling for open_tab or URL-related actions
|
|
1299
|
+
* This function needs to properly format URLs without splitting them
|
|
1300
|
+
*/
|
|
1301
|
+
function createUrlParamsTable(params) {
|
|
1302
|
+
// Start with a table for parameters
|
|
1303
|
+
let html = '<table class="params-table">';
|
|
1304
|
+
|
|
1305
|
+
// Process each parameter
|
|
1306
|
+
params.forEach(([key, value]) => {
|
|
1307
|
+
const valueStr = String(value || '');
|
|
1308
|
+
|
|
1309
|
+
// Special handling for URL parameter
|
|
1310
|
+
if (key === 'url') {
|
|
1311
|
+
html += `
|
|
1312
|
+
<tr>
|
|
1313
|
+
<td class="param-name">url</td>
|
|
1314
|
+
<td class="param-value url-value" colspan="2">
|
|
1315
|
+
<a href="${valueStr}" target="_blank" rel="noopener noreferrer" title="${valueStr}">${escapeHtml(valueStr)}</a>
|
|
1316
|
+
</td>
|
|
1317
|
+
</tr>
|
|
1318
|
+
`;
|
|
1319
|
+
}
|
|
1320
|
+
// Check if any other value looks like a URL
|
|
1321
|
+
else if (isUrl(valueStr)) {
|
|
1322
|
+
html += `
|
|
1323
|
+
<tr>
|
|
1324
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1325
|
+
<td class="param-value url-value" colspan="2">
|
|
1326
|
+
<a href="${valueStr}" target="_blank" rel="noopener noreferrer" title="${valueStr}">${escapeHtml(valueStr)}</a>
|
|
1327
|
+
</td>
|
|
1328
|
+
</tr>
|
|
1329
|
+
`;
|
|
1330
|
+
}
|
|
1331
|
+
// Standard parameter
|
|
1332
|
+
else {
|
|
1333
|
+
html += `
|
|
1334
|
+
<tr>
|
|
1335
|
+
<td class="param-name">${escapeHtml(key)}</td>
|
|
1336
|
+
<td class="param-value">${escapeHtml(valueStr)}</td>
|
|
1337
|
+
</tr>
|
|
1338
|
+
`;
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
html += '</table>';
|
|
1343
|
+
return html;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* Helper function to check if a string looks like a URL
|
|
1348
|
+
* Handles various formats including partial URLs
|
|
1349
|
+
*/
|
|
1350
|
+
function isUrl(str) {
|
|
1351
|
+
if (!str || typeof str !== 'string') return false;
|
|
1352
|
+
|
|
1353
|
+
// First check for full URLs with common protocols
|
|
1354
|
+
if (str.match(/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i)) {
|
|
1355
|
+
return true;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
// Check for domain patterns that might be URLs without protocols
|
|
1359
|
+
if (str.match(/^www\.[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,}(:[0-9]{1,5})?(\/.*)?$/i)) {
|
|
1360
|
+
return true;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// Check for domain with common TLDs without www
|
|
1364
|
+
if (str.match(/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.(com|org|net|edu|gov|mil|io|co|ai|app)(\/.*)?$/i)) {
|
|
1365
|
+
return true;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Synchronise the INFO sidebar with the latest event.
|
|
1373
|
+
* We avoid expensive network calls unless required, updating strings
|
|
1374
|
+
* directly when possible. For structural changes, we emit events for the
|
|
1375
|
+
* sidebar to handle refreshes.
|
|
1376
|
+
*/
|
|
1377
|
+
function handleSidebarUpdates(item) {
|
|
1378
|
+
if (!item || !item.type) return;
|
|
1379
|
+
|
|
1380
|
+
switch (item.type) {
|
|
1381
|
+
case 'status':
|
|
1382
|
+
if (item.data?.status) {
|
|
1383
|
+
setText('current-task-text', item.data.status);
|
|
1384
|
+
// Also update session status
|
|
1385
|
+
updateSessionStatus(item.data.status);
|
|
1386
|
+
// Request session info refresh via event
|
|
1387
|
+
emit('sidebar:refreshRequest', { kind: 'session' });
|
|
1388
|
+
}
|
|
1389
|
+
break;
|
|
1390
|
+
|
|
1391
|
+
case 'task_update':
|
|
1392
|
+
if (item.data?.task) {
|
|
1393
|
+
setText('task-display', item.data.task);
|
|
1394
|
+
}
|
|
1395
|
+
if (item.data?.status) {
|
|
1396
|
+
setText('current-task-text', item.data.status);
|
|
1397
|
+
// Request task and session refresh via events
|
|
1398
|
+
emit('sidebar:refreshRequest', { kind: 'task' });
|
|
1399
|
+
emit('sidebar:refreshRequest', { kind: 'session' });
|
|
1400
|
+
}
|
|
1401
|
+
break;
|
|
1402
|
+
|
|
1403
|
+
case 'agent_registration':
|
|
1404
|
+
case 'multi_agent_relationship':
|
|
1405
|
+
// Agents list potentially changed → request refresh
|
|
1406
|
+
emit('sidebar:refreshRequest', { kind: 'agents' });
|
|
1407
|
+
break;
|
|
1408
|
+
|
|
1409
|
+
case 'service_actions':
|
|
1410
|
+
case 'available_actions':
|
|
1411
|
+
// Services catalogue updated
|
|
1412
|
+
emit('sidebar:refreshRequest', { kind: 'services' });
|
|
1413
|
+
break;
|
|
1414
|
+
|
|
1415
|
+
case 'llm_request':
|
|
1416
|
+
// Stats (tokens / cost) likely changed
|
|
1417
|
+
emit('stats:refreshRequest');
|
|
1418
|
+
break;
|
|
1419
|
+
|
|
1420
|
+
default:
|
|
1421
|
+
break;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
// ------------------------------------------------------------------
|
|
1426
|
+
// Fallback: if no WebSocket payload arrives within a short time span
|
|
1427
|
+
// (e.g. due to missed emission before join), fetch the latest events via
|
|
1428
|
+
// the REST endpoint so the feed is never empty.
|
|
1429
|
+
// ------------------------------------------------------------------
|
|
1430
|
+
setTimeout(async () => {
|
|
1431
|
+
// Check if EventStore already has events (from WS)
|
|
1432
|
+
if (eventStore.size > 0) return;
|
|
1433
|
+
|
|
1434
|
+
try {
|
|
1435
|
+
const response = await fetch(`/api/session/${sessionId}/feed/events?limit=500`);
|
|
1436
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
1437
|
+
const data = await response.json();
|
|
1438
|
+
|
|
1439
|
+
// Handle new API format { events: [...], last_seq: N }
|
|
1440
|
+
const events = data.events || data;
|
|
1441
|
+
if (Array.isArray(events) && events.length) {
|
|
1442
|
+
const inserted = eventStore.insertBatch(events);
|
|
1443
|
+
logger.info(`[Session] REST fallback: inserted ${inserted.length} events`);
|
|
1444
|
+
} else {
|
|
1445
|
+
logger.warn('[Session] Feed fallback returned no events');
|
|
1446
|
+
}
|
|
1447
|
+
} catch (err) {
|
|
1448
|
+
logger.error('[Session] Feed fallback failed:', err);
|
|
1449
|
+
}
|
|
1450
|
+
}, 1500); // 1.5-second grace period after page load for faster recovery
|
|
1451
|
+
|
|
1452
|
+
} finally {
|
|
1453
|
+
// Release the lock - MUST happen regardless of outcome
|
|
1454
|
+
if (releaseLock) releaseLock();
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// Function to trigger socket initialization (can be called externally)
|
|
1459
|
+
function triggerSocketInitialization() {
|
|
1460
|
+
logger.debug('[Session] triggerSocketInitialization called');
|
|
1461
|
+
|
|
1462
|
+
// Use centralized session state
|
|
1463
|
+
const currentSessionId = sessionState.sessionId;
|
|
1464
|
+
const isNew = sessionState.isNew;
|
|
1465
|
+
|
|
1466
|
+
if (!currentSessionId || isNew) {
|
|
1467
|
+
logger.debug('[Session] Cannot initialize - no valid session ID');
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
if (window.io) {
|
|
1472
|
+
initializeSocket(window.io);
|
|
1473
|
+
} else {
|
|
1474
|
+
logger.error('[Session] Socket.IO not available');
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
// Expose function globally for other modules to call
|
|
1479
|
+
window.triggerSocketInitialization = triggerSocketInitialization;
|
|
1480
|
+
|
|
1481
|
+
// Check if Socket.IO is already loaded and initialize if we have an active session
|
|
1482
|
+
if (window.io) {
|
|
1483
|
+
initializeSocket(window.io);
|
|
1484
|
+
} else {
|
|
1485
|
+
// Wait for Socket.IO to load
|
|
1486
|
+
window.socketIOReady.then((io) => {
|
|
1487
|
+
initializeSocket(io);
|
|
1488
|
+
}).catch(err => {
|
|
1489
|
+
logger.error('[Session] Failed to load Socket.IO:', err);
|
|
1490
|
+
setText('refresh-text', 'Connection failed');
|
|
1491
|
+
const feedError = document.getElementById('feed-error');
|
|
1492
|
+
if (feedError) {
|
|
1493
|
+
feedError.textContent = 'Failed to establish connection. Please refresh the page.';
|
|
1494
|
+
feedError.style.display = 'block';
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// Export functions for other modules
|
|
1500
|
+
export { initializeSocket };
|
|
1501
|
+
|
|
1502
|
+
/**
|
|
1503
|
+
* Update the session status in the sidebar
|
|
1504
|
+
*/
|
|
1505
|
+
function updateSessionStatus(status) {
|
|
1506
|
+
// Format and update the status text if the element exists
|
|
1507
|
+
const sessionStatusEl = document.getElementById('session-status');
|
|
1508
|
+
if (sessionStatusEl && status) {
|
|
1509
|
+
sessionStatusEl.textContent = status.charAt(0).toUpperCase() + status.slice(1);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* New Session functionality
|
|
1515
|
+
* Redirects to /new page where user can enter task in chat interface
|
|
1516
|
+
*/
|
|
1517
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
1518
|
+
const newSessionBtn = document.getElementById('new-session-btn');
|
|
1519
|
+
|
|
1520
|
+
if (newSessionBtn) {
|
|
1521
|
+
newSessionBtn.addEventListener('click', () => {
|
|
1522
|
+
// Redirect to new session page (chat.html) where user can type task
|
|
1523
|
+
window.location.href = '/new';
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
|